From 37dafcd4a37d62bbf65caf688e92ab06a3bd090e Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Sun, 5 Jan 2025 16:04:07 +0000 Subject: [PATCH] base: Fix for GCC14 and use m68k-elf- tool prefix --- .github/workflows/ci.yml | 6 +++--- .github/workflows/release.yml | 6 +++--- README.md | 6 +++--- base/Rules.mk | 6 +++--- base/amiga.ld | 12 +++++++++--- base/inc/util.h | 3 +++ testkit/crash.c | 5 +++-- testkit/memory.c | 4 ++-- 8 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a86495..269a53b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: uses: actions/cache@v3 with: path: ~/cross - key: ${{ runner.os }}-${{ env.BINUTILS_RELEASE }}-${{ env.GCC_RELEASE }} + key: ${{ runner.os }}-${{ env.BINUTILS_RELEASE }}-${{ env.GCC_RELEASE }}-2 - name: Build toolchain if: steps.cache-toolchain.outputs.cache-hit != 'true' @@ -53,14 +53,14 @@ jobs: tar xf vasm.tar.gz tar xf vlink.tar.gz cd binutils-${BINUTILS_RELEASE} - ./configure --prefix=$MDIR --target=m68k-unknown-elf + ./configure --prefix=$MDIR --target=m68k-elf make ${MAKE_OPTS} make install cd ../gcc-${GCC_RELEASE} sed -i 's/--check/-c/g' contrib/download_prerequisites ./contrib/download_prerequisites mkdir ../gcc-build && cd ../gcc-build - ../gcc-${GCC_RELEASE}/configure --prefix=$MDIR --target=m68k-unknown-elf --enable-languages=c --disable-libssp + ../gcc-${GCC_RELEASE}/configure --prefix=$MDIR --target=m68k-elf --enable-languages=c --disable-libssp make ${MAKE_OPTS} make install cd ../vasm diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bd39ff2..6787c54 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,7 @@ jobs: uses: actions/cache@v3 with: path: ~/cross - key: ${{ runner.os }}-${{ env.BINUTILS_RELEASE }}-${{ env.GCC_RELEASE }} + key: ${{ runner.os }}-${{ env.BINUTILS_RELEASE }}-${{ env.GCC_RELEASE }}-2 - name: Build toolchain if: steps.cache-toolchain.outputs.cache-hit != 'true' @@ -56,14 +56,14 @@ jobs: tar xf vasm.tar.gz tar xf vlink.tar.gz cd binutils-${BINUTILS_RELEASE} - ./configure --prefix=$MDIR --target=m68k-unknown-elf + ./configure --prefix=$MDIR --target=m68k-elf make ${MAKE_OPTS} make install cd ../gcc-${GCC_RELEASE} sed -i 's/--check/-c/g' contrib/download_prerequisites ./contrib/download_prerequisites mkdir ../gcc-build && cd ../gcc-build - ../gcc-${GCC_RELEASE}/configure --prefix=$MDIR --target=m68k-unknown-elf --enable-languages=c --disable-libssp + ../gcc-${GCC_RELEASE}/configure --prefix=$MDIR --target=m68k-elf --enable-languages=c --disable-libssp make ${MAKE_OPTS} make install cd ../vasm diff --git a/README.md b/README.md index 85d851c..d201487 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,12 @@ use `rjnorthrow/atk:v1.10`. ### Build From Source (Manual Method) Requires a GCC cross-compiler toolchain targetting -`m68k-unknown-elf`. I recommend binutils-2.28 and gcc-7.1.0, built +`m68k-elf`. I recommend binutils-2.34 and gcc-9.3.0, built with the following configuration lines on a Linux host or VM (note these are not exhaustive toolchain build instructions!): ``` -../binutils-2.28/configure --prefix=/path/to/install --target=m68k-unknown-elf -../gcc-7.1.0/configure --prefix=/path/to/install --target=m68k-unknown-elf --enable-languages=c --disable-libssp +../binutils-2.34/configure --prefix=/path/to/install --target=m68k-elf +../gcc-9.3.0/configure --prefix=/path/to/install --target=m68k-elf --enable-languages=c --disable-libssp ``` Note that `/path/to/install/bin` must be on your PATH both when building diff --git a/base/Rules.mk b/base/Rules.mk index 0bfe4c7..951c900 100644 --- a/base/Rules.mk +++ b/base/Rules.mk @@ -1,9 +1,9 @@ # GNU Make cross-dev build rules # Tested cross-dev setups (gcc/binutils) (*=recommended): -# 4.9.2/2.24, 5.3.0/2.26, 7.1.0/2.28, 9.3.0/2.34* -# Target is m68k-unknown-elf +# 4.9.2/2.24, 5.3.0/2.26, 7.1.0/2.28, 9.3.0/2.34*, 14.2.0/2.43.1 +# Target is m68k-elf -TOOL_PREFIX = m68k-unknown-elf- +TOOL_PREFIX = m68k-elf- CC = $(TOOL_PREFIX)gcc OBJCOPY = $(TOOL_PREFIX)objcopy PYTHON = python3 diff --git a/base/amiga.ld b/base/amiga.ld index f0ef0c7..2883778 100644 --- a/base/amiga.ld +++ b/base/amiga.ld @@ -1,5 +1,11 @@ ENTRY(start) +PHDRS +{ + /* Define as RW^X to avoid a linker warning */ + text PT_LOAD FLAGS(6); +} + SECTIONS { SUPER_SP = 0x40000; @@ -15,7 +21,7 @@ SECTIONS *(.rodata*) . = ALIGN(4); _etext = .; - } + } :text .data : { . = ALIGN(4); @@ -24,7 +30,7 @@ SECTIONS *(.data*) . = ALIGN(4); _edat = .; - } + } :text .bss : { . = ALIGN(4); @@ -34,7 +40,7 @@ SECTIONS . = ALIGN(4); _ebss = .; _end = .; - } + } :text /DISCARD/ : { *(.eh_frame) diff --git a/base/inc/util.h b/base/inc/util.h index a9c02a6..ebfdd08 100644 --- a/base/inc/util.h +++ b/base/inc/util.h @@ -21,6 +21,9 @@ #define barrier() asm volatile("" ::: "memory") +/* Suppresses unwanted arroy-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/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; }