"ld.lld: error: undefined symbol: ..." while building MLIR standalone template

Hello

I am noob to LLVM/MLIR. I am trying to get into MLIR world for last couple of days. And members from this community are helping me a lot. I am really grateful to all. :pray:

I am getting these errors (in tons… :unamused:) while I am trying to build the MLIR standalone template

ld.lld: error: undefined symbol: __asan_set_shadow_f5
....
ld.lld: error: undefined symbol: __asan_version_mismatch_check_v8
...

ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
[14/19] Building CXX object standalone...tandalone-opt.dir/standalone-opt.cpp.o
ninja: build stopped: subcommand failed.

What I understood from the error is, linker (ld.lld) cannot find the definitions for certain symbols that are referenced in the code. And this kind of stuff typically happens when there is a mismatch between the declarations and the definitions of functions, variables, or classes.

But I don’t know where to look for it, and where to make changes.

So now let me tell you, how my dev env is designed and setup

  1. Downloaded llvm-project prebuilt binaries for 16.0.0 version and added them to $PATH. I am using the bins lld, clang to build the llvm-project.
  2. Built llvm-project of version 16.x with following cmake config
cmake   \
    -G Ninja    \
    -S ../llvm  \
    -B .    \
    -DCMAKE_BUILD_TYPE=Release      \
    -DCMAKE_INSTALL_PREFIX=../installation  \
    -DLLVM_ENABLE_ASSERTIONS=ON     \
    -DLLVM_ENABLE_PROJECTS="mlir;clang;lldb" \
    -DLLVM_INSTALL_UTILS=ON     \
    -DLLVM_ENABLE_LLD=ON    \
    -DCMAKE_C_COMPILER=clang    \
    -DCMAKE_CXX_COMPILER=clang++    \
    -DLLVM_PARALLEL_LINK_JOBS=1     \
    -DLLVM_TARGETS_TO_BUILD="Native;NVPTX"   \
    -DLLVM_CACHE_BUILD=ON   \
    -DLLVM_USE_SANITIZER="Address;Undefined"    \
    -DMLIR_INCLUDE_INTEGRATION_TESTS=ON    \
    -DLLVM_BUILD_EXAMPLE=ON    \
    -DLLVM_BUILD_TESTS=ON    \
    -DLLVM_INCLUDE_TESTS=ON    \
    -DMLIR_INCLUDE_TESTS=ON
  1. For MLIR standalone template, I copied it from cloned llvm-project/mlir/examples/standalone/* to someplace outside of MLIR project ~/compiler-projects/learn/mlir-standalone/. I am using the following cmake` config
# Where I build llvm-project
export LLVM_PROJECT_ROOT=~/compiler-projects/learn/mlir-intro

export BUILD_DIR=$LLVM_PROJECT_ROOT/build
export PREFIX=$LLVM_PROJECT_ROOT/installation/lib/cmake/mlir

cmake	\
	-G Ninja	\
	-S ../  \
    -B .    \
	-DCMAKE_BUILD_TYPE=Release		\
	-DMLIR_DIR=$PREFIX		\
	-DLLVM_EXTERNAL_LIT=$BUILD_DIR/bin/llvm-lit		\
   	-DCMAKE_C_COMPILER=clang 	\
   	-DCMAKE_CXX_COMPILER=clang++ 	\
	-DLLVM_PARALLEL_LINK_JOBS=1		\
	-DLLVM_ENABLE_LLD=ON
cmake --build . --target check-standalone
  1. Even if I try to build mlir-standalone template inside the llvm-project (i.e. here llvm-project/mlir/examples/standalone/), it is still being ended up with the same error.

Now, What can I do to solve it? Your suggestions, advises are greatly appreciated.

Thanks in advance!

You seem to be building MLIR with sanitizers (-DLLVM_USE_SANITIZER="Address;Undefined" ) but the standalone project without them. This leads to the linker not finding the sanitizer libraries.

1 Like

Thanks a lot for the tips. :clap: :clap: :clap:

I removed the -DLLVM_USE_SANITIZER="Address;Undefined" from the core llvm-project build. Then it worked!! Now none of the cmake config has this settings.

But it doesn’t work and gives the same error if I use this cmake config key in both (i.e. llvm-project config and mlir standalone config). Is it because of MLIR standalone donot have those sanitizers lib in it’s source?

Now I want share some curiosity if you don’t mind. I have searched about these SANITIZERs and found

sanitizer is a programming tool that detects bugs in the form of undefined or suspicious behavior by a compiler inserting instrumentation code at runtime.
Googles AddressSanitizer (or ASan) uses directly mapped shadow memory to detect memory corruption such as buffer overflows or accesses to a dangling pointer (use-after-free).

Considering that, if I donot use sanitizer for MLIR dev, would it be okay? Are there any things to consider for the future regarding sanitizers?

Thanks a lot in advance!