From b8dface221f4490933b0d39deb769e97ca134e5f Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 17 Nov 2023 22:38:15 -0800 Subject: [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 --- lld/ELF/LinkerScript.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lld/ELF/LinkerScript.cpp') 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(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") -- cgit v1.2.3