[openssl-dev] LHASH, -Wcast-align and the union (redux)

Jeffrey Walton noloader at gmail.com
Sun Mar 27 05:38:18 UTC 2016


I'm on CentOS 5 with GCC 4.1.2. It appears there are side effects to
the union for the down level compiler.

Removing the union squashes the warning, but I like Viktor's idea and
placing a few of the larger types in it. I think its safer in the long
run.

Naming the union squashes the warning. The change below tested OK
under OS X, CentOS, Linux and NetBSD.

$ git diff include/openssl/lhash.h
diff --git a/include/openssl/lhash.h b/include/openssl/lhash.h
index e10c522..669cdf1 100644
--- a/include/openssl/lhash.h
+++ b/include/openssl/lhash.h
@@ -180,7 +180,7 @@ void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out);
 # define LHASH_OF(type) struct lhash_st_##type

 # define DEFINE_LHASH_OF(type) \
-    LHASH_OF(type) { union { void* d1; unsigned long d2; int d3; }; }; \
+    LHASH_OF(type) { union { void* d1; unsigned long d2; int d3; } u_st; }; \
     static ossl_inline LHASH_OF(type) * \
         lh_##type##_new(unsigned long (*hfn)(const type *), \
                         int (*cfn)(const type *, const type *)) \

Breaking eggs, making omelets, and catching the issues before they are
pushed to users. Things are working as expected :)

**********

gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_THREADS
-DOPENSSL_NO_DYNAMIC_ENGINE -DOPENSSL_PIC
-DOPENSSLDIR="\"/usr/local/ssl\""
-DENGINESDIR="\"/usr/local/lib64/engines\"" -Wall -O3 -pthread -m64
-DL_ENDIAN  -ansi -fPIC -Iinclude -I. -Icrypto/include -MMD -MF
crypto/asn1/a_bitstr.d.tmp -MT crypto/asn1/a_bitstr.o -c -o
crypto/asn1/a_bitstr.o crypto/asn1/a_bitstr.c
In file included from include/openssl/err.h:123,
                 from crypto/include/internal/cryptlib.h:74,
                 from crypto/aes/aes_wrap.c:54:
include/openssl/lhash.h:265: warning: declaration does not declare
anythingIn file included from include/openssl/err.h:123,
                 from crypto/include/internal/cryptlib.h:74,
                 from crypto/aes/aes_ige.c:51:
include/openssl/lhash.h:265: warning: declaration does not declare anything

include/openssl/lhash.h:266: warning: declaration does not declare anything
include/openssl/lhash.h:266: warning: declaration does not declare anything

And

    $ cat -n include/openssl/lhash.h:
    ...
    265    DEFINE_LHASH_OF(OPENSSL_STRING);
    266    DEFINE_LHASH_OF(OPENSSL_CSTRING);

And catching lots of them.

**********

$ gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55)
Copyright (C) 2006 Free Software Foundation, Inc.


More information about the openssl-dev mailing list