Fix header location with PHDR.
We were not subtracting its size, causing it to overlap with section
data.
Fixes PR34750.
llvm-svn: 314440
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index e72a20d..6fc3875 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -752,8 +752,7 @@
// unless there's a space for them.
uint64_t Base = Opt.HasSections ? alignDown(Min, Config->MaxPageSize) : 0;
if (HeaderSize <= Min - Base || Script->hasPhdrsCommands()) {
- Min = Opt.HasSections ? Base
- : alignDown(Min - HeaderSize, Config->MaxPageSize);
+ Min = alignDown(Min - HeaderSize, Config->MaxPageSize);
Out::ElfHeader->Addr = Min;
Out::ProgramHeaders->Addr = Min + Out::ElfHeader->Size;
return;