diff options
author | Jim Grosbach <grosbach@apple.com> | 2012-01-16 22:26:39 +0000 |
---|---|---|
committer | Jim Grosbach <grosbach@apple.com> | 2012-01-16 22:26:39 +0000 |
commit | eff0a40d7e5a440b470f8f16459c8aa1ad8c1345 (patch) | |
tree | b96f833f38527be3ec29a9dc29b2f026d3480502 /llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | |
parent | d5e4edbfbfe3a36a5733fbef65416ee0fee869c2 (diff) | |
download | bcm5719-llvm-eff0a40d7e5a440b470f8f16459c8aa1ad8c1345.tar.gz bcm5719-llvm-eff0a40d7e5a440b470f8f16459c8aa1ad8c1345.zip |
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.
llvm-svn: 148258
Diffstat (limited to 'llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 54cb350552d..5c45cf3f809 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/llvm/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; |