This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit bf3a5b0b350feff21130662d843e0b21b2300b3b Author: Marco Casaroli <[email protected]> AuthorDate: Thu Sep 24 19:35:57 2026 +0200 libs/libc/elf: Link a kernel-build program the way the loader loads it. The loader packs the allocatable sections of a fully linked program into the text and data regions in section header order, and on a chip that selects ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ every section that is not executable goes to the data region. The template left .rodata in the text region, so the addresses the program carries did not say where it would be loaded. .rodata now leads the data region on such a chip, .eh_frame is placed rather than left an orphan, and the Xtensa literal pools are gathered with the text they belong to: a literal section is not executable, so an orphan one would be loaded into the data region, away from the code that reads it. The ESP32-S3 needs all three. With them the shared template lays out a user program exactly as the board script it replaces did, section for section. Assisted-by: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Marco Casaroli <[email protected]> --- libs/libc/elf/gnu-elf.ld.in | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/libs/libc/elf/gnu-elf.ld.in b/libs/libc/elf/gnu-elf.ld.in index be0c8776050..a43d20efded 100644 --- a/libs/libc/elf/gnu-elf.ld.in +++ b/libs/libc/elf/gnu-elf.ld.in @@ -33,6 +33,21 @@ # define DATA #endif +/* A chip that selects CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ cannot + * read its text region as data, so the loader puts every section that is not + * executable in the data region. A fully linked program is loaded at the + * addresses in its own headers, so .rodata has to be linked there too: it + * leads the data region and .data follows it. + */ + +#ifdef CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ +# define RODATA DATA +# define DATA_START +#else +# define RODATA +# define DATA_START DATA +#endif + #if defined(CONFIG_LIBC_ARCH_ELF_64BIT) # define SECTIONS_ALIGN 8 #else @@ -72,6 +87,8 @@ SECTIONS .text TEXT : { _stext = . ; + *(.literal) + *(.literal.*) *(.text) *(.text.*) *(.gnu.warning) @@ -79,11 +96,19 @@ SECTIONS *(.glue_7) *(.glue_7t) *(.jcr) + + /* C++ support: the .init and .fini sections hold the logic that runs + * the static constructors and destructors. + */ + + *(.gnu.linkonce.t.*) + *(.init) + *(.fini) . = ALIGN(SECTIONS_ALIGN); _etext = . ; } PHDR_TEXT - .rodata : + .rodata RODATA : { _srodata = . ; *(.rodata) @@ -94,9 +119,15 @@ SECTIONS _erodata = . ; } PHDR_TEXT + .eh_frame : + { + KEEP (*(.eh_frame)) + *(.eh_frame.*) + } PHDR_TEXT + DATA_ALIGN - .data DATA : + .data DATA_START : { _sdata = . ; *(.data)
