[llvm-dev] Incorrect LD_LIBRARY_PATH manifests in a totally different way!

Suprateeka R Hegde via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 19 09:31:32 PDT 2016


While building llvm trunk (including compiler-rt), the build (asan link) 
failed with "undefined reference to shm_open".

Upon search, it is found in librt.so. But -lrt was not there on the 
link-line at all. Adding -lrt in the CMake generated link.txt, makes the 
build go through. But thats not the solution.

Upon further searching, I find:
  in file projects/compiler-rt/lib/asan/CMakeLists.txt.

The boolean COMPILER_RT_HAS_LIBRT was set to false, and hence, the "if" 
failed to add -lrt.

But why was the boolean set to false?

Turns out that in the very beginning (cmake configure stage), when 
testing the availability for function shm_open, -lrt was indeed linked, 
but the test failed!

Why because, librt.so has libpthread.so is DT_NEEDED. Unknowingly I had 
set LD_LIBRARY_PATH to an incorrect (actually very latest and 
incompatible glibc) path where the latest  libpthread.so (trunk built 
glibc based) was available. However, this libpthread was incompatible 
with system installed libc.so.

Though all libraries have been picked up from the system standard path, 
libpthread.so being DT_NEEDED inside librt.so, was picked from my 

The test for availability of shm_open failed SILENTLY! At the end, cmake 
returned exit status 0 (success). And eventually compiler-rt (asan) 
build failed.

(I hate this GNU ld behavior of looking under LD_LIBRARY_PATH for 
DT_NEEDED even at static link time. It should search only at runtime. 
Anyway, thats how the system is)

How do I force CMake to bail out in such case? Do I need to change 
"append_list_if(booleans)" to something strict? What is the best solution?


More information about the llvm-dev mailing list