Skip to content

Commit 2042326

Browse files
committed
[runtimes] Build with the install RPATH
Make sure that we build libraries in the runtimes using the final RPATH they will use after installation. This ensures that when we link against these libraries in our tests, they use the same RPATH that they will use after being installed, which increases reproducibility. As a side effect, it also solves the issue that libraries built from different build directories would have different binary signatures since they would have different offsets based on the length of the RPATH used during the build. This was undesirable since it made builds less reproducible. Fixes #67375
1 parent 94c0477 commit 2042326

File tree

6 files changed

+95
-7
lines changed

6 files changed

+95
-7
lines changed

libcxx/cmake/caches/AIX.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
2-
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
32
set(CMAKE_C_FLAGS "-D__LIBC_NO_CPP_MATH_OVERLOADS__" CACHE STRING "")
43
set(CMAKE_CXX_FLAGS "-D__LIBC_NO_CPP_MATH_OVERLOADS__" CACHE STRING "")
54
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-G -Wl,-bcdtors:all:-2147483548:s" CACHE STRING "")

libcxx/test/libcxx/vendor/apple/system-install-properties.sh.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@
2727

2828
// Make sure the install_name is /usr/lib.
2929
//
30-
// In particular, make sure we don't use any @rpath in the load commands. When building as
31-
// a system library, it is important to hardcode the installation paths in the dylib, because
32-
// various tools like dyld and ld64 will treat us specially if they recognize us as being a
33-
// system library.
30+
// In particular, make sure we don't use any @rpath-relative paths in the load commands.
31+
// When building as a system library, it is important to hardcode the installation paths
32+
// in the dylib, because various tools like dyld and ld64 will treat us specially if they
33+
// recognize us as being a system library.
3434
//
3535
// TODO: We currently don't do that correctly in the CMake build.
3636
//
3737
// XRUNX: otool -L "%{lib}/libc++.1.dylib" | grep '/usr/lib/libc++.1.dylib'
38-
// XRUNX: ! otool -l "%{lib}/libc++.1.dylib" | grep -E "LC_RPATH|@loader_path|@rpath"
38+
// XRUNX: otool -l "%{lib}/libc++.1.dylib" | grep --invert-match -E "@loader_path|@rpath"
39+
40+
// Make sure we don't set a RPATH when we build the library. Since we are building a system
41+
// library, we are supposed to find our dependencies at the usual system-provided locations,
42+
// which doesn't require setting a RPATH in the library itself.
43+
//
44+
// RUN: otool -l "%{lib}/libc++.1.dylib" | grep --invert-match -e "LC_RPATH"
3945

4046
// Make sure the compatibility_version of libc++ is 1.0.0.
4147
// Failure to respect this can result in applications not being able to find libc++
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: stdlib=libc++ && target={{.+}}-apple-{{.+}}
10+
11+
// This file checks various properties of the installation of libc++ when built as
12+
// part of the LLVM releases, on Apple platforms.
13+
14+
// Make sure we install the libc++ headers in the right location.
15+
//
16+
// RUN: stat "%{include}/__config"
17+
18+
// Make sure we install libc++.1.dylib and libc++experimental.a in the right location.
19+
//
20+
// RUN: stat "%{lib}/libc++.1.dylib"
21+
// RUN: stat "%{lib}/libc++experimental.a"
22+
23+
// Make sure we install a symlink from libc++.dylib to libc++.1.dylib.
24+
//
25+
// RUN: stat "%{lib}/libc++.dylib"
26+
// RUN: readlink "%{lib}/libc++.dylib" | grep "libc++.1.dylib"
27+
28+
// Make sure we don't set a RPATH when we build the library. Since we are building a system
29+
// library, we are supposed to find our dependencies at the usual system-provided locations,
30+
// which doesn't require setting a RPATH in the library itself.
31+
//
32+
// RUN: otool -l "%{lib}/libc++.1.dylib" | grep --invert-match -e "LC_RPATH"
33+
34+
// Make sure the compatibility_version of libc++ is 1.0.0.
35+
// Failure to respect this can result in applications not being able to find libc++
36+
// when they are loaded by dyld, if the compatibility version was bumped.
37+
//
38+
// RUN: otool -L "%{lib}/libc++.1.dylib" | grep "libc++.1.dylib" | grep "compatibility version 1.0.0"

libcxxabi/test/vendor/apple/system-install-properties.sh.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@
3737
// TODO: We currently don't do that correctly in the CMake build.
3838
//
3939
// XRUNX: otool -L "%{lib}/libc++abi.dylib" | grep '/usr/lib/libc++abi.dylib'
40-
// XRUNX: ! otool -l "%{lib}/libc++abi.dylib" | grep -E "LC_RPATH|@loader_path|@rpath"
40+
// XRUNX: otool -l "%{lib}/libc++abi.dylib" | grep --invert-match -E "LC_RPATH|@loader_path|@rpath"
41+
42+
// Make sure we don't set a RPATH when we build the library. Since we are building a system
43+
// library, we are supposed to find our dependencies at the usual system-provided locations,
44+
// which doesn't require setting a RPATH in the library itself.
45+
//
46+
// RUN: otool -l "%{lib}/libc++abi.dylib" | grep --invert-match -e "LC_RPATH"
4147

4248
// Make sure the compatibility_version of libc++abi is 1.0.0. Failure to respect this can result
4349
// in applications not being able to find libc++abi when they are loaded by dyld, if the
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: stdlib=libc++ && target={{.+}}-apple-{{.+}}
10+
11+
// This file checks various properties of the installation of libc++abi when built as
12+
// part of the LLVM releases, on Apple platforms.
13+
14+
// Make sure we install the libc++abi headers in the right location.
15+
//
16+
// RUN: stat "%{include}/cxxabi.h"
17+
18+
// Make sure we install libc++abi.dylib in the right location.
19+
//
20+
// RUN: stat "%{lib}/libc++abi.1.dylib"
21+
22+
// Make sure we install a symlink from libc++abi.dylib to libc++abi.1.dylib.
23+
//
24+
// RUN: stat "%{lib}/libc++abi.dylib"
25+
// RUN: readlink "%{lib}/libc++abi.dylib" | grep "libc++abi.1.dylib"
26+
27+
// Make sure we don't set a RPATH when we build the library. Since we are building a system
28+
// library, we are supposed to find our dependencies at the usual system-provided locations,
29+
// which doesn't require setting a RPATH in the library itself.
30+
//
31+
// RUN: otool -l "%{lib}/libc++abi.dylib" | grep --invert-match -e "LC_RPATH"
32+
33+
// Make sure the compatibility_version of libc++abi is 1.0.0. Failure to respect this can result
34+
// in applications not being able to find libc++abi when they are loaded by dyld, if the
35+
// compatibility version was bumped.
36+
//
37+
// RUN: otool -L "%{lib}/libc++abi.dylib" | grep "libc++abi.1.dylib" | grep "compatibility version 1.0.0"

runtimes/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# This file handles building LLVM runtime sub-projects.
22
cmake_minimum_required(VERSION 3.20.0)
33

4+
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
5+
46
# Add path for custom and the LLVM build's modules to the CMake module path.
57
set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
68
include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake

0 commit comments

Comments
 (0)