Index: include/llvm/Object/MachO.h =================================================================== --- include/llvm/Object/MachO.h +++ include/llvm/Object/MachO.h @@ -100,6 +100,7 @@ error_code getRelocationValueString(DataRefImpl Rel, SmallVectorImpl &Result) const override; error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const override; + error_code getRelocationLength(DataRefImpl Rel, uint8_t &Res) const; error_code getLibraryNext(DataRefImpl LibData, LibraryRef &Res) const override; Index: include/llvm/Object/RelocVisitor.h =================================================================== --- include/llvm/Object/RelocVisitor.h +++ include/llvm/Object/RelocVisitor.h @@ -18,9 +18,11 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Object/ELFObjectFile.h" +#include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ELF.h" +#include "llvm/Support/MachO.h" #include "llvm/Support/raw_ostream.h" namespace llvm { @@ -161,6 +163,14 @@ case llvm::ELF::R_ARM_ABS32: return visitELF_ARM_ABS32(R, Value); } + } else if (FileFormat == "Mach-O 64-bit x86-64") { + switch (RelocType) { + case llvm::MachO::X86_64_RELOC_UNSIGNED: + return visitMACHO_X86_64_UNSIGNED(R, Value); + default: + HasError = true; + return RelocToApply(); + } } HasError = true; return RelocToApply(); @@ -203,6 +213,15 @@ Obj->getRelocationAddend(DRI, Addend); return Addend; } + + uint8_t getLengthMachO64(RelocationRef R) { + const MachOObjectFile *Obj = cast(R.getObjectFile()); + DataRefImpl DRI = R.getRawDataRefImpl(); + uint8_t Length; + Obj->getRelocationLength(DRI, Length); + return Length; + } + /// Operations /// 386-ELF @@ -338,6 +357,14 @@ return RelocToApply(Value + Addend, 4); } + RelocToApply visitMACHO_X86_64_UNSIGNED(RelocationRef R, uint64_t Value) { + uint8_t Length = getLengthMachO64(R); + Length = 1<isELF()) { + if (Obj->isELF() || Obj->isMachO()) { object::symbol_iterator Sym = Reloc.getSymbol(); - Sym->getAddress(SymAddr); + if (Sym != Obj->symbol_end()) + Sym->getAddress(SymAddr); + else { + // MachO relocations can target sections however, + // when one is not moving sections the resulting + // relocation is a noop, so don't do anything here. + } } + DEBUG(dbgs() << "Sym Addr " << format("%p", SymAddr) << "\n"); + object::RelocVisitor V(Obj->getFileFormatName()); // The section address is always 0 for debug sections. object::RelocToApply R(V.visit(Type, Reloc, 0, SymAddr)); Index: lib/Object/MachOObjectFile.cpp =================================================================== --- lib/Object/MachOObjectFile.cpp +++ lib/Object/MachOObjectFile.cpp @@ -1170,6 +1170,13 @@ return object_error::success; } +error_code +MachOObjectFile::getRelocationLength(DataRefImpl Rel, uint8_t &Res) const { + MachO::any_relocation_info RE = getRelocation(Rel); + Res = getAnyRelocationLength(RE); + return object_error::success; +} + error_code MachOObjectFile::getLibraryNext(DataRefImpl LibData, LibraryRef &Res) const { report_fatal_error("Needed libraries unimplemented in MachOObjectFile");