[lld] r292644 - Don't create a bogus PT_PHDR if we don't allocate the headers.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 12:46:15 PST 2017
Author: rafael
Date: Fri Jan 20 14:46:15 2017
New Revision: 292644
URL: http://llvm.org/viewvc/llvm-project?rev=292644&view=rev
Log:
Don't create a bogus PT_PHDR if we don't allocate the headers.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/ELF/Writer.h
lld/trunk/test/ELF/linkerscript/empty-load.s
lld/trunk/test/ELF/linkerscript/no-space.s
lld/trunk/test/ELF/linkerscript/non-alloc.s
lld/trunk/test/ELF/ttext-tdata-tbss.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=292644&r1=292643&r2=292644&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Jan 20 14:46:15 2017
@@ -1330,7 +1330,7 @@ template <class ELFT> void Writer<ELFT>:
}
template <class ELFT>
-bool elf::allocateHeaders(MutableArrayRef<PhdrEntry> Phdrs,
+bool elf::allocateHeaders(std::vector<PhdrEntry> &Phdrs,
ArrayRef<OutputSectionBase *> OutputSections,
uint64_t Min) {
auto FirstPTLoad =
@@ -1340,8 +1340,14 @@ bool elf::allocateHeaders(MutableArrayRe
return false;
uint64_t HeaderSize = getHeaderSize<ELFT>();
- if (HeaderSize > Min)
+ if (HeaderSize > Min) {
+ auto PhdrI =
+ std::find_if(Phdrs.begin(), Phdrs.end(),
+ [](const PhdrEntry &E) { return E.p_type == PT_PHDR; });
+ if (PhdrI != Phdrs.end())
+ Phdrs.erase(PhdrI);
return false;
+ }
Min = alignDown(Min - HeaderSize, Config->MaxPageSize);
if (!ScriptConfig->HasSections)
@@ -1744,16 +1750,16 @@ template void elf::writeResult<ELF32BE>(
template void elf::writeResult<ELF64LE>();
template void elf::writeResult<ELF64BE>();
-template bool elf::allocateHeaders<ELF32LE>(MutableArrayRef<PhdrEntry>,
+template bool elf::allocateHeaders<ELF32LE>(std::vector<PhdrEntry> &,
ArrayRef<OutputSectionBase *>,
uint64_t);
-template bool elf::allocateHeaders<ELF32BE>(MutableArrayRef<PhdrEntry>,
+template bool elf::allocateHeaders<ELF32BE>(std::vector<PhdrEntry> &,
ArrayRef<OutputSectionBase *>,
uint64_t);
-template bool elf::allocateHeaders<ELF64LE>(MutableArrayRef<PhdrEntry>,
+template bool elf::allocateHeaders<ELF64LE>(std::vector<PhdrEntry> &,
ArrayRef<OutputSectionBase *>,
uint64_t);
-template bool elf::allocateHeaders<ELF64BE>(MutableArrayRef<PhdrEntry>,
+template bool elf::allocateHeaders<ELF64BE>(std::vector<PhdrEntry> &,
ArrayRef<OutputSectionBase *>,
uint64_t);
Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=292644&r1=292643&r2=292644&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Fri Jan 20 14:46:15 2017
@@ -50,7 +50,7 @@ struct PhdrEntry {
llvm::StringRef getOutputSectionName(llvm::StringRef Name);
template <class ELFT>
-bool allocateHeaders(llvm::MutableArrayRef<PhdrEntry>,
+bool allocateHeaders(std::vector<PhdrEntry> &,
llvm::ArrayRef<OutputSectionBase *>, uint64_t Min);
template <class ELFT> void reportDiscarded(InputSectionBase<ELFT> *IS);
Modified: lld/trunk/test/ELF/linkerscript/empty-load.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/empty-load.s?rev=292644&r1=292643&r2=292644&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/empty-load.s (original)
+++ lld/trunk/test/ELF/linkerscript/empty-load.s Fri Jan 20 14:46:15 2017
@@ -5,8 +5,7 @@
# RUN: llvm-objdump -private-headers %t1 | FileCheck %s
## We expect 2 PT_LOAD segments
-# CHECK: PHDR
-# CHECK-NEXT: filesz {{0x[0-9a-f]+}} memsz {{0x[0-9a-f]+}} flags r--
+# CHECK: Program Header:
# CHECK-NEXT: LOAD
# CHECK-NEXT: filesz {{0x[0-9a-f]+}} memsz {{0x[0-9a-f]+}} flags rw-
# CHECK-NEXT: LOAD
Modified: lld/trunk/test/ELF/linkerscript/no-space.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/no-space.s?rev=292644&r1=292643&r2=292644&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/no-space.s (original)
+++ lld/trunk/test/ELF/linkerscript/no-space.s Fri Jan 20 14:46:15 2017
@@ -10,17 +10,15 @@
# RUN: llvm-readobj -elf-output-style=GNU -l %t | FileCheck %s
# There is not enough address space available for the header, so just start the PT_LOAD
-# after it.
+# after it. Don't create a PT_PHDR as the header is not allocated.
# CHECK: Program Headers:
# CHECK-NEXT: Type Offset VirtAddr PhysAddr
-# CHECK-NEXT: PHDR
# CHECK-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000
# CHECK: Section to Segment mapping:
# CHECK-NEXT: Segment Sections...
-# CHECK-NEXT: 00
-# CHECK-NEXT: 01 foo .text .dynsym .hash .dynstr
+# CHECK-NEXT: 00 foo .text .dynsym .hash .dynstr
.section foo, "a"
.quad 0
Modified: lld/trunk/test/ELF/linkerscript/non-alloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/non-alloc.s?rev=292644&r1=292643&r2=292644&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/non-alloc.s (original)
+++ lld/trunk/test/ELF/linkerscript/non-alloc.s Fri Jan 20 14:46:15 2017
@@ -10,15 +10,13 @@
# CHECK: Program Headers:
# CHECK-NEXT: Type
-# CHECK-NEXT: PHDR
# CHECK-NEXT: LOAD {{.*}} R E
# CHECK-NEXT: LOAD {{.*}} RW
# CHECK: Section to Segment mapping:
# CHECK-NEXT: Segment Sections...
-# CHECK-NEXT: 00
-# CHECK-NEXT: 01 .text .dynsym .hash .dynstr
-# CHECK-NEXT: 02 .dynamic
+# CHECK-NEXT: 00 .text .dynsym .hash .dynstr
+# CHECK-NEXT: 01 .dynamic
nop
.section foo
Modified: lld/trunk/test/ELF/ttext-tdata-tbss.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ttext-tdata-tbss.s?rev=292644&r1=292643&r2=292644&view=diff
==============================================================================
--- lld/trunk/test/ELF/ttext-tdata-tbss.s (original)
+++ lld/trunk/test/ELF/ttext-tdata-tbss.s Fri Jan 20 14:46:15 2017
@@ -9,7 +9,8 @@
# CHECK-NEXT: .aw PROGBITS 0000000000202000 002000 000008
# CHECK-NEXT: .data PROGBITS 0000000000202008 002008 000008
# CHECK-NEXT: .bss NOBITS 0000000000202010 002010 000008
-# CHECK: PHDR
+# CHECK: Type
+# CHECK-NEXT: PHDR
# CHECK-NEXT: LOAD 0x000000 0x0000000000200000
## With .text at 0 there is no space to allocate the headers.
@@ -20,7 +21,7 @@
# USER1-NEXT: .bss NOBITS 0000000000008000 002008 000008
# USER1-NEXT: .rodata PROGBITS 0000000000009000 003000 000008
# USER1-NEXT: .aw PROGBITS 000000000000a000 004000 000008
-# USER1: PHDR
+# USER1: Type
# USER1-NEXT: LOAD 0x001000 0x0000000000000000
## With .text at 0x1000 there is space to allocate the headers.
@@ -31,7 +32,8 @@
# USER2-NEXT: .bss NOBITS 0000000000008000 002008 000008
# USER2-NEXT: .rodata PROGBITS 0000000000009000 003000 000008
# USER2-NEXT: .aw PROGBITS 000000000000a000 004000 000008
-# USER2: PHDR
+# USER2: Type
+# USER2-NEXT: PHDR
# USER2-NEXT: LOAD 0x000000 0x0000000000000000
## With .text well above 200000 we don't need to change the image base
@@ -42,7 +44,8 @@
# USER3-NEX: .aw PROGBITS 0000000000203000 003000 000008
# USER3-NEX: .data PROGBITS 0000000000203008 003008 000008
# USER3-NEX: .bss NOBITS 0000000000203010 003010 000008
-# USER3: PHDR
+# USER3: Type
+# USER3-NEXT: PHDR
# USER3-NEXT: LOAD 0x000000 0x0000000000200000
.text
More information about the llvm-commits
mailing list