[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
Tue Feb 14 00:40:48 PST 2017
grimar updated this revision to Diff 88324.
grimar retitled this revision from "[ELF] - Added partial support for --emit-relocs (no --gc-section case)" to "[ELF] - Added support of linkerscript's "/DISCARD/" for --emit-relocs".
grimar edited the summary of this revision.
grimar added a comment.
- Rebased.
https://reviews.llvm.org/D29273
Files:
ELF/InputFiles.cpp
ELF/LinkerScript.cpp
test/ELF/linkerscript/emit-reloc-discard.s
Index: test/ELF/linkerscript/emit-reloc-discard.s
===================================================================
--- test/ELF/linkerscript/emit-reloc-discard.s
+++ test/ELF/linkerscript/emit-reloc-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: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -272,6 +272,15 @@
for (InputSectionBase<ELFT> *S : V) {
S->Live = false;
reportDiscarded(S);
+
+ // If we discard a section, we also should discard a dependent section.
+ // For example if linkerscript discards .text section,
+ // code below will discard .rel[a].text dependent section, which
+ // is impossible and useless to keep then. Used for --emit-relocs.
+ InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S);
+ if (!IS || !IS->DependentSection || !IS->DependentSection->Live)
+ continue;
+ discard({IS->DependentSection});
}
}
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -404,8 +404,14 @@
// 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) {
+ if (!isa<InputSection<ELFT>>(Target))
+ fatal(toString(this) + ": --emit-relocs for relocations sections "
+ "pointing to .eh_frame is not supported");
+ InputSection<ELFT> *RelocSec = make<InputSection<ELFT>>(this, &Sec, Name);
+ cast<InputSection<ELFT>>(Target)->DependentSection = RelocSec;
+ return RelocSec;
+ }
return nullptr;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29273.88324.patch
Type: text/x-patch
Size: 2247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170214/fb9aced2/attachment.bin>
More information about the llvm-commits
mailing list