summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Driver/Tools.cpp23
-rw-r--r--clang/test/Driver/fsanitize.c2
-rw-r--r--clang/test/Driver/pic.c8
3 files changed, 32 insertions, 1 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 615c3758d6d..892810ece15 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -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
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 73f659b07c9..b3c940f0411 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -113,7 +113,7 @@
// 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
diff --git a/clang/test/Driver/pic.c b/clang/test/Driver/pic.c
index 988a20abb3c..9d433addbbb 100644
--- a/clang/test/Driver/pic.c
+++ b/clang/test/Driver/pic.c
@@ -209,3 +209,11 @@
// 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
OpenPOWER on IntegriCloud