summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorJob Noorman <jnoorman@igalia.com>2023-05-02 15:43:37 +0200
committerJob Noorman <jnoorman@igalia.com>2023-05-02 16:18:01 +0200
commitf3ea4228fd357090e80eb668cc15692150523d0e (patch)
treef818cd8bd341cb7ca367ad3ae8c242a9a5f3c6d5 /bolt
parente2f7563d7c30c3aca3ac8b937a4967accb59c209 (diff)
downloadllvm-f3ea4228fd357090e80eb668cc15692150523d0e.tar.gz
[BOLT] Make sure all section allocations have deterministic contents
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. Fixes #59008 Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D149243
Diffstat (limited to 'bolt')
-rw-r--r--bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp b/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp
index 8c41ca97fd35..bc0dd2faa694 100644
--- a/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp
+++ b/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp
@@ -27,6 +27,12 @@ uint8_t *ExecutableFileMemoryManager::allocateSection(
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 =