X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FObject%2FSymbolSize.cpp;h=1d5cd78e6d9cb587dbcb16d71fa563cf712abb8c;hb=5666fc71f0e2ed2c0400d8bca079a1dd3f33fe53;hp=121bf1baa7a1eaf35d6740e4551d51fc70dbef0c;hpb=8bfd2e8447be4edd313a8fc86093751bb1002775;p=oota-llvm.git diff --git a/lib/Object/SymbolSize.cpp b/lib/Object/SymbolSize.cpp index 121bf1baa7a..1d5cd78e6d9 100644 --- a/lib/Object/SymbolSize.cpp +++ b/lib/Object/SymbolSize.cpp @@ -9,7 +9,9 @@ #include "llvm/Object/SymbolSize.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Object/COFF.h" #include "llvm/Object/ELFObjectFile.h" +#include "llvm/Object/MachO.h" using namespace llvm; using namespace object; @@ -19,32 +21,38 @@ struct SymEntry { symbol_iterator I; uint64_t Address; unsigned Number; - SectionRef Section; + unsigned SectionID; }; } static int compareAddress(const SymEntry *A, const SymEntry *B) { - if (A->Section == B->Section) - return A->Address - B->Address; - if (A->Section < B->Section) - return -1; - if (A->Section == B->Section) - return 0; - return 1; + if (A->SectionID != B->SectionID) + return A->SectionID - B->SectionID; + return A->Address - B->Address; } -static int compareNumber(const SymEntry *A, const SymEntry *B) { - return A->Number - B->Number; +static unsigned getSectionID(const ObjectFile &O, SectionRef Sec) { + if (auto *M = dyn_cast(&O)) + return M->getSectionID(Sec); + return cast(O).getSectionID(Sec); } -ErrorOr>> +static unsigned getSymbolSectionID(const ObjectFile &O, SymbolRef Sym) { + if (auto *M = dyn_cast(&O)) + return M->getSymbolSectionID(Sym); + return cast(O).getSymbolSectionID(Sym); +} + +std::vector> llvm::object::computeSymbolSizes(const ObjectFile &O) { std::vector> Ret; - if (isa(&O)) { - for (SymbolRef Sym : O.symbols()) { + if (const auto *E = dyn_cast(&O)) { + auto Syms = E->symbols(); + if (Syms.begin() == Syms.end()) + Syms = E->getDynamicSymbolIterators(); + for (ELFSymbolRef Sym : Syms) Ret.push_back({Sym, Sym.getSize()}); - } return Ret; } @@ -54,19 +62,15 @@ llvm::object::computeSymbolSizes(const ObjectFile &O) { unsigned SymNum = 0; for (symbol_iterator I = O.symbol_begin(), E = O.symbol_end(); I != E; ++I) { SymbolRef Sym = *I; - uint64_t Address; - if (std::error_code EC = Sym.getAddress(Address)) - return EC; - section_iterator SecI = O.section_end(); - if (std::error_code EC = Sym.getSection(SecI)) - return EC; - Addresses.push_back({I, Address, SymNum, *SecI}); + uint64_t Value = Sym.getValue(); + Addresses.push_back({I, Value, SymNum, getSymbolSectionID(O, Sym)}); ++SymNum; } - for (const SectionRef Sec : O.sections()) { + for (SectionRef Sec : O.sections()) { uint64_t Address = Sec.getAddress(); uint64_t Size = Sec.getSize(); - Addresses.push_back({O.symbol_end(), Address + Size, 0, Sec}); + Addresses.push_back( + {O.symbol_end(), Address + Size, 0, getSectionID(O, Sec)}); } array_pod_sort(Addresses.begin(), Addresses.end(), compareAddress); @@ -85,12 +89,12 @@ llvm::object::computeSymbolSizes(const ObjectFile &O) { P.Address = Size; } - // Put back in the original order and copy the result - array_pod_sort(Addresses.begin(), Addresses.end(), compareNumber); + // Assign the sorted symbols in the original order. + Ret.resize(SymNum); for (SymEntry &P : Addresses) { if (P.I == O.symbol_end()) continue; - Ret.push_back({*P.I, P.Address}); + Ret[P.Number] = {*P.I, P.Address}; } return Ret; }