From f6c1590f9513ecab8fe0ea6db8b5367513ce95a1 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Thu, 26 Sep 2024 17:09:32 -0400 Subject: [PATCH 1/2] [libc++abi][libunwind] Run c++abi and unwind tests against a fake install root This is what we started doing in libc++ and it straightens up a lot of things that only happened to work before, notably the presence of relative rpaths in dylibs when running from the build tree. This unlocks the ability to link against a just-built dylib but run against another version of the dylib (for example the system-provided one), which is necessary for proper backdeployment testing. This patch adds a lot of code duplication between the libc++ and libc++abi testing setups. However, there is already a large amount of duplication and the only real way to get rid of it is to merge libc++abi into libc++. In a way, this patch is a step in that direction because it closes the gap between the two libraries' testing setup. --- .../configs/llvm-libc++-shared-mingw.cfg.in | 2 +- .../configs/llvm-libc++-static-mingw.cfg.in | 2 +- libcxxabi/CMakeLists.txt | 6 ++- libcxxabi/src/CMakeLists.txt | 1 - libcxxabi/test/CMakeLists.txt | 51 +++++++++++++++++++ libcxxabi/test/configs/cmake-bridge.cfg.in | 9 ++-- .../llvm-libc++abi-shared-mingw.cfg.in | 25 +++++++++ ....in => llvm-libc++abi-static-mingw.cfg.in} | 2 +- libunwind/CMakeLists.txt | 6 ++- libunwind/test/CMakeLists.txt | 16 +++++- libunwind/test/configs/cmake-bridge.cfg.in | 5 +- .../llvm-libunwind-shared-mingw.cfg.in | 25 +++++++++ ....in => llvm-libunwind-static-mingw.cfg.in} | 2 +- 13 files changed, 138 insertions(+), 14 deletions(-) create mode 100644 libcxxabi/test/configs/llvm-libc++abi-shared-mingw.cfg.in rename libcxxabi/test/configs/{llvm-libc++abi-mingw.cfg.in => llvm-libc++abi-static-mingw.cfg.in} (92%) create mode 100644 libunwind/test/configs/llvm-libunwind-shared-mingw.cfg.in rename libunwind/test/configs/{llvm-libunwind-mingw.cfg.in => llvm-libunwind-static-mingw.cfg.in} (91%) diff --git a/libcxx/test/configs/llvm-libc++-shared-mingw.cfg.in b/libcxx/test/configs/llvm-libc++-shared-mingw.cfg.in index 01c4d58ca05f96..8868f0cadd2aa2 100644 --- a/libcxx/test/configs/llvm-libc++-shared-mingw.cfg.in +++ b/libcxx/test/configs/llvm-libc++-shared-mingw.cfg.in @@ -1,5 +1,5 @@ # This testing configuration handles running the test suite against LLVM's libc++ -# using either a DLL or a static library, with MinGW/Clang on Windows. +# using a DLL with MinGW/Clang on Windows. lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') diff --git a/libcxx/test/configs/llvm-libc++-static-mingw.cfg.in b/libcxx/test/configs/llvm-libc++-static-mingw.cfg.in index 650b60c6536a9f..fb2f9065898a54 100644 --- a/libcxx/test/configs/llvm-libc++-static-mingw.cfg.in +++ b/libcxx/test/configs/llvm-libc++-static-mingw.cfg.in @@ -1,5 +1,5 @@ # This testing configuration handles running the test suite against LLVM's libc++ -# using either a DLL or a static library, with MinGW/Clang on Windows. +# using a static library with MinGW/Clang on Windows. lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index 43400c6e8d9af1..edf3258c8f20e1 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -144,7 +144,11 @@ option(LIBCXXABI_HERMETIC_STATIC_LIBRARY "Do not export any symbols from the static library." ${LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT}) if(MINGW) - set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-mingw.cfg.in") + if (LIBCXXABI_ENABLE_SHARED) + set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared-mingw.cfg.in") + else() + set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-static-mingw.cfg.in") + endif() elseif(WIN32) # clang-cl if (LIBCXXABI_ENABLE_SHARED) set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared-clangcl.cfg.in") diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt index c1a7bcb14eb199..e8c459d1c9cae6 100644 --- a/libcxxabi/src/CMakeLists.txt +++ b/libcxxabi/src/CMakeLists.txt @@ -306,7 +306,6 @@ endif() # Add a meta-target for both libraries. add_custom_target(cxxabi DEPENDS ${LIBCXXABI_BUILD_TARGETS}) -add_dependencies(cxxabi-test-depends cxxabi cxx) if (LIBCXXABI_INSTALL_LIBRARY) install(TARGETS ${LIBCXXABI_INSTALL_TARGETS} diff --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt index 8e3048f2ffe8a1..9eabfb08240b60 100644 --- a/libcxxabi/test/CMakeLists.txt +++ b/libcxxabi/test/CMakeLists.txt @@ -8,6 +8,57 @@ macro(pythonize_bool var) endif() endmacro() +set(LIBCXXABI_TESTING_INSTALL_PREFIX "${LIBCXXABI_BINARY_DIR}/test-suite-install") +add_custom_target(libcxxabi-install-cxx-for-testing + DEPENDS cxx-headers + cxx + cxx_experimental + cxx-modules + COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXXABI_TESTING_INSTALL_PREFIX}" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxx-headers + -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxx-modules + -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxx + -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") +add_dependencies(cxxabi-test-depends libcxxabi-install-cxx-for-testing) + +add_custom_target(libcxxabi-install-cxxabi-for-testing + DEPENDS cxxabi-headers + cxxabi + COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXXABI_TESTING_INSTALL_PREFIX}" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxxabi-headers + -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxxabi + -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") +add_dependencies(cxxabi-test-depends libcxxabi-install-cxxabi-for-testing) + +if (LIBCXXABI_USE_LLVM_UNWINDER AND TARGET unwind) + add_custom_target(libcxxabi-install-unwind-for-testing + DEPENDS unwind-headers + unwind + COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXXABI_TESTING_INSTALL_PREFIX}" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=unwind-headers + -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=unwind + -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + add_dependencies(cxxabi-test-depends libcxxabi-install-unwind-for-testing) +endif() + pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER) set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not edit!") diff --git a/libcxxabi/test/configs/cmake-bridge.cfg.in b/libcxxabi/test/configs/cmake-bridge.cfg.in index 3fefc6a7fdc88a..b00eb642750c9b 100644 --- a/libcxxabi/test/configs/cmake-bridge.cfg.in +++ b/libcxxabi/test/configs/cmake-bridge.cfg.in @@ -27,10 +27,11 @@ config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test') config.host_triple = '@LLVM_HOST_TRIPLE@' config.substitutions.append(('%{libcxx}', '@LIBCXXABI_LIBCXX_PATH@')) -config.substitutions.append(('%{include}', '@LIBCXXABI_SOURCE_DIR@/include')) -config.substitutions.append(('%{cxx-include}', '@LIBCXXABI_HEADER_DIR@/include/c++/v1')) -config.substitutions.append(('%{cxx-target-include}', '@LIBCXXABI_HEADER_DIR@/include/%{triple}/c++/v1')) -config.substitutions.append(('%{lib}', '@LIBCXXABI_LIBRARY_DIR@')) +config.substitutions.append(('%{install-prefix}', '@LIBCXXABI_TESTING_INSTALL_PREFIX@')) +config.substitutions.append(('%{include}', '@LIBCXXABI_TESTING_INSTALL_PREFIX@/include')) +config.substitutions.append(('%{cxx-include}', '@LIBCXXABI_TESTING_INSTALL_PREFIX@/@LIBCXXABI_INSTALL_INCLUDE_DIR@')) +config.substitutions.append(('%{cxx-target-include}', '@LIBCXXABI_TESTING_INSTALL_PREFIX@/include/%{triple}/c++/v1')) +config.substitutions.append(('%{lib}', '@LIBCXXABI_TESTING_INSTALL_PREFIX@/@LIBCXXABI_INSTALL_LIBRARY_DIR@')) if @LIBCXXABI_USE_LLVM_UNWINDER@: config.substitutions.append(('%{maybe-include-libunwind}', '-I "@LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL@"')) diff --git a/libcxxabi/test/configs/llvm-libc++abi-shared-mingw.cfg.in b/libcxxabi/test/configs/llvm-libc++abi-shared-mingw.cfg.in new file mode 100644 index 00000000000000..1ce3082a604230 --- /dev/null +++ b/libcxxabi/test/configs/llvm-libc++abi-shared-mingw.cfg.in @@ -0,0 +1,25 @@ +# This testing configuration handles running the test suite against LLVM's libc++abi +# using a DLL with MinGW/Clang on Windows. + +lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') + +config.substitutions.append(('%{flags}', '')) +config.substitutions.append(('%{compile_flags}', + '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS' +)) +config.substitutions.append(('%{link_flags}', + '-nostdlib++ -L %{lib} -lc++' +)) +config.substitutions.append(('%{exec}', + '%{executor} --execdir %T --prepend_env PATH=%{install-prefix}/bin -- ' +)) + +import os, site +site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils')) +import libcxx.test.params, libcxx.test.config +libcxx.test.config.configure( + libcxx.test.params.DEFAULT_PARAMETERS, + libcxx.test.features.DEFAULT_FEATURES, + config, + lit_config +) diff --git a/libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in b/libcxxabi/test/configs/llvm-libc++abi-static-mingw.cfg.in similarity index 92% rename from libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in rename to libcxxabi/test/configs/llvm-libc++abi-static-mingw.cfg.in index 1e9f202e8dd8a0..8b882976846fa8 100644 --- a/libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in +++ b/libcxxabi/test/configs/llvm-libc++abi-static-mingw.cfg.in @@ -1,5 +1,5 @@ # This testing configuration handles running the test suite against LLVM's libc++abi -# using either a DLL or a static library, with MinGW/Clang on Windows. +# using a static library with MinGW/Clang on Windows. lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index bc57057a705297..b911f482fc26b2 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -68,7 +68,11 @@ set(LIBUNWIND_LIBRARY_VERSION "1.0" CACHE STRING this also controls the linker's 'current_version' property.") if(MINGW) - set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-mingw.cfg.in") + if (LIBUNWIND_ENABLE_SHARED) + set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared-mingw.cfg.in") + else() + set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static-mingw.cfg.in") + endif() elseif (LIBUNWIND_ENABLE_SHARED) set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in") else() diff --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt index c7b1b3d01d8c7d..c222c0bdbf5af1 100644 --- a/libunwind/test/CMakeLists.txt +++ b/libunwind/test/CMakeLists.txt @@ -8,6 +8,20 @@ macro(pythonize_bool var) endif() endmacro() +set(LIBUNWIND_TESTING_INSTALL_PREFIX "${LIBUNWIND_BINARY_DIR}/test-suite-install") +add_custom_target(libunwind-install-unwind-for-testing + DEPENDS unwind-headers + unwind + COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBUNWIND_TESTING_INSTALL_PREFIX}" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=unwind-headers + -DCMAKE_INSTALL_PREFIX="${LIBUNWIND_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=unwind + -DCMAKE_INSTALL_PREFIX="${LIBUNWIND_TESTING_INSTALL_PREFIX}" + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + pythonize_bool(LIBUNWIND_ENABLE_CET) pythonize_bool(LIBUNWIND_ENABLE_GCS) pythonize_bool(LIBUNWIND_ENABLE_THREADS) @@ -48,4 +62,4 @@ configure_lit_site_cfg( add_lit_testsuite(check-unwind "Running libunwind tests" ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS unwind) + DEPENDS libunwind-install-unwind-for-testing) diff --git a/libunwind/test/configs/cmake-bridge.cfg.in b/libunwind/test/configs/cmake-bridge.cfg.in index 7fc7a3da424629..bd7122bbea32c4 100644 --- a/libunwind/test/configs/cmake-bridge.cfg.in +++ b/libunwind/test/configs/cmake-bridge.cfg.in @@ -29,5 +29,6 @@ if not @LIBUNWIND_ENABLE_THREADS@: config.available_features.add('libunwind-no-threads') # Add substitutions for bootstrapping the test suite configuration -config.substitutions.append(('%{include}', '@LIBUNWIND_SOURCE_DIR@/include')) -config.substitutions.append(('%{lib}', '@LIBUNWIND_LIBRARY_DIR@')) +config.substitutions.append(('%{install-prefix}', '@LIBUNWIND_TESTING_INSTALL_PREFIX@')) +config.substitutions.append(('%{include}', '@LIBUNWIND_TESTING_INSTALL_PREFIX@/include')) +config.substitutions.append(('%{lib}', '@LIBUNWIND_TESTING_INSTALL_PREFIX@/lib')) diff --git a/libunwind/test/configs/llvm-libunwind-shared-mingw.cfg.in b/libunwind/test/configs/llvm-libunwind-shared-mingw.cfg.in new file mode 100644 index 00000000000000..b29d83fbab3053 --- /dev/null +++ b/libunwind/test/configs/llvm-libunwind-shared-mingw.cfg.in @@ -0,0 +1,25 @@ +# This testing configuration handles running the test suite against LLVM's libunwind +# using a DLL with MinGW/Clang on Windows. + +lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') + +config.substitutions.append(('%{flags}', '')) +config.substitutions.append(('%{compile_flags}', + '-nostdinc++ -I %{include} -funwind-tables' +)) +config.substitutions.append(('%{link_flags}', + '-L %{lib} -lunwind' +)) +config.substitutions.append(('%{exec}', + '%{executor} --execdir %T --prepend_env PATH=%{install-prefix}/bin -- ' +)) + +import os, site +site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) +import libcxx.test.params, libcxx.test.config +libcxx.test.config.configure( + libcxx.test.params.DEFAULT_PARAMETERS, + libcxx.test.features.DEFAULT_FEATURES, + config, + lit_config +) diff --git a/libunwind/test/configs/llvm-libunwind-mingw.cfg.in b/libunwind/test/configs/llvm-libunwind-static-mingw.cfg.in similarity index 91% rename from libunwind/test/configs/llvm-libunwind-mingw.cfg.in rename to libunwind/test/configs/llvm-libunwind-static-mingw.cfg.in index 33d061a3efc6fc..437c53bea2f06b 100644 --- a/libunwind/test/configs/llvm-libunwind-mingw.cfg.in +++ b/libunwind/test/configs/llvm-libunwind-static-mingw.cfg.in @@ -1,5 +1,5 @@ # This testing configuration handles running the test suite against LLVM's libunwind -# using either a DLL or a static library, with MinGW/Clang on Windows. +# using a static library with MinGW/Clang on Windows. lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') From ea4ed6ef00fa75731cca6bc5900b077361b68113 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Fri, 27 Sep 2024 15:45:10 -0400 Subject: [PATCH 2/2] libc++abi is always statically linked into libc++ on Mingw --- libcxxabi/CMakeLists.txt | 6 +---- ...ngw.cfg.in => llvm-libc++abi-mingw.cfg.in} | 2 +- .../llvm-libc++abi-static-mingw.cfg.in | 25 ------------------- 3 files changed, 2 insertions(+), 31 deletions(-) rename libcxxabi/test/configs/{llvm-libc++abi-shared-mingw.cfg.in => llvm-libc++abi-mingw.cfg.in} (92%) delete mode 100644 libcxxabi/test/configs/llvm-libc++abi-static-mingw.cfg.in diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index edf3258c8f20e1..43400c6e8d9af1 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -144,11 +144,7 @@ option(LIBCXXABI_HERMETIC_STATIC_LIBRARY "Do not export any symbols from the static library." ${LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT}) if(MINGW) - if (LIBCXXABI_ENABLE_SHARED) - set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared-mingw.cfg.in") - else() - set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-static-mingw.cfg.in") - endif() + set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-mingw.cfg.in") elseif(WIN32) # clang-cl if (LIBCXXABI_ENABLE_SHARED) set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared-clangcl.cfg.in") diff --git a/libcxxabi/test/configs/llvm-libc++abi-shared-mingw.cfg.in b/libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in similarity index 92% rename from libcxxabi/test/configs/llvm-libc++abi-shared-mingw.cfg.in rename to libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in index 1ce3082a604230..0d8b7bdcb1d089 100644 --- a/libcxxabi/test/configs/llvm-libc++abi-shared-mingw.cfg.in +++ b/libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in @@ -1,5 +1,5 @@ # This testing configuration handles running the test suite against LLVM's libc++abi -# using a DLL with MinGW/Clang on Windows. +# using a static library merged into libc++ with MinGW/Clang on Windows. lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') diff --git a/libcxxabi/test/configs/llvm-libc++abi-static-mingw.cfg.in b/libcxxabi/test/configs/llvm-libc++abi-static-mingw.cfg.in deleted file mode 100644 index 8b882976846fa8..00000000000000 --- a/libcxxabi/test/configs/llvm-libc++abi-static-mingw.cfg.in +++ /dev/null @@ -1,25 +0,0 @@ -# This testing configuration handles running the test suite against LLVM's libc++abi -# using a static library with MinGW/Clang on Windows. - -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -config.substitutions.append(('%{flags}', '')) -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS' -)) -config.substitutions.append(('%{link_flags}', - '-nostdlib++ -L %{lib} -lc++' -)) -config.substitutions.append(('%{exec}', - '%{executor} --execdir %T --prepend_env PATH=%{lib} -- ' -)) - -import os, site -site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -)