From bc655bbf70d6ce4207168ed0ec457955f0bb1850 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Sun, 5 Jan 2025 18:05:17 +0000 Subject: [PATCH] Remove -Wno-array-bounds workaround for GCC14 compile errors Instead launder array-tagged pointers as needed. --- base/Rules.mk | 2 +- base/inc/util.h | 3 +++ cracking/cracks/nzs/Rules.mk | 2 +- testkit/crash.c | 5 +++-- testkit/memory.c | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/base/Rules.mk b/base/Rules.mk index 725cc59..951c900 100644 --- a/base/Rules.mk +++ b/base/Rules.mk @@ -23,7 +23,7 @@ FLAGS = $(OPT_FLAGS) -nostdlib -std=gnu99 -iquote ../base/inc -fno-builtin FLAGS += -Wall -Werror -Wno-format -Wdeclaration-after-statement FLAGS += -Wstrict-prototypes -Wredundant-decls -Wnested-externs FLAGS += -fno-common -fno-exceptions -fno-strict-aliasing -fomit-frame-pointer -FLAGS += -fno-delete-null-pointer-checks -Wno-array-bounds -m68000 -msoft-float +FLAGS += -fno-delete-null-pointer-checks -m68000 -msoft-float FLAGS += -MMD -MF .$(@F).d DEPS = .*.d diff --git a/base/inc/util.h b/base/inc/util.h index a9c02a6..613078c 100644 --- a/base/inc/util.h +++ b/base/inc/util.h @@ -21,6 +21,9 @@ #define barrier() asm volatile("" ::: "memory") +/* Suppresses unwanted array-bounds compiler warnings. */ +#define arrayptr_launder(x) ({ typeof(x) _x; asm("":"=r"(_x):"0"(x)); _x; }) + #ifndef offsetof #define offsetof(a,b) __builtin_offsetof(a,b) #endif diff --git a/cracking/cracks/nzs/Rules.mk b/cracking/cracks/nzs/Rules.mk index 034d60a..cf1c87b 100644 --- a/cracking/cracks/nzs/Rules.mk +++ b/cracking/cracks/nzs/Rules.mk @@ -10,7 +10,7 @@ FLAGS = -Os -nostdlib -std=gnu99 -iquote inc FLAGS += -Wall -Werror -Wno-format -Wdeclaration-after-statement FLAGS += -Wstrict-prototypes -Wredundant-decls -Wnested-externs FLAGS += -fno-common -fno-exceptions -fno-strict-aliasing -fomit-frame-pointer -FLAGS += -fno-delete-null-pointer-checks -Wno-array-bounds -m68000 -msoft-float +FLAGS += -fno-delete-null-pointer-checks -m68000 -msoft-float FLAGS += -MMD -MF .$(@F).d DEPS = .*.d diff --git a/testkit/crash.c b/testkit/crash.c index 13b0606..182dbea 100644 --- a/testkit/crash.c +++ b/testkit/crash.c @@ -99,13 +99,14 @@ struct frame { /* Fix up one 68000 unrecoverable fault handler. */ static void fixup_68000(void *new_fn, volatile uint32_t *vec) { - uint32_t old_fn = *vec; + volatile uint32_t *_vec = arrayptr_launder(vec); + uint32_t old_fn = *_vec; /* Search for the JMP instruction in the shim handler, and patch it. */ uint16_t *p = new_fn; while (*p != 0x4ef9) p++; *(uint32_t *)(p+1) = old_fn; /* Install our shim handler. */ - *vec = (uint32_t)new_fn; + *_vec = (uint32_t)new_fn; } /* 68000 (only) has weird stack formats for unrecoverable faults. These cause diff --git a/testkit/memory.c b/testkit/memory.c index a8abef2..18e2a2a 100644 --- a/testkit/memory.c +++ b/testkit/memory.c @@ -424,7 +424,7 @@ static void memcheck_direct_scan(void) for (i = 0; i < 27; i++) { if (aliased_slots & (1u << i)) continue; - p = (volatile uint16_t *)&s[0] + (i << 18); + p = (volatile uint16_t *)arrayptr_launder(&s[0]) + (i << 18); p[0] = 0x5555; p[1<<17] = 0xaaaa; if ((p[0] != 0x5555) || (p[1<<17] != 0xaaaa)) { @@ -432,7 +432,7 @@ static void memcheck_direct_scan(void) continue; } for (j = 0; j < i; j++) { - q = (volatile uint16_t *)s + (j << 18); + q = (volatile uint16_t *)arrayptr_launder(&s[0]) + (j << 18); if ((ram_slots & (1u << j)) && (*q == 0x5555)) break; }