Skip to content

Place the GOT directly after .fini_array - #32

Open
Jiu-xiao wants to merge 1 commit into
devfrom
fix/got-after-fini-array
Open

Jiu-xiao wants to merge 1 commit into
devfrom
fix/got-after-fini-array

Conversation

@Jiu-xiao

Copy link
Copy Markdown
Contributor

把链接脚本中的 .got 段移到紧跟 .fini_array 的位置,修复 ST Arm Clang STARM_NEWLIB 配置的链接失败:

ld.lld: error: section: .got is not contiguous with other relro sections

原因

ld.lld 把 .preinit_array、.init_array、.fini_array 和 .got 归入同一段 RELRO 范围,要求它们连续(脚本中的 READONLY 对 ld.lld 不起作用)。.got 原来在 .ccmram、.ccm_heap 之后,这两个段把范围隔开了。MC02、F103、OpenCR 的 .got 本来就紧跟 .fini_array,各配置都能链接。

.got 仍在 FLASH 中,只改位置,并在注释中写明必须紧跟 .fini_array。

验证

Release 构建,GCC 14.2 与 ST Arm Clang 21.1.1:

配置 修改前 修改后
GCC 通过 通过,.bin 逐字节相同
STARM_HYBRID 通过 通过,.bin 逐字节相同
STARM_PICOLIBC 通过 通过,.bin 逐字节相同
STARM_NEWLIB 链接失败 通过,.bin 119780 B,.data 加载地址紧接 Flash 内容

未上板。

相关:xrobot-org/LibXR_CppCodeGenerator#35 让 libxr stm32 setup 为新工程在 .fini_array 之后加入 .got;对 .got 位置不对的已有脚本只给出警告。

ld.lld keeps the init/fini arrays and the GOT in one RELRO range. With .got
after the CCM sections the range was split, and the ST Arm Clang STARM_NEWLIB
profile failed to link with ".got is not contiguous with other relro
sections". The .got section moves directly after .fini_array, still in FLASH.

GCC, STARM_HYBRID and STARM_PICOLIBC images are byte-identical to before;
STARM_NEWLIB links again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant