From 9eb3c69bac0fdfb4e71b2594d0488774e212c5e3 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 4 Jul 2026 13:32:10 +0800
Subject: [PATCH] thp: Link THP PDE tests with $(LOAD-THP-ADDRESS-LDFLAGS)

LOAD-THP-ADDRESS-LDFLAGS was added to work around:

https://sourceware.org/bugzilla/show_bug.cgi?id=34184

which is needed for THP PDE tests.  Add $(LOAD-THP-ADDRESS-LDFLAGS) to
LDFLAGS-tst-thp-1 and LDFLAGS-tst-thp-1-no-s-code if PIE isn't built
by default so that they are linked with $(LOAD-THP-ADDRESS-LDFLAGS).
This fixes BZ #34314.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 sysdeps/unix/sysv/linux/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 1efeac5213..0f8fc24b1f 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -770,6 +770,9 @@ test-xfail-tst-thp-1-no-s-code-static = yes
 endif
 
 LDFLAGS-tst-thp-1 = -Wl,-z,separate-code $(THP-PAGE-SIZE-LDFLAGS)
+ifneq (yes,$(build-pie-default))
+LDFLAGS-tst-thp-1 += $(LOAD-THP-ADDRESS-LDFLAGS)
+endif
 LDFLAGS-tst-thp-1-pde = -Wl,-z,separate-code $(THP-PAGE-SIZE-LDFLAGS) \
 			$(LOAD-THP-ADDRESS-LDFLAGS)
 LDFLAGS-tst-thp-1-static = -Wl,-z,separate-code $(THP-PAGE-SIZE-LDFLAGS)
@@ -778,6 +781,9 @@ LDFLAGS-tst-thp-1-static += $(LOAD-THP-ADDRESS-LDFLAGS)
 endif
 LDFLAGS-tst-thp-1-no-s-code = -Wl,-z,noseparate-code \
 			      $(THP-PAGE-SIZE-LDFLAGS)
+ifneq (yes,$(build-pie-default))
+LDFLAGS-tst-thp-1-no-s-code += $(LOAD-THP-ADDRESS-LDFLAGS)
+endif
 LDFLAGS-tst-thp-1-no-s-code-pde = -Wl,-z,noseparate-code \
 				  $(THP-PAGE-SIZE-LDFLAGS) \
 				  $(LOAD-THP-ADDRESS-LDFLAGS)
-- 
2.54.0

