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

Dimitry Andric via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 26 22:47:10 PST 2015


Author: dim
Date: Sun Dec 27 00:47:09 2015
New Revision: 256461

URL: http://llvm.org/viewvc/llvm-project?rev=256461&view=rev
Log:
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

Modified:
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/Driver/freebsd.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=256461&r1=256460&r2=256461&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Sun Dec 27 00:47:09 2015
@@ -7885,6 +7885,17 @@ void freebsd::Linker::ConstructJob(Compi
     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());

Modified: cfe/trunk/test/Driver/freebsd.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/freebsd.c?rev=256461&r1=256460&r2=256461&view=diff
==============================================================================
--- cfe/trunk/test/Driver/freebsd.c (original)
+++ cfe/trunk/test/Driver/freebsd.c Sun Dec 27 00:47:09 2015
@@ -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"




More information about the cfe-commits mailing list