[PATCH] D25472: [ELF] - Implemented -z wxneeded.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 11 06:19:41 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.

-z wxneeded creates a PHDR PT_OPENBSD_WXNEEDED.

PT_OPENBSD_WXNEEDED
The array element specifies that a process executing this file may need to be able to map or protect memory regions as simultaneously executable and writable. If the system is unable or unwilling to permit that for this executable then it may fail immediately. This segment type is meaningful only for executable files and is ignored in other objects.

http://man.openbsd.org/OpenBSD-current/man5/elf.5


https://reviews.llvm.org/D25472

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/LinkerScript.cpp
  ELF/Writer.cpp
  test/ELF/linkerscript/openbsd-wxneeded.s
  test/ELF/openbsd-wxneeded.s


Index: test/ELF/openbsd-wxneeded.s
===================================================================
--- test/ELF/openbsd-wxneeded.s
+++ test/ELF/openbsd-wxneeded.s
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+# RUN: ld.lld -z wxneeded %t -o %t.out
+# RUN: llvm-readobj --program-headers %t.out | FileCheck %s
+
+# CHECK:      ProgramHeader {
+# CHECK:        Type:  (0x65A3DBE7)
+# CHECK-NEXT:   Offset: 0x0
+# CHECK-NEXT:   VirtualAddress: 0x0
+# CHECK-NEXT:   PhysicalAddress: 0x0
+# CHECK-NEXT:   FileSize: 0
+# CHECK-NEXT:   MemSize: 0
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     PF_X
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Alignment: 0
+# CHECK-NEXT: }
Index: test/ELF/linkerscript/openbsd-wxneeded.s
===================================================================
--- test/ELF/linkerscript/openbsd-wxneeded.s
+++ test/ELF/linkerscript/openbsd-wxneeded.s
@@ -0,0 +1,17 @@
+# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
+# RUN: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; wxneeded PT_OPENBSD_WXNEEDED; }" > %t.script
+# RUN: ld.lld -z wxneeded --script %t.script %t.o -o %t
+# RUN: llvm-readobj --program-headers -s %t | FileCheck %s
+
+# CHECK:      ProgramHeader {
+# CHECK:        Type:  (0x65A3DBE7)
+# CHECK-NEXT:   Offset: 0x0
+# CHECK-NEXT:   VirtualAddress: 0x0
+# CHECK-NEXT:   PhysicalAddress: 0x0
+# CHECK-NEXT:   FileSize: 0
+# CHECK-NEXT:   MemSize: 0
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     PF_R
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Alignment: 0
+# CHECK-NEXT: }
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1109,6 +1109,9 @@
       Hdr.H.p_memsz = Config->ZStackSize;
   }
 
+  if (Config->ZWXNeeded)
+    AddHdr(PT_OPENBSD_WXNEEDED, PF_X);
+
   if (Note.First)
     Ret.push_back(std::move(Note));
   return Ret;
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -1714,6 +1714,7 @@
                      .Case("PT_GNU_EH_FRAME", PT_GNU_EH_FRAME)
                      .Case("PT_GNU_STACK", PT_GNU_STACK)
                      .Case("PT_GNU_RELRO", PT_GNU_RELRO)
+                     .Case("PT_OPENBSD_WXNEEDED", PT_OPENBSD_WXNEEDED)
                      .Default(-1);
 
   if (Ret == (unsigned)-1) {
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -494,6 +494,7 @@
   Config->ZNow = hasZOption(Args, "now");
   Config->ZOrigin = hasZOption(Args, "origin");
   Config->ZRelro = !hasZOption(Args, "norelro");
+  Config->ZWXNeeded = hasZOption(Args, "wxneeded");
 
   if (!Config->Relocatable)
     Config->Strip = getStripOption(Args);
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -126,6 +126,7 @@
   bool ZNow;
   bool ZOrigin;
   bool ZRelro;
+  bool ZWXNeeded;
   DiscardPolicy Discard;
   SortSectionPolicy SortSection;
   StripPolicy Strip = StripPolicy::None;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25472.74238.patch
Type: text/x-patch
Size: 3178 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161011/0ae0e16a/attachment.bin>


More information about the llvm-commits mailing list