Problem with linking libraries

Hello,

I am new to llvm and compiler related stuff. I am trying to link an ir .ll file to a .bc and other libraries and it is not working. My application would compile using clang and run normally. I also have another project that I compile and link to the IR of any *.ll file generated for simple programs that work fine, but not to my application.

My application has multiple files and use different libraries and is built using cmake and make. The commands to link the object files to the libraries and generate the file executable is:
/usr/bin/clang+±4.0 -Wall -O3 -DNDEBUG -flto CMakeFiles/EncoderApp.dir/EncApp.cpp.o CMakeFiles/EncoderApp.dir/EncAppCfg.cpp.o CMakeFiles/EncoderApp.dir/encmain.cpp.o -o …/…/…/…/bin/umake/clang-4.0/x86_64/release/EncoderApp …/…/…/…/lib/umake/clang-4.0/x86_64/release/libCommonLib.a …/…/…/…/lib/umake/clang-4.0/x86_64/release/libEncoderLib.a …/…/…/…/lib/umake/clang-4.0/x86_64/release/libDecoderLib.a …/…/…/…/lib/umake/clang-4.0/x86_64/release/libUtilities.a …/…/…/…/lib/umake/clang-4.0/x86_64/release/libCommonLib.a

What I do to generate the .ll file for my project is I link the object files first into one then use llvm-dis. I can’t link the .a file in the same step, it does not work.

llvm-link-4.0 CMakeFiles/EncoderApp.dir/EncApp.cpp.o CMakeFiles/EncoderApp.dir/EncAppCfg.cpp.o CMakeFiles/EncoderApp.dir/encmain.cpp.o -o …/…/…/…/bin/umake/clang-4.0/x86_64/release/EncoderApp.o

then I generate the .ll file using llvm-dis
llvm-dis-4.0 EncoderApp.o -o EncoderApp.ll

When I generate the executable from the .o file using the first command and link the libraries it works. But when I try to link the .ll file to my other (instrumentation) project, the final executable does not work and I am not sure where to link the .a libraries. I try the following:

llvm-link-4.0 EncoderApp.ll count.bc -o linked_count.bc

//then I do a dynamic optimization pass
opt -load count_bb/build/countBB/libcountBB.so -countBB linked_count.bc -o linked_count_opt.bc

// then I compile
llc-4.0 -O3 linked_count_opt.bc

clang+±4.0 -O3 linked_count_opt.s -o ex.out …/…/…/…/lib/umake/clang-4.0/x86_64/release/libCommonLib.a …/…/…/…/lib/umake/clang-4.0/x86_64/release/libEncoderLib.a …/…/…/…/lib/umake/clang-4.0/x86_64/release/libDecoderLib.a …/…/…/…/lib/umake/clang-4.0/x86_64/release/libUtilities.a …/…/…/…/lib/umake/clang-4.0/x86_64/release/libCommonLib.a

This generates an executable that does not work correctly.
Also, is there a way to link the .a libraries before generating the .ll file?

It isn’t clear from your description what does it mean that “This generates an executable that does not work correctly”? What are the symptoms?

I haven’t debugged it but there is a segmentation fault.

There is a segmentation fault and I wonder if it has to do with the linked (*.a) libraries after linking the count.bc