Flang example plugin does not load

I built llvm and flang with:

cmake \
  -G Ninja \
  ../llvm \
  -DCMAKE_BUILD_TYPE=Release \
  -DFLANG_ENABLE_WERROR=ON \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DLLVM_TARGETS_TO_BUILD=host \
  -DCMAKE_INSTALL_PREFIX=$INSTALLDIR \
  -DLLVM_LIT_ARGS=-v \
  -DLLVM_ENABLE_PROJECTS="clang;mlir;flang" \
  -DLLVM_ENABLE_RUNTIMES="compiler-rt" \
  -DLLVM_ENABLE_PLUGINS=ON \
  -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON \
  -DFLANG_PLUGIN_SUPPORT=ON \
  -DFLANG_BUILD_EXAMPLES=ON \
  -DLLVM_BUILD_LLVM_DYLIB=ON \
  -DLLVM_PARALLEL_LINK_JOBS=1 \
  -DLLVM_PARALLEL_COMPILE_JOBS=3 \
  -DLLVM_USE_LINKER=lld \
  -DLLVM_USE_SPLIT_DWARF=ON

and

ninja -j1

Next I tried to load an example plugin:

bin/flang-new -fc1 -load lib/flangPrintFunctionNames.so

but it failed with

error: unable to load plugin 'lib/flangPrintFunctionNames.so': 'lib/flangPrintFunctionNames.so: undefined symbol: _ZN7Fortran8frontend14FrontendAction22shouldEraseOutputFilesEv'

Hi @imbens ,

Thanks for posting! I was able to re-produce this with your CMake configuration, but I’m not sure what the root cause is. This basically works with the configuration that I normally use:

cmake \
  -G Ninja \
  ../llvm \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_TARGETS_TO_BUILD=host \
  -DLLVM_ENABLE_PROJECTS="clang;mlir;flang" \
  -DFLANG_PLUGIN_SUPPORT=ON \
  -DFLANG_BUILD_EXAMPLES=ON \
  -DBUILD_SHARED_LIBS=ON

You can also check one of our buildbots that builds these examples (and tests them): flang-aarch64-sharedlibs.

I’ll get back to you once I manage to triage this. In the meantime, you can try my configuration and see whether it works for you.

-Andrzej

1 Like

Thank you, @banach-space . That solved the problem. I suspect that BUILD_SHARED_LIBS=ON fixed it.

Thanks again. It is swift, positive and helpful responses like yours, that make this a great project.

Thank you, that’s very kind of you to say! :blush:

I’m still trying to figure out the root cause, but at least you can progress with your stuff now :slight_smile:

I believe that the issue is triggered by -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON. I’ve not had the chance to investigate more. I’ve created a GitHub issue, see #56954. Hopefully somebody with a bit of spare bandwidth will pick it up (or, perhaps, my future self) :slight_smile:

-Andrzej