[lld] r270090 - Fix the function to set the section VMA/LMA fields in case of using
Dima Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Thu May 19 11:15:56 PDT 2016
Author: dstepanov
Date: Thu May 19 13:15:54 2016
New Revision: 270090
URL: http://llvm.org/viewvc/llvm-project?rev=270090&view=rev
Log:
Fix the function to set the section VMA/LMA fields in case of using
the linker script. The cycle in the ELF/LinkerScript.cpp:assignAddresses()
routine will be used to go through all the sections and set all the
addresses correctly.
Add new test to check this case.
Added:
lld/trunk/test/ELF/linkerscript-repsection-va.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=270090&r1=270089&r2=270090&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu May 19 13:15:54 2016
@@ -207,15 +207,6 @@ bool LinkerScript<ELFT>::shouldKeep(Inpu
}
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 @@ void LinkerScript<ELFT>::assignAddresses
continue;
}
- OutputSectionBase<ELFT> *Sec = findSection<ELFT>(Sections, Cmd.SectionName);
- if (!Sec)
- 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;
+ // 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_ALLOC) {
+ Dot = alignTo(Dot, Sec->getAlign());
+ Sec->setVA(Dot);
+ Dot += Sec->getSize();
+ continue;
+ }
}
}
}
Added: lld/trunk/test/ELF/linkerscript-repsection-va.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript-repsection-va.s?rev=270090&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript-repsection-va.s (added)
+++ lld/trunk/test/ELF/linkerscript-repsection-va.s Thu May 19 13:15:54 2016
@@ -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
More information about the llvm-commits
mailing list