[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

Tarun Prabhu via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 21 06:48:01 PDT 2023


https://github.com/tarunprabhu updated https://github.com/llvm/llvm-project/pull/66702

>From 3302fb4937d75c0920e7bcf8f215e12fbe770a36 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun at lanl.gov>
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/2] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +++++--
 flang/test/Driver/linker-flags.f90    | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..bf4c76d4555d152 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5165,7 +5165,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias<resource_dir>;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group<Link_Group>;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group<Link_Group>,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, Flags<[NoArgumentUnused]>,
@@ -5216,7 +5217,8 @@ def segs__read__only__addr : Separate<["-"], "segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group<Link_Group>;
+def shared : Flag<["-", "--"], "shared">, Group<Link_Group>,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group<Link_Group>;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5226,6 +5228,7 @@ def start_no_unused_arguments : Flag<["--"], "start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group<Link_Group>,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..9a9ec5d28acb9c7 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From 653d215a59fc1ab71784776d52a32005359ee93e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun at lanl.gov>
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/2] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 9a9ec5d28acb9c7..c9cc851fa607ae8 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -54,15 +54,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 



More information about the cfe-commits mailing list