]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Replace assert with eu_static_assert where possible. users/mark/try-static-assert
authorMark Wielaard <mark@klomp.org>
Thu, 5 Mar 2026 15:25:11 +0000 (16:25 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 5 Mar 2026 15:41:41 +0000 (16:41 +0100)
This moves the assert from being checked at runtime to being checked
at compile time.

* libdwfl/dwfl_segment_report_module.c (dwfl_segment_report_module):
Replace asserts with eu_static_assert.
* libdwfl/linux-core-attach.c (core_set_initial_registers):
Likewise.
* libdwfl/linux-kernel-modules.c (check_notes): Likewise.
* libebl/eblopenbackend.c (openbackend): Likewise.
* libelf/elf_begin.c (file_read_elf): Likewise.
(write_file): Likewise.
* libelf/elf_clone.c (elf_clone): Likewise.
* libelf/elf_getshdrstrndx.c (elf_getshdrstrndx): Likewise.
* libelf/elf_newscn.c (elf_newscn): Likewise.
* libelf/gelf_getauxv.c (gelf_getauxv): Likewise.
* libelf/gelf_getdyn.c (gelf_getdyn): Likewise.
* libelf/gelf_getlib.c (gelf_getlib): Likewise.
* libelf/gelf_getsym.c (gelf_getsym): Likewise.
* libelf/gelf_getsyminfo.c (gelf_getsyminfo): Likewise.
* libelf/gelf_getsymshndx.c (gelf_getsymshndx): Likewise.
* libelf/gelf_getverdaux.c (gelf_getverdaux): Likewise.
* libelf/gelf_getverdef.c (gelf_getverdef): Likewise.
* libelf/gelf_getvernaux.c (gelf_getvernaux): Likewise.
* libelf/gelf_getverneed.c (gelf_getverneed): Likewise.
* libelf/gelf_getversym.c (gelf_getversym): Likewise.
* libelf/gelf_update_syminfo.c (gelf_update_syminfo): Likewise.
* libelf/gelf_update_verdaux.c (gelf_update_verdaux): Likewise.
* libelf/gelf_update_verdef.c (gelf_update_verdef): Likewise.
* libelf/gelf_update_vernaux.c (gelf_update_vernaux): Likewise.
* libelf/gelf_update_verneed.c (gelf_update_verneed): Likewise.
* libelf/gelf_update_versym.c (gelf_update_versym): Likewise.
* libelf/note_xlate.h (elf_cvt_note): Likewise.
* libelf/version_xlate.h (elf_cvt_Verdef): Likewise.
(elf_cvt_Verneed): Likewise.
* src/arlib.c (arlib_init): Likewise.
(arlib_add_symref): Likewise.
* src/strip.c (handle_elf): Likewise.
* src/unstrip.c (adjust_relocs): Likewise.

Signed-off-by: Mark Wielaard <mark@klomp.org>
31 files changed:
libdwfl/dwfl_segment_report_module.c
libdwfl/linux-core-attach.c
libdwfl/linux-kernel-modules.c
libebl/eblopenbackend.c
libelf/elf_begin.c
libelf/elf_clone.c
libelf/elf_getshdrstrndx.c
libelf/elf_newscn.c
libelf/gelf_getauxv.c
libelf/gelf_getdyn.c
libelf/gelf_getlib.c
libelf/gelf_getsym.c
libelf/gelf_getsyminfo.c
libelf/gelf_getsymshndx.c
libelf/gelf_getverdaux.c
libelf/gelf_getverdef.c
libelf/gelf_getvernaux.c
libelf/gelf_getverneed.c
libelf/gelf_getversym.c
libelf/gelf_update_syminfo.c
libelf/gelf_update_verdaux.c
libelf/gelf_update_verdef.c
libelf/gelf_update_vernaux.c
libelf/gelf_update_verneed.c
libelf/gelf_update_versym.c
libelf/gnuhash_xlate.h
libelf/note_xlate.h
libelf/version_xlate.h
src/arlib.c
src/strip.c
src/unstrip.c

index f2f866c2c70f4ef88a694165ee5ee61602a20f40..8a485c0626723a3e78a964de161b29ab3afd59f0 100644 (file)
@@ -537,7 +537,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
              if (filesz > SIZE_MAX / sizeof (Elf32_Nhdr))
                continue;
 
-              assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
+              eu_static_assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
 
               void *notes;
               if (ei_data == MY_ELFDATA
index 75e3c2198873fe7af179d8f3e1e328b0a49bf482..509e92b7c5e08394961b85dcae9950c5768026e3 100644 (file)
@@ -275,7 +275,7 @@ core_set_initial_registers (Dwfl_Thread *thread, void *thread_arg_voidp)
              reg_desc += sizeof val64;
              val64 = (elf_getident (core, NULL)[EI_DATA] == ELFDATA2MSB
                       ? be64toh (val64) : le64toh (val64));
-             assert (sizeof (*thread->unwound->regs) == sizeof val64);
+             eu_static_assert (sizeof (*thread->unwound->regs) == sizeof val64);
              val = val64;
              break;
            default:
index e9faba26a720d56161e8ae76403d3c6cb769adea..dac64b3405c4f9d38db46ee4d7af71eac8875747 100644 (file)
@@ -577,8 +577,8 @@ check_notes (Dwfl_Module *mod, const char *notesfile,
   if (fd < 0)
     return 1;
 
-  assert (sizeof (Elf32_Nhdr) == sizeof (GElf_Nhdr));
-  assert (sizeof (Elf64_Nhdr) == sizeof (GElf_Nhdr));
+  eu_static_assert (sizeof (Elf32_Nhdr) == sizeof (GElf_Nhdr));
+  eu_static_assert (sizeof (Elf64_Nhdr) == sizeof (GElf_Nhdr));
   union
   {
     GElf_Nhdr nhdr;
index b68dea7a08092c039ec5ed0dd9bbd34141ffb323..dbe4b94741d5e96d4c4a777e6c0741916740f84a 100644 (file)
@@ -311,12 +311,12 @@ openbackend (Elf *elf, const char *emulation, GElf_Half machine)
 
        /* We access some data structures directly.  Make sure the 32 and
           64 bit variants are laid out the same.  */
-       assert (offsetof (Elf32_Ehdr, e_machine)
-               == offsetof (Elf64_Ehdr, e_machine));
-       assert (sizeof (((Elf32_Ehdr *) 0)->e_machine)
-               == sizeof (((Elf64_Ehdr *) 0)->e_machine));
-       assert (offsetof (Elf, state.elf32.ehdr)
-               == offsetof (Elf, state.elf64.ehdr));
+       eu_static_assert (offsetof (Elf32_Ehdr, e_machine)
+                         == offsetof (Elf64_Ehdr, e_machine));
+       eu_static_assert (sizeof (((Elf32_Ehdr *) 0)->e_machine)
+                         == sizeof (((Elf64_Ehdr *) 0)->e_machine));
+       eu_static_assert (offsetof (Elf, state.elf32.ehdr)
+                         == offsetof (Elf, state.elf64.ehdr));
 
        /* Prefer taking the information from the ELF file.  */
        if (elf == NULL)
index d22f107dd5a0ff1d95f59b4d800b0e28c5db30d6..0c9b95ddc2b101837216c35f4e233e461e553441 100644 (file)
@@ -327,8 +327,8 @@ file_read_elf (int fildes, void *map_address, unsigned char *e_ident,
     return NULL;
 
   assert ((unsigned int) scncnt == scncnt);
-  assert (offsetof (struct Elf, state.elf32.scns)
-         == offsetof (struct Elf, state.elf64.scns));
+  eu_static_assert (offsetof (struct Elf, state.elf32.scns)
+                   == offsetof (struct Elf, state.elf64.scns));
   elf->state.elf32.scns.cnt = scncnt;
   elf->state.elf32.scns.max = scnmax;
 
@@ -1159,8 +1159,8 @@ write_file (int fd, Elf_Cmd cmd)
       result->state.elf.scnincr = NSCNSALLOC;
 
       /* We have allocated room for some sections.  */
-      assert (offsetof (struct Elf, state.elf32.scns)
-             == offsetof (struct Elf, state.elf64.scns));
+      eu_static_assert (offsetof (struct Elf, state.elf32.scns)
+                       == offsetof (struct Elf, state.elf64.scns));
       result->state.elf.scns_last = &result->state.elf32.scns;
       result->state.elf32.scns.max = NSCNSALLOC;
     }
index e6fe4729e68f3a6ca1a26d1875ed77a6058676c8..ff96fc2156b818089dfabf57945e177774e5532d 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <stddef.h>
 #include "libelfP.h"
 #include "common.h"
@@ -65,8 +64,8 @@ elf_clone (Elf *elf, Elf_Cmd cmd)
       retval->state.elf.scnincr = 10;
 
       /* We have allocated room for some sections.  */
-      assert (offsetof (struct Elf, state.elf32.scns)
-             == offsetof (struct Elf, state.elf64.scns));
+      eu_static_assert (offsetof (struct Elf, state.elf32.scns)
+                       == offsetof (struct Elf, state.elf64.scns));
       retval->state.elf.scns_last = &retval->state.elf32.scns;
       retval->state.elf32.scns.max = elf->state.elf32.scns.max;
 
index 2391317bffe0c4e1c45e603c6d90d16eb70946f9..af9c3a1479fd122f0f8378dc12c24e06444ca1bf 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <errno.h>
 #include <gelf.h>
 #include <stddef.h>
@@ -58,14 +57,14 @@ elf_getshdrstrndx (Elf *elf, size_t *dst)
 
   /* We rely here on the fact that the `elf' element is a common prefix
      of `elf32' and `elf64'.  */
-  assert (offsetof (struct Elf, state.elf.ehdr)
-         == offsetof (struct Elf, state.elf32.ehdr));
-  assert (sizeof (elf->state.elf.ehdr)
-         == sizeof (elf->state.elf32.ehdr));
-  assert (offsetof (struct Elf, state.elf.ehdr)
-         == offsetof (struct Elf, state.elf64.ehdr));
-  assert (sizeof (elf->state.elf.ehdr)
-         == sizeof (elf->state.elf64.ehdr));
+  eu_static_assert (offsetof (struct Elf, state.elf.ehdr)
+                   == offsetof (struct Elf, state.elf32.ehdr));
+  eu_static_assert (sizeof (elf->state.elf.ehdr)
+                   == sizeof (elf->state.elf32.ehdr));
+  eu_static_assert (offsetof (struct Elf, state.elf.ehdr)
+                   == offsetof (struct Elf, state.elf64.ehdr));
+  eu_static_assert (sizeof (elf->state.elf.ehdr)
+                   == sizeof (elf->state.elf64.ehdr));
 
   if (unlikely (elf->state.elf.ehdr == NULL))
     {
index ec731f759de4772071f921eeff0270671dbc3862..f7b20ab7cb2d9dd26092e394252af19393f4653f 100644 (file)
@@ -51,12 +51,12 @@ elf_newscn (Elf *elf)
 
   /* We rely on the prefix of the `elf', `elf32', and `elf64' element
      being the same.  */
-  assert (offsetof (Elf, state.elf.scns_last)
-         == offsetof (Elf, state.elf32.scns_last));
-  assert (offsetof (Elf, state.elf.scns_last)
-         == offsetof (Elf, state.elf64.scns_last));
-  assert (offsetof (Elf, state.elf32.scns)
-         == offsetof (Elf, state.elf64.scns));
+  eu_static_assert (offsetof (Elf, state.elf.scns_last)
+                   == offsetof (Elf, state.elf32.scns_last));
+  eu_static_assert (offsetof (Elf, state.elf.scns_last)
+                   == offsetof (Elf, state.elf64.scns_last));
+  eu_static_assert (offsetof (Elf, state.elf32.scns)
+                   == offsetof (Elf, state.elf64.scns));
 
   rwlock_wrlock (elf->lock);
 
index 1591be2a5686a0ea7d57b1a8516b2e1bfc8a9bee..405ec6465c83c0449a62f571a52dcce8cacc997a 100644 (file)
@@ -30,7 +30,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -84,7 +83,7 @@ gelf_getauxv (Elf_Data *data, int ndx, GElf_auxv_t *dst)
   else
     {
       /* If this is a 64 bit object it's easy.  */
-      assert (sizeof (GElf_auxv_t) == sizeof (Elf64_auxv_t));
+      eu_static_assert (sizeof (GElf_auxv_t) == sizeof (Elf64_auxv_t));
 
       /* The data is already in the correct form.  Just make sure the
         index is OK.  */
index a0090e147d54e708ed2ea496d54cfb6cfa121ce2..32e75f9a888e67ff6114ef328b4d75d8b55c24ad 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -86,7 +85,7 @@ gelf_getdyn (Elf_Data *data, int ndx, GElf_Dyn *dst)
   else
     {
       /* If this is a 64 bit object it's easy.  */
-      assert (sizeof (GElf_Dyn) == sizeof (Elf64_Dyn));
+      eu_static_assert (sizeof (GElf_Dyn) == sizeof (Elf64_Dyn));
 
       /* The data is already in the correct form.  Just make sure the
         index is OK.  */
index a8ac47850c5b61858fa04d40fa6859621e497474..9a6c24165ece14acc2bb4df3f3f0d722b57a7812 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -56,8 +55,8 @@ gelf_getlib (Elf_Data *data, int ndx, GElf_Lib *dst)
 
   /* The on disk format of Elf32_Lib and Elf64_Lib is identical.  So
      we can simplify things significantly.  */
-  assert (sizeof (GElf_Lib) == sizeof (Elf32_Lib));
-  assert (sizeof (GElf_Lib) == sizeof (Elf64_Lib));
+  eu_static_assert (sizeof (GElf_Lib) == sizeof (Elf32_Lib));
+  eu_static_assert (sizeof (GElf_Lib) == sizeof (Elf64_Lib));
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
index 01534d2ce8fd7bf15a5554c4b195eb957d8a79cf..bc1e7b56bdc50c4bf63be304826d185dd60e3e49 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -91,7 +90,7 @@ gelf_getsym (Elf_Data *data, int ndx, GElf_Sym *dst)
   else
     {
       /* If this is a 64 bit object it's easy.  */
-      assert (sizeof (GElf_Sym) == sizeof (Elf64_Sym));
+      eu_static_assert (sizeof (GElf_Sym) == sizeof (Elf64_Sym));
 
       /* The data is already in the correct form.  Just make sure the
         index is OK.  */
index 8360ed387ad0ec81c5fe3e95247e1c509b0e27e6..d1ec9e7942c9e5dcff09ddc3a6ff74219a5b96d1 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -53,8 +52,8 @@ gelf_getsyminfo (Elf_Data *data, int ndx, GElf_Syminfo *dst)
     }
 
   /* The types for 32 and 64 bit are the same.  Lucky us.  */
-  assert (sizeof (GElf_Syminfo) == sizeof (Elf32_Syminfo));
-  assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
+  eu_static_assert (sizeof (GElf_Syminfo) == sizeof (Elf32_Syminfo));
+  eu_static_assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
 
   rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
 
index 17c90fc6d0825b6c82feb72e80a0b6f556b42702..534502e34f7a23afaf0f675ae62cd9e7e038f7fa 100644 (file)
@@ -32,7 +32,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -110,7 +109,7 @@ gelf_getsymshndx (Elf_Data *symdata, Elf_Data *shndxdata, int ndx,
   else
     {
       /* If this is a 64 bit object it's easy.  */
-      assert (sizeof (GElf_Sym) == sizeof (Elf64_Sym));
+      eu_static_assert (sizeof (GElf_Sym) == sizeof (Elf64_Sym));
 
       /* The data is already in the correct form.  Just make sure the
         index is OK.  */
index 739a7657d8507190af67fa8d236d8d4135ad0bdb..099c6612f5adcf8669553333ff06f17c46b56d93 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -54,8 +53,8 @@ gelf_getverdaux (Elf_Data *data, int offset, GElf_Verdaux *dst)
 
   /* It's easy to handle this type.  It has the same size for 32 and
      64 bit objects.  */
-  assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
-  assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
+  eu_static_assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
+  eu_static_assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
 
   rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
 
index 651f4fadc1cba5fd6c8fb2de543aabfb14b3496b..85be7caf4fa37a26b9cc00bba7766de2a3e862f6 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -54,8 +53,8 @@ gelf_getverdef (Elf_Data *data, int offset, GElf_Verdef *dst)
 
   /* It's easy to handle this type.  It has the same size for 32 and
      64 bit objects.  */
-  assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
-  assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
+  eu_static_assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
+  eu_static_assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
 
   rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
 
index e47fb0a227531a09a743b6e2fc1cb19d0c1ea3ee..234543367606d8fa6826ba99eebf28f8f0e5680e 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -55,10 +54,10 @@ gelf_getvernaux (Elf_Data *data, int offset, GElf_Vernaux *dst)
   /* It's easy to handle this type.  It has the same size for 32 and
      64 bit objects.  And fortunately the `ElfXXX_Vernaux' records
      also have the same size.  */
-  assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Verneed));
-  assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Verneed));
-  assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
-  assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
+  eu_static_assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Verneed));
+  eu_static_assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Verneed));
+  eu_static_assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
+  eu_static_assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
 
   rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
 
index c1f5d3409fcaf91c514a7dc7f6f19017ee4ee845..ff3743ea34510b4a921377bf77c0cce47daa4786 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -55,10 +54,10 @@ gelf_getverneed (Elf_Data *data, int offset, GElf_Verneed *dst)
   /* It's easy to handle this type.  It has the same size for 32 and
      64 bit objects.  And fortunately the `ElfXXX_Vernaux' records
      also have the same size.  */
-  assert (sizeof (GElf_Verneed) == sizeof (Elf32_Verneed));
-  assert (sizeof (GElf_Verneed) == sizeof (Elf64_Verneed));
-  assert (sizeof (GElf_Verneed) == sizeof (Elf32_Vernaux));
-  assert (sizeof (GElf_Verneed) == sizeof (Elf64_Vernaux));
+  eu_static_assert (sizeof (GElf_Verneed) == sizeof (Elf32_Verneed));
+  eu_static_assert (sizeof (GElf_Verneed) == sizeof (Elf64_Verneed));
+  eu_static_assert (sizeof (GElf_Verneed) == sizeof (Elf32_Vernaux));
+  eu_static_assert (sizeof (GElf_Verneed) == sizeof (Elf64_Vernaux));
 
   rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
 
index 68d23c72e9d13f8651dd26f65118766658db5082..aa2c0a0904e1ffafc22aeeda778578b173509d96 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -61,8 +60,8 @@ gelf_getversym (Elf_Data *data, int ndx, GElf_Versym *dst)
 
   /* It's easy to handle this type.  It has the same size for 32 and
      64 bit objects.  */
-  assert (sizeof (GElf_Versym) == sizeof (Elf32_Versym));
-  assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
+  eu_static_assert (sizeof (GElf_Versym) == sizeof (Elf32_Versym));
+  eu_static_assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
 
   rwlock_rdlock (scn->elf->lock);
 
index 6f7f30255a4fb4cab4af790e8c39da1b970a1d68..a471e42983a93ea111bfe998318035888c0ee382 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <stdlib.h>
 
@@ -56,8 +55,8 @@ gelf_update_syminfo (Elf_Data *data, int ndx, GElf_Syminfo *src)
     }
 
   /* The types for 32 and 64 bit are the same.  Lucky us.  */
-  assert (sizeof (GElf_Syminfo) == sizeof (Elf32_Syminfo));
-  assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
+  eu_static_assert (sizeof (GElf_Syminfo) == sizeof (Elf32_Syminfo));
+  eu_static_assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
 
   scn = data_scn->s;
   rwlock_wrlock (scn->elf->lock);
index f3554fdcb6e464737af2b35783abaf654030c814..9f4a43fad275f9c069680c946b0d4309752ef810 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -47,8 +46,8 @@ gelf_update_verdaux (Elf_Data *data, int offset, GElf_Verdaux *src)
     return 0;
 
   /* The types for 32 and 64 bit are the same.  Lucky us.  */
-  assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
-  assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
+  eu_static_assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
+  eu_static_assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
 
   /* Check whether we have to resize the data buffer.  */
   if (unlikely (offset < 0)
index adb5db146a7a780da36a787daf4b99374faf214b..bd224bdba6f4341e98c3b2e94daa9a615b96b6b1 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -47,8 +46,8 @@ gelf_update_verdef (Elf_Data *data, int offset, GElf_Verdef *src)
     return 0;
 
   /* The types for 32 and 64 bit are the same.  Lucky us.  */
-  assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
-  assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
+  eu_static_assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
+  eu_static_assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
 
   /* Check whether we have to resize the data buffer.  */
   if (unlikely (offset < 0)
index 854afabbca4595f3661799ec6f4fdcac533dc6f8..f60429a65b88ff61080fec915e662207da7eb7e5 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -47,8 +46,8 @@ gelf_update_vernaux (Elf_Data *data, int offset, GElf_Vernaux *src)
     return 0;
 
   /* The types for 32 and 64 bit are the same.  Lucky us.  */
-  assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
-  assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
+  eu_static_assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
+  eu_static_assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
 
   /* Check whether we have to resize the data buffer.  */
   if (unlikely (offset < 0)
index bf5af5a305683dae79ece2c0bc005640891238f2..43338a8f76d8a9cd906d0b74d419f6a2cab24069 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <string.h>
 
@@ -47,8 +46,8 @@ gelf_update_verneed (Elf_Data *data, int offset, GElf_Verneed *src)
     return 0;
 
   /* The types for 32 and 64 bit are the same.  Lucky us.  */
-  assert (sizeof (GElf_Verneed) == sizeof (Elf32_Verneed));
-  assert (sizeof (GElf_Verneed) == sizeof (Elf64_Verneed));
+  eu_static_assert (sizeof (GElf_Verneed) == sizeof (Elf32_Verneed));
+  eu_static_assert (sizeof (GElf_Verneed) == sizeof (Elf64_Verneed));
 
   /* Check whether we have to resize the data buffer.  */
   if (unlikely (offset < 0)
index 9949dffb03e085b47fa52087cfc3e0557c9285e9..5dc46222e930afc66d979fb33747352ddb68256f 100644 (file)
@@ -31,7 +31,6 @@
 # include <config.h>
 #endif
 
-#include <assert.h>
 #include <gelf.h>
 #include <stdlib.h>
 
@@ -47,8 +46,8 @@ gelf_update_versym (Elf_Data *data, int ndx, GElf_Versym *src)
     return 0;
 
   /* The types for 32 and 64 bit are the same.  Lucky us.  */
-  assert (sizeof (GElf_Versym) == sizeof (Elf32_Versym));
-  assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
+  eu_static_assert (sizeof (GElf_Versym) == sizeof (Elf32_Versym));
+  eu_static_assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
 
   /* Check whether we have to resize the data buffer.  */
   if (INVALID_NDX (ndx, GElf_Versym, &data_scn->d))
index 3a00ae0ae18b40bf155bb3733470d45d6bc3d32b..cf9d4b57b05375e0134750f154d485f2c8474cb2 100644 (file)
@@ -28,7 +28,6 @@
    the GNU Lesser General Public License along with this program.  If
    not, see <http://www.gnu.org/licenses/>.  */
 
-#include <assert.h>
 #include <gelf.h>
 
 #include "libelfP.h"
index 7e2784b0587fcaca63786aadfce2f5c260c2037c..dc3a35652157ff6e298a3947ee1c077be4579f9f 100644 (file)
@@ -32,7 +32,7 @@ elf_cvt_note (void *dest, const void *src, size_t len, int encode,
 {
   /* Note that the header is always the same size, but the padding
      differs for GNU Property notes.  */
-  assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
+  eu_static_assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
 
   while (len >= sizeof (Elf32_Nhdr))
     {
index 97f3b7303e165a8e40dd792cb4403d7ff5b918e6..f44cb0cef8c25376fb1f4852c90f7f7f346b9f68 100644 (file)
@@ -28,7 +28,6 @@
    the GNU Lesser General Public License along with this program.  If
    not, see <http://www.gnu.org/licenses/>.  */
 
-#include <assert.h>
 #include <gelf.h>
 
 #include "libelfP.h"
@@ -48,10 +47,10 @@ elf_cvt_Verdef (void *dest, const void *src, size_t len, int encode)
   GElf_Verdef *dsrc;
 
   /* We rely on the types being all the same size.  */
-  assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
-  assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
-  assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
-  assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
+  eu_static_assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
+  eu_static_assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
+  eu_static_assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
+  eu_static_assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
 
   if (len == 0)
     return;
@@ -171,10 +170,10 @@ elf_cvt_Verneed (void *dest, const void *src, size_t len, int encode)
   GElf_Verneed *nsrc;
 
   /* We rely on the types being all the same size.  */
-  assert (sizeof (GElf_Verneed) == sizeof (Elf32_Verneed));
-  assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
-  assert (sizeof (GElf_Verneed) == sizeof (Elf64_Verneed));
-  assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
+  eu_static_assert (sizeof (GElf_Verneed) == sizeof (Elf32_Verneed));
+  eu_static_assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
+  eu_static_assert (sizeof (GElf_Verneed) == sizeof (Elf64_Verneed));
+  eu_static_assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
 
   if (len == 0)
     return;
index b8f89ba7df8751f1ddbff8ac7a85833dff45cc3f..80344389da36e5420c261dd2f11ebba20ccc2d5b 100644 (file)
@@ -64,7 +64,7 @@ arlib_init (void)
                     (arlib_deterministic_output ? 0
                      : (long long int) time (NULL)));
   memcpy (ar_hdr.ar_date, tmpbuf, s);
-  assert ((sizeof (struct ar_hdr)  % sizeof (uint32_t)) == 0);
+  eu_static_assert ((sizeof (struct ar_hdr) % sizeof (uint32_t)) == 0);
 
   /* Note the string for the ar_uid and ar_gid cases is longer than
      necessary.  This does not matter since we copy only as much as
@@ -81,7 +81,7 @@ arlib_init (void)
   /* The first word in the offset table specifies the size.  Create
      such an entry now.  The real value will be filled-in later.  For
      all supported platforms the following is true.  */
-  assert (sizeof (uint32_t) == sizeof (int));
+  eu_static_assert (sizeof (uint32_t) == sizeof (int));
   obstack_int_grow (&symtab.symsoffob, 0);
 
   /* The long name obstack also gets its archive header.  As above,
@@ -194,7 +194,7 @@ void
 arlib_add_symref (const char *symname, off_t symoff)
 {
   /* For all supported platforms the following is true.  */
-  assert (sizeof (uint32_t) == sizeof (int));
+  eu_static_assert (sizeof (uint32_t) == sizeof (int));
   obstack_int_grow (&symtab.symsoffob, (int) le_bswap_32 (symoff));
 
   size_t symname_len = strlen (symname) + 1;
index 8d2bb7a959f0c2066e5afae8c4017e455ee30053..20cc8a22e9aec1d97b05d60a4406eebe00fb4c3e 100644 (file)
@@ -2600,10 +2600,12 @@ while computing checksum for debug information"));
 
       if (newehdr->e_ident[EI_CLASS] == ELFCLASS32)
        {
-         assert (offsetof (Elf32_Ehdr, e_shentsize) + sizeof (Elf32_Half)
-                 == offsetof (Elf32_Ehdr, e_shnum));
-         assert (offsetof (Elf32_Ehdr, e_shnum) + sizeof (Elf32_Half)
-                 == offsetof (Elf32_Ehdr, e_shstrndx));
+         eu_static_assert (offsetof (Elf32_Ehdr, e_shentsize)
+                           + sizeof (Elf32_Half)
+                           == offsetof (Elf32_Ehdr, e_shnum));
+         eu_static_assert (offsetof (Elf32_Ehdr, e_shnum)
+                           + sizeof (Elf32_Half)
+                           == offsetof (Elf32_Ehdr, e_shstrndx));
          const Elf32_Off zero_off = 0;
          const Elf32_Half zero[3] = { 0, 0, SHN_UNDEF };
          if (pwrite_retry (fd, &zero_off, sizeof zero_off,
@@ -2620,10 +2622,12 @@ while computing checksum for debug information"));
        }
       else
        {
-         assert (offsetof (Elf64_Ehdr, e_shentsize) + sizeof (Elf64_Half)
-                 == offsetof (Elf64_Ehdr, e_shnum));
-         assert (offsetof (Elf64_Ehdr, e_shnum) + sizeof (Elf64_Half)
-                 == offsetof (Elf64_Ehdr, e_shstrndx));
+         eu_static_assert (offsetof (Elf64_Ehdr, e_shentsize)
+                           + sizeof (Elf64_Half)
+                           == offsetof (Elf64_Ehdr, e_shnum));
+         eu_static_assert (offsetof (Elf64_Ehdr, e_shnum)
+                           +sizeof (Elf64_Half)
+                           == offsetof (Elf64_Ehdr, e_shstrndx));
          const Elf64_Off zero_off = 0;
          const Elf64_Half zero[3] = { 0, 0, SHN_UNDEF };
          if (pwrite_retry (fd, &zero_off, sizeof zero_off,
index 6c2a98ef96f25dd6a49e90f8f29665261d6f4cf7..5585b0e251017822054dece95a00b4c659574323 100644 (file)
@@ -570,8 +570,8 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr,
 
        /* We don't bother using gelf_update_versym because there is
           really no conversion to be done.  */
-       assert (sizeof (Elf32_Versym) == sizeof (GElf_Versym));
-       assert (sizeof (Elf64_Versym) == sizeof (GElf_Versym));
+       eu_static_assert (sizeof (Elf32_Versym) == sizeof (GElf_Versym));
+       eu_static_assert (sizeof (Elf64_Versym) == sizeof (GElf_Versym));
        GElf_Versym *versym = xcalloc (nent, sizeof versym[0]);
 
        for (size_t i = 1; i < onent; ++i)