static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName, std::string ArchiveName = std::string(), std::string ArchitectureName = std::string()) { basic_symbol_iterator IBegin = Obj.symbol_begin(); basic_symbol_iterator IEnd = Obj.symbol_end(); if (DynamicSyms) { if (!Obj.isELF()) { error("File format has no dynamic symbol table", Obj.getFileName()); return; } std::pair<symbol_iterator, symbol_iterator> IDyn = getELFDynamicSymbolIterators(&Obj); IBegin = IDyn.first; IEnd = IDyn.second; } std::string NameBuffer; raw_string_ostream OS(NameBuffer); // If a "-s segname sectname" option was specified and this is a Mach-O // file get the section number for that section in this object file. unsigned int Nsect = 0; MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj); if (SegSect.size() != 0 && MachO) { Nsect = getNsectForSegSect(MachO); // If this section is not in the object file no symbols are printed. if (Nsect == 0) return; } for (basic_symbol_iterator I = IBegin; I != IEnd; ++I) { uint32_t SymFlags = I->getFlags(); if (!DebugSyms && (SymFlags & SymbolRef::SF_FormatSpecific)) continue; if (WithoutAliases) { if (IRObjectFile *IR = dyn_cast<IRObjectFile>(&Obj)) { const GlobalValue *GV = IR->getSymbolGV(I->getRawDataRefImpl()); if (GV && isa<GlobalAlias>(GV)) continue; } } // If a "-s segname sectname" option was specified and this is a Mach-O // file and this section appears in this file, Nsect will be non-zero then // see if this symbol is a symbol from that section and if not skip it. if (Nsect && Nsect != getNsectInMachO(*MachO, I)) continue; NMSymbol S; S.Size = UnknownAddressOrSize; S.Address = UnknownAddressOrSize; if ((PrintSize || SizeSort) && isa<ObjectFile>(Obj)) { symbol_iterator SymI = I; if (error(SymI->getSize(S.Size))) break; } if (PrintAddress && isa<ObjectFile>(Obj)) if (error(symbol_iterator(I)->getAddress(S.Address))) break; S.TypeChar = getNMTypeChar(Obj, I); if (error(I->printName(OS))) break; OS << '\0'; S.Symb = I->getRawDataRefImpl(); SymbolList.push_back(S); } OS.flush(); const char *P = NameBuffer.c_str(); for (unsigned I = 0; I < SymbolList.size(); ++I) { SymbolList[I].Name = P; P += strlen(P) + 1; } CurrentFilename = Obj.getFileName(); sortAndPrintSymbolList(Obj, printName, ArchiveName, ArchitectureName); }
static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName, std::string ArchiveName = std::string(), std::string ArchitectureName = std::string()) { auto Symbols = Obj.symbols(); if (DynamicSyms) { const auto *E = dyn_cast<ELFObjectFileBase>(&Obj); if (!E) { error("File format has no dynamic symbol table", Obj.getFileName()); return; } auto DynSymbols = E->getDynamicSymbolIterators(); Symbols = make_range<basic_symbol_iterator>(DynSymbols.begin(), DynSymbols.end()); } std::string NameBuffer; raw_string_ostream OS(NameBuffer); // If a "-s segname sectname" option was specified and this is a Mach-O // file get the section number for that section in this object file. unsigned int Nsect = 0; MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj); if (SegSect.size() != 0 && MachO) { Nsect = getNsectForSegSect(MachO); // If this section is not in the object file no symbols are printed. if (Nsect == 0) return; } for (BasicSymbolRef Sym : Symbols) { uint32_t SymFlags = Sym.getFlags(); if (!DebugSyms && (SymFlags & SymbolRef::SF_FormatSpecific)) continue; if (WithoutAliases) { if (IRObjectFile *IR = dyn_cast<IRObjectFile>(&Obj)) { const GlobalValue *GV = IR->getSymbolGV(Sym.getRawDataRefImpl()); if (GV && isa<GlobalAlias>(GV)) continue; } } // If a "-s segname sectname" option was specified and this is a Mach-O // file and this section appears in this file, Nsect will be non-zero then // see if this symbol is a symbol from that section and if not skip it. if (Nsect && Nsect != getNsectInMachO(*MachO, Sym)) continue; NMSymbol S; S.Size = 0; S.Address = 0; if (PrintSize) { if (isa<ELFObjectFileBase>(&Obj)) S.Size = ELFSymbolRef(Sym).getSize(); } if (PrintAddress && isa<ObjectFile>(Obj)) { SymbolRef SymRef(Sym); ErrorOr<uint64_t> AddressOrErr = SymRef.getAddress(); if (error(AddressOrErr.getError())) break; S.Address = *AddressOrErr; } S.TypeChar = getNMTypeChar(Obj, Sym); std::error_code EC = Sym.printName(OS); if (EC && MachO) OS << "bad string index"; else error(EC); OS << '\0'; S.Sym = Sym; SymbolList.push_back(S); } OS.flush(); const char *P = NameBuffer.c_str(); for (unsigned I = 0; I < SymbolList.size(); ++I) { SymbolList[I].Name = P; P += strlen(P) + 1; } CurrentFilename = Obj.getFileName(); sortAndPrintSymbolList(Obj, printName, ArchiveName, ArchitectureName); }