summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2024-01-16 13:23:02 +0100
committerMichael Brown2024-01-16 14:35:08 +0100
commit6d29415c89d607b988381bc367c9c521694fa728 (patch)
treeab4a300dc7856a6fcbeb8b6f4db002e70d2f4e86
parent[build] Fix building with newer binutils (diff)
downloadipxe-6d29415c89d607b988381bc367c9c521694fa728.tar.gz
ipxe-6d29415c89d607b988381bc367c9c521694fa728.tar.xz
ipxe-6d29415c89d607b988381bc367c9c521694fa728.zip
[libc] Make static_assert() available via assert.h
Expose static_assert() via assert.h and migrate link-time assertions to build-time assertions where possible. Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/drivers/infiniband/arbel.c4
-rw-r--r--src/drivers/infiniband/hermon.c4
-rw-r--r--src/image/script.c3
-rw-r--r--src/include/assert.h9
-rw-r--r--src/net/aoe.c2
5 files changed, 15 insertions, 7 deletions
diff --git a/src/drivers/infiniband/arbel.c b/src/drivers/infiniband/arbel.c
index 293c1b64..24c0b53b 100644
--- a/src/drivers/infiniband/arbel.c
+++ b/src/drivers/infiniband/arbel.c
@@ -545,8 +545,8 @@ static int arbel_mad ( struct ib_device *ibdev, union ib_mad *mad ) {
union arbelprm_mad mad_ifc;
int rc;
- linker_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ),
- mad_size_mismatch );
+ /* Sanity check */
+ static_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ) );
/* Copy in request packet */
memcpy ( &mad_ifc.mad, mad, sizeof ( mad_ifc.mad ) );
diff --git a/src/drivers/infiniband/hermon.c b/src/drivers/infiniband/hermon.c
index c09baf7a..6fc7d8bd 100644
--- a/src/drivers/infiniband/hermon.c
+++ b/src/drivers/infiniband/hermon.c
@@ -779,8 +779,8 @@ static int hermon_mad ( struct ib_device *ibdev, union ib_mad *mad ) {
union hermonprm_mad mad_ifc;
int rc;
- linker_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ),
- mad_size_mismatch );
+ /* Sanity check */
+ static_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ) );
/* Copy in request packet */
memcpy ( &mad_ifc.mad, mad, sizeof ( mad_ifc.mad ) );
diff --git a/src/image/script.c b/src/image/script.c
index 49b35640..9e8566bc 100644
--- a/src/image/script.c
+++ b/src/image/script.c
@@ -219,8 +219,7 @@ static int script_exec ( struct image *image ) {
static int script_probe ( struct image *image ) {
static const char ipxe_magic[] = "#!ipxe";
static const char gpxe_magic[] = "#!gpxe";
- linker_assert ( sizeof ( ipxe_magic ) == sizeof ( gpxe_magic ),
- magic_size_mismatch );
+ static_assert ( sizeof ( ipxe_magic ) == sizeof ( gpxe_magic ) );
char test[ sizeof ( ipxe_magic ) - 1 /* NUL */
+ 1 /* terminating space */];
diff --git a/src/include/assert.h b/src/include/assert.h
index dd71fa71..6d053180 100644
--- a/src/include/assert.h
+++ b/src/include/assert.h
@@ -56,6 +56,15 @@ assert_printf ( const char *fmt, ... ) asm ( "printf" );
} while ( 0 )
/**
+ * Assert a condition at build time
+ *
+ * If the compiler cannot prove that the condition is true, the build
+ * will fail with an error message.
+ */
+#undef static_assert
+#define static_assert(x) _Static_assert( x, #x )
+
+/**
* Assert a condition at link-time.
*
* If the condition is not true, the link will fail with an unresolved
diff --git a/src/net/aoe.c b/src/net/aoe.c
index e785e897..dba4f51b 100644
--- a/src/net/aoe.c
+++ b/src/net/aoe.c
@@ -374,7 +374,7 @@ static void aoecmd_ata_cmd ( struct aoe_command *aoecmd,
struct aoeata *aoeata = &aoehdr->payload[0].ata;
/* Sanity check */
- linker_assert ( AOE_FL_DEV_HEAD == ATA_DEV_SLAVE, __fix_ata_h__ );
+ static_assert ( AOE_FL_DEV_HEAD == ATA_DEV_SLAVE );
assert ( len == ( sizeof ( *aoehdr ) + sizeof ( *aoeata ) +
command->data_out_len ) );