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.
// (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);