Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -91,20 +91,22 @@ return false; } -template static void assignSymbol(SymbolAssignment *Cmd) { - // If there are sections, then let the value be assigned later in - // `assignAddresses`. - if (ScriptConfig->HasSections) +// Sets value of a symbol. Two kinds of symbols are processed: synthetic +// symbols, whose value is an offset from beginning of section and regular +// symbols whose value is absolute. +template +static void assignSymbol(SymbolAssignment *Cmd, typename ELFT::uint Dot = 0) { + if (!Cmd->Sym) return; - uint64_t Value = Cmd->Expression(0); - if (Cmd->Expression.IsAbsolute()) { - cast>(Cmd->Sym)->Value = Value; - } else { - const OutputSectionBase *Sec = Cmd->Expression.Section(); - if (Sec) - cast(Cmd->Sym)->Value = Value - Sec->Addr; + if (auto *Body = dyn_cast(Cmd->Sym)) { + Body->Section = Cmd->Expression.Section(); + if (Body->Section) + Body->Value = Cmd->Expression(Dot) - Body->Section->Addr; + return; } + + cast>(Cmd->Sym)->Value = Cmd->Expression(Dot); } template static void addSymbol(SymbolAssignment *Cmd) { @@ -123,7 +125,11 @@ Cmd->Sym = addRegular(Cmd); else Cmd->Sym = addSynthetic(Cmd); - assignSymbol(Cmd); + + // If there are sections, then let the value be assigned later in + // `assignAddresses`. + if (!ScriptConfig->HasSections) + assignSymbol(Cmd); } bool SymbolAssignment::classof(const BaseCommand *C) { @@ -371,25 +377,6 @@ addSection(Factory, S, getOutputSectionName(S->Name)); } -// Sets value of a section-defined symbol. Two kinds of -// symbols are processed: synthetic symbols, whose value -// is an offset from beginning of section and regular -// symbols whose value is absolute. -template -static void assignSectionSymbol(SymbolAssignment *Cmd, - typename ELFT::uint Value) { - if (!Cmd->Sym) - return; - - if (auto *Body = dyn_cast(Cmd->Sym)) { - Body->Section = Cmd->Expression.Section(); - Body->Value = Cmd->Expression(Value) - Body->Section->Addr; - return; - } - auto *Body = cast>(Cmd->Sym); - Body->Value = Cmd->Expression(Value); -} - template static bool isTbss(OutputSectionBase *Sec) { return (Sec->Flags & SHF_TLS) && Sec->Type == SHT_NOBITS; } @@ -472,7 +459,7 @@ CurOutSec->Size = Dot - CurOutSec->Addr; return; } - assignSectionSymbol(AssignCmd, Dot); + assignSymbol(AssignCmd, Dot); return; } @@ -794,7 +781,7 @@ if (Cmd->Name == ".") { Dot = Cmd->Expression(Dot); } else if (Cmd->Sym) { - assignSectionSymbol(Cmd, Dot); + assignSymbol(Cmd, Dot); } continue; }