[clang] 5f74671 - [flang][Driver] Support -Xlinker in flang (#107472)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 11:10:21 PDT 2024


Author: Tarun Prabhu
Date: 2024-09-09T12:10:16-06:00
New Revision: 5f74671c85877e03622e8d308aee15ed73ccee7c

URL: https://github.com/llvm/llvm-project/commit/5f74671c85877e03622e8d308aee15ed73ccee7c
DIFF: https://github.com/llvm/llvm-project/commit/5f74671c85877e03622e8d308aee15ed73ccee7c.diff

LOG: [flang][Driver] Support -Xlinker in flang (#107472)

Partially addresses: https://github.com/llvm/llvm-project/issues/89888

Added: 
    flang/test/Driver/xlinker.f90

Modified: 
    clang/include/clang/Driver/Options.td

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index bf8569fc780d6a..f78032255f036f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1051,6 +1051,7 @@ def z : Separate<["-"], "z">, Flags<[LinkerInput]>,
 def offload_link : Flag<["--"], "offload-link">, Group<Link_Group>,
   HelpText<"Use the new offloading linker to perform the link job.">;
 def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
+  Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>,
   HelpText<"Pass <arg> to the linker">, MetaVarName<"<arg>">,
   Group<Link_Group>;
 def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">,

diff  --git a/flang/test/Driver/xlinker.f90 b/flang/test/Driver/xlinker.f90
new file mode 100644
index 00000000000000..feafadcfcec452
--- /dev/null
+++ b/flang/test/Driver/xlinker.f90
@@ -0,0 +1,21 @@
+! RUN: %flang -### --target=ppc64le-linux-gnu -Xlinker -rpath -Xlinker /not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=aarch64-apple-darwin -Xlinker -rpath -Xlinker /not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=sparc-sun-solaris2.11 -Xlinker -rpath -Xlinker /not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-freebsd -Xlinker -rpath -Xlinker /not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-netbsd -Xlinker -rpath -Xlinker /not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-openbsd -Xlinker -rpath -Xlinker /not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-dragonfly -Xlinker -rpath -Xlinker /not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-haiku %s -Xlinker -rpath -Xlinker /not/a/real/path 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-windows-gnu -Xlinker -rpath -Xlinker /not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=aarch64-windows-msvc -Xlinker -rpath -Xlinker /not/a/real/path -o obscure.exe %s 2>&1 | FileCheck %s --check-prefixes=MSVC
+
+! UNIX-LABEL: "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "-rpath" "/not/a/real/path"
+
+! The name of this file contains the word "link" which results in a match on
+! the compiler line as well. Instead look for the final name of the executable
+! to be created since that will only appear in the linker line.
+! MSVC: -out:obscure.exe
+! MSVC-SAME: "-rpath" "/not/a/real/path"
+
+end program


        


More information about the cfe-commits mailing list