[haskell-llvm] Make sure you include the correct TargetSelect.h and that InitializeAllTargetMCs() is being invoked!

Henning Thielemann lemming at henning-thielemann.de
Mon Apr 30 21:40:12 BST 2012


On Mon, 30 Apr 2012, Nathan Howell wrote:

> On Mon, Apr 30, 2012 at 12:07 PM, Henning Thielemann
> <lemming at henning-thielemann.de> wrote:
>> But it does not matter, I still get the following error, when running
>> Align_dyn.exe:
>>
>> Align_dyn.exe: LLVMTargetMachine.cpp:123:
>> llvm::LLVMTargetMachine::LLVMTargetMachine(const llvm::Target&,
>> llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::Reloc::Model,
>> llvm::CodeModel::Model): Assertion `AsmInfo && "MCAsmInfo not initialized."
>> "Make sure you include the correct TargetSelect.h" "and that
>> InitializeAllTargetMCs() is being invoked!"' failed.
>
> Set a breakpoint in gdb on LLVMInitializeNativeTarget and verify that
> it's stepping through the code in the #ifdef LLVM_NATIVE_TARGET block.
> If not, try rebuilding llvm with --enable-targets=host

It must have been a version shadowing problem. 'llvm' did not actually 
import the newly created 'llvm-base'.

I do now understand that your #def in LLVM/FFI/Target.hsc is not a CPP 
directive but a hsc2hs statement. However it seems that Cabal does not 
automatically compile the generated LLVM/FFI/Target_hsc.c file. When 
running Align_dyn.exe I got:

  undefined reference to `hs_LLVMInitializeNativeTarget'


I have added dist/build/LLVM/FFI/Target_hsc.c to the C-Sources field 
in llvm-base.cabal. Now ghc tries to compile it but fails with

In file included from /usr/local/llvm-3.0/include/llvm-c/Core.h:36,
                  from /usr/local/llvm-3.0/include/llvm-c/Target.h:22,
                  from Target.hsc:4,

                  from dist/build/LLVM/FFI/Target_hsc.c:1:0:

/usr/local/llvm-3.0/include/llvm/Support/DataTypes.h:53:3:
      error: #error "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"


Thus I moved in llvm-base.buildinfo.in the @llvm_cppflags@ from 
cpp-options field to a new cc-options field. Now I can compile llvm-base 
and I can successfully run the Align example.

llvm-3.0-git$ examples/Align_dyn.exe
(True,4,4,16,8,16,0x08059874)


However, adding the name of a temporary file (Target_hsc.c) with platform 
specific path (dist/build) to the Cabal description does not look right. 
Consequently, 'cabal sdist' warns about this problem.


Thank you for all your help, so far!



More information about the Haskell-llvm mailing list