Issue 162426
Summary [mlir] ASAN ODR violations in `mlir-pdll` when `LLVM_LINK_LLVM_DYLIB=ON`
Labels mlir
Assignees
Reporter christopherbate
    There appears to be a circular dependency issue with the `[MLIR` `mlir-pdll` tool](https://github.com/llvm/llvm-project/blob/main/mlir/tools/mlir-pdll/CMakeLists.txt):

```cmake
set(LIBS
 MLIRIR
  MLIRPDLLAST
  MLIRPDLLCodeGen
  MLIRPDLLODS
  MLIRPDLLParser
 )

add_tablegen(mlir-pdll MLIR_PDLL
  DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
  EXPORT MLIR
  mlir-pdll.cpp

  DEPENDS
 ${LIBS}
  )
```

Some of the libraries in `LIBS` here will link `libLLVM` when `LLVM_LINK_LLVM_DYLIB=ON`. This includes MLIRIR but also `MLIRPDLLCodeGen` and others. TableGen binaries are explictly linked statically against LLVM. 

This results in ODR violation messages when building with both ASAN and `LLVM_LINK_LLVM_DYLIB=ON`:

```
==1842017==ERROR: AddressSanitizer: odr-violation (0x61a21d591220):
  [1] size=1 'llvm::vfs::FileSystem::ID' /llvm-project/llvm/lib/Support/VirtualFileSystem.cpp in /build/bin/mlir-pdll
  [2] size=1 'llvm::vfs::FileSystem::ID' /llvm-project/llvm/lib/Support/VirtualFileSystem.cpp in /build/bin/../lib/libLLVM.so.21.0git
These globals were registered at these points:
...
``` 

Looking at the dependency graph, we need to force `mlir-pdll` to link all its dependencies statically. That can be done by swapping out targets that aren't explicitly declared STATIc (e.g. `MLIRIR`) with object lib (`obj.MLIRIR`) targets if available, However, you have to transitively resolve all the dependencies required. It looks like the set it needs is (`MLIRIR` , `MLIRSupport` , `MLIRPDLDialect`, and some builtin op interface libraries). In some cases, object libraries are currently not built (e.g. if `BUILD_SHARED_LIBS=ON` and `LLVM_LINK_LLVM_DYLIB=ON` and (too be added in [PR#155488](https://github.com/llvm/llvm-project/pull/155488)) `MLIR_BUILD_MLIR_DYLIB=OFF`. Therefore we would need to start explicitly requesting that object libraries be built for at least this subset of libraries. 

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to