Repository navigation
[clang][win] Fix __global_delete breaking __attribute__((used)) - #217753
Conversation
The `__empty_global_delete` fallback introduced in llvm#209585 was marked used via `llvm::appendToUsed()`, which creates a global named "llvm.used" during codegen. `CodeGenModule::emitLLVMUsed()` later unconditionally creates its own global of that same name at end-of-TU, so the name collision renamed the latter to "llvm.used.1" -- a name LLVM ignores. The result was that every `__attribute__((used))` global in the TU silently lost its used semantics whenever a `__global_delete` wrapper was emitted, letting those symbols be dropped. Mark the fallback used via `CodeGenModule::addUsedGlobal()` instead, so it joins the single llvm.used that `emitLLVMUsed()` emits. `emitLLVMUsed()` runs well after `emitGlobalDeleteForwardingBodies()` in `Release()`, so the fallback is still recorded in time. Fixes a regression reported on llvm#209585.
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Daniel Paoliello (dpaoliello) ChangesThe Mark the fallback used via Fixes a regression reported on #209585. 2 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d348e80780ee9..8e7bfd336e631 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -9100,7 +9100,7 @@ CodeGenModule::getOrCreateMSVCGlobalDeleteWrapper(const FunctionDecl *GlobOD) {
// uses ::delete that alias is replaced by a real forwarding body, leaving
// the empty otherwise unreferenced, so explicitly mark it used to ensure
// it is always emitted (matching MSVC).
- appendToUsed(M, {EmptyFn});
+ addUsedGlobal(EmptyFn);
}
// The wrapper defaults to a weak alias to the trapping __empty_global_delete
diff --git a/clang/test/CodeGenCXX/msvc-global-delete-llvm-used.cpp b/clang/test/CodeGenCXX/msvc-global-delete-llvm-used.cpp
new file mode 100644
index 0000000000000..07811b0f8eecc
--- /dev/null
+++ b/clang/test/CodeGenCXX/msvc-global-delete-llvm-used.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -emit-llvm -fms-extensions %s -triple=x86_64-pc-windows-msvc -o - \
+// RUN: | FileCheck %s --implicit-check-not="@llvm.used.1"
+
+// The __empty_global_delete fallback is marked used so it is always emitted.
+// It must join the single llvm.used that CodeGenModule emits at end-of-TU: if
+// it creates its own llvm.used first, the one holding __attribute__((used))
+// globals gets renamed to llvm.used.1, which LLVM ignores.
+
+struct S { virtual ~S(); };
+S::~S() {}
+void del(S *s) { ::delete s; }
+
+__attribute__((used)) static void keep_me() {}
+
+// CHECK: @llvm.used = appending global
+// CHECK-SAME: @"?__empty_global_delete@@YAXPEAX_K@Z"
+// CHECK-SAME: @"?keep_me@@YAXXZ"
|
|
/cherry-pick 061865f |
Error: Command failed due to missing milestone. |
|
/cherry-pick 061865f |
|
/pull-request #218040 |
…#217753) The `__empty_global_delete` fallback introduced in llvm#209585 was marked used via `llvm::appendToUsed()`, which creates a global named "llvm.used" during codegen. `CodeGenModule::emitLLVMUsed()` later unconditionally creates its own global of that same name at end-of-TU, so the name collision renamed the latter to "llvm.used.1" -- a name LLVM ignores. The result was that every `__attribute__((used))` global in the TU silently lost its used semantics whenever a `__global_delete` wrapper was emitted, letting those symbols be dropped. Mark the fallback used via `CodeGenModule::addUsedGlobal()` instead, so it joins the single llvm.used that `emitLLVMUsed()` emits. `emitLLVMUsed()` runs well after `emitGlobalDeleteForwardingBodies()` in `Release()`, so the fallback is still recorded in time. Fixes a regression reported on llvm#209585. (cherry picked from commit 061865f)
This contains a fix for a prior CL that provides an alternate solution to the linked bug (returning to our prior behavior). The behavior change will happen in a followup CL, this just updates the package. We also remove an old cherry-pick from last year that was a no-op. Bug: 542981236 Change-Id: I3c5f32fe49479df8f6b5b3fc99bce2572509b536 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8280057 Commit-Queue: Devon Loehr <[email protected]> Reviewed-by: Nico Weber <[email protected]> Commit-Queue: Nico Weber <[email protected]> Cr-Commit-Position: refs/heads/main@{#1688204}
This contains a fix for a prior CL that provides an alternate solution to the linked bug (returning to our prior behavior). The behavior change will happen in a followup CL, this just updates the package. We also remove an old cherry-pick from last year that was a no-op. Bug: 542981236 Change-Id: I3c5f32fe49479df8f6b5b3fc99bce2572509b536 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8280057 Commit-Queue: Devon Loehr <[email protected]> Reviewed-by: Nico Weber <[email protected]> Commit-Queue: Nico Weber <[email protected]> Cr-Commit-Position: refs/heads/main@{#1688204}
The
__empty_global_deletefallback introduced in #209585 was marked used viallvm::appendToUsed(), which creates a global named "llvm.used" during codegen.CodeGenModule::emitLLVMUsed()later unconditionally creates its own global of that same name at end-of-TU, so the name collision renamed the latter to "llvm.used.1" -- a name LLVM ignores. The result was that every__attribute__((used))global in the TU silently lost its used semantics whenever a__global_deletewrapper was emitted, letting those symbols be dropped.Mark the fallback used via
CodeGenModule::addUsedGlobal()instead, so it joins the single llvm.used thatemitLLVMUsed()emits.emitLLVMUsed()runs well afteremitGlobalDeleteForwardingBodies()inRelease(), so the fallback is still recorded in time.Fixes a regression reported on #209585.