[lld] r281647 - Make sure we create all necessary PT_LOADs.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 15 12:36:01 PDT 2016
Author: rafael
Date: Thu Sep 15 14:36:01 2016
New Revision: 281647
URL: http://llvm.org/viewvc/llvm-project?rev=281647&view=rev
Log:
Make sure we create all necessary PT_LOADs.
We were some times stopping early when using linker scripts.
Added:
lld/trunk/test/ELF/linkerscript/non-alloc.s
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=281647&r1=281646&r2=281647&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Sep 15 14:36:01 2016
@@ -969,8 +969,15 @@ std::vector<PhdrEntry<ELFT>> Writer<ELFT
Phdr RelRo(PT_GNU_RELRO, PF_R);
Phdr Note(PT_NOTE, PF_R);
for (OutputSectionBase<ELFT> *Sec : OutputSections) {
+ // Skip non alloc section.
+ // The reason we skip instead of just breaking out of the loop is the way
+ // we implement linker scripts. We always put the linker script sections
+ // first, which means that a non alloc section can be in the middle of the
+ // file. Continuing in here means it will be included in a PT_LOAD anyway.
+ // We should probably sort sections based of SHF_ALLOC even if they are
+ // on linker scripts.
if (!(Sec->getFlags() & SHF_ALLOC))
- break;
+ continue;
// If we meet TLS section then we create TLS header
// and put all TLS sections inside for futher use when
Added: lld/trunk/test/ELF/linkerscript/non-alloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/non-alloc.s?rev=281647&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/non-alloc.s (added)
+++ lld/trunk/test/ELF/linkerscript/non-alloc.s Thu Sep 15 14:36:01 2016
@@ -0,0 +1,28 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+
+# RUN: echo "SECTIONS { .foo : {*(foo)} }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t -shared
+# RUN: llvm-readobj -elf-output-style=GNU -s -l %t1 | FileCheck %s
+
+# Test that we create all necessary PT_LOAD. It is a harmless oddity that
+# foo ends in a PT_LOAD. We use to stop at the first non-alloc, causing
+# us to not create PT_LOAD for linker generated sections.
+
+# CHECK: Program Headers:
+# CHECK-NEXT: Type
+# CHECK-NEXT: PHDR
+# CHECK-NEXT: LOAD {{.*}} R
+# CHECK-NEXT: LOAD {{.*}} R E
+# CHECK-NEXT: LOAD {{.*}} RW
+
+# CHECK: Section to Segment mapping:
+# CHECK-NEXT: Segment Sections...
+# CHECK-NEXT: 00
+# CHECK-NEXT: 01 .foo .dynsym .hash .dynstr
+# CHECK-NEXT: 02 .text
+# CHECK-NEXT: 03 .dynamic
+
+nop
+.section foo
+.quad 0
More information about the llvm-commits
mailing list