lld: Fix for ld.lld does not accept "AT" syntax for declaring LMA region

AT> lma_region expression allows to specify the memory region
for section load address.

Should fix [upstream LLVM] PR35684.

LLVM review: https://reviews.llvm.org/D41397

Obtained from:	LLVM r322359 by George Rimar
This commit is contained in:
emaste 2018-01-18 21:38:21 +00:00
parent f629be4b46
commit 2fba69a43f
3 changed files with 18 additions and 0 deletions

View File

@ -667,6 +667,15 @@ void LinkerScript::assignOffsets(OutputSection *Sec) {
Ctx->LMAOffset = [=] { return Sec->LMAExpr().getValue() - D; };
}
if (!Sec->LMARegionName.empty()) {
if (MemoryRegion *MR = MemoryRegions.lookup(Sec->LMARegionName)) {
uint64_t Offset = MR->Origin - Dot;
Ctx->LMAOffset = [=] { return Offset; };
} else {
error("memory region '" + Sec->LMARegionName + "' not declared");
}
}
switchTo(Sec);
// The Size previously denoted how many InputSections had been added to this

View File

@ -99,6 +99,7 @@ class OutputSection final : public BaseCommand, public SectionBase {
ConstraintKind Constraint = ConstraintKind::NoConstraint;
std::string Location;
std::string MemoryRegionName;
std::string LMARegionName;
bool Noload = false;
template <class ELFT> void finalize();

View File

@ -709,6 +709,14 @@ OutputSection *ScriptParser::readOutputSectionDescription(StringRef OutSec) {
if (consume(">"))
Cmd->MemoryRegionName = next();
if (consume("AT")) {
expect(">");
Cmd->LMARegionName = next();
}
if (Cmd->LMAExpr && !Cmd->LMARegionName.empty())
error("section can't have both LMA and a load region");
Cmd->Phdrs = readOutputSectionPhdrs();
if (consume("="))