From: Matt Caswell Date: Fri, 11 Sep 2020 12:22:40 +0000 (+0100) Subject: Provide basis for fixing lhash code X-Git-Tag: openssl-3.0.0-alpha7~210 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=726b3293399cee7b1eedcfb3a524b91537bd5118;p=thirdparty%2Fopenssl.git Provide basis for fixing lhash code Following on from the earlier safestack work we provide the basis for fixing the lhash code such that unused static inline functions do not cause linker errors for applications including those headers. This brings the lhash code into line with the safestack code. Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/12860) --- diff --git a/include/openssl/lhash.h b/include/openssl/lhash.h index 5ad9b16ab2e..816b613eafe 100644 --- a/include/openssl/lhash.h +++ b/include/openssl/lhash.h @@ -125,6 +125,42 @@ void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out); # define LHASH_OF(type) struct lhash_st_##type +/* Helper macro for internal use */ +# define DEFINE_LHASH_OF_INTERNAL(type) \ + LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \ + typedef int (*lh_##type##_compfunc)(const type *a, const type *b); \ + typedef unsigned long (*lh_##type##_hashfunc)(const type *a); \ + typedef void (*lh_##type##_doallfunc)(type *a); \ + static ossl_unused ossl_inline type *ossl_check_##type##_lh_plain_type(type *ptr) \ + { \ + return ptr; \ + } \ + static ossl_unused ossl_inline const type *ossl_check_const_##type##_lh_plain_type(const type *ptr) \ + { \ + return ptr; \ + } \ + static ossl_unused ossl_inline const OPENSSL_LHASH *ossl_check_const_##type##_lh_type(const LHASH_OF(type) *lh) \ + { \ + return (const OPENSSL_LHASH *)lh; \ + } \ + static ossl_unused ossl_inline OPENSSL_LHASH *ossl_check_##type##_lh_type(LHASH_OF(type) *lh) \ + { \ + return (OPENSSL_LHASH *)lh; \ + } \ + static ossl_unused ossl_inline OPENSSL_LH_COMPFUNC ossl_check_##type##_lh_compfunc_type(lh_##type##_compfunc cmp) \ + { \ + return (OPENSSL_LH_COMPFUNC)cmp; \ + } \ + static ossl_unused ossl_inline OPENSSL_LH_HASHFUNC ossl_check_##type##_lh_hashfunc_type(lh_##type##_hashfunc hfn) \ + { \ + return (OPENSSL_LH_HASHFUNC)hfn; \ + } \ + static ossl_unused ossl_inline OPENSSL_LH_DOALL_FUNC ossl_check_##type##_lh_doallfunc_type(lh_##type##_doallfunc dfn) \ + { \ + return (OPENSSL_LH_DOALL_FUNC)dfn; \ + } \ + LHASH_OF(type) + # define DEFINE_LHASH_OF(type) \ LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \ static ossl_unused ossl_inline LHASH_OF(type) *lh_##type##_new(unsigned long (*hfn)(const type *), \ diff --git a/util/perl/OpenSSL/stackhash.pm b/util/perl/OpenSSL/stackhash.pm index fd7a8cbd060..7cf9c26411e 100644 --- a/util/perl/OpenSSL/stackhash.pm +++ b/util/perl/OpenSSL/stackhash.pm @@ -16,7 +16,8 @@ our @ISA = qw(Exporter); our @EXPORT_OK = qw(generate_stack_macros generate_const_stack_macros generate_stack_string_macros generate_stack_const_string_macros - generate_stack_block_macros); + generate_stack_block_macros + generate_lhash_macros); sub generate_stack_macros_int { my $nametype = shift; @@ -77,4 +78,28 @@ sub generate_stack_const_string_macros { sub generate_stack_block_macros { return generate_stack_macros_int("OPENSSL_BLOCK", "void", "void"); } + +sub generate_lhash_macros { + my $type = shift; + + my $macros = <