From: Mark Wielaard Date: Thu, 5 Mar 2026 15:25:11 +0000 (+0100) Subject: Replace assert with eu_static_assert where possible. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fusers%2Fmark%2Ftry-static-assert;p=thirdparty%2Felfutils.git Replace assert with eu_static_assert where possible. 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 --- diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index f2f866c2..8a485c06 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -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 diff --git a/libdwfl/linux-core-attach.c b/libdwfl/linux-core-attach.c index 75e3c219..509e92b7 100644 --- a/libdwfl/linux-core-attach.c +++ b/libdwfl/linux-core-attach.c @@ -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: diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index e9faba26..dac64b34 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -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; diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c index b68dea7a..dbe4b947 100644 --- a/libebl/eblopenbackend.c +++ b/libebl/eblopenbackend.c @@ -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) diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c index d22f107d..0c9b95dd 100644 --- a/libelf/elf_begin.c +++ b/libelf/elf_begin.c @@ -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; } diff --git a/libelf/elf_clone.c b/libelf/elf_clone.c index e6fe4729..ff96fc21 100644 --- a/libelf/elf_clone.c +++ b/libelf/elf_clone.c @@ -31,7 +31,6 @@ # include #endif -#include #include #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; diff --git a/libelf/elf_getshdrstrndx.c b/libelf/elf_getshdrstrndx.c index 2391317b..af9c3a14 100644 --- a/libelf/elf_getshdrstrndx.c +++ b/libelf/elf_getshdrstrndx.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include #include @@ -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)) { diff --git a/libelf/elf_newscn.c b/libelf/elf_newscn.c index ec731f75..f7b20ab7 100644 --- a/libelf/elf_newscn.c +++ b/libelf/elf_newscn.c @@ -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); diff --git a/libelf/gelf_getauxv.c b/libelf/gelf_getauxv.c index 1591be2a..405ec646 100644 --- a/libelf/gelf_getauxv.c +++ b/libelf/gelf_getauxv.c @@ -30,7 +30,6 @@ # include #endif -#include #include #include @@ -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. */ diff --git a/libelf/gelf_getdyn.c b/libelf/gelf_getdyn.c index a0090e14..32e75f9a 100644 --- a/libelf/gelf_getdyn.c +++ b/libelf/gelf_getdyn.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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. */ diff --git a/libelf/gelf_getlib.c b/libelf/gelf_getlib.c index a8ac4785..9a6c2416 100644 --- a/libelf/gelf_getlib.c +++ b/libelf/gelf_getlib.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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. */ diff --git a/libelf/gelf_getsym.c b/libelf/gelf_getsym.c index 01534d2c..bc1e7b56 100644 --- a/libelf/gelf_getsym.c +++ b/libelf/gelf_getsym.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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. */ diff --git a/libelf/gelf_getsyminfo.c b/libelf/gelf_getsyminfo.c index 8360ed38..d1ec9e79 100644 --- a/libelf/gelf_getsyminfo.c +++ b/libelf/gelf_getsyminfo.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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); diff --git a/libelf/gelf_getsymshndx.c b/libelf/gelf_getsymshndx.c index 17c90fc6..534502e3 100644 --- a/libelf/gelf_getsymshndx.c +++ b/libelf/gelf_getsymshndx.c @@ -32,7 +32,6 @@ # include #endif -#include #include #include @@ -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. */ diff --git a/libelf/gelf_getverdaux.c b/libelf/gelf_getverdaux.c index 739a7657..099c6612 100644 --- a/libelf/gelf_getverdaux.c +++ b/libelf/gelf_getverdaux.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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); diff --git a/libelf/gelf_getverdef.c b/libelf/gelf_getverdef.c index 651f4fad..85be7caf 100644 --- a/libelf/gelf_getverdef.c +++ b/libelf/gelf_getverdef.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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); diff --git a/libelf/gelf_getvernaux.c b/libelf/gelf_getvernaux.c index e47fb0a2..23454336 100644 --- a/libelf/gelf_getvernaux.c +++ b/libelf/gelf_getvernaux.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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); diff --git a/libelf/gelf_getverneed.c b/libelf/gelf_getverneed.c index c1f5d340..ff3743ea 100644 --- a/libelf/gelf_getverneed.c +++ b/libelf/gelf_getverneed.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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); diff --git a/libelf/gelf_getversym.c b/libelf/gelf_getversym.c index 68d23c72..aa2c0a09 100644 --- a/libelf/gelf_getversym.c +++ b/libelf/gelf_getversym.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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); diff --git a/libelf/gelf_update_syminfo.c b/libelf/gelf_update_syminfo.c index 6f7f3025..a471e429 100644 --- a/libelf/gelf_update_syminfo.c +++ b/libelf/gelf_update_syminfo.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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); diff --git a/libelf/gelf_update_verdaux.c b/libelf/gelf_update_verdaux.c index f3554fdc..9f4a43fa 100644 --- a/libelf/gelf_update_verdaux.c +++ b/libelf/gelf_update_verdaux.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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) diff --git a/libelf/gelf_update_verdef.c b/libelf/gelf_update_verdef.c index adb5db14..bd224bdb 100644 --- a/libelf/gelf_update_verdef.c +++ b/libelf/gelf_update_verdef.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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) diff --git a/libelf/gelf_update_vernaux.c b/libelf/gelf_update_vernaux.c index 854afabb..f60429a6 100644 --- a/libelf/gelf_update_vernaux.c +++ b/libelf/gelf_update_vernaux.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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) diff --git a/libelf/gelf_update_verneed.c b/libelf/gelf_update_verneed.c index bf5af5a3..43338a8f 100644 --- a/libelf/gelf_update_verneed.c +++ b/libelf/gelf_update_verneed.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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) diff --git a/libelf/gelf_update_versym.c b/libelf/gelf_update_versym.c index 9949dffb..5dc46222 100644 --- a/libelf/gelf_update_versym.c +++ b/libelf/gelf_update_versym.c @@ -31,7 +31,6 @@ # include #endif -#include #include #include @@ -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)) diff --git a/libelf/gnuhash_xlate.h b/libelf/gnuhash_xlate.h index 3a00ae0a..cf9d4b57 100644 --- a/libelf/gnuhash_xlate.h +++ b/libelf/gnuhash_xlate.h @@ -28,7 +28,6 @@ the GNU Lesser General Public License along with this program. If not, see . */ -#include #include #include "libelfP.h" diff --git a/libelf/note_xlate.h b/libelf/note_xlate.h index 7e2784b0..dc3a3565 100644 --- a/libelf/note_xlate.h +++ b/libelf/note_xlate.h @@ -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)) { diff --git a/libelf/version_xlate.h b/libelf/version_xlate.h index 97f3b730..f44cb0ce 100644 --- a/libelf/version_xlate.h +++ b/libelf/version_xlate.h @@ -28,7 +28,6 @@ the GNU Lesser General Public License along with this program. If not, see . */ -#include #include #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; diff --git a/src/arlib.c b/src/arlib.c index b8f89ba7..80344389 100644 --- a/src/arlib.c +++ b/src/arlib.c @@ -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; diff --git a/src/strip.c b/src/strip.c index 8d2bb7a9..20cc8a22 100644 --- a/src/strip.c +++ b/src/strip.c @@ -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, diff --git a/src/unstrip.c b/src/unstrip.c index 6c2a98ef..5585b0e2 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -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)