[Mlir-commits] [mlir] [mlir][python] declare `_PyClassMethod_New` undefined at link time (PR #121597)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jan 3 12:04:53 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

<details>
<summary>Changes</summary>

`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`

See https://github.com/iree-org/iree/issues/19591#issuecomment-2569591755.

---
Full diff: https://github.com/llvm/llvm-project/pull/121597.diff


1 Files Affected:

- (modified) mlir/cmake/modules/AddMLIRPython.cmake (+6) 


``````````diff
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 9d4e06c7909c81..2bcabab6f9c5e3 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -686,6 +686,12 @@ function(add_mlir_python_extension libname extname)
   endif()
 
   target_compile_options(${libname} PRIVATE ${eh_rtti_enable})
+  if(APPLE)
+    # 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
+    set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-U -Wl,_PyClassMethod_New")
+  endif()
 
   # Configure the output to match python expectations.
   set_target_properties(

``````````

</details>


https://github.com/llvm/llvm-project/pull/121597


More information about the Mlir-commits mailing list