[PATCH] Turn on PIC by default on Android
Alexey Volkov
avolkov.intel at gmail.com
Thu Jan 23 06:33:28 PST 2014
volkalexey added you to the CC list for the revision "Turn on PIC by default on Android".
Hi eugenis,
These changes are ported from Android NDK:
PIC should to be turned on by default for Android targets.
Alexey Volkov
Intel Corporation
http://llvm-reviews.chandlerc.com/D2603
Files:
lib/Driver/Tools.cpp
test/Driver/fsanitize.c
test/Driver/pic.c
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2129,6 +2129,29 @@
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: test/Driver/fsanitize.c
===================================================================
--- test/Driver/fsanitize.c
+++ 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
Index: test/Driver/pic.c
===================================================================
--- test/Driver/pic.c
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2603.1.patch
Type: text/x-patch
Size: 2440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140123/97d86b63/attachment.bin>
More information about the cfe-commits
mailing list