[lld] r237973 - [ELF] Simplify dynamic table entry creation.
Davide Italiano
davide at freebsd.org
Thu May 21 16:44:21 PDT 2015
Author: davide
Date: Thu May 21 18:44:19 2015
New Revision: 237973
URL: http://llvm.org/viewvc/llvm-project?rev=237973&view=rev
Log:
[ELF] Simplify dynamic table entry creation.
Differential Revision: http://reviews.llvm.org/D9921
Reviewed by: atanasyan
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h
lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.cpp
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h?rev=237973&r1=237972&r2=237973&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h Thu May 21 18:44:19 2015
@@ -27,53 +27,34 @@ public:
void createDefaultEntries() override {
DynamicTable<ELFT>::createDefaultEntries();
- typename DynamicTable<ELFT>::Elf_Dyn dyn;
-
// Version id for the Runtime Linker Interface.
- dyn.d_un.d_val = 1;
- dyn.d_tag = DT_MIPS_RLD_VERSION;
- this->addEntry(dyn);
+ this->addEntry(DT_MIPS_RLD_VERSION, 1);
// MIPS flags.
- dyn.d_un.d_val = RHF_NOTPOT;
- dyn.d_tag = DT_MIPS_FLAGS;
- this->addEntry(dyn);
+ this->addEntry(DT_MIPS_FLAGS, RHF_NOTPOT);
// The base address of the segment.
- dyn.d_un.d_ptr = 0;
- dyn.d_tag = DT_MIPS_BASE_ADDRESS;
- _dt_baseaddr = this->addEntry(dyn);
+ _dt_baseaddr = this->addEntry(DT_MIPS_BASE_ADDRESS, 0);
// Number of local global offset table entries.
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_MIPS_LOCAL_GOTNO;
- _dt_localgot = this->addEntry(dyn);
+ _dt_localgot = this->addEntry(DT_MIPS_LOCAL_GOTNO, 0);
// Number of entries in the .dynsym section.
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_MIPS_SYMTABNO;
- _dt_symtabno = this->addEntry(dyn);
+ _dt_symtabno = this->addEntry(DT_MIPS_SYMTABNO, 0);
// The index of the first dynamic symbol table entry that corresponds
// to an entry in the global offset table.
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_MIPS_GOTSYM;
- _dt_gotsym = this->addEntry(dyn);
+ _dt_gotsym = this->addEntry(DT_MIPS_GOTSYM, 0);
// Address of the .got section.
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_PLTGOT;
- _dt_pltgot = this->addEntry(dyn);
+ _dt_pltgot = this->addEntry(DT_PLTGOT, 0);
}
void doPreFlight() override {
DynamicTable<ELFT>::doPreFlight();
if (_targetLayout.findOutputSection(".MIPS.options")) {
- typename DynamicTable<ELFT>::Elf_Dyn dyn;
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_MIPS_OPTIONS;
- _dt_options = this->addEntry(dyn);
+ _dt_options = this->addEntry(DT_MIPS_OPTIONS, 0);
}
}
Modified: lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.cpp?rev=237973&r1=237972&r2=237973&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.cpp Thu May 21 18:44:19 2015
@@ -126,28 +126,20 @@ void OutputELFWriter<ELFT>::buildDynamic
}
// Never mark the dynamic linker as DT_NEEDED
_soNeeded.erase(sys::path::filename(_ctx.getInterpreter()));
- for (const auto &loadName : _soNeeded) {
- Elf_Dyn dyn;
- dyn.d_tag = DT_NEEDED;
- dyn.d_un.d_val = _dynamicStringTable->addString(loadName.getKey());
- _dynamicTable->addEntry(dyn);
- }
+ for (const auto &loadName : _soNeeded)
+ _dynamicTable->addEntry(DT_NEEDED,
+ _dynamicStringTable->addString(loadName.getKey()));
const auto &rpathList = _ctx.getRpathList();
if (!rpathList.empty()) {
auto rpath =
new (_alloc) std::string(join(rpathList.begin(), rpathList.end(), ":"));
- Elf_Dyn dyn;
- dyn.d_tag = _ctx.getEnableNewDtags() ? DT_RUNPATH : DT_RPATH;
- dyn.d_un.d_val = _dynamicStringTable->addString(*rpath);
- _dynamicTable->addEntry(dyn);
+ _dynamicTable->addEntry(_ctx.getEnableNewDtags() ? DT_RUNPATH : DT_RPATH,
+ _dynamicStringTable->addString(*rpath));
}
StringRef soname = _ctx.sharedObjectName();
- if (!soname.empty() && _ctx.getOutputELFType() == llvm::ELF::ET_DYN) {
- Elf_Dyn dyn;
- dyn.d_tag = DT_SONAME;
- dyn.d_un.d_val = _dynamicStringTable->addString(soname);
- _dynamicTable->addEntry(dyn);
- }
+ if (!soname.empty() && _ctx.getOutputELFType() == llvm::ELF::ET_DYN)
+ _dynamicTable->addEntry(DT_SONAME, _dynamicStringTable->addString(soname));
+
// The dynamic symbol table need to be sorted earlier because the hash
// table needs to be built using the dynamic symbol table. It would be
// late to sort the symbols due to that in finalize. In the dynamic symbol
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp?rev=237973&r1=237972&r2=237973&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp Thu May 21 18:44:19 2015
@@ -694,8 +694,12 @@ DynamicTable<ELFT>::DynamicTable(const E
this->_flags = SHF_ALLOC;
}
-template <class ELFT> std::size_t DynamicTable<ELFT>::addEntry(Elf_Dyn e) {
- _entries.push_back(e);
+template <class ELFT>
+std::size_t DynamicTable<ELFT>::addEntry(int64_t tag, uint64_t val) {
+ Elf_Dyn dyn;
+ dyn.d_tag = tag;
+ dyn.d_un.d_val = val;
+ _entries.push_back(dyn);
this->_fsize = (_entries.size() * sizeof(Elf_Dyn)) + sizeof(Elf_Dyn);
this->_msize = this->_fsize;
return _entries.size() - 1;
@@ -716,72 +720,41 @@ void DynamicTable<ELFT>::write(ELFWriter
template <class ELFT> void DynamicTable<ELFT>::createDefaultEntries() {
bool isRela = this->_ctx.isRelaOutputFormat();
-
- Elf_Dyn dyn;
- dyn.d_un.d_val = 0;
-
- dyn.d_tag = DT_HASH;
- _dt_hash = addEntry(dyn);
- dyn.d_tag = DT_STRTAB;
- _dt_strtab = addEntry(dyn);
- dyn.d_tag = DT_SYMTAB;
- _dt_symtab = addEntry(dyn);
- dyn.d_tag = DT_STRSZ;
- _dt_strsz = addEntry(dyn);
- dyn.d_tag = DT_SYMENT;
- _dt_syment = addEntry(dyn);
+ _dt_hash = addEntry(DT_HASH, 0);
+ _dt_strtab = addEntry(DT_STRTAB, 0);
+ _dt_symtab = addEntry(DT_SYMTAB, 0);
+ _dt_strsz = addEntry(DT_STRSZ, 0);
+ _dt_syment = addEntry(DT_SYMENT, 0);
if (_layout.hasDynamicRelocationTable()) {
- dyn.d_tag = isRela ? DT_RELA : DT_REL;
- _dt_rela = addEntry(dyn);
- dyn.d_tag = isRela ? DT_RELASZ : DT_RELSZ;
- _dt_relasz = addEntry(dyn);
- dyn.d_tag = isRela ? DT_RELAENT : DT_RELENT;
- _dt_relaent = addEntry(dyn);
-
- if (_layout.getDynamicRelocationTable()->canModifyReadonlySection()) {
- dyn.d_tag = DT_TEXTREL;
- _dt_textrel = addEntry(dyn);
- }
+ _dt_rela = addEntry(isRela ? DT_RELA : DT_REL, 0);
+ _dt_relasz = addEntry(isRela ? DT_RELASZ : DT_RELSZ, 0);
+ _dt_relaent = addEntry(isRela ? DT_RELAENT : DT_RELENT, 0);
+ if (_layout.getDynamicRelocationTable()->canModifyReadonlySection())
+ _dt_textrel = addEntry(DT_TEXTREL, 0);
}
if (_layout.hasPLTRelocationTable()) {
- dyn.d_tag = DT_PLTRELSZ;
- _dt_pltrelsz = addEntry(dyn);
- dyn.d_tag = getGotPltTag();
- _dt_pltgot = addEntry(dyn);
- dyn.d_tag = DT_PLTREL;
- dyn.d_un.d_val = isRela ? DT_RELA : DT_REL;
- _dt_pltrel = addEntry(dyn);
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_JMPREL;
- _dt_jmprel = addEntry(dyn);
+ _dt_pltrelsz = addEntry(DT_PLTRELSZ, 0);
+ _dt_pltgot = addEntry(getGotPltTag(), 0);
+ _dt_pltrel = addEntry(DT_PLTREL, isRela ? DT_RELA : DT_REL);
+ _dt_jmprel = addEntry(DT_JMPREL, 0);
}
}
template <class ELFT> void DynamicTable<ELFT>::doPreFlight() {
- Elf_Dyn dyn;
- dyn.d_un.d_val = 0;
auto initArray = _layout.findOutputSection(".init_array");
auto finiArray = _layout.findOutputSection(".fini_array");
if (initArray) {
- dyn.d_tag = DT_INIT_ARRAY;
- _dt_init_array = addEntry(dyn);
- dyn.d_tag = DT_INIT_ARRAYSZ;
- _dt_init_arraysz = addEntry(dyn);
+ _dt_init_array = addEntry(DT_INIT_ARRAY, 0);
+ _dt_init_arraysz = addEntry(DT_INIT_ARRAYSZ, 0);
}
if (finiArray) {
- dyn.d_tag = DT_FINI_ARRAY;
- _dt_fini_array = addEntry(dyn);
- dyn.d_tag = DT_FINI_ARRAYSZ;
- _dt_fini_arraysz = addEntry(dyn);
- }
- if (getInitAtomLayout()) {
- dyn.d_tag = DT_INIT;
- _dt_init = addEntry(dyn);
- }
- if (getFiniAtomLayout()) {
- dyn.d_tag = DT_FINI;
- _dt_fini = addEntry(dyn);
+ _dt_fini_array = addEntry(DT_FINI_ARRAY, 0);
+ _dt_fini_arraysz = addEntry(DT_FINI_ARRAYSZ, 0);
}
+ if (getInitAtomLayout())
+ _dt_init = addEntry(DT_INIT, 0);
+ if (getFiniAtomLayout())
+ _dt_fini = addEntry(DT_FINI, 0);
}
template <class ELFT> void DynamicTable<ELFT>::finalize() {
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=237973&r1=237972&r2=237973&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Thu May 21 18:44:19 2015
@@ -458,7 +458,7 @@ public:
range<typename EntriesT::iterator> entries() { return _entries; }
/// \returns the index of the entry.
- std::size_t addEntry(Elf_Dyn e);
+ std::size_t addEntry(int64_t tag, uint64_t val);
void write(ELFWriter *writer, TargetLayout<ELFT> &layout,
llvm::FileOutputBuffer &buffer) override;
More information about the llvm-commits
mailing list