[PATCH] D20378: [lld] Wrong section VMA/LMA in case of using linker scripts
Dima Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 18 19:10:14 PDT 2016
dstepanov updated this revision to Diff 57724.
dstepanov added a comment.
The findSection() routine is removed.
New linkerscript-repsection-va.s test case is added to check an issue.
Repository:
rL LLVM
http://reviews.llvm.org/D20378
Files:
ELF/LinkerScript.cpp
test/ELF/linkerscript-repsection-va.s
Index: test/ELF/linkerscript-repsection-va.s
===================================================================
--- test/ELF/linkerscript-repsection-va.s
+++ test/ELF/linkerscript-repsection-va.s
@@ -0,0 +1,24 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+
+# RUN: echo "SECTIONS {.foo : {*(.foo.*)} }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# 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 .foo 00000004 0000000000000158 DATA
+# CHECK-NEXT: 2 .foo 00000004 000000000000015c DATA
+# CHECK-NEXT: 3 .text 00000001 0000000000000160 TEXT DATA
+
+.global _start
+_start:
+ nop
+
+.section .foo.1,"a"
+foo1:
+ .long 0
+
+.section .foo.2,"aw"
+foo2:
+ .long 0
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -207,15 +207,6 @@
}
template <class ELFT>
-static OutputSectionBase<ELFT> *
-findSection(ArrayRef<OutputSectionBase<ELFT> *> V, StringRef Name) {
- for (OutputSectionBase<ELFT> *Sec : V)
- if (Sec->getName() == Name)
- return Sec;
- return nullptr;
-}
-
-template <class ELFT>
void LinkerScript<ELFT>::assignAddresses(
ArrayRef<OutputSectionBase<ELFT> *> Sections) {
// Orphan sections are sections present in the input files which
@@ -239,23 +230,27 @@
continue;
}
- OutputSectionBase<ELFT> *Sec = findSection<ELFT>(Sections, Cmd.SectionName);
- if (!Sec)
- continue;
+ // Find all the sections with required name. There can be more than
+ // ont section with such name, if the alignment, flags or type
+ // attribute differs.
+ for (OutputSectionBase<ELFT> *Sec : Sections) {
+ if (Sec->getName() != Cmd.SectionName)
+ continue;
- if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) {
- uintX_t TVA = Dot + ThreadBssOffset;
- TVA = alignTo(TVA, Sec->getAlign());
- Sec->setVA(TVA);
- ThreadBssOffset = TVA - Dot + Sec->getSize();
- continue;
- }
+ if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) {
+ uintX_t TVA = Dot + ThreadBssOffset;
+ TVA = alignTo(TVA, Sec->getAlign());
+ Sec->setVA(TVA);
+ ThreadBssOffset = TVA - Dot + Sec->getSize();
+ continue;
+ }
- if (Sec->getFlags() & SHF_ALLOC) {
- Dot = alignTo(Dot, Sec->getAlign());
- Sec->setVA(Dot);
- Dot += Sec->getSize();
- continue;
+ if (Sec->getFlags() & SHF_ALLOC) {
+ Dot = alignTo(Dot, Sec->getAlign());
+ Sec->setVA(Dot);
+ Dot += Sec->getSize();
+ continue;
+ }
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20378.57724.patch
Type: text/x-patch
Size: 2856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160519/8555d44d/attachment.bin>
More information about the llvm-commits
mailing list