[lld] r314440 - Fix header location with PHDR.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 28 11:12:13 PDT 2017
Author: rafael
Date: Thu Sep 28 11:12:13 2017
New Revision: 314440
URL: http://llvm.org/viewvc/llvm-project?rev=314440&view=rev
Log:
Fix header location with PHDR.
We were not subtracting its size, causing it to overlap with section
data.
Fixes PR34750.
Added:
lld/trunk/test/ELF/linkerscript/header-phdr.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=314440&r1=314439&r2=314440&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Sep 28 11:12:13 2017
@@ -752,8 +752,7 @@ void LinkerScript::allocateHeaders(std::
// 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;
Added: lld/trunk/test/ELF/linkerscript/header-phdr.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/header-phdr.s?rev=314440&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/header-phdr.s (added)
+++ lld/trunk/test/ELF/linkerscript/header-phdr.s Thu Sep 28 11:12:13 2017
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "PHDRS { foobar PT_LOAD FILEHDR PHDRS; } \
+# RUN: SECTIONS { . = 0x1000; .abc : { *(.zed) } : foobar }" > %t.script
+# RUN: ld.lld --script %t.script %t.o -o %t
+# RUN: llvm-readelf -l -S -W %t | FileCheck %s
+
+.section .zed, "a"
+.zero 4
+
+
+# CHECK: [ 1] .abc PROGBITS 0000000000001000 001000 000004 00 A 0 0 1
+# CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x001004 0x001004 R E 0x1000
More information about the llvm-commits
mailing list