summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/MC/MCObjectDisassembler.h16
-rw-r--r--lib/MC/MCObjectDisassembler.cpp12
2 files changed, 27 insertions, 1 deletions
diff --git a/include/llvm/MC/MCObjectDisassembler.h b/include/llvm/MC/MCObjectDisassembler.h
index de2aae7c6a..edaf7dca5a 100644
--- a/include/llvm/MC/MCObjectDisassembler.h
+++ b/include/llvm/MC/MCObjectDisassembler.h
@@ -65,6 +65,22 @@ public:
virtual ArrayRef<uint64_t> getStaticExitFunctions();
/// @}
+ /// \name Translation between effective and objectfile load address.
+ /// @{
+ /// \brief Compute the effective load address, from an objectfile virtual
+ /// address. This is implemented in a format-specific way, to take into
+ /// account things like PIE/ASLR when doing dynamic disassembly.
+ /// For example, on Mach-O this would be done by adding the VM addr slide,
+ /// on glibc ELF by keeping a map between segment load addresses, filled
+ /// using dl_iterate_phdr, etc..
+ /// In most static situations and in the default impl., this returns \p Addr.
+ virtual uint64_t getEffectiveLoadAddr(uint64_t Addr);
+
+ /// \brief Compute the original load address, as specified in the objectfile.
+ /// This is the inverse of getEffectiveLoadAddr.
+ virtual uint64_t getOriginalLoadAddr(uint64_t EffectiveAddr);
+ /// @}
+
protected:
const object::ObjectFile &Obj;
const MCDisassembler &Dis;
diff --git a/lib/MC/MCObjectDisassembler.cpp b/lib/MC/MCObjectDisassembler.cpp
index 8cb9a8abdf..4ce8e92793 100644
--- a/lib/MC/MCObjectDisassembler.cpp
+++ b/lib/MC/MCObjectDisassembler.cpp
@@ -44,7 +44,7 @@ uint64_t MCObjectDisassembler::getEntrypoint() {
if (Name == "main" || Name == "_main") {
uint64_t Entrypoint;
SI->getAddress(Entrypoint);
- return Entrypoint;
+ return getEffectiveLoadAddr(Entrypoint);
}
}
return 0;
@@ -58,6 +58,14 @@ ArrayRef<uint64_t> MCObjectDisassembler::getStaticExitFunctions() {
return ArrayRef<uint64_t>();
}
+uint64_t MCObjectDisassembler::getEffectiveLoadAddr(uint64_t Addr) {
+ return Addr;
+}
+
+uint64_t MCObjectDisassembler::getOriginalLoadAddr(uint64_t Addr) {
+ return Addr;
+}
+
MCModule *MCObjectDisassembler::buildEmptyModule() {
MCModule *Module = new MCModule;
Module->Entrypoint = getEntrypoint();
@@ -90,6 +98,7 @@ void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
uint64_t SecSize; SI->getSize(SecSize);
if (StartAddr == UnknownAddressOrSize || SecSize == UnknownAddressOrSize)
continue;
+ StartAddr = getEffectiveLoadAddr(StartAddr);
StringRef Contents; SI->getContents(Contents);
StringRefMemoryObject memoryObject(Contents, StartAddr);
@@ -170,6 +179,7 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) {
if (SymType == SymbolRef::ST_Function) {
uint64_t SymAddr;
SI->getAddress(SymAddr);
+ SymAddr = getEffectiveLoadAddr(SymAddr);
Calls.insert(SymAddr);
Splits.insert(SymAddr);
}