Index: lib/Driver/ToolChains.h =================================================================== --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -661,6 +661,7 @@ AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; bool isPIEDefault() const override; + bool isPICDefault() const override; std::string Linker; std::vector ExtraOpts; Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -3379,9 +3379,15 @@ } bool Linux::isPIEDefault() const { + if (getTriple().getEnvironment() == llvm::Triple::Android) + return true; return getSanitizerArgs().hasZeroBaseShadow(); } +bool Linux::isPICDefault() const { + return getTriple().getEnvironment() == llvm::Triple::Android; +} + /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. DragonFly::DragonFly(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2371,8 +2371,15 @@ CheckCodeGenerationOptions(D, Args); - bool PIE = getToolChain().isPIEDefault(); - bool PIC = PIE || getToolChain().isPICDefault(); + bool PIE = false; + bool PIC = false; + if (getToolChain().isPICDefault()) { + PIC = true; + PIE = false; + } else if (getToolChain().isPIEDefault()) { + PIC = PIE = true; + } + bool IsPICLevelTwo = PIC; // Android-specific defaults for PIC/PIE @@ -2386,13 +2393,7 @@ 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; + IsPICLevelTwo = false; break; default: @@ -6916,13 +6917,8 @@ const bool isAndroid = ToolChain.getTriple().getEnvironment() == llvm::Triple::Android; const bool IsPIE = - !Args.hasArg(options::OPT_shared) && - !Args.hasArg(options::OPT_static) && - (Args.hasArg(options::OPT_pie) || ToolChain.isPIEDefault() || - // On Android every code is PIC so every executable is PIE - // Cannot use isPIEDefault here since otherwise - // PIE only logic will be enabled during compilation - isAndroid); + !Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_static) && + (Args.hasArg(options::OPT_pie) || ToolChain.isPIEDefault()); ArgStringList CmdArgs; Index: test/Driver/fsanitize.c =================================================================== --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -113,7 +113,7 @@ // CHECK-MSAN-NO-PIE: "-pie" // RUN: %clang -target arm-linux-androideabi -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-ASAN-NO-PIE -// CHECK-ANDROID-ASAN-NO-PIE: "-mrelocation-model" "pic" "-pic-level" "2" "-pie-level" "2" +// CHECK-ANDROID-ASAN-NO-PIE: "-mrelocation-model" "pic" "-pic-level" "1" // CHECK-ANDROID-ASAN-NO-PIE: "-pie" // RUN: %clang -target arm-linux-androideabi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-NO-ASAN