r191947 - [Mips] For MIPS '-fPIC -static' means to compile as -fPIC but link with

Simon Atanasyan simon at atanasyan.com
Fri Oct 4 03:36:42 PDT 2013


Author: atanasyan
Date: Fri Oct  4 05:36:42 2013
New Revision: 191947

URL: http://llvm.org/viewvc/llvm-project?rev=191947&view=rev
Log:
[Mips] For MIPS '-fPIC -static' means to compile as -fPIC but link with
-static. So do not turn off the PIC flag if -static passed to the
driver in case of MIPS target.

http://llvm.org/bugs/show_bug.cgi?id=14693

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

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=191947&r1=191946&r2=191947&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct  4 05:36:42 2013
@@ -2139,7 +2139,13 @@ void Clang::ConstructJob(Compilation &C,
   if (KernelOrKext &&
       (!Triple.isiOS() || Triple.isOSVersionLT(6)))
     PIC = PIE = false;
-  if (Args.hasArg(options::OPT_static))
+  // Usually '-static' implies no-PIC. But for MIPS '-fPIC -static' means
+  // to compile as -fPIC but link with -static.
+  if (Args.hasArg(options::OPT_static) &&
+      getToolChain().getArch() != llvm::Triple::mips &&
+      getToolChain().getArch() != llvm::Triple::mipsel &&
+      getToolChain().getArch() != llvm::Triple::mips64 &&
+      getToolChain().getArch() != llvm::Triple::mips64el)
     PIC = PIE = false;
 
   if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {

Modified: cfe/trunk/test/Driver/pic.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/pic.c?rev=191947&r1=191946&r2=191947&view=diff
==============================================================================
--- cfe/trunk/test/Driver/pic.c (original)
+++ cfe/trunk/test/Driver/pic.c Fri Oct  4 05:36:42 2013
@@ -209,3 +209,13 @@
 // On OpenBSD, -nopie needs to be passed through to the linker.
 // RUN: %clang %s -target i386-pc-openbsd -nopie -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NOPIE-LD
+//
+// For MIPS -fPIC -static means to compile as -fPIC but link with -static.
+// RUN: %clang -c %s -target mips-linux-gnu -fpic -static -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
+// RUN: %clang -c %s -target mips-linux-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
+// RUN: %clang -c %s -target mips-linux-gnu -fpic -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
+// RUN: %clang -c %s -target mips-linux-gnu -static -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC





More information about the cfe-commits mailing list