diff options
author | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2013-08-21 07:28:37 +0000 |
---|---|---|
committer | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2013-08-21 07:28:37 +0000 |
commit | 2eb593682a308882c5be9322f613b1c0850fc34e (patch) | |
tree | 0f6307cda203882905319a10d0f043d381df2bd6 /llvm/lib | |
parent | 57bc9677cdd2999cd80c4473f13d52853b6507b4 (diff) | |
download | bcm5719-llvm-2eb593682a308882c5be9322f613b1c0850fc34e.tar.gz bcm5719-llvm-2eb593682a308882c5be9322f613b1c0850fc34e.zip |
MC CFG: Add "dynamic disassembly" support to MCObjectDisassembler.
It can now disassemble code in situations where the effective load
address is different than the load address declared in the object file.
This happens for PIC, hence "dynamic".
llvm-svn: 188884
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/MCObjectDisassembler.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCObjectDisassembler.cpp b/llvm/lib/MC/MCObjectDisassembler.cpp index 8cb9a8abdfa..4ce8e927933 100644 --- a/llvm/lib/MC/MCObjectDisassembler.cpp +++ b/llvm/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); } |