[compiler-rt] [compiler-rt] [test] refine target_page_size() in lit.common.cfg.py (NFC) (PR #170475)
Mészáros Gergely via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 8 01:57:41 PST 2025
https://github.com/Maetveis updated https://github.com/llvm/llvm-project/pull/170475
>From 23e12765c5b2cee579c8611dabf63206779d7cb3 Mon Sep 17 00:00:00 2001
From: "Meszaros, Gergely" <gergely.meszaros at intel.com>
Date: Wed, 3 Dec 2025 04:52:36 -0800
Subject: [PATCH 1/2] [compiler-rt] [test] refine target_page_size() in
lit.common.cfg.py (NFC)
Use mmap.PAGESIZE if os.sysconf is not available.
This allows to query the page size on Windows too, which has mmap but not
sysconf.
This is a pedantic change because Windows has a fixed page size of 4KiB.
I found this independently of #168857, and thought it might be worth
committing, since this is technically more correct.
---
compiler-rt/test/lit.common.cfg.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index dce01cc9743b3..9a105aa84afce 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -971,8 +971,19 @@ def target_page_size():
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
+ # Unix has sysconf,
+ # Windows can use mmap.PAGESIZE
+ # Not using mmap.PAGESIZE everywhere because
+ # it is not available in WASI, but sysconf is.
out, err = proc.communicate(
- b'import os; print(os.sysconf("SC_PAGESIZE") if hasattr(os, "sysconf") else "")'
+ b"""
+try:
+ from os import sysconf
+ print(sysconf("SC_PAGESIZE"))
+except ImportError:
+ from mmap import PAGESIZE
+ print(PAGESIZE)
+"""
)
return int(out)
except:
>From 28bbdc295d9804396814b5f55ec29c8a4d408ac3 Mon Sep 17 00:00:00 2001
From: "Meszaros, Gergely" <gergely.meszaros at intel.com>
Date: Mon, 8 Dec 2025 01:57:07 -0800
Subject: [PATCH 2/2] Swap fallback order, try mmap.PAGESIZE first, then
os.sysconf.
---
compiler-rt/test/lit.common.cfg.py | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 9a105aa84afce..fb559753a1041 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -971,18 +971,16 @@ def target_page_size():
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
- # Unix has sysconf,
- # Windows can use mmap.PAGESIZE
- # Not using mmap.PAGESIZE everywhere because
- # it is not available in WASI, but sysconf is.
+ # UNIX (except WASI) and Windows can use mmap.PAGESIZE,
+ # attempt to use os.sysconf for other targets.
out, err = proc.communicate(
b"""
try:
- from os import sysconf
- print(sysconf("SC_PAGESIZE"))
-except ImportError:
from mmap import PAGESIZE
print(PAGESIZE)
+except ImportError:
+ from os import sysconf
+ print(sysconf("SC_PAGESIZE"))
"""
)
return int(out)
More information about the llvm-commits
mailing list