[PATCH] D29273: [ELF] - Added support of linkerscript's "/DISCARD/" for --emit-relocs

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 14:32:38 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL295488: [ELF] - Added support of linkerscript's "/DISCARD/" for --emit-relocs (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D29273?vs=88745&id=88963#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29273

Files:
  lld/trunk/ELF/InputFiles.cpp
  lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s
  lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s


Index: lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s
+++ lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.eh_frame) } }" > %t.script
+# RUN: ld.lld --emit-relocs --script %t.script %t1.o -o %t
+# RUN: llvm-objdump -section-headers %t | FileCheck %s
+
+# CHECK-NOT: .rela.eh_frame
+
+.section .foo,"ax", at progbits
+.cfi_startproc
+.cfi_endproc
Index: lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s
+++ lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.bbb) } }" > %t.script
+# RUN: ld.lld --emit-relocs --script %t.script %t.o -o %t1
+# RUN: llvm-readobj -r %t1 | FileCheck %s
+
+# CHECK:      Relocations [
+# CHECK-NEXT: ]
+
+.section .aaa,"", at progbits
+.Lfoo:
+
+.section .bbb,"", at progbits
+.long .Lfoo
Index: lld/trunk/ELF/InputFiles.cpp
===================================================================
--- lld/trunk/ELF/InputFiles.cpp
+++ lld/trunk/ELF/InputFiles.cpp
@@ -406,8 +406,12 @@
     // from the output, so returning `nullptr` for the normal case.
     // However, if -emit-relocs is given, we need to leave them in the output.
     // (Some post link analysis tools need this information.)
-    if (Config->EmitRelocs)
-      return make<InputSection<ELFT>>(this, &Sec, Name);
+    if (Config->EmitRelocs) {
+      InputSection<ELFT> *RelocSec = make<InputSection<ELFT>>(this, &Sec, Name);
+      // We will not emit relocation section if target was discarded.
+      Target->DependentSections.push_back(RelocSec);
+      return RelocSec;
+    }
     return nullptr;
   }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29273.88963.patch
Type: text/x-patch
Size: 2087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170217/df376ace/attachment.bin>


More information about the llvm-commits mailing list