Work around issue with unreferenced sections marked allocated in the asm being discarded by GNU linker (#1391)

This commit is contained in:
Graham Sanderson 2023-05-26 07:04:40 -05:00 committed by GitHub
parent affbb31a8c
commit c34d3d5602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 12 deletions

View File

@ -523,6 +523,18 @@ __force_inline static uint get_core_num(void) {
#else // __ASSEMBLER__
#if defined __GNUC__
// note LLVM defines __GNUC__
#ifdef __clang__
#define PICO_ASSEMBLER_IS_CLANG 1
#else
#define PICO_ASSEMBLER_IS_GNU 1
#endif
#elif defined __ICCARM__
#else
#error Unsupported toolchain
#endif
#define WRAPPER_FUNC_NAME(x) __wrap_##x
#define SECTION_NAME(x) .text.##x
#define RAM_SECTION_NAME(x) .time_critical.##x

View File

@ -324,13 +324,29 @@ hold_non_core0_in_bootrom:
// ----------------------------------------------------------------------------
// Stack/heap dummies to set size
.section .stack, "a"
// Prior to SDK 1.5.1 these were `.section .stack` without the `, "a"`... Clang linker gives a warning about this,
// however setting it explicitly to `, "a"` makes GCC *now* discard the section unless it is also KEEP. This
// seems like very surprising behavior!
//
// Strictly the most correct thing to do (as .stack and .heap are unreferenced) is to mark them as "a", and also KEEP, which
// works correctly for both GCC and Clang, however doing so may break anyone who already has custom linker scripts without
// the KEEP. Therefore we will only add the "a" on Clang, but will also use KEEP to our own linker scripts.
.macro spacer_section name
#if PICO_ASSEMBLER_IS_CLANG
.section \name, "a"
#else
.section \name
#endif
.endm
spacer_section .stack
// align to allow for memory protection (although this alignment is pretty much ignored by linker script)
.align 5
.p2align 5
.equ StackSize, PICO_STACK_SIZE
.space StackSize
.section .heap, "a"
.align 2
spacer_section .heap
.p2align 2
.equ HeapSize, PICO_HEAP_SIZE
.space HeapSize

View File

@ -208,7 +208,7 @@ SECTIONS
{
__end__ = .;
end = __end__;
*(.heap*)
KEEP(*(.heap*))
__HeapLimit = .;
} > RAM
@ -227,7 +227,7 @@ SECTIONS
} > SCRATCH_X
.stack_dummy (NOLOAD):
{
*(.stack*)
KEEP(*(.stack*))
} > SCRATCH_Y
.flash_end : {

View File

@ -210,7 +210,7 @@ SECTIONS
{
__end__ = .;
end = __end__;
*(.heap*)
KEEP(*(.heap*))
__HeapLimit = .;
} > RAM
@ -229,7 +229,7 @@ SECTIONS
} > SCRATCH_X
.stack_dummy (NOLOAD):
{
*(.stack*)
KEEP(*(.stack*))
} > SCRATCH_Y
.flash_end : {

View File

@ -208,7 +208,7 @@ SECTIONS
{
__end__ = .;
end = __end__;
*(.heap*)
KEEP(*(.heap*))
__HeapLimit = .;
} > RAM
@ -227,7 +227,7 @@ SECTIONS
} > SCRATCH_X
.stack_dummy (NOLOAD):
{
*(.stack*)
KEEP(*(.stack*))
} > SCRATCH_Y
.flash_end : {

View File

@ -178,7 +178,7 @@ SECTIONS
{
__end__ = .;
end = __end__;
*(.heap*)
KEEP(*(.heap*))
__HeapLimit = .;
} > RAM
@ -197,7 +197,7 @@ SECTIONS
} > SCRATCH_X
.stack_dummy (NOLOAD):
{
*(.stack*)
KEEP(*(.stack*))
} > SCRATCH_Y
/* stack limit is poorly named, but historically is maximum heap ptr */