[lld] r328479 - This is PR36799.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 26 01:58:16 PDT 2018
Author: grimar
Date: Mon Mar 26 01:58:16 2018
New Revision: 328479
URL: http://llvm.org/viewvc/llvm-project?rev=328479&view=rev
Log:
This is PR36799.
Currently, we might have a bug with scripts like below:
.foo : ALIGN(8)
{
*(.foo)
} > ram
because do not expand the memory region when doing ALIGN.
This might result in file range overlaps. The patch fixes the issue.
Differential revision: https://reviews.llvm.org/D44730
Added:
lld/trunk/test/ELF/linkerscript/memory-region-alignment.test
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=328479&r1=328478&r2=328479&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Mar 26 01:58:16 2018
@@ -112,8 +112,7 @@ static void expandMemoryRegion(MemoryReg
"': overflowed by " + Twine(NewSize - MemRegion->Length) + " bytes");
}
-void LinkerScript::expandOutputSection(uint64_t Size) {
- Ctx->OutSec->Size += Size;
+void LinkerScript::expandMemoryRegions(uint64_t Size) {
if (Ctx->MemRegion)
expandMemoryRegion(Ctx->MemRegion, Size, Ctx->MemRegion->Name,
Ctx->OutSec->Name);
@@ -122,6 +121,11 @@ void LinkerScript::expandOutputSection(u
Ctx->OutSec->Name);
}
+void LinkerScript::expandOutputSection(uint64_t Size) {
+ Ctx->OutSec->Size += Size;
+ expandMemoryRegions(Size);
+}
+
void LinkerScript::setDot(Expr E, const Twine &Loc, bool InSec) {
uint64_t Val = E().getValue();
if (Val < Dot && InSec)
@@ -707,9 +711,11 @@ void LinkerScript::output(InputSection *
void LinkerScript::switchTo(OutputSection *Sec) {
if (Ctx->OutSec == Sec)
return;
-
Ctx->OutSec = Sec;
+
+ uint64_t Before = advance(0, 1);
Ctx->OutSec->Addr = advance(0, Ctx->OutSec->Alignment);
+ expandMemoryRegions(Ctx->OutSec->Addr - Before);
}
// This function searches for a memory region to place the given output
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=328479&r1=328478&r2=328479&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Mon Mar 26 01:58:16 2018
@@ -232,6 +232,7 @@ class LinkerScript final {
void assignSymbol(SymbolAssignment *Cmd, bool InSec);
void setDot(Expr E, const Twine &Loc, bool InSec);
void expandOutputSection(uint64_t Size);
+ void expandMemoryRegions(uint64_t Size);
std::vector<InputSection *>
computeInputSections(const InputSectionDescription *);
Added: lld/trunk/test/ELF/linkerscript/memory-region-alignment.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/memory-region-alignment.test?rev=328479&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/memory-region-alignment.test (added)
+++ lld/trunk/test/ELF/linkerscript/memory-region-alignment.test Mon Mar 26 01:58:16 2018
@@ -0,0 +1,58 @@
+# REQUIRES: x86
+# RUN: echo '.section .foo,"a"; .quad 0; .section .zed,"M", at progbits,1; .byte 0' > %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+MEMORY {
+ ram (rwx): org = 0x1, len = 96K
+}
+
+SECTIONS {
+ .foo : ALIGN(8) {
+ *(.foo)
+ } > ram
+
+ .zed : {
+ *(.zed)
+ } > ram
+}
+
+# RUN: ld.lld %t.o -o %t --script %s
+# RUN: llvm-readobj -sections %t | FileCheck %s
+
+# CHECK: Name: .foo
+# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: 0x8
+# CHECK-NEXT: Offset: 0x1008
+# CHECK-NEXT: Size: 8
+
+# CHECK: Name: .text
+# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: SHF_EXECINSTR
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: 0x10
+# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Size: 0
+
+# CHECK: Name: .zed
+# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_MERGE
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: 0x10
+# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Size: 1
+
+# CHECK: Name: .comment
+# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_MERGE
+# CHECK-NEXT: SHF_STRINGS
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: 0x0
+# CHECK-NEXT: Offset: 0x1011
+# CHECK-NEXT: Size: 8
More information about the llvm-commits
mailing list