Files
llvm/lld/ELF/LinkerScript.cpp
mykouHW 507f394d03 [ELF] -r/--emit-relocs: Fix crash when processing .rela.text before .text (#156354)
fixes #156417 

When the relocation section is placed before the relocated section and
the relocated section is not defined in the linker script, an error will
occur during the linking process.

**Issue Cause:**  
In a.ro, `.rela.text` precedes its relocated `InputSection` `.text`.
`addOrphanSections` doesn't handle this scenario.
When it processes `.rela.text`, in the called `getOutputSectionName`,
`rel->getOutputSection()` is nullptr (input `.text` doesn't yet have a
parent output section), leading to an assertion failure.

**Solution:**  
For --emit-relocs and -r, ensure the output section for `.text.foo` is
created before the output section for `.rela.text.foo`.

---------

Co-authored-by: Fangrui Song <i@maskray.me>
2025-09-20 16:41:54 +00:00

71 KiB