diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3405,6 +3405,7 @@ HelpText<"Overlay the virtual filesystem described by file over the real file system. " "Additionally, pass this overlay file to the linker if it supports it">; def imultilib : Separate<["-"], "imultilib">, Group; +def K : Flag<["-"], "K">, Flags<[LinkerInput, NoArgumentUnused]>; def keep__private__externs : Flag<["-"], "keep_private_externs">; def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>, Group; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6328,6 +6328,11 @@ } } + if (Arg *A = Args.getLastArgNoClaim(options::OPT_K); + A && !TC.getTriple().isOSAIX()) + D.Diag(diag::err_drv_unsupported_opt_for_target) + << A->getAsString(Args) << TripleStr; + if (Args.getLastArg(options::OPT_fapple_kext) || (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType))) CmdArgs.push_back("-fapple-kext"); diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c --- a/clang/test/Driver/aix-ld.c +++ b/clang/test/Driver/aix-ld.c @@ -1077,3 +1077,19 @@ // RUN: -fopenmp=libfoo \ // RUN: | FileCheck --check-prefixes=CHECK-FOPENMP-FOO %s // CHECK-FOPENMP-FOO: error: unsupported argument 'libfoo' to option '-fopenmp=' + +// Check powerpc-ibm-aix7.1.0.0. -K is a passthrough linker option. +// RUN: %clang %s 2>&1 -### \ +// RUN: --target=powerpc-ibm-aix7.1.0.0 \ +// RUN: --sysroot %S/Inputs/aix_ppc_tree \ +// RUN: --unwindlib=libunwind \ +// RUN: -K \ +// RUN: | FileCheck --check-prefixes=CHECK-K %s +// CHECK-K: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0" +// CHECK-K: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-K: "{{.*}}ld{{(.exe)?}}" +// CHECK-K: "-b32" +// CHECK-K: "-bpT:0x10000000" "-bpD:0x20000000" +// CHECK-K: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o" +// CHECK-K: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o" +// CHECK-K: "-K"`