[llvm] r206750 - Convert getFileOffset to getOffset and move it to its only user.

Rafael Espindola rafael.espindola at gmail.com
Mon Apr 21 06:45:33 PDT 2014


Author: rafael
Date: Mon Apr 21 08:45:32 2014
New Revision: 206750

URL: http://llvm.org/viewvc/llvm-project?rev=206750&view=rev
Log:
Convert getFileOffset to getOffset and move it to its only user.

We normally don't drop functions from the C API's, but in this case I think we
can:

* The old implementation of getFileOffset was fairly broken
* The introduction of LLVMGetSymbolFileOffset was itself a C api breaking
  change as it removed LLVMGetSymbolOffset.
* It is an incredibly specialized use case. The only reason MCJIT needs it is
  because of its odd position of being a dynamic linker of .o files.

Modified:
    llvm/trunk/bindings/python/llvm/object.py
    llvm/trunk/include/llvm-c/Object.h
    llvm/trunk/include/llvm/Object/ObjectFile.h
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
    llvm/trunk/lib/Object/Object.cpp
    llvm/trunk/tools/llvm-c-test/object.c

Modified: llvm/trunk/bindings/python/llvm/object.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/python/llvm/object.py?rev=206750&r1=206749&r2=206750&view=diff
==============================================================================
--- llvm/trunk/bindings/python/llvm/object.py (original)
+++ llvm/trunk/bindings/python/llvm/object.py Mon Apr 21 08:45:32 2014
@@ -311,14 +311,6 @@ class Symbol(LLVMObject):
         return lib.LLVMGetSymbolAddress(self)
 
     @CachedProperty
-    def file_offset(self):
-        """The offset of this symbol in the file, in long bytes."""
-        if self.expired:
-            raise Exception('Symbol instance has expired.')
-
-        return lib.LLVMGetSymbolFileOffset(self)
-
-    @CachedProperty
     def size(self):
         """The size of the symbol, in long bytes."""
         if self.expired:
@@ -345,7 +337,6 @@ class Symbol(LLVMObject):
         """Cache all cacheable properties."""
         getattr(self, 'name')
         getattr(self, 'address')
-        getattr(self, 'file_offset')
         getattr(self, 'size')
 
     def expire(self):
@@ -495,9 +486,6 @@ def register_library(library):
     library.LLVMGetSymbolAddress.argtypes = [Symbol]
     library.LLVMGetSymbolAddress.restype = c_uint64
 
-    library.LLVMGetSymbolFileOffset.argtypes = [Symbol]
-    library.LLVMGetSymbolFileOffset.restype = c_uint64
-
     library.LLVMGetSymbolSize.argtypes = [Symbol]
     library.LLVMGetSymbolSize.restype = c_uint64
 

Modified: llvm/trunk/include/llvm-c/Object.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Object.h?rev=206750&r1=206749&r2=206750&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Object.h (original)
+++ llvm/trunk/include/llvm-c/Object.h Mon Apr 21 08:45:32 2014
@@ -78,7 +78,6 @@ void LLVMMoveToNextRelocation(LLVMReloca
 // SymbolRef accessors
 const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
 uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
-uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI);
 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
 
 // RelocationRef accessors

Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=206750&r1=206749&r2=206750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Mon Apr 21 08:45:32 2014
@@ -145,7 +145,6 @@ public:
   /// Returns the symbol virtual address (i.e. address at which it will be
   /// mapped).
   error_code getAddress(uint64_t &Result) const;
-  error_code getFileOffset(uint64_t &Result) const;
   /// @brief Get the alignment of this symbol as the actual value (not log 2).
   error_code getAlignment(uint32_t &Result) const;
   error_code getSize(uint64_t &Result) const;
@@ -348,42 +347,6 @@ inline error_code SymbolRef::getAddress(
   return getObject()->getSymbolAddress(getRawDataRefImpl(), Result);
 }
 
-inline error_code SymbolRef::getFileOffset(uint64_t &Result) const {
-  uint64_t Address;
-  if (error_code EC = getAddress(Address))
-    return EC;
-  if (Address == UnknownAddressOrSize) {
-    Result = UnknownAddressOrSize;
-    return object_error::success;
-  }
-
-  const ObjectFile *Obj = getObject();
-  section_iterator SecI(Obj->section_begin());
-  if (error_code EC = getSection(SecI))
-    return EC;
-
-  if (SecI == Obj->section_end()) {
-    Result = UnknownAddressOrSize;
-    return object_error::success;
-  }
-
-  uint64_t SectionAddress;
-  if (error_code EC = SecI->getAddress(SectionAddress))
-    return EC;
-
-  uint64_t OffsetInSection = Address - SectionAddress;
-
-  StringRef SecContents;
-  if (error_code EC = SecI->getContents(SecContents))
-    return EC;
-
-  // FIXME: this is a hack.
-  uint64_t SectionOffset = (uint64_t)SecContents.data() - (uint64_t)Obj->base();
-
-  Result = SectionOffset + OffsetInSection;
-  return object_error::success;
-}
-
 inline error_code SymbolRef::getAlignment(uint32_t &Result) const {
   return getObject()->getSymbolAlignment(getRawDataRefImpl(), Result);
 }

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=206750&r1=206749&r2=206750&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Mon Apr 21 08:45:32 2014
@@ -72,6 +72,34 @@ void RuntimeDyldImpl::mapSectionAddress(
   llvm_unreachable("Attempting to remap address of unknown section!");
 }
 
+static error_code getOffset(const SymbolRef &Sym, uint64_t &Result) {
+  uint64_t Address;
+  if (error_code EC = Sym.getAddress(Address))
+    return EC;
+
+  if (Address == UnknownAddressOrSize) {
+    Result = UnknownAddressOrSize;
+    return object_error::success;
+  }
+
+  const ObjectFile *Obj = Sym.getObject();
+  section_iterator SecI(Obj->section_begin());
+  if (error_code EC = Sym.getSection(SecI))
+    return EC;
+
+ if (SecI == Obj->section_end()) {
+   Result = UnknownAddressOrSize;
+   return object_error::success;
+ }
+
+  uint64_t SectionAddress;
+  if (error_code EC = SecI->getAddress(SectionAddress))
+    return EC;
+
+  Result = Address - SectionAddress;
+  return object_error::success;
+}
+
 ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
   MutexGuard locked(lock);
 
@@ -125,26 +153,21 @@ ObjectImage *RuntimeDyldImpl::loadObject
       if (SymType == object::SymbolRef::ST_Function ||
           SymType == object::SymbolRef::ST_Data ||
           SymType == object::SymbolRef::ST_Unknown) {
-        uint64_t FileOffset;
+        uint64_t SectOffset;
         StringRef SectionData;
         bool IsCode;
         section_iterator SI = Obj->end_sections();
-        Check(I->getFileOffset(FileOffset));
+        Check(getOffset(*I, SectOffset));
         Check(I->getSection(SI));
         if (SI == Obj->end_sections())
           continue;
         Check(SI->getContents(SectionData));
         Check(SI->isText(IsCode));
-        const uint8_t *SymPtr =
-            (const uint8_t *)Obj->getData().data() + (uintptr_t)FileOffset;
-        uintptr_t SectOffset =
-            (uintptr_t)(SymPtr - (const uint8_t *)SectionData.begin());
         unsigned SectionID =
             findOrEmitSection(*Obj, *SI, IsCode, LocalSections);
         LocalSymbols[Name.data()] = SymbolLoc(SectionID, SectOffset);
-        DEBUG(dbgs() << "\tFileOffset: " << format("%p", (uintptr_t)FileOffset)
-                     << " flags: " << Flags << " SID: " << SectionID
-                     << " Offset: " << format("%p", SectOffset));
+        DEBUG(dbgs() << "\tOffset: " << format("%p", (uintptr_t)SectOffset)
+                     << " flags: " << Flags << " SID: " << SectionID);
         GlobalSymbolTable[Name] = SymbolLoc(SectionID, SectOffset);
       }
     }

Modified: llvm/trunk/lib/Object/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Object.cpp?rev=206750&r1=206749&r2=206750&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Object.cpp (original)
+++ llvm/trunk/lib/Object/Object.cpp Mon Apr 21 08:45:32 2014
@@ -184,13 +184,6 @@ uint64_t LLVMGetSymbolAddress(LLVMSymbol
   return ret;
 }
 
-uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI) {
-  uint64_t ret;
-  if (error_code ec = (*unwrap(SI))->getFileOffset(ret))
-    report_fatal_error(ec.message());
-  return ret;
-}
-
 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
   uint64_t ret;
   if (error_code ec = (*unwrap(SI))->getSize(ret))

Modified: llvm/trunk/tools/llvm-c-test/object.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/object.c?rev=206750&r1=206749&r2=206750&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/object.c (original)
+++ llvm/trunk/tools/llvm-c-test/object.c Mon Apr 21 08:45:32 2014
@@ -72,9 +72,8 @@ int object_list_symbols(void) {
   while (!LLVMIsSymbolIteratorAtEnd(O, sym)) {
 
     LLVMMoveToContainingSection(sect, sym);
-    printf("%s @0x%08" PRIx64 "/0x%08" PRIx64 " +%" PRIu64 " (%s)\n",
-           LLVMGetSymbolName(sym), LLVMGetSymbolAddress(sym),
-           LLVMGetSymbolFileOffset(sym), LLVMGetSymbolSize(sym),
+    printf("%s @0x%08" PRIx64 " +%" PRIu64 " (%s)\n", LLVMGetSymbolName(sym),
+           LLVMGetSymbolAddress(sym), LLVMGetSymbolSize(sym),
            LLVMGetSectionName(sect));
 
     LLVMMoveToNextSymbol(sym);





More information about the llvm-commits mailing list