The first argument is LLVMCreateDisasm ,
"testname"
Invalid TripleName . TripleName will instruct LLVM on what your goal is, and this is necessary because LLVM contains support for multiple goals in one installation.
You can specify supported target architectures by running the command
llc -version
And there are goals for x86 and x86_64
x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64
To build the correct TripleName name, you need to find some good subarch (i486 or x86_64) for your purpose, then add the provider and OS:
http://llvm.org/docs/doxygen/html/Triple_8h_source.html
00022 /// Triple - Helper class for working with autoconf configuration names. For 00023 /// historical reasons, we also call these 'triples' (they used to contain 00024 /// exactly three fields). 00025 /// 00026 /// Configuration names are strings in the canonical form: 00027 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM 00028 /// or 00029 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
ArchType enumerations are listed here, with a list of recognized Arch in the comment (actual parser lib / Support / Triple.cpp - parseArch ), for example
arm, // ARM: arm, armv.*, xscale aarch64, // AArch64: aarch64 .... x86, // X86: i[3-9]86 x86_64, // X86-64: amd64, x86_64
The same file has valid providers ( enum VendorType ), OS types ( enum OSType ) and Envronments ( enum EnvironmentType ). In most cases, you can use "unknown" for providers and os, but "-unknown-linux-gnu" is often used.
Some examples of valid TripleName s:
x86_64
The following is a description of the actual clang triples: http://clang.llvm.org/docs/CrossCompilation.html and some valid names listed in https://stackoverflow.com/a/3/3/2 ...
Another limitation in LLVMCreateDisasm is that not all targets have an implemented MCDisassembler . For example, in LLVM-2.9 there are MCDissasemblers files only for X86, X86_64, ARM, and MBlaze; in later (svn from 2014-02-01) also for Sparc, PPC, MIPS, SystemZ, XCore and AArch64.
If you could not create MCDisassembler even with the correct triple, there are several options for debugging the LLVMCreateDisasmCPU function from the MC / MCDisassembler / Disassembler.cpp file. You can break into gdb and then do the βnextβ -stepping before the error (this will be more beautiful and easier with the debug build of LLVM); or you can add printf debugging to the LLVMCreateDisasmCPU value or a temporary change returned from simple NULL information that is different from every error.
UPDATE: It seems that your LLVM was not initialized during the conversation. LLVM (~ 3.4 or later) has many LLVM initializers in the llvm-c / Target.h header :
LLVMInitializeAllTargetInfos() - The main program must call this function if it wants to access all available objects for which LLVM is configured to support.
LLVMInitializeAllTargets() - The main program should call this function if it wants to link all the available goals for which LLVM is configured to support.
LLVMInitializeAllTargetMCs() - The main program should call this function if it wants to access all available target MCs that LLVM is configured to support.
LLVMInitializeAllDisassemblers() - The main program should call this function if it wants all disassemblers to be configured to support LLVM, to make them accessible through TargetRegistry.
LLVMInitializeAllAsmPrinters() - The main program should call this function if it wants all asm printers that LLVM is configured to support to make them accessible through TargetRegistry.
etc. ( https://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Target.h?logsort=rev&diff_format=h&r1=192697&r2=192696&pathrev=192697 ).
There is even a LLVMInitializeNativeTarget function that initializes its own object:
LLVMInitializeNativeTarget() - The main program should call this function to initialize its own target corresponding to the host. This is useful for JIT applications to ensure proper target binding.