]> granicus.if.org Git - clang/commitdiff
Turn on PIC by default on Android (http://llvm-reviews.chandlerc.com/D2603)
authorAlexey Bataev <a.bataev@hotmail.com>
Tue, 28 Jan 2014 06:30:35 +0000 (06:30 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Tue, 28 Jan 2014 06:30:35 +0000 (06:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200290 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/fsanitize.c
test/Driver/pic.c

index 615c3758d6df765420722bb7d683e802908c9913..892810ece15a924b42cab2426a6027ab927e5be0 100644 (file)
@@ -2136,6 +2136,29 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   bool PIC = PIE || getToolChain().isPICDefault();
   bool IsPICLevelTwo = PIC;
 
+  // Android-specific defaults for PIC/PIE
+  if (getToolChain().getTriple().getEnvironment() == llvm::Triple::Android) {
+    switch (getToolChain().getTriple().getArch()) {
+    case llvm::Triple::arm:
+    case llvm::Triple::thumb:
+    case llvm::Triple::mips:
+    case llvm::Triple::mipsel:
+    case llvm::Triple::mips64:
+    case llvm::Triple::mips64el:
+      PIC = true; // "-fpic"
+      break;
+
+    case llvm::Triple::x86:
+    case llvm::Triple::x86_64:
+      PIC = true; // "-fPIC"
+      IsPICLevelTwo = true;
+      break;
+
+    default:
+      break;
+    }
+  }
+
   // For the PIC and PIE flag options, this logic is different from the
   // legacy logic in very old versions of GCC, as that logic was just
   // a bug no one had ever fixed. This logic is both more rational and
index 73f659b07c94c8b60ddf9b0a23f67b4a89805cb6..b3c940f0411dc89934d193fc814baf05d85a176e 100644 (file)
 // CHECK-ANDROID-ASAN-NO-PIE: "-pie"
 
 // RUN: %clang -target arm-linux-androideabi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-NO-ASAN
-// CHECK-ANDROID-NO-ASAN: "-mrelocation-model" "static"
+// CHECK-ANDROID-NO-ASAN: "-mrelocation-model" "pic"
 
 // RUN: %clang -target x86_64-linux-gnu %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER
 // RUN: %clang -target x86_64-linux-gnu %s -fsanitize-recover -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER
index 988a20abb3ce5d8d17fc11ef1f350469b24ffe99..9d433addbbb5190ef743df45908ac8e9f72b4a15 100644 (file)
 // 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
+//
+// On Android PIC is enabled by default
+// RUN: %clang -c %s -target i686-linux-android -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+// RUN: %clang -c %s -target arm-linux-androideabi -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
+// RUN: %clang -c %s -target mipsel-linux-android -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC1