Simplify handling of mips gp* symbols.

Give them values instead of computing it during relocation.

llvm-svn: 265986
This commit is contained in:
Rafael Espindola
2016-04-11 20:34:27 +00:00
parent 892f167aa5
commit 8396f72f7b
4 changed files with 20 additions and 13 deletions

View File

@@ -38,8 +38,6 @@ enum class BuildIdKind { None, Fnv1, Md5, Sha1 };
// Most fields are initialized by the driver.
struct Configuration {
SymbolBody *EntrySym = nullptr;
SymbolBody *MipsGpDisp = nullptr;
SymbolBody *MipsLocalGp = nullptr;
InputFile *FirstElf = nullptr;
llvm::StringRef DynamicLinker;
llvm::StringRef Entry;

View File

@@ -206,12 +206,10 @@ template <class ELFT, class uintX_t>
static uintX_t adjustMipsSymVA(uint32_t Type, const elf::ObjectFile<ELFT> &File,
const SymbolBody &Body, uintX_t AddrLoc,
uintX_t SymVA) {
if (Type == R_MIPS_HI16 && &Body == Config->MipsGpDisp)
return getMipsGpAddr<ELFT>() - AddrLoc;
if (Type == R_MIPS_LO16 && &Body == Config->MipsGpDisp)
return getMipsGpAddr<ELFT>() - AddrLoc + 4;
if (&Body == Config->MipsLocalGp)
return getMipsGpAddr<ELFT>();
if (Type == R_MIPS_HI16 && &Body == ElfSym<ELFT>::MipsGpDisp)
return SymVA - AddrLoc;
if (Type == R_MIPS_LO16 && &Body == ElfSym<ELFT>::MipsGpDisp)
return SymVA - AddrLoc + 4;
if (Body.isLocal() && (Type == R_MIPS_GPREL16 || Type == R_MIPS_GPREL32))
// We need to adjust SymVA value in case of R_MIPS_GPREL16/32
// relocations because they use the following expression to calculate

View File

@@ -405,6 +405,9 @@ template <class ELFT> struct ElfSym {
// The content for _gp symbol for MIPS target.
static DefinedRegular<ELFT> *MipsGp;
static DefinedRegular<ELFT> *MipsLocalGp;
static DefinedRegular<ELFT> *MipsGpDisp;
// __rel_iplt_start/__rel_iplt_end for signaling
// where R_[*]_IRELATIVE relocations do live.
static SymbolBody *RelaIpltStart;
@@ -418,6 +421,8 @@ 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> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGp;
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsLocalGp;
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGpDisp;
template <class ELFT> SymbolBody *ElfSym<ELFT>::RelaIpltStart;
template <class ELFT> SymbolBody *ElfSym<ELFT>::RelaIpltEnd;

View File

@@ -454,8 +454,8 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
// pointer into GOT. __gnu_local_gp is equal to the current value of
// the 'gp'. Therefore any relocations against them do not require
// dynamic relocation.
if (Config->EMachine == EM_MIPS &&
(&Body == Config->MipsGpDisp || &Body == Config->MipsLocalGp))
if (Config->EMachine == EM_MIPS && (&Body == ElfSym<ELFT>::MipsGpDisp ||
&Body == ElfSym<ELFT>::MipsLocalGp))
continue;
if (Preemptible) {
@@ -930,12 +930,12 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
if (Config->EMachine == EM_MIPS) {
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
// start of function and 'gp' pointer into GOT.
Config->MipsGpDisp = Symtab.addIgnored("_gp_disp");
ElfSym<ELFT>::MipsGpDisp = Symtab.addIgnored("_gp_disp");
// The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
// pointer. This symbol is used in the code generated by .cpload pseudo-op
// in case of using -mno-shared option.
// https://sourceware.org/ml/binutils/2004-12/msg00094.html
Config->MipsLocalGp = Symtab.addIgnored("__gnu_local_gp");
ElfSym<ELFT>::MipsLocalGp = Symtab.addIgnored("__gnu_local_gp");
}
// In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
@@ -1510,8 +1510,14 @@ static uint16_t getELFType() {
// symbol values that depend on section address and size.
template <class ELFT> void Writer<ELFT>::fixAbsoluteSymbols() {
// Update MIPS _gp absolute symbol so that it points to the static data.
if (Config->EMachine == EM_MIPS)
if (Config->EMachine == EM_MIPS) {
ElfSym<ELFT>::MipsGp->Value = getMipsGpAddr<ELFT>();
if (ElfSym<ELFT>::MipsLocalGp)
ElfSym<ELFT>::MipsLocalGp->Value = getMipsGpAddr<ELFT>();
if (ElfSym<ELFT>::MipsGpDisp)
ElfSym<ELFT>::MipsGpDisp->Value = getMipsGpAddr<ELFT>();
}
// _etext is the first location after the last read-only loadable segment.
// _edata is the first location after the last read-write loadable segment.