From 03d5952c3c4f18dc6ed899950ae5eb3ddbb8ac4b Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Tue, 28 Jan 2014 06:30:35 +0000 Subject: [PATCH] Turn on PIC by default on Android (http://llvm-reviews.chandlerc.com/D2603) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200290 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 23 +++++++++++++++++++++++ test/Driver/fsanitize.c | 2 +- test/Driver/pic.c | 8 ++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 615c3758d6..892810ece1 100644 --- a/lib/Driver/Tools.cpp +++ b/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/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index 73f659b07c..b3c940f041 100644 --- a/test/Driver/fsanitize.c +++ b/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/test/Driver/pic.c b/test/Driver/pic.c index 988a20abb3..9d433addbb 100644 --- a/test/Driver/pic.c +++ b/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 -- 2.40.0