[llvm] 5229dd1 - [build] Add LLVM_LOCAL_RPATH which can set an rpath on just unit test binaries

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Tue May 26 03:24:36 PDT 2020


Author: Nico Weber
Date: 2020-05-26T06:23:57-04:00
New Revision: 5229dd1366ab1423d66d3d16dddff6fbaee049d8

URL: https://github.com/llvm/llvm-project/commit/5229dd1366ab1423d66d3d16dddff6fbaee049d8
DIFF: https://github.com/llvm/llvm-project/commit/5229dd1366ab1423d66d3d16dddff6fbaee049d8.diff

LOG: [build] Add LLVM_LOCAL_RPATH which can set an rpath on just unit test binaries

After D80096, bots that build clang for distribution and that can't use
system gcc / libstdc++ need to pass a working rpath so that unit test
binaries can run. The method suggested in GettingStarted.rst works fine
for local development, but it results in an absolute local rpath ending
up even in distributed binaries like clang, which is both ugly and
unnecessary.

Add an explicit toggle that can be used to add an rpath only for the
non-distributed binaries that need it.

Differential Revision: https://reviews.llvm.org/D80534

Added: 
    

Modified: 
    llvm/CMakeLists.txt
    llvm/cmake/modules/AddLLVM.cmake
    llvm/docs/GettingStarted.rst

Removed: 
    


################################################################################
diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 3fbe1e6cf9a4..06b8646ca37b 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -439,6 +439,9 @@ set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
 option(LLVM_FORCE_USE_OLD_TOOLCHAIN
        "Set to ON to force using an old, unsupported host toolchain." OFF)
 
+set(LLVM_LOCAL_RPATH "" CACHE FILEPATH
+  "If set, an absolute path added as rpath on binaries that do not already contain an executable-relative rpath.")
+
 option(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN
        "Set to ON to only warn when using a toolchain which is about to be deprecated, instead of emitting an error." OFF)
 

diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 5b6b7f56777b..9f14561fe0a6 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -821,6 +821,10 @@ macro(add_llvm_executable name)
 
   if(NOT ARG_NO_INSTALL_RPATH)
     llvm_setup_rpath(${name})
+  elseif (LLVM_LOCAL_RPATH)
+    set_target_properties(${name} PROPERTIES
+                          BUILD_WITH_INSTALL_RPATH On
+                          INSTALL_RPATH "${LLVM_LOCAL_RPATH}")
   endif()
 
   if(DEFINED windows_resource_file)

diff  --git a/llvm/docs/GettingStarted.rst b/llvm/docs/GettingStarted.rst
index 46e337d2cec9..5cce01b72c11 100644
--- a/llvm/docs/GettingStarted.rst
+++ b/llvm/docs/GettingStarted.rst
@@ -340,6 +340,16 @@ If you fail to set rpath, most LLVM binaries will fail on startup with a message
 from the loader similar to ``libstdc++.so.6: version `GLIBCXX_3.4.20' not
 found``. This means you need to tweak the -rpath linker flag.
 
+This method will add an absolute path to the rpath of all executables. That's
+fine for local development. If you want to distribute the binaries you build
+so that they can run on older systems, copy ``libstdc++.so.6`` into the
+``lib/`` directory.  All of LLVM's shipping binaries have an rpath pointing at
+``$ORIGIN/../lib``, so they will find ``libstdc++.so.6`` there.  Non-distributed
+binaries don't have an rpath set and won't find ``libstdc++.so.6``. Pass
+``-DLLVM_LOCAL_RPATH="$HOME/toolchains/lib64"`` to cmake to add an absolute
+path to ``libstdc++.so.6`` as above. Since these binaries are not distributed,
+having an absolute local path is fine for them.
+
 When you build Clang, you will need to give *it* access to modern C++
 standard library in order to use it as your new host in part of a bootstrap.
 There are two easy ways to do this, either build (and install) libc++ along


        


More information about the llvm-commits mailing list