[lld] r283307 - Do not join sections for relocatable object files

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 5 03:10:45 PDT 2016


Author: evgeny777
Date: Wed Oct  5 05:10:45 2016
New Revision: 283307

URL: http://llvm.org/viewvc/llvm-project?rev=283307&view=rev
Log:
Do not join sections for relocatable object files

Differential revision: https://reviews.llvm.org/D25232

Added:
    lld/trunk/test/ELF/relocatable-sections.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/Writer.cpp
    lld/trunk/ELF/Writer.h

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=283307&r1=283306&r2=283307&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Oct  5 05:10:45 2016
@@ -345,7 +345,7 @@ void LinkerScript<ELFT>::createSections(
   for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles())
     for (InputSectionBase<ELFT> *S : F->getSections())
       if (!isDiscarded(S) && !S->OutSec)
-        addSection(Factory, S, getOutputSectionName(S));
+        addSection(Factory, S, getOutputSectionName(S->Name));
 }
 
 // Sets value of a section-defined symbol. Two kinds of

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=283307&r1=283306&r2=283307&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Oct  5 05:10:45 2016
@@ -89,9 +89,10 @@ private:
 };
 } // anonymous namespace
 
-template <class ELFT>
-StringRef elf::getOutputSectionName(InputSectionBase<ELFT> *S) {
-  StringRef Name = S->Name;
+StringRef elf::getOutputSectionName(StringRef Name) {
+  if (Config->Relocatable)
+    return Name;
+
   for (StringRef V :
        {".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.",
         ".init_array.", ".fini_array.", ".ctors.", ".dtors.", ".tbss.",
@@ -712,7 +713,7 @@ template <class ELFT> void Writer<ELFT>:
       }
       OutputSectionBase<ELFT> *Sec;
       bool IsNew;
-      std::tie(Sec, IsNew) = Factory.create(IS, getOutputSectionName(IS));
+      std::tie(Sec, IsNew) = Factory.create(IS, getOutputSectionName(IS->Name));
       if (IsNew)
         OutputSections.push_back(Sec);
       Sec->addSection(IS);
@@ -1444,11 +1445,6 @@ template bool elf::isRelroSection<ELF32B
 template bool elf::isRelroSection<ELF64LE>(OutputSectionBase<ELF64LE> *);
 template bool elf::isRelroSection<ELF64BE>(OutputSectionBase<ELF64BE> *);
 
-template StringRef elf::getOutputSectionName<ELF32LE>(InputSectionBase<ELF32LE> *);
-template StringRef elf::getOutputSectionName<ELF32BE>(InputSectionBase<ELF32BE> *);
-template StringRef elf::getOutputSectionName<ELF64LE>(InputSectionBase<ELF64LE> *);
-template StringRef elf::getOutputSectionName<ELF64BE>(InputSectionBase<ELF64BE> *);
-
 template void elf::reportDiscarded<ELF32LE>(InputSectionBase<ELF32LE> *);
 template void elf::reportDiscarded<ELF32BE>(InputSectionBase<ELF32BE> *);
 template void elf::reportDiscarded<ELF64LE>(InputSectionBase<ELF64LE> *);

Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=283307&r1=283306&r2=283307&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Wed Oct  5 05:10:45 2016
@@ -41,8 +41,7 @@ struct PhdrEntry {
   bool HasLMA = false;
 };
 
-template <class ELFT>
-llvm::StringRef getOutputSectionName(InputSectionBase<ELFT> *S);
+llvm::StringRef getOutputSectionName(llvm::StringRef Name);
 
 template <class ELFT> void reportDiscarded(InputSectionBase<ELFT> *IS);
 

Added: lld/trunk/test/ELF/relocatable-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-sections.s?rev=283307&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-sections.s (added)
+++ lld/trunk/test/ELF/relocatable-sections.s Wed Oct  5 05:10:45 2016
@@ -0,0 +1,30 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: ld.lld -r %t1.o -o %t
+# RUN: llvm-objdump -section-headers %t | FileCheck %s
+
+# CHECK:      .text
+# CHECK-NEXT: .text._init
+# CHECK-NEXT: .text._fini
+# CHECK-NEXT: .rela.text     
+# CHECK-NEXT: .rela.text._init
+# CHECK-NEXT: .rela.text._fini
+
+.globl _start
+_start:
+ call foo
+ nop
+
+.section .xxx,"a"
+ .quad 0
+
+.section .text._init,"ax"
+ .quad .xxx
+foo:
+ call bar
+ nop
+
+
+.section .text._fini,"ax"
+ .quad .xxx
+bar:
+ nop




More information about the llvm-commits mailing list