]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Fix build failures with older versions of gcc
authorMichael Brown <mcb30@ipxe.org>
Sat, 10 Feb 2024 14:41:29 +0000 (14:41 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sat, 10 Feb 2024 14:48:56 +0000 (14:48 +0000)
Some versions of gcc (observed with gcc 4.8.5 in CentOS 7) will report
spurious build_assert() failures for some assertions about structure
layouts.  There is no clear pattern as to what causes these spurious
failures, and the build assertion does succeed in that no unresolvable
symbol reference is generated in the compiled code.

Adjust the assertions to work around these apparent compiler issues.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/gcm.c
src/include/ipxe/gcm.h

index c21aad14c9f57d8b7fa7ddf0686a5eed6cbd4be0..a32890d595830341dd0035951d419ed37aea1898 100644 (file)
@@ -469,13 +469,15 @@ int gcm_setkey ( struct gcm_context *context, const void *key, size_t keylen,
  * @v ivlen            Initialisation vector length
  */
 void gcm_setiv ( struct gcm_context *context, const void *iv, size_t ivlen ) {
-       union gcm_block *check = ( ( void * ) context );
 
-       /* Sanity checks */
-       build_assert ( &context->hash == check );
-       build_assert ( &context->len == check + 1 );
-       build_assert ( &context->ctr == check + 2 );
-       build_assert ( &context->key == check + 3 );
+       /* Sanity check: ensure that memset()s will clear expected state */
+       build_assert ( &context->hash < &context->ctr );
+       build_assert ( &context->len < &context->ctr );
+       build_assert ( &context->ctr < &context->key );
+       build_assert ( ( ( void * ) &context->raw_cipher ) >
+                      ( ( void * ) &context->key ) );
+       build_assert ( ( ( void * ) context->raw_ctx ) >
+                      ( ( void * ) &context->key ) );
 
        /* Reset non-key state */
        memset ( context, 0, offsetof ( typeof ( *context ), key ) );
index 9653a0a1ac096b2a17d8fcb027e928935b29638b..4864445d24ae90a043c9069a93b326be4960dbba 100644 (file)
@@ -89,7 +89,8 @@ static int _gcm_name ## _setkey ( void *ctx, const void *key,         \
                                  size_t keylen ) {                     \
        struct _gcm_name ## _context *context = ctx;                    \
        build_assert ( _blocksize == sizeof ( context->gcm.key ) );     \
-       build_assert ( ( ( void * ) &context->gcm ) == ctx );           \
+       build_assert ( ( ( void * ) &context->gcm ) ==                  \
+                      ( ( void * ) context ) );                        \
        build_assert ( ( ( void * ) &context->raw ) ==                  \
                       ( ( void * ) context->gcm.raw_ctx ) );           \
        return gcm_setkey ( &context->gcm, key, keylen, &_raw_cipher ); \