Skip to content

[flang] Add dependency for out-of-tree flang on compiler-rt #482

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
Jun 25, 2025

Conversation

DavidTruby
Copy link
Member

flang on AArch64 now always depends on compiler-rt so it needs to be
built in the main LLVM build for the out-of-tree flang bots.

flang on AArch64 now always depends on compiler-rt so it needs to be
built in the main LLVM build for the out-of-tree flang bots.
@DavidTruby DavidTruby requested review from Meinersbur and luporl June 24, 2025 16:25
@luporl luporl requested a review from DavidSpickett June 24, 2025 17:05
@@ -19,7 +19,7 @@ def getFlangOutOfTreeBuildFactory(
f = getCmakeWithNinjaBuildFactory(
depends_on_projects=['llvm','clang','mlir','openmp','flang','flang-rt'],
enable_projects=['llvm','clang','mlir'],
enable_runtimes=['openmp'],
enable_runtimes=['openmp', 'compiler-rt'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but I think that 'compiler-rt' should also be added to depends_on_projects.
My understanding is that this way builds are also triggered by changes in compiler-rt.

Add compiler-rt to depends_on_projects
@DavidSpickett
Copy link
Contributor

https://lab.llvm.org/staging/#/builders/46/builds/4084 uses the out of tree config now too, so this will fix that builder as well.

I don't see any more of our Flang builders with this issue, so we can assume they don't need changing.

Copy link
Contributor

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DavidTruby
Copy link
Member Author

DavidTruby commented Jun 25, 2025

In-tree flang has the dependency listed in the cmake so compiler-rt will get auto added, in the same way flang-rt does. There's just no real way to do this for out of tree flang unfortunately.

I'm also adding to the release notes to note this new dependency on compiler-rt.

@DavidTruby DavidTruby merged commit ece8298 into llvm:main Jun 25, 2025
2 checks passed
@DavidSpickett
Copy link
Contributor

This is now present on staging, but the flang-libcxx builder is still failing the test.

The initial llvm build has compiler-rt now:

cmake -DLLVM_TARGETS_TO_BUILD=AArch64 -DCMAKE_CXX_STANDARD=17 -DLLVM_ENABLE_WERROR=OFF -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_LIBCXX=On -DCMAKE_BUILD_TYPE=Release '-DLLVM_ENABLE_PROJECTS=llvm;clang;mlir' '-DLLVM_ENABLE_RUNTIMES=openmp;compiler-rt' '-DLLVM_LIT_ARGS=-v -vv' -GNinja ../llvm-project/llvm

Test fails:

/usr/bin/ld: cannot find /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build_flang/lib/clang/21/lib/aarch64-unknown-linux-gnu/libclang_rt.builtins.a: No such file or directory
flang-21: error: linker command failed with exit code 1 (use -v to see invocation)

I see two of those files, but not in that location:

/worker/flang-aarch64-libcxx$ find -name "*.a" | grep aarch64 | grep builtins | grep -v llvm-project
./build/lib/clang/21/lib/aarch64-unknown-linux-gnu/libclang_rt.builtins.a
./build_llvm/lib/clang/21/lib/aarch64-unknown-linux-gnu/libclang_rt.builtins.a

I think ./build is just the old build directory from before the configuration change. ./build_llvm is the current one.

@luporl can you take a look at this?

@luporl
Copy link
Contributor

luporl commented Jun 26, 2025

It looks like after llvm/llvm-project#144710 out-of-tree flang can't build executables anymore, when it is run from its build dir.
This is apparently because it now assumes compiler-rt builtins will be under the same build directory of flang executable.

$ /home/leandro.lupori/git/flang/build_flang/bin/flang -L/home/leandro.lupori/git/flang/build_flang_rt/flang-rt/lib -v hello.f90
flang version 21.0.0git (git@github.com:luporl/llvm-project.git 97c794f9a97d9b6d22df7284c2f5c605e89de1b2)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/leandro.lupori/git/flang/build_flang/bin
Build config: +assertions
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/aarch64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/home/leandro.lupori/git/flang/build_flang/bin/flang" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -resource-dir /home/leandro.lupori/git/flang/build_flang/lib/clang/21 -mframe-pointer=non-leaf -o /tmp/hello-3a661d.o -x f95 hello.f90
 "/usr/bin/ld" -EL -z relro --hash-style=gnu --eh-frame-hdr -m aarch64linux -pie -dynamic-linker /lib/ld-linux-aarch64.so.1 -o a.out /lib/aarch64-linux-gnu/Scrt1.o /lib/aarch64-linux-gnu/crti.o /usr/lib/gcc/aarch64-linux-gnu/14/crtbeginS.o -L/home/leandro.lupori/git/flang/build_flang_rt/flang-rt/lib -L/usr/lib/gcc/aarch64-linux-gnu/14 -L/lib/aarch64-linux-gnu -L/usr/lib/aarch64-linux-gnu -L/lib -L/usr/lib /tmp/hello-3a661d.o -L/home/leandro.lupori/git/flang/build_flang/lib -lflang_rt.runtime -lm -lgcc --as-needed -lgcc_s --no-as-needed --as-needed /home/leandro.lupori/git/flang/build_flang/lib/clang/21/lib/aarch64-unknown-linux-gnu/libclang_rt.builtins.a --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed --as-needed /home/leandro.lupori/git/flang/build_flang/lib/clang/21/lib/aarch64-unknown-linux-gnu/libclang_rt.builtins.a --no-as-needed /usr/lib/gcc/aarch64-linux-gnu/14/crtendS.o /lib/aarch64-linux-gnu/crtn.o
/usr/bin/ld: cannot find /home/leandro.lupori/git/flang/build_flang/lib/clang/21/lib/aarch64-unknown-linux-gnu/libclang_rt.builtins.a: No such file or directory
flang-21: error: linker command failed with exit code 1 (use -v to see invocation)

The problem is that, unlike flang-rt, compiler-rt builtins' path is hardcoded, so I don't know if it is possible to work around it using driver flags only. Appending the correct path to builtins doesn't work, as the linker still complains that the other library was not found.

Even when out-of-tree flang is installed, it will only be able to find compiler-rt builtins, and thus generate binaries, if it is installed in the same directory as the unified tree.

@DavidTruby, do you have any suggestions on how to address this issue?

@DavidTruby
Copy link
Member Author

Oh, I see. How does an out of tree clang with -DCLANG_DEFAULT_RTLIB=compiler-rt resolve this, if at all? I guess I should have a look at that...

@luporl
Copy link
Contributor

luporl commented Jun 30, 2025

Oh, I see. How does an out of tree clang with -DCLANG_DEFAULT_RTLIB=compiler-rt resolve this, if at all? I guess I should have a look at that...

Does clang support being built out of tree? Is it documented somewhere?

I tried it but got blocked by some cmake errors.

@Meinersbur
Copy link
Member

Clang is supposed to be able to be built standalone with pre-compiled LLVM:
https://github.com/llvm/llvm-project/blob/6b1c92cbcb760ff95affc66c689236d40288e1ad/clang/CMakeLists.txt#L10-L15

It is possible that it is not working anymore because nobody is testing it.

@DavidTruby
Copy link
Member Author

Sorry, I just got around to looking at this again; clang has the same issue as flang here if built out of tree with -DCLANG_DEFAULT_RTLIB=compiler-rt. The driver code simply assumes that the path to compiler-rt is relative to the driver itself. I think changing this might be non-trivial.
Could we possibly fix this with CMAKE_INSTALL_PREFIX being the same for both the LLVM build and the flang build, and installing both there? I guess you can't run the tests that way...

@DavidTruby
Copy link
Member Author

I think @MaskRay might know better what the logic is for how clang looks for compiler-rt; maybe they have an idea what we could do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants