}
template <class ELFT>
-bool elf::allocateHeaders(MutableArrayRef<PhdrEntry> Phdrs,
+bool elf::allocateHeaders(std::vector<PhdrEntry> &Phdrs,
ArrayRef<OutputSectionBase *> OutputSections,
uint64_t Min) {
auto FirstPTLoad =
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)
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);
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);
# 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
# 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
# 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
# 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.
# 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.
# 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
# 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