extern "C" const char* LLVMRustArchiveReadSection(Archive *ar, char *name, size_t *size) { for (Archive::child_iterator child = ar->child_begin(), end = ar->child_end(); child != end; ++child) { StringRef sect_name; error_code err = child->getName(sect_name); if (err) continue; if (sect_name.trim(" ") == name) { StringRef buf = child->getBuffer(); *size = buf.size(); return buf.data(); } } return NULL; }
static void dumpSymbolNamesFromFile(std::string &Filename) { std::unique_ptr<MemoryBuffer> Buffer; if (error(MemoryBuffer::getFileOrSTDIN(Filename, Buffer), Filename)) return; LLVMContext &Context = getGlobalContext(); ErrorOr<Binary *> BinaryOrErr = createBinary(Buffer.release(), &Context); if (error(BinaryOrErr.getError(), Filename)) return; std::unique_ptr<Binary> Bin(BinaryOrErr.get()); if (Archive *A = dyn_cast<Archive>(Bin.get())) { if (ArchiveMap) { Archive::symbol_iterator I = A->symbol_begin(); Archive::symbol_iterator E = A->symbol_end(); if (I != E) { outs() << "Archive map\n"; for (; I != E; ++I) { Archive::child_iterator C; StringRef SymName; StringRef FileName; if (error(I->getMember(C))) return; if (error(I->getName(SymName))) return; if (error(C->getName(FileName))) return; outs() << SymName << " in " << FileName << "\n"; } outs() << "\n"; } } for (Archive::child_iterator I = A->child_begin(), E = A->child_end(); I != E; ++I) { std::unique_ptr<Binary> Child; if (I->getAsBinary(Child, &Context)) continue; if (SymbolicFile *O = dyn_cast<SymbolicFile>(Child.get())) { outs() << O->getFileName() << ":\n"; dumpSymbolNamesFromObject(O); } } return; } if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(Bin.get())) { for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), E = UB->end_objects(); I != E; ++I) { std::unique_ptr<ObjectFile> Obj; if (!I->getAsObjectFile(Obj)) { outs() << Obj->getFileName() << ":\n"; dumpSymbolNamesFromObject(Obj.get()); } } return; } if (SymbolicFile *O = dyn_cast<SymbolicFile>(Bin.get())) { dumpSymbolNamesFromObject(O); return; } error("unrecognizable file type", Filename); return; }