From: Daniel Palmer <daniel@thingy.jp>
To: linux@weissschuh.net, w@1wt.eu
Cc: kees@kernel.org, linux-kernel@vger.kernel.org,
Daniel Palmer <daniel@thingy.jp>
Subject: [RFC PATCH 8/9] selftests/nolibc: Add option for building with -static-pie
Date: Sat, 31 Jan 2026 16:44:39 +0900 [thread overview]
Message-ID: <20260131074440.732588-9-daniel@thingy.jp> (raw)
In-Reply-To: <20260131074440.732588-1-daniel@thingy.jp>
Allow the tests to build with -static-pie instead of -static to
test the self relocation code works.
Note: This doesn't work 100% correctly. For x86_64 I can see the
test binary is static or static-pie depending on if -static or
-static-pie is used but for m68k it's always static and I had
to hack in the workaround.
I have somehow got the tests to seem to produce static PIE
binaries when requested, and regular static ones when not but
its a mess and this can't be used as-is.
Signed-off-by: Daniel Palmer <daniel@thingy.jp>
---
tools/testing/selftests/nolibc/Makefile | 2 +-
tools/testing/selftests/nolibc/Makefile.nolibc | 8 ++++----
tools/testing/selftests/nolibc/run-tests.sh | 10 +++++++++-
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index 40f5c2908dda..5d5c3231cc19 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -9,7 +9,7 @@ cc-option = $(call __cc-option, $(CC),,$(1),$(2))
include Makefile.include
-CFLAGS = -nostdlib -nostdinc -static \
+CFLAGS = -nostdlib -nostdinc \
-isystem $(top_srcdir)/tools/include/nolibc -isystem $(top_srcdir)/usr/include \
$(CFLAGS_NOLIBC_TEST)
diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing/selftests/nolibc/Makefile.nolibc
index f9d43cbdc894..c55f4c17e06d 100644
--- a/tools/testing/selftests/nolibc/Makefile.nolibc
+++ b/tools/testing/selftests/nolibc/Makefile.nolibc
@@ -304,12 +304,12 @@ sysroot/$(ARCH)/include:
ifneq ($(NOLIBC_SYSROOT),0)
nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include
- $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
- -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
+ -nostdlib -nostdinc -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
else
nolibc-test: nolibc-test.c nolibc-test-linkage.c
- $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
- -nostdlib -static -include $(srctree)/tools/include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
+ -nostdlib -include $(srctree)/tools/include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
endif
libc-test: nolibc-test.c nolibc-test-linkage.c
diff --git a/tools/testing/selftests/nolibc/run-tests.sh b/tools/testing/selftests/nolibc/run-tests.sh
index 3917cfb8fdc4..12b4774a77d8 100755
--- a/tools/testing/selftests/nolibc/run-tests.sh
+++ b/tools/testing/selftests/nolibc/run-tests.sh
@@ -16,6 +16,7 @@ build_location="$(realpath "${cache_dir}"/nolibc-tests/)"
perform_download=0
test_mode=system
werror=1
+staticpie=0
llvm=
all_archs=(
i386 x86_64 x32
@@ -31,7 +32,7 @@ all_archs=(
)
archs="${all_archs[@]}"
-TEMP=$(getopt -o 'j:d:c:b:a:m:pelh' -n "$0" -- "$@")
+TEMP=$(getopt -o 'j:d:c:b:a:m:peslh' -n "$0" -- "$@")
eval set -- "$TEMP"
unset TEMP
@@ -55,6 +56,7 @@ Options:
-b [DIR] Build location (default: ${build_location})
-m [MODE] Test mode user/system (default: ${test_mode})
-e Disable -Werror
+ -s Enable static PIE (default: ${staticpie})
-l Build with LLVM/clang
EOF
}
@@ -85,6 +87,9 @@ while true; do
'-e')
werror=0
shift; continue ;;
+ '-s')
+ staticpie=1
+ shift; continue ;;
'-l')
llvm=1
shift; continue ;;
@@ -171,6 +176,9 @@ test_arch() {
if [ "$werror" -ne 0 ]; then
CFLAGS_EXTRA="$CFLAGS_EXTRA -Werror -Wl,--fatal-warnings"
fi
+ if [ "$staticpie" -ne 0 ]; then
+ CFLAGS_EXTRA="$CFLAGS_EXTRA -ggdb -fPIE -pie -Wl,--no-dynamic-linker -Wl,-ztext -Wl,-zseparate-code"
+ fi
MAKE=(make -f Makefile.nolibc -j"${nproc}" XARCH="${arch}" CROSS_COMPILE="${cross_compile}" LLVM="${llvm}" O="${build_dir}")
case "$test_mode" in
--
2.51.0
next prev parent reply other threads:[~2026-01-31 7:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-31 7:44 [RFC PATCH 0/9] nolibc: Add static-pie support Daniel Palmer
2026-01-31 7:44 ` [RFC PATCH 1/9] elf: Add relocation types used by nolibc Daniel Palmer
2026-02-01 16:25 ` Thomas Weißschuh
2026-01-31 7:44 ` [RFC PATCH 2/9] tools/nolibc: crt: Split _start_c() into stack-only and normal part Daniel Palmer
2026-02-01 16:33 ` Thomas Weißschuh
2026-01-31 7:44 ` [RFC PATCH 3/9] tools/nolibc: Add basic ELF self-relocation support for static PIE Daniel Palmer
2026-02-01 16:42 ` Thomas Weißschuh
2026-02-01 21:54 ` Daniel Palmer
2026-01-31 7:44 ` [RFC PATCH 4/9] tools/nolibc: m68k: Add relocation support Daniel Palmer
2026-01-31 7:44 ` [RFC PATCH 5/9] tools/nolibc: x86: Add relocation support for x86_64 Daniel Palmer
2026-02-01 17:56 ` Willy Tarreau
2026-01-31 7:44 ` [RFC PATCH 6/9] tools/nolibc: riscv: Add relocation support Daniel Palmer
2026-01-31 7:44 ` [RFC PATCH 7/9] tools/nolibc: arm: " Daniel Palmer
2026-01-31 7:44 ` Daniel Palmer [this message]
2026-01-31 7:44 ` [RFC PATCH 9/9] fs/binfmt_elf_fdpic: Reflect that PIE binaries also work in KConfig help Daniel Palmer
2026-02-01 16:27 ` Thomas Weißschuh
2026-02-01 18:14 ` [RFC PATCH 0/9] nolibc: Add static-pie support Willy Tarreau
2026-02-01 21:45 ` Daniel Palmer
2026-02-01 21:49 ` Willy Tarreau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260131074440.732588-9-daniel@thingy.jp \
--to=daniel@thingy.jp \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome