LLVM sets CMAKE_INSTALL_RPATH in its top-level CMakeLists.txt to "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}". When Clang is built with LLVM, this propagates to Clang as well and ensures that even if CMAKE_INSTALL_PREFIX is set, installed binaries always find their dependent libraries.
When compiling clang as a separately build, no such rpath is set. If CMAKE_INSTALL_PREFIX is not set and libraries are installed to standard locations, this is not a problem. But when defining CMAKE_INSTALL_PREFIX, even if the same as that of LLVM, and installing and then executing binaries like clang, it results in
error while loading shared libraries: libLLVMBPFCodeGen.so.4.0: cannot open shared object file: No such file or directory
In the case of using a separate CMAKE_INSTALL_PREFIX from LLVM's, eg., "/usr/lib/clang-4.0.0", the build needs rpaths for both its own libraries and that of LLVM. The build should set "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}:${LLVM_LIBRARY_DIR}" as the rpath in the general case. The rpath section was taken and modified from the top-level LLVM CMakeLists.txt.