https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/72601
>From 8d478b98effa8b6bb5d59605034ce35086cc0112 Mon Sep 17 00:00:00 2001 From: Brad Smith <b...@comstyle.com> Date: Wed, 15 Nov 2023 14:24:11 -0500 Subject: [PATCH] [flang][Driver] Support -nodefaultlibs, -nostartfiles and -nostdlib --- clang/include/clang/Driver/Options.td | 9 ++++--- flang/test/Driver/dynamic-linker.f90 | 36 +++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) 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..e7e00f637858edf 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{{[^.]+}}.o +! 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{{[^.]+}}.o +! NOSTARTFILES: "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits