]> granicus.if.org Git - clang/commitdiff
[mips] Prevent PIC to be set to level 2
authorAleksandar Beserminji <Aleksandar.Beserminji@mips.com>
Mon, 16 Apr 2018 10:21:24 +0000 (10:21 +0000)
committerAleksandar Beserminji <Aleksandar.Beserminji@mips.com>
Mon, 16 Apr 2018 10:21:24 +0000 (10:21 +0000)
MIPS does not use PIC level 2 for historical reasons,
even with -fPIC/-mxgot/multigot options. This patch
prevents PIC to be set to level 2 for MIPS.

Differential Revision: https://reviews.llvm.org/D44381

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330118 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/CommonArgs.cpp
test/Driver/pic.c

index dac81ee902e26bcdc91d9082b2a2cd9c2b6811c5..869cf4c8f2ef690c5a1081d3e4c6b49fd492ec93 100644 (file)
@@ -1007,12 +1007,17 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
   if ((ROPI || RWPI) && (PIC || PIE))
     ToolChain.getDriver().Diag(diag::err_drv_ropi_rwpi_incompatible_with_pic);
 
-  // When targettng MIPS64 with N64, the default is PIC, unless -mno-abicalls is
-  // used.
-  if ((Triple.getArch() == llvm::Triple::mips64 ||
-       Triple.getArch() == llvm::Triple::mips64el) &&
-      Args.hasArg(options::OPT_mno_abicalls))
-    return std::make_tuple(llvm::Reloc::Static, 0U, false);
+  if (Triple.getArch() == llvm::Triple::mips ||
+       Triple.getArch() == llvm::Triple::mipsel ||
+       Triple.getArch() == llvm::Triple::mips64 ||
+       Triple.getArch() == llvm::Triple::mips64el) {
+    // When targettng MIPS with -mno-abicalls, it's always static.
+    if(Args.hasArg(options::OPT_mno_abicalls))
+      return std::make_tuple(llvm::Reloc::Static, 0U, false);
+    // Unlike other architectures, MIPS, even with -fPIC/-mxgot/multigot,
+    // does not use PIC level 2 for historical reasons.
+    IsPICLevelTwo = false;
+  }
 
   if (PIC)
     return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE);
index 1b4257c28bb565b6a44e1cd2ecfc5c6d508d927a..68a307914f6148b4c60c22e9212a86795503920c 100644 (file)
 // RUN: %clang -c %s -target mipsel-linux-android14 -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
 // RUN: %clang -c %s -target mipsel-linux-android16 -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
 // RUN: %clang -c %s -target mipsel-linux-android24 -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
 //
 // 64-bit Android targets are always PIE.
 // RUN: %clang -c %s -target aarch64-linux-android -### 2>&1 \