[llvm] [BOLT] fix hugify for old krenels (#201813) (PR #201818)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 04:58:06 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: DmitriiMartynov
<details>
<summary>Changes</summary>
The PIE binary optimized with hugify option may crash on kernels below 5.10 due to unexpected segment alignment.
---
Full diff: https://github.com/llvm/llvm-project/pull/201818.diff
2 Files Affected:
- (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+3-1)
- (modified) bolt/test/runtime/hugify.c (+5)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/201818
More information about the llvm-commits
mailing list