libLTO: Add a utility method to initialize the disassemblers.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 24 Nov 2012 16:59:10 +0000 (16:59 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 24 Nov 2012 16:59:10 +0000 (16:59 +0000)
Necessary to give disassembler users (like darwin's otool) a possibility to
dlopen libLTO and still initialize the required LLVM bits. This used to go
through libMCDisassembler but that's a gross layering violation, the MC layer
can't pull in functions from the targets. Adding a function to libLTO is a bit
of a hack but not worse than exposing other disassembler bits from libLTO.

Fixes PR14362.

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

include/llvm-c/lto.h
lib/MC/MCDisassembler/Disassembler.cpp
tools/lto/CMakeLists.txt
tools/lto/LTODisassembler.cpp [new file with mode: 0644]
tools/lto/lto.exports

index f43d365e3dbefb123bccd470f3d97b335daf8209..74915c0006f74a0c1eec035d248c18b47f18b49b 100644 (file)
@@ -291,6 +291,13 @@ lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
 extern void
 lto_codegen_debug_options(lto_code_gen_t cg, const char *);
 
+/**
+ * Initializes LLVM disassemblers.
+ * FIXME: This doesn't really belong here.
+ */
+extern void
+lto_initialize_disassembler(void);
+
 #ifdef __cplusplus
 }
 #endif
index 5189c9daeed6ed8f1b5318d1b0e5b53e7e97a1e3..490ca75bc8cd36edf154965bafdf31d975bc8f71 100644 (file)
@@ -20,7 +20,6 @@
 #include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/Support/MemoryObject.h"
 #include "llvm/Support/TargetRegistry.h"
-#include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace llvm {
@@ -38,18 +37,6 @@ using namespace llvm;
 LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
                                       int TagType, LLVMOpInfoCallback GetOpInfo,
                                       LLVMSymbolLookupCallback SymbolLookUp) {
-  // Initialize targets and assembly printers/parsers.
-  // FIXME: Clients are responsible for initializing the targets. And this
-  // would be done by calling routines in "llvm-c/Target.h" which are static
-  // line functions. But the current use of LLVMCreateDisasm() is to dynamically
-  // load libLTO with dlopen() and then lookup the symbols using dlsym().
-  // And since these initialize routines are static that does not work which
-  // is why the call to them in this 'C' library API was added back.
-  llvm::InitializeAllTargetInfos();
-  llvm::InitializeAllTargetMCs();
-  llvm::InitializeAllAsmParsers();
-  llvm::InitializeAllDisassemblers();
-
   // Get the target.
   std::string Error;
   const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
index 911297609b0c26e3834c0704b7e0e73994a8409c..a004bad189a929bd73f8925eb9cb0d2a546bf61d 100644 (file)
@@ -6,6 +6,7 @@ add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" )
 
 set(SOURCES
   LTOCodeGenerator.cpp
+  LTODisassembler.cpp
   lto.cpp
   LTOModule.cpp
   )
diff --git a/tools/lto/LTODisassembler.cpp b/tools/lto/LTODisassembler.cpp
new file mode 100644 (file)
index 0000000..186aceb
--- /dev/null
@@ -0,0 +1,26 @@
+//===-- LTODisassembler.cpp - LTO Disassembler interface ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This function provides utility methods used by clients of libLTO that want
+// to use the disassembler.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm-c/lto.h"
+#include "llvm/Support/TargetSelect.h"
+
+using namespace llvm;
+
+void lto_initialize_disassembler() {
+  // Initialize targets and assembly printers/parsers.
+  llvm::InitializeAllTargetInfos();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmParsers();
+  llvm::InitializeAllDisassemblers();
+}
index 4940bb147efa34c5a94af164e669a9cd2afa0a1e..d783d1cb187467967fab0bfd83d85ec744c01441 100644 (file)
@@ -1,5 +1,6 @@
 lto_get_error_message
 lto_get_version
+lto_initialize_disassembler
 lto_module_create
 lto_module_create_from_fd
 lto_module_create_from_fd_at_offset