[Skiboot] [PATCH v2 2/9] build: fix non-constant build asserts

Nicholas Piggin npiggin at gmail.com
Mon Nov 11 16:44:41 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 equivalent as/ld checks which actually do
the right thing.

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 58f9aea97..21e653f00 100644
--- a/asm/head.S
+++ b/asm/head.S
@@ -575,6 +575,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 e6efb6003..fd1a9134e 100644
--- a/core/init.c
+++ b/core/init.c
@@ -829,8 +829,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 06cef1b2b..1bb87805c 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 cb27f2497..e460f15ab 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 32139b2c5..1dc0ca92e 100644
--- a/skiboot.lds.S
+++ b/skiboot.lds.S
@@ -228,6 +228,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