[ELF] - Refactoring of end/edata/etext implementation.
Minor refactoring of how end/edata/etext symbols are handled. Differential revision: http://reviews.llvm.org/D19109 llvm-svn: 266317
This commit is contained in:
parent
bd5262629d
commit
8bbff7ec85
@ -390,17 +390,16 @@ private:
|
||||
// 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;
|
||||
@ -414,12 +413,10 @@ template <class ELFT> struct ElfSym {
|
||||
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;
|
||||
|
||||
@ -1102,9 +1102,8 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
||||
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.
|
||||
@ -1112,12 +1111,12 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
||||
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
|
||||
@ -1645,6 +1644,14 @@ static uint16_t getELFType() {
|
||||
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.
|
||||
@ -1656,24 +1663,13 @@ template <class ELFT> void Writer<ELFT>::fixAbsoluteSymbols() {
|
||||
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;
|
||||
assignSymValue<ELFT>(ElfSym<ELFT>::End, H.p_vaddr + H.p_memsz);
|
||||
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user