0

I am working in a project that consist of some C++ teams. Each team delivers libraries and our team is integrating these libraries into a front end application.

The application is cross platform, so it means that other the teams have to provide the same (static) libraries compiled for different platforms/CPU architecture/configuration. Eg. we have Visual Studio 2015/2013, 32bit/64bit, linux, Debug/Release etc.

It would be nice to reduce the number of these static library "manifests", so I was looking into the Clang/LLVM. The idea would be compile the static libraries into LLVM bitcode and use the llvm-ar tool to create an llvm static library. When we have to make the binaries for a specific platform we would use the llc (LLVM platform compiler) to create the native code static library and do the linking with the platform linker.

Questions:

  • is there a better way to do what I want to achieve?
  • the llc does not seem to support the compiling of a static library, only individual translation units (.bc -> .o). Of course I can extract each individual bitcode file, assemble it to native object file and use the platform librarian tool (lib/ar) to make the static library, but I wonder if there is a more streamlined solution.
  • the gold linker seems to make something I need, but seems to be restricted to ELF format. I have to support Windows/Linux and maybe IOS
user2281723
  • 519
  • 1
  • 5
  • 16
  • As far as I know LLVM bitcode is still machine-dependent. Best way to compile the library and link would be to just use ld/lld with --enable-llvm and -flte flags - it will then pick out objects in llvm bitcode format, perform Whole Program Optimization on it and link to final binary. – berkus Dec 18 '16 at 16:15
  • Can you explain why the bitcode is still machine dependent? I guess only syscalls shall make a difference, but I am going to use the C runtime. I found the lld project on the llvm webpage, it looks good! Unfortunately I did not fund on the page the command line options, can you explain what the f,l,t,e flags do? In the normal gnu ld command line I did not find these switches – user2281723 Dec 18 '16 at 18:11
  • See Anton's answer below for details. – berkus Dec 19 '16 at 11:00
  • -f`lto` is the flag to enable link-time optimizations (whole program opt) - sorry was a typo – berkus Dec 19 '16 at 11:01

1 Answers1

1

LLVM IR generated from target-specific and platform-specific language (C/C++) won't be target neutral. Think about type sizes, alignments, ABI requirements, etc. Not the mention pure source code features like preprocessor. So, no, the approach you thought about won't work at all.

See LLVM bitcode cross-platform for some more information.

Community
  • 1
  • 1
Anton Korobeynikov
  • 9,074
  • 25
  • 28
  • Thanks for the link! What if I avoid all specialities in my algorithms. What we have are mostly number crunching algorithms, so special things like platform dependent preprocessor macroes, special call conventions (stdcall, etc) - except cdecl are not expected. Do you think if we restrict ourselves by these rules, then it is still impossible/useless to do it? – user2281723 Dec 19 '16 at 07:43
  • Sure. If you're using e.g. std::vector - think about sizeof(size_t) or sizeof(void*). – Anton Korobeynikov Dec 19 '16 at 10:15