[PATCH] D32749: [LLD][ELF] Fix problems with fabricateDefaultCommands() and --section-start
Peter Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 3 01:58:07 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL302007: [ELF] Fix problems with fabricateDefaultCommands() and --section-start (authored by psmith).
Changed prior to commit:
https://reviews.llvm.org/D32749?vs=97445&id=97571#toc
Repository:
rL LLVM
https://reviews.llvm.org/D32749
Files:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/sectionstart-noallochdr.s
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -252,7 +252,7 @@
} else {
if (!Script->Opt.HasSections) {
fixSectionAlignments();
- Script->fabricateDefaultCommands(Config->MaxPageSize);
+ Script->fabricateDefaultCommands(AllocateHeader);
}
Script->synchronize();
Script->assignAddresses(Phdrs);
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -428,13 +428,12 @@
if (AllocateHeader)
StartAddr += elf::getHeaderSize();
- // The Sections with -T<section> are sorted in order of ascending address
- // we must use this if it is lower than StartAddr as calls to setDot() must
- // be monotonically increasing
- if (!Config->SectionStartMap.empty()) {
- uint64_t LowestSecStart = Config->SectionStartMap.begin()->second;
- StartAddr = std::min(StartAddr, LowestSecStart);
- }
+ // The Sections with -T<section> have been sorted in order of ascending
+ // address. We must lower StartAddr if the lowest -T<section address> as
+ // calls to setDot() must be monotonically increasing.
+ for (auto& KV : Config->SectionStartMap)
+ StartAddr = std::min(StartAddr, KV.second);
+
Commands.push_back(
make<SymbolAssignment>(".", [=] { return StartAddr; }, ""));
@@ -444,17 +443,19 @@
if (!(Sec->Flags & SHF_ALLOC))
continue;
+ auto *OSCmd = make<OutputSectionCommand>(Sec->Name);
+ OSCmd->Sec = Sec;
+
+ // Prefer user supplied address over additional alignment constraint
auto I = Config->SectionStartMap.find(Sec->Name);
if (I != Config->SectionStartMap.end())
Commands.push_back(
make<SymbolAssignment>(".", [=] { return I->second; }, ""));
-
- auto *OSCmd = make<OutputSectionCommand>(Sec->Name);
- OSCmd->Sec = Sec;
- if (Sec->PageAlign)
+ else if (Sec->PageAlign)
OSCmd->AddrExpr = [=] {
return alignTo(Script->getDot(), Config->MaxPageSize);
};
+
Commands.push_back(OSCmd);
if (Sec->Sections.size()) {
auto *ISD = make<InputSectionDescription>("");
Index: lld/trunk/test/ELF/sectionstart-noallochdr.s
===================================================================
--- lld/trunk/test/ELF/sectionstart-noallochdr.s
+++ lld/trunk/test/ELF/sectionstart-noallochdr.s
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o --section-start .data=0x20 \
+# RUN: --section-start .bss=0x30 --section-start .text=0x10 -o %t1
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+
+# CHECK: Sections:
+# CHECK-NEXT: Idx Name Size Address Type
+# CHECK-NEXT: 0 00000000 0000000000000000
+# CHECK-NEXT: 1 .text 00000001 0000000000000010 TEXT DATA
+# CHECK-NEXT: 2 .data 00000004 0000000000000020 DATA
+# CHECK-NEXT: 3 .bss 00000004 0000000000000030 BSS
+
+.text
+.globl _start
+_start:
+ nop
+
+.data
+.long 0
+
+.bss
+.zero 4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32749.97571.patch
Type: text/x-patch
Size: 3187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170503/03b8f66b/attachment.bin>
More information about the llvm-commits
mailing list