[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
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 835706d..9077c8c 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -550,6 +550,7 @@
}
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 @@
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;