[PATCH v2] elf: Only build THP tests for ABIs that define THP-PAGE-SIZE
Carlos O'Donell
carlos@redhat.com
Mon Sep 28 13:45:52 GMT 2026
On 9/3/26 12:25 PM, Adhemerval Zanella wrote:
> The THP tests added by 53d909a283085c82bdcc71e1cf06c0899506b664 only
> make sense for ABIs that support THP. Also, some ABIs have a strict
> limit for the PT_LOAD alignment value; for instance, on arc, the
> large alignment makes the R_ARC_S25W_PCREL branch from __start to
> __libc_start_mainn in the static tests exceed its +-16 6MB range.
>
> Explicit disable the tests on ABIs that do not support it, but
> setting THP-PAGE-SIZE to 0 and define a suitable value for each
> ABI:
>
> * aarch64: 32MB (16KB base pages; 4KB uses 2MB, 64KB uses 512MB which
> is larger than MAX_THP_PAGESIZE).
>
> * arc: 2MB (MMUv4 only; the kernel supports 2MB and 16MB super pages,
> but a 16MB PT_LOAD alignment can not be linked on arc.
>
> * arm: 2MB (LPAE only).
>
> * i386: 4MB (non-PAE PGD level huge page; PAE and 64-bit kernels use
> 2MB).
>
> * loongarch: 32MB (default 16KB base pages; 4KB uses 2MB, 64KB uses
> 512MB which is larger than MAX_THP_PAGESIZE).
>
> * mips: 32MB (16KB base pages on 64-bit and 32-bit huge TLB layouts;
> 4KB uses 2MB, 64KB uses 512MB which is larger than MAX_THP_PAGESIZE).
>
> * powerpc: 16MB (book3s64 only; hash MMU with 64KB base pages uses
> 16MB, radix uses 2MB).
>
> * riscv: 2MB (64-bit only).
>
> * s390: 1MB (segment size).
>
> * sparc: 8MB (sparc64 only, unchanged).
>
> * x86_64: 2MB (also for x32).
>
> The remaining Linux ABIs (alpha, csky, hppa, m68k, microblaze, or1k,
> and sh) do not support transparent huge pages and no longer build the
> THP tests.
>
> Tested with a 'make check run-built-tests=no' on all affected ABIs
> and checked on x86_64-linux-gnu and aarch64-linux-gnu.
LGTM.
Covers Florian's comment from v1.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> sysdeps/unix/sysv/linux/Makefile | 24 +++++++++++++++------
> sysdeps/unix/sysv/linux/aarch64/Makefile | 8 +++++++
> sysdeps/unix/sysv/linux/alpha/Makefile | 4 ++++
> sysdeps/unix/sysv/linux/arc/Makefile | 6 ++++++
> sysdeps/unix/sysv/linux/csky/Makefile | 4 ++++
> sysdeps/unix/sysv/linux/hppa/Makefile | 1 +
> sysdeps/unix/sysv/linux/i386/Makefile | 4 ++++
> sysdeps/unix/sysv/linux/loongarch/Makefile | 10 ++++++++-
> sysdeps/unix/sysv/linux/m68k/Makefile | 4 ++++
> sysdeps/unix/sysv/linux/microblaze/Makefile | 4 ++++
> sysdeps/unix/sysv/linux/mips/Makefile | 8 +++++++
> sysdeps/unix/sysv/linux/or1k/Makefile | 4 ++++
> sysdeps/unix/sysv/linux/powerpc/Makefile | 5 +++++
> sysdeps/unix/sysv/linux/s390/Makefile | 3 +++
> sysdeps/unix/sysv/linux/sh/Makefile | 4 ++++
> 15 files changed, 86 insertions(+), 7 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
> index 1b15cdc53e..3a31fb3caa 100644
> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -713,19 +713,13 @@ $(objpfx)pldd: $(objpfx)xmalloc.o
> tests += \
> tst-rseq-tls-range \
> tst-rseq-tls-range-4096 \
> - tst-thp-1 \
> - tst-thp-1-pde \
> - tst-thp-1-static \
> - tst-thp-align \
> # tests
> tests-static += \
> tst-rseq-tls-range-4096-static \
> tst-rseq-tls-range-static \
> - tst-thp-1-static \
> # tests-static
> modules-names += \
> tst-rseq-tls-range-mod \
> - tst-thp-size-mod \
> # modules-names
> CFLAGS-tst-rseq-tls-range.c += -DMAIN_TLS_ALIGN=4
> CFLAGS-tst-rseq-tls-range-4096.c += -DMAIN_TLS_ALIGN=4096
> @@ -746,12 +740,29 @@ tests-special += \
> # tests-special
> endif
>
> +# THP-PAGE-SIZE is the largest PMD transparent huge page size the ABI supports
> +# that does not exceed MAX_THP_PAGESIZE. Default to 2MB, the most common PMD
> +# huge page size, and each ABIs with a different size can override it in their
> +# sysdeps Makefile or set it to 0 to skip the THP tests.
> ifndef THP-PAGE-SIZE
> # Align PT_LOAD segments in THP tests to THP page size so that kernel will
> # map PIE to the address aligned to THP page size. Default THP page size
> # to 2MB which can be overridden in Makefile in subdirectories.
> THP-PAGE-SIZE = 0x200000
> endif
> +ifneq (0,$(THP-PAGE-SIZE))
> +tests += \
> + tst-thp-1 \
> + tst-thp-1-pde \
> + tst-thp-1-static \
> + tst-thp-align \
> +# tests
> +tests-static += \
> + tst-thp-1-static \
> +# tests-static
> +modules-names += \
> + tst-thp-size-mod \
> +# modules-names
OK. Perfect, move to THP-PAGE-SIZE. Also many of these won't even build as noted before.
>
> THP-PAGE-SIZE-CFLAGS = -DTHP_PAGE_SIZE=$(THP-PAGE-SIZE)
> THP-PAGE-SIZE-LDFLAGS = -Wl,-z,max-page-size=$(THP-PAGE-SIZE)
> @@ -935,6 +946,7 @@ $(objpfx)strace-tst-thp-align-disabled.out: \
> $(evaluate-test)
> endif # [madvise]
> endif # $(cross-compiling)
> +endif # $(THP-PAGE-SIZE)
> endif # $(subdir) == elf
>
> ifeq ($(subdir),rt)
> diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
> index baefac15b5..95dc0a165f 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/Makefile
> +++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
> @@ -1,4 +1,12 @@
> ifeq ($(subdir),elf)
> +# The PMD transparent huge page size depends of the page size:
> +# * 4Kb -> 2MB
> +# * 16Kb -> 32MB
> +# * 64Kb -> 512MB
> +# Use 32MB for now. The 512MB is larger than MAX_THP_PAGESIZE, and
> +# the THP tests are marked as unsupported at runtime.
> +THP-PAGE-SIZE = 0x2000000
> +
> tests += \
> tst-tlsdesc-pac \
> # tests
> diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile
> index d7c7d7fc16..4180d339bb 100644
> --- a/sysdeps/unix/sysv/linux/alpha/Makefile
> +++ b/sysdeps/unix/sysv/linux/alpha/Makefile
> @@ -34,3 +34,7 @@ ifeq ($(subdir),conform)
> # For bug 21260.
> conformtest-xfail-conds += alpha-linux
> endif
> +
> +ifeq ($(subdir),elf)
> +THP-PAGE-SIZE = 0
> +endif
> diff --git a/sysdeps/unix/sysv/linux/arc/Makefile b/sysdeps/unix/sysv/linux/arc/Makefile
> index dd3da52c39..c3f409ec0e 100644
> --- a/sysdeps/unix/sysv/linux/arc/Makefile
> +++ b/sysdeps/unix/sysv/linux/arc/Makefile
> @@ -11,3 +11,9 @@ ifeq ($(subdir),misc)
> sysdep_headers += sys/cachectl.h
> sysdep_routines += cacheflush
> endif
> +
> +# Note for THP-PAGE-SIZE: only MMUv4 supports transparent huge pages, and
> +# the PMD size is a kernel configuration choice (ARC_HUGEPAGE_2M or
> +# ARC_HUGEPAGE_16M). Only the default 2MB is supported, a 16MB PT_LOAD
> +# alignment can not be linked on arc because the R_ARC_S25W_PCREL branch
> +# from __start to __libc_start_main in static tests has a +-16MB range.
> diff --git a/sysdeps/unix/sysv/linux/csky/Makefile b/sysdeps/unix/sysv/linux/csky/Makefile
> index 4462bc0bc7..e338473c17 100644
> --- a/sysdeps/unix/sysv/linux/csky/Makefile
> +++ b/sysdeps/unix/sysv/linux/csky/Makefile
> @@ -6,3 +6,7 @@ endif
> ifeq ($(subdir),stdlib)
> gen-as-const-headers += ucontext_i.sym
> endif
> +
> +ifeq ($(subdir),elf)
> +THP-PAGE-SIZE = 0
> +endif
> diff --git a/sysdeps/unix/sysv/linux/hppa/Makefile b/sysdeps/unix/sysv/linux/hppa/Makefile
> index 9eebe8e0e7..658949dff3 100644
> --- a/sysdeps/unix/sysv/linux/hppa/Makefile
> +++ b/sysdeps/unix/sysv/linux/hppa/Makefile
> @@ -13,6 +13,7 @@ test-xfail-check-execstack = yes
> # trampoline used during lazy binding.
> test-xfail-check-wx-segment = *
>
> +THP-PAGE-SIZE = 0
> endif # $(subdir) == elf
>
> ifeq ($(subdir),misc)
> diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
> index 9a70905df8..d3def32ee0 100644
> --- a/sysdeps/unix/sysv/linux/i386/Makefile
> +++ b/sysdeps/unix/sysv/linux/i386/Makefile
> @@ -41,4 +41,8 @@ CFLAGS-dl-mmap.o = $(no-stack-protector)
> CFLAGS-dl-mmap.op = $(no-stack-protector)
> CFLAGS-dl-writev.o = $(no-stack-protector)
> CFLAGS-dl-writev.op = $(no-stack-protector)
> +
> +# Non-PAE kernels map the transparent huge page at the PGD level (4MB),
> +# while PAE and 64-bit kernels use a 2MB PMD huge page.
> +THP-PAGE-SIZE = 0x400000
> endif
> diff --git a/sysdeps/unix/sysv/linux/loongarch/Makefile b/sysdeps/unix/sysv/linux/loongarch/Makefile
> index d5beb62440..9ee9adc592 100644
> --- a/sysdeps/unix/sysv/linux/loongarch/Makefile
> +++ b/sysdeps/unix/sysv/linux/loongarch/Makefile
> @@ -13,5 +13,13 @@ abi-ilp32d-condition := __WORDSIZE == 32 && defined __loongarch_double_float
> abi-lp64s-condition := __WORDSIZE == 64 && defined __loongarch_soft_float
> abi-lp64d-condition := __WORDSIZE == 64 && defined __loongarch_double_float
>
> -# Align THP tests to 32MB.
> +ifeq ($(subdir),elf)
> +# The PMD transparent huge page size depends of the page size:
> +# * 4KB -> 2MB
> +# * 16KB -> 32MB
> +# * 64KB -> 512MB
> +# Use 32MB for now, which is also de default. The 512MB is larger
> +# than MAX_THP_PAGESIZE, and the THP tests are marked as unsupported
> +# at runtime.
> THP-PAGE-SIZE = 0x2000000
> +endif
> diff --git a/sysdeps/unix/sysv/linux/m68k/Makefile b/sysdeps/unix/sysv/linux/m68k/Makefile
> index 6640cb4a28..7ca5a2b1f3 100644
> --- a/sysdeps/unix/sysv/linux/m68k/Makefile
> +++ b/sysdeps/unix/sysv/linux/m68k/Makefile
> @@ -15,3 +15,7 @@ ifeq ($(subdir),misc)
> sysdep_routines += mremap
> sysdep_headers += sys/reg.h
> endif
> +
> +ifeq ($(subdir),elf)
> +THP-PAGE-SIZE = 0
> +endif
> diff --git a/sysdeps/unix/sysv/linux/microblaze/Makefile b/sysdeps/unix/sysv/linux/microblaze/Makefile
> index 614553204f..31a7c382ce 100644
> --- a/sysdeps/unix/sysv/linux/microblaze/Makefile
> +++ b/sysdeps/unix/sysv/linux/microblaze/Makefile
> @@ -1,3 +1,7 @@
> ifeq ($(subdir),resource)
> sysdep_routines += backtrace_linux
> endif
> +
> +ifeq ($(subdir),elf)
> +THP-PAGE-SIZE = 0
> +endif
> diff --git a/sysdeps/unix/sysv/linux/mips/Makefile b/sysdeps/unix/sysv/linux/mips/Makefile
> index 05ec9150b2..03f047eafe 100644
> --- a/sysdeps/unix/sysv/linux/mips/Makefile
> +++ b/sysdeps/unix/sysv/linux/mips/Makefile
> @@ -63,6 +63,14 @@ ifneq ($(mips-has-gnustack),yes)
> test-xfail-check-execstack = yes
> CFLAGS-tst-execstack.c += -DDEFAULT_RWX_STACK=1
> endif
> +
> +# The PMD transparent huge page size depends of the page size:
> +# * 4KB -> 2MB
> +# * 16KB -> 32MB
> +# * 64KB -> 512MB
> +# Use 32MB for now. The 512MB is larger than MAX_THP_PAGESIZE, and
> +# the THP tests are marked as unsupported at runtime.
> +THP-PAGE-SIZE = 0x2000000
> endif
>
> ifeq ($(subdir),stdlib)
> diff --git a/sysdeps/unix/sysv/linux/or1k/Makefile b/sysdeps/unix/sysv/linux/or1k/Makefile
> index 7d85fb6eea..655e8388a8 100644
> --- a/sysdeps/unix/sysv/linux/or1k/Makefile
> +++ b/sysdeps/unix/sysv/linux/or1k/Makefile
> @@ -5,3 +5,7 @@ endif
> ifeq ($(subdir),stdlib)
> gen-as-const-headers += ucontext_i.sym
> endif
> +
> +ifeq ($(subdir),elf)
> +THP-PAGE-SIZE = 0
> +endif
> diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile
> index cddb624bf2..8be4fd99e6 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/Makefile
> +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile
> @@ -17,6 +17,11 @@ dl-routines += \
> dl-hwcap-info \
> # dl-routines
>
> +# Only book3s64 supports transparent huge pages. The radix MMU uses a 2MB
> +# PMD huge page, while the hash MMU (with 64KB base pages) uses a 16MB
> +# huge page.
> +THP-PAGE-SIZE = 0x1000000
> +
> # Otherwise tst-tls-dlinfo fails due to tst-tlsmod2.so using static tls.
> ifeq ($(have-tls-get-addr-optimize),yes)
> LDFLAGS-tst-tlsmod2.so += -Wl,--no-tls-get-addr-optimize
> diff --git a/sysdeps/unix/sysv/linux/s390/Makefile b/sysdeps/unix/sysv/linux/s390/Makefile
> index 3033290998..630f80b8a8 100644
> --- a/sysdeps/unix/sysv/linux/s390/Makefile
> +++ b/sysdeps/unix/sysv/linux/s390/Makefile
> @@ -1,4 +1,7 @@
> ifeq ($(subdir),elf)
> +# The segment (PMD) transparent huge page size is 1MB.
> +THP-PAGE-SIZE = 0x100000
> +
> ifeq (yes,$(build-shared))
> # This is needed to support g++ v2 and v3.
> sysdep_routines += \
> diff --git a/sysdeps/unix/sysv/linux/sh/Makefile b/sysdeps/unix/sysv/linux/sh/Makefile
> index 8c4cb73824..d38be5851a 100644
> --- a/sysdeps/unix/sysv/linux/sh/Makefile
> +++ b/sysdeps/unix/sysv/linux/sh/Makefile
> @@ -16,3 +16,7 @@ ifeq ($(subdir),math)
> # The libm.so link can't find __fpscr_values
> libm.so-no-z-defs = yes
> endif
> +
> +ifeq ($(subdir),elf)
> +THP-PAGE-SIZE = 0
> +endif
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list