[clang] [llvm] [Flang] Search flang_rt in clang_rt path (PR #151954)
Paul H. Hargrove via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 6 11:59:45 PDT 2025
PHHargrove wrote:
> @PHHargrove Thanks for the details. There is something weird about your setup.
>
> 1. `libflang_rt.runtime.a` in `arm64-apple-darwin23.6.0/`. As long as CMake detects [`APPLE`](https://cmake.org/cmake/help/latest/variable/APPLE.html), the install directory will be [`CMAKE_SYSTEM_NAME`](https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html) (lower case). I have no explanation for this.
> 2. The native target is `arm64-apple-darwin23.6.0`, but you are compiling for `arm64-apple-macosx14.0.0`, probably because you compiled LLVM with an `LLVM_DEFAULT_TARGET_TRIPLE` option, or you updated your OS since you first configured LLVM. This has elements of cross-compilation which is still unsupported for Flang. Consider deleting your build directory a running cmake from scratch.
Regarding item 2: `-triple arm64-apple-macosx14.0.0` does not match the reported `Target: arm64-apple-darwin23.6.0`.
My `cmake` command (given below, for completeness) does not include any `LLVM_DEFAULT_TARGET_TRIPLE` option.
I have not updated my system recently, and certainly not since since running `cmake`.
I cannot account for the difference, but have determined that Homebrew's `flang` and *Apple's* `clang` both display the same "discrepancy" between the native target reported by the driver and the `-triple` it passes to the compiler.
So, I am going to assume this is the _expected_ behavior despite @Meinersbur's assertion that it is not.
Regarding item 1: unexpected library directory.
I removed both the build and installation directories, checked out the merge commit which closed this PR ([8de4819](https://github.com/llvm/llvm-project/commit/8de481913353a1e37264687d5cc73db0de19e6cc)), reran `cmake` in a _new_ build directory, and proceeded to `make -j8 all install`.
The flang runtime is installed in `$prefix/lib/clang/22/lib/darwin` which _is_ included in the `-L` options the driver passes to the linker (directly addressing the defect reported in @ktras's #151031)
TL;DR:
I cannot account for either of the "something weird" items, but with a fresh build I no longer reproduce #151031.
So, It is working for me now. :+1:
----
cmake commoand:
```
cmake ../llvm \
-DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \
-DCMAKE_INSTALL_PREFIX=/opt/llvm \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_ENABLE_PROJECTS="flang;mlir" \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_TARGETS_TO_BUILD=host
```
Verbose compile and run:
```
$ /opt/llvm/bin/flang -v ~/Hello/hello.f && ./a.out
flang version 22.0.0git (git at github.com:llvm/llvm-project 8de481913353a1e37264687d5cc73db0de19e6cc)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /opt/llvm/bin
"/opt/llvm/bin/flang" -fc1 -triple arm64-apple-macosx14.0.0 -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu apple-m1 -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +ccpp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -resource-dir /opt/llvm/lib/clang/22 -mframe-pointer=non-leaf -o /var/folders/dt/tfds1s310vgbwph7tvcvqwlm0000gp/T/hello-12a9a2.o -x f95 /Users/phhargrove/Hello/hello.f
"/usr/bin/ld" -demangle -lto_library /opt/llvm/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 14.0.0 14.0.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mllvm -enable-linkonceodr-outlining -o a.out /var/folders/dt/tfds1s310vgbwph7tvcvqwlm0000gp/T/hello-12a9a2.o -L/opt/llvm/lib/clang/22/lib/darwin -L/opt/llvm/lib -lflang_rt.runtime -lSystem
Hello, world!
Fortran STOP
```
https://github.com/llvm/llvm-project/pull/151954
More information about the llvm-commits
mailing list