diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index fb50d72491bd..3c2f136a3227 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -7885,6 +7885,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("elf32ppc_fbsd"); } + if (Arg *A = Args.getLastArg(options::OPT_G)) { + if (ToolChain.getArch() == llvm::Triple::mips || + ToolChain.getArch() == llvm::Triple::mipsel || + ToolChain.getArch() == llvm::Triple::mips64 || + ToolChain.getArch() == llvm::Triple::mips64el) { + StringRef v = A->getValue(); + CmdArgs.push_back(Args.MakeArgString("-G" + v)); + A->claim(); + } + } + if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); diff --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c index d773504e72a8..45e92043619b 100644 --- a/clang/test/Driver/freebsd.c +++ b/clang/test/Driver/freebsd.c @@ -136,3 +136,8 @@ // RUN: | FileCheck --check-prefix=CHECK-SPARC-CPU %s // CHECK-SPARC-CPU: cc1{{.*}}" "-target-cpu" "ultrasparc" // CHECK-SPARC-CPU: as{{.*}}" "-Av9 + +// Check that -G flags are passed to the linker for mips +// RUN: %clang -target mips-unknown-freebsd %s -### -G0 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MIPS-G %s +// CHECK-MIPS-G: ld{{.*}}" "-G0"