<div class="gmail_quote">On Tue, Apr 17, 2012 at 12:12 AM, Preston Gurd <span dir="ltr"><<a href="mailto:preston.gurd@intel.com">preston.gurd@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: pgurd<br>
Date: Mon Apr 16 17:12:58 2012<br>
New Revision: 154868<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=154868&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=154868&view=rev</a><br>
Log:<br>
Implement GDB integration for source level debugging of code JITed using<br>
the MCJIT execution engine.<br>
<br>
The GDB JIT debugging integration support works by registering a loaded<br>
object image with a pre-defined function that GDB will monitor if GDB<br>
is attached. GDB integration support is implemented for ELF only at this<br>
time. This integration requires GDB version 7.0 or newer.<br></blockquote><div><br></div><div>This broke all the CMake builds:</div><div><br></div><div><a href="http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/1496/steps/build_llvm/logs/stdio">http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/1496/steps/build_llvm/logs/stdio</a></div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Patch by Andy Kaylor!<br>
<br>
<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Object/ELF.h<br>
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt<br>
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp<br>
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp<br>
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h<br>
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h<br>
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp<br>
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h<br>
    llvm/trunk/lib/Object/ELFObjectFile.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Object/ELF.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/Object/ELF.h (original)<br>
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Apr 16 17:12:58 2012<br>
@@ -33,6 +33,15 @@<br>
 namespace llvm {<br>
 namespace object {<br>
<br>
+// Subclasses of ELFObjectFile may need this for template instantiation<br>
+inline std::pair<unsigned char, unsigned char><br>
+getElfArchType(MemoryBuffer *Object) {<br>
+  if (Object->getBufferSize() < ELF::EI_NIDENT)<br>
+    return std::make_pair((uint8_t)ELF::ELFCLASSNONE,(uint8_t)ELF::ELFDATANONE);<br>
+  return std::make_pair( (uint8_t)Object->getBufferStart()[ELF::EI_CLASS]<br>
+                       , (uint8_t)Object->getBufferStart()[ELF::EI_DATA]);<br>
+}<br>
+<br>
 // Templates to choose Elf_Addr and Elf_Off depending on is64Bits.<br>
 template<support::endianness target_endianness><br>
 struct ELFDataTypeTypedefHelperCommon {<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt Mon Apr 16 17:12:58 2012<br>
@@ -1,5 +1,6 @@<br>
 add_llvm_library(LLVMRuntimeDyld<br>
+  GDBRegistrar.cpp<br>
   RuntimeDyld.cpp<br>
-  RuntimeDyldMachO.cpp<br>
   RuntimeDyldELF.cpp<br>
+  RuntimeDyldMachO.cpp<br>
   )<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Mon Apr 16 17:12:58 2012<br>
@@ -59,11 +59,17 @@<br>
   llvm_unreachable("Attempting to remap address of unknown section!");<br>
 }<br>
<br>
+// Subclasses can implement this method to create specialized image instances<br>
+// The caller owns the the pointer that is returned.<br>
+ObjectImage *RuntimeDyldImpl::createObjectImage(const MemoryBuffer *InputBuffer) {<br>
+  ObjectFile *ObjFile = ObjectFile::createObjectFile(const_cast<MemoryBuffer*><br>
+                                                                 (InputBuffer));<br>
+  ObjectImage *Obj = new ObjectImage(ObjFile);<br>
+  return Obj;<br>
+}<br>
+<br>
 bool RuntimeDyldImpl::loadObject(const MemoryBuffer *InputBuffer) {<br>
-  // FIXME: ObjectFile don't modify MemoryBuffer.<br>
-  //        It should use const MemoryBuffer as parameter.<br>
-  OwningPtr<ObjectFile> obj(ObjectFile::createObjectFile(<br>
-                                       const_cast<MemoryBuffer*>(InputBuffer)));<br>
+  OwningPtr<ObjectImage> obj(createObjectImage(InputBuffer));<br>
   if (!obj)<br>
     report_fatal_error("Unable to create object image from memory buffer!");<br>
<br>
@@ -110,7 +116,8 @@<br>
                                 (uintptr_t)FileOffset;<br>
         uintptr_t SectOffset = (uintptr_t)(SymPtr - (const uint8_t*)sData.begin());<br>
         unsigned SectionID =<br>
-          findOrEmitSection(*si,<br>
+          findOrEmitSection(*obj,<br>
+                            *si,<br>
                             SymType == object::SymbolRef::ST_Function,<br>
                             LocalSections);<br>
         bool isGlobal = flags & SymbolRef::SF_Global;<br>
@@ -128,7 +135,7 @@<br>
<br>
   // Allocate common symbols<br>
   if (CommonSize != 0)<br>
-    emitCommonSymbols(CommonSymbols, CommonSize, LocalSymbols);<br>
+    emitCommonSymbols(*obj, CommonSymbols, CommonSize, LocalSymbols);<br>
<br>
   // Parse and proccess relocations<br>
   DEBUG(dbgs() << "Parse relocations:\n");<br>
@@ -145,7 +152,7 @@<br>
<br>
       // If it's first relocation in this section, find its SectionID<br>
       if (isFirstRelocation) {<br>
-        SectionID = findOrEmitSection(*si, true, LocalSections);<br>
+        SectionID = findOrEmitSection(*obj, *si, true, LocalSections);<br>
         DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n");<br>
         isFirstRelocation = false;<br>
       }<br>
@@ -164,10 +171,14 @@<br>
       processRelocationRef(RI, *obj, LocalSections, LocalSymbols, Stubs);<br>
     }<br>
   }<br>
+<br>
+  handleObjectLoaded(obj.take());<br>
+<br>
   return false;<br>
 }<br>
<br>
-unsigned RuntimeDyldImpl::emitCommonSymbols(const CommonSymbolMap &Map,<br>
+unsigned RuntimeDyldImpl::emitCommonSymbols(ObjectImage &Obj,<br>
+                                            const CommonSymbolMap &Map,<br>
                                             uint64_t TotalSize,<br>
                                             LocalSymbolMap &LocalSymbols) {<br>
   // Allocate memory for the section<br>
@@ -191,6 +202,7 @@<br>
     uint64_t Size = it->second;<br>
     StringRef Name;<br>
     it->first.getName(Name);<br>
+    Obj.updateSymbolAddress(it->first, (uint64_t)Addr);<br>
     LocalSymbols[Name.data()] = SymbolLoc(SectionID, Offset);<br>
     Offset += Size;<br>
     Addr += Size;<br>
@@ -199,7 +211,8 @@<br>
   return SectionID;<br>
 }<br>
<br>
-unsigned RuntimeDyldImpl::emitSection(const SectionRef &Section,<br>
+unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,<br>
+                                      const SectionRef &Section,<br>
                                       bool IsCode) {<br>
<br>
   unsigned StubBufSize = 0,<br>
@@ -257,6 +270,7 @@<br>
                  << " StubBufSize: " << StubBufSize<br>
                  << " Allocate: " << Allocate<br>
                  << "\n");<br>
+    Obj.updateSectionAddress(Section, (uint64_t)Addr);<br>
   }<br>
   else {<br>
     // Even if we didn't load the section, we need to record an entry for it<br>
@@ -277,7 +291,8 @@<br>
   return SectionID;<br>
 }<br>
<br>
-unsigned RuntimeDyldImpl::findOrEmitSection(const SectionRef &Section,<br>
+unsigned RuntimeDyldImpl::findOrEmitSection(ObjectImage &Obj,<br>
+                                            const SectionRef &Section,<br>
                                             bool IsCode,<br>
                                             ObjSectionToIDMap &LocalSections) {<br>
<br>
@@ -286,7 +301,7 @@<br>
   if (i != LocalSections.end())<br>
     SectionID = i->second;<br>
   else {<br>
-    SectionID = emitSection(Section, IsCode);<br>
+    SectionID = emitSection(Obj, Section, IsCode);<br>
     LocalSections[Section] = SectionID;<br>
   }<br>
   return SectionID;<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp Mon Apr 16 17:12:58 2012<br>
@@ -20,11 +20,176 @@<br>
 #include "llvm/Object/ObjectFile.h"<br>
 #include "llvm/Support/ELF.h"<br>
 #include "llvm/ADT/Triple.h"<br>
+#include "llvm/Object/ELF.h"<br>
+#include "JITRegistrar.h"<br>
 using namespace llvm;<br>
 using namespace llvm::object;<br>
<br>
+namespace {<br>
+<br>
+template<support::endianness target_endianness, bool is64Bits><br>
+class DyldELFObject : public ELFObjectFile<target_endianness, is64Bits> {<br>
+  LLVM_ELF_IMPORT_TYPES(target_endianness, is64Bits)<br>
+<br>
+  typedef Elf_Shdr_Impl<target_endianness, is64Bits> Elf_Shdr;<br>
+  typedef Elf_Sym_Impl<target_endianness, is64Bits> Elf_Sym;<br>
+  typedef Elf_Rel_Impl<target_endianness, is64Bits, false> Elf_Rel;<br>
+  typedef Elf_Rel_Impl<target_endianness, is64Bits, true> Elf_Rela;<br>
+<br>
+  typedef typename ELFObjectFile<target_endianness, is64Bits>::<br>
+    Elf_Ehdr Elf_Ehdr;<br>
+<br>
+  typedef typename ELFDataTypeTypedefHelper<<br>
+          target_endianness, is64Bits>::value_type addr_type;<br>
+<br>
+protected:<br>
+  // This duplicates the 'Data' member in the 'Binary' base class<br>
+  // but it is necessary to workaround a bug in gcc 4.2<br>
+  MemoryBuffer *InputData;<br>
+<br>
+public:<br>
+  DyldELFObject(MemoryBuffer *Object, error_code &ec);<br>
+<br>
+  void updateSectionAddress(const SectionRef &Sec, uint64_t Addr);<br>
+  void updateSymbolAddress(const SymbolRef &Sym, uint64_t Addr);<br>
+<br>
+  const MemoryBuffer& getBuffer() const { return *InputData; }<br>
+<br>
+  // Methods for type inquiry through isa, cast, and dyn_cast<br>
+  static inline bool classof(const Binary *v) {<br>
+    return (isa<ELFObjectFile<target_endianness, is64Bits> >(v)<br>
+            && classof(cast<ELFObjectFile<target_endianness, is64Bits> >(v)));<br>
+  }<br>
+  static inline bool classof(<br>
+      const ELFObjectFile<target_endianness, is64Bits> *v) {<br>
+    return v->isDyldType();<br>
+  }<br>
+  static inline bool classof(const DyldELFObject *v) {<br>
+    return true;<br>
+  }<br>
+};<br>
+<br>
+template<support::endianness target_endianness, bool is64Bits><br>
+class ELFObjectImage : public ObjectImage {<br>
+  protected:<br>
+    DyldELFObject<target_endianness, is64Bits> *DyldObj;<br>
+    bool Registered;<br>
+<br>
+  public:<br>
+    ELFObjectImage(DyldELFObject<target_endianness, is64Bits> *Obj)<br>
+    : ObjectImage(Obj),<br>
+      DyldObj(Obj),<br>
+      Registered(false) {}<br>
+<br>
+    virtual ~ELFObjectImage() {<br>
+      if (Registered)<br>
+        deregisterWithDebugger();<br>
+    }<br>
+<br>
+    // Subclasses can override these methods to update the image with loaded<br>
+    // addresses for sections and common symbols<br>
+    virtual void updateSectionAddress(const SectionRef &Sec, uint64_t Addr)<br>
+    {<br>
+      DyldObj->updateSectionAddress(Sec, Addr);<br>
+    }<br>
+<br>
+    virtual void updateSymbolAddress(const SymbolRef &Sym, uint64_t Addr)<br>
+    {<br>
+      DyldObj->updateSymbolAddress(Sym, Addr);<br>
+    }<br>
+<br>
+    virtual void registerWithDebugger()<br>
+    {<br>
+      JITRegistrar::getGDBRegistrar().registerObject(DyldObj->getBuffer());<br>
+      Registered = true;<br>
+    }<br>
+    virtual void deregisterWithDebugger()<br>
+    {<br>
+      JITRegistrar::getGDBRegistrar().deregisterObject(DyldObj->getBuffer());<br>
+    }<br>
+};<br>
+<br>
+template<support::endianness target_endianness, bool is64Bits><br>
+DyldELFObject<target_endianness, is64Bits>::DyldELFObject(MemoryBuffer *Object,<br>
+                                                          error_code &ec)<br>
+  : ELFObjectFile<target_endianness, is64Bits>(Object, ec),<br>
+    InputData(Object) {<br>
+  this->isDyldELFObject = true;<br>
+}<br>
+<br>
+template<support::endianness target_endianness, bool is64Bits><br>
+void DyldELFObject<target_endianness, is64Bits>::updateSectionAddress(<br>
+                                                       const SectionRef &Sec,<br>
+                                                       uint64_t Addr) {<br>
+  DataRefImpl ShdrRef = Sec.getRawDataRefImpl();<br>
+  Elf_Shdr *shdr = const_cast<Elf_Shdr*>(<br>
+                          reinterpret_cast<const Elf_Shdr *>(ShdrRef.p));<br>
+<br>
+  // This assumes the address passed in matches the target address bitness<br>
+  // The template-based type cast handles everything else.<br>
+  shdr->sh_addr = static_cast<addr_type>(Addr);<br>
+}<br>
+<br>
+template<support::endianness target_endianness, bool is64Bits><br>
+void DyldELFObject<target_endianness, is64Bits>::updateSymbolAddress(<br>
+                                                       const SymbolRef &SymRef,<br>
+                                                       uint64_t Addr) {<br>
+<br>
+  Elf_Sym *sym = const_cast<Elf_Sym*>(<br>
+                                 ELFObjectFile<target_endianness, is64Bits>::<br>
+                                   getSymbol(SymRef.getRawDataRefImpl()));<br>
+<br>
+  // This assumes the address passed in matches the target address bitness<br>
+  // The template-based type cast handles everything else.<br>
+  sym->st_value = static_cast<addr_type>(Addr);<br>
+}<br>
+<br>
+} // namespace<br>
+<br>
+<br>
 namespace llvm {<br>
<br>
+ObjectImage *RuntimeDyldELF::createObjectImage(<br>
+                                         const MemoryBuffer *ConstInputBuffer) {<br>
+  MemoryBuffer *InputBuffer = const_cast<MemoryBuffer*>(ConstInputBuffer);<br>
+  std::pair<unsigned char, unsigned char> Ident = getElfArchType(InputBuffer);<br>
+  error_code ec;<br>
+<br>
+  if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) {<br>
+    DyldELFObject<support::little, false> *Obj =<br>
+           new DyldELFObject<support::little, false>(InputBuffer, ec);<br>
+    return new ELFObjectImage<support::little, false>(Obj);<br>
+  }<br>
+  else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB) {<br>
+    DyldELFObject<support::big, false> *Obj =<br>
+           new DyldELFObject<support::big, false>(InputBuffer, ec);<br>
+    return new ELFObjectImage<support::big, false>(Obj);<br>
+  }<br>
+  else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB) {<br>
+    DyldELFObject<support::big, true> *Obj =<br>
+           new DyldELFObject<support::big, true>(InputBuffer, ec);<br>
+    return new ELFObjectImage<support::big, true>(Obj);<br>
+  }<br>
+  else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) {<br>
+    DyldELFObject<support::little, true> *Obj =<br>
+           new DyldELFObject<support::little, true>(InputBuffer, ec);<br>
+    return new ELFObjectImage<support::little, true>(Obj);<br>
+  }<br>
+  else<br>
+    llvm_unreachable("Unexpected ELF format");<br>
+}<br>
+<br>
+void RuntimeDyldELF::handleObjectLoaded(ObjectImage *Obj)<br>
+{<br>
+  Obj->registerWithDebugger();<br>
+  // Save the loaded object.  It will deregister itself when deleted<br>
+  LoadedObject = Obj;<br>
+}<br>
+<br>
+RuntimeDyldELF::~RuntimeDyldELF() {<br>
+  if (LoadedObject)<br>
+    delete LoadedObject;<br>
+}<br>
<br>
 void RuntimeDyldELF::resolveX86_64Relocation(uint8_t *LocalAddress,<br>
                                              uint64_t FinalAddress,<br>
@@ -167,7 +332,7 @@<br>
 }<br>
<br>
 void RuntimeDyldELF::processRelocationRef(const ObjRelocationInfo &Rel,<br>
-                                          const ObjectFile &Obj,<br>
+                                          ObjectImage &Obj,<br>
                                           ObjSectionToIDMap &ObjSectionToID,<br>
                                           LocalSymbolMap &Symbols,<br>
                                           StubMap &Stubs) {<br>
@@ -206,7 +371,7 @@<br>
           if (si == Obj.end_sections())<br>
             llvm_unreachable("Symbol section not found, bad object file format!");<br>
           DEBUG(dbgs() << "\t\tThis is section symbol\n");<br>
-          Value.SectionID = findOrEmitSection((*si), true, ObjSectionToID);<br>
+          Value.SectionID = findOrEmitSection(Obj, (*si), true, ObjSectionToID);<br>
           Value.Addend = Addend;<br>
           break;<br>
         }<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h Mon Apr 16 17:12:58 2012<br>
@@ -22,6 +22,8 @@<br>
 namespace llvm {<br>
 class RuntimeDyldELF : public RuntimeDyldImpl {<br>
 protected:<br>
+  ObjectImage *LoadedObject;<br>
+<br>
   void resolveX86_64Relocation(uint8_t *LocalAddress,<br>
                                uint64_t FinalAddress,<br>
                                uint64_t Value,<br>
@@ -47,12 +49,18 @@<br>
                                  int64_t Addend);<br>
<br>
   virtual void processRelocationRef(const ObjRelocationInfo &Rel,<br>
-                                    const ObjectFile &Obj,<br>
+                                    ObjectImage &Obj,<br>
                                     ObjSectionToIDMap &ObjSectionToID,<br>
                                     LocalSymbolMap &Symbols, StubMap &Stubs);<br>
<br>
+  virtual ObjectImage *createObjectImage(const MemoryBuffer *InputBuffer);<br>
+  virtual void handleObjectLoaded(ObjectImage *Obj);<br>
+<br>
 public:<br>
-  RuntimeDyldELF(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}<br>
+  RuntimeDyldELF(RTDyldMemoryManager *mm)<br>
+      : RuntimeDyldImpl(mm), LoadedObject(0) {}<br>
+<br>
+  virtual ~RuntimeDyldELF();<br>
<br>
   bool isCompatibleFormat(const MemoryBuffer *InputBuffer) const;<br>
 };<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h Mon Apr 16 17:12:58 2012<br>
@@ -29,6 +29,7 @@<br>
 #include "llvm/ADT/Triple.h"<br>
 #include <map><br>
 #include "llvm/Support/Format.h"<br>
+#include "ObjectImage.h"<br>
<br>
 using namespace llvm;<br>
 using namespace llvm::object;<br>
@@ -154,7 +155,8 @@<br>
<br>
   /// \brief Emits a section containing common symbols.<br>
   /// \return SectionID.<br>
-  unsigned emitCommonSymbols(const CommonSymbolMap &Map,<br>
+  unsigned emitCommonSymbols(ObjectImage &Obj,<br>
+                             const CommonSymbolMap &Map,<br>
                              uint64_t TotalSize,<br>
                              LocalSymbolMap &Symbols);<br>
<br>
@@ -162,14 +164,18 @@<br>
   /// \param IsCode if it's true then allocateCodeSection() will be<br>
   ///        used for emmits, else allocateDataSection() will be used.<br>
   /// \return SectionID.<br>
-  unsigned emitSection(const SectionRef &Section, bool IsCode);<br>
+  unsigned emitSection(ObjectImage &Obj,<br>
+                       const SectionRef &Section,<br>
+                       bool IsCode);<br>
<br>
   /// \brief Find Section in LocalSections. If the secton is not found - emit<br>
   ///        it and store in LocalSections.<br>
   /// \param IsCode if it's true then allocateCodeSection() will be<br>
   ///        used for emmits, else allocateDataSection() will be used.<br>
   /// \return SectionID.<br>
-  unsigned findOrEmitSection(const SectionRef &Section, bool IsCode,<br>
+  unsigned findOrEmitSection(ObjectImage &Obj,<br>
+                             const SectionRef &Section,<br>
+                             bool IsCode,<br>
                              ObjSectionToIDMap &LocalSections);<br>
<br>
   /// \brief If Value.SymbolName is NULL then store relocation to the<br>
@@ -200,11 +206,18 @@<br>
   /// \brief Parses the object file relocation and store it to Relocations<br>
   ///        or SymbolRelocations. Its depend from object file type.<br>
   virtual void processRelocationRef(const ObjRelocationInfo &Rel,<br>
-                                    const ObjectFile &Obj,<br>
+                                    ObjectImage &Obj,<br>
                                     ObjSectionToIDMap &ObjSectionToID,<br>
                                     LocalSymbolMap &Symbols, StubMap &Stubs) = 0;<br>
<br>
   void resolveSymbols();<br>
+  virtual ObjectImage *createObjectImage(const MemoryBuffer *InputBuffer);<br>
+  virtual void handleObjectLoaded(ObjectImage *Obj)<br>
+  {<br>
+    // Subclasses may choose to retain this image if they have a use for it<br>
+    delete Obj;<br>
+  }<br>
+<br>
 public:<br>
   RuntimeDyldImpl(RTDyldMemoryManager *mm) : MemMgr(mm), HasError(false) {}<br>
<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Mon Apr 16 17:12:58 2012<br>
@@ -205,7 +205,7 @@<br>
 }<br>
<br>
 void RuntimeDyldMachO::processRelocationRef(const ObjRelocationInfo &Rel,<br>
-                                            const ObjectFile &Obj,<br>
+                                            ObjectImage &Obj,<br>
                                             ObjSectionToIDMap &ObjSectionToID,<br>
                                             LocalSymbolMap &Symbols,<br>
                                             StubMap &Stubs) {<br>
@@ -246,7 +246,7 @@<br>
         break;<br>
     }<br>
     assert(si != se && "No section containing relocation!");<br>
-    Value.SectionID = findOrEmitSection(*si, true, ObjSectionToID);<br>
+    Value.SectionID = findOrEmitSection(Obj, *si, true, ObjSectionToID);<br>
     Value.Addend = *(const intptr_t *)Target;<br>
     if (Value.Addend) {<br>
       // The MachO addend is offset from the current section, we need set it<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h Mon Apr 16 17:12:58 2012<br>
@@ -49,7 +49,7 @@<br>
                             int64_t Addend);<br>
<br>
   virtual void processRelocationRef(const ObjRelocationInfo &Rel,<br>
-                                    const ObjectFile &Obj,<br>
+                                    ObjectImage &Obj,<br>
                                     ObjSectionToIDMap &ObjSectionToID,<br>
                                     LocalSymbolMap &Symbols, StubMap &Stubs);<br>
<br>
@@ -59,7 +59,7 @@<br>
                                  uint64_t Value,<br>
                                  uint32_t Type,<br>
                                  int64_t Addend);<br>
-<br>
+<br>
   RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}<br>
<br>
   bool isCompatibleFormat(const MemoryBuffer *InputBuffer) const;<br>
<br>
Modified: llvm/trunk/lib/Object/ELFObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFObjectFile.cpp?rev=154868&r1=154867&r2=154868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFObjectFile.cpp?rev=154868&r1=154867&r2=154868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Object/ELFObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Object/ELFObjectFile.cpp Mon Apr 16 17:12:58 2012<br>
@@ -17,16 +17,6 @@<br>
<br>
 using namespace object;<br>
<br>
-namespace {<br>
-  std::pair<unsigned char, unsigned char><br>
-  getElfArchType(MemoryBuffer *Object) {<br>
-    if (Object->getBufferSize() < ELF::EI_NIDENT)<br>
-      return std::make_pair((uint8_t)ELF::ELFCLASSNONE,(uint8_t)ELF::ELFDATANONE);<br>
-    return std::make_pair( (uint8_t)Object->getBufferStart()[ELF::EI_CLASS]<br>
-                         , (uint8_t)Object->getBufferStart()[ELF::EI_DATA]);<br>
-  }<br>
-}<br>
-<br>
 // Creates an in-memory object-file by default: createELFObjectFile(Buffer)<br>
 ObjectFile *ObjectFile::createELFObjectFile(MemoryBuffer *Object) {<br>
   std::pair<unsigned char, unsigned char> Ident = getElfArchType(Object);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br>