[lld] r295324 - Ignore relocation sections in linker scripts.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 06:36:10 PST 2017


Author: rafael
Date: Thu Feb 16 08:36:09 2017
New Revision: 295324

URL: http://llvm.org/viewvc/llvm-project?rev=295324&view=rev
Log:
Ignore relocation sections in linker scripts.

Unfortunately, the common way of writing linker scripts seems to be
to get the output of ld.bfd --verbose and edit it a bit.

Also unfortunately, the bfd default script contains things like

.rela.dyn : { *(... .rela.data ...) }

but bfd actually ignores that for -emit-relocs, so we have to do the
same.

Added:
    lld/trunk/test/ELF/linkerscript/emit-reloc.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=295324&r1=295323&r2=295324&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Feb 16 08:36:09 2017
@@ -234,6 +234,11 @@ void LinkerScript<ELFT>::computeInputSec
     for (InputSectionBase<ELFT> *S : Symtab<ELFT>::X->Sections) {
       if (!S->Live || S->Assigned)
         continue;
+      // For -emit-relocs we have to ignore entries like
+      //   .rela.dyn : { *(.rela.data) }
+      // which are common because they are in the default bfd script.
+      if (S->Type == SHT_REL || S->Type == SHT_RELA)
+        continue;
 
       StringRef Filename = basename(S);
       if (!I->FilePat.match(Filename) || Pat.ExcludedFilePat.match(Filename))

Added: lld/trunk/test/ELF/linkerscript/emit-reloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/emit-reloc.s?rev=295324&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/emit-reloc.s (added)
+++ lld/trunk/test/ELF/linkerscript/emit-reloc.s Thu Feb 16 08:36:09 2017
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "SECTIONS { .rela.dyn : { *(.rela.data) } }" > %t.script
+# RUN: ld.lld -T %t.script --emit-relocs %t.o -o %t.so -shared
+# RUN: llvm-readobj -r %t.so | FileCheck %s
+
+.data
+.quad .foo
+
+# CHECK:      Relocations [
+# CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
+# CHECK-NEXT:     0x66 R_X86_64_64 .foo 0x0
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Section ({{.*}}) .rela.data {
+# CHECK-NEXT:     0x66 R_X86_64_64 .foo 0x0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]




More information about the llvm-commits mailing list