Skip to content

Commit

Permalink
Remove -Wno-array-bounds workaround for GCC14 compile errors
Browse files Browse the repository at this point in the history
Instead launder array-tagged pointers as needed.
  • Loading branch information
keirf committed Jan 5, 2025
1 parent bb9a1d7 commit bc655bb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion base/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions base/inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cracking/cracks/nzs/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions testkit/crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testkit/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,15 @@ 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)) {
p[0] = p[1<<17] = 0;
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;
}
Expand Down

0 comments on commit bc655bb

Please sign in to comment.