summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-06-23 02:08:48 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-06-23 02:08:48 +0000
commitb109c032bd44068e1fd8275117513bba172a9886 (patch)
tree3c7bc93c06c4956b493db8f2b9ed1fc28b7abd12 /llvm/tools
parent0b554ed364981a0b5172a0202ee183ef6fc5ae85 (diff)
downloadbcm5719-llvm-b109c032bd44068e1fd8275117513bba172a9886.tar.gz
bcm5719-llvm-b109c032bd44068e1fd8275117513bba172a9886.zip
Extract an utility for computing symbol sizes on MachO and COFF.
I will add a second user in the next commit. llvm-svn: 240366
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp52
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.
OpenPOWER on IntegriCloud