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 @@ -815,7 +815,9 @@ def bind__at__load : Flag<["-"], "bind_at_load">; def bundle__loader : Separate<["-"], "bundle_loader">; def bundle : Flag<["-"], "bundle">; -def b : JoinedOrSeparate<["-"], "b">, Flags<[Unsupported]>; +def b : JoinedOrSeparate<["-"], "b">, Flags<[LinkerInput, RenderAsInput]>, + HelpText<"Pass -b to the linker on AIX (only).">, MetaVarName<"">, + Group; def cl_opt_disable : Flag<["-"], "cl-opt-disable">, Group, Flags<[CC1Option]>, HelpText<"OpenCL only. This option disables all optimizations. By default optimizations are enabled.">; def cl_strict_aliasing : Flag<["-"], "cl-strict-aliasing">, Group, Flags<[CC1Option]>, diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -257,6 +257,16 @@ // Otherwise, this is a linker input argument. const Arg &A = II.getInputArg(); + if (A.getOption().matches(options::OPT_b)) { + const llvm::Triple &T = TC.getTriple(); + if (!T.isOSAIX()) { + TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target) + << A.getSpelling() << T.str(); + } + // Pass -b prefix for AIX linker. + A.claim(); + A.render(Args, CmdArgs); + } // Handle reserved library options. if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) TC.AddCXXStdlibLibArgs(Args, CmdArgs); diff --git a/clang/test/Driver/Xlinker-args.c b/clang/test/Driver/Xlinker-args.c --- a/clang/test/Driver/Xlinker-args.c +++ b/clang/test/Driver/Xlinker-args.c @@ -11,10 +11,20 @@ // RUN: -e _start -T a.lds -Xlinker one -Xlinker --no-demangle \ // RUN: -Wl,two,--no-demangle,three -Xlinker four -z five -r %s 2> %t // RUN: FileCheck -check-prefix=LINUX < %t %s -// + +// RUN: %clang -target powerpc-unknown-aix -### \ +// RUN: -b one %s 2> %t +// RUN: FileCheck -check-prefix=AIX < %t %s + +// RUN: %clang -target powerpc-unknown-linux -### \ +// RUN: -b one %s 2> %t +// RUN: FileCheck -check-prefix=NOT-AIX < %t %s + // DARWIN-NOT: --no-demangle // DARWIN: "one" "two" "three" "four" "-z" "five" "-r" // LINUX: "--no-demangle" "-e" "_start" "one" "two" "three" "four" "-z" "five" "-r" {{.*}} "-T" "a.lds" +// AIX: "-b" "one" +// NOT-AIX: error: unsupported option '-b' for target 'powerpc-unknown-linux' // Check that we forward '-Xlinker' and '-Wl,' on Windows. // RUN: %clang -target i686-pc-win32 -fuse-ld=link -### \