[lld] r295488 - [ELF] - Added support of linkerscript's "/DISCARD/" for --emit-relocs
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 17 11:46:47 PST 2017
Author: grimar
Date: Fri Feb 17 13:46:47 2017
New Revision: 295488
URL: http://llvm.org/viewvc/llvm-project?rev=295488&view=rev
Log:
[ELF] - Added support of linkerscript's "/DISCARD/" for --emit-relocs
Previously LLD crashed on on provided testcases because "/DISCARD/" was
not supported. Patch implements that.
After this I think there is no known issues with --emit-relocs implementation
required for linux kernel linking.
Differential revision: https://reviews.llvm.org/D29273
Added:
lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s
lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s
Modified:
lld/trunk/ELF/InputFiles.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=295488&r1=295487&r2=295488&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Feb 17 13:46:47 2017
@@ -406,8 +406,12 @@ elf::ObjectFile<ELFT>::createInputSectio
// 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;
}
}
Added: lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s?rev=295488&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s (added)
+++ lld/trunk/test/ELF/linkerscript/emit-relocs-discard.s Fri Feb 17 13:46:47 2017
@@ -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
Added: lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s?rev=295488&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s (added)
+++ lld/trunk/test/ELF/linkerscript/emit-relocs-ehframe-discard.s Fri Feb 17 13:46:47 2017
@@ -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
More information about the llvm-commits
mailing list