[PATCH] D43665: Take SHF_ARM_PURECODE into consideration when setting the program header flags

Rafael Avila de Espindola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 17:54:02 PST 2018


espindola created this revision.
espindola added a reviewer: peter.smith.
Herald added subscribers: kristof.beyls, arichardson, javed.absar, emaste.

Hi Peter,

Is this how SHF_ARM_PURECODE is supposed to work?


https://reviews.llvm.org/D43665

Files:
  ELF/OutputSections.cpp
  test/ELF/arm-execute-only.s


Index: test/ELF/arm-execute-only.s
===================================================================
--- /dev/null
+++ test/ELF/arm-execute-only.s
@@ -0,0 +1,19 @@
+// RUN: llvm-mc -filetype=obj -triple=armv7-pc-linux %s -o %t.o
+// RUN: ld.lld %t.o -o %t.so -shared
+// RUN: llvm-readelf -l %t.so | FileCheck %s
+
+// CHECK-NOT:  LOAD
+// CHECK:      LOAD           0x000000 0x00000000 0x00000000 0x00169 0x00169 R   0x1000
+// CHECK:      LOAD           0x001000 0x00001000 0x00001000 0x00004 0x00004 R E 0x1000
+// CHECK:      LOAD           0x002000 0x00002000 0x00002000 0x00004 0x00004   E 0x1000
+// CHECK:      LOAD           0x003000 0x00003000 0x00003000 0x00038 0x00038 RW  0x1000
+// CHECK-NOT:  LOAD
+
+// CHECK: 01     .dynsym .gnu.hash .hash .dynstr
+// CHECK: 02     .text
+// CHECK: 03     .foo
+// CHECK: 04     .dynamic
+
+        bx lr
+        .section .foo,"axy"
+        bx lr
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -45,7 +45,9 @@
 std::vector<OutputSection *> elf::OutputSections;
 
 uint32_t OutputSection::getPhdrFlags() const {
-  uint32_t Ret = PF_R;
+  uint32_t Ret = 0;
+  if (Config->EMachine != EM_ARM || !(Flags & SHF_ARM_PURECODE))
+    Ret |= PF_R;
   if (Flags & SHF_WRITE)
     Ret |= PF_W;
   if (Flags & SHF_EXECINSTR)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43665.135577.patch
Type: text/x-patch
Size: 1376 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180223/9364f803/attachment.bin>


More information about the llvm-commits mailing list