// Some linker-generated symbols need to be created as
// DefinedRegular symbols.
template <class ELFT> struct ElfSym {
+ typedef std::pair<DefinedRegular<ELFT> *, DefinedRegular<ELFT> *> SymPair;
+
// The content for _etext and etext symbols.
- static DefinedRegular<ELFT> *Etext;
- static DefinedRegular<ELFT> *Etext2;
+ static SymPair Etext;
// The content for _edata and edata symbols.
- static DefinedRegular<ELFT> *Edata;
- static DefinedRegular<ELFT> *Edata2;
+ static SymPair Edata;
// The content for _end and end symbols.
- static DefinedRegular<ELFT> *End;
- static DefinedRegular<ELFT> *End2;
+ static SymPair End;
// The content for _gp symbol for MIPS target.
static SymbolBody *MipsGp;
static SymbolBody *RelaIpltEnd;
};
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Etext;
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Etext2;
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Edata;
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Edata2;
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End;
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End2;
+template <class ELFT> typename ElfSym<ELFT>::SymPair ElfSym<ELFT>::Etext;
+template <class ELFT> typename ElfSym<ELFT>::SymPair ElfSym<ELFT>::Edata;
+template <class ELFT> typename ElfSym<ELFT>::SymPair ElfSym<ELFT>::End;
+
template <class ELFT> SymbolBody *ElfSym<ELFT>::MipsGp;
template <class ELFT> SymbolBody *ElfSym<ELFT>::MipsLocalGp;
template <class ELFT> SymbolBody *ElfSym<ELFT>::MipsGpDisp;
if (!isOutputDynamic())
Symtab.addIgnored("__tls_get_addr");
- auto Define = [this](StringRef S, DefinedRegular<ELFT> *&Sym,
- DefinedRegular<ELFT> *&Sym2) {
- Sym = Symtab.addIgnored(S, STV_DEFAULT);
+ auto Define = [this](StringRef S, ElfSym<ELFT>::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.
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<ELFT>::End, ElfSym<ELFT>::End2);
- Define("_etext", ElfSym<ELFT>::Etext, ElfSym<ELFT>::Etext2);
- Define("_edata", ElfSym<ELFT>::Edata, ElfSym<ELFT>::Edata2);
+ Define("_end", ElfSym<ELFT>::End);
+ Define("_etext", ElfSym<ELFT>::Etext);
+ Define("_edata", ElfSym<ELFT>::Edata);
}
// Sort input sections by section name suffixes for
return ET_EXEC;
}
+template <class ELFT, class SymPair, class uintX_t>
+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.
Elf_Phdr &H = P.H;
if (H.p_type != PT_LOAD)
continue;
- uintX_t Val = H.p_vaddr + H.p_memsz;
- if (ElfSym<ELFT>::End)
- ElfSym<ELFT>::End->Value = Val;
- if (ElfSym<ELFT>::End2)
- ElfSym<ELFT>::End2->Value = Val;
-
- Val = H.p_vaddr + H.p_filesz;
- if (H.p_flags & PF_W) {
- if (ElfSym<ELFT>::Edata)
- ElfSym<ELFT>::Edata->Value = Val;
- if (ElfSym<ELFT>::Edata2)
- ElfSym<ELFT>::Edata2->Value = Val;
- } else {
- if (ElfSym<ELFT>::Etext)
- ElfSym<ELFT>::Etext->Value = Val;
- if (ElfSym<ELFT>::Etext2)
- ElfSym<ELFT>::Etext2->Value = Val;
- }
+ assignSymValue<ELFT>(ElfSym<ELFT>::End, H.p_vaddr + H.p_memsz);
+
+ uintX_t Val = H.p_vaddr + H.p_filesz;
+ if (H.p_flags & PF_W)
+ assignSymValue<ELFT>(ElfSym<ELFT>::Edata, Val);
+ else
+ assignSymValue<ELFT>(ElfSym<ELFT>::Etext, Val);
}
}