Skip to content

Linking with all LLVM libraries #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2019
Merged

Conversation

AlexeySotkin
Copy link
Contributor

Also adding " -Wl,--no-undefined" to the link flags.

@AlexeySotkin
Copy link
Contributor Author

There is a corresponding PR for ocl-open-80 branch - #54

@dvrogozh
Copy link
Contributor

I am checking now #54 (for 80 branch) against static LLVM libraries. @tripzero : would you be able to check the patch against dynamic LLVM? If not, it will take 1 day on my side since I don't have dynamic LLVM at hand and building it takes a while.

@dvrogozh
Copy link
Contributor

#54 works for me when I link against statically linked LLVM. I will try to check now dynamic linkage against LLVM. This will take a while, I need to rebuild it...

set(ADDITIONAL_LIBS )

if(USE_PREBUILT_LLVM AND NOT LLVMSPIRV_INCLUDED_IN_LLVM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause linker error for LLVMSPIRVLib for systems that have LLVMSPIRV built into libLLVM.so

@tripzero
Copy link
Contributor

I'm in the process of testing by compiling intel-compute-runtime for dynamic llvm libs case.

@dvrogozh
Copy link
Contributor

dvrogozh commented Mar 20, 2019

Building common_clang against dynamic LLVM (built with -DLLVM_BUILD_LLVM_DYLIB=ON) works fine as well for me. So, regarding this PR I have nothing against, but you may wish to address comment from @tripzero to allow builds against LLVM which include SPIRV translator. However, I am not quite sure that this would be a common practice among distributions since/till SPIRV translator won't show up as a standard tool included into default LLVM distributions, for example, appearing here: https://github.com/llvm/llvm-project. For that matter, Debian approach to package SPIRV translator separately https://salsa.debian.org/opencl-team/spirv-llvm-translator seems to be more native for me.

A bit of bad news however. So, common clang build is ok. IGC is also ok. Problem happens with NEO opencl driver. Configuring LLVM in this way:
cmake -DCMAKE_INSTALL_PREFIX=/home/dvrogozh/git/github/install.llvm8 -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_ENABLE_PROJECTS=clang ../llvm-project/llvm

I see this:

ocloc: /home/dvrogozh/git/github/llvm-project/llvm/include/llvm/Support/CommandLine.h:804: void llvm::cl::parser<DataType>::addLiteralOption(llvm::StringRef, const DT&, llvm::StringRef) [with DT = llvm::ScheduleDAGInstrs* (*)(llvm::MachineSchedContext*); DataType = llvm::ScheduleDAGInstrs* (*)(llvm::MachineSchedContext*)]: Assertion `findOption(Name) == Values.size() && "Option already exists!"' failed.

It is coming from here:
https://github.com/llvm/llvm-project/blob/d2298e74235598f15594fe2c99bbac870a507c59/llvm/include/llvm/Support/CommandLine.h#L804

I should note that I surprisingly don't see this issue when I build against static LLVM, i.e. with -DLLVM_BUILD_LLVM_DYLIB=OFF.

And the stack leading to that looks to be:

#0  0x00007ffff6e05277 in raise () from /lib64/libc.so.6
#1  0x00007ffff6e06968 in abort () from /lib64/libc.so.6
#2  0x00007ffff6dfe096 in __assert_fail_base () from /lib64/libc.so.6
#3  0x00007ffff6dfe142 in __assert_fail () from /lib64/libc.so.6
#4  0x00007fffef53f7a5 in llvm::cl::parser<llvm::ScheduleDAGInstrs* (*)(llvm::MachineSchedContext*)>::addLiteralOption<llvm::ScheduleDAGInstrs* (*)(llvm::MachineSchedContext*)> (
    this=0x7ffff68def08 <MachineSchedOpt+200>, Name=..., V=@0x7fffffffd2f0: 0x7fffe45c1ba4 <createR600MachineScheduler(llvm::MachineSchedContext*)>, HelpStr=...)
    at /home/dvrogozh/git/github/tmp/llvm-project/llvm/include/llvm/Support/CommandLine.h:804
#5  0x00007fffef542e02 in llvm::RegisterPassParser<llvm::MachineSchedRegistry>::NotifyAdd (this=0x7ffff68def00 <MachineSchedOpt+192>, N=...,
    C=0x7fffe45c1ba4 <createR600MachineScheduler(llvm::MachineSchedContext*)>, D=...) at /home/dvrogozh/git/github/tmp/llvm-project/llvm/include/llvm/CodeGen/MachinePassRegistry.h:163
#6  0x00007fffe45c7254 in llvm::MachinePassRegistry<llvm::ScheduleDAGInstrs* (*)(llvm::MachineSchedContext*)>::Add (this=0x7ffff68de5a0 <llvm::MachineSchedRegistry::Registry>,
    Node=0x7fffea31b7a0 <R600SchedRegistry>) at /home/dvrogozh/git/github/tmp/llvm-project/llvm/include/llvm/CodeGen/MachinePassRegistry.h:111
#7  0x00007fffe45c61a8 in llvm::MachineSchedRegistry::MachineSchedRegistry (this=0x7fffea31b7a0 <R600SchedRegistry>, N=0x7fffe76146b2 "r600", D=0x7fffe7615318 "Run R600's custom scheduler",
    C=0x7fffe45c1ba4 <createR600MachineScheduler(llvm::MachineSchedContext*)>) at /home/dvrogozh/git/github/tmp/llvm-project/llvm/include/llvm/CodeGen/MachineScheduler.h:148
#8  0x00007fffe45c5bd7 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535)
    at /home/dvrogozh/git/github/tmp/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp:264
#9  0x00007fffe45c5d2e in _GLOBAL__sub_I_AMDGPUTargetMachine.cpp(void) () at /home/dvrogozh/git/github/tmp/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp:928
#10 0x00007ffff7deab03 in _dl_init_internal () from /lib64/ld-linux-x86-64.so.2
#11 0x00007ffff7def6de in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
#12 0x00007ffff7dea914 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#13 0x00007ffff7deeccb in _dl_open () from /lib64/ld-linux-x86-64.so.2
#14 0x00007ffff7bd7fbb in dlopen_doit () from /lib64/libdl.so.2
#15 0x00007ffff7dea914 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#16 0x00007ffff7bd85bd in _dlerror_run () from /lib64/libdl.so.2
#17 0x00007ffff7bd8051 in dlopen@@GLIBC_2.2.5 () from /lib64/libdl.so.2
#18 0x00007ffff6b513d7 in TC::CClangTranslationBlock::Create(TC::STB_CreateArgs const*, TC::CClangTranslationBlock*&) () from /lib64/libigdfcl.so.1
#19 0x00007ffff6b5bfde in IGC::FclOclDeviceCtx<1ul>::CreateTranslationCtxImpl(unsigned long, unsigned long, unsigned long) () from /lib64/libigdfcl.so.1
#20 0x000000000041ced3 in OCLRT::OfflineCompiler::buildSourceCode() ()
#21 0x0000000000420fbe in OCLRT::OfflineCompiler::build() ()
#22 0x0000000000425174 in int SafetyGuardLinux::call<int, OCLRT::OfflineCompiler, int (OCLRT::OfflineCompiler::*)()>(OCLRT::OfflineCompiler*, int (OCLRT::OfflineCompiler::*)(), int) ()
#23 0x0000000000425074 in buildWithSafetyGuard(OCLRT::OfflineCompiler*) ()
#24 0x00000000004117a2 in main ()

So, here https://github.com/llvm/llvm-project/blob/release/8.x/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp#L264 there is some globals initialization in LLVM which error out:

static MachineSchedRegistry
R600SchedRegistry("r600", "Run R600's custom scheduler",
                   createR600MachineScheduler);

Can that be that we have initialized something already within other DLL loading?

@tripzero
Copy link
Contributor

I also see a core dump when using ocloc, but mine appears to be slightly different:

[ 66%] Generating ../../../bin/built_ins/x64/gen8/aux_translation_Gen8core.spv, ../../../bin/built_ins/x64/gen8/aux_translation_Gen8core.bin, ../../../bin/built_ins/x64/gen8/aux_translation_Gen8core.cpp, ../../../bin/built_ins/x64/gen8/aux_translation_Gen8core.gen
cd /builddir/build/BUILD/compute-runtime-19.09.12487/runtime/built_ins/kernels && LD_LIBRARY_PATH=/builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/ocloc -q -file aux_translation.igdrcl_built_in -device bdw -64 -out_dir /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/built_ins/x64/gen8 -cpp_file -options -cl-kernel-arg-info
[0]: /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/ocloc(_ZN16SafetyGuardLinux9sigActionEiP9siginfo_tPv+0x26) [0x41f446]
[1]: /usr/lib64/libpthread.so.0(+0x14600) [0x7f2efd681600]
[2]: /lib64/ld-linux-x86-64.so.2(+0x16935) [0x7f2efd6ad935]
[3]: /usr/lib64/libc.so.6(_dl_catch_exception+0x77) [0x7f2efd41d617]
[4]: /usr/lib64/libc.so.6(_dl_catch_error+0x33) [0x7f2efd41d6b3]
[5]: /usr/lib64/libdl.so.2(+0x1b39) [0x7f2efd690b39]
[6]: /usr/lib64/libdl.so.2(dlclose+0x28) [0x7f2efd690478]
[7]: /usr/lib64/libigdfcl.so(+0x3a3a) [0x7f2efd0f7a3a]
[8]: /usr/lib64/libigdfcl.so(+0x3c63) [0x7f2efd0f7c63]
[9]: /usr/lib64/libigdfcl.so(+0xecfb) [0x7f2efd102cfb]
[10]: /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/ocloc(_ZN5OCLRT15OfflineCompiler15buildSourceCodeEv+0x33d) [0x419ccd]
[11]: /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/ocloc(_ZN5OCLRT15OfflineCompiler5buildEv+0xf) [0x41bcaf]
[12]: /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/ocloc(_ZN16SafetyGuardLinux4callIiN5OCLRT15OfflineCompilerEMS2_FivEEET_PT0_T1_S5_+0x4a) [0x41f4fa]
[13]: /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/ocloc(_Z20buildWithSafetyGuardPN5OCLRT15OfflineCompilerE+0x71) [0x41f411]
[14]: /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/ocloc(main+0xae) [0x40d76e]
[15]: /usr/lib64/libc.so.6(__libc_start_main+0xf3) [0x7f2efd2e4e73]
[16]: /builddir/build/BUILD/compute-runtime-19.09.12487/clr-build/bin/ocloc(_start+0x2e) [0x40da9e]

@dvrogozh
Copy link
Contributor

@tripzero : I saw such code dumps when ocloc or one of igc libraries fails to dlopen() another library. Mind that ocloc loads libigdrcl.so, libigc.so, libcommon_clang.so and other libs from LLVM. They need to be in a libraries search path. Moreover, you won't be able to adjust it via LD_LIBRARY_PATH since there are these constructions for ocloc: "LD_LIBRARY_PATH=/path/to/comput_runtime/location ocloc..."

@tripzero
Copy link
Contributor

@dvrogozh right, I was missing the dependency on opencl-clang within compute-runtime. I don't get any assertions/crashes now.

@dvrogozh
Copy link
Contributor

In case of Release build of LLVM instead of assert I see this error:
Two passes with the same argument (-domtree) attempted to be registered!
on the NEO build. Build fails.

@AlexeySotkin
Copy link
Contributor Author

@dvrogozh could you run cloc with "LD_DEBUG=files" in front of the command line.
Also I think you should use -DLLVM_LINK_LLVM_DYLIB=ON instead of -DLLVM_BUILD_LLVM_DYLIB=ON

@dvrogozh
Copy link
Contributor

@AlexeySotkin : that was the first time I attempted building LLVM into dynamic library and I was looking here for the options: http://llvm.org/docs/GettingStarted.html. This page lists LLVM_BUILD_LLVM_DYLIB. However, I saw at least in ClearLinux LLVM .spec file that they use LLVM_LINK_LLVM_DYLIB instead as you suggested. I am not sure what's the difference. So, I was curious. I trusted official LLVM document. I will try to rebuild with LLVM_LINK_LLVM_DYLIB today and see what will happen.

@dvrogozh
Copy link
Contributor

@AlexeySotkin : here is ocloc rerun with LD_DEBUG=files:

      7405:	file=libdl.so.2 [0];  needed by /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc [0]
      7405:	file=libdl.so.2 [0];  generating link map
      7405:	  dynamic: 0x00007f753b5add88  base: 0x00007f753b3ab000   size: 0x0000000000203130
      7405:	    entry: 0x00007f753b3abe60  phdr: 0x00007f753b3ab040  phnum:                  7
      7405:	
      7405:	
      7405:	file=libpthread.so.0 [0];  needed by /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc [0]
      7405:	file=libpthread.so.0 [0];  generating link map
      7405:	  dynamic: 0x00007f753b3a5d50  base: 0x00007f753b18f000   size: 0x000000000021b488
      7405:	    entry: 0x00007f753b195d00  phdr: 0x00007f753b18f040  phnum:                  9
      7405:	
      7405:	
      7405:	file=libstdc++.so.6 [0];  needed by /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc [0]
      7405:	file=libstdc++.so.6 [0];  generating link map
      7405:	  dynamic: 0x00007f753b1774d8  base: 0x00007f753ae88000   size: 0x0000000000306360
      7405:	    entry: 0x00007f753aee3220  phdr: 0x00007f753ae88040  phnum:                  8
      7405:	
      7405:	
      7405:	file=libm.so.6 [0];  needed by /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc [0]
      7405:	file=libm.so.6 [0];  generating link map
      7405:	  dynamic: 0x00007f753ae86d90  base: 0x00007f753ab86000   size: 0x0000000000301138
      7405:	    entry: 0x00007f753ab8b370  phdr: 0x00007f753ab86040  phnum:                  7
      7405:	
      7405:	
      7405:	file=libgcc_s.so.1 [0];  needed by /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc [0]
      7405:	file=libgcc_s.so.1 [0];  generating link map
      7405:	  dynamic: 0x00007f753ab84dd8  base: 0x00007f753a970000   size: 0x0000000000215400
      7405:	    entry: 0x00007f753a972a90  phdr: 0x00007f753a970040  phnum:                  7
      7405:	
      7405:	
      7405:	file=libc.so.6 [0];  needed by /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc [0]
      7405:	file=libc.so.6 [0];  generating link map
      7405:	  dynamic: 0x00007f753a968b80  base: 0x00007f753a5a3000   size: 0x00000000003cc1e0
      7405:	    entry: 0x00007f753a5c5550  phdr: 0x00007f753a5a3040  phnum:                 10
      7405:	
      7405:	
      7405:	calling init: /lib64/libpthread.so.0
      7405:	
      7405:	
      7405:	calling init: /lib64/libc.so.6
      7405:	
      7405:	
      7405:	calling init: /lib64/libgcc_s.so.1
      7405:	
      7405:	
      7405:	calling init: /lib64/libm.so.6
      7405:	
      7405:	
      7405:	calling init: /lib64/libstdc++.so.6
      7405:	
      7405:	
      7405:	calling init: /lib64/libdl.so.2
      7405:	
      7405:	
      7405:	initialize program: /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc
      7405:	
      7405:	
      7405:	transferring control: /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc
      7405:	
      7405:	
      7405:	file=libigdfcl.so.1 [0];  dynamically loaded by /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc [0]
      7405:	file=libigdfcl.so.1 [0];  generating link map
      7405:	  dynamic: 0x00007f753a534b28  base: 0x00007f753a322000   size: 0x0000000000280dc0
      7405:	    entry: 0x00007f753a324d40  phdr: 0x00007f753a322040  phnum:                  7
      7405:	
      7405:	
      7405:	file=librt.so.1 [0];  needed by /lib64/libigdfcl.so.1 [0]
      7405:	file=librt.so.1 [0];  generating link map
      7405:	  dynamic: 0x00007f753a320d70  base: 0x00007f753a11a000   size: 0x0000000000207c38
      7405:	    entry: 0x00007f753a11c250  phdr: 0x00007f753a11a040  phnum:                  7
      7405:	
      7405:	
      7405:	file=libLLVM-8.so [0];  needed by /lib64/libigdfcl.so.1 [0]
      7405:	file=libLLVM-8.so [0];  generating link map
      7405:	  dynamic: 0x00007f753a072c68  base: 0x00007f7535dcb000   size: 0x000000000434efb8
      7405:	    entry: 0x00007f753658fdc0  phdr: 0x00007f7535dcb040  phnum:                  8
      7405:	
      7405:	
      7405:	file=libz.so.1 [0];  needed by /lib64/libLLVM-8.so [0]
      7405:	file=libz.so.1 [0];  generating link map
      7405:	  dynamic: 0x00007f7535dc9dd8  base: 0x00007f7535bb5000   size: 0x0000000000215208
      7405:	    entry: 0x00007f7535bb7170  phdr: 0x00007f7535bb5040  phnum:                  7
      7405:	
      7405:	
      7405:	file=libxml2.so.2 [0];  needed by /lib64/libLLVM-8.so [0]
      7405:	file=libxml2.so.2 [0];  generating link map
      7405:	  dynamic: 0x00007f7535bb0b30  base: 0x00007f753584b000   size: 0x0000000000369058
      7405:	    entry: 0x00007f7535879920  phdr: 0x00007f753584b040  phnum:                  7
      7405:	
      7405:	
      7405:	file=liblzma.so.5 [0];  needed by /lib64/libxml2.so.2 [0]
      7405:	file=liblzma.so.5 [0];  generating link map
      7405:	  dynamic: 0x00007f7535849dc0  base: 0x00007f7535625000   size: 0x0000000000225288
      7405:	    entry: 0x00007f7535628080  phdr: 0x00007f7535625040  phnum:                  7
      7405:	
      7405:	
      7405:	calling init: /lib64/liblzma.so.5
      7405:	
      7405:	
      7405:	calling init: /lib64/libz.so.1
      7405:	
      7405:	
      7405:	calling init: /lib64/libxml2.so.2
      7405:	
      7405:	
      7405:	calling init: /lib64/librt.so.1
      7405:	
      7405:	
      7405:	calling init: /lib64/libLLVM-8.so
      7405:	
      7405:	
      7405:	calling init: /lib64/libigdfcl.so.1
      7405:	
      7405:	opening file=/lib64/libigdfcl.so.1 [0]; direct_opencount=1
      7405:	
      7405:	
      7405:	file=libigc.so.1 [0];  dynamically loaded by /home/dvrogozh/git/github/tmp/neo/compute-runtime/build/bin/ocloc [0]
      7405:	file=libigc.so.1 [0];  generating link map
      7405:	  dynamic: 0x00007f75345f9340  base: 0x00007f7533ad6000   size: 0x0000000001b4e448
      7405:	    entry: 0x00007f7533b9a300  phdr: 0x00007f7533ad6040  phnum:                  8
      7405:	
      7405:	
      7405:	calling init: /lib64/libigc.so.1
      7405:	
      7405:	opening file=/lib64/libigc.so.1 [0]; direct_opencount=1
      7405:	
      7405:	
      7405:	file=libopencl_clang.so [0];  dynamically loaded by /lib64/libigdfcl.so.1 [0]
      7405:	file=libopencl_clang.so [0];  generating link map
      7405:	  dynamic: 0x00007f75339b3f10  base: 0x00007f752f686000   size: 0x000000000444ffb8
      7405:	    entry: 0x00007f752fb3c450  phdr: 0x00007f752f686040  phnum:                  7
      7405:	
      7405:	
      7405:	file=libLLVMSPIRVLib.so.8 [0];  needed by /lib64/libopencl_clang.so [0]
      7405:	file=libLLVMSPIRVLib.so.8 [0];  generating link map
      7405:	  dynamic: 0x00007f752f640350  base: 0x00007f752e4c8000   size: 0x00000000011bdc00
      7405:	    entry: 0x00007f752ea64020  phdr: 0x00007f752e4c8040  phnum:                  8
      7405:	
      7405:	
      7405:	file=libLTO.so.8 [0];  needed by /lib64/libopencl_clang.so [0]
      7405:	file=libLTO.so.8 [0];  generating link map
      7405:	  dynamic: 0x00007f752e451530  base: 0x00007f752ae85000   size: 0x00000000036423d0
      7405:	    entry: 0x00007f752b190dc0  phdr: 0x00007f752ae85040  phnum:                  8
      7405:	
      7405:	
      7405:	file=libOptRemarks.so.8 [0];  needed by /lib64/libopencl_clang.so [0]
      7405:	file=libOptRemarks.so.8 [0];  generating link map
      7405:	  dynamic: 0x00007f752ae83d90  base: 0x00007f752ac83000   size: 0x0000000000201020
      7405:	    entry: 0x00007f752ac83520  phdr: 0x00007f752ac83040  phnum:                  7
      7405:	
      7405:	
      7405:	calling init: /lib64/libOptRemarks.so.8
      7405:	
      7405:	
      7405:	calling init: /lib64/libLTO.so.8
      7405:	
      7405:	
      7405:	calling init: /lib64/libLLVMSPIRVLib.so.8
      7405:	
      7405:	
      7405:	calling init: /lib64/libopencl_clang.so
      7405:	
      7405:	opening file=/lib64/libopencl_clang.so [0]; direct_opencount=1
      7405:	
Two passes with the same argument (-domtree) attempted to be registered!
      7405:	opening file=/lib64/libgcc_s.so.1 [0]; direct_opencount=1
      7405:	

@dvrogozh
Copy link
Contributor

By the way, libLLVM-8.so is encountered at least twice in dependencies resolution:

# ldd /usr/lib64/libigdfcl.so.1
        linux-vdso.so.1 =>  (0x00007ffd62dbf000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f116a61c000)
        libLLVM-8.so => /lib64/libLLVM-8.so (0x00007f11662cd000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f11660c9000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f1165dc2000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f1165ac0000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f11658aa000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f11654dd000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f11652c1000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f11650ab000)
        libxml2.so.2 => /lib64/libxml2.so.2 (0x00007f1164d41000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f116aaa5000)
        liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f1164b1b000)

# ldd /usr/lib64/libcommon_clang.so.8
        linux-vdso.so.1 =>  (0x00007fff82b4d000)
        libLLVMSPIRVLib.so.8 => /lib64/libLLVMSPIRVLib.so.8 (0x00007efca5573000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007efca536f000)
        libLTO.so.8 => /lib64/libLTO.so.8 (0x00007efca1d2c000)
        libLLVM-8.so => /lib64/libLLVM-8.so (0x00007efc9d9dd000)
        libOptRemarks.so.8 => /lib64/libOptRemarks.so.8 (0x00007efc9d7db000)
        libz.so.1 => /lib64/libz.so.1 (0x00007efc9d5c5000)
        librt.so.1 => /lib64/librt.so.1 (0x00007efc9d3bd000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007efc9d1a1000)
        libxml2.so.2 => /lib64/libxml2.so.2 (0x00007efc9ce37000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007efc9cb30000)
        libm.so.6 => /lib64/libm.so.6 (0x00007efc9c82e000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007efc9c618000)
        libc.so.6 => /lib64/libc.so.6 (0x00007efc9c24b000)
        /lib64/ld-linux-x86-64.so.2 (0x00007efcaab81000)
        liblzma.so.5 => /lib64/liblzma.so.5 (0x00007efc9c025000)

And as you can see in LD_DEBUG=files log, libLLVM-8 was loaded by libigdfcl,so.1 and was not loaded for libcommon_clang.so.8 since it was already there. I wonder, this 2nd faulty registering of parser comes for libLLVM.so or from something else?

@AlexeySachkov
Copy link
Contributor

@dvrogozh, looking at Building LLVM with CMake looks like for common_clang build purposes both of these options should be the same:

LLVM_BUILD_LLVM_DYLIB:BOOL

If enabled, the target for building the libLLVM shared library is added. This library contains all of LLVM’s components in a single shared library. Defaults to OFF. This cannot be used in conjunction with BUILD_SHARED_LIBS. Tools will only be linked to the libLLVM shared library if LLVM_LINK_LLVM_DYLIB is also ON. The components in the library can be customised by setting LLVM_DYLIB_COMPONENTS to a list of the desired components.

LLVM_LINK_LLVM_DYLIB:BOOL

If enabled, tools will be linked with the libLLVM shared library. Defaults to OFF. Setting LLVM_LINK_LLVM_DYLIB to ON also sets LLVM_BUILD_LLVM_DYLIB to ON.

@dvrogozh
Copy link
Contributor

dvrogozh commented Mar 21, 2019

There is something which I don't quite understand and which bothers me. So, I built LLVM with LLVM_BUILD_LLVM_DYLIB=ON. Still, I got both libLLVM-8.so and a bunch of lib*.a files. Moreover, when I run this, I get that I need to link all the static libs, it does not mention .so:

./bin/llvm-config --libs all
-lLLVMLTO -lLLVMPasses -lLLVMObjCARCOpts -lLLVMMIRParser -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoDWARF -lLLVMCoverage -lLLVMMCA -lLLVMTableGen -lLLVMDlltoolDriver -lLLVMXRay -lLLVMOrcJIT -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMWebAssemblyDisassembler -lLLVMWebAssemblyCodeGen -lLLVMWebAssemblyDesc -lLLVMWebAssemblyAsmPrinter -lLLVMWebAssemblyAsmParser -lLLVMWebAssemblyInfo -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcDisassembler -lLLVMSparcCodeGen -lLLVMSparcAsmParser -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMSparcAsmPrinter -lLLVMPowerPCDisassembler -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430Disassembler -lLLVMMSP430CodeGen -lLLVMMSP430AsmParser -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMLanaiDisassembler -lLLVMLanaiCodeGen -lLLVMLanaiAsmParser -lLLVMLanaiDesc -lLLVMLanaiAsmPrinter -lLLVMLanaiInfo -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMBPFDisassembler -lLLVMBPFCodeGen -lLLVMBPFAsmParser -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMBPFAsmPrinter -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMARMUtils -lLLVMAMDGPUDisassembler -lLLVMAMDGPUCodeGen -lLLVMAMDGPUAsmParser -lLLVMAMDGPUDesc -lLLVMAMDGPUInfo -lLLVMAMDGPUAsmPrinter -lLLVMAMDGPUUtils -lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMObjectYAML -lLLVMLibDriver -lLLVMOption -lLLVMOptRemarks -lLLVMWindowsManifest -lLLVMTextAPI -lLLVMFuzzMutate -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMLineEditor -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMCodeGen -lLLVMTarget -lLLVMCoroutines -lLLVMipo -lLLVMInstrumentation -lLLVMVectorize -lLLVMScalarOpts -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMInstCombine -lLLVMBitWriter -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMBitReader -lLLVMCore -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle

And here is link command line for common_clang (sorry, it is a long one):
/opt/rh/devtoolset-7/root/usr/bin/c++ -fPIC -Wl,-rpath-link, -Wl,-O3 -Wl,--gc-sections -Wl,--no-undefined -Wl,-Bsymbolic -Wl,--version-script=/home/dvrogozh/git/github/tmp/common_clang/common_clang.map -shared -Wl,-soname,libcommon_clang.so.8 -o libcommon_clang.so.8 CMakeFiles/common_clang.dir/common_clang.cpp.o CMakeFiles/common_clang.dir/options.cpp.o CMakeFiles/common_clang.dir/pch_mgr.cpp.o CMakeFiles/common_clang.dir/options_compile.cpp.o cl_headers/CMakeFiles/cl_headers.dir/opencl-c.h.cpp.o -L/home/dvrogozh/git/github/tmp/install.llvm8/lib -Wl,-rpath,"\$ORIGIN/../lib" -lclangBasic -lclangCodeGen -lclangDriver -lclangFrontend -lclangFrontendTool -lclangCodeGen -lclangRewriteFrontend -lclangARCMigrate -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangCrossTU -lclangIndex -lclangFrontend -lclangDriver -lclangParse -lclangSerialization -lclangSema -lclangAnalysis -lclangEdit -lclangFormat -lclangToolingInclusions -lclangToolingCore -lclangRewrite -lclangASTMatchers -lclangAST -lclangLex -lclangBasic -lLLVMSPIRVLib -ldl /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDemangle.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSupport.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMTableGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMCore.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMFuzzMutate.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMIRReader.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSelectionDAG.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMIRParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMGlobalISel.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBinaryFormat.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBitReader.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBitWriter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMTransformUtils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMInstrumentation.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAggressiveInstCombine.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMInstCombine.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMScalarOpts.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMipo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMVectorize.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMObjCARCOpts.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMCoroutines.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLinker.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAnalysis.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLTO.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMC.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMCParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMCDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMCA.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMObject.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMObjectYAML.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMOption.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMOptRemarks.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDebugInfoDWARF.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDebugInfoMSF.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDebugInfoCodeView.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDebugInfoPDB.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSymbolize.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMExecutionEngine.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMInterpreter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMCJIT.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMOrcJIT.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMRuntimeDyld.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMTarget.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64CodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64AsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64Disassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64AsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64Desc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64Info.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64Utils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUUtils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMUtils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBPFCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBPFAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBPFDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBPFAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBPFDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBPFInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMHexagonCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMHexagonAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMHexagonDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMHexagonDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMHexagonInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLanaiCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLanaiAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLanaiDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLanaiAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLanaiDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLanaiInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMipsCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMipsAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMipsDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMipsAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMipsDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMipsInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430CodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430AsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430Desc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430Info.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430AsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430Disassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMNVPTXCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMNVPTXAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMNVPTXDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMNVPTXInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMPowerPCCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMPowerPCAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMPowerPCDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMPowerPCAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMPowerPCDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMPowerPCInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSparcCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSparcAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSparcDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSparcAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSparcDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSparcInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSystemZCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSystemZAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSystemZDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSystemZAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSystemZDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSystemZInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMWebAssemblyCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMWebAssemblyAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMWebAssemblyDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMWebAssemblyAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMWebAssemblyDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMWebAssemblyInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86CodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86AsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86Disassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86AsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86Desc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86Info.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86Utils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMXCoreCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMXCoreDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMXCoreAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMXCoreDesc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMXCoreInfo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLineEditor.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMProfileData.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMCoverage.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMPasses.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMTextAPI.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDlltoolDriver.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLibDriver.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMXRay.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMWindowsManifest.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLTO.so.8 /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVM-8.so /home/dvrogozh/git/github/tmp/install.llvm8/lib/libOptRemarks.so.8 -lclangCodeGen -lclangDriver -lclangFrontend -lclangFrontendTool -lclangRewriteFrontend -lclangARCMigrate -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangCrossTU -lclangIndex -lclangParse -lclangSerialization -lclangSema -lclangAnalysis -lclangEdit -lclangFormat -lclangToolingInclusions -lclangToolingCore -lclangRewrite -lclangASTMatchers -lclangAST -lclangLex -lLLVMSPIRVLib /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMObjCARCOpts.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDebugInfoDWARF.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDebugInfoPDB.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMExecutionEngine.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMRuntimeDyld.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64AsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAArch64Utils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAMDGPUUtils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMARMUtils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBPFAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLanaiAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMipsAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430Desc.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430AsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMSP430Info.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMipo.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMIRReader.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAsmParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMInstrumentation.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMLinker.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMVectorize.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMNVPTXAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMPowerPCAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSparcAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSystemZAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMWebAssemblyAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMGlobalISel.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86AsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMX86Utils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSelectionDAG.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMCodeGen.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBitWriter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMScalarOpts.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAggressiveInstCombine.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMInstCombine.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMTransformUtils.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMTarget.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMAnalysis.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMXCoreAsmPrinter.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMCDisassembler.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMProfileData.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMOption.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMObject.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBitReader.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMCore.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMCParser.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMMC.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMBinaryFormat.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDebugInfoCodeView.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDebugInfoMSF.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMSupport.a /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVMDemangle.a -lz -lrt -ldl -lpthread -lm -lxml2

If you will search thru it, you will see that it has /home/dvrogozh/git/github/tmp/install.llvm8/lib/libLLVM-8.so and a bunch of .a files as well. Can that be that we somehow link the same twice?

@dvrogozh
Copy link
Contributor

It seems I root caused it. So, I tried 2 experiments hacking the above common_clang linker command line:

  1. First time I just removed libLLVM-8.so from linker command line - ocloc works
  2. Second time I removed all libLLVM*.a from linker command line and left libLLVM-8.so - ocloc works

Thus, it seems that we can not link llvm component libLLVM*.a and libLLVM-8.so at the same time. It seems that this behavior was caused by add_llvm_library() since I don't see that we have any command to link libLLVM-8.so or libLLVM*.a explicitly. I thought that this macro is capable to correctly handle situation by itself, but it seems it is not... I wonder, is that correct thing to do to use add_llvm_library()? Maybe the purpose of it is to implement new llvm component which don't depend on others and it is not applicable in case when we try to create a library which uses other components?

@dvrogozh
Copy link
Contributor

As of now I don't see other way to distinguish between 2 kinds of LLVM builds other than check it on project's cmake level. In a way that's project decision how it wants to link against LLVM: statically or dynamically. I believe that nice default would be link against libLLVM-8.so if it is available and link against .a if it is not. We might consider to introduce a build option to force one way or another. In case of the default described above, I did this:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -187,6 +187,13 @@ add_subdirectory(cl_headers)

 set(LLVM_REQUIRES_EH ON)

+if (TARGET LLVM)
+  set(llvm_libs "")
+  set(ADDITIONAL_LIBS "${ADDITIONAL_LIBS};LTO;LLVM;OptRemarks")
+else()
+  set(llvm_libs all)
+endif()
+
 add_llvm_library(${TARGET_NAME} SHARED
   ${TARGET_INCLUDE_FILES}
   ${TARGET_SOURCE_FILES}
@@ -194,7 +201,7 @@ add_llvm_library(${TARGET_NAME} SHARED

   DEPENDS CClangCompileOptions
   LINK_COMPONENTS
-    all
+    ${llvm_libs}
   LINK_LIBS
 # The list of clang libraries is taken from clang makefile
 # (build/tools/clang/tools/driver/CMakeFiles/clang.dir/link.txt)

So, if(TARGET LLVM) checks whether libLLVM-8.so is actually available. You might need to implement some more sophisticated way to check for the library in case of prebuilt path though. I was trying to find a way to avoid manually specifying "LTO;LLVM;OptRemarks", i.e. libs to link against, but I did not find such a path.

@AlexeySotkin : can you, please, review this proposal?

Also adding " -Wl,--no-undefined" to the link flags.
@AlexeySachkov
Copy link
Contributor

@dvrogozh,

Thus, it seems that we can not link llvm component libLLVM*.a and libLLVM-8.so at the same time. It seems that this behavior was caused by add_llvm_library() since I don't see that we have any command to link libLLVM-8.so or libLLVM*.a explicitly. I thought that this macro is capable to correctly handle situation by itself, but it seems it is not...

I'm not sure, but this is probably caused by a some cmake/make error, because add_llvm_library should correctly handle LLVM_LINK_LLVM_DYLIB configuration, see https://github.com/llvm-mirror/llvm/blob/master/cmake/modules/AddLLVM.cmake#L366
According to this option, your library should be automatically linked into libLLVM when LLVM_LINK_LLVM_DYLIB is present.

And such linkage is actually performed here: https://github.com/llvm-mirror/llvm/blob/master/cmake/modules/AddLLVM.cmake#L550

Did you perform clean-build when you switched between LLVM_BUILD_LLVM_DYLIB to LLVM_LINK_LLVM_DYLIB?

I wonder, is that correct thing to do to use add_llvm_library()? Maybe the purpose of it is to implement new llvm component which don't depend on others and it is not applicable in case when we try to create a library which uses other components?

AFAIK, each of LLVM library (i.e. Support, IR, etc.) is built using exactly this functionality: creating a new component with dependencies on some of the already existing

Copy link
Contributor

@AlexeySachkov AlexeySachkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dvrogozh, could you please re-check this pull request using clean build of LLVM?

@dvrogozh
Copy link
Contributor

@AlexeySachkov : all experiments which I did were done with clean build of LLVM. I think you are mistaken regarding add_llvm_library().

https://github.com/llvm-mirror/llvm/blob/master/cmake/modules/AddLLVM.cmake#L366

You don't use this function, you use add_llvm_library() instead of llvm_add_library() which you have referenced. However, I have tried to use the latter one - this don't help.

your library should be automatically linked into libLLVM

This phrase means that library we produce (libcommon_clang) will be marked to be linked inside libLLVM during LLVM build. However, this is not our case: we don't need to build libLLVM into libLLVM.so, instead we are trying to produce libcommon_clang.so. And DISABLE_LLVM_LINK_LLVM_DYLIB can be used to disable the behavior, i.e. make sure that libLLVM.so will not include inside our library.

@dvrogozh
Copy link
Contributor

I finally tried to build with -DLLVM_LINK_LLVM_DYLIB=ON and it really works! So, indeed this flag is being propagated into LLVM installed environment and is visible for the end-users via LLVMConfig.cmake. Indeed, this flag permits to tell that libraries should be built against libLLVM-8.so and not against .a static libs.

So, we have 3 build variants and the following status with current state of PR:

  1. cmake ... -> produces .a files -> NEO build pass
  2. cmake -DLLVM_BUILD_LLVM_DYLIB=ON ... -> produces .a files + .so -> NEO build fails
  3. cmake -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON ... -> produces .a files + .so -> NEO build pass

Distributions seem to prefer variant 3). For example, here is Debian packaging instructions: https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/blob/8/debian/rules#L358. For distributions which prefer 1) or 3) current PR should be fine. @tripzero, @tjaalton : FYI

  1. fails because for some reasons LLVM generates the list of llvm_config(all) targets which contains both all static .a libraries and libLLVM-8.so. Hence, question is whether this is by intent and we should handle this in our cmake scripts or this is a bug in LLVM? I plan to ask in LLMV mailing list.

Anyhow, we can distinguish 2) with the following check which is similar to what I suggested above:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -187,6 +187,13 @@ add_subdirectory(cl_headers)

 set(LLVM_REQUIRES_EH ON)

+if (NOT LLVM_LINK_LLVM_DYLIB AND TARGET LLVM)
+  # link against LLVM dylib if it is available
+  set(llvm_libs "")
+  set(ADDITIONAL_LIBS "${ADDITIONAL_LIBS};LTO;LLVM;OptRemarks")
+else()
+  set(llvm_libs all)
+endif()
+
 add_llvm_library(${TARGET_NAME} SHARED
   ${TARGET_INCLUDE_FILES}
   ${TARGET_SOURCE_FILES}
@@ -194,7 +201,7 @@ add_llvm_library(${TARGET_NAME} SHARED

   DEPENDS CClangCompileOptions
   LINK_COMPONENTS
-    all
+    ${llvm_libs}
   LINK_LIBS
 # The list of clang libraries is taken from clang makefile
 # (build/tools/clang/tools/driver/CMakeFiles/clang.dir/link.txt)

I am not sure about priority of fixing that. It might be ok to merge the change as is and clarify with LLVM developers without a rush.

@dvrogozh
Copy link
Contributor

I posted a question here: http://lists.llvm.org/pipermail/llvm-dev/2019-March/131252.html

@AlexeySotkin AlexeySotkin merged commit 94e1b34 into intel:master Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants