[Skiboot] [PATCH v6 29/29] build: fix non-constant build asserts

Nicholas Piggin npiggin at gmail.com
Wed Nov 6 23:10:47 AEDT 2019


BUILD_ASSERT can not be used for constants generated by the assembler
or linker. This results in variable length arrays that do not catch
the failure condition. This was caught by sparse.

Remove these and add some as/ld alternatives.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 asm/head.S        | 4 ++++
 core/init.c       | 2 --
 core/mem_region.c | 4 ----
 hw/slw.c          | 7 +------
 skiboot.lds.S     | 2 ++
 5 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/asm/head.S b/asm/head.S
index 68f153b36..b565f6c9c 100644
--- a/asm/head.S
+++ b/asm/head.S
@@ -582,6 +582,10 @@ reset_patch_start:
 .global reset_patch_end
 reset_patch_end:
 
+.if reset_patch_end - reset_patch_start > 0x100
+	.error "Reset patch overflow"
+.endif
+
 /* Wakeup vector in r3 */
 .global reset_wakeup
 reset_wakeup:
diff --git a/core/init.c b/core/init.c
index 341b148bb..d32791be9 100644
--- a/core/init.c
+++ b/core/init.c
@@ -840,8 +840,6 @@ void copy_exception_vectors(void)
 	 * this is the boot flag used by CPUs still potentially entering
 	 * skiboot.
 	 */
-	BUILD_ASSERT((&reset_patch_end - &reset_patch_start) <
-			EXCEPTION_VECTORS_END - 0x100);
 	memcpy((void *)0x100, (void *)(SKIBOOT_BASE + 0x100),
 			EXCEPTION_VECTORS_END - 0x100);
 	sync_icache();
diff --git a/core/mem_region.c b/core/mem_region.c
index 3ab039aba..eb48a1a11 100644
--- a/core/mem_region.c
+++ b/core/mem_region.c
@@ -1058,10 +1058,6 @@ void mem_region_init(void)
 	struct dt_node *i;
 	bool rc;
 
-	/* Ensure we have no collision between skiboot core and our heap */
-	extern char _end[];
-	BUILD_ASSERT(HEAP_BASE >= (uint64_t)_end);
-
 	/*
 	 * Add associativity properties outside of the lock
 	 * to avoid recursive locking caused by allocations
diff --git a/hw/slw.c b/hw/slw.c
index 5a7e24e58..97df81f1c 100644
--- a/hw/slw.c
+++ b/hw/slw.c
@@ -28,9 +28,7 @@
 #include <p8_pore_table_gen_api.H>
 #include <sbe_xip_image.h>
 
-#define MAX_RESET_PATCH_SIZE	0x100
-
-static uint32_t slw_saved_reset[MAX_RESET_PATCH_SIZE];
+static uint32_t slw_saved_reset[0x100];
 
 static bool slw_current_le = false;
 
@@ -146,9 +144,6 @@ static void slw_patch_reset(void)
 {
 	uint32_t *src, *dst, *sav;
 
-	BUILD_ASSERT((&reset_patch_end - &reset_patch_start) <=
-		     MAX_RESET_PATCH_SIZE);
-
 	src = &reset_patch_start;
 	dst = (uint32_t *)0x100;
 	sav = slw_saved_reset;
diff --git a/skiboot.lds.S b/skiboot.lds.S
index 12981f3c8..1822334b2 100644
--- a/skiboot.lds.S
+++ b/skiboot.lds.S
@@ -233,6 +233,8 @@ SECTIONS
 	_ebss = .;
 	_end = .;
 
+	ASSERT(HEAP_BASE >= _end, "Heap collision with image")
+
 	DEBUG_SECTIONS
 
 	/* Optional kernel image */
-- 
2.23.0



More information about the Skiboot mailing list