summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEli Bendersky <eli.bendersky@intel.com>2012-05-01 06:58:59 +0000
committerEli Bendersky <eli.bendersky@intel.com>2012-05-01 06:58:59 +0000
commitd98c9e918c9750d965c1efe9efcc9e13feacbe13 (patch)
treed85e0b1338e2838386364bc04162ac44393267b2 /lib
parente499cdf10c157d447393708b3a28497e42b1b555 (diff)
downloadllvm-d98c9e918c9750d965c1efe9efcc9e13feacbe13.tar.gz
llvm-d98c9e918c9750d965c1efe9efcc9e13feacbe13.tar.bz2
llvm-d98c9e918c9750d965c1efe9efcc9e13feacbe13.tar.xz
RuntimeDyld code cleanup:
- There's no point having a different type for the local and global symbol tables. - Renamed SymbolTable to GlobalSymbolTable to clarify the intention - Improved const correctness where relevant git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155898 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp29
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp9
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h3
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h16
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp8
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h3
6 files changed, 38 insertions, 30 deletions
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index ce45404051..7266f69190 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -75,11 +75,15 @@ bool RuntimeDyldImpl::loadObject(const MemoryBuffer *InputBuffer) {
Arch = (Triple::ArchType)obj->getArch();
- LocalSymbolMap LocalSymbols; // Functions and data symbols from the
- // object file.
- ObjSectionToIDMap LocalSections; // Used sections from the object file
- CommonSymbolMap CommonSymbols; // Common symbols requiring allocation
- uint64_t CommonSize = 0;
+ // Symbols found in this object
+ StringMap<SymbolLoc> LocalSymbols;
+ // Used sections from the object file
+ ObjSectionToIDMap LocalSections;
+
+ // Common symbols requiring allocation, and the total size required to
+ // allocate all common symbols.
+ CommonSymbolMap CommonSymbols;
+ uint64_t CommonSize = 0;
error_code err;
// Parse symbols
@@ -128,7 +132,7 @@ bool RuntimeDyldImpl::loadObject(const MemoryBuffer *InputBuffer) {
<< " Offset: " << format("%p", SectOffset));
bool isGlobal = flags & SymbolRef::SF_Global;
if (isGlobal)
- SymbolTable[Name] = SymbolLoc(SectionID, SectOffset);
+ GlobalSymbolTable[Name] = SymbolLoc(SectionID, SectOffset);
}
}
DEBUG(dbgs() << "\tType: " << SymType << " Name: " << Name << "\n");
@@ -181,7 +185,7 @@ bool RuntimeDyldImpl::loadObject(const MemoryBuffer *InputBuffer) {
unsigned RuntimeDyldImpl::emitCommonSymbols(ObjectImage &Obj,
const CommonSymbolMap &Map,
uint64_t TotalSize,
- LocalSymbolMap &LocalSymbols) {
+ SymbolTableMap &Symbols) {
// Allocate memory for the section
unsigned SectionID = Sections.size();
uint8_t *Addr = MemMgr->allocateDataSection(TotalSize, sizeof(void*),
@@ -204,7 +208,7 @@ unsigned RuntimeDyldImpl::emitCommonSymbols(ObjectImage &Obj,
StringRef Name;
it->first.getName(Name);
Obj.updateSymbolAddress(it->first, (uint64_t)Addr);
- LocalSymbols[Name.data()] = SymbolLoc(SectionID, Offset);
+ Symbols[Name.data()] = SymbolLoc(SectionID, Offset);
Offset += Size;
Addr += Size;
}
@@ -330,8 +334,9 @@ void RuntimeDyldImpl::addRelocation(const RelocationValueRef &Value,
// ExternalSymbolRelocations.
RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
- StringMap<SymbolLoc>::const_iterator Loc = SymbolTable.find(Value.SymbolName);
- if (Loc == SymbolTable.end()) {
+ SymbolTableMap::const_iterator Loc =
+ GlobalSymbolTable.find(Value.SymbolName);
+ if (Loc == GlobalSymbolTable.end()) {
ExternalSymbolRelocations[Value.SymbolName].push_back(RE);
} else {
RE.Addend += Loc->second.second;
@@ -400,8 +405,8 @@ void RuntimeDyldImpl::resolveExternalSymbols() {
for (; i != e; i++) {
StringRef Name = i->first();
RelocationList &Relocs = i->second;
- StringMap<SymbolLoc>::const_iterator Loc = SymbolTable.find(Name);
- if (Loc == SymbolTable.end()) {
+ SymbolTableMap::const_iterator Loc = GlobalSymbolTable.find(Name);
+ if (Loc == GlobalSymbolTable.end()) {
// This is an external symbol, try to get it address from
// MemoryManager.
uint8_t *Addr = (uint8_t*) MemMgr->getPointerToNamedFunction(Name.data(),
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index 748693c6e1..e010785c44 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -334,7 +334,7 @@ void RuntimeDyldELF::resolveRelocation(uint8_t *LocalAddress,
void RuntimeDyldELF::processRelocationRef(const ObjRelocationInfo &Rel,
ObjectImage &Obj,
ObjSectionToIDMap &ObjSectionToID,
- LocalSymbolMap &Symbols,
+ const SymbolTableMap &Symbols,
StubMap &Stubs) {
uint32_t RelType = (uint32_t)(Rel.Type & 0xffffffffL);
@@ -348,14 +348,15 @@ void RuntimeDyldELF::processRelocationRef(const ObjRelocationInfo &Rel,
<< " TargetName: " << TargetName
<< "\n");
// First look the symbol in object file symbols.
- LocalSymbolMap::iterator lsi = Symbols.find(TargetName.data());
+ SymbolTableMap::const_iterator lsi = Symbols.find(TargetName.data());
if (lsi != Symbols.end()) {
Value.SectionID = lsi->second.first;
Value.Addend = lsi->second.second;
} else {
// Second look the symbol in global symbol table.
- StringMap<SymbolLoc>::iterator gsi = SymbolTable.find(TargetName.data());
- if (gsi != SymbolTable.end()) {
+ SymbolTableMap::const_iterator gsi =
+ GlobalSymbolTable.find(TargetName.data());
+ if (gsi != GlobalSymbolTable.end()) {
Value.SectionID = gsi->second.first;
Value.Addend = gsi->second.second;
} else {
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
index e7f6fab16f..e413f780f5 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
@@ -51,7 +51,8 @@ protected:
virtual void processRelocationRef(const ObjRelocationInfo &Rel,
ObjectImage &Obj,
ObjSectionToIDMap &ObjSectionToID,
- LocalSymbolMap &Symbols, StubMap &Stubs);
+ const SymbolTableMap &Symbols,
+ StubMap &Stubs);
virtual ObjectImage *createObjectImage(const MemoryBuffer *InputBuffer);
virtual void handleObjectLoaded(ObjectImage *Obj);
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
index 42dd24cce1..f3ae7dcd98 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
@@ -129,11 +129,11 @@ protected:
// references it.
typedef std::map<SectionRef, unsigned> ObjSectionToIDMap;
- // Master symbol table. As modules are loaded and symbols are
- // resolved, their addresses are stored here as a SectionID/Offset pair.
+ // A global symbol table for symbols from all loaded modules. Maps the
+ // symbol name to a (SectionID, offset in section) pair.
typedef std::pair<unsigned, uintptr_t> SymbolLoc;
- StringMap<SymbolLoc> SymbolTable;
- typedef DenseMap<const char*, SymbolLoc> LocalSymbolMap;
+ typedef StringMap<SymbolLoc> SymbolTableMap;
+ SymbolTableMap GlobalSymbolTable;
// Keep a map of common symbols to their sizes
typedef std::map<SymbolRef, unsigned> CommonSymbolMap;
@@ -184,7 +184,7 @@ protected:
unsigned emitCommonSymbols(ObjectImage &Obj,
const CommonSymbolMap &Map,
uint64_t TotalSize,
- LocalSymbolMap &Symbols);
+ SymbolTableMap &Symbols);
/// \brief Emits section data from the object file to the MemoryManager.
/// \param IsCode if it's true then allocateCodeSection() will be
@@ -234,7 +234,7 @@ protected:
virtual void processRelocationRef(const ObjRelocationInfo &Rel,
ObjectImage &Obj,
ObjSectionToIDMap &ObjSectionToID,
- LocalSymbolMap &Symbols,
+ const SymbolTableMap &Symbols,
StubMap &Stubs) = 0;
/// \brief Resolve relocations to external symbols.
@@ -256,9 +256,9 @@ public:
void *getSymbolAddress(StringRef Name) {
// FIXME: Just look up as a function for now. Overly simple of course.
// Work in progress.
- if (SymbolTable.find(Name) == SymbolTable.end())
+ if (GlobalSymbolTable.find(Name) == GlobalSymbolTable.end())
return 0;
- SymbolLoc Loc = SymbolTable.lookup(Name);
+ SymbolLoc Loc = GlobalSymbolTable.lookup(Name);
return getSectionAddress(Loc.first) + Loc.second;
}
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
index a9574eb0ba..9bf043754b 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
@@ -205,7 +205,7 @@ bool RuntimeDyldMachO::resolveARMRelocation(uint8_t *LocalAddress,
void RuntimeDyldMachO::processRelocationRef(const ObjRelocationInfo &Rel,
ObjectImage &Obj,
ObjSectionToIDMap &ObjSectionToID,
- LocalSymbolMap &Symbols,
+ const SymbolTableMap &Symbols,
StubMap &Stubs) {
uint32_t RelType = (uint32_t) (Rel.Type & 0xffffffffL);
@@ -219,14 +219,14 @@ void RuntimeDyldMachO::processRelocationRef(const ObjRelocationInfo &Rel,
const SymbolRef &Symbol = Rel.Symbol;
Symbol.getName(TargetName);
// First look the symbol in object file symbols.
- LocalSymbolMap::iterator lsi = Symbols.find(TargetName.data());
+ SymbolTableMap::const_iterator lsi = Symbols.find(TargetName.data());
if (lsi != Symbols.end()) {
Value.SectionID = lsi->second.first;
Value.Addend = lsi->second.second;
} else {
// Second look the symbol in global symbol table.
- StringMap<SymbolLoc>::iterator gsi = SymbolTable.find(TargetName.data());
- if (gsi != SymbolTable.end()) {
+ SymbolTableMap::const_iterator gsi = GlobalSymbolTable.find(TargetName.data());
+ if (gsi != GlobalSymbolTable.end()) {
Value.SectionID = gsi->second.first;
Value.Addend = gsi->second.second;
} else
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
index 418d130f63..707664c732 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
@@ -51,7 +51,8 @@ protected:
virtual void processRelocationRef(const ObjRelocationInfo &Rel,
ObjectImage &Obj,
ObjSectionToIDMap &ObjSectionToID,
- LocalSymbolMap &Symbols, StubMap &Stubs);
+ const SymbolTableMap &Symbols,
+ StubMap &Stubs);
public:
virtual void resolveRelocation(uint8_t *LocalAddress,