]> git.ipfire.org Git - thirdparty/ipxe.git/commit
[libc] Replace linker_assert() with build_assert()
authorMichael Brown <mcb30@ipxe.org>
Tue, 16 Jan 2024 13:24:29 +0000 (13:24 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 16 Jan 2024 13:35:08 +0000 (13:35 +0000)
commit4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c
tree9ee6e4fab3807cea2b6b4c5fa8f1984510e6107a
parent6d29415c89d607b988381bc367c9c521694fa728
[libc] Replace linker_assert() with build_assert()

We currently implement build-time assertions via a mechanism that
generates a call to an undefined external function that will cause the
link to fail unless the compiler can prove that the asserted condition
is true (and thereby eliminate the undefined function call).

This assertion mechanism can be used for conditions that are not
amenable to the use of static_assert(), since static_assert() will not
allow for proofs via dead code elimination.

Add __attribute__((error(...))) to the undefined external function, so
that the error is raised at compile time rather than at link time.
This allows us to provide a more meaningful error message (which will
include the file name and line number, as with any other compile-time
error), and avoids the need for the caller to specify a unique symbol
name for the external function.

Change the name from linker_assert() to build_assert(), since the
assertion now takes place at compile time rather than at link time.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
12 files changed:
src/crypto/gcm.c
src/crypto/md4.c
src/crypto/md5.c
src/crypto/sha1.c
src/crypto/sha256.c
src/crypto/sha512.c
src/drivers/infiniband/linda.c
src/drivers/infiniband/qib7322.c
src/include/assert.h
src/include/ipxe/asn1.h
src/include/ipxe/entropy.h
src/include/ipxe/gcm.h