Questions about the methods of compilation.

Hi, I have some questions about the compilation of the llvm.
First, why the majority of the results of compilation are static library ( *.a files in the $(LLVM_HOME)/Release+Asserts/lib/), Why don’t generate dynamic link library (.so files in the directory). The exception is the file libLTO.a and libLTO.so, why the library LTO were generated for static and dynamic both? How to control the generation of the library file, could it be controlled in the file Makefile.config? One item of the Makefile.config is as follow.

Do we want to build a shared library and link the tools with it?

ENABLE_SHARED := 0

Second, I followed the pass specification of the llvm (http://llvm.org/docs/WritingAnLLVMPass.html) and wrote my own pass to do something. However, why did it generate the dynamic library (*.so) just like the example of the specification of LLVMHello.so rather than a static library because it used the same Makefile.config file with the build of the LLVM?

Third, How can I get my own pass build together with the LLVM, generate *.a file in the directory of $(LLVM_HOME)/Release+Asserts/lib/?

Thank you, very appreciate.

Best

Hi, I have some questions about the compilation of the llvm.
First, why the majority of the results of compilation are static library ( *.a files in the $(LLVM_HOME)/Release+Asserts/lib/), Why don’t generate dynamic link library (.so files in the directory).

We can turn the question around: why would we? :wink:
Dynamic library are making the compiler really slower, that’s the main reason I believe.

The exception is the file libLTO.a and libLTO.so, why the library LTO were generated for static and dynamic both?

Are you sure it is libLTO.a and not libLLVMLTO.a?
These are different: libLLVMLTO.a contains only the LTO API, while libLTO.so contains all of LLVM and the LTO API in order for linkers to dynamically load LLVM to perform LTO.

How to control the generation of the library file, could it be controlled in the file Makefile.config? One item of the Makefile.config is as follow.

Do we want to build a shared library and link the tools with it?

ENABLE_SHARED := 0

I believe you want the CMake option -DBUILD_SHARED_LIBS=ON

See the doc for the various configuration around shared libraries: http://www.llvm.org/docs/CMake.html

Second, I followed the pass specification of the llvm (http://llvm.org/docs/WritingAnLLVMPass.html) and wrote my own pass to do something. However, why did it generate the dynamic library (*.so) just like the example of the specification of LLVMHello.so rather than a static library because it used the same Makefile.config file with the build of the LLVM?

I assume you mean CMakeList.txt instead of Makefile.config?

The important part is that to have your pass dynamically loadable, it is configured with add_llvm_loadable_module in your cmake file, while LLVM libraries are added with add_llvm_library.

Third, How can I get my own pass build together with the LLVM, generate *.a file in the directory of $(LLVM_HOME)/Release+Asserts/lib/?

I suggest that you start with this tutorial from last year Dev Meeting: http://llvm.org/devmtg/2015-10/#tutorial1 (slides and video are online).

Last time I built LLVM/clang on FreeBSD/PPC64, the code size was too large for it to link. I had to switch to using shared libraries to make it work.
I'm guessing that this is not a common issue, but maybe the day is coming... :slight_smile:

-Krzysztof