std::vector<symbol> read(const COFFObjectFile& obj) { std::vector<symbol> symbols; const pe32_header *pe32; if (error_code err = obj.getPE32Header(pe32)) llvm_binary_fail(err); for (auto it = obj.begin_symbols(); it != obj.end_symbols(); ++it) { auto sym = obj.getCOFFSymbol(it); if (!sym) llvm_binary_fail("not a coff symbol"); const coff_section *sec = nullptr; if (sym->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) continue; if (error_code ec = obj.getSection(sym->SectionNumber, sec)) llvm_binary_fail(ec); if (!sec) continue; uint64_t size = (sec->VirtualAddress + sec->SizeOfRawData) - sym->Value; for (auto it = obj.begin_symbols(); it != obj.end_symbols(); ++it) { auto next = obj.getCOFFSymbol(it); if (next->SectionNumber == sym->SectionNumber) { auto new_size = next->Value > sym->Value ? next->Value - sym->Value : size; size = new_size < size ? new_size : size; } } auto addr = sec->VirtualAddress + pe32->ImageBase + sym->Value; symbols.push_back(symbol(*it,addr,size)); } return symbols; }