这是indexloc提供的服务,不要输入任何密码
Skip to content

[Bug] Undefined symbol: TVMFFIFunctionCall #3284

@Arunkumarvallal

Description

@Arunkumarvallal

🐛 Bug

Linking fails when running mlc_llm package for the Android target. The process fails with undefined TVM FFI symbol errors during the build of tvm4j_runtime_packed.

To Reproduce

Steps to reproduce the behavior:

  1. Clone the mlc-llm repo and navigate to the project root.

  2. Run the following command from the Android build path:
    mlc_llm package

Observe the linker errors.

>>> referenced by IRModule.CodeGenLLVM:0
>>>               lib0.o:(qwen3_q0f16_e709b04052d95e24b38d40e4259e1f14_NT_matmul) in archive lib/libmodel_android.a
>>> referenced by IRModule.CodeGenLLVM:0
>>>               lib0.o:(qwen3_q0f16_e709b04052d95e24b38d40e4259e1f14_NT_matmul) in archive lib/libmodel_android.a
>>> referenced by IRModule.CodeGenLLVM:0
>>>               lib0.o:(qwen3_q0f16_e709b04052d95e24b38d40e4259e1f14_NT_matmul) in archive lib/libmodel_android.a
>>> referenced 155 more times

ld.lld: error: undefined symbol: TVMFFIErrorSetRaisedFromCStr
>>> referenced by IRModule.CodeGenLLVM:0
>>>               lib0.o:(qwen3_q0f16_e709b04052d95e24b38d40e4259e1f14_NT_matmul) in archive lib/libmodel_android.a
>>> referenced by IRModule.CodeGenLLVM:0
>>>               lib0.o:(qwen3_q0f16_e709b04052d95e24b38d40e4259e1f14_NT_matmul1) in archive lib/libmodel_android.a
>>> referenced by IRModule.CodeGenLLVM:0
>>>               lib0.o:(qwen3_q0f16_e709b04052d95e24b38d40e4259e1f14_NT_matmul10) in archive lib/libmodel_android.a
>>> referenced 124 more times
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [libtvm4j_runtime_packed.so] Error 1
make[2]: *** [CMakeFiles/tvm4j_runtime_packed.dir/all] Error 2
make[1]: *** [CMakeFiles/tvm4j_runtime_packed.dir/rule] Error 2
make: *** [tvm4j_runtime_packed] Error 2
Traceback (most recent call last):
  File "/Users/arun/Documents/Projects/mlc-llm/android/mlc4j/prepare_libs.py", line 120, in <module>
    main(parsed.mlc_llm_source_dir)
  File "/Users/arun/Documents/Projects/mlc-llm/android/mlc4j/prepare_libs.py", line 103, in main
    run_cmake_build()
  File "/Users/arun/Documents/Projects/mlc-llm/android/mlc4j/prepare_libs.py", line 66, in run_cmake_build
    subprocess.run(cmd, check=True, env=os.environ)
  File "/opt/homebrew/Cellar/python@3.11/3.11.12/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'tvm4j_runtime_packed', '--config', 'release', '-j8']' returned non-zero exit status 2.
Traceback (most recent call last):
  File "/opt/homebrew/bin/mlc_llm", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mlc_llm/__main__.py", line 54, in main
    cli.main(sys.argv[2:])
  File "/opt/homebrew/lib/python3.11/site-packages/mlc_llm/cli/package.py", line 64, in main
    package(
  File "/opt/homebrew/lib/python3.11/site-packages/mlc_llm/interface/package.py", line 361, in package
    build_android_binding(mlc_llm_source_dir, output)
  File "/opt/homebrew/lib/python3.11/site-packages/mlc_llm/interface/package.py", line 275, in build_android_binding
    subprocess.run([sys.executable, mlc4j_path / "prepare_libs.py"], check=True, env=os.environ)
  File "/opt/homebrew/Cellar/python@3.11/3.11.12/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/opt/homebrew/opt/python@3.11/bin/python3.11', PosixPath('/Users/arun/Documents/Projects/mlc-llm/android/mlc4j/prepare_libs.py')]' returned non-zero exit status 1.

Expected behavior

The build should succeed without error.

Environment

  • Platform (e.g. WebGPU/Vulkan/IOS/Android/CUDA): Android
  • Operating system (e.g. Ubuntu/Windows/MacOS/...): 15.4
  • Device : iphone 14
  • How you installed MLC-LLM (conda, source): conda
  • How you installed TVM-Unity (pip, source): pip3
  • Python version (e.g. 3.10): 3.11
  • GPU driver version (if applicable):
  • CUDA/cuDNN version (if applicable):
  • TVM Unity Hash Tag (python -c "import tvm; print('\n'.join(f'{k}: {v}' for k, v in tvm.support.libinfo().items()))", applicable if you compile models):
USE_GTEST: AUTO
SUMMARIZE: OFF
TVM_DEBUG_WITH_ABI_CHANGE: OFF
USE_IOS_RPC: OFF
USE_MSC: OFF
USE_ETHOSU: 
CUDA_VERSION: NOT-FOUND
USE_LIBBACKTRACE: AUTO
DLPACK_PATH: 3rdparty/dlpack/include
USE_TENSORRT_CODEGEN: OFF
USE_THRUST: OFF
USE_TARGET_ONNX: OFF
USE_AOT_EXECUTOR: ON
BUILD_DUMMY_LIBTVM: OFF
USE_CUDNN: OFF
USE_TENSORRT_RUNTIME: OFF
USE_ARM_COMPUTE_LIB_GRAPH_EXECUTOR: OFF
USE_CCACHE: AUTO
USE_ARM_COMPUTE_LIB: OFF
USE_CPP_RTVM: 
USE_OPENCL_GTEST: /path/to/opencl/gtest
TVM_LOG_BEFORE_THROW: OFF
USE_MKL: OFF
USE_PT_TVMDSOOP: OFF
MLIR_VERSION: NOT-FOUND
USE_CLML: OFF
USE_STACKVM_RUNTIME: OFF
USE_GRAPH_EXECUTOR_CUDA_GRAPH: OFF
ROCM_PATH: /opt/rocm
USE_DNNL: OFF
USE_MSCCL: OFF
USE_VITIS_AI: OFF
USE_MLIR: OFF
USE_RCCL: OFF
USE_LLVM: llvm-config --link-static
USE_VERILATOR: OFF
USE_TF_TVMDSOOP: OFF
USE_THREADS: ON
USE_MSVC_MT: OFF
BACKTRACE_ON_SEGFAULT: OFF
USE_GRAPH_EXECUTOR: ON
USE_NCCL: OFF
USE_ROCBLAS: OFF
GIT_COMMIT_HASH: 2685d6ace64c30a077c1b3f6893d2e38589be7bb
USE_VULKAN: OFF
USE_RUST_EXT: OFF
USE_CUTLASS: OFF
USE_CPP_RPC: OFF
USE_HEXAGON: OFF
USE_CUSTOM_LOGGING: OFF
USE_UMA: OFF
USE_FALLBACK_STL_MAP: OFF
USE_SORT: ON
USE_RTTI: ON
GIT_COMMIT_TIME: 2024-09-07 15:18:06 -0400
USE_HIPBLAS: OFF
USE_HEXAGON_SDK: /path/to/sdk
USE_BLAS: none
USE_ETHOSN: OFF
USE_LIBTORCH: OFF
USE_RANDOM: ON
USE_CUDA: OFF
USE_COREML: OFF
USE_AMX: OFF
BUILD_STATIC_RUNTIME: OFF
USE_CMSISNN: OFF
USE_KHRONOS_SPIRV: OFF
USE_CLML_GRAPH_EXECUTOR: OFF
USE_TFLITE: OFF
USE_HEXAGON_GTEST: /path/to/hexagon/gtest
PICOJSON_PATH: 3rdparty/picojson
USE_OPENCL_ENABLE_HOST_PTR: OFF
INSTALL_DEV: OFF
USE_PROFILER: ON
USE_NNPACK: OFF
LLVM_VERSION: 15.0.7
USE_MRVL: OFF
USE_OPENCL: OFF
COMPILER_RT_PATH: 3rdparty/compiler-rt
RANG_PATH: 3rdparty/rang/include
USE_SPIRV_KHR_INTEGER_DOT_PRODUCT: OFF
USE_OPENMP: OFF
USE_BNNS: OFF
USE_FLASHINFER: 
USE_CUBLAS: OFF
USE_METAL: ON
USE_MICRO_STANDALONE_RUNTIME: OFF
USE_HEXAGON_EXTERNAL_LIBS: OFF
USE_ALTERNATIVE_LINKER: AUTO
USE_BYODT_POSIT: OFF
USE_NVSHMEM: OFF
USE_HEXAGON_RPC: OFF
USE_MICRO: OFF
DMLC_PATH: 3rdparty/dmlc-core/include
INDEX_DEFAULT_I64: ON
USE_RELAY_DEBUG: OFF
USE_RPC: ON
USE_TENSORFLOW_PATH: none
TVM_CLML_VERSION: 
USE_MIOPEN: OFF
USE_ROCM: OFF
USE_PAPI: OFF
USE_CURAND: OFF
TVM_CXX_COMPILER_PATH: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
HIDE_PRIVATE_SYMBOLS: ON```
 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bugs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions