diff options
-rw-r--r-- | lld/ELF/Writer.cpp | 18 | ||||
-rw-r--r-- | lld/ELF/Writer.h | 2 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/empty-load.s | 3 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/no-space.s | 6 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/non-alloc.s | 6 | ||||
-rw-r--r-- | lld/test/ELF/ttext-tdata-tbss.s | 11 |
6 files changed, 25 insertions, 21 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 30ba84868f7..7e49ce0e9db 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1330,7 +1330,7 @@ template <class ELFT> void Writer<ELFT>::fixSectionAlignments() { } 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(MutableArrayRef<PhdrEntry> Phdrs, 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); diff --git a/lld/ELF/Writer.h b/lld/ELF/Writer.h index 7942fa2cc9b..afecdd04901 100644 --- a/lld/ELF/Writer.h +++ b/lld/ELF/Writer.h @@ -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); diff --git a/lld/test/ELF/linkerscript/empty-load.s b/lld/test/ELF/linkerscript/empty-load.s index 0a87d572747..ea58d71402d 100644 --- a/lld/test/ELF/linkerscript/empty-load.s +++ b/lld/test/ELF/linkerscript/empty-load.s @@ -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 diff --git a/lld/test/ELF/linkerscript/no-space.s b/lld/test/ELF/linkerscript/no-space.s index a96797269e4..fc9e5b13325 100644 --- a/lld/test/ELF/linkerscript/no-space.s +++ b/lld/test/ELF/linkerscript/no-space.s @@ -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 diff --git a/lld/test/ELF/linkerscript/non-alloc.s b/lld/test/ELF/linkerscript/non-alloc.s index 2060129a802..861c74996b8 100644 --- a/lld/test/ELF/linkerscript/non-alloc.s +++ b/lld/test/ELF/linkerscript/non-alloc.s @@ -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 diff --git a/lld/test/ELF/ttext-tdata-tbss.s b/lld/test/ELF/ttext-tdata-tbss.s index c31c56e7569..a52d88b4957 100644 --- a/lld/test/ELF/ttext-tdata-tbss.s +++ b/lld/test/ELF/ttext-tdata-tbss.s @@ -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 |