[flang-commits] [clang] [flang] [flang] Add -rtlib flag (PR #99058)
David Truby via flang-commits
flang-commits at lists.llvm.org
Wed Jul 17 04:01:27 PDT 2024
https://github.com/DavidTruby updated https://github.com/llvm/llvm-project/pull/99058
>From 66e13f92a0680742b552fabde25df7752f8510c9 Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Tue, 16 Jul 2024 15:39:28 +0000
Subject: [PATCH 1/3] [flang] Add -rtlib flag
This patch allows the -rtlib flag with flang-new to select between the
libgcc_s and compiler-rt runtimes. The behaviour is identical to the
same flag with clang.
---
clang/include/clang/Driver/Options.td | 2 +-
flang/test/Driver/linker-flags.f90 | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 234958f4eb382..c434fe64b3f53 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5621,7 +5621,7 @@ def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
Alias<resource_dir>;
def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group<Link_Group>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
-def rtlib_EQ : Joined<["-", "--"], "rtlib=">, Visibility<[ClangOption, CLOption]>,
+def rtlib_EQ : Joined<["-", "--"], "rtlib=">, Visibility<[ClangOption, CLOption, FlangOption]>,
HelpText<"Compiler runtime library to use">;
def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, Flags<[NoArgumentUnused]>,
Visibility<[ClangOption, FlangOption]>,
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 02e217494f818..25f1d6dcd8786 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -11,6 +11,7 @@
! RUN: %flang -### --target=x86_64-unknown-dragonfly %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib
! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,HAIKU,HAIKU-F128%f128-lib
! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW,MINGW-F128%f128-lib
+! RUN: %flang -### -rtlib=compiler-rt --target=aarch64-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,COMPILER-RT
! NOTE: Clang's driver library, clangDriver, usually adds 'oldnames' on Windows,
! but it is not needed when compiling Fortran code and they might bring in
@@ -27,12 +28,14 @@
! suffix. Clang's driver will try to resolve the path to the ld
! executable and may find the GNU linker from MinGW or Cygwin.
! UNIX-LABEL: "{{.*}}ld{{(\.exe)?}}"
+! COMPILER-RT: "{{.*}}/clang_rt.crtbegin.o"
! UNIX-SAME: "[[object_file]]"
! UNIX-F128NONE-NOT: FortranFloat128Math
! 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"
+! COMPILER-RT: "{{.*}}/libclang_rt.builtins.a" "{{.*}}/clang_rt.crtend.o"
! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
! DARWIN-SAME: "[[object_file]]"
@@ -61,3 +64,6 @@
! MSVC-LABEL: link
! MSVC-SAME: /subsystem:console
! MSVC-SAME: "[[object_file]]"
+
+! COMPILER-RT-NOT: "-lgcc"
+! COMPILER-RT-NOT: "-lgcc_s"
>From 70dbdf25b5952d957133d1fa2f7b832b2359f43b Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Tue, 16 Jul 2024 20:19:57 +0000
Subject: [PATCH 2/3] Remove clang_rt.crtbegin and clang_rt.crtend check
---
flang/test/Driver/linker-flags.f90 | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 25f1d6dcd8786..6b8957cdbcf3a 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -28,14 +28,13 @@
! suffix. Clang's driver will try to resolve the path to the ld
! executable and may find the GNU linker from MinGW or Cygwin.
! UNIX-LABEL: "{{.*}}ld{{(\.exe)?}}"
-! COMPILER-RT: "{{.*}}/clang_rt.crtbegin.o"
! UNIX-SAME: "[[object_file]]"
! UNIX-F128NONE-NOT: FortranFloat128Math
! 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"
-! COMPILER-RT: "{{.*}}/libclang_rt.builtins.a" "{{.*}}/clang_rt.crtend.o"
+! COMPILER-RT: "{{.*}}/libclang_rt.builtins.a"
! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
! DARWIN-SAME: "[[object_file]]"
>From 878a9a9c0809930499920eb6197b469c71904d5e Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Wed, 17 Jul 2024 11:00:59 +0000
Subject: [PATCH 3/3] Fix windows path (\\ vs /)
---
flang/test/Driver/linker-flags.f90 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 6b8957cdbcf3a..ac9500d7c45ce 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -34,7 +34,7 @@
! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal" "-lm"
-! COMPILER-RT: "{{.*}}/libclang_rt.builtins.a"
+! COMPILER-RT: "{{.*}}{{\\|/}}libclang_rt.builtins.a"
! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
! DARWIN-SAME: "[[object_file]]"
More information about the flang-commits
mailing list