Author: prakhar
Date: Thu Dec 15 01:59:24 2016
New Revision: 289786
URL: http://llvm.org/viewvc/llvm-project?rev=289786&view=rev
Log:
[ARM] Implement execute-only support in CodeGen
Summary:
This implements execute-only support for ARM code generation, which
prevents the compiler from generating data accesses to code sections.
The following changes are involved:
* Add the CodeGen option "-arm-execute-only" to the ARM code generator.
* Add the clang flag "-mexecute-only" as well as the GCC-compatible
alias "-mpure-code" to enable this option.
* When enabled, literal pools are replaced with MOVW/MOVT instructions,
with VMOV used in addition for floating-point literals. As the MOVT
instruction is required, execute-only support is only available in
Thumb mode for targets supporting ARMv8-M baseline or Thumb2.
* Jump tables are placed in data sections when in execute-only mode.
* The execute-only text section is assigned section ID 0, and is
marked as unreadable with the SHF_ARM_PURECODE flag with symbol 'y'.
This also overrides selection of ELF sections for globals.
Reviewers: t.p.northover, rengolin
Subscribers: llvm-commits, aemerson
Differential Revision: https://reviews.llvm.org/D27450
Added:
cfe/trunk/test/Driver/arm-execute-only.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=289786&r1=289785&r2=289786&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Thu Dec 15 01:59:24
2016
@@ -190,6 +190,8 @@ def err_target_unsupported_fpmath : Erro
"the '%0' unit is not supported with this instruction set">;
def err_target_unsupported_unaligned : Error<
"the %0 sub-architecture does not support unaligned accesses">;
+def err_target_unsupported_execute_only : Error<
+ "execute only is not supported for the %0 sub-architecture">;
def err_opt_not_valid_with_opt : Error<
"option '%0' cannot be specified with '%1'">;
Modified: cfe/trunk/include/clang/Driver/Options.td
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=289786&r1=289785&r2=289786&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Dec 15 01:59:24 2016
@@ -1455,6 +1455,12 @@ def mlong_calls : Flag<["-"], "mlong-cal
HelpText<"Generate branches with extended addressability, usually via
indirect jumps.">;
def mno_long_calls : Flag<["-"], "mno-long-calls">, Group,
HelpText<"Restore the default behaviour of not generating long calls">;
+def mexecute_only : Flag<["-"], "mexecute-only">, Group,
+ HelpText<"Disallow generation of data access to code sections (ARM only)">;
+def mno_execute_only : Flag<["-"], "mno-execute-only">,
Group,
+ HelpText<"Allow generation of data access to code sections (ARM only)">;
+def mpure_code : Flag<["-"], "mpure-code">, Alias; // Alias for
GCC compatibility
+def mno_pure_code : Flag<["-"], "mno-pure-code">, Alias;
def mtvos_version_min_EQ : Joined<["-"], "mtvos-version-min=">, Group;
def mappletvos_version_min_EQ : Joined<["-"], "mappletvos-version-min=">,
Alias;
def mtvos_simulator_version_min_EQ : Joined<["-"],
"mtvos-simulator-version-min=">, Alias;
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=289786&r1=289785&r2=289786&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Dec 15 01:59:24 2016
@@ -1001,6 +1001,7 @@ arm::FloatABI arm::getARMFloatABI(const
static void getARMTargetFeatures(const ToolChain &TC,
const llvm::Triple &Triple,
const ArgList &Args,
+ ArgStringList &CmdArgs,
std::vector &Features,
bool ForAS) {
const Driver &D = TC.getDriver();
@@ -1139,6 +1140,28 @@ static void getARMTargetFeatures(const T
Features.push_back("+long-calls");
}
+ // Generate execute-only output (no data access to code sections).
+ // Supported only on ARMv6T2 and ARMv7 and above.
+ // Cannot be combined with -mno-movt or -mlong-calls
+ if (Arg *A = Args.getLastArg(options::OPT_mexecute_only,
options::OPT_mno_execute_only)) {
+if (A->getOption().matches(options::OPT_mexecute_only)) {
+ if (getARMSubArchVersionNumber(Triple) < 7 &&
+ llvm::ARM::parseArch(Triple.getArchName()) != llvm::A