diff options
Diffstat (limited to 'llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp')
| -rw-r--r-- | llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp | 52 |
1 files changed, 8 insertions, 44 deletions
diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp index f857b2ef973..5bc18d3bfbe 100644 --- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -25,6 +25,7 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Object/MachO.h" +#include "llvm/Object/SymbolSize.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/ManagedStatic.h" @@ -252,38 +253,14 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) { std::unique_ptr<DIContext> Context( new DWARFContextInMemory(*SymbolObj,LoadedObjInfo.get())); - // FIXME: This is generally useful. Figure out a place in lib/Object to - // put utility functions. - std::map<object::SectionRef, std::vector<uint64_t>> FuncAddresses; - if (!isa<ELFObjectFileBase>(SymbolObj)) { - for (object::SymbolRef Sym : SymbolObj->symbols()) { - object::SymbolRef::Type SymType; - if (Sym.getType(SymType)) - continue; - if (SymType != object::SymbolRef::ST_Function) - continue; - uint64_t Addr; - if (Sym.getAddress(Addr)) - continue; - object::section_iterator Sec = SymbolObj->section_end(); - if (Sym.getSection(Sec)) - continue; - std::vector<uint64_t> &Addrs = FuncAddresses[*Sec]; - if (Addrs.empty()) { - uint64_t SecAddr = Sec->getAddress(); - uint64_t SecSize = Sec->getSize(); - Addrs.push_back(SecAddr + SecSize); - } - Addrs.push_back(Addr); - } - for (auto &Pair : FuncAddresses) { - std::vector<uint64_t> &Addrs = Pair.second; - array_pod_sort(Addrs.begin(), Addrs.end()); - } - } + ErrorOr<std::vector<std::pair<SymbolRef, uint64_t>>> SymAddrOrErr = + object::computeSymbolSizes(*SymbolObj); + if (std::error_code EC = SymAddrOrErr.getError()) + return Error(EC.message()); // Use symbol info to iterate functions in the object. - for (object::SymbolRef Sym : SymbolObj->symbols()) { + for (const auto &P : *SymAddrOrErr) { + object::SymbolRef Sym = P.first; object::SymbolRef::Type SymType; if (Sym.getType(SymType)) continue; @@ -295,20 +272,7 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) { if (Sym.getAddress(Addr)) continue; - uint64_t Size; - if (isa<ELFObjectFileBase>(SymbolObj)) { - Size = Sym.getSize(); - } else { - object::section_iterator Sec = SymbolObj->section_end(); - if (Sym.getSection(Sec)) - continue; - const std::vector<uint64_t> &Addrs = FuncAddresses[*Sec]; - auto AddrI = std::find(Addrs.begin(), Addrs.end(), Addr); - assert(AddrI != Addrs.end() && (AddrI + 1) != Addrs.end()); - assert(*AddrI == Addr); - Size = *(AddrI + 1) - Addr; - } - + uint64_t Size = P.second; // If we're not using the debug object, compute the address of the // symbol in memory (rather than that in the unrelocated object file) // and use that to query the DWARFContext. |

