Skip to content

[flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX and LoP #131041

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 15 commits into from
Apr 3, 2025

Conversation

DanielCChen
Copy link
Contributor

@DanielCChen DanielCChen commented Mar 12, 2025

This PR is to improve the driver code to build flang-rt path by re-using the logic and code of compiler-rt.

  1. Moved addFortranRuntimeLibraryPath and addFortranRuntimeLibs to ToolChain.h and made them virtual so that they can be overridden if customization is needed. The current implementation of those two procedures is moved to ToolChain.cpp as the base implementation to default to.

  2. Both AIX and PPCLinux now override addFortranRuntimeLibs.
    The overriding function of addFortranRuntimeLibs for both AIX and PPCLinux calls getCompilerRTArgString => getCompilerRT => buildCompilerRTBasename to get the path to flang-rt. This code handles LLVM_ENABLE_PER_TARGET_RUNTIME_DIR setting. As shown in PPCLinux.cpp, FT_static is the default. If not found, it will search and build for FT_shared. To differentiate flang-rt from clang-rt, a boolean flag IsFortran is passed to the chain of functions in order to reach buildCompilerRTBasename.

@DanielCChen DanielCChen self-assigned this Mar 12, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Mar 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 12, 2025

@llvm/pr-subscribers-backend-powerpc
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Daniel Chen (DanielCChen)

Changes

On AIX, we want to pass the whole path (e.g. /home/user/build/lib/clang/21/lib/aix/libflang_rt.runtime.a) to the linker to be consistent with clang RT on AIX.


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

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+10-1)
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b43472a52038b..21f934cdba468 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1345,7 +1345,16 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
       if (AsNeeded)
         addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
     }
-    CmdArgs.push_back("-lflang_rt.runtime");
+    if (TC.getTriple().isOSAIX()) {
+      // On AIX, pass the whole path of flang_rt.runtime.a to be consistent
+      // with clang.
+      std::string CRTBasename = "libflang_rt.runtime.a";
+      SmallString<128> Path(TC.getCompilerRTPath());
+      llvm::sys::path::append(Path, CRTBasename);
+      if (TC.getVFS().exists(Path))
+        CmdArgs.push_back(Args.MakeArgString(std::string(Path)));
+    } else
+      CmdArgs.push_back("-lflang_rt.runtime");
     addArchSpecificRPath(TC, Args, CmdArgs);
 
     // needs libexecinfo for backtrace functions

Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

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

This is what I would like to do more generally, not just for AIX. This PR however will break using a shared library libflang_rt.runtime.so. Ideally, we would synchronize with the compiler-rt implementation which already has many supporting functions such as buildCompilerRTBasename.

Comment on lines 1354 to 1355
if (TC.getVFS().exists(Path))
CmdArgs.push_back(Args.MakeArgString(std::string(Path)));
Copy link
Member

Choose a reason for hiding this comment

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

IMHO just doing nothing if the file does exist is a very confusing behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO just doing nothing if the file does exist is a very confusing behavior.

There are some similar usages in the Driver code.
It adds the path to the linker arg list only if the path has been created. Otherwise, not adding it (i.e. do nothing).

For example, if I didn't have -DLLVM_ENABLE_RUNTIMES="flang-rt" specified, I wouldn't have build/lib/clang/21/lib/aix/libflang_rt.runtime.a, so this code will check that and not adding that to the linker arg list.

That being said, I totally understand your point. Just I don't have a good answer for it.

Copy link
Member

@Meinersbur Meinersbur Mar 13, 2025

Choose a reason for hiding this comment

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

There are some similar usages in the Driver code.

And its source of one of my biggest grievences. See #122152 and all the discussion in #87866.

If the file does not exist, I want an error message about the file not existing. With the runtime not being added, one will get an error about a symbol not resolved. Someone will have to debug why flang-rt does not define the symbol only to discover that flang-rt is not added to the linker line. Then they have to find out why and the only way I can think of is to find this line in the source that tells them that the flang-rt it not present or just in the wrong path. The result of getCompilerRTPath() varies by some parameters, or the triple is sligthly different (x86_64-unknown-linux-gnu vs x86_64-linux-gnu), or ... . I know because I went through this rabbit hole for #122152. Let's please just not do this.

If the absolute path cannot be resolved, at least add -lflang_rt.runtime so the linker can either resolve the library itself, or display an appropriate error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. I will add -lflang_rt.runtime if the path does not exist.

@DanielCChen
Copy link
Contributor Author

This is what I would like to do more generally, not just for AIX. This PR however will break using a shared library libflang_rt.runtime.so. Ideally, we would synchronize with the compiler-rt implementation which already has many supporting functions such as buildCompilerRTBasename.

Right. I tried with FLANG_RT_ENABLE_SHARED=ON on AIX. I was able to dynamically link to the shared flang-rt and execute the a.out successfully.

As for buildCompilerRTBasename, it is currently specific to clang_rt with different Component (e.g. builtins or profile).

Would you prefer to have a new additional set of functions for flang-rt?

Something like:

getCompilerRTArgString => getFortranRTArgString
getCompilerRT => getFortranRT
buildCompilerRTBasename => buildFortranRTBasename

@Meinersbur
Copy link
Member

Meinersbur commented Mar 13, 2025

Right. I tried with FLANG_RT_ENABLE_SHARED=ON on AIX. I was able to dynamically link to the shared flang-rt and execute the a.out successfully.

With this PR applied? It hardcodes libflang_rt.runtime.a on AIX, how can it find the .so?

As for buildCompilerRTBasename, it is currently specific to clang_rt with different Component (e.g. builtins or profile).

flang-rt also has components, currently there are runtime, quadmath, and cuda_<version>.

Would you prefer to have a new additional set of functions for flang-rt?

I don't find the compiler-rt ones very logical as they have grown over time, especially with the LLVM_ENABLE_PER_TARGET_RUNTIME_DIR transition. Flang-RT only does LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON which could simplify some things, but code-reuse of the compiler-rt functions could be worthwhile as well. I would have to experiment to know what works best. Note that the linker currently resolves -lflang_rt.runtime because ToolChain::LibraryPath (I think) which contains ToolChain::getRuntimePath() is added as -L argument to the linker. That might be the way to get the location of flang_rt.*.a. It would just be nice to have a function that returns the canonical location of flang_rt.*.a because currently its all over the place. There is tools::addFortranRuntimeLibraryPath but it doesn't contain flang-rt when using LLVM_ENABLE_RUNTIMES=flang-rt.

Also: multilib.

@DanielCChen
Copy link
Contributor Author

With this PR applied? It hardcodes libflang_rt.runtime.a on AIX, how can it find the .so?

Sorry, I just realized on AIX, both static and shared library are named .a, which is why it didn't fail for me. But it is not the case for other platforms.

@DanielCChen
Copy link
Contributor Author

I am working on a patch that re-uses compilerRT code as much as possible.

@DanielCChen
Copy link
Contributor Author

DanielCChen commented Mar 15, 2025

@Meinersbur and other reviewers,

In the attempt to make building the path of flant-rt more general as well as customizable in response to the review comment, I made the following changes in this latest commit (sorry about a few more commits that fixed some typos).

  1. Moved addFortranRuntimeLibraryPath and addFortranRuntimeLibs to ToolChain.h and made them virtual so that they can be overridden if customization is needed. The current implementation of those two procedures is moved to ToolChain.cpp as the base implementation to default to.
  2. Both AIX and PPCLinux now override addFortranRuntimeLibs. Those are the two systems I have access to, but the code could be used by others if suitable.
  3. I re-used compilerRT code as much as possible. Now, addFortranRuntimeLibs calls getCompilerRTArgString => getCompilerRT => buildCompilerRTBasename to get the path to flang-rt. As shown in PPCLinux.cpp, static is the default. If not found, it will search and build for shared. To differentiate flang-rt from clang-rt, a boolean flag IsFortran is passed to the chain of functions.
  4. (NFC) The current base getCompilerRT in ToolChain.cpp handles both lib/${triple} and lib/${os_dirname} paths. Because AIX is not supporting -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, I added a AIX::getCompilerRT to only build lib/${os_dirname}.

Please let me know if this approach is acceptable.

Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

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

Approach look OK to me.

Could you add test(s) along the lines of aix-rlib.c. If we make further changes, knowing what is expected on AIX/PPCLinux would be very helpful.

A review from someone involved with the Clang driver side would be helpful. @MaskRay ?

Comment on lines 111 to 112
Path = getCompilerRTArgString(Args, "runtime", ToolChain::FT_Static,
getDriver().IsFlangMode()))))
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we always in IsFlangMode when executing addFortranRuntimeLibs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we are.
The IsFlangMode() is indeed checked before we call addFortranRuntimeLibs.
Change both AIX.cpp and PPCLinux.cpp to true.

@DanielCChen
Copy link
Contributor Author

DanielCChen commented Mar 17, 2025

Approach look OK to me.

Could you add test(s) along the lines of aix-rlib.c. If we make further changes, knowing what is expected on AIX/PPCLunux would be very helpful.

A review from someone involved with the Clang driver side would be helpful. @MaskRay ?

Thanks for the review again.
I am planning to add tests once the principle of the design is accepted.

Future improvement:

  1. The addFortranRuntimeLibs should contain common code only (something similar to what AIX.cpp is doing: just get the path) and leave platform specific stuff to the overriding functions for each platform (if they have unique stuff). The overriding functions can call the base one to get the common code.
  2. getCompilerRT may be split into two: one for lib/${os_dirname} and one for lib/${triple}. For the platform like AIX that it only needs os_dirname, it can just use the base one without needing to override it. For the platform like LoP that honers the LLVM_ENABLE_PER_TARGET_RUNTIME_DIR option, it can call both without needing to override it (similar to PPCLinux.cpp)
  3. Note that I only made AIX and LoP re-using the compilerRT code as I don't have means to test other platforms. But in theory, this code can go into the base function for other platforms.

Copy link

github-actions bot commented Mar 18, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

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

Haven't read all comments. But the PR now changes many files, and there is a noticeable change to clang/lib/Driver/ToolChains/PPCLinux.cpp . However, the description hasn't been updated.

@DanielCChen
Copy link
Contributor Author

Haven't read all comments. But the PR now changes many files, and there is a noticeable change to clang/lib/Driver/ToolChains/PPCLinux.cpp . However, the description hasn't been updated.

Thanks for the comments! I updated the description to reflect the latest changes.

@DanielCChen
Copy link
Contributor Author

The intention is to make this PR for flang-rt only. As discussed with @daltenty, I remove the NFC-change of adding an overriding getCompilerRT in AIX.cpp as it actually breaches into clang space.

@DanielCChen DanielCChen force-pushed the daniel_driver branch 2 times, most recently from f812a8a to b63b099 Compare March 25, 2025 16:36
@DanielCChen
Copy link
Contributor Author

@Meinersbur @MaskRay and all other reviewers,

PR #132821 enables LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. As a result, I no longer need to "force" AIX to use os_dirname for flang-rt.

The change in this PR is intact because I re-used the same code to handle the option either ON or OFF.

I updated the description of this PR to reflect that.

I will undo PR #130875 and add a LIT test to this PR as soon as PR #132821 lands.

Sorry about the change or direction.

@DanielCChen DanielCChen changed the title [flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX [flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX and LoP Apr 3, 2025
Copy link
Member

@daltenty daltenty left a comment

Choose a reason for hiding this comment

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

LGTM (I'd generalize this more in a follow on though, there's no reason for this to be limited to LoP)

@DanielCChen DanielCChen merged commit 2080334 into llvm:main Apr 3, 2025
11 checks passed
@DanielCChen DanielCChen deleted the daniel_driver branch April 3, 2025 15:21
@DanielCChen
Copy link
Contributor Author

LGTM (I'd generalize this more in a follow on though, there's no reason for this to be limited to LoP)

Thanks for the suggestion! I will investigate that and post a separate PR.

@klausler
Copy link
Contributor

klausler commented Apr 3, 2025

I think that this patch broke our x86-64 builds with a test failure in Driver/linker-flags.f90.

FAIL: Flang :: Driver/linker-flags.f90 (1 of 3428)
******************** TEST 'Flang :: Driver/linker-flags.f90' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/pklausler/llvm-project/build/x86/gcc/9.3.0/Release/shared/bin/flang -### --target=ppc64le-linux-gnu /home/pklausler/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /home/pklausler/llvm-project/build/x86/gcc/9.3.0/Release/shared/bin/FileCheck /home/pklausler/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,UNIX-F128LIBQUADMATH # RUN: at line 5
+ /home/pklausler/llvm-project/build/x86/gcc/9.3.0/Release/shared/bin/flang -### --target=ppc64le-linux-gnu /home/pklausler/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /home/pklausler/llvm-project/build/x86/gcc/9.3.0/Release/shared/bin/FileCheck /home/pklausler/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,UNIX-F128LIBQUADMATH
/home/pklausler/llvm-project/flang/test/Driver/linker-flags.f90:34:30: error: UNIX-F128LIBQUADMATH-SAME: expected string not found in input
! UNIX-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "--as-needed" "-lquadmath" "--no-as-needed"
                             ^
<stdin>:7:265: note: scanning from here
 "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf64lppc" "-pie" "-dynamic-linker" "/lib64/ld64.so.2" "-o" "a.out" "Scrt1.o" "crti.o" "crtbeginS.o" "-L/lib/../lib64" "-L/usr/lib64" "-L/lib" "-L/usr/lib" "/tmp/lit-tmp-09dnh4a2/hello-b61698.o" "-L/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/lib" "-lflang_rt.runtime" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "crtendS.o" "crtn.o"
                                                                                                                                                                                                                                                                        ^
<stdin>:7:409: note: possible intended match here
 "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf64lppc" "-pie" "-dynamic-linker" "/lib64/ld64.so.2" "-o" "a.out" "Scrt1.o" "crti.o" "crtbeginS.o" "-L/lib/../lib64" "-L/usr/lib64" "-L/lib" "-L/usr/lib" "/tmp/lit-tmp-09dnh4a2/hello-b61698.o" "-L/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/lib" "-lflang_rt.runtime" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "crtendS.o" "crtn.o"
                                                                                                                                                                                                                                                                                                                                                                                                                        ^

Input file: <stdin>
Check file: /home/pklausler/llvm-project/flang/test/Driver/linker-flags.f90

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: flang version 21.0.0git (git@github.com:klausler/llvm-project.git f3945874f06884a6a8fecb116be79024b22e88ab) 
           2: Target: ppc64le-unknown-linux-gnu 
           3: Thread model: posix 
           4: InstalledDir: /local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/bin 
           5: Build config: +assertions 
           6:  "/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/bin/flang" "-fc1" "-triple" "ppc64le-unknown-linux-gnu" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "ppc64le" "-resource-dir" "/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/lib/clang/21" "-mframe-pointer=all" "-o" "/tmp/lit-tmp-09dnh4a2/hello-b61698.o" "-x" "f95-cpp-input" "/home/pklausler/llvm-project/flang/test/Driver/Inputs/hello.f90" 
           7:  "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf64lppc" "-pie" "-dynamic-linker" "/lib64/ld64.so.2" "-o" "a.out" "Scrt1.o" "crti.o" "crtbeginS.o" "-L/lib/../lib64" "-L/usr/lib64" "-L/lib" "-L/usr/lib" "/tmp/lit-tmp-09dnh4a2/hello-b61698.o" "-L/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/lib" "-lflang_rt.runtime" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "crtendS.o" "crtn.o" 
same:34'0                                                                                                                                                                                                                                                                             X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
same:34'1                                                                                                                                                                                                                                                                                                                                                                                                                             ?                                                                                       possible intended match
>>>>>>

--

@DanielCChen
Copy link
Contributor Author

Thanks! I will take a look.

@DanielCChen
Copy link
Contributor Author

@klausler It seems it passes for me on LoP after I pull the latest source. Could you please try again and see if you still run into the failure?

-- Testing: 1 tests, 1 workers --
PASS: Flang :: Driver/linker-flags.f90 (1 of 1)
Exit Code: 0

Command Output (stderr):
--
/scratch/cdchen/FLANG/build/bin/flang -### --target=ppc64le-linux-gnu /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,UNIX-F128NONE # RUN: at line 5
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=ppc64le-linux-gnu /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,UNIX-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### --target=aarch64-apple-darwin /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,DARWIN,DARWIN-F128NONE # RUN: at line 6
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=aarch64-apple-darwin /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,DARWIN,DARWIN-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### --target=sparc-sun-solaris2.11 /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,SOLARIS-F128NONE # RUN: at line 7
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=sparc-sun-solaris2.11 /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,SOLARIS-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-freebsd /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,BSD,BSD-F128NONE # RUN: at line 8
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-freebsd /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,BSD,BSD-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-netbsd /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,BSD,BSD-F128NONE # RUN: at line 9
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-netbsd /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,BSD,BSD-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-openbsd /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,BSD,BSD-F128NONE # RUN: at line 10
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-openbsd /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,BSD,BSD-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-dragonfly /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,BSD,BSD-F128NONE # RUN: at line 11
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-dragonfly /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,BSD,BSD-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-haiku /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,HAIKU,HAIKU-F128NONE # RUN: at line 12
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-unknown-haiku /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,HAIKU,HAIKU-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-windows-gnu /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,MINGW,MINGW-F128NONE # RUN: at line 13
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=x86_64-windows-gnu /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,MINGW,MINGW-F128NONE
/scratch/cdchen/FLANG/build/bin/flang -### -rtlib=compiler-rt --target=aarch64-linux-gnu /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,COMPILER-RT # RUN: at line 14
+ /scratch/cdchen/FLANG/build/bin/flang -### -rtlib=compiler-rt --target=aarch64-linux-gnu /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,COMPILER-RT
/scratch/cdchen/FLANG/build/bin/flang -### --target=aarch64-windows-msvc -fuse-ld= /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,MSVC --implicit-check-not oldnames # RUN: at line 19
+ /scratch/cdchen/FLANG/build/bin/flang -### --target=aarch64-windows-msvc -fuse-ld= /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /scratch/cdchen/FLANG/build/bin/FileCheck /scratch/cdchen/FLANG/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,MSVC --implicit-check-not oldnames

--

********************

Testing Time: 0.11s

Total Discovered Tests: 1
  Passed: 1 (100.00%)

@klausler
Copy link
Contributor

klausler commented Apr 3, 2025

Still fails in my x86-64 environment.

@DanielCChen
Copy link
Contributor Author

DanielCChen commented Apr 3, 2025

Still fail at the same ppc64le-unknown-linux-gnu target? The reason I am asking is that I was able to reproduce the failure at line 44. ! BSD-SAME: -lexecinfo, but all passed with the latest source.

@klausler
Copy link
Contributor

klausler commented Apr 3, 2025

FAIL: Flang :: Driver/linker-flags.f90 (1 of 3430)
******************** TEST 'Flang :: Driver/linker-flags.f90' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/pklausler/llvm-project/build/x86/gcc/9.3.0/Release/shared/bin/flang -### --target=ppc64le-linux-gnu /home/pklausler/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /home/pklausler/llvm-project/build/x86/gcc/9.3.0/Release/shared/bin/FileCheck /home/pklausler/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,UNIX-F128LIBQUADMATH # RUN: at line 5
+ /home/pklausler/llvm-project/build/x86/gcc/9.3.0/Release/shared/bin/flang -### --target=ppc64le-linux-gnu /home/pklausler/llvm-project/flang/test/Driver/Inputs/hello.f90
+ /home/pklausler/llvm-project/build/x86/gcc/9.3.0/Release/shared/bin/FileCheck /home/pklausler/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,UNIX,UNIX-F128LIBQUADMATH
/home/pklausler/llvm-project/flang/test/Driver/linker-flags.f90:34:30: error: UNIX-F128LIBQUADMATH-SAME: expected string not found in input
! UNIX-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "--as-needed" "-lquadmath" "--no-as-needed"
                             ^
<stdin>:7:265: note: scanning from here
 "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf64lppc" "-pie" "-dynamic-linker" "/lib64/ld64.so.2" "-o" "a.out" "Scrt1.o" "crti.o" "crtbeginS.o" "-L/lib/../lib64" "-L/usr/lib64" "-L/lib" "-L/usr/lib" "/tmp/lit-tmp-lj2vq0ix/hello-bf8634.o" "-L/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/lib" "-lflang_rt.runtime" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "crtendS.o" "crtn.o"
                                                                                                                                                                                                                                                                        ^
<stdin>:7:409: note: possible intended match here
 "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf64lppc" "-pie" "-dynamic-linker" "/lib64/ld64.so.2" "-o" "a.out" "Scrt1.o" "crti.o" "crtbeginS.o" "-L/lib/../lib64" "-L/usr/lib64" "-L/lib" "-L/usr/lib" "/tmp/lit-tmp-lj2vq0ix/hello-bf8634.o" "-L/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/lib" "-lflang_rt.runtime" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "crtendS.o" "crtn.o"
                                                                                                                                                                                                                                                                                                                                                                                                                        ^

Input file: <stdin>
Check file: /home/pklausler/llvm-project/flang/test/Driver/linker-flags.f90

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: flang version 21.0.0git (git@github.com:klausler/llvm-project.git 8cc63d9cd4f14c4a4b444401e5f77c0a9e500a3f) 
           2: Target: ppc64le-unknown-linux-gnu 
           3: Thread model: posix 
           4: InstalledDir: /local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/bin 
           5: Build config: +assertions 
           6:  "/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/bin/flang" "-fc1" "-triple" "ppc64le-unknown-linux-gnu" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "ppc64le" "-resource-dir" "/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/lib/clang/21" "-mframe-pointer=all" "-o" "/tmp/lit-tmp-lj2vq0ix/hello-bf8634.o" "-x" "f95-cpp-input" "/home/pklausler/llvm-project/flang/test/Driver/Inputs/hello.f90" 
           7:  "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf64lppc" "-pie" "-dynamic-linker" "/lib64/ld64.so.2" "-o" "a.out" "Scrt1.o" "crti.o" "crtbeginS.o" "-L/lib/../lib64" "-L/usr/lib64" "-L/lib" "-L/usr/lib" "/tmp/lit-tmp-lj2vq0ix/hello-bf8634.o" "-L/local/home/pklausler/build/llvm-project/x86/gcc/9.3.0/Release/shared/lib" "-lflang_rt.runtime" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "crtendS.o" "crtn.o" 
same:34'0                                                                                                                                                                                                                                                                             X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
same:34'1                                                                                                                                                                                                                                                                                                                                                                                                                             ?                                                                                       possible intended match
>>>>>>

--

vzakhari added a commit to vzakhari/llvm-project that referenced this pull request Apr 3, 2025
After llvm#131041, the F128 libraries are not linked for PPC targets even when
the driver is built with FLANG_RUNTIME_F128_MATH_LIB.
@DanielCChen
Copy link
Contributor Author

Seems PR #134320 is fixing this.

vzakhari added a commit that referenced this pull request Apr 3, 2025
After #131041, the F128 libraries are not linked for PPC targets even
when the driver is built with FLANG_RUNTIME_F128_MATH_LIB.
DanielCChen added a commit that referenced this pull request Apr 13, 2025
…e.a. (#134362)

The PR is to generalize the re-use of the `compilerRT` code of adding
the path of `libflang_rt.runtime.a (so)` from AIX and LoP only to all
platforms via a new function `addFlangRTLibPath`.

It also added `-static-libflangrt` and `-shared-libflangrt` compiler
options to allow users choosing which `flang-rt` to link to. It defaults
to shared `flang-rt`, which is consistent with the linker behavior,
except on AIX, it defaults to static.

Also, PR #134320 exposed an issue in PR #131041 that the the overriding
`addFortranRuntimeLibs` is missing the link to `libquadmath`. This PR
also fixed that and restored the test case that PR #131041 broke.
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…e.a. (llvm#134362)

The PR is to generalize the re-use of the `compilerRT` code of adding
the path of `libflang_rt.runtime.a (so)` from AIX and LoP only to all
platforms via a new function `addFlangRTLibPath`.

It also added `-static-libflangrt` and `-shared-libflangrt` compiler
options to allow users choosing which `flang-rt` to link to. It defaults
to shared `flang-rt`, which is consistent with the linker behavior,
except on AIX, it defaults to static.

Also, PR llvm#134320 exposed an issue in PR llvm#131041 that the the overriding
`addFortranRuntimeLibs` is missing the link to `libquadmath`. This PR
also fixed that and restored the test case that PR llvm#131041 broke.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants