[llvm] [Orc] Strip weak in assertion for requested symbol flags (PR #151514)

Stefan Gränitz via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 06:15:05 PDT 2025


https://github.com/weliveindetail created https://github.com/llvm/llvm-project/pull/151514

I recently ran into this assertion, reduced my repro and came up with this quick-fix. The case for common symbols looks similar, so for the moment I didn't spend more time investigating. Should we take it like this?

>From 77ffafa07265d97b6e57aa6107f0e13d0d659c92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Thu, 31 Jul 2025 14:47:13 +0200
Subject: [PATCH 1/2] [Orc] Test comdat any fails asserts: Resolving symbol
 with incorrect flags

---
 llvm/test/ExecutionEngine/Orc/comdat-any.ll | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 llvm/test/ExecutionEngine/Orc/comdat-any.ll

diff --git a/llvm/test/ExecutionEngine/Orc/comdat-any.ll b/llvm/test/ExecutionEngine/Orc/comdat-any.ll
new file mode 100644
index 0000000000000..61bf94f4da57a
--- /dev/null
+++ b/llvm/test/ExecutionEngine/Orc/comdat-any.ll
@@ -0,0 +1,21 @@
+; MachO doesn't support COMDATs
+; UNSUPPORTED: system-darwin
+;
+; Works with MCJIT:
+; RUN: lli --jit-kind=mcjit %s
+;
+; Fails assertion in ORC: Resolving symbol with incorrect flags
+; RUN: lli --jit-kind=orc %s
+
+$f = comdat any
+
+define i32 @f() comdat {
+entry:
+  ret i32 0
+}
+
+define i32 @main() {
+entry:
+  %0 = call i32 @f()
+  ret i32 %0
+}

>From af2c3838ec6f75158d1a62f202b1858eb57dd62d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Wed, 30 Jul 2025 14:51:35 +0200
Subject: [PATCH 2/2] [Orc] Fix asserts: strip weak in requested symbol flags

---
 llvm/lib/ExecutionEngine/Orc/Core.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp
index f47b7ecdcc7bb..1d67d1e1da9b4 100644
--- a/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -923,7 +923,8 @@ Error JITDylib::resolve(MaterializationResponsibility &MR,
                      "Resolving symbol with incorrect flags");
 
             } else
-              assert(KV.second.getFlags() == SymI->second.getFlags() &&
+              assert(KV.second.getFlags() ==
+                         (SymI->second.getFlags() & ~JITSymbolFlags::Weak) &&
                      "Resolved flags should match the declared flags");
 
             Worklist.push_back(
@@ -2909,7 +2910,7 @@ Error ExecutionSession::OL_notifyResolved(MaterializationResponsibility &MR,
                  (I->second & ~JITSymbolFlags::Common) &&
              "Resolving symbol with incorrect flags");
     } else
-      assert(KV.second.getFlags() == I->second &&
+      assert(KV.second.getFlags() == (I->second & ~JITSymbolFlags::Weak) &&
              "Resolving symbol with incorrect flags");
   }
 #endif



More information about the llvm-commits mailing list