For FreeBSD on mips, pass -G options to the linker

Summary:
On {mips,mipsel,mips64,mips64el}-freebsd, we need to pass any -G option to the linker.  See also:

https://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html#index-G-2007

This has been adapted from https://reviews.freebsd.org/D1190, with an added test case.

Reviewers: theraven, atanasyan, emaste

Subscribers: brooks, tomatabacu, cfe-commits, seanbruno, emaste

Differential Revision: http://reviews.llvm.org/D9114

llvm-svn: 256461
This commit is contained in:
Dimitry Andric 2015-12-27 06:47:09 +00:00
parent 2f2625c056
commit 904895f0ff
2 changed files with 16 additions and 0 deletions

View File

@ -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());

View File

@ -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"