[llvm-commits] [llvm] r148264 - in /llvm/trunk: include/llvm/ExecutionEngine/ExecutionEngine.h include/llvm/ExecutionEngine/RuntimeDyld.h lib/ExecutionEngine/MCJIT/MCJIT.h lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
Jim Grosbach
grosbach at apple.com
Mon Jan 16 15:50:55 PST 2012
Author: grosbach
Date: Mon Jan 16 17:50:55 2012
New Revision: 148264
URL: http://llvm.org/viewvc/llvm-project?rev=148264&view=rev
Log:
ExecutionEngine interface to re-map addresses for engines that support it.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h
llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=148264&r1=148263&r2=148264&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Mon Jan 16 17:50:55 2012
@@ -239,6 +239,14 @@
virtual void *getPointerToNamedFunction(const std::string &Name,
bool AbortOnFailure = true) = 0;
+ /// mapSectionAddress - map a section to its target address space value.
+ /// Map the address of a JIT section as returned from the memory manager
+ /// to the address in the target process as the running code will see it.
+ /// This is the address which will be used for relocation resolution.
+ virtual void mapSectionAddress(void *LocalAddress, uint64_t TargetAddress) {
+ assert(0 && "Re-mapping of section addresses not supported with this EE!");
+ }
+
/// runStaticConstructorsDestructors - This method is used to execute all of
/// the static constructors or destructors for a program.
///
Modified: llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h?rev=148264&r1=148263&r2=148264&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h Mon Jan 16 17:50:55 2012
@@ -64,6 +64,10 @@
// interface.
RuntimeDyldImpl *Dyld;
RTDyldMemoryManager *MM;
+protected:
+ // Change the address associated with a section when resolving relocations.
+ // Any relocations already associated with the symbol will be re-resolved.
+ void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
public:
RuntimeDyld(RTDyldMemoryManager*);
~RuntimeDyld();
@@ -75,9 +79,13 @@
void *getSymbolAddress(StringRef Name);
// Resolve the relocations for all symbols we currently know about.
void resolveRelocations();
- // Change the address associated with a section when resolving relocations.
- // Any relocations already associated with the symbol will be re-resolved.
- void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
+
+ /// mapSectionAddress - map a section to its target address space value.
+ /// Map the address of a JIT section as returned from the memory manager
+ /// to the address in the target process as the running code will see it.
+ /// This is the address which will be used for relocation resolution.
+ void mapSectionAddress(void *LocalAddress, uint64_t TargetAddress);
+
StringRef getErrorString();
};
Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h?rev=148264&r1=148263&r2=148264&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h Mon Jan 16 17:50:55 2012
@@ -67,6 +67,14 @@
///
virtual void *getPointerToNamedFunction(const std::string &Name,
bool AbortOnFailure = true);
+ /// mapSectionAddress - map a section to its target address space value.
+ /// Map the address of a JIT section as returned from the memory manager
+ /// to the address in the target process as the running code will see it.
+ /// This is the address which will be used for relocation resolution.
+ virtual void mapSectionAddress(void *LocalAddress, uint64_t TargetAddress) {
+ Dyld.mapSectionAddress(LocalAddress, TargetAddress);
+ }
+
/// @}
/// @name (Private) Registration Interfaces
/// @{
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=148264&r1=148263&r2=148264&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Mon Jan 16 17:50:55 2012
@@ -54,6 +54,14 @@
}
}
+void RuntimeDyldImpl::mapSectionAddress(void *LocalAddress,
+ uint64_t TargetAddress) {
+ assert(SectionLocalMemToID.count(LocalAddress) &&
+ "Attempting to remap address of unknown section!");
+ unsigned SectionID = SectionLocalMemToID[LocalAddress];
+ reassignSectionAddress(SectionID, TargetAddress);
+}
+
//===----------------------------------------------------------------------===//
// RuntimeDyld class implementation
RuntimeDyld::RuntimeDyld(RTDyldMemoryManager *mm) {
@@ -116,6 +124,11 @@
Dyld->reassignSectionAddress(SectionID, Addr);
}
+void RuntimeDyld::mapSectionAddress(void *LocalAddress,
+ uint64_t TargetAddress) {
+ Dyld->mapSectionAddress(LocalAddress, TargetAddress);
+}
+
StringRef RuntimeDyld::getErrorString() {
return Dyld->getErrorString();
}
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h?rev=148264&r1=148263&r2=148264&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h Mon Jan 16 17:50:55 2012
@@ -16,6 +16,7 @@
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/Object/MachOObject.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/IndexedMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
@@ -45,10 +46,14 @@
// Indexed by SectionID.
SmallVector<sys::MemoryBlock, 32> Sections;
// For each section, the address it will be considered to live at for
- // relocations. The same as the pointer the above memory block for hosted
+ // relocations. The same as the pointer to the above memory block for hosted
// JITs. Indexed by SectionID.
SmallVector<uint64_t, 32> SectionLoadAddress;
+ // Keep a map of starting local address to the SectionID which references it.
+ // Lookup function for when we assign virtual addresses.
+ DenseMap<void *, unsigned> SectionLocalMemToID;
+
// Master symbol table. As modules are loaded and external symbols are
// resolved, their addresses are stored here as a SectionID/Offset pair.
typedef std::pair<unsigned, uint64_t> SymbolLoc;
@@ -90,6 +95,8 @@
virtual void reassignSectionAddress(unsigned SectionID, uint64_t Addr) = 0;
+ void mapSectionAddress(void *LocalAddress, uint64_t TargetAddress);
+
// Is the linker in an error state?
bool hasError() { return HasError; }
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=148264&r1=148263&r2=148264&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Mon Jan 16 17:50:55 2012
@@ -172,6 +172,7 @@
// Remember what got allocated for this SectionID.
Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
+ SectionLocalMemToID[Buffer] = SectionID;
// By default, the load address of a section is its memory buffer.
SectionLoadAddress.push_back((uint64_t)Buffer);
@@ -291,6 +292,7 @@
// Remember what got allocated for this SectionID.
Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
+ SectionLocalMemToID[Buffer] = SectionID;
// By default, the load address of a section is its memory buffer.
SectionLoadAddress.push_back((uint64_t)Buffer);
More information about the llvm-commits
mailing list