[lld] r200328 - [Mips] Declare MipsDynamicTable class in a separate header file.
Simon Atanasyan
simon at atanasyan.com
Tue Jan 28 10:52:41 PST 2014
Author: atanasyan
Date: Tue Jan 28 12:52:41 2014
New Revision: 200328
URL: http://llvm.org/viewvc/llvm-project?rev=200328&view=rev
Log:
[Mips] Declare MipsDynamicTable class in a separate header file.
Added:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h?rev=200328&r1=200327&r2=200328&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h Tue Jan 28 12:52:41 2014
@@ -10,6 +10,7 @@
#define MIPS_DYNAMIC_LIBRARY_WRITER_H
#include "DynamicLibraryWriter.h"
+#include "MipsDynamicTable.h"
#include "MipsELFWriters.h"
#include "MipsLinkingContext.h"
@@ -85,7 +86,7 @@ template <class ELFT>
LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>)
MipsDynamicLibraryWriter<ELFT>::createDynamicTable() {
return LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>)(new (
- this->_alloc) MipsDynamicTable(_mipsContext, _mipsTargetLayout));
+ this->_alloc) MipsDynamicTable<ELFT>(_mipsContext, _mipsTargetLayout));
}
/// \brief create dynamic symbol table
Added: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h?rev=200328&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h Tue Jan 28 12:52:41 2014
@@ -0,0 +1,103 @@
+//===- lib/ReaderWriter/ELF/Mips/MipsDynamicTable.h -----------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLD_READER_WRITER_ELF_MIPS_DYNAMIC_TABLE_H
+#define LLD_READER_WRITER_ELF_MIPS_DYNAMIC_TABLE_H
+
+#include "DefaultLayout.h"
+#include "SectionChunks.h"
+
+namespace lld {
+namespace elf {
+
+class MipsLinkingContext;
+template <class ELFType> class MipsTargetLayout;
+
+template <class MipsELFType>
+class MipsDynamicTable : public DynamicTable<MipsELFType> {
+public:
+ MipsDynamicTable(MipsLinkingContext &context,
+ MipsTargetLayout<MipsELFType> &layout)
+ : DynamicTable<MipsELFType>(context, layout, ".dynamic",
+ DefaultLayout<MipsELFType>::ORDER_DYNAMIC),
+ _mipsTargetLayout(layout) {}
+
+ virtual void createDefaultEntries() {
+ DynamicTable<MipsELFType>::createDefaultEntries();
+
+ typename DynamicTable<MipsELFType>::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);
+
+ // MIPS flags.
+ dyn.d_un.d_val = RHF_NOTPOT;
+ dyn.d_tag = DT_MIPS_FLAGS;
+ this->addEntry(dyn);
+
+ // The base address of the segment.
+ dyn.d_un.d_ptr = 0;
+ dyn.d_tag = DT_MIPS_BASE_ADDRESS;
+ _dt_baseaddr = this->addEntry(dyn);
+
+ // 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);
+
+ // Number of entries in the .dynsym section.
+ dyn.d_un.d_val = 0;
+ dyn.d_tag = DT_MIPS_SYMTABNO;
+ _dt_symtabno = this->addEntry(dyn);
+
+ // 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);
+
+ // Address of the .got section.
+ dyn.d_un.d_val = 0;
+ dyn.d_tag = DT_PLTGOT;
+ _dt_pltgot = this->addEntry(dyn);
+ }
+
+ virtual void updateDynamicTable() {
+ DynamicTable<MipsELFType>::updateDynamicTable();
+
+ // Assign the minimum segment address to the DT_MIPS_BASE_ADDRESS tag.
+ auto baseAddr = std::numeric_limits<uint64_t>::max();
+ for (auto si : _mipsTargetLayout.segments())
+ if (si->segmentType() != llvm::ELF::PT_NULL)
+ baseAddr = std::min(baseAddr, si->virtualAddr());
+ this->_entries[_dt_baseaddr].d_un.d_val = baseAddr;
+
+ auto &got = _mipsTargetLayout.getGOTSection();
+
+ this->_entries[_dt_symtabno].d_un.d_val = this->getSymbolTable()->size();
+ this->_entries[_dt_gotsym].d_un.d_val =
+ this-> getSymbolTable()->size() - got.getGlobalCount();
+ this->_entries[_dt_localgot].d_un.d_val = got.getLocalCount();
+ this->_entries[_dt_pltgot].d_un.d_ptr =
+ _mipsTargetLayout.findOutputSection(".got")->virtualAddr();
+ }
+
+private:
+ std::size_t _dt_symtabno;
+ std::size_t _dt_localgot;
+ std::size_t _dt_gotsym;
+ std::size_t _dt_pltgot;
+ std::size_t _dt_baseaddr;
+ MipsTargetLayout<MipsELFType> &_mipsTargetLayout;
+};
+} // end namespace elf
+} // end namespace lld
+
+#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h?rev=200328&r1=200327&r2=200328&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h Tue Jan 28 12:52:41 2014
@@ -10,6 +10,7 @@
#define MIPS_EXECUTABLE_WRITER_H
#include "ExecutableWriter.h"
+#include "MipsDynamicTable.h"
#include "MipsELFWriters.h"
#include "MipsLinkingContext.h"
@@ -85,7 +86,7 @@ template <class ELFT>
LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>)
MipsExecutableWriter<ELFT>::createDynamicTable() {
return LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>)(new (
- this->_alloc) MipsDynamicTable(_mipsContext, _mipsTargetLayout));
+ this->_alloc) MipsDynamicTable<ELFT>(_mipsContext, _mipsTargetLayout));
}
/// \brief create dynamic symbol table
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h?rev=200328&r1=200327&r2=200328&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h Tue Jan 28 12:52:41 2014
@@ -116,85 +116,6 @@ private:
MipsTargetLayout<Mips32ElELFType> &_mipsTargetLayout;
};
-class MipsDynamicTable : public DynamicTable<Mips32ElELFType> {
-public:
- MipsDynamicTable(MipsLinkingContext &context,
- MipsTargetLayout<Mips32ElELFType> &layout)
- : DynamicTable<Mips32ElELFType>(
- context, layout, ".dynamic",
- DefaultLayout<Mips32ElELFType>::ORDER_DYNAMIC),
- _mipsTargetLayout(layout) {}
-
- virtual void createDefaultEntries() {
- DynamicTable<Mips32ElELFType>::createDefaultEntries();
-
- Elf_Dyn dyn;
-
- // Version id for the Runtime Linker Interface.
- dyn.d_un.d_val = 1;
- dyn.d_tag = DT_MIPS_RLD_VERSION;
- addEntry(dyn);
-
- // MIPS flags.
- dyn.d_un.d_val = RHF_NOTPOT;
- dyn.d_tag = DT_MIPS_FLAGS;
- addEntry(dyn);
-
- // The base address of the segment.
- dyn.d_un.d_ptr = 0;
- dyn.d_tag = DT_MIPS_BASE_ADDRESS;
- _dt_baseaddr = addEntry(dyn);
-
- // Number of local global offset table entries.
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_MIPS_LOCAL_GOTNO;
- _dt_localgot = addEntry(dyn);
-
- // Number of entries in the .dynsym section.
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_MIPS_SYMTABNO;
- _dt_symtabno = addEntry(dyn);
-
- // 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 = addEntry(dyn);
-
- // Address of the .got section.
- dyn.d_un.d_val = 0;
- dyn.d_tag = DT_PLTGOT;
- _dt_pltgot = addEntry(dyn);
- }
-
- virtual void updateDynamicTable() {
- DynamicTable<Mips32ElELFType>::updateDynamicTable();
-
- // Assign the minimum segment address to the DT_MIPS_BASE_ADDRESS tag.
- auto baseAddr = std::numeric_limits<uint64_t>::max();
- for (auto si : _mipsTargetLayout.segments())
- if (si->segmentType() != llvm::ELF::PT_NULL)
- baseAddr = std::min(baseAddr, si->virtualAddr());
- _entries[_dt_baseaddr].d_un.d_val = baseAddr;
-
- auto &got = _mipsTargetLayout.getGOTSection();
-
- _entries[_dt_symtabno].d_un.d_val = getSymbolTable()->size();
- _entries[_dt_gotsym].d_un.d_val =
- getSymbolTable()->size() - got.getGlobalCount();
- _entries[_dt_localgot].d_un.d_val = got.getLocalCount();
- _entries[_dt_pltgot].d_un.d_ptr =
- _mipsTargetLayout.findOutputSection(".got")->virtualAddr();
- }
-
-private:
- std::size_t _dt_symtabno;
- std::size_t _dt_localgot;
- std::size_t _dt_gotsym;
- std::size_t _dt_pltgot;
- std::size_t _dt_baseaddr;
- MipsTargetLayout<Mips32ElELFType> &_mipsTargetLayout;
-};
} // end namespace elf
} // end namespace lld
More information about the llvm-commits
mailing list