[PATCH] D149243: [BOLT] Make sure all section allocations have deterministic contents

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 01:29:37 PDT 2023


jobnoorman created this revision.
jobnoorman added reviewers: rafauler, maksfb, yota9, Amir.
Herald added subscribers: asb, treapster, pmatos, ayermolo, mgrang.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

For empty sections, RuntimeDyld always allocates 1 byte but leaves it
uninitialized. This causes the contents of some output sections to be
non-deterministic.

Note that this issue is also solved by D147544 <https://reviews.llvm.org/D147544>.

Fixes 59008


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149243

Files:
  bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp


Index: bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp
===================================================================
--- bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp
+++ bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp
@@ -27,6 +27,12 @@
   uint8_t *Ret = static_cast<uint8_t *>(llvm::allocate_buffer(Size, Alignment));
   AllocatedSections.push_back(AllocInfo{Ret, Size, Alignment});
 
+  // A Size of 1 might mean an empty section for which RuntimeDyld decided to
+  // allocate 1 byte. In this case, the allocation will never be initialized
+  // causing non-deterministic output section contents.
+  if (Size == 1)
+    *Ret = 0;
+
   // Register a debug section as a note section.
   if (!ObjectsLoaded && RewriteInstance::isDebugSection(SectionName)) {
     BinarySection &Section =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149243.517090.patch
Type: text/x-patch
Size: 800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230426/9d623c63/attachment.bin>


More information about the llvm-commits mailing list