[llvm] r188884 - MC CFG: Add "dynamic disassembly" support to MCObjectDisassembler.
Ahmed Bougacha
ahmed.bougacha at gmail.com
Wed Aug 21 12:46:59 PDT 2013
On Wed, Aug 21, 2013 at 10:30 AM, David Blaikie <dblaikie at gmail.com> wrote:
> On Wed, Aug 21, 2013 at 12:28 AM, Ahmed Bougacha
> <ahmed.bougacha at gmail.com> wrote:
>> Author: ab
>> Date: Wed Aug 21 02:28:37 2013
>> New Revision: 188884
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=188884&view=rev
>> Log:
>> MC CFG: Add "dynamic disassembly" support to MCObjectDisassembler.
>
> Tests?
I should have made the message more obvious, but this is really a
no-op, for the following implementation.
Same thing as your other comments, could be rolled with the actual usage.
-- Ahmed
>>
>> 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".
>>
>> Modified:
>> llvm/trunk/include/llvm/MC/MCObjectDisassembler.h
>> llvm/trunk/lib/MC/MCObjectDisassembler.cpp
>>
>> Modified: llvm/trunk/include/llvm/MC/MCObjectDisassembler.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectDisassembler.h?rev=188884&r1=188883&r2=188884&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/MC/MCObjectDisassembler.h (original)
>> +++ llvm/trunk/include/llvm/MC/MCObjectDisassembler.h Wed Aug 21 02:28:37 2013
>> @@ -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;
>>
>> Modified: llvm/trunk/lib/MC/MCObjectDisassembler.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectDisassembler.cpp?rev=188884&r1=188883&r2=188884&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/MC/MCObjectDisassembler.cpp (original)
>> +++ llvm/trunk/lib/MC/MCObjectDisassembler.cpp Wed Aug 21 02:28:37 2013
>> @@ -44,7 +44,7 @@ uint64_t MCObjectDisassembler::getEntryp
>> 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:
>> 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::buildSectionA
>> 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(MCMo
>> if (SymType == SymbolRef::ST_Function) {
>> uint64_t SymAddr;
>> SI->getAddress(SymAddr);
>> + SymAddr = getEffectiveLoadAddr(SymAddr);
>> Calls.insert(SymAddr);
>> Splits.insert(SymAddr);
>> }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list