[PATCH] D49456: [AArch64] Support execute-only LOAD segments.

Ivan Lozano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 26 13:40:38 PDT 2018


ivanlozano updated this revision to Diff 157569.
ivanlozano added a comment.

As mentioned in my last comment, I'm disabling the execute-only flag when linker scripts with sections defined are used. This also changes the proposed flag from "aarch64-execute-only" to just "execute-only" and makes the suggested modifications to the test.


https://reviews.llvm.org/D49456

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/Options.td
  ELF/ScriptParser.cpp
  ELF/Writer.cpp
  test/ELF/execute-only.s


Index: test/ELF/execute-only.s
===================================================================
--- /dev/null
+++ test/ELF/execute-only.s
@@ -0,0 +1,10 @@
+// REQUIRES: aarch64
+
+// RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o
+// RUN: ld.lld -Ttext=0xcafe0000 %t.o -o %t.so -shared -execute-only
+// RUN: llvm-readelf -l %t.so | FileCheck %s
+
+// CHECK:      LOAD           {{.*}} 0x00000000cafe0000 0x00000000cafe0000 0x000004 0x000004   E 0x{{.*}}
+// CHECK-NOT:  LOAD           {{.*}} 0x00000000cafe0000 0x00000000cafe0000 0x000004 0x000004 R E 0x{{.*}}
+
+        br lr
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1768,6 +1768,8 @@
     return PF_R | PF_W | PF_X;
   if (Config->SingleRoRx && !(Flags & PF_W))
     return Flags | PF_X;
+  if (Config->ExecuteOnly && (Flags & PF_X))
+    return Flags & ~PF_R;
   return Flags;
 }
 
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -488,6 +488,7 @@
   // their own segment. We do the same if SECTIONS command is present in linker
   // script. See comment for computeFlags().
   Config->SingleRoRx = true;
+  Config->ExecuteOnly = false;
 
   expect("{");
   std::vector<BaseCommand *> V;
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -131,6 +131,10 @@
 
 defm exclude_libs: Eq<"exclude-libs", "Exclude static libraries from automatic export">;
 
+defm execute_only: B<"execute-only",
+    "Do not mark executable sections readable.",
+    "Mark executable sections readable.">;
+
 defm export_dynamic: B<"export-dynamic",
     "Put symbols in the dynamic symbol table",
     "Do not put symbols in the dynamic symbol table (default)">;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -299,6 +299,14 @@
     if (Config->Pie)
       error("-r and -pie may not be used together");
   }
+
+  if (Config->ExecuteOnly) {
+    if (Config->EMachine != EM_AARCH64)
+      error("-execute-only is only supported on AArch64 targets");
+
+    if (Config->SingleRoRx)
+      error("-execute-only and -no-rosegment cannot be used together");
+  }
 }
 
 static const char *getReproduceOption(opt::InputArgList &Args) {
@@ -735,6 +743,8 @@
   Config->EnableNewDtags =
       Args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true);
   Config->Entry = Args.getLastArgValue(OPT_entry);
+  Config->ExecuteOnly = Args.hasFlag(OPT_execute_only,
+                                     OPT_no_execute_only, false);
   Config->ExportDynamic =
       Args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);
   Config->FilterList = args::getStrings(Args, OPT_filter);
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -130,6 +130,7 @@
   bool EhFrameHdr;
   bool EmitRelocs;
   bool EnableNewDtags;
+  bool ExecuteOnly;
   bool ExportDynamic;
   bool FixCortexA53Errata843419;
   bool GcSections;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49456.157569.patch
Type: text/x-patch
Size: 3196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180726/c76bd484/attachment.bin>


More information about the llvm-commits mailing list