mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 16:24:23 +00:00
ExecutionEngine interface to re-map addresses for engines that support it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148264 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -239,6 +239,14 @@ public:
|
|||||||
virtual void *getPointerToNamedFunction(const std::string &Name,
|
virtual void *getPointerToNamedFunction(const std::string &Name,
|
||||||
bool AbortOnFailure = true) = 0;
|
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
|
/// runStaticConstructorsDestructors - This method is used to execute all of
|
||||||
/// the static constructors or destructors for a program.
|
/// the static constructors or destructors for a program.
|
||||||
///
|
///
|
||||||
|
@ -64,6 +64,10 @@ class RuntimeDyld {
|
|||||||
// interface.
|
// interface.
|
||||||
RuntimeDyldImpl *Dyld;
|
RuntimeDyldImpl *Dyld;
|
||||||
RTDyldMemoryManager *MM;
|
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:
|
public:
|
||||||
RuntimeDyld(RTDyldMemoryManager*);
|
RuntimeDyld(RTDyldMemoryManager*);
|
||||||
~RuntimeDyld();
|
~RuntimeDyld();
|
||||||
@ -75,9 +79,13 @@ public:
|
|||||||
void *getSymbolAddress(StringRef Name);
|
void *getSymbolAddress(StringRef Name);
|
||||||
// Resolve the relocations for all symbols we currently know about.
|
// Resolve the relocations for all symbols we currently know about.
|
||||||
void resolveRelocations();
|
void resolveRelocations();
|
||||||
// Change the address associated with a section when resolving relocations.
|
|
||||||
// Any relocations already associated with the symbol will be re-resolved.
|
/// mapSectionAddress - map a section to its target address space value.
|
||||||
void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
|
/// 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();
|
StringRef getErrorString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,6 +67,14 @@ public:
|
|||||||
///
|
///
|
||||||
virtual void *getPointerToNamedFunction(const std::string &Name,
|
virtual void *getPointerToNamedFunction(const std::string &Name,
|
||||||
bool AbortOnFailure = true);
|
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
|
/// @name (Private) Registration Interfaces
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -54,6 +54,14 @@ void RuntimeDyldImpl::resolveRelocations() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 class implementation
|
||||||
RuntimeDyld::RuntimeDyld(RTDyldMemoryManager *mm) {
|
RuntimeDyld::RuntimeDyld(RTDyldMemoryManager *mm) {
|
||||||
@ -116,6 +124,11 @@ void RuntimeDyld::reassignSectionAddress(unsigned SectionID,
|
|||||||
Dyld->reassignSectionAddress(SectionID, Addr);
|
Dyld->reassignSectionAddress(SectionID, Addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RuntimeDyld::mapSectionAddress(void *LocalAddress,
|
||||||
|
uint64_t TargetAddress) {
|
||||||
|
Dyld->mapSectionAddress(LocalAddress, TargetAddress);
|
||||||
|
}
|
||||||
|
|
||||||
StringRef RuntimeDyld::getErrorString() {
|
StringRef RuntimeDyld::getErrorString() {
|
||||||
return Dyld->getErrorString();
|
return Dyld->getErrorString();
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "llvm/ExecutionEngine/RuntimeDyld.h"
|
#include "llvm/ExecutionEngine/RuntimeDyld.h"
|
||||||
#include "llvm/Object/MachOObject.h"
|
#include "llvm/Object/MachOObject.h"
|
||||||
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/IndexedMap.h"
|
#include "llvm/ADT/IndexedMap.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
#include "llvm/ADT/Twine.h"
|
#include "llvm/ADT/Twine.h"
|
||||||
@ -45,10 +46,14 @@ protected:
|
|||||||
// Indexed by SectionID.
|
// Indexed by SectionID.
|
||||||
SmallVector<sys::MemoryBlock, 32> Sections;
|
SmallVector<sys::MemoryBlock, 32> Sections;
|
||||||
// For each section, the address it will be considered to live at for
|
// 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.
|
// JITs. Indexed by SectionID.
|
||||||
SmallVector<uint64_t, 32> SectionLoadAddress;
|
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
|
// Master symbol table. As modules are loaded and external symbols are
|
||||||
// resolved, their addresses are stored here as a SectionID/Offset pair.
|
// resolved, their addresses are stored here as a SectionID/Offset pair.
|
||||||
typedef std::pair<unsigned, uint64_t> SymbolLoc;
|
typedef std::pair<unsigned, uint64_t> SymbolLoc;
|
||||||
@ -90,6 +95,8 @@ public:
|
|||||||
|
|
||||||
virtual void reassignSectionAddress(unsigned SectionID, uint64_t Addr) = 0;
|
virtual void reassignSectionAddress(unsigned SectionID, uint64_t Addr) = 0;
|
||||||
|
|
||||||
|
void mapSectionAddress(void *LocalAddress, uint64_t TargetAddress);
|
||||||
|
|
||||||
// Is the linker in an error state?
|
// Is the linker in an error state?
|
||||||
bool hasError() { return HasError; }
|
bool hasError() { return HasError; }
|
||||||
|
|
||||||
|
@ -172,6 +172,7 @@ loadSegment32(const MachOObject *Obj,
|
|||||||
|
|
||||||
// Remember what got allocated for this SectionID.
|
// Remember what got allocated for this SectionID.
|
||||||
Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
|
Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
|
||||||
|
SectionLocalMemToID[Buffer] = SectionID;
|
||||||
|
|
||||||
// By default, the load address of a section is its memory buffer.
|
// By default, the load address of a section is its memory buffer.
|
||||||
SectionLoadAddress.push_back((uint64_t)Buffer);
|
SectionLoadAddress.push_back((uint64_t)Buffer);
|
||||||
@ -291,6 +292,7 @@ loadSegment64(const MachOObject *Obj,
|
|||||||
|
|
||||||
// Remember what got allocated for this SectionID.
|
// Remember what got allocated for this SectionID.
|
||||||
Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
|
Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
|
||||||
|
SectionLocalMemToID[Buffer] = SectionID;
|
||||||
|
|
||||||
// By default, the load address of a section is its memory buffer.
|
// By default, the load address of a section is its memory buffer.
|
||||||
SectionLoadAddress.push_back((uint64_t)Buffer);
|
SectionLoadAddress.push_back((uint64_t)Buffer);
|
||||||
|
Reference in New Issue
Block a user