summaryrefslogtreecommitdiff
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2023-11-17 22:38:15 -0800
committerFangrui Song <i@maskray.me>2023-11-17 22:38:15 -0800
commitb8dface221f4490933b0d39deb769e97ca134e5f (patch)
treeadbd589ca1b1883c68074e077d1a5891d5e3505a /lld/ELF/LinkerScript.cpp
parent2b71f91b06ad4f5a0c54725b06283fd731620b92 (diff)
[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
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 1b8acbe1c908..28ae4b854306 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -51,11 +51,8 @@ static bool isSectionPrefix(StringRef prefix, StringRef name) {
}
static StringRef getOutputSectionName(const InputSectionBase *s) {
- if (config->relocatable)
- return s->name;
-
- // This is for --emit-relocs. If .text.foo is emitted as .text.bar, we want
- // to emit .rela.text.foo as .rela.text.bar for consistency (this is not
+ // This is for --emit-relocs and -r. If .text.foo is emitted as .text.bar, we
+ // want to emit .rela.text.foo as .rela.text.bar for consistency (this is not
// technically required, but not doing it is odd). This code guarantees that.
if (auto *isec = dyn_cast<InputSection>(s)) {
if (InputSectionBase *rel = isec->getRelocatedSection()) {
@@ -66,6 +63,9 @@ static StringRef getOutputSectionName(const InputSectionBase *s) {
}
}
+ if (config->relocatable)
+ return s->name;
+
// A BssSection created for a common symbol is identified as "COMMON" in
// linker scripts. It should go to .bss section.
if (s->name == "COMMON")