This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 0da36c750ad libs/libc/elf: Align the constructor tables of a program.
0da36c750ad is described below
commit 0da36c750adbf0d89020e0d53af15b204d5e3bdc
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 1 11:14:08 2026 +0100
libs/libc/elf: Align the constructor tables of a program.
gnu-elf.ld.in aligns .init_array and .fini_array only at their end.
Their start is where the section before them ended. On RISC-V the
small data sections (.sdata.*) are not in .data, so the linker places
them after it as orphans, and .init_array can start at an odd address.
A table without constructors is then not empty. For example, with
rv-virt:knsh64 and CONFIG_HAVE_CXXINITIALIZE, the small data of
/system/bin/init ends with the 1-byte .sdata.g_syslog_mask at
0xc0101280: _sctors is 0xc0101281 and _ectors, after the alignment,
0xc0101284. crt0.c calls each pointer from _sctors until it is equal
to _ectors, so it calls bytes of other data: init jumps to address 0
before main() and the system does not start.
Align .init_array and .fini_array at their start too, and put the small
data sections of RISC-V (.sdata, .srodata) in .data and .rodata, where
the other data of the same kind is.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
libs/libc/elf/gnu-elf.ld.in | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libs/libc/elf/gnu-elf.ld.in b/libs/libc/elf/gnu-elf.ld.in
index 51a79640211..b2d7096514e 100644
--- a/libs/libc/elf/gnu-elf.ld.in
+++ b/libs/libc/elf/gnu-elf.ld.in
@@ -121,6 +121,7 @@ SECTIONS
*(.rodata)
*(.rodata1)
*(.rodata.*)
+ *(.srodata .srodata.*)
*(.gnu.linkonce.r*)
. = ALIGN(SECTIONS_ALIGN);
_erodata = . ;
@@ -166,6 +167,7 @@ SECTIONS
*(.data)
*(.data1)
*(.data.*)
+ *(.sdata .sdata.*)
*(.gnu.linkonce.d*)
. = ALIGN(SECTIONS_ALIGN);
_edata = . ;
@@ -173,6 +175,7 @@ SECTIONS
.init_array :
{
+ . = ALIGN(SECTIONS_ALIGN);
_sinit = .;
_sctors = .;
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)
SORT_BY_INIT_PRIORITY(.ctors.*)))
@@ -184,6 +187,7 @@ SECTIONS
.fini_array :
{
+ . = ALIGN(SECTIONS_ALIGN);
_sfini = .;
_sdtors = .;
KEEP (*(.dtors))