[compiler-rt] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 16 13:44:22 PST 2025
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/121819
>From 9f952de3cb3e973f17121c057089a28bf4c6e5e0 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Mon, 6 Jan 2025 11:15:35 -0800
Subject: [PATCH 1/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
=?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6-beta.1
---
libunwind/src/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e7ea57734cca97..72dd3f5bca9960 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,7 +20,7 @@ set(LIBUNWIND_C_SOURCES
)
set_source_files_properties(${LIBUNWIND_C_SOURCES}
PROPERTIES
- COMPILE_FLAGS "-std=c99")
+ COMPILE_FLAGS "-std=c99 -fexceptions")
set(LIBUNWIND_ASM_SOURCES
UnwindRegistersRestore.S
>From 71603241c3e377a5b74c308367f066f3f9e760ae Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Tue, 7 Jan 2025 14:59:24 -0800
Subject: [PATCH 2/5] Update commit message and add comment
Created using spr 1.3.6-beta.1
---
libunwind/src/CMakeLists.txt | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 72dd3f5bca9960..602c99fe237b8e 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,6 +20,11 @@ set(LIBUNWIND_C_SOURCES
)
set_source_files_properties(${LIBUNWIND_C_SOURCES}
PROPERTIES
+ # We need to set `-fexceptions` here so that key
+ # unwinding functions, like
+ # _UNWIND_RaiseExcpetion, are not marked as
+ # `nounwind`, which breaks LTO builds of
+ # libunwind. See #56825 and #120657 for context.
COMPILE_FLAGS "-std=c99 -fexceptions")
set(LIBUNWIND_ASM_SOURCES
>From cc9ecaa7eb4025fb5718dcbc01133f4f53e0a251 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Fri, 10 Jan 2025 12:56:30 -0800
Subject: [PATCH 3/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=20introduced=20through=20rebase?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6-beta.1
[skip ci]
---
.../lib/rtsan/tests/rtsan_test_functional.cpp | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
index ef11b71f167e1b..40c4f3b129129d 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
@@ -145,13 +145,24 @@ TEST(TestRtsan, LaunchingAThreadDiesWhenRealtime) {
namespace {
void InvokeStdFunction(std::function<void()> &&function) { function(); }
+
+template <typename T>
+void HideMemoryFromCompiler(T* memory) {
+ // Pass the pointer to an empty assembly block as an input, and inform
+ // the compiler that memory is read to and possibly modified. This should not
+ // be architecture specific, since the asm block is empty.
+ __asm__ __volatile__("" ::"r"(memory) : "memory");
+}
} // namespace
TEST(TestRtsan, CopyingALambdaWithLargeCaptureDiesWhenRealtime) {
std::array<float, 16> lots_of_data;
auto LargeLambda = [lots_of_data]() mutable {
- // Stop everything getting optimised out
lots_of_data[3] = 0.25f;
+ // In LTO builds, this lambda can be optimized away, since the compiler can
+ // see through the memory accesses after inlining across TUs. Ensure it can
+ // no longer reason about the memory access, so that won't happen.
+ HideMemoryFromCompiler(&lots_of_data[3]);
EXPECT_EQ(16u, lots_of_data.size());
EXPECT_EQ(0.25f, lots_of_data[3]);
};
>From 0a419a5cbb4f2c811726a85f55a4beed00a3fa56 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Fri, 10 Jan 2025 13:04:15 -0800
Subject: [PATCH 4/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=20introduced=20through=20rebase?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6-beta.1
[skip ci]
---
compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
index 40c4f3b129129d..e05d7ae78b5d99 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
@@ -146,8 +146,7 @@ TEST(TestRtsan, LaunchingAThreadDiesWhenRealtime) {
namespace {
void InvokeStdFunction(std::function<void()> &&function) { function(); }
-template <typename T>
-void HideMemoryFromCompiler(T* memory) {
+template <typename T> void HideMemoryFromCompiler(T *memory) {
// Pass the pointer to an empty assembly block as an input, and inform
// the compiler that memory is read to and possibly modified. This should not
// be architecture specific, since the asm block is empty.
>From 6c5b665e10a86ce86812d95d0db01c8c3389b193 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 16 Jan 2025 13:44:12 -0800
Subject: [PATCH 5/5] Update libunwind/src/CMakeLists.txt
Fix typo
Co-authored-by: Petr Hosek <phosek at google.com>
---
libunwind/src/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 602c99fe237b8e..ecbd019bb29ea8 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -22,7 +22,7 @@ set_source_files_properties(${LIBUNWIND_C_SOURCES}
PROPERTIES
# We need to set `-fexceptions` here so that key
# unwinding functions, like
- # _UNWIND_RaiseExcpetion, are not marked as
+ # _UNWIND_RaiseException, are not marked as
# `nounwind`, which breaks LTO builds of
# libunwind. See #56825 and #120657 for context.
COMPILE_FLAGS "-std=c99 -fexceptions")
More information about the llvm-commits
mailing list