Index: lld/trunk/ELF/Symbols.h =================================================================== --- lld/trunk/ELF/Symbols.h +++ lld/trunk/ELF/Symbols.h @@ -390,17 +390,16 @@ // Some linker-generated symbols need to be created as // DefinedRegular symbols. template struct ElfSym { + typedef std::pair *, DefinedRegular *> SymPair; + // The content for _etext and etext symbols. - static DefinedRegular *Etext; - static DefinedRegular *Etext2; + static SymPair Etext; // The content for _edata and edata symbols. - static DefinedRegular *Edata; - static DefinedRegular *Edata2; + static SymPair Edata; // The content for _end and end symbols. - static DefinedRegular *End; - static DefinedRegular *End2; + static SymPair End; // The content for _gp symbol for MIPS target. static SymbolBody *MipsGp; @@ -414,12 +413,10 @@ static SymbolBody *RelaIpltEnd; }; -template DefinedRegular *ElfSym::Etext; -template DefinedRegular *ElfSym::Etext2; -template DefinedRegular *ElfSym::Edata; -template DefinedRegular *ElfSym::Edata2; -template DefinedRegular *ElfSym::End; -template DefinedRegular *ElfSym::End2; +template typename ElfSym::SymPair ElfSym::Etext; +template typename ElfSym::SymPair ElfSym::Edata; +template typename ElfSym::SymPair ElfSym::End; + template SymbolBody *ElfSym::MipsGp; template SymbolBody *ElfSym::MipsLocalGp; template SymbolBody *ElfSym::MipsGpDisp; Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -1102,9 +1102,8 @@ if (!isOutputDynamic()) Symtab.addIgnored("__tls_get_addr"); - auto Define = [this](StringRef S, DefinedRegular *&Sym, - DefinedRegular *&Sym2) { - Sym = Symtab.addIgnored(S, STV_DEFAULT); + auto Define = [this](StringRef S, ElfSym::SymPair &Sym) { + Sym.first = Symtab.addIgnored(S, STV_DEFAULT); // The name without the underscore is not a reserved name, // so it is defined only when there is a reference against it. @@ -1112,12 +1111,12 @@ S = S.substr(1); if (SymbolBody *B = Symtab.find(S)) if (B->isUndefined()) - Sym2 = Symtab.addAbsolute(S, STV_DEFAULT); + Sym.second = Symtab.addAbsolute(S, STV_DEFAULT); }; - Define("_end", ElfSym::End, ElfSym::End2); - Define("_etext", ElfSym::Etext, ElfSym::Etext2); - Define("_edata", ElfSym::Edata, ElfSym::Edata2); + Define("_end", ElfSym::End); + Define("_etext", ElfSym::Etext); + Define("_edata", ElfSym::Edata); } // Sort input sections by section name suffixes for @@ -1645,6 +1644,14 @@ return ET_EXEC; } +template +static void assignSymValue(SymPair &Sym, uintX_t Val) { + if (Sym.first) + Sym.first->Value = Val; + if (Sym.second) + Sym.second->Value = Val; +} + // This function is called after we have assigned address and size // to each section. This function fixes some predefined absolute // symbol values that depend on section address and size. @@ -1656,24 +1663,13 @@ Elf_Phdr &H = P.H; if (H.p_type != PT_LOAD) continue; - uintX_t Val = H.p_vaddr + H.p_memsz; - if (ElfSym::End) - ElfSym::End->Value = Val; - if (ElfSym::End2) - ElfSym::End2->Value = Val; - - Val = H.p_vaddr + H.p_filesz; - if (H.p_flags & PF_W) { - if (ElfSym::Edata) - ElfSym::Edata->Value = Val; - if (ElfSym::Edata2) - ElfSym::Edata2->Value = Val; - } else { - if (ElfSym::Etext) - ElfSym::Etext->Value = Val; - if (ElfSym::Etext2) - ElfSym::Etext2->Value = Val; - } + assignSymValue(ElfSym::End, H.p_vaddr + H.p_memsz); + + uintX_t Val = H.p_vaddr + H.p_filesz; + if (H.p_flags & PF_W) + assignSymValue(ElfSym::Edata, Val); + else + assignSymValue(ElfSym::Etext, Val); } }