[clang] [flang] [clang][Driver] Add RPATH by default (PR #115286)

Paul Osmialowski via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 7 01:46:06 PST 2024


https://github.com/pawosm-arm created https://github.com/llvm/llvm-project/pull/115286

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.

>From f50c075b706b691bedab835ad66330741e08fe76 Mon Sep 17 00:00:00 2001
From: Paul Osmialowski <pawel.osmialowski at arm.com>
Date: Thu, 7 Nov 2024 09:33:54 +0000
Subject: [PATCH] [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.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp       | 2 +-
 clang/test/Driver/arch-specific-libdir-rpath.c   | 4 ++--
 flang/test/Driver/arch-specific-libdir-rpath.f95 | 5 ++---
 flang/test/Driver/linker-flags.f90               | 3 ++-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index ca06fb115dfa11..6983ab4567f9a6 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1183,7 +1183,7 @@ void tools::addOpenMPRuntimeLibraryPath(const ToolChain &TC,
 void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
                                  ArgStringList &CmdArgs) {
   if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
-                    options::OPT_fno_rtlib_add_rpath, false))
+                    options::OPT_fno_rtlib_add_rpath, true))
     return;
 
   SmallVector<std::string> CandidateRPaths(TC.getArchSpecificLibPaths());
diff --git a/clang/test/Driver/arch-specific-libdir-rpath.c b/clang/test/Driver/arch-specific-libdir-rpath.c
index 1e6bbbc5929ac2..3277da9287233f 100644
--- a/clang/test/Driver/arch-specific-libdir-rpath.c
+++ b/clang/test/Driver/arch-specific-libdir-rpath.c
@@ -2,11 +2,11 @@
 // {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath'
 //
 // Test the default behavior when neither -frtlib-add-rpath nor
-// -fno-rtlib-add-rpath is specified, which is to skip -rpath
+// -fno-rtlib-add-rpath is specified, which is to add -rpath
 // RUN: %clang %s -### --target=x86_64-linux \
 // RUN:     -fsanitize=address -shared-libasan \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,RPATH-X86_64 %s
 //
 // Test that -rpath is not added under -fno-rtlib-add-rpath even if other
 // conditions are met.
diff --git a/flang/test/Driver/arch-specific-libdir-rpath.f95 b/flang/test/Driver/arch-specific-libdir-rpath.f95
index 23fb52abfbd574..5ce57dab96c260 100644
--- a/flang/test/Driver/arch-specific-libdir-rpath.f95
+++ b/flang/test/Driver/arch-specific-libdir-rpath.f95
@@ -1,12 +1,11 @@
-! REQUIRES: x86-registered-target
 ! Test that the driver adds an arch-specific subdirectory in
 ! {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath'
 !
 ! Test the default behavior when neither -frtlib-add-rpath nor
-! -fno-rtlib-add-rpath is specified, which is to skip -rpath
+! -fno-rtlib-add-rpath is specified, which is to add -rpath
 ! RUN: %flang %s -### --target=x86_64-linux \
 ! RUN:     -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_arch_subdir 2>&1 \
-! RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
+! RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,RPATH-X86_64 %s
 !
 ! Test that -rpath is not added under -fno-rtlib-add-rpath
 ! RUN: %flang %s -### --target=x86_64-linux \
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index ac9500d7c45cec..c4ee26c5dacab8 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -33,7 +33,8 @@
 ! SOLARIS-F128NONE-NOT: FortranFloat128Math
 ! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
 ! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
-! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal" "-lm"
+! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal"
+! UNIX-SAME: "-lm"
 ! COMPILER-RT: "{{.*}}{{\\|/}}libclang_rt.builtins.a"
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"



More information about the cfe-commits mailing list