summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2017-07-25 08:29:29 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2017-07-25 08:29:29 +0000
commitf694d33f4cc91a922ca6f7cbaf34ab5507cab326 (patch)
tree70e877a87e5c0774f835a95ae3693260f31ed7ed
parent97c8e097904daa82c1ad28f3623d8a12a81ae73d (diff)
downloadbcm5719-llvm-f694d33f4cc91a922ca6f7cbaf34ab5507cab326.tar.gz
bcm5719-llvm-f694d33f4cc91a922ca6f7cbaf34ab5507cab326.zip
[ELF] - Fix calculation of memory region offset.
This is PR33714. Previously for each input section offset of memory region was incremented on a size of output section. That resulted in a wrong error message saying about overflow. Patch fixes that. Differential revision: https://reviews.llvm.org/D35803 llvm-svn: 308955
-rw-r--r--lld/ELF/LinkerScript.cpp3
-rw-r--r--lld/test/ELF/linkerscript/memory2.s14
2 files changed, 16 insertions, 1 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 835706d591e..9077c8c6152 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -550,6 +550,7 @@ uint64_t LinkerScript::advance(uint64_t Size, unsigned Align) {
}
void LinkerScript::output(InputSection *S) {
+ uint64_t Before = advance(0, 1);
uint64_t Pos = advance(S->getSize(), S->Alignment);
S->OutSecOff = Pos - S->getSize() - CurAddressState->OutSec->Addr;
@@ -563,7 +564,7 @@ void LinkerScript::output(InputSection *S) {
if (CurAddressState->MemRegion) {
uint64_t &CurOffset =
CurAddressState->MemRegionOffset[CurAddressState->MemRegion];
- CurOffset += CurAddressState->OutSec->Size;
+ CurOffset += Pos - Before;
uint64_t CurSize = CurOffset - CurAddressState->MemRegion->Origin;
if (CurSize > CurAddressState->MemRegion->Length) {
uint64_t OverflowAmt = CurSize - CurAddressState->MemRegion->Length;
diff --git a/lld/test/ELF/linkerscript/memory2.s b/lld/test/ELF/linkerscript/memory2.s
new file mode 100644
index 00000000000..2e7381fb891
--- /dev/null
+++ b/lld/test/ELF/linkerscript/memory2.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "MEMORY { ram (rwx) : ORIGIN = 0, LENGTH = 2K } \
+# RUN: SECTIONS { .text : { *(.text*) } > ram }" > %t.script
+# RUN: ld.lld -o %t2 --script %t.script %t
+
+.text
+.global _start
+_start:
+ .zero 1024
+
+.section .text.foo,"ax",%progbits
+foo:
+ nop
OpenPOWER on IntegriCloud