[PATCH] D68094: ELF: Don't merge SHF_LINK_ORDER sections for different output sections in relocatable links.
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 22:53:24 PDT 2019
MaskRay added a comment.
For the record, the original approach does not work for the `ld.lld exidx.o exidx2.o -r -o exidxr.o -T exidx.lds` example at https://reviews.llvm.org/D68094?id=221994#1685161:
[ 1] .foo PROGBITS 00000000 000034 000010 00 AX 0 0 1
[ 2] .text PROGBITS 00000000 000044 000004 00 AX 0 0 4
[ 3] .ARM.exidx.text.f1 ARM_EXIDX 00000000 000048 000008 00 AL 1 0 4
[ 4] .rel.ARM.exidx.text.f1 REL 00000000 000050 000008 08 I 13 3 4
[ 5] .ARM.exidx.text.f2 ARM_EXIDX 00000000 000058 000008 00 AL 1 0 4
[ 6] .rel.ARM.exidx.text.f2 REL 00000000 000060 000010 08 I 13 5 4
[ 7] .ARM.attributes ARM_ATTRIBUTES 00000000 000070 00001e 00 0 0 1
[ 8] .ARM.exidx.text.f1 ARM_EXIDX 00000000 000090 000008 00 AL 1 0 4
[ 9] .rel.ARM.exidx.text.f1 REL 00000000 000098 000010 08 I 13 8 4
[10] .ARM.exidx.text.f2 ARM_EXIDX 00000000 0000a8 000008 00 AL 1 0 4
[11] .rel.ARM.exidx.text.f2 REL 00000000 0000b0 000008 08 I 13 10 4
The new approach can cause a segfault. The following 3 sections are consecutive in inputSections:
.text.f1 # `add` returned early because parent(.text.f1) is set (it is specified by a SECTIONS command)
.ARM.exidx.text.f1 # skipped because it has the SHF_LINK_ORDER flag
.rel.ARM.exidx.text.f1 # SIGSEGV when dereferencing `OutputSection *out = sec->getRelocatedSection()->getOutputSection();` because out is null.
One probably fix is:
- auto add = [&](InputSectionBase *s) {
+ std::function<void(InputSectionBase *)> add;
+ add = [&](InputSectionBase *s) {
+ auto onExit = make_scope_exit([&]() {
+ if (config->relocatable)
+ for (InputSectionBase *depSec : s->dependentSections)
+ if (depSec->flags & SHF_LINK_ORDER)
+ add(depSec);
+ });
We may need a proper topological sort when the ordering requirement gets more complicated.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68094/new/
https://reviews.llvm.org/D68094
More information about the llvm-commits
mailing list