[lld] r263387 - ELF: Add `Rela` member variable to Config.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 13 13:10:20 PDT 2016
Author: ruiu
Date: Sun Mar 13 15:10:20 2016
New Revision: 263387
URL: http://llvm.org/viewvc/llvm-project?rev=263387&view=rev
Log:
ELF: Add `Rela` member variable to Config.
The member is true if we want to create relocatin sections with RELA
instead of REL.
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=263387&r1=263386&r2=263387&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Sun Mar 13 15:10:20 2016
@@ -69,6 +69,7 @@ struct Configuration {
bool NoUndefined;
bool NoinhibitExec;
bool PrintGcSections;
+ bool Rela;
bool Relocatable;
bool SaveTemps;
bool Shared;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=263387&r1=263386&r2=263387&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sun Mar 13 15:10:20 2016
@@ -327,17 +327,20 @@ template <class ELFT> static void initSy
}
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.
//
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=263387&r1=263386&r2=263387&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Sun Mar 13 15:10:20 2016
@@ -228,10 +228,10 @@ template <class ELFT> void PltSection<EL
}
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 @@ typename ELFFile<ELFT>::uintX_t DynamicR
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 @@ template <class ELFT> void DynamicSectio
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 @@ template <class ELFT> void DynamicSectio
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});
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=263387&r1=263386&r2=263387&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Sun Mar 13 15:10:20 2016
@@ -244,19 +244,17 @@ class RelocationSection final : public O
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>
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=263387&r1=263386&r2=263387&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sun Mar 13 15:10:20 2016
@@ -124,19 +124,16 @@ private:
};
} // 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 @@ template <class ELFT> void elf::writeRes
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 @@ template <class ELFT>
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);
}
More information about the llvm-commits
mailing list