https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/72601
>From da17459071b039e9da0f53ae5e68ab1c3aaa13e4 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 | 35 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b2f2bcb6ac37910..bc04c53d7c76b9d 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5152,7 +5152,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">; @@ -5162,7 +5163,8 @@ def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>; 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>; @@ -5170,7 +5172,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 df119c22a2ea516..aa90be5ac196e0e 100644 --- a/flang/test/Driver/dynamic-linker.f90 +++ b/flang/test/Driver/dynamic-linker.f90 @@ -18,3 +18,38 @@ ! MSVC-LINKER-OPTIONS: "{{.*}}link{{(.exe)?}}" ! MSVC-LINKER-OPTIONS-SAME: "-dll" ! MSVC-LINKER-OPTIONS-SAME: "-rpath" "/path/to/dir" + +! Verify that certain linker flags are known to the frontend and are not passed on +! to the linker. + +! 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