ELF: Add `Rela` member variable to Config.
The member is true if we want to create relocatin sections with RELA
instead of REL.
llvm-svn: 263387
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 0c4a01f..fa31b40 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -69,6 +69,7 @@
bool NoUndefined;
bool NoinhibitExec;
bool PrintGcSections;
+ bool Rela;
bool Relocatable;
bool SaveTemps;
bool Shared;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index b22407d..22c6145 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -327,17 +327,20 @@
}
template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
- initSymbols<ELFT>();
// For LTO
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
+ initSymbols<ELFT>();
+
SymbolTable<ELFT> Symtab;
std::unique_ptr<TargetInfo> TI(createTarget());
Target = TI.get();
+ Config->Rela = ELFT::Is64Bits;
+
if (!Config->Shared && !Config->Relocatable) {
// Add entry symbol.
//
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index bd4d912..9a15ad1 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -228,10 +228,10 @@
}
template <class ELFT>
-RelocationSection<ELFT>::RelocationSection(StringRef Name, bool IsRela)
- : OutputSectionBase<ELFT>(Name, IsRela ? SHT_RELA : SHT_REL, SHF_ALLOC),
- IsRela(IsRela) {
- this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
+RelocationSection<ELFT>::RelocationSection(StringRef Name)
+ : OutputSectionBase<ELFT>(Name, Config->Rela ? SHT_RELA : SHT_REL,
+ SHF_ALLOC) {
+ this->Header.sh_entsize = Config->Rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
this->Header.sh_addralign = sizeof(uintX_t);
}
@@ -267,10 +267,10 @@
template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
for (const DynamicReloc<ELFT> &Rel : Relocs) {
auto *P = reinterpret_cast<Elf_Rela *>(Buf);
- Buf += IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
+ Buf += Config->Rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
SymbolBody *Sym = Rel.Sym;
- if (IsRela)
+ if (Config->Rela)
P->r_addend = Rel.UseSymVA ? Sym->getVA<ELFT>(Rel.Addend) : Rel.Addend;
P->r_offset = Rel.getOffset();
uint32_t SymIdx = (!Rel.UseSymVA && Sym) ? Sym->DynsymIndex : 0;
@@ -541,7 +541,7 @@
Out<ELFT>::DynStrTab->finalize();
if (Out<ELFT>::RelaDyn->hasRelocs()) {
- bool IsRela = Out<ELFT>::RelaDyn->isRela();
+ bool IsRela = Config->Rela;
Add({IsRela ? DT_RELA : DT_REL, Out<ELFT>::RelaDyn});
Add({IsRela ? DT_RELASZ : DT_RELSZ, Out<ELFT>::RelaDyn->getSize()});
Add({IsRela ? DT_RELAENT : DT_RELENT,
@@ -552,7 +552,7 @@
Add({DT_PLTRELSZ, Out<ELFT>::RelaPlt->getSize()});
Add({Config->EMachine == EM_MIPS ? DT_MIPS_PLTGOT : DT_PLTGOT,
Out<ELFT>::GotPlt});
- Add({DT_PLTREL, uint64_t(Out<ELFT>::RelaPlt->isRela() ? DT_RELA : DT_REL)});
+ Add({DT_PLTREL, uint64_t(Config->Rela ? DT_RELA : DT_REL)});
}
Add({DT_SYMTAB, Out<ELFT>::DynSymTab});
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h
index d0c6779..4a7b3f6 100644
--- a/lld/ELF/OutputSections.h
+++ b/lld/ELF/OutputSections.h
@@ -244,19 +244,17 @@
typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
public:
- RelocationSection(StringRef Name, bool IsRela);
+ RelocationSection(StringRef Name);
void addReloc(const DynamicReloc<ELFT> &Reloc);
unsigned getRelocOffset();
void finalize() override;
void writeTo(uint8_t *Buf) override;
bool hasRelocs() const { return !Relocs.empty(); }
- bool isRela() const { return IsRela; }
bool Static = false;
private:
std::vector<DynamicReloc<ELFT>> Relocs;
- const bool IsRela;
};
template <class ELFT>
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 3d677b0..beaad67 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -124,19 +124,16 @@
};
} // anonymous namespace
-template <class ELFT> static bool shouldUseRela() { return ELFT::Is64Bits; }
-
template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
typedef typename ELFFile<ELFT>::uintX_t uintX_t;
// Create singleton output sections.
- bool IsRela = shouldUseRela<ELFT>();
DynamicSection<ELFT> Dynamic(*Symtab);
EhFrameHeader<ELFT> EhFrameHdr;
GotSection<ELFT> Got;
InterpSection<ELFT> Interp;
PltSection<ELFT> Plt;
- RelocationSection<ELFT> RelaDyn(IsRela ? ".rela.dyn" : ".rel.dyn", IsRela);
+ RelocationSection<ELFT> RelaDyn(Config->Rela ? ".rela.dyn" : ".rel.dyn");
StringTableSection<ELFT> DynStrTab(".dynstr", true);
StringTableSection<ELFT> ShStrTab(".shstrtab", false);
SymbolTableSection<ELFT> DynSymTab(*Symtab, DynStrTab);
@@ -162,9 +159,9 @@
if (Config->SysvHash)
HashTab.reset(new HashTableSection<ELFT>);
if (Target->UseLazyBinding) {
- StringRef S = IsRela ? ".rela.plt" : ".rel.plt";
+ StringRef S = Config->Rela ? ".rela.plt" : ".rel.plt";
GotPlt.reset(new GotPltSection<ELFT>);
- RelaPlt.reset(new RelocationSection<ELFT>(S, IsRela));
+ RelaPlt.reset(new RelocationSection<ELFT>(S));
}
if (!Config->StripAll) {
StrTab.reset(new StringTableSection<ELFT>(".strtab", false));
@@ -794,13 +791,11 @@
void Writer<ELFT>::addRelIpltSymbols() {
if (isOutputDynamic() || !Out<ELFT>::RelaPlt)
return;
- bool IsRela = shouldUseRela<ELFT>();
-
- StringRef S = IsRela ? "__rela_iplt_start" : "__rel_iplt_start";
+ StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start";
if (Symtab.find(S))
Symtab.addAbsolute(S, ElfSym<ELFT>::RelaIpltStart);
- S = IsRela ? "__rela_iplt_end" : "__rel_iplt_end";
+ S = Config->Rela ? "__rela_iplt_end" : "__rel_iplt_end";
if (Symtab.find(S))
Symtab.addAbsolute(S, ElfSym<ELFT>::RelaIpltEnd);
}