summaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2012-01-16 22:26:39 +0000
committerJim Grosbach <grosbach@apple.com>2012-01-16 22:26:39 +0000
commit61425c0a7f4e3608a85f7bbf254cd052a15b7446 (patch)
tree54cde5d3f935fec86f9d6bd60ce2ccbea3376cf7 /lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
parent27bf56056bed53d55d7ef0fd67d1851fa860b4f2 (diff)
downloadllvm-61425c0a7f4e3608a85f7bbf254cd052a15b7446.tar.gz
llvm-61425c0a7f4e3608a85f7bbf254cd052a15b7446.tar.bz2
llvm-61425c0a7f4e3608a85f7bbf254cd052a15b7446.tar.xz
MCJIT support for non-function sections.
Move to a by-section allocation and relocation scheme. This allows better support for sections which do not contain externally visible symbols. Flesh out the relocation address vs. local storage address separation a bit more as well. Remote process JITs use this to tell the relocation resolution code where the code will live when it executes. The startFunctionBody/endFunctionBody interfaces to the JIT and the memory manager are deprecated. They'll stick around for as long as the old JIT does, but the MCJIT doesn't use them anymore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp')
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp57
1 files changed, 44 insertions, 13 deletions
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index 54cb350552..5c45cf3f80 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -154,17 +154,31 @@ bool RuntimeDyldELF::loadObject(MemoryBuffer *InputBuffer) {
return false;
}
+void RuntimeDyldELF::resolveRelocations() {
+ // FIXME: deprecated. should be changed to use the by-section
+ // allocation and relocation scheme.
+
+ // Just iterate over the symbols in our symbol table and assign their
+ // addresses.
+ StringMap<SymbolLoc>::iterator i = SymbolTable.begin();
+ StringMap<SymbolLoc>::iterator e = SymbolTable.end();
+ for (;i != e; ++i) {
+ assert (i->getValue().second == 0 && "non-zero offset in by-function sym!");
+ reassignSymbolAddress(i->getKey(),
+ (uint8_t*)Sections[i->getValue().first].base());
+ }
+}
+
void RuntimeDyldELF::resolveX86_64Relocation(StringRef Name,
uint8_t *Addr,
const RelocationEntry &RE) {
uint8_t *TargetAddr;
if (RE.IsFunctionRelative) {
- StringMap<sys::MemoryBlock>::iterator ContainingFunc
- = Functions.find(RE.Target);
- assert(ContainingFunc != Functions.end()
- && "Function for relocation not found");
- TargetAddr = reinterpret_cast<uint8_t*>(ContainingFunc->getValue().base()) +
- RE.Offset;
+ StringMap<SymbolLoc>::const_iterator Loc = SymbolTable.find(RE.Target);
+ assert(Loc != SymbolTable.end() && "Function for relocation not found");
+ TargetAddr =
+ reinterpret_cast<uint8_t*>(Sections[Loc->second.first].base()) +
+ Loc->second.second + RE.Offset;
} else {
// FIXME: Get the address of the target section and add that to RE.Offset
assert(0 && ("Non-function relocation not implemented yet!"));
@@ -209,12 +223,11 @@ void RuntimeDyldELF::resolveX86Relocation(StringRef Name,
const RelocationEntry &RE) {
uint8_t *TargetAddr;
if (RE.IsFunctionRelative) {
- StringMap<sys::MemoryBlock>::iterator ContainingFunc
- = Functions.find(RE.Target);
- assert(ContainingFunc != Functions.end()
- && "Function for relocation not found");
- TargetAddr = reinterpret_cast<uint8_t*>(
- ContainingFunc->getValue().base()) + RE.Offset;
+ StringMap<SymbolLoc>::const_iterator Loc = SymbolTable.find(RE.Target);
+ assert(Loc != SymbolTable.end() && "Function for relocation not found");
+ TargetAddr =
+ reinterpret_cast<uint8_t*>(Sections[Loc->second.first].base()) +
+ Loc->second.second + RE.Offset;
} else {
// FIXME: Get the address of the target section and add that to RE.Offset
assert(0 && ("Non-function relocation not implemented yet!"));
@@ -266,7 +279,11 @@ void RuntimeDyldELF::resolveRelocation(StringRef Name,
}
void RuntimeDyldELF::reassignSymbolAddress(StringRef Name, uint8_t *Addr) {
- SymbolTable[Name] = Addr;
+ // FIXME: deprecated. switch to reassignSectionAddress() instead.
+ //
+ // Actually moving the symbol address requires by-section mapping.
+ assert(Sections[SymbolTable.lookup(Name).first].base() == (void*)Addr &&
+ "Unable to relocate section in by-function JIT allocation model!");
RelocationList &Relocs = Relocations[Name];
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
@@ -275,6 +292,20 @@ void RuntimeDyldELF::reassignSymbolAddress(StringRef Name, uint8_t *Addr) {
}
}
+// Assign an address to a symbol name and resolve all the relocations
+// associated with it.
+void RuntimeDyldELF::reassignSectionAddress(unsigned SectionID, uint64_t Addr) {
+ // The address to use for relocation resolution is not
+ // the address of the local section buffer. We must be doing
+ // a remote execution environment of some sort. Re-apply any
+ // relocations referencing this section with the given address.
+ //
+ // Addr is a uint64_t because we can't assume the pointer width
+ // of the target is the same as that of the host. Just use a generic
+ // "big enough" type.
+ assert(0);
+}
+
bool RuntimeDyldELF::isCompatibleFormat(const MemoryBuffer *InputBuffer) const {
StringRef Magic = InputBuffer->getBuffer().slice(0, ELF::EI_NIDENT);
return (memcmp(Magic.data(), ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;