[llvm] [llvm] Allow Rust personality name to contain arbitrary prefix (PR #166095)

via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 2 12:28:46 PST 2025


https://github.com/Noratrieb created https://github.com/llvm/llvm-project/pull/166095

LLVM needs to figure out the type of EH personality for various reasons. To do this, it currently matches against a hardcoded list of names. In Rust, we would like to mangle our personality function to better support linking multiple Rust standard libraries via staticlib. We have currently mangled all symbols except the personality, which remains unmangled because of this LLVM hardcoding.

Instead, this now does a suffix match of the personality name, which will work with the mangling scheme used for these internal symbols (e.g. `_RNvCseCSg29WUqSe_7___rustc12___rust_alloc`).

>From 010f0e0b7dcad52942d16a8dc19549247574f36f Mon Sep 17 00:00:00 2001
From: Noratrieb <48135649+Noratrieb at users.noreply.github.com>
Date: Sun, 2 Nov 2025 20:00:50 +0100
Subject: [PATCH] [llvm] Allow Rust personality name to contain arbitrary
 prefix

LLVM needs to figure out the type of EH personality for various reasons.
To do this, it currently matches against a hardcoded list of names. In
Rust, we would like to mangle our personality function to better support
linking multiple Rust standard libraries via staticlib. We have
currently mangled all symbols except the personality, which remains
unmangled because of this LLVM hardcoding.

Instead, this now does a suffix match of the personality name, which
will work with the mangling scheme used for these internal symbols
(e.g. `_RNvCseCSg29WUqSe_7___rustc12___rust_alloc`).
---
 llvm/lib/IR/EHPersonalities.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/IR/EHPersonalities.cpp b/llvm/lib/IR/EHPersonalities.cpp
index 9297a82e7d2b0..12ae4748e1f4a 100644
--- a/llvm/lib/IR/EHPersonalities.cpp
+++ b/llvm/lib/IR/EHPersonalities.cpp
@@ -47,7 +47,8 @@ EHPersonality llvm::classifyEHPersonality(const Value *Pers) {
       .Case("__C_specific_handler", EHPersonality::MSVC_TableSEH)
       .Case("__CxxFrameHandler3", EHPersonality::MSVC_CXX)
       .Case("ProcessCLRException", EHPersonality::CoreCLR)
-      .Case("rust_eh_personality", EHPersonality::Rust)
+      // Rust mangles its personality function, so we can't test exact equality.
+      .EndsWith("rust_eh_personality", EHPersonality::Rust)
       .Case("__gxx_wasm_personality_v0", EHPersonality::Wasm_CXX)
       .Case("__xlcxx_personality_v1", EHPersonality::XL_CXX)
       .Case("__zos_cxx_personality_v2", EHPersonality::ZOS_CXX)
@@ -77,7 +78,8 @@ StringRef llvm::getEHPersonalityName(EHPersonality Pers) {
   case EHPersonality::CoreCLR:
     return "ProcessCLRException";
   case EHPersonality::Rust:
-    return "rust_eh_personality";
+    llvm_unreachable(
+        "Cannot get personality name of Rust personality, since it is mangled");
   case EHPersonality::Wasm_CXX:
     return "__gxx_wasm_personality_v0";
   case EHPersonality::XL_CXX:



More information about the llvm-commits mailing list