diff options
author | Ed Maste <emaste@FreeBSD.org> | 2018-01-18 21:39:59 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2018-01-18 21:39:59 +0000 |
commit | 62de8f4add483ec1ef324999952bb8f773e60bae (patch) | |
tree | 485b8dd4cec6c58b99bdbc86199c5eee134fba1a /contrib | |
parent | cc877d7c33692726fa283771e252588648591980 (diff) | |
download | src-62de8f4add483ec1ef324999952bb8f773e60bae.tar.gz src-62de8f4add483ec1ef324999952bb8f773e60bae.zip |
lld: Fix incorrect physical address on self-referencing AT command.
When a section placement (AT) command references the section itself,
the physical address of the section in the ELF header was calculated
incorrectly due to alignment happening right after the location
pointer's value was captured.
The problem was diagnosed and the first version of the patch written
by Erick Reyes.
Obtained from: LLVM r322421 by Rafael Espindola
Notes
Notes:
svn path=/head/; revision=328144
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/llvm/tools/lld/ELF/LinkerScript.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/contrib/llvm/tools/lld/ELF/LinkerScript.cpp b/contrib/llvm/tools/lld/ELF/LinkerScript.cpp index 95848bd20bed..33a618952456 100644 --- a/contrib/llvm/tools/lld/ELF/LinkerScript.cpp +++ b/contrib/llvm/tools/lld/ELF/LinkerScript.cpp @@ -608,13 +608,6 @@ void LinkerScript::switchTo(OutputSection *Sec) { Ctx->OutSec = Sec; Ctx->OutSec->Addr = advance(0, Ctx->OutSec->Alignment); - - // If neither AT nor AT> is specified for an allocatable section, the linker - // will set the LMA such that the difference between VMA and LMA for the - // section is the same as the preceding output section in the same region - // https://sourceware.org/binutils/docs-2.20/ld/Output-Section-LMA.html - if (Ctx->LMAOffset) - Ctx->OutSec->LMAOffset = Ctx->LMAOffset(); } // This function searches for a memory region to place the given output @@ -662,6 +655,8 @@ void LinkerScript::assignOffsets(OutputSection *Sec) { if (Ctx->MemRegion) Dot = Ctx->MemRegionOffset[Ctx->MemRegion]; + switchTo(Sec); + if (Sec->LMAExpr) { uint64_t D = Dot; Ctx->LMAOffset = [=] { return Sec->LMAExpr().getValue() - D; }; @@ -676,7 +671,12 @@ void LinkerScript::assignOffsets(OutputSection *Sec) { } } - switchTo(Sec); + // If neither AT nor AT> is specified for an allocatable section, the linker + // will set the LMA such that the difference between VMA and LMA for the + // section is the same as the preceding output section in the same region + // https://sourceware.org/binutils/docs-2.20/ld/Output-Section-LMA.html + if (Ctx->LMAOffset) + Ctx->OutSec->LMAOffset = Ctx->LMAOffset(); // The Size previously denoted how many InputSections had been added to this // section, and was used for sorting SHF_LINK_ORDER sections. Reset it to |