From: Simon Atanasyan Date: Fri, 4 Oct 2013 10:36:42 +0000 (+0000) Subject: [Mips] For MIPS '-fPIC -static' means to compile as -fPIC but link with X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd55e97f4452b9a6fa18d6503c936d8b1c33029d;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191947 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 2f824cbcad..d2ca9fb8df 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2139,7 +2139,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, 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)) { diff --git a/test/Driver/pic.c b/test/Driver/pic.c index 30e1005c97..7bf514caa3 100644 --- a/test/Driver/pic.c +++ b/test/Driver/pic.c @@ -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