Author: danalbert Date: Thu Mar 28 11:08:28 2019 New Revision: 357197 URL: http://llvm.org/viewvc/llvm-project?rev=357197&view=rev Log: [Driver] Default Android toolchains to noexecstack.
Android does not support executable stacks. Reviewers: srhines, pirama Reviewed By: pirama Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D53343 Modified: cfe/trunk/include/clang/Driver/ToolChain.h cfe/trunk/lib/Driver/ToolChain.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Driver/ToolChains/Gnu.cpp cfe/trunk/lib/Driver/ToolChains/Linux.cpp cfe/trunk/lib/Driver/ToolChains/Linux.h cfe/trunk/test/Driver/integrated-as.c cfe/trunk/test/Driver/linux-as.c cfe/trunk/test/Driver/linux-ld.c Modified: cfe/trunk/include/clang/Driver/ToolChain.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/ToolChain.h (original) +++ cfe/trunk/include/clang/Driver/ToolChain.h Thu Mar 28 11:08:28 2019 @@ -412,6 +412,9 @@ public: /// Test whether this toolchain defaults to PIE. virtual bool isPIEDefault() const = 0; + /// Test whether this toolchaind defaults to non-executable stacks. + virtual bool isNoExecStackDefault() const; + /// Tests whether this toolchain forces its default for PIC, PIE or /// non-PIC. If this returns true, any PIC related flags should be ignored /// and instead the results of \c isPICDefault() and \c isPIEDefault() are Modified: cfe/trunk/lib/Driver/ToolChain.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChain.cpp (original) +++ cfe/trunk/lib/Driver/ToolChain.cpp Thu Mar 28 11:08:28 2019 @@ -112,6 +112,10 @@ bool ToolChain::useRelaxRelocations() co return ENABLE_X86_RELAX_RELOCATIONS; } +bool ToolChain::isNoExecStackDefault() const { + return false; +} + const SanitizerArgs& ToolChain::getSanitizerArgs() const { if (!SanitizerArguments.get()) SanitizerArguments.reset(new SanitizerArgs(*this, Args)); Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Mar 28 11:08:28 2019 @@ -2053,6 +2053,7 @@ static void CollectArgsForIntegratedAsse bool TakeNextArg = false; bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations(); + bool UseNoExecStack = C.getDefaultToolChain().isNoExecStackDefault(); const char *MipsTargetFeature = nullptr; for (const Arg *A : Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) { @@ -2134,7 +2135,7 @@ static void CollectArgsForIntegratedAsse } else if (Value == "--fatal-warnings") { CmdArgs.push_back("-massembler-fatal-warnings"); } else if (Value == "--noexecstack") { - CmdArgs.push_back("-mnoexecstack"); + UseNoExecStack = true; } else if (Value.startswith("-compress-debug-sections") || Value.startswith("--compress-debug-sections") || Value == "-nocompress-debug-sections" || @@ -2197,6 +2198,8 @@ static void CollectArgsForIntegratedAsse } if (UseRelaxRelocations) CmdArgs.push_back("--mrelax-relocations"); + if (UseNoExecStack) + CmdArgs.push_back("-mnoexecstack"); if (MipsTargetFeature != nullptr) { CmdArgs.push_back("-target-feature"); CmdArgs.push_back(MipsTargetFeature); Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Thu Mar 28 11:08:28 2019 @@ -360,6 +360,11 @@ void tools::gnutools::Linker::ConstructJ CmdArgs.push_back("--no-dynamic-linker"); } + if (ToolChain.isNoExecStackDefault()) { + CmdArgs.push_back("-z"); + CmdArgs.push_back("noexecstack"); + } + if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); @@ -609,6 +614,10 @@ void tools::gnutools::Assembler::Constru } } + if (getToolChain().isNoExecStackDefault()) { + CmdArgs.push_back("--noexecstack"); + } + switch (getToolChain().getArch()) { default: break; Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Thu Mar 28 11:08:28 2019 @@ -971,6 +971,10 @@ bool Linux::isPIEDefault() const { getTriple().isMusl() || getSanitizerArgs().requiresPIE(); } +bool Linux::isNoExecStackDefault() const { + return getTriple().isAndroid(); +} + bool Linux::IsMathErrnoDefault() const { if (getTriple().isAndroid()) return false; Modified: cfe/trunk/lib/Driver/ToolChains/Linux.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.h?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Linux.h (original) +++ cfe/trunk/lib/Driver/ToolChains/Linux.h Thu Mar 28 11:08:28 2019 @@ -38,6 +38,7 @@ public: llvm::opt::ArgStringList &CC1Args) const override; CXXStdlibType GetDefaultCXXStdlibType() const override; bool isPIEDefault() const override; + bool isNoExecStackDefault() const override; bool IsMathErrnoDefault() const override; SanitizerMask getSupportedSanitizers() const override; void addProfileRTLibs(const llvm::opt::ArgList &Args, Modified: cfe/trunk/test/Driver/integrated-as.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/integrated-as.c?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/test/Driver/integrated-as.c (original) +++ cfe/trunk/test/Driver/integrated-as.c Thu Mar 28 11:08:28 2019 @@ -13,3 +13,8 @@ // NOFIAS-NOT: cc1as // NOFIAS: -cc1 // NOFIAS: -no-integrated-as + +// RUN: %clang -target arm-linux-androideabi -### \ +// RUN: -integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ARM-ANDROID %s +// CHECK-ARM-ANDROID: "-mnoexecstack" Modified: cfe/trunk/test/Driver/linux-as.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-as.c?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/test/Driver/linux-as.c (original) +++ cfe/trunk/test/Driver/linux-as.c Thu Mar 28 11:08:28 2019 @@ -108,12 +108,12 @@ // RUN: %clang -target arm-linux-androideabi -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-ANDROID %s -// CHECK-ARM-ANDROID: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" +// CHECK-ARM-ANDROID: as{{(.exe)?}}" "--noexecstack" "-EL" "-mfloat-abi=soft" // // RUN: %clang -target arm-linux-androideabi -march=armv7-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-ANDROID-SOFTFP %s -// CHECK-ARM-ANDROID-SOFTFP: as{{(.exe)?}}" "-EL" "-mfloat-abi=softfp" "-march=armv7-a" +// CHECK-ARM-ANDROID-SOFTFP: as{{(.exe)?}}" "--noexecstack" "-EL" "-mfloat-abi=softfp" "-march=armv7-a" // // RUN: %clang -target arm-linux-eabi -mhard-float -### \ // RUN: -no-integrated-as -c %s 2>&1 \ Modified: cfe/trunk/test/Driver/linux-ld.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-ld.c?rev=357197&r1=357196&r2=357197&view=diff ============================================================================== --- cfe/trunk/test/Driver/linux-ld.c (original) +++ cfe/trunk/test/Driver/linux-ld.c Thu Mar 28 11:08:28 2019 @@ -997,6 +997,15 @@ // RUN: | FileCheck --check-prefix=CHECK-ANDROID-HASH-STYLE-M %s // CHECK-ANDROID-HASH-STYLE-M: "{{.*}}ld{{(.exe)?}}" // CHECK-ANDROID-HASH-STYLE-M: "--hash-style=gnu" + +// RUN: %clang %s -### -o %t.o 2>&1 \ +// RUN: --target=armv7-linux-android21 \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-NOEXECSTACK %s +// CHECK-ANDROID-NOEXECSTACK: "{{.*}}ld{{(.exe)?}}" +// CHECK-ANDROID-NOEXECSTACK: "-z" "noexecstack" +// CHECK-ANDROID-NOEXECSTACK-NOT: "-z" "execstack" +// CHECK-ANDROID-NOEXECSTACK-NOT: "-z,execstack" +// CHECK-ANDROID-NOEXECSTACK-NOT: "-zexecstack" // // RUN: %clang %s -### -o %t.o 2>&1 --target=mips64-linux-gnuabin32 \ // RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-GNUABIN32 %s _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits