[flang-commits] [clang] [flang] [flang][Driver] Support -nodefaultlibs, -nostartfiles and -nostdlib (PR #72601)
via flang-commits
flang-commits at lists.llvm.org
Thu Nov 16 18:40:49 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-driver
@llvm/pr-subscribers-clang
Author: Brad Smith (brad0)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/72601.diff
2 Files Affected:
- (modified) clang/include/clang/Driver/Options.td (+6-3)
- (modified) flang/test/Driver/dynamic-linker.f90 (+34-2)
``````````diff
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 811550416110b3d..a0eb04a5cd9c6a7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5131,7 +5131,8 @@ def : Flag<["-"], "nocudalib">, Alias<nogpulib>;
def gpulibc : Flag<["-"], "gpulibc">, Visibility<[ClangOption, CC1Option]>,
HelpText<"Link the LLVM C Library for GPUs">;
def nogpulibc : Flag<["-"], "nogpulibc">, Visibility<[ClangOption, CC1Option]>;
-def nodefaultlibs : Flag<["-"], "nodefaultlibs">;
+def nodefaultlibs : Flag<["-"], "nodefaultlibs">,
+ Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
def nodriverkitlib : Flag<["-"], "nodriverkitlib">;
def nofixprebinding : Flag<["-"], "nofixprebinding">;
def nolibc : Flag<["-"], "nolibc">;
@@ -5141,7 +5142,8 @@ def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>, Alia
def noprebind : Flag<["-"], "noprebind">;
def noprofilelib : Flag<["-"], "noprofilelib">;
def noseglinkedit : Flag<["-"], "noseglinkedit">;
-def nostartfiles : Flag<["-"], "nostartfiles">, Group<Link_Group>;
+def nostartfiles : Flag<["-"], "nostartfiles">, Group<Link_Group>,
+ Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
def nostdinc : Flag<["-"], "nostdinc">,
Visibility<[ClangOption, CLOption, DXCOption]>, Group<IncludePath_Group>;
def nostdlibinc : Flag<["-"], "nostdlibinc">, Group<IncludePath_Group>;
@@ -5149,7 +5151,8 @@ def nostdincxx : Flag<["-"], "nostdinc++">, Visibility<[ClangOption, CC1Option]>
Group<IncludePath_Group>,
HelpText<"Disable standard #include directories for the C++ standard library">,
MarshallingInfoNegativeFlag<HeaderSearchOpts<"UseStandardCXXIncludes">>;
-def nostdlib : Flag<["-"], "nostdlib">, Group<Link_Group>;
+def nostdlib : Flag<["-"], "nostdlib">, Group<Link_Group>,
+ Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
def nostdlibxx : Flag<["-"], "nostdlib++">;
def object : Flag<["-"], "object">;
def o : JoinedOrSeparate<["-"], "o">,
diff --git a/flang/test/Driver/dynamic-linker.f90 b/flang/test/Driver/dynamic-linker.f90
index 2745822dc107769..432e0cd586f1118 100644
--- a/flang/test/Driver/dynamic-linker.f90
+++ b/flang/test/Driver/dynamic-linker.f90
@@ -1,5 +1,5 @@
-! Verify that certain linker flags are known to the frontend and are passed on
-! to the linker.
+! Verify that certain linker flags are known to the frontend and are passed or
+! not passed on to the linker.
! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
! RUN: -static %s 2>&1 | FileCheck \
@@ -18,3 +18,35 @@
! MSVC-LINKER-OPTIONS: "{{.*}}link.exe"
! MSVC-LINKER-OPTIONS-SAME: "-dll"
! MSVC-LINKER-OPTIONS-SAME: "-rpath" "/path/to/dir"
+
+! RUN: %flang -### --target=x86_64-unknown-freebsd -nostdlib %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NOSTDLIB %s
+! RUN: %flang -### --target=x86_64-unknown-netbsd -nostdlib %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NOSTDLIB %s
+! RUN: %flang -### --target=i386-pc-solaris2.11 -nostdlib %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NOSTDLIB %s
+
+! NOSTDLIB: "{{.*}}ld{{(.exe)?}}"
+! NOSTDLIB-NOT: crt*
+! NOSTDLIB-NOT: "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm"
+
+! RUN: %flang -### --target=x86_64-unknown-freebsd -nodefaultlibs %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NODEFAULTLIBS %s
+! RUN: %flang -### --target=x86_64-unknown-netbsd -nodefaultlibs %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NODEFAULTLIBS %s
+! RUN: %flang -### --target=i386-pc-solaris2.11 -nodefaultlibs %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NODEFAULTLIBS %s
+
+! NODEFAULTLIBS: "{{.*}}ld{{(.exe)?}}"
+! NODEFAULTLIBS-NOT: "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm"
+
+! RUN: %flang -### --target=x86_64-unknown-freebsd -nostartfiles %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NOSTARTFILES %s
+! RUN: %flang -### --target=x86_64-unknown-netbsd -nostartfiles %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NOSTARTFILES %s
+! RUN: %flang -### --target=i386-pc-solaris2.11 -nostartfiles %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=NOSTARTFILES %s
+
+! NOSTARTFILES: "{{.*}}ld{{(.exe)?}}"
+! NOSTARTFILES-NOT: crt*
+! NOSTARTFILES: "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm"
``````````
</details>
https://github.com/llvm/llvm-project/pull/72601
More information about the flang-commits
mailing list