[PATCH] thp: Limit THP code padding to 2 * THP page size
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Jun 23 16:05:21 GMT 2026
On 23/06/26 01:51, H.J. Lu wrote:
> Since R_ARC_S25W_PCREL range is limited, 32MB THP code padding leads to
> relocation overflow:
>
> .../support/libsupport_nonshared.a(support_test_main.oS):
> in function `support_test_main':
> .../support/support_test_main.c:396:(.text+0x650): relocation
> truncated to fit: R_ARC_S25W_PCREL_PLT against symbol `atexit' defined
> in .text section in
> ../glibc/libc_nonshared.a(atexit.oS)
> .../install/compilers/arc-linux-gnu/arc-glibc-linux-gnu/bin/ld: final
> link failed
> collect2: error: ld returned 1 exit status
>
> Limit THP code padding to 2 * THP page size to avoid R_ARC_S25W_PCREL
> relocation overflow.
>
> Tested natively for Linux/x86-64 and Linux/i686 as well as with
> build-many-glibcs.py for arc-linux-gnu.
>
> This fixes BZ #34311
>
>
> From 0fa8b7fddf0aaad47a4761f959ca226d9457fe9c Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Tue, 23 Jun 2026 08:10:05 +0800
> Subject: [PATCH] thp: Limit THP code padding to 2 * THP page size
>
> Since R_ARC_S25W_PCREL range is limited, 32MB THP code padding leads to
> relocation overflow:
>
> .../support/libsupport_nonshared.a(support_test_main.oS):
> in function `support_test_main':
> .../support/support_test_main.c:396:(.text+0x650): relocation truncated to fit: R_ARC_S25W_PCREL_PLT against symbol `atexit' defined in .text section in
> ../glibc/libc_nonshared.a(atexit.oS)
> .../install/compilers/arc-linux-gnu/arc-glibc-linux-gnu/bin/ld: final link failed
> collect2: error: ld returned 1 exit status
>
> Limit THP code padding to 2 * THP page size to avoid R_ARC_S25W_PCREL
> relocation overflow.
>
> Tested natively for Linux/x86-64 and Linux/i686 as well as with
> build-many-glibcs.py for arc-linux-gnu.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>
> This fixes BZ #34311
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
> sysdeps/unix/sysv/linux/Makefile | 15 +++++++++------
> sysdeps/unix/sysv/linux/tst-thp-size.S | 20 ++++++++++++++++++++
> 2 files changed, 29 insertions(+), 6 deletions(-)
> create mode 100644 sysdeps/unix/sysv/linux/tst-thp-size.S
>
> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
> index a048dbc732..1efeac5213 100644
> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -737,6 +737,7 @@ ifndef THP-PAGE-SIZE
> THP-PAGE-SIZE = 0x200000
> endif
>
> +THP-PAGE-SIZE-CFLAGS = -DTHP_PAGE_SIZE=$(THP-PAGE-SIZE)
> THP-PAGE-SIZE-LDFLAGS = -Wl,-z,max-page-size=$(THP-PAGE-SIZE)
>
> # -Wl,-z,max-page-size=$(THP-PAGE-SIZE) alone doesn't work for PDE when
> @@ -786,9 +787,11 @@ ifneq (yes,$(enable-static-pie))
> LDFLAGS-tst-thp-1-no-s-code-static += $(LOAD-THP-ADDRESS-LDFLAGS)
> endif
>
> -$(objpfx)tst-thp-1-no-s-code: $(objpfx)tst-thp-size-mod.o
> -$(objpfx)tst-thp-1-no-s-code-pde: $(objpfx)tst-thp-size-mod.o
> -$(objpfx)tst-thp-1-no-s-code-static: $(objpfx)tst-thp-size-mod.o
> +ASFLAGS-tst-thp-size.S = $(THP-PAGE-SIZE-CFLAGS)
> +
> +$(objpfx)tst-thp-1-no-s-code: $(objpfx)tst-thp-size.o
> +$(objpfx)tst-thp-1-no-s-code-pde: $(objpfx)tst-thp-size.o
> +$(objpfx)tst-thp-1-no-s-code-static: $(objpfx)tst-thp-size.o
>
> tst-thp-1-no-s-code-ENV = GLIBC_TUNABLES=glibc.elf.thp=1
> tst-thp-1-no-s-code-pde-ENV = GLIBC_TUNABLES=glibc.elf.thp=1
> @@ -800,9 +803,9 @@ tst-thp-1-ENV = GLIBC_TUNABLES=glibc.elf.thp=1
> tst-thp-1-pde-ENV = GLIBC_TUNABLES=glibc.elf.thp=1
> tst-thp-1-static-ENV = GLIBC_TUNABLES=glibc.elf.thp=1
>
> -$(objpfx)tst-thp-1: $(objpfx)tst-thp-size-mod.o
> -$(objpfx)tst-thp-1-pde: $(objpfx)tst-thp-size-mod.o
> -$(objpfx)tst-thp-1-static: $(objpfx)tst-thp-size-mod.o
> +$(objpfx)tst-thp-1: $(objpfx)tst-thp-size.o
> +$(objpfx)tst-thp-1-pde: $(objpfx)tst-thp-size.o
> +$(objpfx)tst-thp-1-static: $(objpfx)tst-thp-size.o
>
> tst-thp-1-pde-no-pie = yes
>
> diff --git a/sysdeps/unix/sysv/linux/tst-thp-size.S b/sysdeps/unix/sysv/linux/tst-thp-size.S
> new file mode 100644
> index 0000000000..29c5f4e750
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-thp-size.S
> @@ -0,0 +1,20 @@
> +/* A file that provides THP code size for testing.
> + Copyright (C) 2026 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> + .text
> + .space 2 * THP_PAGE_SIZE
> --
> 2.54.0
>
More information about the Libc-alpha
mailing list