Skip to content

Conversation

@kwk
Copy link
Contributor

@kwk kwk commented Oct 31, 2025

When there are multiple gcc versions installed, we want flang to be able
to find the right one based on the triple. Here's flang selecting an
unwanted gcc candidate installation, namely
/usr/lib/gcc/x86_64-linux-gnu/15:

~/src/llvm-project/main/build-RelWithDebInfo > ./bin/flang -v
flang version 22.0.0custombuild
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /home/fedora/src/llvm-project/main/build-RelWithDebInfo/bin
System configuration file directory: /etc/clang/
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/15
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/15
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

When passing --gcc-triple=x86_64-redhat-linux we get the desired gcc
candidate installation:

~/src/llvm-project/main/build-RelWithDebInfo > ./bin/flang --gcc-triple=x86_64-redhat-linux -v
flang version 22.0.0custombuild
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /home/fedora/src/llvm-project/main/build-RelWithDebInfo/bin
System configuration file directory: /etc/clang/
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
  • Test: LIT_FILTER="Flang :: Driver/gcc-triple.f90" ninja check-flang
    • Copied flang/test/Driver/Inputs/fedora_39_tree from clang/test/Driver/Inputs/fedora_39_tree.
    • Testing what default triple is selected when two are possible.
    • Testing that we can select an existing triple.
    • Testing that triple is not selected if it doesn't exist.

@kwk kwk self-assigned this Oct 31, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Oct 31, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2025

@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-clang

Author: Konrad Kleine (kwk)

Changes

When there are multiple gcc versions installed, we want flang to be able to find the right one based on the triple. Here's flang selecting an unwanted gcc candidate installation, namely
/usr/lib/gcc/x86_64-linux-gnu/15:

~/src/llvm-project/main/build-RelWithDebInfo > ./bin/flang -v
flang version 22.0.0custombuild
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /home/fedora/src/llvm-project/main/build-RelWithDebInfo/bin
System configuration file directory: /etc/clang/
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/15
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/15
Candidate multilib: .;@<!-- -->m64
Candidate multilib: 32;@<!-- -->m32
Selected multilib: .;@<!-- -->m64

When passing --gcc-triple=x86_64-redhat-linux we get the desired gcc candidate installation, namely /usr/lib/gcc/x86_64-redhat-linux/15:

~/src/llvm-project/main/build-RelWithDebInfo &gt; ./bin/flang --gcc-triple=x86_64-redhat-linux -v
flang version 22.0.0custombuild
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /home/fedora/src/llvm-project/main/build-RelWithDebInfo/bin
System configuration file directory: /etc/clang/
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Candidate multilib: .;@<!-- -->m64
Candidate multilib: 32;@<!-- -->m32
Selected multilib: .;@<!-- -->m64

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

1 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+1)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index cb5cb888c6da7..8b728e9acbb8b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -741,6 +741,7 @@ def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>,
     "Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
     "Flang will use the GCC installation with the largest version">;
 def gcc_triple_EQ : Joined<["--"], "gcc-triple=">,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Search for the GCC installation with the specified triple.">;
 def CC : Flag<["-"], "CC">, Visibility<[ClangOption, CC1Option]>,
   Group<Preprocessor_Group>,

@kwk kwk changed the title Bing --gcc-triple to flang Bring --gcc-triple to flang Oct 31, 2025
Copy link
Contributor

@tuliom tuliom left a comment

Choose a reason for hiding this comment

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

I believe it's important to add a test.
Similar to clang/test/Driver/gcc-triple.cpp.

@kwk kwk force-pushed the bring-gcc-triple-to-flang branch from 8509a3c to 4b5f74e Compare October 31, 2025 22:08
@llvmbot llvmbot added the flang Flang issues not falling into any other category label Oct 31, 2025
@kwk kwk force-pushed the bring-gcc-triple-to-flang branch from 4b5f74e to 9db125a Compare October 31, 2025 22:43
@kwk
Copy link
Contributor Author

kwk commented Oct 31, 2025

I believe it's important to add a test. Similar to clang/test/Driver/gcc-triple.cpp.

@tuliom, thank you for pointing this out. I've added tests now.

@kwk kwk force-pushed the bring-gcc-triple-to-flang branch from 9db125a to bf5e3d0 Compare October 31, 2025 23:53
Copy link
Contributor

@tarunprabhu tarunprabhu left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. Barring some minor changes, this LGTM.

Please change the title to [flang][driver] Bring --gcc-triple to flang. This should also be the first line of the commit message.

Out of curiosity, did the absence of --gcc-triple cause any problems? Did you file an issue?

When there are multiple gcc versions installed, we want `flang` to be able
to find the right one based on the triple. Here's `flang` selecting an
unwanted `gcc` candidate installation, namely
`/usr/lib/gcc/x86_64-linux-gnu/15`:

```
~/src/llvm-project/main/build-RelWithDebInfo > ./bin/flang -v
flang version 22.0.0custombuild
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /home/fedora/src/llvm-project/main/build-RelWithDebInfo/bin
System configuration file directory: /etc/clang/
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/15
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/15
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
```

When passing `--gcc-triple=x86_64-redhat-linux` we get the desired gcc
candidate installation:

```
~/src/llvm-project/main/build-RelWithDebInfo > ./bin/flang --gcc-triple=x86_64-redhat-linux -v
flang version 22.0.0custombuild
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /home/fedora/src/llvm-project/main/build-RelWithDebInfo/bin
System configuration file directory: /etc/clang/
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/15
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
```

* Test: `LIT_FILTER="Flang :: Driver/gcc-triple.f90" ninja check-flang`
  * Copied `flang/test/Driver/Inputs/fedora_39_tree` from `clang/test/Driver/Inputs/fedora_39_tree`.
  * Testing what default triple is selected when two are given.
  * Testing that we can select an existing triple.
  * Testing that triple is not selected if it doesn't exist.
@kwk kwk force-pushed the bring-gcc-triple-to-flang branch from bf5e3d0 to d1a24f8 Compare November 3, 2025 15:22
@kwk kwk changed the title Bring --gcc-triple to flang [flang][driver] Bring --gcc-triple to flang Nov 3, 2025
@kwk
Copy link
Contributor Author

kwk commented Nov 3, 2025

Thanks for working on this. Barring some minor changes, this LGTM.

@tarunprabhu Thank you for reviewing this!

Please change the title to [flang][driver] Bring --gcc-triple to flang. This should also be the first line of the commit message.

Done.

Out of curiosity, did the absence of --gcc-triple cause any problems?

Yes, it caused a problem. In case of multiple gcc installations candidate, we couldn't select the right one by using a triple but instead had to specify the --gcc-install-dir which includes the gcc version information. In case the major gcc version changes we would have to rebuild llvm which isn't what we wanted.

Did you file an issue?

No I didn't. Is that required in this case? Want me to create one?

@kwk kwk enabled auto-merge (squash) November 3, 2025 15:39
@kwk kwk removed the request for review from banach-space November 3, 2025 15:45
@kwk kwk merged commit bf5332c into llvm:main Nov 3, 2025
10 checks passed
@tarunprabhu
Copy link
Contributor

Out of curiosity, did the absence of --gcc-triple cause any problems?

Yes, it caused a problem. In case of multiple gcc installations candidate, we couldn't select the right one by using a triple but instead had to specify the --gcc-install-dir which includes the gcc version information. In case the major gcc version changes we would have to rebuild llvm which isn't what we wanted.

Got it.

No I didn't. Is that required in this case? Want me to create one?

Not required at all. I was just wondering if I missed something that you might have filed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category flang:driver flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants