[Mlir-commits] [mlir] [mlir][python] handle more undefined symbols not covered by nanobind (PR #153861)

Maksim Levental llvmlistbot at llvm.org
Fri Aug 15 15:17:19 PDT 2025


https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/153861

>From 632c7a7116e1789435d0fa364f2d66a2c40ab05d Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Fri, 15 Aug 2025 15:42:22 -0400
Subject: [PATCH] [mlir][python] handle more undefined symbols not covered by
 pybind and fix warning unused

Introduced (but omitted from this CMake) in https://github.com/llvm/llvm-project/pull/151246.
---
 mlir/cmake/modules/AddMLIRPython.cmake | 7 ++++++-
 mlir/lib/Bindings/Python/IRCore.cpp    | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index c14e614ed7d92..2b883558d33c6 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -704,7 +704,12 @@ function(add_mlir_python_extension libname extname)
       # NanobindAdaptors.h uses PyClassMethod_New to build `pure_subclass`es but nanobind
       # doesn't declare this API as undefined in its linker flags. So we need to declare it as such
       # for downstream users that do not do something like `-undefined dynamic_lookup`.
-      target_link_options(${libname} PUBLIC "LINKER:-U,_PyClassMethod_New")
+      # Same for the rest.
+      target_link_options(${libname} PUBLIC
+        "LINKER:-U,_PyClassMethod_New"
+        "LINKER:-U,_PyCode_Addr2Location"
+        "LINKER:-U,_PyFrame_GetLasti"
+      )
     endif()
   endif()
 
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index 390cdc5429beb..4b3a06cbce854 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -2810,7 +2810,7 @@ class PyOpAttributeMap {
 
 // bpo-42262 added Py_XNewRef()
 #if !defined(Py_XNewRef)
-PyObject *_Py_XNewRef(PyObject *obj) {
+[[maybe_unused]] PyObject *_Py_XNewRef(PyObject *obj) {
   Py_XINCREF(obj);
   return obj;
 }
@@ -2819,7 +2819,7 @@ PyObject *_Py_XNewRef(PyObject *obj) {
 
 // bpo-42262 added Py_NewRef()
 #if !defined(Py_NewRef)
-PyObject *_Py_NewRef(PyObject *obj) {
+[[maybe_unused]] PyObject *_Py_NewRef(PyObject *obj) {
   Py_INCREF(obj);
   return obj;
 }



More information about the Mlir-commits mailing list