https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/127268
>From a705acfd439e6310648b0ed1ad612eaffc408ad5 Mon Sep 17 00:00:00 2001 From: Tom Stellard <tstel...@redhat.com> Date: Fri, 14 Feb 2025 17:46:25 +0000 Subject: [PATCH 1/8] [CMake][Release] Statically link clang with stage1 runtimes This change will cause clang and the other tools to statically link against the runtimes built in stage1. This will make the built binaries more portable by eliminating dependencies on system libraries like libgcc and libstdc++. --- clang/cmake/caches/Release.cmake | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake index 23e99493087ff..290e186baf6fe 100644 --- a/clang/cmake/caches/Release.cmake +++ b/clang/cmake/caches/Release.cmake @@ -48,10 +48,8 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "") set(STAGE1_PROJECTS "clang") -# Building Flang on Windows requires compiler-rt, so we need to build it in -# stage1. compiler-rt is also required for building the Flang tests on -# macOS. -set(STAGE1_RUNTIMES "compiler-rt") +# Build all runtimes so we can statically link them into the stage2 compiler. +set(STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind") if (LLVM_RELEASE_ENABLE_PGO) list(APPEND STAGE1_PROJECTS "lld") @@ -90,9 +88,18 @@ else() set(CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "") endif() +if (LLVM_RELEASE_ENABLE_LTO) + # Enable LTO for the runtimes. We need to configure stage1 clang to default + # to using lld as the linker because the stage1 toolchain will be used to + # build and link the runtimes. + set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" CACHE STRING "") + set(LLVM_ENABLE_LLD ON CACHE STRING "") +endif() + # Stage 1 Common Config set(LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "") set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "") +set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "") # stage2-instrumented and Final Stage Config: # Options that need to be set in both the instrumented stage (if we are doing @@ -102,6 +109,11 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}" if (LLVM_RELEASE_ENABLE_LTO) set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL) endif() +set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL) +set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL) +set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) +set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) +set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) # Final Stage Config (stage2) set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING) >From c5680225d3fa6ef229b9d7bf8624fb9c81dddb2b Mon Sep 17 00:00:00 2001 From: Tom Stellard <tstel...@redhat.com> Date: Sat, 15 Feb 2025 03:02:07 +0000 Subject: [PATCH 2/8] Fix linker usage --- clang/cmake/caches/Release.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake index 290e186baf6fe..310717ab47889 100644 --- a/clang/cmake/caches/Release.cmake +++ b/clang/cmake/caches/Release.cmake @@ -92,8 +92,7 @@ if (LLVM_RELEASE_ENABLE_LTO) # Enable LTO for the runtimes. We need to configure stage1 clang to default # to using lld as the linker because the stage1 toolchain will be used to # build and link the runtimes. - set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" CACHE STRING "") - set(LLVM_ENABLE_LLD ON CACHE STRING "") + set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DLLVM_ENABLE_LLD=ON" CACHE STRING "") endif() # Stage 1 Common Config >From 88e8ad406c26c6c65a2a6ed51d8b4696a0acf36e Mon Sep 17 00:00:00 2001 From: Tom Stellard <tstel...@redhat.com> Date: Sat, 15 Feb 2025 14:46:20 +0000 Subject: [PATCH 3/8] flang: Fix build with latest libc++ I think this first stopped working with 954836634abb446f18719b14120c386a929a42d1. This patch fixes the following error: /home/runner/work/llvm-project/llvm-project/flang/runtime/io-api-minimal.cpp:153:11: error: '__libcpp_verbose_abort' is missing exception specification 'noexcept' 153 | void std::__libcpp_verbose_abort(char const *format, ...) { | ^ | noexcept /mnt/build/bin/../include/c++/v1/__verbose_abort:30:28: note: previous declaration is here 30 | __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT; | ^ 1 error generated. --- flang/runtime/io-api-minimal.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp index 68768427be0c2..6aefef824a9e9 100644 --- a/flang/runtime/io-api-minimal.cpp +++ b/flang/runtime/io-api-minimal.cpp @@ -150,7 +150,12 @@ bool IODEF(OutputLogical)(Cookie cookie, bool truth) { // Provide own definition for `std::__libcpp_verbose_abort` to avoid dependency // on the version provided by libc++. -void std::__libcpp_verbose_abort(char const *format, ...) { +#if !defined(_LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT) + #define _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT +#endif + + +void std::__libcpp_verbose_abort(char const *format, ...) _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEP { va_list list; va_start(list, format); std::vfprintf(stderr, format, list); >From 92d6389dde4bc58fd0d25e0bac63a9e3b4e942ca Mon Sep 17 00:00:00 2001 From: Tom Stellard <tstel...@redhat.com> Date: Sat, 15 Feb 2025 08:55:07 -0800 Subject: [PATCH 4/8] Fix typo in flang fix --- flang/runtime/io-api-minimal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp index 6aefef824a9e9..24cd559eaa39e 100644 --- a/flang/runtime/io-api-minimal.cpp +++ b/flang/runtime/io-api-minimal.cpp @@ -155,7 +155,7 @@ bool IODEF(OutputLogical)(Cookie cookie, bool truth) { #endif -void std::__libcpp_verbose_abort(char const *format, ...) _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEP { +void std::__libcpp_verbose_abort(char const *format, ...) _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT { va_list list; va_start(list, format); std::vfprintf(stderr, format, list); >From 8ddc8a94028c8171177a8ceb4cc69f0b0f458111 Mon Sep 17 00:00:00 2001 From: Tom Stellard <tstel...@redhat.com> Date: Sat, 15 Feb 2025 08:58:07 -0800 Subject: [PATCH 5/8] Drop -static-libgcc option on Darwin --- clang/cmake/caches/Release.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake index 310717ab47889..c4c3eab7ce961 100644 --- a/clang/cmake/caches/Release.cmake +++ b/clang/cmake/caches/Release.cmake @@ -110,9 +110,14 @@ if (LLVM_RELEASE_ENABLE_LTO) endif() set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL) set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL) -set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) -set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) -set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) +set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind") +if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") + set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc") +endif() + +set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING) +set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING) +set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING) # Final Stage Config (stage2) set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING) >From 9701c52491615cfca7427e02d3b2c916d67ec0d0 Mon Sep 17 00:00:00 2001 From: Tom Stellard <tstel...@redhat.com> Date: Sat, 15 Feb 2025 14:15:10 -0800 Subject: [PATCH 6/8] flang fix --- flang/runtime/io-api-minimal.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp index 24cd559eaa39e..e53089e02d93d 100644 --- a/flang/runtime/io-api-minimal.cpp +++ b/flang/runtime/io-api-minimal.cpp @@ -150,12 +150,12 @@ bool IODEF(OutputLogical)(Cookie cookie, bool truth) { // Provide own definition for `std::__libcpp_verbose_abort` to avoid dependency // on the version provided by libc++. -#if !defined(_LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT) - #define _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT +#if !defined(_LIBCPP_VERBOSE_ABORT_NOEXCEPT) + #define _LIBCPP_VERBOSE_ABORT_NOEXCEPT #endif -void std::__libcpp_verbose_abort(char const *format, ...) _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT { +void std::__libcpp_verbose_abort(char const *format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT { va_list list; va_start(list, format); std::vfprintf(stderr, format, list); >From ff19330b8c071d5ca04c2e4f9ecea07c5d1b4c54 Mon Sep 17 00:00:00 2001 From: Tom Stellard <tstel...@redhat.com> Date: Mon, 17 Feb 2025 22:54:05 +0000 Subject: [PATCH 7/8] Better fix --- flang/runtime/io-api-minimal.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp index e53089e02d93d..107c02c469003 100644 --- a/flang/runtime/io-api-minimal.cpp +++ b/flang/runtime/io-api-minimal.cpp @@ -146,16 +146,8 @@ bool IODEF(OutputLogical)(Cookie cookie, bool truth) { } // namespace Fortran::runtime::io -#if defined(_LIBCPP_VERBOSE_ABORT) -// Provide own definition for `std::__libcpp_verbose_abort` to avoid dependency -// on the version provided by libc++. - -#if !defined(_LIBCPP_VERBOSE_ABORT_NOEXCEPT) - #define _LIBCPP_VERBOSE_ABORT_NOEXCEPT -#endif - - -void std::__libcpp_verbose_abort(char const *format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT { +void std::__libcpp_verbose_abort(char const *format, ...) + noexcept(noexcept(std::__libcpp_verbose_abort(""))) { va_list list; va_start(list, format); std::vfprintf(stderr, format, list); >From cd61d6ef887f5862cc8881ad1f23ebb0e13e9657 Mon Sep 17 00:00:00 2001 From: Tom Stellard <tstel...@redhat.com> Date: Mon, 17 Feb 2025 23:12:38 +0000 Subject: [PATCH 8/8] Fix formatting --- flang-rt/lib/runtime/io-api-minimal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flang-rt/lib/runtime/io-api-minimal.cpp b/flang-rt/lib/runtime/io-api-minimal.cpp index 340903cef6a56..e7490fcd13613 100644 --- a/flang-rt/lib/runtime/io-api-minimal.cpp +++ b/flang-rt/lib/runtime/io-api-minimal.cpp @@ -146,8 +146,8 @@ bool IODEF(OutputLogical)(Cookie cookie, bool truth) { } // namespace Fortran::runtime::io -void std::__libcpp_verbose_abort(char const *format, ...) - noexcept(noexcept(std::__libcpp_verbose_abort(""))) { +void std::__libcpp_verbose_abort(char const *format, ...) noexcept( + noexcept(std::__libcpp_verbose_abort(""))) { va_list list; va_start(list, format); std::vfprintf(stderr, format, list); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits