This is already a simplification, but will allow much more.
llvm-svn: 263224
SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
unsigned char Binding = Sym->getBinding();
if (Binding == STB_LOCAL)
- return new (Alloc) LocalSymbol<ELFT>(*Sym);
+ return new (Alloc) LocalSymbol<ELFT>(*Sym, getSection(*Sym));
StringRef Name = check(Sym->getName(this->StringTable));
if (IsRela) {
uintX_t VA = 0;
- if (Rel.UseSymVA)
- VA = Sym->getVA<ELFT>();
- else if (Rel.TargetSec)
- VA = Rel.TargetSec->getOffset(Rel.OffsetInTargetSec) +
- Rel.TargetSec->OutSec->getVA();
- reinterpret_cast<Elf_Rela *>(P)->r_addend = Rel.Addend + VA;
+ uintX_t Addend = Rel.Addend;
+ if (Rel.UseSymVA) {
+ if (auto *L = dyn_cast<LocalSymbol<ELFT>>(Sym)) {
+ uintX_t Pos = L->Sym.st_value;
+ if (L->Sym.getType() == STT_SECTION) {
+ Pos += Addend;
+ Addend = 0;
+ }
+ VA = L->Section->OutSec->getVA() + L->Section->getOffset(Pos);
+ } else {
+ VA = Sym->getVA<ELFT>();
+ }
+ }
+ reinterpret_cast<Elf_Rela *>(P)->r_addend = Addend + VA;
}
P->r_offset = Rel.getOffset();
InputSectionBase<ELFT> *OffsetSec = nullptr;
uintX_t OffsetInSec = 0;
bool UseSymVA = false;
- InputSectionBase<ELFT> *TargetSec = nullptr;
- uintX_t OffsetInTargetSec = 0;
uintX_t Addend = 0;
DynamicReloc(uint32_t Type, OffsetKind OKind, SymbolBody *Sym)
: Type(Type), OKind(Off_Sec), Sym(Sym), OffsetSec(OffsetSec),
OffsetInSec(OffsetInSec), UseSymVA(UseSymVA), Addend(Addend) {}
- DynamicReloc(uint32_t Type, InputSectionBase<ELFT> *OffsetSec,
- uintX_t OffsetInSec, InputSectionBase<ELFT> *TargetSec,
- uintX_t OffsetInTargetSec, uintX_t Addend)
- : Type(Type), OKind(Off_Sec), OffsetSec(OffsetSec),
- OffsetInSec(OffsetInSec), TargetSec(TargetSec),
- OffsetInTargetSec(OffsetInTargetSec), Addend(Addend) {}
-
uintX_t getOffset() const;
};
typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
public:
- LocalSymbol(const Elf_Sym &Sym)
- : DefinedElf<ELFT>(SymbolBody::DefinedLocalKind, "", Sym) {}
+ LocalSymbol(const Elf_Sym &Sym, InputSectionBase<ELFT> *Section)
+ : DefinedElf<ELFT>(SymbolBody::DefinedLocalKind, "", Sym),
+ Section(Section) {}
static bool classof(const SymbolBody *S) {
return S->kind() == SymbolBody::DefinedLocalKind;
}
+
+ InputSectionBase<ELFT> *Section;
};
// This class represents a symbol defined in an archive file. It is
(uintX_t)getPPC64TocBase() + Addend});
continue;
}
- if (!Body.isLocal()) {
- Out<ELFT>::RelaDyn->addReloc(
- {Target->RelativeRel, &C, RI.r_offset, true, &Body, Addend});
- continue;
- }
- const Elf_Sym &Sym = cast<LocalSymbol<ELFT>>(Body).Sym;
- InputSectionBase<ELFT> *Section = File.getSection(Sym);
- uintX_t Offset = Sym.st_value;
- if (Sym.getType() == STT_SECTION) {
- Offset += Addend;
- Addend = 0;
- }
Out<ELFT>::RelaDyn->addReloc(
- {Target->RelativeRel, &C, RI.r_offset, Section, Offset, Addend});
+ {Target->RelativeRel, &C, RI.r_offset, true, &Body, Addend});
}
}