Skip to content

[flang] Fix linking to libMLIR #135483

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 2 commits into from
Apr 14, 2025
Merged

[flang] Fix linking to libMLIR #135483

merged 2 commits into from
Apr 14, 2025

Conversation

mgorny
Copy link
Member

@mgorny mgorny commented Apr 12, 2025

Fix regression to MLIR dylib support introduced in #135240. Without the fix, the build with no static libraries fails:

FAILED: bin/fir-opt 
: && /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++ -O2 -pipe -march=native -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-ctad-maybe-unsupported -fno-strict-aliasing -fno-semantic-interposition -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs    -Wl,-rpath-link,/var/tmp/portage/llvm-core/flang-21.0.0.9999/work/flang_build/lib  -Wl,--gc-sections  -Wl,--dependency-file=tools/fir-opt/CMakeFiles/fir-opt.dir/link.d tools/fir-opt/CMakeFiles/fir-opt.dir/fir-opt.cpp.o -o bin/fir-opt -L/usr/lib/llvm/21/lib64 -Wl,-rpath,"\$ORIGIN/../lib64:/usr/lib/llvm/21/lib64:"  lib/libCUFAttrs.a  lib/libCUFDialect.a  lib/libFIRDialect.a  lib/libFIRSupport.a  lib/libFIRTransforms.a  lib/libFIRCodeGen.a  lib/libFIRCodeGenDialect.a  lib/libHLFIRDialect.a  lib/libHLFIRTransforms.a  lib/libFIROpenACCSupport.a  lib/libFIROpenMPSupport.a  lib/libFlangOpenMPTransforms.a  lib/libFIRAnalysis.a  lib/libFIRTransforms.a  lib/libFIRCodeGen.a  lib/libFIROpenACCSupport.a  lib/libFIRCodeGenDialect.a  -lMLIRIR  lib/libFIROpenMPSupport.a  lib/libFIRAnalysis.a  lib/libFIRBuilder.a  lib/libCUFDialect.a  lib/libFIRSupport.a  lib/libHLFIRDialect.a  lib/libFIRDialect.a  lib/libCUFAttrs.a  lib/libFIRDialectSupport.a  lib/libFortranEvaluate.a  lib/libFortranDecimal.a  lib/libFortranParser.a  lib/libFortranSupport.a  /usr/lib/llvm/21/lib64/libMLIR.so.21.0gitfa4ac19f  /usr/lib/llvm/21/lib64/libclang-cpp.so.21.0gitfa4ac19f  /usr/lib/llvm/21/lib64/libLLVM.so.21.0gitfa4ac19f  -lquadmath && :
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lMLIRIR: No such file or directory
collect2: error: ld returned 1 exit status

Fix regression to MLIR dylib support introduced in llvm#135240.
@mgorny mgorny requested a review from vzakhari April 12, 2025 08:13
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Apr 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 12, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Michał Górny (mgorny)

Changes

Fix regression to MLIR dylib support introduced in #135240.


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

1 Files Affected:

  • (modified) flang/lib/Optimizer/Dialect/FIRCG/CMakeLists.txt (+2)
diff --git a/flang/lib/Optimizer/Dialect/FIRCG/CMakeLists.txt b/flang/lib/Optimizer/Dialect/FIRCG/CMakeLists.txt
index 107d567056b59..af9315a980afb 100644
--- a/flang/lib/Optimizer/Dialect/FIRCG/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/FIRCG/CMakeLists.txt
@@ -6,6 +6,8 @@ add_flang_library(FIRCodeGenDialect
 
   LINK_LIBS
   FIRDialect
+
+  MLIR_LIBS
   MLIRIR
 
   LINK_COMPONENTS

@vzakhari
Copy link
Contributor

Thank you for the change! Can you please explain how the failure looks like? I did not see issues with my local builds using both static and shared libs, but I must have missed something.

It looks like the LINK_COMPONENTS section needs to be hoisted above MLIR_LIBS - I think CMake code in AddFlang.cmake is not handling the ordering very well.

@mgorny
Copy link
Member Author

mgorny commented Apr 14, 2025

Thank you for the change! Can you please explain how the failure looks like? I did not see issues with my local builds using both static and shared libs, but I must have missed something.

Sure, lemme just build it again, since I didn't save the logs. That said, I'm pretty sure it was the usual linker error about -lMLIRIR not being found — since we install MLIR without static libraries.

It looks like the LINK_COMPONENTS section needs to be hoisted above MLIR_LIBS - I think CMake code in AddFlang.cmake is not handling the ordering very well.

You are correct, sorry about that — pushed a fix.

@mgorny
Copy link
Member Author

mgorny commented Apr 14, 2025

Yep, it is:

FAILED: bin/fir-opt 
: && /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++ -O2 -pipe -march=native -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-ctad-maybe-unsupported -fno-strict-aliasing -fno-semantic-interposition -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs    -Wl,-rpath-link,/var/tmp/portage/llvm-core/flang-21.0.0.9999/work/flang_build/lib  -Wl,--gc-sections  -Wl,--dependency-file=tools/fir-opt/CMakeFiles/fir-opt.dir/link.d tools/fir-opt/CMakeFiles/fir-opt.dir/fir-opt.cpp.o -o bin/fir-opt -L/usr/lib/llvm/21/lib64 -Wl,-rpath,"\$ORIGIN/../lib64:/usr/lib/llvm/21/lib64:"  lib/libCUFAttrs.a  lib/libCUFDialect.a  lib/libFIRDialect.a  lib/libFIRSupport.a  lib/libFIRTransforms.a  lib/libFIRCodeGen.a  lib/libFIRCodeGenDialect.a  lib/libHLFIRDialect.a  lib/libHLFIRTransforms.a  lib/libFIROpenACCSupport.a  lib/libFIROpenMPSupport.a  lib/libFlangOpenMPTransforms.a  lib/libFIRAnalysis.a  lib/libFIRTransforms.a  lib/libFIRCodeGen.a  lib/libFIROpenACCSupport.a  lib/libFIRCodeGenDialect.a  -lMLIRIR  lib/libFIROpenMPSupport.a  lib/libFIRAnalysis.a  lib/libFIRBuilder.a  lib/libCUFDialect.a  lib/libFIRSupport.a  lib/libHLFIRDialect.a  lib/libFIRDialect.a  lib/libCUFAttrs.a  lib/libFIRDialectSupport.a  lib/libFortranEvaluate.a  lib/libFortranDecimal.a  lib/libFortranParser.a  lib/libFortranSupport.a  /usr/lib/llvm/21/lib64/libMLIR.so.21.0gitfa4ac19f  /usr/lib/llvm/21/lib64/libclang-cpp.so.21.0gitfa4ac19f  /usr/lib/llvm/21/lib64/libLLVM.so.21.0gitfa4ac19f  -lquadmath && :
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lMLIRIR: No such file or directory
collect2: error: ld returned 1 exit status

@mgorny mgorny merged commit aad09da into llvm:main Apr 14, 2025
8 of 10 checks passed
bcardosolopes added a commit to bcardosolopes/llvm-project that referenced this pull request Apr 14, 2025
* origin/main: (199 commits)
  [NFC][AsmPrinter] Refactor AsmPrinter and AArch64AsmPrinter to prepare for jump table partitions on aarch64 (llvm#125993)
  [HEXAGON] Fix corner cases for hwloops pass (llvm#135439)
  [flang] Handle volatility in lowering and codegen (llvm#135311)
  [MLIR][Shape] Support >2 args in `shape.broadcast` folder (llvm#126808)
  [DirectX] Use scalar arguments for @llvm.dx.dot intrinsics (llvm#134570)
  Remove the redundant check for "WeakPtr" in isSmartPtrClass to fix the issue 135612. (llvm#135629)
  [BOLT] Support relative vtable (llvm#135449)
  [flang] Fix linking to libMLIR (llvm#135483)
  [AsmPrinter] Link .section_sizes to the correct section (llvm#135583)
  [ctxprof] Handle instrumenting functions with `musttail` calls (llvm#135121)
  [SystemZ] Consider VST/VL as SimpleBDXStore/Load (llvm#135623)
  [libc++][CI] Pin the XCode version. (llvm#135412)
  [lldb-dap] Fix win32 build. (llvm#135638)
  [Interp] Mark inline-virtual.cpp as unsupported with ASan (llvm#135402)
  [libc++] Removes the _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT macro. (llvm#135494)
  [CVP] Add tests for ucmp/scmp with switch (NFC)
  [mlir][tosa] Align AbsOp example variable names (llvm#135268)
  [mlir][tosa] Align AddOp examples to spec (llvm#135266)
  [mlir][tosa] Align RFFT2d and FFT2d operator examples (llvm#135261)
  [flang][OpenMP][HLFIR] Support vector subscripted array sections for DEPEND (llvm#133892)
  ...
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
Fix regression to MLIR dylib support introduced in llvm#135240. Without the
fix, the build with no static libraries fails:

```
FAILED: bin/fir-opt 
: && /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++ -O2 -pipe -march=native -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-ctad-maybe-unsupported -fno-strict-aliasing -fno-semantic-interposition -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs    -Wl,-rpath-link,/var/tmp/portage/llvm-core/flang-21.0.0.9999/work/flang_build/lib  -Wl,--gc-sections  -Wl,--dependency-file=tools/fir-opt/CMakeFiles/fir-opt.dir/link.d tools/fir-opt/CMakeFiles/fir-opt.dir/fir-opt.cpp.o -o bin/fir-opt -L/usr/lib/llvm/21/lib64 -Wl,-rpath,"\$ORIGIN/../lib64:/usr/lib/llvm/21/lib64:"  lib/libCUFAttrs.a  lib/libCUFDialect.a  lib/libFIRDialect.a  lib/libFIRSupport.a  lib/libFIRTransforms.a  lib/libFIRCodeGen.a  lib/libFIRCodeGenDialect.a  lib/libHLFIRDialect.a  lib/libHLFIRTransforms.a  lib/libFIROpenACCSupport.a  lib/libFIROpenMPSupport.a  lib/libFlangOpenMPTransforms.a  lib/libFIRAnalysis.a  lib/libFIRTransforms.a  lib/libFIRCodeGen.a  lib/libFIROpenACCSupport.a  lib/libFIRCodeGenDialect.a  -lMLIRIR  lib/libFIROpenMPSupport.a  lib/libFIRAnalysis.a  lib/libFIRBuilder.a  lib/libCUFDialect.a  lib/libFIRSupport.a  lib/libHLFIRDialect.a  lib/libFIRDialect.a  lib/libCUFAttrs.a  lib/libFIRDialectSupport.a  lib/libFortranEvaluate.a  lib/libFortranDecimal.a  lib/libFortranParser.a  lib/libFortranSupport.a  /usr/lib/llvm/21/lib64/libMLIR.so.21.0gitfa4ac19f  /usr/lib/llvm/21/lib64/libclang-cpp.so.21.0gitfa4ac19f  /usr/lib/llvm/21/lib64/libLLVM.so.21.0gitfa4ac19f  -lquadmath && :
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lMLIRIR: No such file or directory
collect2: error: ld returned 1 exit status
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants