//===----------------------------------------------------------------------===//
#include "llvm/Object/MachO.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Format.h"
SwapValue(C.count);
}
+template<>
+void SwapStruct(MachO::version_min_command&C) {
+ SwapValue(C.cmd);
+ SwapValue(C.cmdsize);
+ SwapValue(C.version);
+ SwapValue(C.reserved);
+}
+
template<>
void SwapStruct(MachO::data_in_code_entry &C) {
SwapValue(C.offset);
if (IsScattered) {
uint32_t Val = O->getPlainRelocationSymbolNum(RE);
- for (symbol_iterator SI = O->symbol_begin(), SE = O->symbol_end();
- SI != SE; ++SI) {
+ for (const SymbolRef &Symbol : O->symbols()) {
error_code ec;
uint64_t Addr;
StringRef Name;
- if ((ec = SI->getAddress(Addr)))
+ if ((ec = Symbol.getAddress(Addr)))
report_fatal_error(ec.message());
- if (Addr != Val) continue;
- if ((ec = SI->getName(Name)))
+ if (Addr != Val)
+ continue;
+ if ((ec = Symbol.getName(Name)))
report_fatal_error(ec.message());
fmt << Name;
return;
// If we couldn't find a symbol that this relocation refers to, try
// to find a section beginning instead.
- for (section_iterator SI = O->section_begin(), SE = O->section_end();
- SI != SE; ++SI) {
+ for (const SectionRef &Section : O->sections()) {
error_code ec;
uint64_t Addr;
StringRef Name;
- if ((ec = SI->getAddress(Addr)))
+ if ((ec = Section.getAddress(Addr)))
report_fatal_error(ec.message());
- if (Addr != Val) continue;
- if ((ec = SI->getName(Name)))
+ if (Addr != Val)
+ continue;
+ if ((ec = Section.getName(Name)))
report_fatal_error(ec.message());
fmt << Name;
return;
}
// Unfortunately symbols are unsorted so we need to touch all
// symbols from load command
- for (symbol_iterator I = symbol_begin(), E = symbol_end(); I != E; ++I) {
- DataRefImpl DRI = I->getRawDataRefImpl();
+ for (const SymbolRef &Symbol : symbols()) {
+ DataRefImpl DRI = Symbol.getRawDataRefImpl();
Entry = getSymbolTableEntryBase(this, DRI);
getSymbolAddress(DRI, Value);
if (Entry.n_sect == SectionIndex && Value > BeginOffset)
return relocation_iterator(RelocationRef(Ret, this));
}
+bool MachOObjectFile::section_rel_empty(DataRefImpl Sec) const {
+ if (is64Bit()) {
+ MachO::section_64 Sect = getSection64(Sec);
+ return Sect.nreloc == 0;
+ } else {
+ MachO::section Sect = getSection(Sec);
+ return Sect.nreloc == 0;
+ }
+}
+
void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
const MachO::any_relocation_info *P =
reinterpret_cast<const MachO::any_relocation_info *>(Rel.p);
res = Table[RType];
break;
}
+ case Triple::arm64:
+ case Triple::aarch64: {
+ static const char *const Table[] = {
+ "ARM64_RELOC_UNSIGNED", "ARM64_RELOC_SUBTRACTOR",
+ "ARM64_RELOC_BRANCH26", "ARM64_RELOC_PAGE21",
+ "ARM64_RELOC_PAGEOFF12", "ARM64_RELOC_GOT_LOAD_PAGE21",
+ "ARM64_RELOC_GOT_LOAD_PAGEOFF12", "ARM64_RELOC_POINTER_TO_GOT",
+ "ARM64_RELOC_TLVP_LOAD_PAGE21", "ARM64_RELOC_TLVP_LOAD_PAGEOFF12",
+ "ARM64_RELOC_ADDEND"
+ };
+
+ if (RType >= array_lengthof(Table))
+ res = "Unknown";
+ else
+ res = Table[RType];
+ break;
+ }
case Triple::ppc: {
static const char *const Table[] = {
"PPC_RELOC_VANILLA",
switch (CPUType) {
case llvm::MachO::CPU_TYPE_X86_64:
return "Mach-O 64-bit x86-64";
+ case llvm::MachO::CPU_TYPE_ARM64:
+ return "Mach-O arm64";
case llvm::MachO::CPU_TYPE_POWERPC64:
return "Mach-O 64-bit ppc64";
default:
return Triple::x86_64;
case llvm::MachO::CPU_TYPE_ARM:
return Triple::arm;
+ case llvm::MachO::CPU_TYPE_ARM64:
+ return Triple::arm64;
case llvm::MachO::CPU_TYPE_POWERPC:
return Triple::ppc;
case llvm::MachO::CPU_TYPE_POWERPC64:
return getStruct<MachO::linker_options_command>(this, L.Ptr);
}
+MachO::version_min_command
+MachOObjectFile::getVersionMinLoadCommand(const LoadCommandInfo &L) const {
+ return getStruct<MachO::version_min_command>(this, L.Ptr);
+}
+
MachO::any_relocation_info
MachOObjectFile::getRelocation(DataRefImpl Rel) const {
const char *P = reinterpret_cast<const char *>(Rel.p);