[lld] r325213 - [ELF] Simplify handling of AT section attribute.
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 22:13:52 PST 2018
Author: ikudrin
Date: Wed Feb 14 22:13:52 2018
New Revision: 325213
URL: http://llvm.org/viewvc/llvm-project?rev=325213&view=rev
Log:
[ELF] Simplify handling of AT section attribute.
This also makes the behavior close to GNU ld's.
Differential Revision: https://reviews.llvm.org/D43284
Added:
lld/trunk/test/ELF/linkerscript/at4.s
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/ELF/Writer.h
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=325213&r1=325212&r2=325213&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Feb 14 22:13:52 2018
@@ -821,8 +821,6 @@ void PhdrEntry::add(OutputSection *Sec)
p_align = std::max(p_align, Sec->Alignment);
if (p_type == PT_LOAD)
Sec->PtLoad = this;
- if (Sec->LMAExpr)
- ASectionHasLMA = true;
}
// The beginning and the ending of .rel[a].plt section are marked
@@ -1697,9 +1695,11 @@ template <class ELFT> std::vector<PhdrEn
// (e.g. executable or writable). There is one phdr for each segment.
// Therefore, we need to create a new phdr when the next section has
// different flags or is loaded at a discontiguous address using AT linker
- // script command.
+ // script command. At the same time, we don't want to create a separate
+ // load segment for the headers, even if the first output section has
+ // an AT attribute.
uint64_t NewFlags = computeFlags(Sec->getPhdrFlags());
- if ((Sec->LMAExpr && Load->ASectionHasLMA) ||
+ if ((Sec->LMAExpr && Load->LastSec != Out::ProgramHeaders) ||
Sec->MemRegion != Load->FirstSec->MemRegion || Flags != NewFlags) {
Load = AddHdr(PT_LOAD, NewFlags);
Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=325213&r1=325212&r2=325213&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Wed Feb 14 22:13:52 2018
@@ -45,11 +45,6 @@ struct PhdrEntry {
OutputSection *LastSec = nullptr;
bool HasLMA = false;
- // True if one of the sections in this program header has a LMA specified via
- // linker script: AT(addr). We never allow 2 or more sections with LMA in the
- // same program header.
- bool ASectionHasLMA = false;
-
uint64_t LMAOffset = 0;
};
Added: lld/trunk/test/ELF/linkerscript/at4.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/at4.s?rev=325213&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/at4.s (added)
+++ lld/trunk/test/ELF/linkerscript/at4.s Wed Feb 14 22:13:52 2018
@@ -0,0 +1,36 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { \
+# RUN: . = 0x1000; \
+# RUN: .aaa : { *(.aaa) } \
+# RUN: .bbb : AT(0x2008) { *(.bbb) } \
+# RUN: .ccc : { *(.ccc) } \
+# RUN: }" > %t.script
+# RUN: ld.lld %t --script %t.script -o %t2
+# RUN: llvm-readobj -program-headers %t2 | FileCheck %s
+
+# CHECK: Type: PT_LOAD
+# CHECK-NEXT: Offset: 0x1000
+# CHECK-NEXT: VirtualAddress: 0x1000
+# CHECK-NEXT: PhysicalAddress: 0x1000
+# CHECK-NEXT: FileSize: 8
+# CHECK-NEXT: MemSize: 8
+# CHECK: Type: PT_LOAD
+# CHECK-NEXT: Offset: 0x1008
+# CHECK-NEXT: VirtualAddress: 0x1008
+# CHECK-NEXT: PhysicalAddress: 0x2008
+# CHECK-NEXT: FileSize: 17
+# CHECK-NEXT: MemSize: 17
+
+.global _start
+_start:
+ nop
+
+.section .aaa, "a"
+.quad 0
+
+.section .bbb, "a"
+.quad 0
+
+.section .ccc, "a"
+.quad 0
More information about the llvm-commits
mailing list