Skip to content

[mlir][python] declare _PyClassMethod_New undefined at link time #121597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 3, 2025

Conversation

makslevental
Copy link
Contributor

@makslevental makslevental commented Jan 3, 2025

NanobindAdaptors.h uses PyClassMethod_New to build pure_subclasses 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 iree-org/iree#19591 (comment).

@llvmbot llvmbot added the mlir label Jan 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 3, 2025

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

NanobindAdaptors.h uses PyClassMethod_New to build pure_subclasses 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 iree-org/iree#19591 (comment).


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

1 Files Affected:

  • (modified) mlir/cmake/modules/AddMLIRPython.cmake (+6)
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(

@makslevental makslevental merged commit 78f0447 into main Jan 3, 2025
8 checks passed
@makslevental makslevental deleted the users/makslevental/fix-apple-nanobind branch January 3, 2025 21:52
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 4, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve-vls running on linaro-g3-01 while building mlir at step 7 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/4553

Here is the relevant piece of the build log for the reference
Step 7 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'MLIR :: Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 21
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-opt /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir --sparsifier="enable-runtime-library=true" | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-cpu-runner -e main -entry-point-result=void -shared-libs=/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_c_runner_utils.so,/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_runner_utils.so | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-opt /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir --sparsifier=enable-runtime-library=true
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-cpu-runner -e main -entry-point-result=void -shared-libs=/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_c_runner_utils.so,/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_runner_utils.so
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# RUN: at line 25
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-opt /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir --sparsifier="enable-runtime-library=false" | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-cpu-runner -e main -entry-point-result=void -shared-libs=/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_c_runner_utils.so,/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_runner_utils.so | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-opt /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir --sparsifier=enable-runtime-library=false
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-cpu-runner -e main -entry-point-result=void -shared-libs=/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_c_runner_utils.so,/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_runner_utils.so
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# RUN: at line 29
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-opt /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir --sparsifier="enable-runtime-library=false vl=2 reassociate-fp-reductions=true enable-index-optimizations=true" | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-cpu-runner -e main -entry-point-result=void -shared-libs=/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_c_runner_utils.so,/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_runner_utils.so | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-opt /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir '--sparsifier=enable-runtime-library=false vl=2 reassociate-fp-reductions=true enable-index-optimizations=true'
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-cpu-runner -e main -entry-point-result=void -shared-libs=/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_c_runner_utils.so,/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/lib/libmlir_runner_utils.so
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# RUN: at line 32
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-opt /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir --sparsifier="enable-arm-sve=true enable-runtime-library=false vl=2 reassociate-fp-reductions=true enable-index-optimizations=true" | mlir-cpu-runner --march=aarch64 --mattr="+sve" -e main -entry-point-result=void -shared-libs=/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/./lib/libmlir_runner_utils.so,/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/./lib/libmlir_c_runner_utils.so | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/mlir-opt /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir '--sparsifier=enable-arm-sve=true enable-runtime-library=false vl=2 reassociate-fp-reductions=true enable-index-optimizations=true'
# .---command stderr------------
# | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir:76:10: error: null operand found
# |     %0 = linalg.generic #trait_reduction
# |          ^
# | /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir:76:10: note: see current operation: %18 = "arith.muli"(<<NULL VALUE>>, %2) <{overflowFlags = #arith.overflow<none>}> : (<<NULL TYPE>>, index) -> index
# `-----------------------------
# error: command failed with exit status: 1
# executed command: mlir-cpu-runner --march=aarch64 --mattr=+sve -e main -entry-point-result=void -shared-libs=/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/./lib/libmlir_runner_utils.so,/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/./lib/libmlir_c_runner_utils.so
# .---command stderr------------
# | Error: entry point not found
# `-----------------------------
# error: command failed with exit status: 1
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/FileCheck /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reductions.mlir
# `-----------------------------
# error: command failed with exit status: 2

--

********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants