Skip to content

Commit 469758c

Browse files
[Flang] Add options frtlib-add-rpath and resource-dir (#88280)
frtlib-add-rpath option is used by clang and should also be visible in flang. It is already handled by the toolchains used by both clang and flang. Reported issue: #82553
1 parent b502dc5 commit 469758c

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5464,21 +5464,23 @@ def rdynamic : Flag<["-"], "rdynamic">, Group<Link_Group>,
54645464
Visibility<[ClangOption, FlangOption]>;
54655465
def resource_dir : Separate<["-"], "resource-dir">,
54665466
Flags<[NoXarchOption, HelpHidden]>,
5467-
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
5467+
Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption, FC1Option]>,
54685468
HelpText<"The directory which holds the compiler resource files">,
54695469
MarshallingInfoString<HeaderSearchOpts<"ResourceDir">>;
54705470
def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
5471-
Visibility<[ClangOption, CLOption, DXCOption]>,
5471+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
54725472
Alias<resource_dir>;
54735473
def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group<Link_Group>,
54745474
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
54755475
def rtlib_EQ : Joined<["-", "--"], "rtlib=">, Visibility<[ClangOption, CLOption]>,
54765476
HelpText<"Compiler runtime library to use">;
54775477
def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, Flags<[NoArgumentUnused]>,
5478+
Visibility<[ClangOption, FlangOption]>,
54785479
HelpText<"Add -rpath with architecture-specific resource directory to the linker flags. "
54795480
"When --hip-link is specified, also add -rpath with HIP runtime library directory to the linker flags">;
54805481
def fno_rtlib_add_rpath: Flag<["-"], "fno-rtlib-add-rpath">,
54815482
Flags<[NoArgumentUnused]>,
5483+
Visibility<[ClangOption, FlangOption]>,
54825484
HelpText<"Do not add -rpath with architecture-specific resource directory to the linker flags. "
54835485
"When --hip-link is specified, do not add -rpath with HIP runtime library directory to the linker flags">;
54845486
def offload_add_rpath: Flag<["--"], "offload-add-rpath">,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,10 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
786786
}
787787
}
788788

789+
// Pass the path to compiler resource files.
790+
CmdArgs.push_back("-resource-dir");
791+
CmdArgs.push_back(D.ResourceDir.c_str());
792+
789793
// Offloading related options
790794
addOffloadOptions(C, Inputs, JA, Args, CmdArgs);
791795

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! REQUIRES: x86-registered-target
2+
! Test that the driver adds an arch-specific subdirectory in
3+
! {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath'
4+
!
5+
! Test the default behavior when neither -frtlib-add-rpath nor
6+
! -fno-rtlib-add-rpath is specified, which is to skip -rpath
7+
! RUN: %flang %s -### --target=x86_64-linux \
8+
! RUN: -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_arch_subdir 2>&1 \
9+
! RUN: | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
10+
!
11+
! Test that -rpath is not added under -fno-rtlib-add-rpath
12+
! RUN: %flang %s -### --target=x86_64-linux \
13+
! RUN: -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_arch_subdir \
14+
! RUN: -fno-rtlib-add-rpath 2>&1 \
15+
! RUN: | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
16+
!
17+
! Test that -rpath is added
18+
!
19+
! Add LIBPATH, RPATH for OpenMP
20+
!
21+
! RUN: %flang %s -### --target=x86_64-linux -fopenmp \
22+
! RUN: -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_arch_subdir \
23+
! RUN: -frtlib-add-rpath 2>&1 \
24+
! RUN: | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,RPATH-X86_64 %s
25+
!
26+
!
27+
! RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
28+
!
29+
! LIBPATH-X86_64: -L[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}
30+
! RPATH-X86_64: "-rpath" "[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}"
31+
!
32+
! NO-RPATH-X86_64-NOT: "-rpath" "[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}"

flang/test/Driver/driver-help-hidden.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
! CHECK-NEXT: -fno-lto Disable LTO mode (default)
6969
! CHECK-NEXT: -fno-ppc-native-vector-element-order
7070
! CHECK-NEXT: Specifies PowerPC non-native vector element order
71+
! CHECK-NEXT: -fno-rtlib-add-rpath Do not add -rpath with architecture-specific resource directory to the linker flags. When --hip-link is specified, do not add -rpath with HIP runtime library directory to the linker flags
7172
! CHECK-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
7273
! CHECK-NEXT: -fno-stack-arrays Allocate array temporaries on the heap (default)
7374
! CHECK-NEXT: -fno-version-loops-for-stride
@@ -93,6 +94,7 @@
9394
! CHECK-NEXT: Specifies PowerPC native vector element order (default)
9495
! CHECK-NEXT: -freciprocal-math Allow division operations to be reassociated
9596
! CHECK-NEXT: -fropi Generate read-only position independent code (ARM only)
97+
! CHECK-NEXT: -frtlib-add-rpath Add -rpath with architecture-specific resource directory to the linker flags. When --hip-link is specified, also add -rpath with HIP runtime library directory to the linker flags
9698
! CHECK-NEXT: -frwpi Generate read-write position independent code (ARM only)
9799
! CHECK-NEXT: -fsave-optimization-record=<format>
98100
! CHECK-NEXT: Generate an optimization record file in a specific format
@@ -145,6 +147,7 @@
145147
! CHECK-NEXT: -print-target-triple Print the normalized target triple
146148
! CHECK-NEXT: -pthread Support POSIX threads in generated code
147149
! CHECK-NEXT: -P Disable linemarker output in -E mode
150+
! CHECK-NEXT: -resource-dir <value> The directory which holds the compiler resource files
148151
! CHECK-NEXT: -Rpass-analysis=<value> Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
149152
! CHECK-NEXT: -Rpass-missed=<value> Report missed transformations by optimization passes whose name matches the given POSIX regular expression
150153
! CHECK-NEXT: -Rpass=<value> Report transformations performed by optimization passes whose name matches the given POSIX regular expression

flang/test/Driver/driver-help.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
! HELP-NEXT: -fno-lto Disable LTO mode (default)
6161
! HELP-NEXT: -fno-ppc-native-vector-element-order
6262
! HELP-NEXT: Specifies PowerPC non-native vector element order
63+
! HELP-NEXT: -fno-rtlib-add-rpath Do not add -rpath with architecture-specific resource directory to the linker flags. When --hip-link is specified, do not add -rpath with HIP runtime library directory to the linker flags
6364
! HELP-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
6465
! HELP-NEXT: -fno-stack-arrays Allocate array temporaries on the heap (default)
6566
! HELP-NEXT: -fno-version-loops-for-stride
@@ -81,6 +82,7 @@
8182
! HELP-NEXT: Specifies PowerPC native vector element order (default)
8283
! HELP-NEXT: -freciprocal-math Allow division operations to be reassociated
8384
! HELP-NEXT: -fropi Generate read-only position independent code (ARM only)
85+
! HELP-NEXT: -frtlib-add-rpath Add -rpath with architecture-specific resource directory to the linker flags. When --hip-link is specified, also add -rpath with HIP runtime library directory to the linker flags
8486
! HELP-NEXT: -frwpi Generate read-write position independent code (ARM only)
8587
! HELP-NEXT: -fsave-optimization-record=<format>
8688
! HELP-NEXT: Generate an optimization record file in a specific format

0 commit comments

Comments
 (0)