tools: avoid use of std::function
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 25 May 2014 21:37:59 +0000 (21:37 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 25 May 2014 21:37:59 +0000 (21:37 +0000)
Remove the use of the std::function and replace the capturing lambda with a
non-capturing one, opting to pass the user data down to the context.  This is
needed as std::function is not yet available on all hosted platforms (it
requires RTTI, which breaks on Windows).

Thanks to Nico Rieck for pointing this out!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209607 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-readobj/COFFDumper.cpp
tools/llvm-readobj/Win64EHDumper.cpp
tools/llvm-readobj/Win64EHDumper.h

index 7b9595f84c5bd207effcad0bd8646eeb3c2b3cca..91f2a57dccfcbaba72844fbd871b5506afa0fd6c 100644 (file)
@@ -849,11 +849,12 @@ void COFFDumper::printUnwindInfo() {
   case COFF::IMAGE_FILE_MACHINE_AMD64: {
     Win64EH::Dumper Dumper(W);
     Win64EH::Dumper::SymbolResolver Resolver =
-      [this](const object::coff_section *Section, uint64_t Offset,
-             SymbolRef &Symbol) -> error_code {
-        return this->resolveSymbol(Section, Offset, Symbol);
+      [](const object::coff_section *Section, uint64_t Offset,
+         SymbolRef &Symbol, void *user_data) -> error_code {
+        COFFDumper *Dumper = reinterpret_cast<COFFDumper*>(user_data);
+        return Dumper->resolveSymbol(Section, Offset, Symbol);
       };
-    Win64EH::Dumper::Context Ctx(*Obj, Resolver);
+    Win64EH::Dumper::Context Ctx(*Obj, Resolver, this);
     Dumper.printData(Ctx);
     break;
   }
index 449df001cc97b5eae058d2d4383feab770d10992..c64d362469bf8728aec33b020e716dc5642d0bdd 100644 (file)
@@ -120,7 +120,8 @@ static std::string formatSymbol(const Dumper::Context &Ctx,
 
   StringRef Name;
   SymbolRef Symbol;
-  if (Ctx.ResolveSymbol(Section, Offset, Symbol) || Symbol.getName(Name)) {
+  if (Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData) ||
+      Symbol.getName(Name)) {
     OS << format(" (0x%" PRIX64 ")", Offset);
     return OS.str();
   }
@@ -139,7 +140,7 @@ static error_code resolveRelocation(const Dumper::Context &Ctx,
                                     const coff_section *&ResolvedSection,
                                     uint64_t &ResolvedAddress) {
   SymbolRef Symbol;
-  if (error_code EC = Ctx.ResolveSymbol(Section, Offset, Symbol))
+  if (error_code EC = Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData))
     return EC;
 
   if (error_code EC = Symbol.getAddress(ResolvedAddress))
index d0c129c68b80a71d358e0975e4a0bf3dcfcdaae0..2eac81048b4f950c1c834d1703b6df1075b32002 100644 (file)
@@ -13,8 +13,6 @@
 #include "StreamWriter.h"
 #include "llvm/Support/Win64EH.h"
 
-#include <functional>
-
 namespace llvm {
 namespace object {
 class COFFObjectFile;
@@ -28,15 +26,17 @@ class Dumper {
   raw_ostream &OS;
 
 public:
-  typedef std::function<error_code(const object::coff_section *, uint64_t,
-                                   object::SymbolRef &)> SymbolResolver;
+  typedef error_code (*SymbolResolver)(const object::coff_section *, uint64_t,
+                                       object::SymbolRef &, void *);
 
   struct Context {
     const object::COFFObjectFile &COFF;
     SymbolResolver ResolveSymbol;
+    void *UserData;
 
-    Context(const object::COFFObjectFile &COFF, SymbolResolver Resolver)
-      : COFF(COFF), ResolveSymbol(Resolver) {}
+    Context(const object::COFFObjectFile &COFF, SymbolResolver Resolver,
+            void *UserData)
+      : COFF(COFF), ResolveSymbol(Resolver), UserData(UserData) {}
   };
 
 private: