[PATCH] D48794: [AArch64] Implement execute-only support.

Ivan Lozano via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 29 15:07:16 PDT 2018


ivanlozano created this revision.
ivanlozano added reviewers: srhines, eugenis, peter.smith, echristo.
Herald added a reviewer: javed.absar.
Herald added subscribers: cfe-commits, kristof.beyls.

This implements execute-only support for AArch64 targets, similar to the ARM execute-only support.


Repository:
  rC Clang

https://reviews.llvm.org/D48794

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/AArch64.cpp
  lib/Driver/ToolChains/Arch/AArch64.h
  lib/Driver/ToolChains/Clang.cpp
  test/CodeGen/aarch64-execute-only.c


Index: test/CodeGen/aarch64-execute-only.c
===================================================================
--- /dev/null
+++ test/CodeGen/aarch64-execute-only.c
@@ -0,0 +1,24 @@
+// RUN: %clang -target aarch64-linux-eabi -### %s 2>&1 \
+// RUN:    | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY
+
+// RUN: %clang -target aarch64-linux-eabi -### -mexecute-only %s 2>&1 \
+// RUN:    | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY
+
+// RUN: %clang -target aarch64-linux-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \
+// RUN:    | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY
+
+
+// -mpure-code flag for GCC compatibility
+// RUN: %clang -target aarch64-linux-eabi -### %s 2>&1 \
+// RUN:    | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY
+
+// RUN: %clang -target aarch64-linux-eabi -### -mpure-code %s 2>&1 \
+// RUN:    | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY
+
+// RUN: %clang -target aarch64-linux-eabi -### -mpure-code -mno-pure-code %s 2>&1 \
+// RUN:    | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY
+
+// CHECK-NO-EXECUTE-ONLY-NOT: "+execute-only"
+// CHECK-EXECUTE-ONLY: "+execute-only"
+
+void a() {}
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -341,7 +341,7 @@
     break;
   case llvm::Triple::aarch64:
   case llvm::Triple::aarch64_be:
-    aarch64::getAArch64TargetFeatures(D, Args, Features);
+    aarch64::getAArch64TargetFeatures(D, Args, CmdArgs, Features);
     break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
Index: lib/Driver/ToolChains/Arch/AArch64.h
===================================================================
--- lib/Driver/ToolChains/Arch/AArch64.h
+++ lib/Driver/ToolChains/Arch/AArch64.h
@@ -22,6 +22,7 @@
 namespace aarch64 {
 
 void getAArch64TargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
+                              llvm::opt::ArgStringList &CmdArgs,
                               std::vector<llvm::StringRef> &Features);
 
 std::string getAArch64TargetCPU(const llvm::opt::ArgList &Args,
Index: lib/Driver/ToolChains/Arch/AArch64.cpp
===================================================================
--- lib/Driver/ToolChains/Arch/AArch64.cpp
+++ lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -150,6 +150,7 @@
 }
 
 void aarch64::getAArch64TargetFeatures(const Driver &D, const ArgList &Args,
+                                       ArgStringList &CmdArgs,
                                        std::vector<StringRef> &Features) {
   Arg *A;
   bool success = true;
@@ -203,4 +204,11 @@
 
   if (Args.hasArg(options::OPT_mno_neg_immediates))
     Features.push_back("+no-neg-immediates");
+
+  // Generate execute-only output (no data access to code sections).
+  if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, options::OPT_mno_execute_only)) {
+    if (A->getOption().matches(options::OPT_mexecute_only)) {
+      Features.push_back("+execute-only");
+    }
+  }
 }
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1885,9 +1885,9 @@
 def mno_long_calls : Flag<["-"], "mno-long-calls">, Group<m_Group>,
   HelpText<"Restore the default behaviour of not generating long calls">;
 def mexecute_only : Flag<["-"], "mexecute-only">, Group<m_arm_Features_Group>,
-  HelpText<"Disallow generation of data access to code sections (ARM only)">;
+  HelpText<"Disallow generation of data access to code sections (ARM/AArch64 only)">;
 def mno_execute_only : Flag<["-"], "mno-execute-only">, Group<m_arm_Features_Group>,
-  HelpText<"Allow generation of data access to code sections (ARM only)">;
+  HelpText<"Allow generation of data access to code sections (ARM/AArch64 only)">;
 def mtp_mode_EQ : Joined<["-"], "mtp=">, Group<m_arm_Features_Group>, Values<"soft, cp15">,
   HelpText<"Read thread pointer from coprocessor register (ARM only)">;
 def mpure_code : Flag<["-"], "mpure-code">, Alias<mexecute_only>; // Alias for GCC compatibility


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48794.153589.patch
Type: text/x-patch
Size: 4130 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180629/d916d0da/attachment-0001.bin>


More information about the cfe-commits mailing list