[lld] [lld/elf] rename relocation section for relocatable file. (PR #67953)

Xavier Hsinyuan via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 1 23:14:41 PDT 2023


https://github.com/thelastlin created https://github.com/llvm/llvm-project/pull/67953

This is for #67910.

It's odd not to rename relocation section when creating relocatable object file even with `--emit-reloc`.

>From bf6e583166e90a91d3340d87dc3120b58b56c27c Mon Sep 17 00:00:00 2001
From: Xavier Hsinyuan <thelastlin at hotmail.com>
Date: Mon, 2 Oct 2023 13:36:55 +0800
Subject: [PATCH] [lld/elf] rename relocation section for relocatable file.

It's odd not to rename relocation section when creating relocatable
object file.
---
 lld/ELF/LinkerScript.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index df091613dc0a144..54ef5ba48923e2c 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -51,9 +51,6 @@ 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
   // technically required, but not doing it is odd). This code guarantees that.
@@ -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")



More information about the llvm-commits mailing list