[llvm] [ORC] Define `LLVM_HAS_ATTRIBUTE_WEAK` and guard `__unw_*_dynamic_eh_frame_section` by it (PR #227709)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 03:27:22 PDT 2026
https://github.com/lhames updated https://github.com/llvm/llvm-project/pull/227709
>From 7d7a4cc1e9eb082eabfd2918bebc9d4b540e26dd Mon Sep 17 00:00:00 2001
From: kikairoya <kikairoya at gmail.com>
Date: Wed, 30 Sep 2026 20:56:31 +0900
Subject: [PATCH 1/2] [ORC] Disable __unw_add_dynamic_eh_frame_section on
Cygwin
Causes a link error by #212260:
```
ld.lld: error: undefined symbol: __unw_add_dynamic_eh_frame_section
>>> referenced by libLLVMOrcTargetProcess.a(RegisterEHFrames.cpp.o):(llvm::orc::registerEHFrameSection(void const*, unsigned long))
>>> referenced by libLLVMOrcTargetProcess.a(RegisterEHFrames.cpp.o):(registerEHFrameWrapper(llvm::orc::ExecutorAddrRange))
```
---
.../ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
index b64f7664f80f3..e261b3f001ab1 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
@@ -22,7 +22,7 @@ using namespace llvm::orc::shared;
namespace llvm {
namespace orc {
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__CYGWIN__)
extern "C" void
__unw_add_dynamic_eh_frame_section(const void *) LLVM_ATTRIBUTE_WEAK;
extern "C" void
@@ -130,7 +130,7 @@ Error walkLibunwindEHFrameSection(const char *const SectionStart,
Error registerEHFrameSection(const void *EHFrameSectionAddr,
size_t EHFrameSectionSize) {
// For libunwind after D111863.
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__CYGWIN__)
if (__unw_add_dynamic_eh_frame_section &&
__unw_remove_dynamic_eh_frame_section) {
__unw_add_dynamic_eh_frame_section(EHFrameSectionAddr);
@@ -157,7 +157,7 @@ Error registerEHFrameSection(const void *EHFrameSectionAddr,
Error deregisterEHFrameSection(const void *EHFrameSectionAddr,
size_t EHFrameSectionSize) {
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__CYGWIN__)
if (__unw_add_dynamic_eh_frame_section &&
__unw_remove_dynamic_eh_frame_section) {
__unw_remove_dynamic_eh_frame_section(EHFrameSectionAddr);
>From de75bf10bae674a69f1a8e4b6ea5a95fd750d2f6 Mon Sep 17 00:00:00 2001
From: kikairoya <kikairoya at gmail.com>
Date: Wed, 30 Sep 2026 23:00:20 +0900
Subject: [PATCH 2/2] define LLVM_HAS_ATTRIBUTE_WEAK and use it
---
llvm/include/llvm/Support/Compiler.h | 5 +++++
.../Orc/TargetProcess/RegisterEHFrames.cpp | 8 +++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 33ea019a87be5..d8a13a261b77a 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -309,6 +309,11 @@
// FIXME: Provide this for PE/COFF targets.
#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
!defined(_WIN32)
+#define LLVM_HAS_ATTRIBUTE_WEAK 1
+#else
+#define LLVM_HAS_ATTRIBUTE_WEAK 0
+#endif
+#if LLVM_HAS_ATTRIBUTE_WEAK
#define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
#else
#define LLVM_ATTRIBUTE_WEAK
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
index e261b3f001ab1..01b5f67f8f04d 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
@@ -22,7 +22,9 @@ using namespace llvm::orc::shared;
namespace llvm {
namespace orc {
-#if !defined(_WIN32) && !defined(__CYGWIN__)
+// Reference __unw_* only if __attribute__((weak)) is available to avoid force
+// pulling them.
+#if LLVM_HAS_ATTRIBUTE_WEAK
extern "C" void
__unw_add_dynamic_eh_frame_section(const void *) LLVM_ATTRIBUTE_WEAK;
extern "C" void
@@ -130,7 +132,7 @@ Error walkLibunwindEHFrameSection(const char *const SectionStart,
Error registerEHFrameSection(const void *EHFrameSectionAddr,
size_t EHFrameSectionSize) {
// For libunwind after D111863.
-#if !defined(_WIN32) && !defined(__CYGWIN__)
+#if LLVM_HAS_ATTRIBUTE_WEAK
if (__unw_add_dynamic_eh_frame_section &&
__unw_remove_dynamic_eh_frame_section) {
__unw_add_dynamic_eh_frame_section(EHFrameSectionAddr);
@@ -157,7 +159,7 @@ Error registerEHFrameSection(const void *EHFrameSectionAddr,
Error deregisterEHFrameSection(const void *EHFrameSectionAddr,
size_t EHFrameSectionSize) {
-#if !defined(_WIN32) && !defined(__CYGWIN__)
+#if LLVM_HAS_ATTRIBUTE_WEAK
if (__unw_add_dynamic_eh_frame_section &&
__unw_remove_dynamic_eh_frame_section) {
__unw_remove_dynamic_eh_frame_section(EHFrameSectionAddr);
More information about the llvm-commits
mailing list