[dwarfdump] Do not apply relocations in mach-o files if there is no LoadedObjectInfo.
[oota-llvm.git] / lib / DebugInfo / DWARF / DWARFContext.cpp
index 4316934df0497380d8192329b5a3865f60aa1935..aecd991ff0db2c32c60b3e4e435054eab4ab4215 100644 (file)
@@ -637,6 +637,14 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
     if (L && L->getLoadedSectionContents(*RelocatedSection,RelSecData))
       continue;
 
+    // In Mach-o files, the relocations do not need to be applied if
+    // there is no load offset to apply. The value read at the
+    // relocation point already factors in the section address
+    // (actually applying the relocations will produce wrong results
+    // as the section address will be added twice).
+    if (!L && dyn_cast<MachOObjectFile>(&Obj))
+      continue;
+
     RelSecName = RelSecName.substr(
         RelSecName.find_first_not_of("._")); // Skip . and _ prefixes.
 
@@ -705,8 +713,8 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
         //           (Address of Section in File) +
         //           (Load Address of Section)
         if (L != nullptr && RSec != Obj.section_end()) {
-          // RSec is now either the section being targetted or the section
-          // containing the symbol being targetted. In either case,
+          // RSec is now either the section being targeted or the section
+          // containing the symbol being targeted. In either case,
           // we need to perform the same computation.
           StringRef SecName;
           RSec->getName(SecName);