linking a parser bitcode

Hello again,

My partner and I am modifying a PEG parser generator to produce LLVM bitcode from a version of a parsing expression grammar that takes LLVM Assembly as code. It accepts external libraries in its current state so we are writing an external library in C++ using C bindings for the linkage. Trying to get it to link is proving to be more challenging than expected. My partner is trying to link on a Win32 system so the Gold plugin is not an option. He also doesn't have Perl installed so using llvm-config is also not an option.

Here is the command line of trying to compile the resultant amos.bc file from our parser generator with the main program that hosts it:

llvm-link -o out.bc main.bc amos.bc
llc -f out.bc
..\..\..\..\llvm-gcc\bin\llvm-g++ out.s -L..\..\..\..\llvm\lib -L..\..\..\..\llvm-gcc\lib -lgcc -lLLVMLinker -lLLVMipo -lLLVMInstrumentation -lLLVMDebugger -lLLVMBitWriter -lLLVMAsmParser -lLLVMArchive -lLLVMBitReader -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMCore -lLLVMSupport -lLLVMSystem -lsupc++

It is complaining about not being able to find __gxx_personality_sj0 and the LLVM command line parser-related files. What else do we need to link?

--Sam

Hello

It is complaining about not being able to find __gxx_personality_sj0 and the LLVM command line parser-related files. What else do we need to link?

This is personality function for sjlj eh. How the source bitcode files
in questions were generated?

Hello Anton,

Our main.bc was generated with the following command line:

llvm-g++ -Illvm\include -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -c -emit-llvm -omain.bc main.cpp

The amos.bc file was generated by our experimental llvm-peg parser generator whose internal workings are assembled internally using LLVM Assembly. The parser generator links a C++ library bitcode with C bindings called libBasicFrontends.bc internally. The command line for the libBasicFrontends.bc is similar to the llvm-g++ command line given above. Is there anything we should be doing differently for the libBasicFrontends.bc file?

Also, as a quick update, the command line parser is now linking properly so only the SJ/LJ stuff is not linking correctly.

Kind regards,

--Sam Crow

Hello, Samuel

llvm-g++ -Illvm\include -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -c -emit-llvm -omain.bc main.cpp

Ok. How was llvm-g++ built? Have you used release tarball, or built
everything by hands?

Hello Anton,

We used the release tarball. Oh! I forgot to mention it's the version 2.5 stable release that we've been developing with.

Thanks,

--Sam

Hello, Samuel

We used the release tarball. Oh! I forgot to mention it's the version 2.5 stable release that we've been developing with.

Hrm, something is broken there.... Try to compile your code with
-fno-exceptions then

Hello Anton,

While we have been discussing this, my partner discovered the source of where the sj/lj stuff is coming from. Does this mean that the LLVM libraries we're using are broken?

Type.cpp
..\..\..\..\llvm\lib/libLLVMCore.a(Type.cpp.obj):Type.cpp.text+0x722): undefined reference to `__gxx_personality_sj0'
..\..\..\..\llvm\lib/libLLVMCore.a(Type.cpp.obj):Type.cpp.text+0x750): undefined reference to `_Unwind_SjLj_Register'
..\..\..\..\llvm\lib/libLLVMCore.a(Type.cpp.obj):Type.cpp.text+0x848): undefined reference to `_Unwind_SjLj_Resume'
..\..\..\..\llvm\lib/libLLVMCore.a(Type.cpp.obj):Type.cpp.text+0xa31): undefined reference to `_Unwind_SjLj_Resume'

Thanks,

--Samuel Crow

Hello, Samuel

While we have been discussing this, my partner discovered the source of where the sj/lj stuff is coming from. Does this mean that the LLVM libraries we're using are broken?

Type.cpp
..\..\..\..\llvm\lib/libLLVMCore.a(Type.cpp.obj):Type.cpp.text+0x722): undefined reference to `__gxx_personality_sj0'
..\..\..\..\llvm\lib/libLLVMCore.a(Type.cpp.obj):Type.cpp.text+0x750): undefined reference to `_Unwind_SjLj_Register'
..\..\..\..\llvm\lib/libLLVMCore.a(Type.cpp.obj):Type.cpp.text+0x848): undefined reference to `_Unwind_SjLj_Resume'
..\..\..\..\llvm\lib/libLLVMCore.a(Type.cpp.obj):Type.cpp.text+0xa31): undefined reference to `_Unwind_SjLj_Resume'

Ah, I've re-read the whole thread and now understand the whole situation:

1. You compiled llvm (on windows, as it seems to me) with the compiler
which does sjlj-style EH (e.g. mingw's gcc 3.4.5)
2. LLVM supports only dwarf-based EH (however, EH on windows is
currently unsupported), thus llvm-compiled libgcc does not contain any
sjlj-related routines

So, the best way to resolve the situation is:
- Do not use EH in the code you're compiling via llvm-gcc (it won't
work until someone will feel brave to implement missed EH bits on
windows)
- link everything with g++, not llvm-g++

Hope this will help.

Thanks Anton,

We'll try it on Monday when he gets back to work.

--Samuel

From: Anton Korobeynikov <anton@korobeynikov.info>
To: Samuel Crow <samuraileumas@yahoo.com>
Cc: LLVM Developers Mailing List <llvmdev@cs.uiuc.edu>
Sent: Fri, December 4, 2009 4:19:31 PM
Subject: Re: [LLVMdev] linking a parser bitcode

-snip-