[llvm] [Draft][BOLT] fix hugify for old kernels (#201813) (PR #201818)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 03:45:36 PDT 2026
https://github.com/DmitriiMartynov updated https://github.com/llvm/llvm-project/pull/201818
>From 97e6791030b93b4157d6dfda56049bf55750a754 Mon Sep 17 00:00:00 2001
From: Dmitrii Martynov <martynovdmitryvladimirovich at yandex.ru>
Date: Fri, 5 Jun 2026 13:03:50 +0300
Subject: [PATCH] [BOLT] fix hugify for old krenels (#201813)
The PIE binary optimized with hugify option may crash on kernels
below 5.10 due to unexpected segment alignment.
---
bolt/lib/Rewrite/RewriteInstance.cpp | 4 +++-
bolt/test/runtime/hugify.c | 5 +++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 9364e32939982..4b2f777000d50 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -705,6 +705,7 @@ Error RewriteInstance::discoverStorage(ELFObjectFile<ELFT> *ELFObjFile) {
// Hugify: Additional huge page from left side due to
// weird ASLR mapping addresses (4KB aligned)
+ // dm: no need for kernels 5.10 and above
if (opts::Hugify && !BC->HasFixedLoadAddress) {
NextAvailableAddress += BC->PageAlign;
}
@@ -4251,9 +4252,10 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
// Hugify: Additional huge page from right side due to
// weird ASLR mapping addresses (4KB aligned)
+ // dm: For kernels 5.10 and above alignment is enough
if (opts::Hugify && !BC->HasFixedLoadAddress &&
Section->getName() == LastNonColdSectionName)
- Address = alignTo(Address, Section->getAlignment());
+ Address += BC->PageAlign;
}
// Make sure we allocate enough space for huge pages.
diff --git a/bolt/test/runtime/hugify.c b/bolt/test/runtime/hugify.c
index a4a718a1160df..ec234515351da 100644
--- a/bolt/test/runtime/hugify.c
+++ b/bolt/test/runtime/hugify.c
@@ -2,6 +2,11 @@
#include <stdio.h>
+// For testing hugify on kernels below 5.10 without patch
+// "fs/binfmt_elf: use PT_LOAD p_align values for suitable start address"
+const char dummy_const_var_in_text[2 * 1024 * 1024 - 0x1000]
+ __attribute__((section(".text")));
+
int main(int argc, char **argv) {
printf("Hello world\n");
return 0;
More information about the llvm-commits
mailing list