Skip to content

Commit 4b5f74e

Browse files
committed
Bring --gcc-triple to flang
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.
1 parent 98ceb45 commit 4b5f74e

File tree

10 files changed

+20
-0
lines changed

10 files changed

+20
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>,
741741
"Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
742742
"Flang will use the GCC installation with the largest version">;
743743
def gcc_triple_EQ : Joined<["--"], "gcc-triple=">,
744+
Visibility<[ClangOption, FlangOption]>,
744745
HelpText<"Search for the GCC installation with the specified triple.">;
745746
def CC : Flag<["-"], "CC">, Visibility<[ClangOption, CC1Option]>,
746747
Group<Preprocessor_Group>,

flang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtbegin.o

Whitespace-only changes.

flang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtend.o

Whitespace-only changes.

flang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crti.o

Whitespace-only changes.

flang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtn.o

Whitespace-only changes.

flang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13/crtbegin.o

Whitespace-only changes.

flang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13/crtend.o

Whitespace-only changes.

flang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13/crti.o

Whitespace-only changes.

flang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13/crtn.o

Whitespace-only changes.

flang/test/Driver/gcc-triple.f90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
!! UNSUPPORTED: system-windows
2+
3+
!! Test that --gcc-triple option is working as expected.
4+
5+
! RUN: %flang -v --sysroot=%S/Inputs/fedora_39_tree 2>&1 | FileCheck %s --dump-input=always --check-prefix=DEFAULT_TRIPLE
6+
! DEFAULT_TRIPLE: Target: x86_64-redhat-linux-gnu
7+
! DEFAULT_TRIPLE: {{^}}Found candidate GCC installation:
8+
! DEFAULT_TRIPLE: fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13
9+
! DEFAULT_TRIPLE: {{^}}Found candidate GCC installation:
10+
! DEFAULT_TRIPLE: fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13
11+
! DEFAULT_TRIPLE: {{^}}Selected GCC installation:
12+
! DEFAULT_TRIPLE: fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13
13+
14+
! RUN: %flang -v --sysroot=%S/Inputs/fedora_39_tree --gcc-triple=x86_64-redhat-linux 2>&1 | FileCheck %s --check-prefix=TRIPLE_EXISTS
15+
! TRIPLE_EXISTS: {{^}}Selected GCC installation:
16+
! TRIPLE_EXISTS: fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13
17+
18+
! RUN: %flang -v --sysroot=%S/Inputs/fedora_39_tree --gcc-triple=x86_64-foo-linux 2>&1 | FileCheck %s --check-prefix=TRIPLE_DOES_NOT_EXISTS
19+
! TRIPLE_DOES_NOT_EXISTS-NOT: x86_64-foo-linux

0 commit comments

Comments
 (0)