[PATCH] D137921: [LLD][ELF] Add support for OpenBSD PT_OPENBSD_MUTABLE segment type

Brad Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 13 17:00:05 PST 2022


brad created this revision.
brad added a reviewer: MaskRay.
brad added a project: lld.
Herald added subscribers: StephenFan, krytarowski, arichardson, emaste.
Herald added a project: All.
brad requested review of this revision.
Herald added a project: LLVM.

Add support to the linker for 'PT_OPENBSD_MUTABLE' segment type.

https://github.com/openbsd/src/commit/bd249b5664da50f0178adea78250a7a0d8ea6566


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137921

Files:
  lld/ELF/ScriptParser.cpp
  lld/ELF/Writer.cpp


Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -2369,6 +2369,12 @@
     addHdr(PT_GNU_EH_FRAME, part.ehFrameHdr->getParent()->getPhdrFlags())
         ->add(part.ehFrameHdr->getParent());
 
+  // PT_OPENBSD_MUTABLE is an OpenBSD-specific feature. That makes
+  // the dynamic linker fill the segment with zero data, like bss, but
+  // it can be treated differently.
+  if (OutputSection *cmd = findSection(".openbsd.mutable", partNo))
+    addHdr(PT_OPENBSD_MUTABLE, cmd->getPhdrFlags())->add(cmd);
+
   // PT_OPENBSD_RANDOMIZE is an OpenBSD-specific feature. That makes
   // the dynamic linker fill the segment with random data.
   if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo))
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -1575,6 +1575,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_MUTABLE", PT_OPENBSD_MUTABLE)
                      .Case("PT_OPENBSD_RANDOMIZE", PT_OPENBSD_RANDOMIZE)
                      .Case("PT_OPENBSD_WXNEEDED", PT_OPENBSD_WXNEEDED)
                      .Case("PT_OPENBSD_BOOTDATA", PT_OPENBSD_BOOTDATA)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137921.475029.patch
Type: text/x-patch
Size: 1448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221114/cf9e9dd4/attachment.bin>


More information about the llvm-commits mailing list