Skip to content

Commit b8dface

Browse files
committed
[ELF] -r: rename orphan SHT_REL/SHT_RELA when the relocated input section is placed in an output section
This ports https://reviews.llvm.org/D40652 (--emit-relocs) to -r and matches GNU ld. Close #67910
1 parent 2b71f91 commit b8dface

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lld/ELF/LinkerScript.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ static bool isSectionPrefix(StringRef prefix, StringRef name) {
5151
}
5252

5353
static StringRef getOutputSectionName(const InputSectionBase *s) {
54-
if (config->relocatable)
55-
return s->name;
56-
57-
// This is for --emit-relocs. If .text.foo is emitted as .text.bar, we want
58-
// to emit .rela.text.foo as .rela.text.bar for consistency (this is not
54+
// This is for --emit-relocs and -r. If .text.foo is emitted as .text.bar, we
55+
// want to emit .rela.text.foo as .rela.text.bar for consistency (this is not
5956
// technically required, but not doing it is odd). This code guarantees that.
6057
if (auto *isec = dyn_cast<InputSection>(s)) {
6158
if (InputSectionBase *rel = isec->getRelocatedSection()) {
@@ -66,6 +63,9 @@ static StringRef getOutputSectionName(const InputSectionBase *s) {
6663
}
6764
}
6865

66+
if (config->relocatable)
67+
return s->name;
68+
6969
// A BssSection created for a common symbol is identified as "COMMON" in
7070
// linker scripts. It should go to .bss section.
7171
if (s->name == "COMMON")

lld/test/ELF/linkerscript/emit-reloc-section-names.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# RUN: echo "SECTIONS { .text.zed : { *(.text.foo) } .text.qux : { *(.text.bar) } }" > %t.script
44
# RUN: ld.lld -T %t.script --emit-relocs %t.o -o %t
55
# RUN: llvm-objdump --section-headers %t | FileCheck %s
6+
# RUN: ld.lld -T %t.script -r %t.o -o %t.ro
7+
# RUN: llvm-readelf -S %t.ro | FileCheck %s
68

79
## Check we name relocation sections in according to
810
## their target sections names.

lld/test/ELF/linkerscript/emit-relocs-multiple.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# RUN: echo "SECTIONS { .zed : { *(.foo) *(.bar) } }" > %t.script
44
# RUN: ld.lld --emit-relocs --script %t.script %t.o -o %t1
55
# RUN: llvm-readobj -r %t1 | FileCheck %s
6+
# RUN: ld.lld -r --script %t.script %t.o -o %t.ro
7+
# RUN: llvm-readobj -r %t.ro | FileCheck %s
68

79
# CHECK: Relocations [
810
# CHECK-NEXT: Section {{.*}} .rela.zed {

0 commit comments

Comments
 (0)