diff --git a/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-print-mrs.test b/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-print-mrs.test --- a/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-print-mrs.test +++ b/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-print-mrs.test @@ -1,3 +1,3 @@ -RUN: llvm-objdump -d -m --no-show-raw-insn %p/Inputs/print-mrs.obj.macho-aarch64 | FileCheck %s +RUN: llvm-objdump -d -m --no-show-raw-insn --mcpu=cyclone %p/Inputs/print-mrs.obj.macho-aarch64 | FileCheck %s CHECK: 0: mrs x0, CPM_IOACC_CTL_EL3 diff --git a/llvm/test/tools/llvm-objdump/MachO/apple-latest-default.s b/llvm/test/tools/llvm-objdump/MachO/apple-latest-default.s new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/MachO/apple-latest-default.s @@ -0,0 +1,9 @@ +## Verify llvm-objdump inferred "apple-latest" by disassembling fmlal. + +# RUN: llvm-mc -triple arm64-apple-ios -mattr=+apple-a13 -filetype=obj %s \ +# RUN: -o - | llvm-objdump --macho --disassemble - | FileCheck %s + +fmlal V0.2s, v1.2h, v2.h[0] + +# CHECK: (__TEXT,__text) section +# CHECK: 0: 20 00 82 0f fmlal v0, v1, v2[0] diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -191,13 +191,19 @@ TripleName = TT.str(); } - if (TT.getArch() == Triple::arm) { + Triple::ArchType arch = TT.getArch(); + if (arch == Triple::arm) { // We've inferred a 32-bit ARM target from the object file. All MachO CPUs // that support ARM are also capable of Thumb mode. Triple ThumbTriple = TT; std::string ThumbName = (Twine("thumb") + TT.getArchName().substr(3)).str(); ThumbTriple.setArchName(ThumbName); ThumbTripleName = ThumbTriple.str(); + } else if (arch == Triple::aarch64 || arch == Triple::aarch64_32) { + // We've inferred a 64-bit ARM target. Return "apple-latest" for the + // McpuDefault. + if (*McpuDefault) + *McpuDefault = "apple-latest"; } // Get the target specific parser. @@ -380,7 +386,8 @@ BaseSegmentAddress = SLC.vmaddr; } } else if (Command.C.cmd == MachO::LC_SEGMENT_64) { - MachO::segment_command_64 SLC = MachOObj->getSegment64LoadCommand(Command); + MachO::segment_command_64 SLC = + MachOObj->getSegment64LoadCommand(Command); StringRef SegName = SLC.segname; if (!BaseSegmentAddressSet && SegName != "__PAGEZERO") { BaseSegmentAddressSet = true; @@ -391,7 +398,7 @@ } static bool DumpAndSkipDataInCode(uint64_t PC, const uint8_t *bytes, - DiceTable &Dices, uint64_t &InstSize) { + DiceTable &Dices, uint64_t &InstSize) { // Check the data in code table here to see if this is data not an // instruction to be disassembled. DiceTable Dice; @@ -783,51 +790,48 @@ static void PrintRType(const uint64_t cputype, const unsigned r_type) { static char const *generic_r_types[] = { - "VANILLA ", "PAIR ", "SECTDIF ", "PBLAPTR ", "LOCSDIF ", "TLV ", - " 6 (?) ", " 7 (?) ", " 8 (?) ", " 9 (?) ", " 10 (?) ", " 11 (?) ", - " 12 (?) ", " 13 (?) ", " 14 (?) ", " 15 (?) " - }; + "VANILLA ", "PAIR ", "SECTDIF ", "PBLAPTR ", "LOCSDIF ", "TLV ", + " 6 (?) ", " 7 (?) ", " 8 (?) ", " 9 (?) ", " 10 (?) ", " 11 (?) ", + " 12 (?) ", " 13 (?) ", " 14 (?) ", " 15 (?) "}; static char const *x86_64_r_types[] = { - "UNSIGND ", "SIGNED ", "BRANCH ", "GOT_LD ", "GOT ", "SUB ", - "SIGNED1 ", "SIGNED2 ", "SIGNED4 ", "TLV ", " 10 (?) ", " 11 (?) ", - " 12 (?) ", " 13 (?) ", " 14 (?) ", " 15 (?) " - }; + "UNSIGND ", "SIGNED ", "BRANCH ", "GOT_LD ", "GOT ", "SUB ", + "SIGNED1 ", "SIGNED2 ", "SIGNED4 ", "TLV ", " 10 (?) ", " 11 (?) ", + " 12 (?) ", " 13 (?) ", " 14 (?) ", " 15 (?) "}; static char const *arm_r_types[] = { - "VANILLA ", "PAIR ", "SECTDIFF", "LOCSDIF ", "PBLAPTR ", - "BR24 ", "T_BR22 ", "T_BR32 ", "HALF ", "HALFDIF ", - " 10 (?) ", " 11 (?) ", " 12 (?) ", " 13 (?) ", " 14 (?) ", " 15 (?) " - }; + "VANILLA ", "PAIR ", "SECTDIFF", "LOCSDIF ", "PBLAPTR ", "BR24 ", + "T_BR22 ", "T_BR32 ", "HALF ", "HALFDIF ", " 10 (?) ", " 11 (?) ", + " 12 (?) ", " 13 (?) ", " 14 (?) ", " 15 (?) "}; static char const *arm64_r_types[] = { - "UNSIGND ", "SUB ", "BR26 ", "PAGE21 ", "PAGOF12 ", - "GOTLDP ", "GOTLDPOF", "PTRTGOT ", "TLVLDP ", "TLVLDPOF", - "ADDEND ", " 11 (?) ", " 12 (?) ", " 13 (?) ", " 14 (?) ", " 15 (?) " - }; + "UNSIGND ", "SUB ", "BR26 ", "PAGE21 ", "PAGOF12 ", "GOTLDP ", + "GOTLDPOF", "PTRTGOT ", "TLVLDP ", "TLVLDPOF", "ADDEND ", " 11 (?) ", + " 12 (?) ", " 13 (?) ", " 14 (?) ", " 15 (?) "}; - if (r_type > 0xf){ + if (r_type > 0xf) { outs() << format("%-7u", r_type) << " "; return; } switch (cputype) { - case MachO::CPU_TYPE_I386: - outs() << generic_r_types[r_type]; - break; - case MachO::CPU_TYPE_X86_64: - outs() << x86_64_r_types[r_type]; - break; - case MachO::CPU_TYPE_ARM: - outs() << arm_r_types[r_type]; - break; - case MachO::CPU_TYPE_ARM64: - case MachO::CPU_TYPE_ARM64_32: - outs() << arm64_r_types[r_type]; - break; - default: - outs() << format("%-7u ", r_type); + case MachO::CPU_TYPE_I386: + outs() << generic_r_types[r_type]; + break; + case MachO::CPU_TYPE_X86_64: + outs() << x86_64_r_types[r_type]; + break; + case MachO::CPU_TYPE_ARM: + outs() << arm_r_types[r_type]; + break; + case MachO::CPU_TYPE_ARM64: + case MachO::CPU_TYPE_ARM64_32: + outs() << arm64_r_types[r_type]; + break; + default: + outs() << format("%-7u ", r_type); } } static void PrintRLength(const uint64_t cputype, const unsigned r_type, - const unsigned r_length, const bool previous_arm_half){ + const unsigned r_length, + const bool previous_arm_half) { if (cputype == MachO::CPU_TYPE_ARM && (r_type == MachO::ARM_RELOC_HALF || r_type == MachO::ARM_RELOC_HALF_SECTDIFF || previous_arm_half == true)) { @@ -841,23 +845,23 @@ outs() << "thm "; } else { switch (r_length) { - case 0: - outs() << "byte "; - break; - case 1: - outs() << "word "; - break; - case 2: - outs() << "long "; - break; - case 3: - if (cputype == MachO::CPU_TYPE_X86_64) - outs() << "quad "; - else - outs() << format("?(%2d) ", r_length); - break; - default: + case 0: + outs() << "byte "; + break; + case 1: + outs() << "word "; + break; + case 2: + outs() << "long "; + break; + case 3: + if (cputype == MachO::CPU_TYPE_X86_64) + outs() << "quad "; + else outs() << format("?(%2d) ", r_length); + break; + default: + outs() << format("?(%2d) ", r_length); } } } @@ -865,8 +869,7 @@ static void PrintRelocationEntries(const MachOObjectFile *O, const relocation_iterator Begin, const relocation_iterator End, - const uint64_t cputype, - const bool verbose) { + const uint64_t cputype, const bool verbose) { const MachO::symtab_command Symtab = O->getSymtabLoadCommand(); bool previous_arm_half = false; bool previous_sectdiff = false; @@ -880,12 +883,12 @@ const unsigned r_pcrel = O->getAnyRelocationPCRel(RE); const unsigned r_length = O->getAnyRelocationLength(RE); const unsigned r_address = O->getAnyRelocationAddress(RE); - const bool r_extern = (r_scattered ? false : - O->getPlainRelocationExternal(RE)); - const uint32_t r_value = (r_scattered ? - O->getScatteredRelocationValue(RE) : 0); - const unsigned r_symbolnum = (r_scattered ? 0 : - O->getPlainRelocationSymbolNum(RE)); + const bool r_extern = + (r_scattered ? false : O->getPlainRelocationExternal(RE)); + const uint32_t r_value = + (r_scattered ? O->getScatteredRelocationValue(RE) : 0); + const unsigned r_symbolnum = + (r_scattered ? 0 : O->getPlainRelocationSymbolNum(RE)); if (r_scattered && cputype != MachO::CPU_TYPE_X86_64) { if (verbose) { @@ -939,15 +942,13 @@ else previous_arm_half = false; outs() << "\n"; - } - else { + } else { // scattered: address pcrel length extern type scattered value outs() << format("%08x %1d %-2d n/a %-7d 1 0x%08x\n", (unsigned int)r_address, r_pcrel, r_length, r_type, (unsigned int)r_value); } - } - else { + } else { if (verbose) { // plain: address if (cputype == MachO::CPU_TYPE_ARM && r_type == MachO::ARM_RELOC_PAIR) @@ -984,8 +985,7 @@ else outs() << name << "\n"; } - } - else { + } else { // plain: extern & type & scattered outs() << "False "; PrintRType(cputype, r_type); @@ -1007,14 +1007,13 @@ uint32_t nsects = O->section_end()->getRawDataRefImpl().d.a; if (r_symbolnum > 0 && r_symbolnum <= nsects) { object::DataRefImpl DRI; - DRI.d.a = r_symbolnum-1; + DRI.d.a = r_symbolnum - 1; StringRef SegName = O->getSectionFinalSegmentName(DRI); if (Expected NameOrErr = O->getSectionName(DRI)) outs() << "(" << SegName << "," << *NameOrErr << ")\n"; else outs() << "(?,?)\n"; - } - else { + } else { outs() << "(?,?)\n"; } } @@ -1026,8 +1025,7 @@ previous_arm_half = true; else previous_arm_half = false; - } - else { + } else { // plain: address pcrel length extern type scattered symbolnum/section outs() << format("%08x %1d %-2d %1d %-7d 0 %d\n", (unsigned int)r_address, r_pcrel, r_length, r_extern, @@ -1600,8 +1598,8 @@ static void DumpInitTermPointerSection(MachOObjectFile *O, const SectionRef &Section, - const char *sect, - uint32_t sect_size, uint64_t sect_addr, + const char *sect, uint32_t sect_size, + uint64_t sect_addr, SymbolAddressMap *AddrMap, bool verbose) { uint32_t stride; @@ -1646,9 +1644,10 @@ } if (verbose) { // First look for an external relocation entry for this pointer. - auto Reloc = find_if(Relocs, [&](const std::pair &P) { - return P.first == i; - }); + auto Reloc = + find_if(Relocs, [&](const std::pair &P) { + return P.first == i; + }); if (Reloc != Relocs.end()) { symbol_iterator RelocSym = Reloc->second; outs() << " " << unwrapOrError(RelocSym->getName(), O->getFileName()); @@ -1711,9 +1710,9 @@ uint32_t size, uint32_t addr); #ifdef HAVE_LIBXAR static void DumpBitcodeSection(MachOObjectFile *O, const char *sect, - uint32_t size, bool verbose, - bool PrintXarHeader, bool PrintXarFileHeaders, - std::string XarMemberName); + uint32_t size, bool verbose, bool PrintXarHeader, + bool PrintXarFileHeaders, + std::string XarMemberName); #endif // defined(HAVE_LIBXAR) static void DumpSectionContents(StringRef Filename, MachOObjectFile *O, @@ -1851,7 +1850,8 @@ StringRef SegName = O->getSectionFinalSegmentName(Ref); if (SegName == "__TEXT" && SectName == "__info_plist") { if (!NoLeadingHeaders) - outs() << "Contents of (" << SegName << "," << SectName << ") section\n"; + outs() << "Contents of (" << SegName << "," << SectName + << ") section\n"; StringRef BytesStr = unwrapOrError(Section.getContents(), O->getFileName()); const char *sect = reinterpret_cast(BytesStr.data()); @@ -1882,13 +1882,12 @@ &McpuDefault, &ArchFlag); } else { H = MachO->MachOObjectFile::getHeader(); - T = MachOObjectFile::getArchTriple(H.cputype, H.cpusubtype, - &McpuDefault, &ArchFlag); + T = MachOObjectFile::getArchTriple(H.cputype, H.cpusubtype, &McpuDefault, + &ArchFlag); } const std::string ArchFlagName(ArchFlag); - if (none_of(ArchFlags, [&](const std::string &Name) { - return Name == ArchFlagName; - })) { + if (none_of(ArchFlags, + [&](const std::string &Name) { return Name == ArchFlagName; })) { WithColor::error(errs(), "llvm-objdump") << Filename << ": no architecture specified.\n"; return false; @@ -1954,8 +1953,7 @@ DisassembleMachO(FileName, MachOOF, SegName, SectName); } } - } - else if (Disassemble) { + } else if (Disassemble) { if (MachOOF->getHeader().filetype == MachO::MH_KEXT_BUNDLE && MachOOF->getHeader().cputype == MachO::CPU_TYPE_ARM64) DisassembleMachO(FileName, MachOOF, "__TEXT_EXEC", "__text"); @@ -2188,7 +2186,8 @@ else outs() << " capabilities " << format("0x%" PRIx32, - (cpusubtype & MachO::CPU_SUBTYPE_MASK) >> 24) << "\n"; + (cpusubtype & MachO::CPU_SUBTYPE_MASK) >> 24) + << "\n"; outs() << " offset " << OFA.getOffset(); if (OFA.getOffset() > size) outs() << " (past end of file)"; @@ -2384,12 +2383,11 @@ for (unsigned i = 0; i < ArchFlags.size(); ++i) { ArchFound = false; for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), - E = UB->end_objects(); - I != E; ++I) { + E = UB->end_objects(); + I != E; ++I) { if (ArchFlags[i] == I->getArchFlagName()) { ArchFound = true; - Expected> ObjOrErr = - I->getAsObjectFile(); + Expected> ObjOrErr = I->getAsObjectFile(); std::string ArchitectureName = ""; if (ArchFlags.size() > 1) ArchitectureName = I->getArchFlagName(); @@ -2451,8 +2449,8 @@ // matches the host architecture dump only that. if (!ArchAll) { for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), - E = UB->end_objects(); - I != E; ++I) { + E = UB->end_objects(); + I != E; ++I) { if (MachOObjectFile::getHostArch().getArchName() == I->getArchFlagName()) { Expected> ObjOrErr = I->getAsObjectFile(); @@ -2503,8 +2501,8 @@ // and this does not contain the host architecture so dump all the slices. bool moreThanOneArch = UB->getNumberOfObjects() > 1; for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), - E = UB->end_objects(); - I != E; ++I) { + E = UB->end_objects(); + I != E; ++I) { Expected> ObjOrErr = I->getAsObjectFile(); std::string ArchitectureName = ""; if (moreThanOneArch) @@ -2540,7 +2538,7 @@ dyn_cast(&*ChildOrErr.get())) { if (MachOObjectFile *MachOOF = dyn_cast(O)) ProcessMachO(Filename, MachOOF, MachOOF->getFileName(), - ArchitectureName); + ArchitectureName); } } if (Err) @@ -2559,7 +2557,7 @@ struct DisassembleInfo { DisassembleInfo(MachOObjectFile *O, SymbolAddressMap *AddrMap, std::vector *Sections, bool verbose) - : verbose(verbose), O(O), AddrMap(AddrMap), Sections(Sections) {} + : verbose(verbose), O(O), AddrMap(AddrMap), Sections(Sections) {} bool verbose; MachOObjectFile *O; SectionRef S; @@ -3148,8 +3146,8 @@ if (strcmp(*ReferenceName, "_objc_msgSend") == 0) { if (info->selector_name != nullptr) { if (info->class_name != nullptr) { - info->method = std::make_unique( - 5 + strlen(info->class_name) + strlen(info->selector_name)); + info->method = std::make_unique(5 + strlen(info->class_name) + + strlen(info->selector_name)); char *method = info->method.get(); if (method != nullptr) { strcpy(method, "+["); @@ -5377,8 +5375,8 @@ if (name != nullptr) outs() << " " << name; else { - name = get_dyld_bind_info_symbolname(S.getAddress() + - offset + offsetof(struct class64_t, superclass), info); + name = get_dyld_bind_info_symbolname( + S.getAddress() + offset + offsetof(struct class64_t, superclass), info); if (name != nullptr) outs() << " " << name; } @@ -5420,13 +5418,11 @@ if (!print_class_ro64_t((c.data + n_value) & ~0x7, info, is_meta_class)) return; - if (!is_meta_class && - c.isa + isa_n_value != p && - c.isa + isa_n_value != 0 && + if (!is_meta_class && c.isa + isa_n_value != p && c.isa + isa_n_value != 0 && info->depth < 100) { - info->depth++; - outs() << "Meta Class\n"; - print_class64_t(c.isa + isa_n_value, info); + info->depth++; + outs() << "Meta Class\n"; + print_class64_t(c.isa + isa_n_value, info); } } @@ -5990,15 +5986,15 @@ outs() << " Swift 1.0"; else if (swift_version == 2) outs() << " Swift 1.1"; - else if(swift_version == 3) + else if (swift_version == 3) outs() << " Swift 2.0"; - else if(swift_version == 4) + else if (swift_version == 4) outs() << " Swift 3.0"; - else if(swift_version == 5) + else if (swift_version == 5) outs() << " Swift 4.0"; - else if(swift_version == 6) + else if (swift_version == 6) outs() << " Swift 4.1/Swift 4.2"; - else if(swift_version == 7) + else if (swift_version == 7) outs() << " Swift 5 or later"; else outs() << " unknown future Swift version (" << swift_version << ")"; @@ -6048,15 +6044,15 @@ outs() << " Swift 1.0"; else if (swift_version == 2) outs() << " Swift 1.1"; - else if(swift_version == 3) + else if (swift_version == 3) outs() << " Swift 2.0"; - else if(swift_version == 4) + else if (swift_version == 4) outs() << " Swift 3.0"; - else if(swift_version == 5) + else if (swift_version == 5) outs() << " Swift 4.0"; - else if(swift_version == 6) + else if (swift_version == 6) outs() << " Swift 4.1/Swift 4.2"; - else if(swift_version == 7) + else if (swift_version == 7) outs() << " Swift 5 or later"; else outs() << " unknown future Swift version (" << swift_version << ")"; @@ -6481,7 +6477,7 @@ } static void PrintModeVerbose(uint32_t mode) { - switch(mode & S_IFMT){ + switch (mode & S_IFMT) { case S_IFDIR: outs() << "d"; break; @@ -6506,49 +6502,49 @@ } /* owner permissions */ - if(mode & S_IREAD) + if (mode & S_IREAD) outs() << "r"; else outs() << "-"; - if(mode & S_IWRITE) + if (mode & S_IWRITE) outs() << "w"; else outs() << "-"; - if(mode & S_ISUID) + if (mode & S_ISUID) outs() << "s"; - else if(mode & S_IEXEC) + else if (mode & S_IEXEC) outs() << "x"; else outs() << "-"; /* group permissions */ - if(mode & (S_IREAD >> 3)) + if (mode & (S_IREAD >> 3)) outs() << "r"; else outs() << "-"; - if(mode & (S_IWRITE >> 3)) + if (mode & (S_IWRITE >> 3)) outs() << "w"; else outs() << "-"; - if(mode & S_ISGID) + if (mode & S_ISGID) outs() << "s"; - else if(mode & (S_IEXEC >> 3)) + else if (mode & (S_IEXEC >> 3)) outs() << "x"; else outs() << "-"; /* other permissions */ - if(mode & (S_IREAD >> 6)) + if (mode & (S_IREAD >> 6)) outs() << "r"; else outs() << "-"; - if(mode & (S_IWRITE >> 6)) + if (mode & (S_IWRITE >> 6)) outs() << "w"; else outs() << "-"; - if(mode & S_ISVTX) + if (mode & S_ISVTX) outs() << "t"; - else if(mode & (S_IEXEC >> 6)) + else if (mode & (S_IEXEC >> 6)) outs() << "x"; else outs() << "-"; @@ -6571,7 +6567,7 @@ // Go through the xar's files. for (xf = xar_file_first(xar, xi); xf; xf = xar_file_next(xi)) { ScopedXarIter xp; - if(!xp){ + if (!xp) { WithColor::error(errs(), "llvm-objdump") << "can't obtain an xar iterator for xar archive " << XarFilename << "\n"; @@ -6584,63 +6580,63 @@ size = nullptr; mtime = nullptr; name = nullptr; - for(key = xar_prop_first(xf, xp); key; key = xar_prop_next(xp)){ + for (key = xar_prop_first(xf, xp); key; key = xar_prop_next(xp)) { const char *val = nullptr; xar_prop_get(xf, key, &val); #if 0 // Useful for debugging. outs() << "key: " << key << " value: " << val << "\n"; #endif - if(strcmp(key, "type") == 0) + if (strcmp(key, "type") == 0) type = val; - if(strcmp(key, "mode") == 0) + if (strcmp(key, "mode") == 0) mode = val; - if(strcmp(key, "user") == 0) + if (strcmp(key, "user") == 0) user = val; - if(strcmp(key, "group") == 0) + if (strcmp(key, "group") == 0) group = val; - if(strcmp(key, "data/size") == 0) + if (strcmp(key, "data/size") == 0) size = val; - if(strcmp(key, "mtime") == 0) + if (strcmp(key, "mtime") == 0) mtime = val; - if(strcmp(key, "name") == 0) + if (strcmp(key, "name") == 0) name = val; } - if(mode != nullptr){ + if (mode != nullptr) { mode_value = strtoul(mode, &endp, 8); - if(*endp != '\0') + if (*endp != '\0') outs() << "(mode: \"" << mode << "\" contains non-octal chars) "; - if(strcmp(type, "file") == 0) + if (strcmp(type, "file") == 0) mode_value |= S_IFREG; PrintModeVerbose(mode_value); outs() << " "; } - if(user != nullptr) + if (user != nullptr) outs() << format("%10s/", user); - if(group != nullptr) + if (group != nullptr) outs() << format("%-10s ", group); - if(size != nullptr) + if (size != nullptr) outs() << format("%7s ", size); - if(mtime != nullptr){ - for(m = mtime; *m != 'T' && *m != '\0'; m++) + if (mtime != nullptr) { + for (m = mtime; *m != 'T' && *m != '\0'; m++) outs() << *m; - if(*m == 'T') + if (*m == 'T') m++; outs() << " "; - for( ; *m != 'Z' && *m != '\0'; m++) + for (; *m != 'Z' && *m != '\0'; m++) outs() << *m; outs() << " "; } - if(name != nullptr) + if (name != nullptr) outs() << name; outs() << "\n"; } } static void DumpBitcodeSection(MachOObjectFile *O, const char *sect, - uint32_t size, bool verbose, - bool PrintXarHeader, bool PrintXarFileHeaders, - std::string XarMemberName) { - if(size < sizeof(struct xar_header)) { + uint32_t size, bool verbose, bool PrintXarHeader, + bool PrintXarFileHeaders, + std::string XarMemberName) { + if (size < sizeof(struct xar_header)) { outs() << "size of (__LLVM,__bundle) section too small (smaller than size " "of struct xar_header)\n"; return; @@ -6669,27 +6665,27 @@ << "\n"; outs() << " cksum_alg "; switch (XarHeader.cksum_alg) { - case XAR_CKSUM_NONE: - outs() << "XAR_CKSUM_NONE\n"; - break; - case XAR_CKSUM_SHA1: - outs() << "XAR_CKSUM_SHA1\n"; - break; - case XAR_CKSUM_MD5: - outs() << "XAR_CKSUM_MD5\n"; - break; + case XAR_CKSUM_NONE: + outs() << "XAR_CKSUM_NONE\n"; + break; + case XAR_CKSUM_SHA1: + outs() << "XAR_CKSUM_SHA1\n"; + break; + case XAR_CKSUM_MD5: + outs() << "XAR_CKSUM_MD5\n"; + break; #ifdef XAR_CKSUM_SHA256 - case XAR_CKSUM_SHA256: - outs() << "XAR_CKSUM_SHA256\n"; - break; + case XAR_CKSUM_SHA256: + outs() << "XAR_CKSUM_SHA256\n"; + break; #endif #ifdef XAR_CKSUM_SHA512 - case XAR_CKSUM_SHA512: - outs() << "XAR_CKSUM_SHA512\n"; - break; + case XAR_CKSUM_SHA512: + outs() << "XAR_CKSUM_SHA512\n"; + break; #endif - default: - outs() << XarHeader.cksum_alg << "\n"; + default: + outs() << XarHeader.cksum_alg << "\n"; } } @@ -6735,7 +6731,7 @@ } ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(TocFilename.c_str()); + MemoryBuffer::getFileOrSTDIN(TocFilename.c_str()); if (std::error_code EC = FileOrErr.getError()) { WithColor::error(errs(), "llvm-objdump") << EC.message() << "\n"; return; @@ -6751,19 +6747,19 @@ // TODO: Go through the xar's files. ScopedXarIter xi; - if(!xi){ + if (!xi) { WithColor::error(errs(), "llvm-objdump") << "can't obtain an xar iterator for xar archive " << XarFilename.c_str() << "\n"; return; } - for(xar_file_t xf = xar_file_first(xar, xi); xf; xf = xar_file_next(xi)){ + for (xar_file_t xf = xar_file_first(xar, xi); xf; xf = xar_file_next(xi)) { const char *key; const char *member_name, *member_type, *member_size_string; size_t member_size; ScopedXarIter xp; - if(!xp){ + if (!xp) { WithColor::error(errs(), "llvm-objdump") << "can't obtain an xar iterator for xar archive " << XarFilename.c_str() << "\n"; @@ -6772,7 +6768,7 @@ member_name = NULL; member_type = NULL; member_size_string = NULL; - for(key = xar_prop_first(xf, xp); key; key = xar_prop_next(xp)){ + for (key = xar_prop_first(xf, xp); key; key = xar_prop_next(xp)) { const char *val = nullptr; xar_prop_get(xf, key, &val); #if 0 // Useful for debugging. @@ -6790,8 +6786,7 @@ * and with the type being "file" see if that is a xar file. */ if (member_name != NULL && member_type != NULL && - strcmp(member_type, "file") == 0 && - member_size_string != NULL){ + strcmp(member_type, "file") == 0 && member_size_string != NULL) { // Extract the file into a buffer. char *endptr; member_size = strtoul(member_size_string, &endptr, 10); @@ -7140,8 +7135,7 @@ *ReferenceName = info->demangled_name; *ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name; } - } - else { + } else { *ReferenceName = nullptr; *ReferenceType = LLVMDisassembler_ReferenceType_InOut_None; } @@ -7263,9 +7257,8 @@ ThumbMRI.reset(ThumbTarget->createMCRegInfo(ThumbTripleName)); ThumbAsmInfo.reset( ThumbTarget->createMCAsmInfo(*ThumbMRI, ThumbTripleName, MCOptions)); - ThumbSTI.reset( - ThumbTarget->createMCSubtargetInfo(ThumbTripleName, MachOMCPU, - FeaturesStr)); + ThumbSTI.reset(ThumbTarget->createMCSubtargetInfo(ThumbTripleName, + MachOMCPU, FeaturesStr)); ThumbCtx.reset(new MCContext(ThumbAsmInfo.get(), ThumbMRI.get(), nullptr)); ThumbDisAsm.reset(ThumbTarget->createMCDisassembler(*ThumbSTI, *ThumbCtx)); MCContext *PtrThumbCtx = ThumbCtx.get(); @@ -7359,7 +7352,7 @@ DSYMBuf = std::move(BufOrErr.get()); Expected> BinaryOrErr = - createBinary(DSYMBuf.get()->getMemBufferRef()); + createBinary(DSYMBuf.get()->getMemBufferRef()); if (!BinaryOrErr) { reportError(BinaryOrErr.takeError(), DSYMPath); return; @@ -7371,14 +7364,12 @@ // this is a Mach-O object file, use it if (MachOObjectFile *MachDSYM = dyn_cast(&*O)) { DbgObj = MachDSYM; - } - else { + } else { WithColor::error(errs(), "llvm-objdump") - << DSYMPath << " is not a Mach-O file type.\n"; + << DSYMPath << " is not a Mach-O file type.\n"; return; } - } - else if (auto UB = dyn_cast(DSYMBinary.get())){ + } else if (auto UB = dyn_cast(DSYMBinary.get())) { // this is a Universal Binary, find a Mach-O for this architecture uint32_t CPUType, CPUSubType; const char *ArchFlag; @@ -7403,10 +7394,9 @@ // We need to keep the Binary alive with the buffer DbgObj = &*MachDSYM.get(); DSYMBinary = std::move(*MachDSYM); - } - else { + } else { WithColor::error(errs(), "llvm-objdump") - << DSYMPath << " is not a Mach-O or Universal file type.\n"; + << DSYMPath << " is not a Mach-O or Universal file type.\n"; return; } } @@ -7505,10 +7495,10 @@ continue; } // The __mh_execute_header is special and we need to deal with that fact - // this symbol is before the start of the (__TEXT,__text) section and at the - // address of the start of the __TEXT segment. This is because this symbol - // is an N_SECT symbol in the (__TEXT,__text) but its address is before the - // start of the section in a standard MH_EXECUTE filetype. + // this symbol is before the start of the (__TEXT,__text) section and at + // the address of the start of the __TEXT segment. This is because this + // symbol is an N_SECT symbol in the (__TEXT,__text) but its address is + // before the start of the section in a standard MH_EXECUTE filetype. if (!DisSymName.empty() && DisSymName == "__mh_execute_header") { outs() << "-dis-symname: __mh_execute_header not in any section\n"; return; @@ -7577,8 +7567,7 @@ if (DisSymName.empty() && FirstSymbol && Start != 0) { FirstSymbolAtSectionStart = false; Start = 0; - } - else + } else outs() << SymName << ":\n"; DILineInfo lastLine; @@ -7660,7 +7649,7 @@ (*(Bytes.data() + Index + 1) & 0xff) << 8; outs() << format("\t.short\t0x%04x\n", opcode); Size = 2; - } else{ + } else { WithColor::warning(errs(), "llvm-objdump") << "invalid instruction encoding\n"; if (Size == 0) @@ -7790,7 +7779,7 @@ LSDAAddr = readNext(Contents, Offset); } }; -} +} // namespace /// Given a relocation from __compact_unwind, consisting of the RelocationRef /// and data being relocated, determine the best base Name and Addend to use for @@ -7920,8 +7909,8 @@ << format("0x%" PRIx32, Entry.OffsetInSection) << ":\n"; // 1. Start of the region this entry applies to. - outs() << " start: " << format("0x%" PRIx64, - Entry.FunctionAddr) << ' '; + outs() << " start: " + << format("0x%" PRIx64, Entry.FunctionAddr) << ' '; printUnwindRelocDest(Obj, Symbols, Entry.FunctionReloc, Entry.FunctionAddr); outs() << '\n'; @@ -7943,8 +7932,8 @@ // 5. This entry's language-specific data area. if (Entry.LSDAReloc.getObject()) { - outs() << " LSDA: " << format("0x%" PRIx64, - Entry.LSDAAddr) << ' '; + outs() << " LSDA: " + << format("0x%" PRIx64, Entry.LSDAAddr) << ' '; printUnwindRelocDest(Obj, Symbols, Entry.LSDAReloc, Entry.LSDAAddr); outs() << '\n'; } @@ -8174,7 +8163,8 @@ Pos = IndexEntries[i].SecondLevelPageStart; if (Pos + sizeof(uint32_t) > Contents.size()) { - outs() << "warning: invalid offset for second level page: " << Pos << '\n'; + outs() << "warning: invalid offset for second level page: " << Pos + << '\n'; continue; } @@ -8564,9 +8554,8 @@ else outs() << "\n"; if (verbose) { - if ((maxprot & - ~(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | - MachO::VM_PROT_EXECUTE)) != 0) + if ((maxprot & ~(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | + MachO::VM_PROT_EXECUTE)) != 0) outs() << " maxprot ?" << format("0x%08" PRIx32, maxprot) << "\n"; else { outs() << " maxprot "; @@ -8574,9 +8563,8 @@ outs() << ((maxprot & MachO::VM_PROT_WRITE) ? "w" : "-"); outs() << ((maxprot & MachO::VM_PROT_EXECUTE) ? "x\n" : "-\n"); } - if ((initprot & - ~(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | - MachO::VM_PROT_EXECUTE)) != 0) + if ((initprot & ~(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | + MachO::VM_PROT_EXECUTE)) != 0) outs() << " initprot ?" << format("0x%08" PRIx32, initprot) << "\n"; else { outs() << " initprot "; @@ -9084,9 +9072,8 @@ outs() << " Incorrect size\n"; else outs() << "\n"; - outs() << " version " - << MachOObjectFile::getVersionMinMajor(vd, false) << "." - << MachOObjectFile::getVersionMinMinor(vd, false); + outs() << " version " << MachOObjectFile::getVersionMinMajor(vd, false) + << "." << MachOObjectFile::getVersionMinMinor(vd, false); uint32_t Update = MachOObjectFile::getVersionMinUpdate(vd, false); if (Update != 0) outs() << "." << Update; @@ -9094,9 +9081,8 @@ if (vd.sdk == 0) outs() << " sdk n/a"; else { - outs() << " sdk " - << MachOObjectFile::getVersionMinMajor(vd, true) << "." - << MachOObjectFile::getVersionMinMinor(vd, true); + outs() << " sdk " << MachOObjectFile::getVersionMinMajor(vd, true) + << "." << MachOObjectFile::getVersionMinMinor(vd, true); } Update = MachOObjectFile::getVersionMinUpdate(vd, true); if (Update != 0) @@ -9127,9 +9113,8 @@ MachO::build_version_command bd) { outs() << " cmd LC_BUILD_VERSION\n"; outs() << " cmdsize " << bd.cmdsize; - if (bd.cmdsize != - sizeof(struct MachO::build_version_command) + - bd.ntools * sizeof(struct MachO::build_tool_version)) + if (bd.cmdsize != sizeof(struct MachO::build_version_command) + + bd.ntools * sizeof(struct MachO::build_tool_version)) outs() << " Incorrect size\n"; else outs() << "\n"; @@ -9538,59 +9523,59 @@ static void Print_arm_thread_state32_t(MachO::arm_thread_state32_t &cpu32) { outs() << "\t r0 " << format("0x%08" PRIx32, cpu32.r[0]); - outs() << " r1 " << format("0x%08" PRIx32, cpu32.r[1]); - outs() << " r2 " << format("0x%08" PRIx32, cpu32.r[2]); - outs() << " r3 " << format("0x%08" PRIx32, cpu32.r[3]) << "\n"; + outs() << " r1 " << format("0x%08" PRIx32, cpu32.r[1]); + outs() << " r2 " << format("0x%08" PRIx32, cpu32.r[2]); + outs() << " r3 " << format("0x%08" PRIx32, cpu32.r[3]) << "\n"; outs() << "\t r4 " << format("0x%08" PRIx32, cpu32.r[4]); - outs() << " r5 " << format("0x%08" PRIx32, cpu32.r[5]); - outs() << " r6 " << format("0x%08" PRIx32, cpu32.r[6]); - outs() << " r7 " << format("0x%08" PRIx32, cpu32.r[7]) << "\n"; + outs() << " r5 " << format("0x%08" PRIx32, cpu32.r[5]); + outs() << " r6 " << format("0x%08" PRIx32, cpu32.r[6]); + outs() << " r7 " << format("0x%08" PRIx32, cpu32.r[7]) << "\n"; outs() << "\t r8 " << format("0x%08" PRIx32, cpu32.r[8]); - outs() << " r9 " << format("0x%08" PRIx32, cpu32.r[9]); - outs() << " r10 " << format("0x%08" PRIx32, cpu32.r[10]); - outs() << " r11 " << format("0x%08" PRIx32, cpu32.r[11]) << "\n"; + outs() << " r9 " << format("0x%08" PRIx32, cpu32.r[9]); + outs() << " r10 " << format("0x%08" PRIx32, cpu32.r[10]); + outs() << " r11 " << format("0x%08" PRIx32, cpu32.r[11]) << "\n"; outs() << "\t r12 " << format("0x%08" PRIx32, cpu32.r[12]); - outs() << " sp " << format("0x%08" PRIx32, cpu32.sp); - outs() << " lr " << format("0x%08" PRIx32, cpu32.lr); - outs() << " pc " << format("0x%08" PRIx32, cpu32.pc) << "\n"; + outs() << " sp " << format("0x%08" PRIx32, cpu32.sp); + outs() << " lr " << format("0x%08" PRIx32, cpu32.lr); + outs() << " pc " << format("0x%08" PRIx32, cpu32.pc) << "\n"; outs() << "\t cpsr " << format("0x%08" PRIx32, cpu32.cpsr) << "\n"; } static void Print_arm_thread_state64_t(MachO::arm_thread_state64_t &cpu64) { outs() << "\t x0 " << format("0x%016" PRIx64, cpu64.x[0]); - outs() << " x1 " << format("0x%016" PRIx64, cpu64.x[1]); - outs() << " x2 " << format("0x%016" PRIx64, cpu64.x[2]) << "\n"; + outs() << " x1 " << format("0x%016" PRIx64, cpu64.x[1]); + outs() << " x2 " << format("0x%016" PRIx64, cpu64.x[2]) << "\n"; outs() << "\t x3 " << format("0x%016" PRIx64, cpu64.x[3]); - outs() << " x4 " << format("0x%016" PRIx64, cpu64.x[4]); - outs() << " x5 " << format("0x%016" PRIx64, cpu64.x[5]) << "\n"; + outs() << " x4 " << format("0x%016" PRIx64, cpu64.x[4]); + outs() << " x5 " << format("0x%016" PRIx64, cpu64.x[5]) << "\n"; outs() << "\t x6 " << format("0x%016" PRIx64, cpu64.x[6]); - outs() << " x7 " << format("0x%016" PRIx64, cpu64.x[7]); - outs() << " x8 " << format("0x%016" PRIx64, cpu64.x[8]) << "\n"; + outs() << " x7 " << format("0x%016" PRIx64, cpu64.x[7]); + outs() << " x8 " << format("0x%016" PRIx64, cpu64.x[8]) << "\n"; outs() << "\t x9 " << format("0x%016" PRIx64, cpu64.x[9]); - outs() << " x10 " << format("0x%016" PRIx64, cpu64.x[10]); - outs() << " x11 " << format("0x%016" PRIx64, cpu64.x[11]) << "\n"; + outs() << " x10 " << format("0x%016" PRIx64, cpu64.x[10]); + outs() << " x11 " << format("0x%016" PRIx64, cpu64.x[11]) << "\n"; outs() << "\t x12 " << format("0x%016" PRIx64, cpu64.x[12]); - outs() << " x13 " << format("0x%016" PRIx64, cpu64.x[13]); - outs() << " x14 " << format("0x%016" PRIx64, cpu64.x[14]) << "\n"; + outs() << " x13 " << format("0x%016" PRIx64, cpu64.x[13]); + outs() << " x14 " << format("0x%016" PRIx64, cpu64.x[14]) << "\n"; outs() << "\t x15 " << format("0x%016" PRIx64, cpu64.x[15]); - outs() << " x16 " << format("0x%016" PRIx64, cpu64.x[16]); - outs() << " x17 " << format("0x%016" PRIx64, cpu64.x[17]) << "\n"; + outs() << " x16 " << format("0x%016" PRIx64, cpu64.x[16]); + outs() << " x17 " << format("0x%016" PRIx64, cpu64.x[17]) << "\n"; outs() << "\t x18 " << format("0x%016" PRIx64, cpu64.x[18]); - outs() << " x19 " << format("0x%016" PRIx64, cpu64.x[19]); - outs() << " x20 " << format("0x%016" PRIx64, cpu64.x[20]) << "\n"; + outs() << " x19 " << format("0x%016" PRIx64, cpu64.x[19]); + outs() << " x20 " << format("0x%016" PRIx64, cpu64.x[20]) << "\n"; outs() << "\t x21 " << format("0x%016" PRIx64, cpu64.x[21]); - outs() << " x22 " << format("0x%016" PRIx64, cpu64.x[22]); - outs() << " x23 " << format("0x%016" PRIx64, cpu64.x[23]) << "\n"; + outs() << " x22 " << format("0x%016" PRIx64, cpu64.x[22]); + outs() << " x23 " << format("0x%016" PRIx64, cpu64.x[23]) << "\n"; outs() << "\t x24 " << format("0x%016" PRIx64, cpu64.x[24]); - outs() << " x25 " << format("0x%016" PRIx64, cpu64.x[25]); - outs() << " x26 " << format("0x%016" PRIx64, cpu64.x[26]) << "\n"; + outs() << " x25 " << format("0x%016" PRIx64, cpu64.x[25]); + outs() << " x26 " << format("0x%016" PRIx64, cpu64.x[26]) << "\n"; outs() << "\t x27 " << format("0x%016" PRIx64, cpu64.x[27]); - outs() << " x28 " << format("0x%016" PRIx64, cpu64.x[28]); - outs() << " fp " << format("0x%016" PRIx64, cpu64.fp) << "\n"; + outs() << " x28 " << format("0x%016" PRIx64, cpu64.x[28]); + outs() << " fp " << format("0x%016" PRIx64, cpu64.fp) << "\n"; outs() << "\t lr " << format("0x%016" PRIx64, cpu64.lr); - outs() << " sp " << format("0x%016" PRIx64, cpu64.sp); - outs() << " pc " << format("0x%016" PRIx64, cpu64.pc) << "\n"; - outs() << "\t cpsr " << format("0x%08" PRIx32, cpu64.cpsr) << "\n"; + outs() << " sp " << format("0x%016" PRIx64, cpu64.sp); + outs() << " pc " << format("0x%016" PRIx64, cpu64.pc) << "\n"; + outs() << "\t cpsr " << format("0x%08" PRIx32, cpu64.cpsr) << "\n"; } static void PrintThreadCommand(MachO::thread_command t, const char *Ptr, @@ -10257,8 +10242,7 @@ if (ReExport) outs() << "[re-export] "; else - outs() << format("0x%08llX ", - Entry.address() + BaseSegmentAddress); + outs() << format("0x%08llX ", Entry.address() + BaseSegmentAddress); outs() << Entry.name(); if (WeakDef || ThreadLocal || Resolver || Abs) { bool NeedsComma = false; @@ -10459,9 +10443,8 @@ if (MachOObjectFile *MachO = dyn_cast(o)) printMachOLazyBindTable(MachO); else - WithColor::error() - << "This operation is only currently supported " - "for Mach-O executable files.\n"; + WithColor::error() << "This operation is only currently supported " + "for Mach-O executable files.\n"; } void objdump::printWeakBindTable(ObjectFile *o) { @@ -10469,9 +10452,8 @@ if (MachOObjectFile *MachO = dyn_cast(o)) printMachOWeakBindTable(MachO); else - WithColor::error() - << "This operation is only currently supported " - "for Mach-O executable files.\n"; + WithColor::error() << "This operation is only currently supported " + "for Mach-O executable files.\n"; } void objdump::printExportsTrie(const ObjectFile *o) { @@ -10479,9 +10461,8 @@ if (const MachOObjectFile *MachO = dyn_cast(o)) printMachOExportsTrie(MachO); else - WithColor::error() - << "This operation is only currently supported " - "for Mach-O executable files.\n"; + WithColor::error() << "This operation is only currently supported " + "for Mach-O executable files.\n"; } void objdump::printRebaseTable(ObjectFile *o) { @@ -10489,9 +10470,8 @@ if (MachOObjectFile *MachO = dyn_cast(o)) printMachORebaseTable(MachO); else - WithColor::error() - << "This operation is only currently supported " - "for Mach-O executable files.\n"; + WithColor::error() << "This operation is only currently supported " + "for Mach-O executable files.\n"; } void objdump::printBindTable(ObjectFile *o) { @@ -10499,7 +10479,6 @@ if (MachOObjectFile *MachO = dyn_cast(o)) printMachOBindTable(MachO); else - WithColor::error() - << "This operation is only currently supported " - "for Mach-O executable files.\n"; + WithColor::error() << "This operation is only currently supported " + "for Mach-O executable files.\n"; }