aboutsummaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2024-01-16 13:24:29 +0000
committerMichael Brown <mcb30@ipxe.org>2024-01-16 13:35:08 +0000
commit4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c (patch)
tree9ee6e4fab3807cea2b6b4c5fa8f1984510e6107a /src/drivers
parent6d29415c89d607b988381bc367c9c521694fa728 (diff)
downloadipxe-4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c.zip
ipxe-4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c.tar.gz
ipxe-4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c.tar.bz2
[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>
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/infiniband/linda.c4
-rw-r--r--src/drivers/infiniband/qib7322.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/drivers/infiniband/linda.c b/src/drivers/infiniband/linda.c
index 8c59126..0c8a043 100644
--- a/src/drivers/infiniband/linda.c
+++ b/src/drivers/infiniband/linda.c
@@ -721,7 +721,7 @@ static int linda_init_recv ( struct linda *linda ) {
eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_17CTX_OTHER;
break;
default:
- linker_assert ( 0, invalid_LINDA_NUM_CONTEXTS );
+ build_assert ( 0 );
return -EINVAL;
}
@@ -1108,7 +1108,7 @@ static int linda_post_recv ( struct ib_device *ibdev,
case 16384: bufsize = LINDA_EAGER_BUFFER_16K; break;
case 32768: bufsize = LINDA_EAGER_BUFFER_32K; break;
case 65536: bufsize = LINDA_EAGER_BUFFER_64K; break;
- default: linker_assert ( 0, invalid_rx_payload_size );
+ default: build_assert ( 0 );
bufsize = LINDA_EAGER_BUFFER_NONE;
}
diff --git a/src/drivers/infiniband/qib7322.c b/src/drivers/infiniband/qib7322.c
index da055b7..a011daf 100644
--- a/src/drivers/infiniband/qib7322.c
+++ b/src/drivers/infiniband/qib7322.c
@@ -893,7 +893,7 @@ static int qib7322_init_recv ( struct qib7322 *qib7322 ) {
eager_array_size_user = QIB7322_EAGER_ARRAY_SIZE_18CTX_USER;
break;
default:
- linker_assert ( 0, invalid_QIB7322_NUM_CONTEXTS );
+ build_assert ( 0 );
return -EINVAL;
}
@@ -1351,7 +1351,7 @@ static int qib7322_post_recv ( struct ib_device *ibdev,
case 16384: bufsize = QIB7322_EAGER_BUFFER_16K; break;
case 32768: bufsize = QIB7322_EAGER_BUFFER_32K; break;
case 65536: bufsize = QIB7322_EAGER_BUFFER_64K; break;
- default: linker_assert ( 0, invalid_rx_payload_size );
+ default: build_assert ( 0 );
bufsize = QIB7322_EAGER_BUFFER_NONE;
}