Fix MachO's getRelocationAdditionalInfo.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 11 Apr 2013 02:21:31 +0000 (02:21 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 11 Apr 2013 02:21:31 +0000 (02:21 +0000)
It was returning the loaded address of the section containing the relocation,
which really doesn't seem to be the intent of this function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179255 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/MachO.h
lib/Object/MachOObjectFile.cpp

index 49800fc381a6ff018a6f17cc1551fb039b0e9db0..b02e1ac100761f7b58120ec6a60381699f475a75 100644 (file)
@@ -271,6 +271,8 @@ protected:
 
   virtual error_code getLibraryNext(DataRefImpl LibData, LibraryRef &Res) const;
   virtual error_code getLibraryPath(DataRefImpl LibData, StringRef &Res) const;
+  virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
+                                                 int64_t &Res) const;
 
   std::size_t getSectionIndex(DataRefImpl Sec) const;
 
@@ -346,8 +348,6 @@ public:
   virtual error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const;
   virtual error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const;
   virtual error_code getRelocationSymbol(DataRefImpl Rel, SymbolRef &Res) const;
-  virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
-                                                 int64_t &Res) const;
   virtual error_code getRelocationType(DataRefImpl Rel, uint64_t &Res) const;
   virtual error_code getRelocationTypeName(DataRefImpl Rel,
                                            SmallVectorImpl<char> &Result) const;
@@ -531,22 +531,6 @@ MachOObjectFile<MachOT>::getRelocationSymbol(DataRefImpl Rel,
   return object_error::success;
 }
 
-template<class MachOT>
-error_code
-MachOObjectFile<MachOT>::getRelocationAdditionalInfo(DataRefImpl Rel,
-                                                     int64_t &Res) const {
-  const RelocationEntry *RE = getRelocation(Rel);
-  bool isExtern = (RE->Word1 >> 27) & 1;
-  Res = 0;
-  if (!isExtern) {
-    const uint8_t* sectAddress = base();
-    const Section *Sect = getSection(Sections[Rel.d.b]);
-    sectAddress += Sect->Offset;
-    Res = reinterpret_cast<uintptr_t>(sectAddress);
-  }
-  return object_error::success;
-}
-
 template<class MachOT>
 error_code MachOObjectFile<MachOT>::getRelocationType(DataRefImpl Rel,
                                                       uint64_t &Res) const {
index f4df8e012cf0aa2846981ff24866ec3b2bfbaf1d..c846206e6e4b099c142f951deef9866a15c67bb3 100644 (file)
@@ -512,6 +512,12 @@ error_code MachOObjectFileBase::getLibraryPath(DataRefImpl LibData,
   report_fatal_error("Needed libraries unimplemented in MachOObjectFileBase");
 }
 
+error_code MachOObjectFileBase::getRelocationAdditionalInfo(DataRefImpl Rel,
+                                                           int64_t &Res) const {
+  Res = 0;
+  return object_error::success;
+}
+
 
 /*===-- Miscellaneous -----------------------------------------------------===*/