[lld] r316760 - [ELF] - Stop naming relocation sections with first input section name.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 04:38:31 PDT 2017


Author: grimar
Date: Fri Oct 27 04:38:31 2017
New Revision: 316760

URL: http://llvm.org/viewvc/llvm-project?rev=316760&view=rev
Log:
[ELF] - Stop naming relocation sections with first input section name.

It was reported (https://reviews.llvm.org/D38724#902841) that when we use 
-ffunction-sections --emit-relocs build, REL[A] output section receives the name of first
input section, like .rela.text.first_function_in_text rather than .rela.text.

It is probably not really an issue as sh_info still points to correct target section, but
it does not look clean in output and allows internal section name to leak there,
what at least looks confusing and is not consistent with ld.bfd.

Patch changes this behavior so that target output section name is used as a base.

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

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/emit-relocs-merge.s
    lld/trunk/test/ELF/emit-relocs.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=316760&r1=316759&r2=316760&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Oct 27 04:38:31 2017
@@ -98,6 +98,14 @@ StringRef elf::getOutputSectionName(Stri
   if (Config->Relocatable)
     return Name;
 
+  // This is for --emit-relocs. If .text.foo is emitted as .text, we want to
+  // emit .rela.text.foo as .rel.text for consistency (this is not technically
+  // required, but not doing it is odd). This code guarantees that.
+  if (Name.startswith(".rel."))
+    return Saver.save(".rel" + getOutputSectionName(Name.substr(4)));
+  if (Name.startswith(".rela."))
+    return Saver.save(".rela" + getOutputSectionName(Name.substr(5)));
+
   for (StringRef V :
        {".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.rel.ro.",
         ".bss.", ".init_array.", ".fini_array.", ".ctors.", ".dtors.", ".tbss.",

Modified: lld/trunk/test/ELF/emit-relocs-merge.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emit-relocs-merge.s?rev=316760&r1=316759&r2=316760&view=diff
==============================================================================
--- lld/trunk/test/ELF/emit-relocs-merge.s (original)
+++ lld/trunk/test/ELF/emit-relocs-merge.s Fri Oct 27 04:38:31 2017
@@ -8,7 +8,7 @@
 # CHECK-NEXT:     0x1000 R_X86_64_64 zed 0x0
 # CHECK-NEXT:     0x1008 R_X86_64_64 zed 0x0
 # CHECK-NEXT:   }
-# CHECK-NEXT:   Section ({{.*}}) .rela.data.foo {
+# CHECK-NEXT:   Section ({{.*}}) .rela.data {
 # CHECK-NEXT:     0x1000 R_X86_64_64 zed 0x0
 # CHECK-NEXT:     0x1008 R_X86_64_64 zed 0x0
 # CHECK-NEXT:   }

Modified: lld/trunk/test/ELF/emit-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emit-relocs.s?rev=316760&r1=316759&r2=316760&view=diff
==============================================================================
--- lld/trunk/test/ELF/emit-relocs.s (original)
+++ lld/trunk/test/ELF/emit-relocs.s Fri Oct 27 04:38:31 2017
@@ -83,7 +83,7 @@
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
 
-.section .text,"ax", at progbits,unique,0
+.section .text.fn,"ax", at progbits,unique,0
 .globl fn
 .type fn, at function
 fn:
@@ -94,7 +94,7 @@ bar:
   callq fn at PLT
   nop
 
-.section .text,"ax", at progbits,unique,1
+.section .text.fn2,"ax", at progbits,unique,1
 .globl fn2
 .type fn2, at function
 fn2:




More information about the llvm-commits mailing list