Move getLocalRelTarget to the file where it is used.
llvm-svn: 263152
This commit is contained in:
parent
17d6983a4e
commit
f3314b2e4f
|
@ -183,6 +183,48 @@ InputSectionBase<ELFT>::findMipsPairedReloc(uint8_t *Buf, uint32_t SymIndex,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// Returns a VA which a relocatin RI refers to. Used only for local symbols.
|
||||
// For non-local symbols, use SymbolBody::getVA instead.
|
||||
template <class ELFT, bool IsRela>
|
||||
static typename ELFFile<ELFT>::uintX_t
|
||||
getLocalRelTarget(const ObjectFile<ELFT> &File,
|
||||
const Elf_Rel_Impl<ELFT, IsRela> &RI,
|
||||
typename ELFFile<ELFT>::uintX_t Addend) {
|
||||
typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
|
||||
typedef typename ELFFile<ELFT>::uintX_t uintX_t;
|
||||
|
||||
// PPC64 has a special relocation representing the TOC base pointer
|
||||
// that does not have a corresponding symbol.
|
||||
if (Config->EMachine == EM_PPC64 && RI.getType(false) == R_PPC64_TOC)
|
||||
return getPPC64TocBase() + Addend;
|
||||
|
||||
const Elf_Sym *Sym =
|
||||
File.getObj().getRelocationSymbol(&RI, File.getSymbolTable());
|
||||
|
||||
if (!Sym)
|
||||
fatal("Unsupported relocation without symbol");
|
||||
|
||||
InputSectionBase<ELFT> *Section = File.getSection(*Sym);
|
||||
|
||||
if (Sym->getType() == STT_TLS)
|
||||
return (Section->OutSec->getVA() + Section->getOffset(*Sym) + Addend) -
|
||||
Out<ELFT>::TlsPhdr->p_vaddr;
|
||||
|
||||
// According to the ELF spec reference to a local symbol from outside
|
||||
// the group are not allowed. Unfortunately .eh_frame breaks that rule
|
||||
// and must be treated specially. For now we just replace the symbol with
|
||||
// 0.
|
||||
if (Section == InputSection<ELFT>::Discarded || !Section->Live)
|
||||
return Addend;
|
||||
|
||||
uintX_t Offset = Sym->st_value;
|
||||
if (Sym->getType() == STT_SECTION) {
|
||||
Offset += Addend;
|
||||
Addend = 0;
|
||||
}
|
||||
return Section->OutSec->getVA() + Section->getOffset(Offset) + Addend;
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
template <bool isRela>
|
||||
void InputSectionBase<ELFT>::relocate(uint8_t *Buf, uint8_t *BufEnd,
|
||||
|
|
|
@ -888,48 +888,6 @@ template <class ELFT> void OutputSection<ELFT>::sortCtorsDtors() {
|
|||
reassignOffsets();
|
||||
}
|
||||
|
||||
// Returns a VA which a relocatin RI refers to. Used only for local symbols.
|
||||
// For non-local symbols, use SymbolBody::getVA instead.
|
||||
template <class ELFT, bool IsRela>
|
||||
typename ELFFile<ELFT>::uintX_t
|
||||
elf::getLocalRelTarget(const ObjectFile<ELFT> &File,
|
||||
const Elf_Rel_Impl<ELFT, IsRela> &RI,
|
||||
typename ELFFile<ELFT>::uintX_t Addend) {
|
||||
typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
|
||||
typedef typename ELFFile<ELFT>::uintX_t uintX_t;
|
||||
|
||||
// PPC64 has a special relocation representing the TOC base pointer
|
||||
// that does not have a corresponding symbol.
|
||||
if (Config->EMachine == EM_PPC64 && RI.getType(false) == R_PPC64_TOC)
|
||||
return getPPC64TocBase() + Addend;
|
||||
|
||||
const Elf_Sym *Sym =
|
||||
File.getObj().getRelocationSymbol(&RI, File.getSymbolTable());
|
||||
|
||||
if (!Sym)
|
||||
fatal("Unsupported relocation without symbol");
|
||||
|
||||
InputSectionBase<ELFT> *Section = File.getSection(*Sym);
|
||||
|
||||
if (Sym->getType() == STT_TLS)
|
||||
return (Section->OutSec->getVA() + Section->getOffset(*Sym) + Addend) -
|
||||
Out<ELFT>::TlsPhdr->p_vaddr;
|
||||
|
||||
// According to the ELF spec reference to a local symbol from outside
|
||||
// the group are not allowed. Unfortunately .eh_frame breaks that rule
|
||||
// and must be treated specially. For now we just replace the symbol with
|
||||
// 0.
|
||||
if (Section == InputSection<ELFT>::Discarded || !Section->Live)
|
||||
return Addend;
|
||||
|
||||
uintX_t Offset = Sym->st_value;
|
||||
if (Sym->getType() == STT_SECTION) {
|
||||
Offset += Addend;
|
||||
Addend = 0;
|
||||
}
|
||||
return Section->OutSec->getVA() + Section->getOffset(Offset) + Addend;
|
||||
}
|
||||
|
||||
// Returns true if a symbol can be replaced at load-time by a symbol
|
||||
// with the same name defined in other ELF executable or DSO.
|
||||
bool elf::canBePreempted(const SymbolBody *Body) {
|
||||
|
@ -1668,30 +1626,5 @@ template class SymbolTableSection<ELF32LE>;
|
|||
template class SymbolTableSection<ELF32BE>;
|
||||
template class SymbolTableSection<ELF64LE>;
|
||||
template class SymbolTableSection<ELF64BE>;
|
||||
|
||||
template uint32_t getLocalRelTarget(const ObjectFile<ELF32LE> &,
|
||||
const ELFFile<ELF32LE>::Elf_Rel &,
|
||||
uint32_t);
|
||||
template uint32_t getLocalRelTarget(const ObjectFile<ELF32BE> &,
|
||||
const ELFFile<ELF32BE>::Elf_Rel &,
|
||||
uint32_t);
|
||||
template uint64_t getLocalRelTarget(const ObjectFile<ELF64LE> &,
|
||||
const ELFFile<ELF64LE>::Elf_Rel &,
|
||||
uint64_t);
|
||||
template uint64_t getLocalRelTarget(const ObjectFile<ELF64BE> &,
|
||||
const ELFFile<ELF64BE>::Elf_Rel &,
|
||||
uint64_t);
|
||||
template uint32_t getLocalRelTarget(const ObjectFile<ELF32LE> &,
|
||||
const ELFFile<ELF32LE>::Elf_Rela &,
|
||||
uint32_t);
|
||||
template uint32_t getLocalRelTarget(const ObjectFile<ELF32BE> &,
|
||||
const ELFFile<ELF32BE>::Elf_Rela &,
|
||||
uint32_t);
|
||||
template uint64_t getLocalRelTarget(const ObjectFile<ELF64LE> &,
|
||||
const ELFFile<ELF64LE>::Elf_Rela &,
|
||||
uint64_t);
|
||||
template uint64_t getLocalRelTarget(const ObjectFile<ELF64BE> &,
|
||||
const ELFFile<ELF64BE>::Elf_Rela &,
|
||||
uint64_t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,12 +47,6 @@ getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rela &Rel) {
|
|||
return Rel.r_addend;
|
||||
}
|
||||
|
||||
template <class ELFT, bool IsRela>
|
||||
typename llvm::object::ELFFile<ELFT>::uintX_t
|
||||
getLocalRelTarget(const ObjectFile<ELFT> &File,
|
||||
const llvm::object::Elf_Rel_Impl<ELFT, IsRela> &Rel,
|
||||
typename llvm::object::ELFFile<ELFT>::uintX_t Addend);
|
||||
|
||||
bool canBePreempted(const SymbolBody *Body);
|
||||
|
||||
bool isValidCIdentifier(StringRef S);
|
||||
|
|
Loading…
Reference in New Issue