forked from OSchip/llvm-project
Centralize Config->IsRela handling.
This merges the two places were we check Config->IsRela to decide how to write a relocation addend. llvm-svn: 321889
This commit is contained in:
parent
578ce90635
commit
73584cb587
|
@ -832,16 +832,8 @@ template <class ELFT> static void addGotEntry(Symbol &Sym, bool Preemptible) {
|
|||
Type = Target->RelativeRel;
|
||||
else
|
||||
Type = Target->GotRel;
|
||||
InX::RelaDyn->addReloc({Type, InX::Got, Off, !Preemptible, &Sym, 0});
|
||||
|
||||
// REL type relocations don't have addend fields unlike RELAs, and
|
||||
// their addends are stored to the section to which they are applied.
|
||||
// So, store addends if we need to.
|
||||
//
|
||||
// This is ugly -- the difference between REL and RELA should be
|
||||
// handled in a better way. It's a TODO.
|
||||
if (!Config->IsRela && !Preemptible)
|
||||
InX::Got->Relocations.push_back({R_ABS, Target->GotRel, Off, 0, &Sym});
|
||||
InX::RelaDyn->addReloc(Type, InX::Got, Off, !Preemptible, &Sym, 0, R_ABS,
|
||||
Target->GotRel);
|
||||
}
|
||||
|
||||
// The reason we have to do this early scan is as follows
|
||||
|
@ -1022,15 +1014,8 @@ static void scanRelocs(InputSectionBase &Sec, ArrayRef<RelTy> Rels) {
|
|||
// dynamic linker. We can however do better than just copying the incoming
|
||||
// relocation. We can process some of it and and just ask the dynamic
|
||||
// linker to add the load address.
|
||||
if (Config->IsRela) {
|
||||
InX::RelaDyn->addReloc(
|
||||
{Target->RelativeRel, &Sec, Offset, true, &Sym, Addend});
|
||||
} else {
|
||||
// In REL, addends are stored to the target section.
|
||||
InX::RelaDyn->addReloc(
|
||||
{Target->RelativeRel, &Sec, Offset, true, &Sym, 0});
|
||||
Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});
|
||||
}
|
||||
InX::RelaDyn->addReloc(Target->RelativeRel, &Sec, Offset, true, &Sym,
|
||||
Addend, Expr, Type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1202,6 +1202,19 @@ RelocationBaseSection::RelocationBaseSection(StringRef Name, uint32_t Type,
|
|||
: SyntheticSection(SHF_ALLOC, Type, Config->Wordsize, Name),
|
||||
DynamicTag(DynamicTag), SizeDynamicTag(SizeDynamicTag) {}
|
||||
|
||||
void RelocationBaseSection::addReloc(uint32_t DynType,
|
||||
InputSectionBase *InputSec,
|
||||
uint64_t OffsetInSec, bool UseSymVA,
|
||||
Symbol *Sym, int64_t Addend, RelExpr Expr,
|
||||
RelType Type) {
|
||||
// REL type relocations don't have addend fields unlike RELAs, and
|
||||
// their addends are stored to the section to which they are applied.
|
||||
// So, store addends if we need to.
|
||||
if (!Config->IsRela && UseSymVA)
|
||||
InputSec->Relocations.push_back({Expr, Type, OffsetInSec, Addend, Sym});
|
||||
addReloc({DynType, InputSec, OffsetInSec, UseSymVA, Sym, Addend});
|
||||
}
|
||||
|
||||
void RelocationBaseSection::addReloc(const DynamicReloc &Reloc) {
|
||||
if (Reloc.Type == Target->RelativeRel)
|
||||
++NumRelativeRelocs;
|
||||
|
|
|
@ -361,6 +361,9 @@ class RelocationBaseSection : public SyntheticSection {
|
|||
public:
|
||||
RelocationBaseSection(StringRef Name, uint32_t Type, int32_t DynamicTag,
|
||||
int32_t SizeDynamicTag);
|
||||
void addReloc(uint32_t DynType, InputSectionBase *InputSec,
|
||||
uint64_t OffsetInSec, bool UseSymVA, Symbol *Sym,
|
||||
int64_t Addend, RelExpr Expr, RelType Type);
|
||||
void addReloc(const DynamicReloc &Reloc);
|
||||
bool empty() const override { return Relocs.empty(); }
|
||||
size_t getSize() const override { return Relocs.size() * this->Entsize; }
|
||||
|
|
Loading…
Reference in New Issue