• Home
  • Raw
  • Download

Lines Matching +full:mach +full:- +full:o

1 //===-- llvm-nm.cpp - Symbol table dumping utility for llvm ---------------===//
8 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
59 clEnumVal(darwin, "Darwin -m format"), clEnumValEnd),
61 cl::alias OutputFormat2("f", cl::desc("Alias for --format"),
67 cl::opt<bool> UndefinedOnly("undefined-only",
69 cl::alias UndefinedOnly2("u", cl::desc("Alias for --undefined-only"),
75 cl::alias DynamicSyms2("D", cl::desc("Alias for --dynamic"),
78 cl::opt<bool> DefinedOnly("defined-only",
80 cl::alias DefinedOnly2("U", cl::desc("Alias for --defined-only"),
83 cl::opt<bool> ExternalOnly("extern-only",
85 cl::alias ExternalOnly2("g", cl::desc("Alias for --extern-only"),
88 cl::opt<bool> BSDFormat("B", cl::desc("Alias for --format=bsd"),
90 cl::opt<bool> POSIXFormat("P", cl::desc("Alias for --format=posix"),
92 cl::opt<bool> DarwinFormat("m", cl::desc("Alias for --format=darwin"),
96 ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
101 "print-file-name",
104 cl::alias PrintFileNameA("A", cl::desc("Alias for --print-file-name"),
106 cl::alias PrintFileNameo("o", cl::desc("Alias for --print-file-name"),
109 cl::opt<bool> DebugSyms("debug-syms",
111 cl::alias DebugSymsa("a", cl::desc("Alias for --debug-syms"),
114 cl::opt<bool> NumericSort("numeric-sort", cl::desc("Sort symbols by address"));
115 cl::alias NumericSortn("n", cl::desc("Alias for --numeric-sort"),
117 cl::alias NumericSortv("v", cl::desc("Alias for --numeric-sort"),
120 cl::opt<bool> NoSort("no-sort", cl::desc("Show symbols in order encountered"));
121 cl::alias NoSortp("p", cl::desc("Alias for --no-sort"), cl::aliasopt(NoSort),
124 cl::opt<bool> ReverseSort("reverse-sort", cl::desc("Sort in reverse order"));
125 cl::alias ReverseSortr("r", cl::desc("Alias for --reverse-sort"),
128 cl::opt<bool> PrintSize("print-size",
130 cl::alias PrintSizeS("S", cl::desc("Alias for --print-size"),
133 cl::opt<bool> SizeSort("size-sort", cl::desc("Sort symbols by size"));
135 cl::opt<bool> WithoutAliases("without-aliases", cl::Hidden,
138 cl::opt<bool> ArchiveMap("print-armap", cl::desc("Print the archive map"));
139 cl::alias ArchiveMaps("M", cl::desc("Alias for --print-armap"),
142 enum Radix { d, o, x }; enumerator
144 AddressRadix("radix", cl::desc("Radix (o/d/x) for printing symbol Values"),
145 cl::values(clEnumVal(d, "decimal"), clEnumVal(o, "octal"),
148 cl::alias RadixAlias("t", cl::desc("Alias for --radix"),
151 cl::opt<bool> JustSymbolName("just-symbol-name",
153 cl::alias JustSymbolNames("j", cl::desc("Alias for --just-symbol-name"),
157 // on the command line. Such that "llvm-nm -s __TEXT __text foo.o" would work.
159 // this work. For now the "-s __TEXT __text" has to be last on the command
163 "and section name, Mach-O only"));
166 "Mach-O only"), cl::Grouping);
168 cl::opt<bool> NoLLVMBitcode("no-llvm-bc",
194 // "libx.a(foo.o)" after the ToolName before the error message. It sets
221 // is from, for example: "foo.o (for architecture i386)" after the ToolName
269 Module &M = IRobj->getModule(); in isSymbolList64Bit()
278 return MachO->is64Bit(); in isSymbolList64Bit()
288 // darwinPrintSymbol() is used to print a symbol from a Mach-O file when the
289 // the OutputFormat is darwin or we are printing Mach-O symbols in hex. For
290 // the darwin format it produces the same output as darwin's nm(1) -m output
291 // and when printing Mach-O symbols in hex it produces the same output as
292 // darwin's nm(1) -x format.
307 uint32_t SymFlags = I->Sym.getFlags(); in darwinPrintSymbol()
323 NSect = (getSymbolNMTypeChar(*IRobj, I->Sym) == 't') ? 1 : 2; in darwinPrintSymbol()
329 DataRefImpl SymDRI = I->Sym.getRawDataRefImpl(); in darwinPrintSymbol()
330 if (MachO->is64Bit()) { in darwinPrintSymbol()
331 H_64 = MachO->MachOObjectFile::getHeader64(); in darwinPrintSymbol()
334 MachO::nlist_64 STE_64 = MachO->getSymbol64TableEntry(SymDRI); in darwinPrintSymbol()
341 H = MachO->MachOObjectFile::getHeader(); in darwinPrintSymbol()
344 MachO::nlist STE = MachO->getSymbolTableEntry(SymDRI); in darwinPrintSymbol()
353 // If we are printing Mach-O symbols in hex do that and return. in darwinPrintSymbol()
366 outs() << I->Name << "\n"; in darwinPrintSymbol()
423 MachO->getSymbolSection(I->Sym.getRawDataRefImpl()); in darwinPrintSymbol()
430 DataRefImpl Ref = Sec->getRawDataRefImpl(); in darwinPrintSymbol()
432 MachO->getSectionName(Ref, SectionName); in darwinPrintSymbol()
433 StringRef SegmentName = MachO->getSectionFinalSegmentName(Ref); in darwinPrintSymbol()
463 outs() << "non-external (was a private external) "; in darwinPrintSymbol()
465 outs() << "non-external "; in darwinPrintSymbol()
486 outs() << I->Name << " (for "; in darwinPrintSymbol()
489 MachO->getIndirectName(I->Sym.getRawDataRefImpl(), IndirectName)) in darwinPrintSymbol()
494 outs() << I->Name; in darwinPrintSymbol()
508 MachO->getLibraryShortNameByIndex(LibraryOrdinal - 1, LibraryName)) in darwinPrintSymbol()
519 // Table that maps Darwin's Mach-O stab constants to strings to allow printing.
567 // a stab n_type value in a Mach-O file.
574 DataRefImpl SymDRI = I->Sym.getRawDataRefImpl(); in darwinPrintStab()
575 if (MachO->is64Bit()) { in darwinPrintStab()
576 STE_64 = MachO->getSymbol64TableEntry(SymDRI); in darwinPrintStab()
581 STE = MachO->getSymbolTableEntry(SymDRI); in darwinPrintStab()
631 printDashes = "----------------"; in sortAndPrintSymbolList()
633 case Radix::o: in sortAndPrintSymbolList()
644 printDashes = "--------"; in sortAndPrintSymbolList()
646 case Radix::o: in sortAndPrintSymbolList()
659 uint32_t SymFlags = I->Sym.getFlags(); in sortAndPrintSymbolList()
678 outs() << I->Name << "\n"; in sortAndPrintSymbolList()
685 if (OutputFormat == sysv || I->TypeChar == 'U') { in sortAndPrintSymbolList()
687 format(printFormat, I->Address) in sortAndPrintSymbolList()
695 if (I->TypeChar != 'U') { in sortAndPrintSymbolList()
699 format(printFormat, I->Address) in sortAndPrintSymbolList()
702 format(printFormat, I->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr)); in sortAndPrintSymbolList()
704 // If OutputFormat is darwin or we are printing Mach-O symbols in hex and in sortAndPrintSymbolList()
706 // nm(1) -m output or hex, else if OutputFormat is darwin or we are in sortAndPrintSymbolList()
707 // printing Mach-O symbols in hex and not a Mach-O object fall back to in sortAndPrintSymbolList()
714 outs() << I->Name << " " << I->TypeChar << " "; in sortAndPrintSymbolList()
726 outs() << I->TypeChar; in sortAndPrintSymbolList()
727 if (I->TypeChar == '-' && MachO) in sortAndPrintSymbolList()
729 outs() << " " << I->Name << "\n"; in sortAndPrintSymbolList()
731 std::string PaddedName(I->Name); in sortAndPrintSymbolList()
734 outs() << PaddedName << "|" << SymbolAddrStr << "| " << I->TypeChar in sortAndPrintSymbolList()
747 Expected<elf_section_iterator> SecIOrErr = SymI->getSection(); in getSymbolNMTypeChar()
755 switch (SecI->getType()) { in getSymbolNMTypeChar()
758 switch (SecI->getFlags()) { in getSymbolNMTypeChar()
775 if (SymI->getELFType() == ELF::STT_SECTION) { in getSymbolNMTypeChar()
776 Expected<StringRef> Name = SymI->getName(); in getSymbolNMTypeChar()
795 Expected<StringRef> Name = SymI->getName(); in getSymbolNMTypeChar()
811 Expected<section_iterator> SecIOrErr = SymI->getSection(); in getSymbolNMTypeChar()
818 Characteristics = Section->Characteristics; in getSymbolNMTypeChar()
843 DataRefImpl Symb = I->getRawDataRefImpl(); in getSymbolNMTypeChar()
848 return '-'; in getSymbolNMTypeChar()
862 DataRefImpl Ref = Sec->getRawDataRefImpl(); in getSymbolNMTypeChar()
882 return GV.getValueType()->isFunctionTy() ? 't' : 'd'; in getSymbolNMTypeChar()
886 const GlobalValue *GV = Obj.getSymbolGV(I->getRawDataRefImpl()); in getSymbolNMTypeChar()
893 : elf_symbol_iterator(I)->getELFType() == ELF::STT_OBJECT; in isObject()
897 uint32_t Symflags = I->getFlags(); in getNMTypeChar()
931 // getNsectForSegSect() is used to implement the Mach-O "-s segname sectname"
932 // option to dump only those symbols from that section in a Mach-O file.
933 // It is called once for each Mach-O file from dumpSymbolNamesFromObject()
935 // arguments. It returns the section number for that section in the Mach-O
939 for (auto &S : Obj->sections()) { in getNsectForSegSect()
942 Obj->getSectionName(Ref, SectionName); in getNsectForSegSect()
943 StringRef SegmentName = Obj->getSectionFinalSegmentName(Ref); in getNsectForSegSect()
951 // getNsectInMachO() is used to implement the Mach-O "-s segname sectname"
952 // option to dump only those symbols from that section in a Mach-O file.
953 // It is called once for each symbol in a Mach-O file from
977 auto DynSymbols = E->getDynamicSymbolIterators(); in dumpSymbolNamesFromObject()
983 // If a "-s segname sectname" option was specified and this is a Mach-O in dumpSymbolNamesFromObject()
999 const GlobalValue *GV = IR->getSymbolGV(Sym.getRawDataRefImpl()); in dumpSymbolNamesFromObject()
1004 // If a "-s segname sectname" option was specified and this is a Mach-O in dumpSymbolNamesFromObject()
1005 // file and this section appears in this file, Nsect will be non-zero then in dumpSymbolNamesFromObject()
1047 // checkMachOAndArchFlags() checks to see if the SymbolicFile is a Mach-O file
1049 // check to make sure this Mach-O file is one of those architectures or all
1052 static bool checkMachOAndArchFlags(SymbolicFile *O, std::string &Filename) { in checkMachOAndArchFlags() argument
1053 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(O); in checkMachOAndArchFlags()
1061 if (MachO->is64Bit()) { in checkMachOAndArchFlags()
1062 H_64 = MachO->MachOObjectFile::getHeader64(); in checkMachOAndArchFlags()
1065 H = MachO->MachOObjectFile::getHeader(); in checkMachOAndArchFlags()
1085 BufferOrErr.get()->getMemBufferRef(), NoLLVMBitcode ? nullptr : &Context); in dumpSymbolNamesFromFile()
1094 Archive::symbol_iterator I = A->symbol_begin(); in dumpSymbolNamesFromFile()
1095 Archive::symbol_iterator E = A->symbol_end(); in dumpSymbolNamesFromFile()
1099 ErrorOr<Archive::Child> C = I->getMember(); in dumpSymbolNamesFromFile()
1102 ErrorOr<StringRef> FileNameOrErr = C->getName(); in dumpSymbolNamesFromFile()
1105 StringRef SymName = I->getName(); in dumpSymbolNamesFromFile()
1114 for (auto &C : A->children(Err)) { in dumpSymbolNamesFromFile()
1121 if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) { in dumpSymbolNamesFromFile() local
1122 if (!checkMachOAndArchFlags(O, Filename)) in dumpSymbolNamesFromFile()
1126 if (isa<MachOObjectFile>(O)) { in dumpSymbolNamesFromFile()
1127 outs() << Filename << "(" << O->getFileName() << ")"; in dumpSymbolNamesFromFile()
1129 outs() << O->getFileName(); in dumpSymbolNamesFromFile()
1132 dumpSymbolNamesFromObject(*O, false, Filename); in dumpSymbolNamesFromFile()
1136 error(std::move(Err), A->getFileName()); in dumpSymbolNamesFromFile()
1147 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), in dumpSymbolNamesFromFile()
1148 E = UB->end_objects(); in dumpSymbolNamesFromFile()
1150 if (ArchFlags[i] == I->getArchTypeName()) { in dumpSymbolNamesFromFile()
1153 I->getAsObjectFile(); in dumpSymbolNamesFromFile()
1162 ArchitectureName = I->getArchTypeName(); in dumpSymbolNamesFromFile()
1165 << I->getArchTypeName() << ")" in dumpSymbolNamesFromFile()
1173 StringRef(I->getArchTypeName()) : StringRef()); in dumpSymbolNamesFromFile()
1176 I->getAsArchive()) { in dumpSymbolNamesFromFile()
1179 for (auto &C : A->children(Err)) { in dumpSymbolNamesFromFile()
1186 StringRef(I->getArchTypeName()) : StringRef()); in dumpSymbolNamesFromFile()
1190 if (SymbolicFile *O = in dumpSymbolNamesFromFile() local
1193 ArchiveName = A->getFileName(); in dumpSymbolNamesFromFile()
1195 ArchitectureName = I->getArchTypeName(); in dumpSymbolNamesFromFile()
1197 outs() << "\n" << A->getFileName(); in dumpSymbolNamesFromFile()
1198 outs() << "(" << O->getFileName() << ")"; in dumpSymbolNamesFromFile()
1200 outs() << " (for architecture " << I->getArchTypeName() in dumpSymbolNamesFromFile()
1205 dumpSymbolNamesFromObject(*O, false, ArchiveName, in dumpSymbolNamesFromFile()
1210 error(std::move(Err), A->getFileName()); in dumpSymbolNamesFromFile()
1214 StringRef(I->getArchTypeName()) + in dumpSymbolNamesFromFile()
1215 " is not a Mach-O file or an archive file", in dumpSymbolNamesFromFile()
1216 "Mach-O universal file"); in dumpSymbolNamesFromFile()
1232 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), in dumpSymbolNamesFromFile()
1233 E = UB->end_objects(); in dumpSymbolNamesFromFile()
1235 if (HostArchName == I->getArchTypeName()) { in dumpSymbolNamesFromFile()
1236 Expected<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile(); in dumpSymbolNamesFromFile()
1247 I->getAsArchive()) { in dumpSymbolNamesFromFile()
1250 for (auto &C : A->children(Err)) { in dumpSymbolNamesFromFile()
1259 if (SymbolicFile *O = in dumpSymbolNamesFromFile() local
1262 ArchiveName = A->getFileName(); in dumpSymbolNamesFromFile()
1264 outs() << "\n" << A->getFileName() << "(" << O->getFileName() in dumpSymbolNamesFromFile()
1267 dumpSymbolNamesFromObject(*O, false, ArchiveName); in dumpSymbolNamesFromFile()
1271 error(std::move(Err), A->getFileName()); in dumpSymbolNamesFromFile()
1275 StringRef(I->getArchTypeName()) + in dumpSymbolNamesFromFile()
1276 " is not a Mach-O file or an archive file", in dumpSymbolNamesFromFile()
1277 "Mach-O universal file"); in dumpSymbolNamesFromFile()
1285 bool moreThanOneArch = UB->getNumberOfObjects() > 1; in dumpSymbolNamesFromFile()
1286 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), in dumpSymbolNamesFromFile()
1287 E = UB->end_objects(); in dumpSymbolNamesFromFile()
1289 Expected<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile(); in dumpSymbolNamesFromFile()
1298 ArchitectureName = I->getArchTypeName(); in dumpSymbolNamesFromFile()
1304 outs() << " (for architecture " << I->getArchTypeName() << ")"; in dumpSymbolNamesFromFile()
1311 StringRef(I->getArchTypeName()) : StringRef()); in dumpSymbolNamesFromFile()
1314 I->getAsArchive()) { in dumpSymbolNamesFromFile()
1317 for (auto &C : A->children(Err)) { in dumpSymbolNamesFromFile()
1327 if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) { in dumpSymbolNamesFromFile() local
1329 ArchiveName = A->getFileName(); in dumpSymbolNamesFromFile()
1330 if (isa<MachOObjectFile>(O) && moreThanOneArch) in dumpSymbolNamesFromFile()
1331 ArchitectureName = I->getArchTypeName(); in dumpSymbolNamesFromFile()
1333 outs() << "\n" << A->getFileName(); in dumpSymbolNamesFromFile()
1334 if (isa<MachOObjectFile>(O)) { in dumpSymbolNamesFromFile()
1335 outs() << "(" << O->getFileName() << ")"; in dumpSymbolNamesFromFile()
1337 outs() << " (for architecture " << I->getArchTypeName() in dumpSymbolNamesFromFile()
1340 outs() << ":" << O->getFileName(); in dumpSymbolNamesFromFile()
1343 dumpSymbolNamesFromObject(*O, false, ArchiveName, ArchitectureName); in dumpSymbolNamesFromFile()
1347 error(std::move(Err), A->getFileName()); in dumpSymbolNamesFromFile()
1351 StringRef(I->getArchTypeName()) + in dumpSymbolNamesFromFile()
1352 " is not a Mach-O file or an archive file", in dumpSymbolNamesFromFile()
1353 "Mach-O universal file"); in dumpSymbolNamesFromFile()
1358 if (SymbolicFile *O = dyn_cast<SymbolicFile>(&Bin)) { in dumpSymbolNamesFromFile() local
1359 if (!checkMachOAndArchFlags(O, Filename)) in dumpSymbolNamesFromFile()
1361 dumpSymbolNamesFromObject(*O, true); in dumpSymbolNamesFromFile()
1373 // llvm-nm only reads binary files. in main()
1390 // The relative order of these is important. If you pass --size-sort it should in main()
1391 // only print out the size. However, if you pass -S --size-sort, it should in main()
1408 "for the -arch option"); in main()
1414 "for the -s option"); in main()