Skip to content

Commit f50c075

Browse files
committed
[clang][Driver] Add RPATH by default
The `-frtlib-add-rpath` is very convenient when linking against various runtimes (OpenMP, Fortran, sanitizers), so much so we could argue that this should be a default behavior. This patch makes adding RPATH the default behavior that could be prevented by explicitly using the `-fno-rtlib-add-rpath` flag.
1 parent e3a0775 commit f50c075

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ void tools::addOpenMPRuntimeLibraryPath(const ToolChain &TC,
11831183
void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
11841184
ArgStringList &CmdArgs) {
11851185
if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
1186-
options::OPT_fno_rtlib_add_rpath, false))
1186+
options::OPT_fno_rtlib_add_rpath, true))
11871187
return;
11881188

11891189
SmallVector<std::string> CandidateRPaths(TC.getArchSpecificLibPaths());

clang/test/Driver/arch-specific-libdir-rpath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath'
33
//
44
// Test the default behavior when neither -frtlib-add-rpath nor
5-
// -fno-rtlib-add-rpath is specified, which is to skip -rpath
5+
// -fno-rtlib-add-rpath is specified, which is to add -rpath
66
// RUN: %clang %s -### --target=x86_64-linux \
77
// RUN: -fsanitize=address -shared-libasan \
88
// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
9-
// RUN: | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
9+
// RUN: | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,RPATH-X86_64 %s
1010
//
1111
// Test that -rpath is not added under -fno-rtlib-add-rpath even if other
1212
// conditions are met.

flang/test/Driver/arch-specific-libdir-rpath.f95

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
! REQUIRES: x86-registered-target
21
! Test that the driver adds an arch-specific subdirectory in
32
! {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath'
43
!
54
! Test the default behavior when neither -frtlib-add-rpath nor
6-
! -fno-rtlib-add-rpath is specified, which is to skip -rpath
5+
! -fno-rtlib-add-rpath is specified, which is to add -rpath
76
! RUN: %flang %s -### --target=x86_64-linux \
87
! 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
8+
! RUN: | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,RPATH-X86_64 %s
109
!
1110
! Test that -rpath is not added under -fno-rtlib-add-rpath
1211
! RUN: %flang %s -### --target=x86_64-linux \

flang/test/Driver/linker-flags.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
! SOLARIS-F128NONE-NOT: FortranFloat128Math
3434
! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
3535
! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
36-
! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal" "-lm"
36+
! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal"
37+
! UNIX-SAME: "-lm"
3738
! COMPILER-RT: "{{.*}}{{\\|/}}libclang_rt.builtins.a"
3839

3940
! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"

0 commit comments

Comments
 (0)