From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB72A40756B for ; Wed, 4 Feb 2026 12:46:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209163; cv=none; b=CUOKUTJrkHdPtFek28pYxLfUNCUVPVukGKUAPQmbm88X7kNTOQ8t7acMLOCry5+VVM882kPAEA4IgHSSh8pxeIUCUZ20mpMlM5hAZIYKQbw+TEaIO+lkBZLuSyrTWM3JRZQ4BR7flazYbCNtCeiGCLj7nNCRp5Btiy79jPZyMEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209163; c=relaxed/simple; bh=K1HB1drOWj5j33NGKYCuiSya0F7BuXnyoBGH67Q5AGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dnqQMyitMzfpgmNUS+tJxhQmK1wCOopgMCWgFOEArkifkn4jNh6niFajO6aYvMWmZ6eA8blqKYmMIL5TCPYdNsQZMBOAlv4K/R1eIN49jOSKSS2zbqVpzYID4DZ66H3f5AL+19dm9VvBANjOi63TUCz1fprDv8sgnjNZk5bq698= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=MBbx6oOD; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="MBbx6oOD" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-c633984fbeeso347518a12.0 for ; Wed, 04 Feb 2026 04:46:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209163; x=1770813963; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OvIzJVD0f/EAs0vOP9AMWUz0tgYOHLh4UNVtG/HHyO4=; b=MBbx6oODmfV0QeecRH3wYC0ZluxTmNU/OUfGIWKnuTXK7ENG21H8AkwBXW+kO69MTH F0o6AvB/fN2DtdxzkeAOeSmDy5qP759n3ljNRl+UKOXvbNuQyoZBd6oweuAUQ8Akffpr ZYAXSG/5QP1ULzHfW9y04YZJVNWtwV5yALZF4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209163; x=1770813963; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OvIzJVD0f/EAs0vOP9AMWUz0tgYOHLh4UNVtG/HHyO4=; b=SF+QwEB9uLpajiYRY0Su+Jj8OUWUt+MjMmsf5WChbeNYyhBC+SlEz3LnpvkJ1LTdsK uypGu7YsQJnLbHS7jLld3ZdB1xkzghNGfRuQ28g6s6L79HnnnBibqjscKViDbgXx0sSJ 0zuKbZfjnzMOOOlg9mN3lbF3GpEha2fiMuf5r9Z3dBH8/oXq74bCbSH2FqvR3TSRS3Ap X0eO7CScvuFdBRxGlACWVlzN+4edROYZNnvCumczk0qZYt9nXubrqPXGH5X3xayywe2E hLmhj+tr/MHj1W+6/8+sMEUOrhOykZbGdpZqLu4s+hWF5E7q8iVcAHltbR6Pm0kwDTZ5 JB6Q== X-Gm-Message-State: AOJu0YwyZFc8op3L7mxYr7t58BOYQEJ6thU0gZqNUWpeHc6WYiKf4wIH KrX07fpSthBfHGximyUwLBjmjtQFcGeO03D8v11ZLwfladykMyCHiTRdNmKypsADMNUtiw9M8jR wPje6 X-Gm-Gg: AZuq6aKg1jwqwsvJyqaaZzil/ScUpmfYClxo7NlQtZYEUZTA6SOwshlB5kAeqvbcw4O kZPBw+twlGIv9oQYF63EPVNbIorL5SGekB+HNs4vQsuR8fdifchI3ElZsajvrNukgvazkZpCQIs qplb2l6ZrUGhR0CMH1FwM1lMk5UgwAGBeX/fzLtCrFnetdxhqpiqNNrcndTE+xlFnMzVz4wzaIP FpN5qxoOUmtkO83d9dms26FZrjFk71qENeC34WGoexlGATwz8T7dBJcvXxw0fNA3BSPeCBX0uoZ mJoRstTc3CEXBHWiVlekfP3HI+Q5bWA0mpW0gBUx2Ke1hBSVmvLdIikurUABA05JlYpfQw8l9mb kJ6DqzvkYSi4ys9hMM0kDpTIBFd8tdE5E4zWBtLAlLqNOVKozQi9JOp6h4lSbFoST4byRDLPIvo V8ls7E0SUagt0AE4/9Fxk0UBhmmgzf77wlA5YriGHlY8jMiapH0ByQodtnlgZz6UK4c57Z2wCyn YRRjsPbiWp9gYU= X-Received: by 2002:a17:90b:558b:b0:340:29a3:800f with SMTP id 98e67ed59e1d1-3547785483fmr5999168a91.15.1770209163142; Wed, 04 Feb 2026 04:46:03 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:02 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 01/10] elf: Add relocation types used by nolibc Date: Wed, 4 Feb 2026 21:45:33 +0900 Message-ID: <20260204124542.523567-2-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" nolibc based programs are gaining the ability to relocate themselves so that they can support PIE without needing a linker or special crt from the toolchain. Add the required relocation types. Signed-off-by: Daniel Palmer --- include/uapi/linux/elf-r.h | 27 +++++++++++++++++++++++++++ include/uapi/linux/elf.h | 1 + 2 files changed, 28 insertions(+) create mode 100644 include/uapi/linux/elf-r.h diff --git a/include/uapi/linux/elf-r.h b/include/uapi/linux/elf-r.h new file mode 100644 index 000000000000..a1dce23104a7 --- /dev/null +++ b/include/uapi/linux/elf-r.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_ELF_R_H +#define _LINUX_ELF_R_H + +/* These constants define various ELF relocation types */ +#define R_386_RELATIVE 8 + +#define R_68K_RELATIVE 22 + +#define R_AARCH64_RELATIVE 1027 + +#define R_AMD64_RELATIVE 8 + +#define R_ARM_RELATIVE 23 + +#define R_LARCH_RELATIVE 3 + +#define R_PPC_RELATIVE 22 + +#define R_RISCV_RELATIVE 3 + +#define R_SH_RELATIVE 165 + +#define R_SPARC_NONE 0 +#define R_SPARC_RELATIVE 22 + +#endif /* _LINUX_ELF_R_H */ diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h index 819ded2d39de..3d18543d5460 100644 --- a/include/uapi/linux/elf.h +++ b/include/uapi/linux/elf.h @@ -4,6 +4,7 @@ =20 #include #include +#include =20 /* 32-bit ELF base types. */ typedef __u32 Elf32_Addr; --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C46CA40756F for ; Wed, 4 Feb 2026 12:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209165; cv=none; b=eOSVaB0wLke4DpNvCS+fIHI2NnZ2/aBRGvn7le9bKwO9lJvNXd8hFhAflx0E2kuJVLFqnPByY5EZaQVmHnZjU91+3xgL+E38eQ+PO0ifPSJgSMOmwndXdmoGVx305v2EOxqRilda7R8lqZUnHzyqqSJUT0m8mxxq1Adfx1c0VoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209165; c=relaxed/simple; bh=kw8nIebEJ1W/2MtV19pDi8GYjx1nCCzD9M9vXLLoZ8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=juLVfmlOq+3XTyrX83yddMkARxlR27U/HbjcfMNzJWZuPJxRFF4EZ0CkbZZLwpONlamzdCO7kCOwJh1PesTHEZFO6POz5RtKLH6A02rQtKkdqMe8nzLBDpqM/75SqFjYZjVAOmkfCbRke8sSYMPymnB/pG8QtpDIAeQt0nz/V6s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=e/G7gIPg; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="e/G7gIPg" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-34c27d14559so3529327a91.2 for ; Wed, 04 Feb 2026 04:46:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209165; x=1770813965; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3yVWdm59KuOGRwQxop0ZdtM+o+m7FWy3RTyTSA11l9g=; b=e/G7gIPgW0NUSrQmnoZv/Lrbhc6po/9uBhryAMSknrX/oI3RlkpRY8YzirVxZx92qx PqTi94ye6/FllCQc9AKOJVfotky/dpSxmzTcEQ8Sh7knDdzZe+D6dZerKkUaJ/rbyrP+ UkJxs1Aq2zBbJSe2C1MOyfduchqNA66HdPUx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209165; x=1770813965; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=3yVWdm59KuOGRwQxop0ZdtM+o+m7FWy3RTyTSA11l9g=; b=wzHFCZxAB+/g/n+CWECOamTfOjw4yVjOwNiAZj3Wmz2sDbO/bwRDZmHJG9VyBRYrcH JGyIPLnOG3tY/kREY3TBHUbNAT7vc5yEzTqexbCGgrtVf1aMDOSFSlEvEaIMxd1JmIMM mdA5+ey0mXtcwxWU+N8Dp/F8vxeNBAy0uOHOTmBgHXfZ065sH7ydf5Lv/7Chq0kRDuaF ql5rX5VH8c1tnYnck7qAyhDZnCO8etSWB1CyE7hOYqxvB6pEsSLSUrHkzGgkFQx/fdQo lIVwYv9S+TFQcAppxBvzOE7g61HovUEcu+2jP6TJz1YVOB3kb86gjdGwIYjifrfDl8bn mLUA== X-Gm-Message-State: AOJu0YyjxToaaUeMPZ/m31KCe0156Y9/F8tzCf3Ru0/AVX4NLqTv9PpE bDFsZ53004dj2TaPPkFzC0wl+C+v/k/Nb4711Iy+AISHT3J80HfB82oYxGTzOs3fClI= X-Gm-Gg: AZuq6aLsgHOU+gIk+Ohgd6+omBFT8AWkr18fuf5YdDlgUvbBTqLaphf/HCl2NB2L2Zw P0qO8NI6/Hyjr6RhHiNcaQrEjvhXe5iWHaK6jFhbqkWh0Kifbbk/39xr6UXDrG7Y6B9bpl8Qe7l y4FODmuORH8GqFdSSr3EZbnv6ovSfG+bBctlvCyPKamc9rOk27UMyj/LDRXjlLjCqNNc8SwtX43 XlhnBamNtYL75aL9NmgiuuUIINMQq4PPcObaVNtxRiO7IpR15oJFN4jois/dxV9S5XsNQYpRZpe txz+DB3YZuqutDbPMM+JsWu6sYy5TnnbowEvUBEcxdK6JSbLWOPQEuUqnTdY960tpfzG9Wf3sU8 s9z6EjrsC3ATAYZTjdtLzoEXiQhvElifpV/T2FgsF7aeLtztt6Pni55lbPPp+dDjd3XV0nZhcHT 4Ea0n0i6s5Lc1ol1pnR+Kn2urLoC3PNIxO/0WLRgIiBoqYp0e4hd06fLvErCCPLKslm5X+hcCRe 9BC X-Received: by 2002:a17:90b:2fc8:b0:340:2f48:b51a with SMTP id 98e67ed59e1d1-35487106f8cmr2922872a91.15.1770209165090; Wed, 04 Feb 2026 04:46:05 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:04 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 02/10] tools/nolibc: crt: Split _start_c() into stack-only and normal parts Date: Wed, 4 Feb 2026 21:45:34 +0900 Message-ID: <20260204124542.523567-3-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To prepare for nolibc programs being able to relocate themselves we need to split _start_c() into two parts: - One part that only uses the stack so there are no accesses via the GOT etc that isn't setup yet. Note that on m68k at least this also means forcing the stackprotector off because accessing the stack protector canary is done via the GOT. - Another part that is called after we have done relocation so it is safe to access global variables etc that might use the GOT etc. Signed-off-by: Daniel Palmer --- tools/include/nolibc/compiler.h | 6 ++++ tools/include/nolibc/crt.h | 57 ++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compile= r.h index 87090bbc53e0..3f403e54e4f4 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -47,4 +47,10 @@ # define __nolibc_fallthrough do { } while (0) #endif /* __nolibc_has_attribute(fallthrough) */ =20 +#if __nolibc_has_feature(undefined_behavior_sanitizer) +# define __no_sanitize __attribute__((no_sanitize("function"))) +#else +# define __no_sanitize +#endif + #endif /* _NOLIBC_COMPILER_H */ diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index d9262998dae9..fab042f1ff62 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -27,26 +27,45 @@ extern void (*const __init_array_end[])(int, char **, c= har**) __attribute__((wea extern void (*const __fini_array_start[])(void) __attribute__((weak)); extern void (*const __fini_array_end[])(void) __attribute__((weak)); =20 -void _start_c(long *sp); -__attribute__((weak,used)) -#if __nolibc_has_feature(undefined_behavior_sanitizer) - __attribute__((no_sanitize("function"))) -#endif -void _start_c(long *sp) +void _start_c_global_data(long argc, char **argv, char **envp, const unsig= ned long *auxv); +__attribute__((weak, used)) +void __no_sanitize __no_stack_protector _start_c_global_data(long argc, ch= ar **argv, char **envp, const unsigned long *auxv) { - long argc; - char **argv; - char **envp; - int exitcode; void (* const *ctor_func)(int, char **, char **); void (* const *dtor_func)(void); - const unsigned long *auxv; /* silence potential warning: conflicting types for 'main' */ int _nolibc_main(int, char **, char **) __asm__ ("main"); + int exitcode; =20 /* initialize stack protector */ __stack_chk_init(); =20 + environ =3D envp; + _auxv =3D auxv; + + for (ctor_func =3D __preinit_array_start; ctor_func < __preinit_array_end= ; ctor_func++) + (*ctor_func)(argc, argv, envp); + for (ctor_func =3D __init_array_start; ctor_func < __init_array_end; ctor= _func++) + (*ctor_func)(argc, argv, envp); + + /* go to application */ + exitcode =3D _nolibc_main(argc, argv, envp); + + for (dtor_func =3D __fini_array_end; dtor_func > __fini_array_start;) + (*--dtor_func)(); + + exit(exitcode); +} + +void _start_c(long *sp); +__attribute__((weak, used)) +void __no_sanitize __no_stack_protector _start_c(long *sp) +{ + long argc; + char **argv; + char **envp; + const unsigned long *auxv; + /* * sp : argc <-- argument count, required by main() * argv: argv[0] <-- argument vector, required by main() @@ -69,25 +88,13 @@ void _start_c(long *sp) argv =3D (void *)(sp + 1); =20 /* find environ */ - environ =3D envp =3D argv + argc + 1; + envp =3D argv + argc + 1; =20 /* find _auxv */ for (auxv =3D (void *)envp; *auxv++;) ; - _auxv =3D auxv; =20 - for (ctor_func =3D __preinit_array_start; ctor_func < __preinit_array_end= ; ctor_func++) - (*ctor_func)(argc, argv, envp); - for (ctor_func =3D __init_array_start; ctor_func < __init_array_end; ctor= _func++) - (*ctor_func)(argc, argv, envp); - - /* go to application */ - exitcode =3D _nolibc_main(argc, argv, envp); - - for (dtor_func =3D __fini_array_end; dtor_func > __fini_array_start;) - (*--dtor_func)(); - - exit(exitcode); + _start_c_global_data(argc, argv, envp, auxv); } =20 #endif /* NOLIBC_NO_RUNTIME */ --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF876407584 for ; Wed, 4 Feb 2026 12:46:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209168; cv=none; b=R7R8srPFe3c1VfajOJu70EuvmusWwFFfbtWttM/LcfZyeKcTowQBlTCnSAV6SBG8Uusf6fIMJDXZM8AydgxIDr2RtEvs9lhYedJzUJYJ/3slgHeneN4KeJEK06/Rp/nGUjGoFFjjzHX7ld7OELoUDTMJPtwNdILy80k1n2jPWaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209168; c=relaxed/simple; bh=rRE/64mBS3/v/jBX6itS/EmFfQCHwtBLqFj/bKMb6jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UwRn1SAZgE2t3z7qQyZ7HRhKnYJZmrKrqjDdfYx14LE8LG0a6uIpXQwI6UD7NP79FcTH0dtnjn3j5aGkMRm0Ihb2PYDjeYcgJngBIDeMAT/5ydjrxYt122oJU7+QsE5oI24WeBXT2oFkX0jOTngTH0y+k1OnpMSLZMOZ75RsTRw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=itE2DbNG; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="itE2DbNG" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-81f47610542so422575b3a.0 for ; Wed, 04 Feb 2026 04:46:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209167; x=1770813967; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zDQ9QOq4As3oGAjNtR1/Q1QpxaNmxwJeFefZqtE96/g=; b=itE2DbNG7H/AvPsKCbrH9ZdV+o3HQbtfc5fBQH+LUq2Nt9L2RF9v1u+kH5WtYQrkZZ 3rbJZvbfcS5GHeTn4i635AqHlxV9qO7n839krE87qc9ZHOl28F4M3Lp690zRsIXtiZ0+ hMA+TzB2sZlvtH7jRxsQCWEiR2ISgKLbRkf8A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209167; x=1770813967; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zDQ9QOq4As3oGAjNtR1/Q1QpxaNmxwJeFefZqtE96/g=; b=B/XEJvrqT6nzTqRbwBb1YUtL0yVU6WZx7WYIEpRzXgVP3X+xyrmE8tu630KEBCggv3 hyLimZZYjBw0e8r11KbQAaP5tp6WtDAO0pGkr+isyPO80ObDsWPH1XHrIhowm3T8s8vj HGjEg7sgvQPRqwpfDI8zq2RAurArpK7X9dc+cW6piwNiXZZyad7usYZ8fAOIoZ94p8Qh Oslkf96Uj/+hbFTb6H01/u3Kzogkemgam3FmhsNwJQhMmBCKWkjAkETmGmHRLvLuO6M7 8LpInXxWGr4CcWKlyXcy1oJUxyNFGIZCUsWbetXf7tPbL7iJn+uBDkGD0d60/j09k6Rb trOg== X-Gm-Message-State: AOJu0YyobG7lWl3z8UeYSZIh2tou6eLK5tZHNpTqOjLmzIfX5a06XaUT N4lyl/KzmrlmW+K2aG5nef29jkvjpJxo7h/RTjJy+YWXy0FEstw4qoFwygLhJ0vcPSE= X-Gm-Gg: AZuq6aJ9ZedaVZ8iIQLolm/bImzLSy1hmFO4KQTckJJfGvRzCO1yyjXoqvRX80+AmjR v64sDJ2a7KELks58zycY8OpgK2e0JVrUldoOwR47iFqutRdHQCoamyutsCLXUm+fl7wo6NtkeKj q+bxXTR3ONkEnrLftxXMdV/hMXL/CYgG79NHyG7GL3FcLPOErwNtTuZ+t/+PSAumfVSiwwpiUTK dp5aG+i1ufAX3rv6Pa/BvG8OQLQF2AVlmlcOqaejONR5b6Jdp3YVlW+FkyGbmXPF5QSAGIOmyWq lzztNRtLDY+OrVftbdzs0wc43lh2SEAe2ozrhUi+3s1stgvdzwD16ucuVIEcXqjjiFeIjxZJWbD YC+Q9Qa3hzXti+j8NPUILfb6mz6JGWNMz6XZkBiHTLtMO7Lm0+Z/vdmedMpphzQPSLw0HZF0q2A lqxqnCEr86WCSxtzUDAiOKuModGEAgTqu6P1UpYfrTTR1uA76qKUhzQqcDCfvUnWb7qRkqdP84O mHb X-Received: by 2002:a05:6a21:3994:b0:38e:5535:bb4e with SMTP id adf61e73a8af0-393724cbd73mr2561464637.76.1770209167041; Wed, 04 Feb 2026 04:46:07 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:06 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 03/10] tools/nolibc: Add basic ELF self-relocation support for static PIE Date: Wed, 4 Feb 2026 21:45:35 +0900 Message-ID: <20260204124542.523567-4-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently nolibc programs cannot be compiled with -static-pie. Which is basically no shared libraries, no interpreter, but contain relocation information in the ELF to allow the program to be fixed up to run at the address that the kernel loaded it to. There might be other use cases for static PIE but mine is for nommu. The ELF FDPIC loader can actually load normal ELFs is long as they can be relocated. This very basic implementation does the following: - Works out if we are PIE and need to be relocated. ELF type =3D=3D ET_DYN - Works out if we are static PIE, have no interpreter, and need to relocate ourselves. - Calculates the base address using the ELF program header address given to us by the kernel and the size of the ELF header that should be directly above. - Finds the ELF relocation data. - Calls an arch specific function to handle each of the relocations. Note that from testing a lot of archs don't produce static PIE binaries with the -static-pie option and you need to compile with -pie -Wl,--no-dynamic-linker to get a static PIE binary. Currently REL and RELA formats are supported. Signed-off-by: Daniel Palmer --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/crt.h | 7 ++ tools/include/nolibc/reloc.h | 224 ++++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 tools/include/nolibc/reloc.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 8118e22844f1..2b968a097854 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -38,6 +38,7 @@ all_files :=3D \ math.h \ nolibc.h \ poll.h \ + reloc.h \ sched.h \ signal.h \ stackprotector.h \ diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index fab042f1ff62..4b5be276b83b 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -10,6 +10,7 @@ #ifndef NOLIBC_NO_RUNTIME =20 #include "compiler.h" +#include "reloc.h" =20 char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); @@ -94,6 +95,12 @@ void __no_sanitize __no_stack_protector _start_c(long *s= p) for (auxv =3D (void *)envp; *auxv++;) ; =20 + /* + * Do relocation if required and supported, this must happen before any + * global variables are updated or used. + */ + _relocate(auxv); + _start_c_global_data(argc, argv, envp, auxv); } =20 diff --git a/tools/include/nolibc/reloc.h b/tools/include/nolibc/reloc.h new file mode 100644 index 000000000000..aead8cc680f5 --- /dev/null +++ b/tools/include/nolibc/reloc.h @@ -0,0 +1,224 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * Self relocation support for NOLIBC + * Copyright (C) 2026 Daniel Palmer + * + * This allows a PIE compiled nolibc binary relocate itself + * instead of relying on a dynamic linker. So called "static PIE". + * + * With some care binaries produced with this relocation code + * can run via the FDPIC ELF loader on nommu systems. + */ + +#ifndef _NOLIBC_RELOC_H +#define _NOLIBC_RELOC_H + +/* + * If NOLIBC_WANT_RELOC is not defined decide based on the + * compiler defining __pie__ or not. + */ +#ifndef NOLIBC_WANT_RELOC +#ifdef __pie__ +#define NOLIBC_WANT_RELOC +#endif +#endif + +#ifdef NOLIBC_WANT_RELOC +#ifndef _NOLIBC_ARCH_HAS_RELOC +#error "Relocation requested but arch does not support it" +#endif + +#include +#include "elf.h" + +#ifdef _NOLIBC_ARCH_ELF32 +#define _nolibc_elf_ehdr Elf32_Ehdr +#define _nolibc_elf_phdr Elf32_Phdr +/* 32bit ARM, x86 uses REL instead of RELA */ +#ifdef _NOLIBC_ARCH_ELF_REL +#define _nolibc_elf_rel Elf32_Rel +#else +#define _nolibc_elf_rela Elf32_Rela +#endif +#define _nolibc_elf_dyn Elf32_Dyn +#define _nolibc_elf_addr Elf32_Addr +#define _nolibc_elf_r_type(_x) ELF32_R_TYPE(_x) +#else +#define _nolibc_elf_ehdr Elf64_Ehdr +#define _nolibc_elf_phdr Elf64_Phdr +#define _nolibc_elf_dyn Elf64_Dyn +#define _nolibc_elf_rela Elf64_Rela +#define _nolibc_elf_addr Elf64_Addr +#define _nolibc_elf_r_type(_x) ELF64_R_TYPE(_x) +#endif + +#ifdef _NOLIBC_ARCH_ELF_REL +#define _nolibc_elf_dt_rel_rela DT_REL +#define _nolibc_elf_dt_rel_rela_count DT_RELCOUNT +#else +#define _nolibc_elf_dt_rel_rela DT_RELA +#define _nolibc_elf_dt_rel_rela_count DT_RELACOUNT +#endif + +#ifdef _NOLIBC_ARCH_ELF_REL +/* + * Your arch needs to provide this to actually handle doing each of the + * relocations if it uses the REL format. + */ +static int __relocate_rel(unsigned long base, _nolibc_elf_rel *entry); + +/* Generic implementation of R_x_RELATIVE for REL */ +static __inline__ void __relocate_rel_relative(unsigned long base, _nolibc= _elf_rel *entry) +{ + _nolibc_elf_addr *addr; + int addend; + + addr =3D (_nolibc_elf_addr *)(base + entry->r_offset); + addend =3D *addr; + *addr =3D base + addend; +} + +static __inline__ int __relocate(unsigned long base, + unsigned long rel_off, + unsigned long rel_count) +{ + _nolibc_elf_rel *rel =3D (_nolibc_elf_rel *)(base + rel_off); + unsigned long i; + + for (i =3D 0; i < rel_count; i++) { + if (__relocate_rel(base, &rel[i])) + return -1; + } + + return 0; +} +#else +/* + * Your arch needs to provide this to actually handle doing each of the + * relocations if it uses the RELA format. + */ +static int __relocate_rela(unsigned long base, _nolibc_elf_rela *entry); + +/* Generic implementation of R_x_RELATIVE for RELA */ +static __inline__ void __relocate_rela_relative(unsigned long base, _nolib= c_elf_rela *entry) +{ + _nolibc_elf_addr *addr; + + addr =3D (_nolibc_elf_addr *) (base + entry->r_offset); + *addr =3D (_nolibc_elf_addr) (base + entry->r_addend); +} + +static __inline__ int __relocate(unsigned long base, + unsigned long rela_off, + unsigned long rela_count) +{ + _nolibc_elf_rela *rela =3D (_nolibc_elf_rela *)(base + rela_off); + unsigned long i; + + for (i =3D 0; i < rela_count; i++) { + if (__relocate_rela(base, &rela[i])) + return -1; + } + + return 0; +} +#endif + +static __inline__ void _relocate(const unsigned long *auxv) +{ + _nolibc_elf_phdr *phdr_dyn =3D NULL; + unsigned long rel_rela_count =3D 0; + unsigned long rel_rela_off =3D 0; + unsigned long phdr_addr =3D 0; + unsigned long phdr_num =3D 0; + _nolibc_elf_ehdr *ehdr; + _nolibc_elf_phdr *phdr; + _nolibc_elf_dyn *dyn; + unsigned long base; + unsigned long i; + int remaining; + + for (remaining =3D 2; remaining; ) { + if (!auxv[0] && !auxv[1]) + break; + + switch (auxv[0]) { + case AT_NOTELF: + return; + + case AT_PHDR: + phdr_addr =3D auxv[1]; + remaining--; + break; + + case AT_PHNUM: + phdr_num =3D auxv[1]; + remaining--; + break; + } + + auxv +=3D 2; + } + + if (remaining) + goto failed; + + /* + * The ELF header and the start of our image in memory + * should be the size of the ELF header above the program + * headers. + */ + base =3D phdr_addr - sizeof(_nolibc_elf_ehdr); + + /* Check that we are PIE */ + ehdr =3D (_nolibc_elf_ehdr *) base; + if (ehdr->e_type !=3D ET_DYN) + return; + + phdr =3D (_nolibc_elf_phdr *) phdr_addr; + for (i =3D 0; i < phdr_num; i++, phdr++) { + switch (phdr->p_type) { + case PT_INTERP: + /* Interp was set, we were relocated already?, return */ + return; + case PT_DYNAMIC: + phdr_dyn =3D phdr; + break; + } + } + + if (!phdr_dyn) + goto failed; + + dyn =3D (_nolibc_elf_dyn *)(base + phdr_dyn->p_vaddr); + for (remaining =3D 2; dyn->d_tag !=3D DT_NULL; dyn++) { + switch (dyn->d_tag) { + case _nolibc_elf_dt_rel_rela: + rel_rela_off =3D dyn->d_un.d_ptr; + remaining--; + break; + case _nolibc_elf_dt_rel_rela_count: + rel_rela_count =3D dyn->d_un.d_val; + remaining--; + break; + } + } + + if (remaining) + goto failed; + + if (__relocate(base, rel_rela_off, rel_rela_count)) + goto failed; + + return; + +failed: + __builtin_trap(); +} +#else +static void _relocate(const unsigned long *auxv __attribute__((unused))) +{ +} +#endif /* NOLIBC_WANT_RELOC */ + +#endif /* _NOLIBC_RELOC_H */ --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7568540759B for ; Wed, 4 Feb 2026 12:46:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209169; cv=none; b=nxn9t/WrDlmeB4omUh8/ppgbDmKcEK1acnXvpQDn2Bp45fA0d1tpqlx38F5fXXj0RBRE1zXlPx25O4lNjuAcixK+N6GowZlpDrGuWkAA1ek84aR4k6zXbO/L46EsieVmIsNp30SanM/tckAP75nzaXPFKq05CCwoKPss+yCAjtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209169; c=relaxed/simple; bh=opLHo4fm18mdrEX23VuwnVvQDJ+lI0n6ntdc8dyjZZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s4tmocy8EOdDUDZIp9J96Ytq3V3Y4hsUC7hP2B4JEUbCsYGuwHNfSEeNrvfA3RSn3BK6YRsSR16ldsxEl4a5qx7ZBeRNrErxXHennkkO0Z/DLodqlyiS9zlzWRsMLtfYcttniTugEZk5hFN+mRGDt9fp16JsBj4hz3DHpruBd9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=PozJSE8N; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="PozJSE8N" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-81ecbdfdcebso3723463b3a.1 for ; Wed, 04 Feb 2026 04:46:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209169; x=1770813969; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pNvWfRWqxUd/IFngJuH9rrMFeO8aVqebLe9MltDnISQ=; b=PozJSE8NZWyLNTv0jOjhBxtfY4Ydj42go49Ki/Dmwgs6YpZg4OvlY7YtXfL08Adn+P M5WVEnDvjOjJ+GXpc+kLJlmtPWQQOtgoWe7pb7Ot5Faf7L4tFDwZwGAqc/mLECW5R0Fc 8BlqR4F5LdeG2F7SDPzK4VA5pB7d6xZ2SX2dk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209169; x=1770813969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=pNvWfRWqxUd/IFngJuH9rrMFeO8aVqebLe9MltDnISQ=; b=I/RfYdUGyqX1+sO1foEPK4/8mEviPnLxrC8RixIgCBOUUXlDfBKgFH22bnHQOCywCY h8zgso72yc8zVOLwiJMlTU8QH0tR1dZo42KvsSwwkOVoaNbtq1IRmT+SEPXuuwToYqvp RBkfpxr1Xroupalf2H5F1S3CzTVNxr5Hhbn8ts+EZvbg81PUj3GeFEkz/MJExl4aBVyR tTdGHlYAy3IUOybIZrAVd31b55bxeqd8I4+oUPzJrr4OdnWtG5RdpqsNxw3PBqmZz0H6 DxNry4503eaBdeAUMMyU41VhmHvP13TVDP7zU890/2Wc6XQy/YW74xCmMxCLKkwpDLUW I7SA== X-Gm-Message-State: AOJu0Yz4gtRvjiZ7aRqARNimgvF3GcWZ0A4edFNwXl5NWCt0Rq0ofB5J LxzvPXfmGiUP03xgsfZg4B8xzXmkXYclcrOFhhjRlB44IlpLkVtpqUdSjz8279+/Cbc= X-Gm-Gg: AZuq6aLGPN+lxjmexzpe+CQm0GUb1XobYU96tJHxMvG0ENW9AkcqtVo/aSyiiojkrgP bJ14pBzB4SsQUnEIqAm1Q7ds0J7GUW2pUkO7huQhxeGRGSgq+CuGg28dWqJvZ7MS+SdhRcwr2RT SzzOqi2x/hhX8Jo9oQdqmrPsxrwvHf8OEPDfunAeLT9hBS8unZjf0qMsgd1IKLiZxwFilYhxvq/ 85F0tMQTCVWkVNJxGBPea0X6SEZYUWff6dzw1oWoL8+ZsdN3FYNtRXO3a3W84v/sR1zsOhfosgd PhnZQZO7j1dp7q505ej85rXHDIJfv096jrRCOqsLSTq2wB96mnyzQiPhcazKSFp86j0SVgEOWpo Pp7KnlaMWrL8JNryWAaZzmHtDbGm+Zd1WgyOKf0kYMDvk1bnNEIKoW7xgc16pfxWpnLuetCeaB7 /JWgjTztvIIk9BBHCjDNc1W1UCNemR0cHz0HUIK/vSbvlJwdpbGPNev2wDrJnJ7bcsh+20Cp++s w8R X-Received: by 2002:a05:6a21:6b85:b0:364:be7:6ffc with SMTP id adf61e73a8af0-393720db58dmr2966940637.18.1770209168747; Wed, 04 Feb 2026 04:46:08 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:08 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 04/10] tools/nolibc: m68k: Add relocation support Date: Wed, 4 Feb 2026 21:45:36 +0900 Message-ID: <20260204124542.523567-5-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for handling relocations on m68k. This also changes the branch to _start_c to be relative. This might break FLAT binaries so needs to be checked and probably wrapped in some #ifdef .. magic. Signed-off-by: Daniel Palmer --- tools/include/nolibc/arch-m68k.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-m68k.h b/tools/include/nolibc/arch-m= 68k.h index 2a4fbada5e79..e82ff48d3fb8 100644 --- a/tools/include/nolibc/arch-m68k.h +++ b/tools/include/nolibc/arch-m68k.h @@ -10,8 +10,16 @@ #ifndef _NOLIBC_ARCH_M68K_H #define _NOLIBC_ARCH_M68K_H =20 +#include "elf.h" + +#ifdef R_68K_RELATIVE +#define _NOLIBC_ARCH_HAS_RELOC +#define _NOLIBC_ARCH_ELF32 +#endif + #include "compiler.h" #include "crt.h" +#include "reloc.h" =20 #define _NOLIBC_SYSCALL_CLOBBERLIST "memory" =20 @@ -129,12 +137,29 @@ }) =20 #ifndef NOLIBC_NO_RUNTIME + +#ifdef NOLIBC_WANT_RELOC +static __inline__ int __relocate_rela(unsigned long base, _nolibc_elf_rela= *entry) +{ + switch (_nolibc_elf_r_type(entry->r_info)) { + case R_68K_RELATIVE: + __relocate_rela_relative(base, entry); + break; + default: + return -1; + } + + return 0; +} +#endif /* NOLIBC_WANT_RELOC */ + void _start(void); void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { __asm__ volatile ( "movel %sp, %sp@-\n" - "jsr _start_c\n" + "lea _start_c(%pc), %a0\n" + "jsr (%a0)\n" ); __nolibc_entrypoint_epilogue(); } --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5629A40B6C7 for ; Wed, 4 Feb 2026 12:46:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209171; cv=none; b=ffsZ7oHGdZ3tCDwa1XpqA9C8K++RvMk8JELhM15GnGjU8NEheKkBGJD+/YqGOnw6zEOCj0pQJwgSiBcFO4JkO2/2RLgsWmcL6dGiHM1j8BhDVW3xfNo4mC6q/WVNms8zjyxI/n+8IXljEGbQ5gMAGrU/GTt0G9wMmkjK9d5uevo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209171; c=relaxed/simple; bh=2xNmeZGbjUpjTbH4NVZ4jiU+PS5WHhzuwO+Qma4U+l0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XDO/kelRlFQa8d4cXgLmjPC9JgCIDgYNYbB3iorQPSWptHpBE3Mc4pjckIt173z7ykooyUBTN1YKmlxj1iKGdqdfUig2nU4wM4jbQUpY8YdgKRAaA1V56e4moN75lR3wEWpiv/7jfQgUqVI2SE7pJIsaTAA2giNRgg2TjucC7IY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=SP7fRlnB; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="SP7fRlnB" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-c636487ccaeso318126a12.1 for ; Wed, 04 Feb 2026 04:46:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209171; x=1770813971; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r5J09chRTQQEbG4KqdBcKgXGG1Mm7lCzrPTPbQLlfoo=; b=SP7fRlnBNBMKoBr6nKjXMkcMvroQDBLs/i69sAUIqC8ykuYyim1nqGfuVVzIjk+wnQ OfiFdvQ1wpzUa4p1jm9mXZAWTatfwzHDeYOIhxBw3SVhBWYPRuvc+lCLcsYAcDOiURwT FbVFb0wxd2tH5I6BHMevlhrYu31VIAQy3DK/A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209171; x=1770813971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=r5J09chRTQQEbG4KqdBcKgXGG1Mm7lCzrPTPbQLlfoo=; b=J7VdEmr3/3MVv5qAzL/3ngrcp9I+MwXsNKWtcpndIq8ISvvypzoFeTcXvDABDnBwQt x9cNFzOczkZUmul7NXrT0jeFxzL1rQGHpD6xrgQ2pj46sFl6PfF1CmVHuXWbtvkjRcrD f4VDAm/LuYyHPSc8m80zmBWp3gn6okGnRs0zUB+z4SlNDS9P46ojaQxWM6VD1uyNExr2 mSfrdGYRkqWX+Szoy6STdqiwqOwHeIoF6CMROcrrK36gwnILBPaegNM+B1YlkTC7Q3ix 4zErQ5TFsUnQskgTrbZzVKdXMrvZVg2EWNQrDItwa9Sl2gYaxXnLUO8EbXZMDnPHNoZR NBLg== X-Gm-Message-State: AOJu0YyKxSI5S/uQ1ifWoe/Z/lO3/hkz2rS89zQpwbNHlx8smykOxSIs AzUd4tQ2j1PCDG3gSjeHGDiHPY0xshiXDAcKsV6iAUKz0rj017kpzEYs7ZegVP/TnD6806YB8Q6 i4/Jt X-Gm-Gg: AZuq6aIv1JQ7GyuSru3+15lNTozaenwmmJBJJoyVCmd1R7bDR/JLYOTN2XhrIc0HK+N t7q8fkO14PEFG/QCIXECL6AnlXc7WJk3SyzqLrNkmx0CnlX1yTMYXU4HmhfaCpYCmVun65g2qA+ Yoo4S4AWBqHV6LWdUBedrxC23szdP27UXXtGG+e849zE/Z44P3CFiV2d5Ksqf8GFFqbd831CBCa 9ETV8ZEwIUsem7CNbDeysHQSkn08FuCQCRaXRd+RyxzTltHre8CN7DWhIJ1HwIrXTnutIlDcoTS 8Hy0VtZ8UnE3e+dLkrJDw7Q3Xzrrk0eQKJyDSacJOeLTgREW1XgZ/EtRg0wS4i86SLWjSmQnVBP Z1crO66J7Dn/qNvQA4FzgzRBo+ca32GiD0BRxzTZPsYoEBQYs34A2FFdJijAqe8zIoVar1cC9iY f79bW6vSUj1sFai5hWoJ06usvQRkWdMDkdn1flNrj3km7qixCooYhsiH8SRvSU9HN4OF2U9PCyw yPO3rud3HSFrOo= X-Received: by 2002:a17:90b:4c51:b0:32d:f352:f764 with SMTP id 98e67ed59e1d1-354870b1e6dmr2447171a91.2.1770209170712; Wed, 04 Feb 2026 04:46:10 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:10 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 05/10] tools/nolibc: x86: Add relocation support Date: Wed, 4 Feb 2026 21:45:37 +0900 Message-ID: <20260204124542.523567-6-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add relocation support for x86, both 32bit and 64bit (including x32). Signed-off-by: Daniel Palmer --- tools/include/nolibc/arch-x86.h | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tools/include/nolibc/arch-x86.h b/tools/include/nolibc/arch-x8= 6.h index f6c43ac5377b..263734c56537 100644 --- a/tools/include/nolibc/arch-x86.h +++ b/tools/include/nolibc/arch-x86.h @@ -7,8 +7,29 @@ #ifndef _NOLIBC_ARCH_X86_H #define _NOLIBC_ARCH_X86_H =20 +#include "elf.h" + +/* x86_64 and x32 */ +#if defined(__x86_64__) +#if defined(R_AMD64_RELATIVE) +#define _NOLIBC_ARCH_HAS_RELOC +#endif +/* x32 uses ELF32 */ +#if defined(__ILP32__) +#define _NOLIBC_ARCH_ELF32 +#endif +/* i386 */ +#else +#if defined(R_386_RELATIVE) +#define _NOLIBC_ARCH_HAS_RELOC +#define _NOLIBC_ARCH_ELF32 +#define _NOLIBC_ARCH_ELF_REL +#endif +#endif + #include "compiler.h" #include "crt.h" +#include "reloc.h" =20 #if !defined(__x86_64__) =20 @@ -158,6 +179,22 @@ }) =20 #ifndef NOLIBC_NO_RUNTIME + +#ifdef NOLIBC_WANT_RELOC +static __inline__ int __relocate_rel(unsigned long base, _nolibc_elf_rel *= entry) +{ + switch (_nolibc_elf_r_type(entry->r_info)) { + case R_386_RELATIVE: + __relocate_rel_relative(base, entry); + break; + default: + return -1; + } + + return 0; +} +#endif /* NOLIBC_WANT_RELOC */ + /* startup code */ /* * i386 System V ABI mandates: @@ -326,6 +363,22 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoi= nt __no_stack_protector _s }) =20 #ifndef NOLIBC_NO_RUNTIME + +#ifdef NOLIBC_WANT_RELOC +static __inline__ int __relocate_rela(unsigned long base, _nolibc_elf_rela= *entry) +{ + switch (_nolibc_elf_r_type(entry->r_info)) { + case R_AMD64_RELATIVE: + __relocate_rela_relative(base, entry); + break; + default: + return -1; + } + + return 0; +} +#endif /* NOLIBC_WANT_RELOC */ + /* startup code */ /* * x86-64 System V ABI mandates: --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1957407588 for ; Wed, 4 Feb 2026 12:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209173; cv=none; b=fRxgsKBEcM2BomF/pBQp5e4KU8vptdJjQzrGD2oMu9+cKvgN1zf/l2B6bAzoRL5IIBodgBR6eTi1MkEzANLdmCf1itnzxzbcVaqQuxkF0IRzaKMee6dNl6qVfsYalOSTngslieUTD2beDQi/Whi6lwjetqKSCNA9KGRQnxAdVMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209173; c=relaxed/simple; bh=0P9zx5/hmE4v9NdLwzS4Tx8PsMhqIKGbeFJtBRx32t8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ExqJTns44MpH3o2xAxsc3FtsZIGn0Li9Nb4M7YHvQ9+/+FP2xA1nLynCQqK29SLBvVQUqE5W0R0B6W01UTvGru8fb935boZMPppfx/GVnKUnWU54/jSKF94c7f2kb/J4oJ/0/8yXfW6s2d13eCoOhC/Kto7ODqiEOAQ7kisT86E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=T1C1JNKQ; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="T1C1JNKQ" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-bc17d39ccd2so2728870a12.3 for ; Wed, 04 Feb 2026 04:46:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209172; x=1770813972; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+KGA9l8QyOppOd6iM407RUKEAnKjKrcTX0YNYhQz1lE=; b=T1C1JNKQuNg9qKy8jd9yXocECDhLT86yhEnp5RY4EE8XZrXd/20B+nq0Lf6KwJ62KU pf25Zv31M+mN0d649TrtJwshTUwUY6lBE0fQ4N/epg+PEE6a7NdX/XjkHSE5kj4JswBD aUaR8S4ZbiMYgtrkdWBPtDiud1msqPVYfacZ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209172; x=1770813972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+KGA9l8QyOppOd6iM407RUKEAnKjKrcTX0YNYhQz1lE=; b=E/K1hvxukIoUh1PG/ecOoau6XI47AVBPQtIfgyChcEROR44gi4G1eSdYGYQ7A+tyIC OoUXgdRDtqM121MPSoJn+ritoFXdh/eONbWnDa2HuCgv7UPjU7dTePytNbXM53fhhqNC VU4Ym6EUKamAtvgKRhLi6lFVIiz3YD0xaz0Cftds9a5fWpsSkUxRoFN9SgA2k0HKsSAs 96AlqPS0z6JMPTSg8U60BSZ5XBMB6Oxi5uvXGvURPurZO12B7DdlZ5Itzy5VD3a6gVSI 34lQhwL9XQr79Wepp3e7txZcePk54svQds3pevvAdUajDNxcjaTneTKk3wsBUxfCg6p0 VsdQ== X-Gm-Message-State: AOJu0YyLHs4TMT1FaesEyBBrp4dFQHfhjoafHy2Zmsh5pP6QEcUEf8+a b+9khENbRKZt4NjMeA4Xt3gNOOx4AansRNbqw2GK/T6k3uTIdbAR31A0UWBj5CwGd88= X-Gm-Gg: AZuq6aLIL3YitcJjKt3zrBHdU6qfXiH9o6Rci0+bjDKvsVVPelyYaGR2JtF/ATn8eOn KvfblL9F2jlzAcYbf8GC9hJ9UYn0s7AmlHqs60tCK1ncPRP3efR80JHDWKx4EhJx3C7jNsgd3/s 59P77/VFi2mhtBbpgqtXjN6tWKzetSglBatnKniPVD284n68uPfEIUYgVs7GJzApAFuNZ82ER0+ 6xBLwVs9UFnjYbmCELoErZB5R7w4FuTc0bNxLHH7q50sYuo//vRQfeGwr4nTRIxKzqEvwG2+Gea j4Eq5brJYCjCy9fZzw8pV3E3tW1buGWLChwKwIwm2/O4ZhhM5acSh136L13rVP6Qs+JEzOjBHio bJZU2Sa6W6MsA0+0S5I3gtUlclghiXfSUc2qQA69dg9z/GIOHbdcQk18YrCNcjid0FY31naBnQa xyESp3gNLVQ1eOvvKFzcb0wu426wm+d5K9yt1563QfFj1UwP60PuZ5aIi+/D22lxousc/pd7wOL c4mgfLmNa7Pz9s= X-Received: by 2002:a17:90b:4b8a:b0:341:2150:4856 with SMTP id 98e67ed59e1d1-354871a9754mr2713377a91.17.1770209172323; Wed, 04 Feb 2026 04:46:12 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:12 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 06/10] tools/nolibc: riscv: Add relocation support Date: Wed, 4 Feb 2026 21:45:38 +0900 Message-ID: <20260204124542.523567-7-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add relocation support for 32 and 64bit riscv. Signed-off-by: Daniel Palmer --- tools/include/nolibc/arch-riscv.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index 1c00cacf57e1..0a6a4300c318 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -7,8 +7,18 @@ #ifndef _NOLIBC_ARCH_RISCV_H #define _NOLIBC_ARCH_RISCV_H =20 +#include "elf.h" + +#ifdef R_RISCV_RELATIVE +#define _NOLIBC_ARCH_HAS_RELOC +#if __riscv_xlen =3D=3D 32 +#define _NOLIBC_ARCH_ELF32 +#endif +#endif + #include "compiler.h" #include "crt.h" +#include "reloc.h" =20 /* Syscalls for RISCV : * - stack is 16-byte aligned @@ -140,6 +150,22 @@ }) =20 #ifndef NOLIBC_NO_RUNTIME + +#ifdef NOLIBC_WANT_RELOC +static __inline__ int __relocate_rela(unsigned long base, _nolibc_elf_rela= *entry) +{ + switch (_nolibc_elf_r_type(entry->r_info)) { + case R_RISCV_RELATIVE: + __relocate_rela_relative(base, entry); + break; + default: + return -1; + } + + return 0; +} +#endif /* NOLIBC_WANT_RELOC */ + /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0274407576 for ; Wed, 4 Feb 2026 12:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209174; cv=none; b=VQ5UTGGt5c1R2gQBnzemGCBw3vrzeu1EMOq8Sa1lKFGgx3H9cUEnda0tfaX0dlrZUs5Mk/DjaXcWoh2k8RqZLEN3sXBV1bdcfV4ypRgEEpc7lEnwQK5wgzF9h8k5PRa9D2qXVhOHmsh734fIJtB7F8ChXix2MePO7SBSKCNQouo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209174; c=relaxed/simple; bh=zXrB7Fm9DUIfmDUnpAnPYKYUN1dPMwyrZ4EO12pKQKc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZqiCYGMolcGB9+99a0Ei3JWZ9tNHoBVw6aHRpdP9QWmHwaurkTBGQScZj1gIq/WCotsZb0HiJWjTlfYDpXU3bJkYCdLtFmsWwORHemDiCzMY0W6GX6/Ao2Hl//SzXkilbI8HFrw996XX8Jn6gXsBoQ5myiIGYQ5YhPYej4GBM00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=a1QW6XOc; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="a1QW6XOc" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-34f634dbfd6so5305148a91.2 for ; Wed, 04 Feb 2026 04:46:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209174; x=1770813974; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qNfavEXYQM1h3M/NKp/a6qGlpSj+nP7sqxqphE2tp88=; b=a1QW6XOcDkjqokVzDRqEH1GzJyPq7SK8g71oe/bCgk1PMMxLRrc8ZrMLS9HfwmLQ7O Pe2hdPtyVAfWyo7XZhKX7VxEn7MsTHXXNF1KInQG1Zinj9C41poCSzHeSxAzT81GCtSW S/e6O9vBz68YGa+REZS3rtp/O6VusX3yvzvyQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209174; x=1770813974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=qNfavEXYQM1h3M/NKp/a6qGlpSj+nP7sqxqphE2tp88=; b=TgA4J6WpnG5Ctwjb2FJitCNLgLyFn0m54vES6eZrU8qYSFMwuFC9tK6G47SRkZ39Bk F2cyQfP86LJqRjYSsbpfu5/JZBsB5zkQ+nZy6nmGUgtLuG+1vCKuh53uMarKYXNn9xOq ldUcicQH+FcbcIMWUo1dcrWhoMoPL1ajz8/9CFJWk7g92Ai3WNLKv31dhAkLrY30ha7r YFPsy4hoveGVog16suklLQDeH+c1jZwR+E56k9jb4Ei7amDWiqEqrIXvb/5vBS3SZcYJ X8T1n8No0oobLotHYWXTEGXZ1i/QA7GHCAtf3gLgIJkhFan1mIUy3opgdwoVzYOu15eq DkeQ== X-Gm-Message-State: AOJu0Yz7orCPvMYwWOrWei/ydrvSz97y9TRUK/QVeXpkp+2JjvhhwlNh Fqn2+40m1O305Mgx9g7xrBbnR2J+QMfY7+fLODN5H4tGmUQLFVpY9+hluau3cfO5H+k= X-Gm-Gg: AZuq6aIw5Sl6V50sbRFqKGVqw98hL+BFwX/MZ+jilBIpMX0tcNwZ0qrjphU37Z2tW6M KDaXXzStq+wCQiVrGcpZwFXr//G/6khYq4nEjt3bfMIFChimGRQMAxHEGahu1VhiKMr5E03VY93 OoK/7h3K5zKcp215qPDkrue/ZzrsELFPMJMfWYPdUGSrfko3rGrEI6ZtPpHoDvXCiTSw5sgF01D 9AeY0XyXYDFJf/MhhCLiDqwcb1ESGRIxG6hmp9AvkZwGRhOugK8Vg+eNxw1GwC8h8wPbmwEWfJD itjkFRxoWOBJaKQjKRoid7b7gSxLYiLJFiP6AVhvkO5PNOhI8l7YgJ7YP6TuJD7Wfuw1wC3cKb0 /nIJqQx53RXJs1V9cKfVGQJZB/pk3cOnlOfhScdpKnkYIDowpcP+Ci9asPEogcScbP/DhNro2pm T22T8N1WPxLyjTPU4FTBVNe4p+62pc2r4/TE+rU8/29jyEoTQ2Adr19vORY/uvWI01NwEhoFDWB ZQg X-Received: by 2002:a17:90b:5384:b0:347:5ddd:b2d1 with SMTP id 98e67ed59e1d1-354871bd57emr2373167a91.27.1770209174204; Wed, 04 Feb 2026 04:46:14 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:13 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 07/10] tools/nolibc: arm: Add relocation support Date: Wed, 4 Feb 2026 21:45:39 +0900 Message-ID: <20260204124542.523567-8-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add relocation support for arm. Signed-off-by: Daniel Palmer --- tools/include/nolibc/arch-arm.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 251c42579028..0a0d864c857a 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -7,8 +7,17 @@ #ifndef _NOLIBC_ARCH_ARM_H #define _NOLIBC_ARCH_ARM_H =20 +#include "elf.h" + +#ifdef R_ARM_RELATIVE +#define _NOLIBC_ARCH_HAS_RELOC +#define _NOLIBC_ARCH_ELF32 +#define _NOLIBC_ARCH_ELF_REL +#endif + #include "compiler.h" #include "crt.h" +#include "reloc.h" =20 /* Syscalls for ARM in ARM or Thumb modes : * - registers are 32-bit @@ -185,6 +194,22 @@ }) =20 #ifndef NOLIBC_NO_RUNTIME + +#ifdef NOLIBC_WANT_RELOC +static __inline__ int __relocate_rel(unsigned long base, _nolibc_elf_rel *= entry) +{ + switch (_nolibc_elf_r_type(entry->r_info)) { + case R_ARM_RELATIVE: + __relocate_rel_relative(base, entry); + break; + default: + return -1; + } + + return 0; +} +#endif /* NOLIBC_WANT_RELOC */ + /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8B1D407582 for ; Wed, 4 Feb 2026 12:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209176; cv=none; b=GdOYSCw2TUskFTAuXkKfbBloe4e+y5ozEMPQz0n9JvWuB/ClPv+7V6wPTDNHlj/W2QzEEZJ/YY4UMPqK+/6PURbTemtzg5u/mMSsd5vTa4kjyqSqb31HfxzeJukZvg7Av9tuZ90vAzR22f+9Sn/UnYYWpo/+yUKkPCQ/hQiHHgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209176; c=relaxed/simple; bh=5/1WaKLsUxx/IULT+4VnnJ3n88GA7G+nrdyZeft8Jd8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dXuzu7MpmvgpJLNFv1RXCJMMWifmIkK0eS8YT1D13j8gpcs8iaW0TZ9pHUjr2efj1vI6dGVsUl2GeulH0twbIHXsA485SmPUX9XBh/WIkS1uw+Ps9P6mn1z0vjoigC7GhHBe3B/iY3kLfFBOoxPnpF45IjvRY/tP3m8Fh4H97xQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=bgN+Aw5i; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="bgN+Aw5i" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-8230c839409so5547748b3a.3 for ; Wed, 04 Feb 2026 04:46:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209176; x=1770813976; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HSEthSt+H3WjY/D+Uptcu8IcwwAQm4ZNPX9pbmBIkYg=; b=bgN+Aw5idFw+M1BtykaIDIKqNUhz+0JrkJQuE0SAOZgcCUGQTUtOomh0/H6dOTl2bh qcMs+UmUtuB4FbQpGMjIlfHvK/qMo1+9yeOPvjpkCwtq/b/Ccur/jy4iEwbIGY6Y62aB uIY4/EhuPp000VssrSnpthw+MUr44BcIRlS1g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209176; x=1770813976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HSEthSt+H3WjY/D+Uptcu8IcwwAQm4ZNPX9pbmBIkYg=; b=ntpOfaKCjGRW+t/4d/OWm7/9v1ePE5XoLsNi9bVUY2IH7JYeOWjs5/Bm03tIb/9kN6 ZmpichQhVbP2cdlQy9lT7b3cNP941BjppAAcv1PzF+FH7gRnpZXvuKtri0Fr80SaFeCv mJyn6jlK9d0vlrv1hSNSKsPwdTO2fbsUd/sNSaJPluutXSPteWbC5bE84pzLTU9uVjpg DJWFb9QUAzg3K770FhgRhifIB65sB9kYVTwdn7BQIKInDuI7IUgz419OLQdTAJlaEqGr CjwFN6Pm0UuBF0IrENS/Ahljbnji9qVc4pY95cqIPp4xtCgSPpPRRvQbWPBMg5H6gR1x 35ig== X-Gm-Message-State: AOJu0Yzon+ectmNKMqXuAV5Yut8FkkYtLVqzTcR/kQjC/s9yoXXzMdq9 AioVcRJwJyRyrqsZlN3EL6bShrvPHW2RHAYz3LaPe+72NHd7+j3eF5d4n5fLyoQAGaI= X-Gm-Gg: AZuq6aJCEcECTJNRb0waYdUq71SVwe9G0ZFrbXoF3x3/LLAjUZWfxp13f0EpHLhMtJY oHAWMoFy/FQ+kRtGCqwG5fNvw8CSFjVepbQPRooLA28LyMRT/LOuBxhVnNvu2mscPB4Q3bVWrzu RAV205qZWC/2pLXys+oSQat2cHwXsRzabS7S2JL2wAQut143LgNFziy7A3+Vcg9icJMc88m9hQx gt4wjm1EyFvw8Wm8bGLvmXVJ1/QnsYms59clj6kzhGS33JesNjjAUUo9VHuqijmommmndoWXJME Fh9cvabz4JLy4RbHE4By/DO1PI3WFgW/bZ+9bt+GaiCa54kHPJ+/0dW5jLdJ8GFfi869iLIPvNK 0JvF+unQ0we5cBDU36dPsb0Uu62tO/swkvmhLuWoPGKlbHiRn+4zGLTl4dmo9XxApCgc4u5dEV5 99ZYOaTWYM+2PgaTmdYmJ9P3V/kUuKdHes/KbZrBvm72QaC9h2IBRr5eahxTy6sRynFWuEBNHot qJYKPQM6mKDWtA= X-Received: by 2002:a05:6a20:43a2:b0:364:13ab:4119 with SMTP id adf61e73a8af0-3937208f054mr2740500637.15.1770209176052; Wed, 04 Feb 2026 04:46:16 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:15 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 08/10] tools/nolibc: sh: Add relocation support Date: Wed, 4 Feb 2026 21:45:40 +0900 Message-ID: <20260204124542.523567-9-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add relocation support for SuperH Signed-off-by: Daniel Palmer --- tools/include/nolibc/arch-sh.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/include/nolibc/arch-sh.h b/tools/include/nolibc/arch-sh.h index 7a421197d104..8e0507977ca1 100644 --- a/tools/include/nolibc/arch-sh.h +++ b/tools/include/nolibc/arch-sh.h @@ -7,8 +7,16 @@ #ifndef _NOLIBC_ARCH_SH_H #define _NOLIBC_ARCH_SH_H =20 +#include "elf.h" + +#ifdef R_SH_RELATIVE +#define _NOLIBC_ARCH_HAS_RELOC +#define _NOLIBC_ARCH_ELF32 +#endif + #include "compiler.h" #include "crt.h" +#include "reloc.h" =20 /* * Syscalls for SuperH: @@ -141,6 +149,22 @@ }) =20 #ifndef NOLIBC_NO_RUNTIME + +#ifdef NOLIBC_WANT_RELOC +static __inline__ int __relocate_rela(unsigned long base, _nolibc_elf_rela= *entry) +{ + switch (_nolibc_elf_r_type(entry->r_info)) { + case R_SH_RELATIVE: + __relocate_rela_relative(base, entry); + break; + default: + return -1; + } + + return 0; +} +#endif + /* startup code */ void _start_wrapper(void); void __attribute__((weak,noreturn)) __nolibc_entrypoint __no_stack_protect= or _start_wrapper(void) --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D46740758E for ; Wed, 4 Feb 2026 12:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209178; cv=none; b=hseXNyK/R7j4vz0sB3e1iSDsG9Vlw+HDBf7eIpGlMKLvgIy0sBg0VPkhwQuD1eiMeZCWr+vs0RKAEoHk3HIkuZuj3P6CUdhujC4Uw+CjU7snzakvowXWAjLTramTb+qZazHaXl4qnqRn0Qk+6Qk13MURLccD9iklUKgjBiI1bAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209178; c=relaxed/simple; bh=BzOAuOajeDnSciuB6ybBotlmKkP4pxYFjxloaZ0n+8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FSJSCvc2GFq3cGa2ss2YxGt1AiyAQqH6JQRfVJur9BhrNAxJTEB/8hJ6iwWr1QqhB7s7ojMr93Vhv6UrqZdGjrWcYZ9aMIkiSRjIX6K/UhdbueFsi3zRXmxR4ImLaJoA6Z2xlUOMZto6QP1C9T3utsTV2Iuu6hXaPbg9RIU3sPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=cOinF57k; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="cOinF57k" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3532aa9a77eso3195906a91.0 for ; Wed, 04 Feb 2026 04:46:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209178; x=1770813978; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+SuVf7XciEfxkw0e3JqAh6PJ8tv0hya9bYr584kpMko=; b=cOinF57ksVfD94tZ3s6NEFshS2JpWYBDrPmvvSxHq9D/u/E7fORo3wyEOQKiLQenGE 5b1z7P36Vc1c76xM7qOGBLyfcwuADqAmrIyPWpM8qJiBJxfnE2vb0b/AEFtgqOIjLT1u QY9adkt+P/yz47VdNWvvRCeIwo5kDYTNwrfCA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209178; x=1770813978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+SuVf7XciEfxkw0e3JqAh6PJ8tv0hya9bYr584kpMko=; b=JpRZSRRPfgvCuAgHxX25JQPU5GDRTj9tqAFpvoXf0ZMNehZmW8SHl2RcwJneAlFPGs gdNq4NoY6h7EuNQXXQjhmZ+tqMt94/xgzNUZyNx3+XY0dA2zOP4RtBVT+H0uszytWwzO brJfdBe3bPssDyAf27V326AvCiF8vv8OnoHI3hnf3163PGDyjfTdHEYjv8Bb9RZXwotM uX6z6ubxRt//YzXKQwFhoDyRi0HswTCQKj/Hc9RGJWT39IQlBsj6icS1ZwPFkvrvEaUI BJpPnFXneBq16vtFk4u+S+i1AmxxlQ6iH6EGaTIfj29+T0438x81wTy9gIAIZspSGzcm bf4A== X-Gm-Message-State: AOJu0YyFGwQJvbQXOOVxSi1RHAlAJymVLrWPKHUi1Ui7lRuBc21Fztaf slwiCKSE8lQ3XnXoQdF8gT6CkNjX7C4RI7rxIDxhBf69XsPdZiOxeft0XTIBwtkhkZg= X-Gm-Gg: AZuq6aLO4CMWMJfPB32TjkZmwEp+LUlmD69KKMWvdZuk7k93QY09NU7xXBvYcMafKNP JGN3rUZGvb9yIlRVtM01zocUWDJvCVNzdTL22Q/74oRDLNGRFxaALhs2fc03FXPc9FuP1UkJpQk /8bMz6UuDa8sYppdIJ/qcxBuZSEyo+MkzMVNA/Ck40S3S8dvfD8I/1L56zBBHQaylmVc0sFd/FP d44/AKnB6QPQRc1msvwoZGKZ8v703/nPQhKymTwypz/OznoWtPu+gj+FMfrOurEwARfN5uUAM2d sdKaY95T/Yv09pvRogcBPlJeshtJDntnQXWeG4B8nFN91aaAv+cMXpz2UcpeHI6HKHUpif438oD +baemOdeh2NmBU9ewljgUFI+Ol2LdbELE51OKcnIacX7rVDifHXnAQgvezcneywc1Y2ftH0kBoa 4FfoILH9QJiqrDeboArAy6FIQ3rXcjadIqhEpMNanBBRAponsx806RktBxIoHNa4IpMj24YZmUq kMa X-Received: by 2002:a17:90b:510f:b0:341:194:5e7d with SMTP id 98e67ed59e1d1-35487195256mr2466403a91.24.1770209177887; Wed, 04 Feb 2026 04:46:17 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:17 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 09/10] tools/nolibc: ppc: Add relocation support Date: Wed, 4 Feb 2026 21:45:41 +0900 Message-ID: <20260204124542.523567-10-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add relocation support for 32bit and 64bit ppc. Signed-off-by: Daniel Palmer --- tools/include/nolibc/arch-powerpc.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/include/nolibc/arch-powerpc.h b/tools/include/nolibc/arc= h-powerpc.h index e0c7e0b81f7c..a23c41b51cf7 100644 --- a/tools/include/nolibc/arch-powerpc.h +++ b/tools/include/nolibc/arch-powerpc.h @@ -7,8 +7,16 @@ #ifndef _NOLIBC_ARCH_POWERPC_H #define _NOLIBC_ARCH_POWERPC_H =20 +#include "elf.h" + +#define _NOLIBC_ARCH_HAS_RELOC +#ifndef __powerpc64__ +#define _NOLIBC_ARCH_ELF32 +#endif + #include "compiler.h" #include "crt.h" +#include "reloc.h" =20 /* Syscalls for PowerPC : * - stack is 16-byte aligned @@ -184,6 +192,22 @@ #endif /* !__powerpc64__ */ =20 #ifndef NOLIBC_NO_RUNTIME + +#ifdef NOLIBC_WANT_RELOC +static __inline__ int __relocate_rela(unsigned long base, _nolibc_elf_rela= *entry) +{ + switch (_nolibc_elf_r_type(entry->r_info)) { + case R_PPC_RELATIVE: + __relocate_rela_relative(base, entry); + break; + default: + return -1; + } + + return 0; +} +#endif /* NOLIBC_WANT_RELOC */ + /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { --=20 2.51.0 From nobody Sat Feb 7 10:08:42 2026 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7566B40B6F0 for ; Wed, 4 Feb 2026 12:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209180; cv=none; b=u9Q/tnyAoCVbD+PoMuVRJuoEuY4BTW3NenfsF5W7EMwcd2y+1euSIdLLxR6l6eQ5MG/UYVxLzbRZsNP15BEqZ7AVlKuadu0FF5G55p5yND+giyuW/nK1ZHr1v1xC/RJG1A7VQnWqKR3mQeXmL/+vX8wGXRxEsOd2IlNB8JLUcQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209180; c=relaxed/simple; bh=kZc/LHINNlskIjqK/Ezt0wdgB6dmXTDesKjw7YYNfKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a3cP7DYUO7NkjSS54ARUsr9qjLv0DCGjwf8SmO4dJE/KovT5q7pLj0o6h2XKhswQ85KI8efpS5z941uLQMIjru8kQjGP1PYDyc4PhvSUUk5mS+yu2VU9YlPoMejG4eGHbWAAEITJkmzpL6xQlR59rnmKNVRSOyTPmYNA2rWHywc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=nJA0ngI5; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="nJA0ngI5" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-c5513f598c0so342660a12.0 for ; Wed, 04 Feb 2026 04:46:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209180; x=1770813980; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nMHV7n3E7WwDamOikF+MO/K8LzPwGrACYORp1duWaic=; b=nJA0ngI5tTHBJyl88/DLpYeXHyYvtJ4TdSFE9L57I1G/jETp/0w+pKZ3MiaabaG+lX lgT1+6BCQekXvookYrOUrQv6BnDM+JQoWoqIeCehl9TC2PHDyrlbFxiDeqKV+kRkYAAb PrgFCItyl7DrOonJr7lUKMpCBHA1B6vQckO5c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209180; x=1770813980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nMHV7n3E7WwDamOikF+MO/K8LzPwGrACYORp1duWaic=; b=aWjLEwMMe97XJFQH4YUuvNNXQZ4wOhy0K6ZyU09XFMjQmV8oBjZDa31EDiJvB4Vodf I71cNLC9a0S6A/9DK2KhCOg12jvVX+Jd/IQYSV+W2zdSZJYnd9zP5NeSzca1LF4A+dpC jRR7UY1vyvezmOsS5hJwiGhfIdU9dWpu9XG4osVB2WYwbYtV+dhFG1HlpJARs9+Swt3+ F/4nYE7klIkiqi8UAa9NH2sdjYLSisFEp12Sg6nkTBgWdSuBJAEt9VKHoDHcbKP9u8+s Blowu+/nW4i7tqvEbvm3HTwBNfcidciY0E8O+1ECds1xTaWp92dpEPOtgcCBVmhP2IwO IzqQ== X-Gm-Message-State: AOJu0Yw7I9NSHXmTKSOrS8/ykZD5EM6idTl6iBNljszGln6QaZfrEoPl w9Ejm+gO5ufHDYBGra5cW9bToa+C4Ea8r7CV9xsl+WsBu2AyuwG76taZjMNgcshcGQ3DruTBmUc 9Zjz4 X-Gm-Gg: AZuq6aIlxUZc0olFAlhgPeXsePIhQ5Thi0ahCDnlVQN6O9vzqLxMFZsj3UYvHlDyN9W uDecNCGURazwzlb486Yt7OwmGHFSXl5Y7Rrq81X2XXfaGZbef1KLTXCkrZRk9/kteSPYjR85QrU af+juViI1y47HNr8HWn4GgQlmcy2n0Kxs8Ndk7x53MZbsuA0x2aCKbulCNVUj3/znNS+DorMOwP cKYxpl2edUqKC8QfJJNuoZ2Eopza3jQm7vuV285StmppZklnQjiN9dT69z/lky1g9fLuCyprCvd KxcE6KKhtTF+Wy9jupqRbwWYjGxC7mguCaaB2Tu40+uWSlLl7jSamp5DdQFODIWMiGCc+5KTgHh nqSDSXm/wtEGEx95A8Ym4YiA188XdLshJW/gtXU+Zl90KqrDvkspwnL/HnsC1G5NVgvFGqNKSTu vtNYrqPBtluAxGBjxJMl2ZsJ4B27YJ1Wd+auIN31rrdeilsokga3GTfdpiOFl5UBI7hqVrczAna y9/ X-Received: by 2002:a17:90b:2fc6:b0:352:cdda:7aa7 with SMTP id 98e67ed59e1d1-354871af6edmr2577349a91.24.1770209179915; Wed, 04 Feb 2026 04:46:19 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:19 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 10/10] selftests/nolibc: Add option for building with -static-pie Date: Wed, 4 Feb 2026 21:45:42 +0900 Message-ID: <20260204124542.523567-11-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260204124542.523567-1-daniel@thingy.jp> References: <20260204124542.523567-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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/selfte= sts/nolibc/Makefile index 40f5c2908dda..5d5c3231cc19 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -9,7 +9,7 @@ cc-option =3D $(call __cc-option, $(CC),,$(1),$(2)) =20 include Makefile.include =20 -CFLAGS =3D -nostdlib -nostdinc -static \ +CFLAGS =3D -nostdlib -nostdinc \ -isystem $(top_srcdir)/tools/include/nolibc -isystem $(top_srcdir)/usr/i= nclude \ $(CFLAGS_NOLIBC_TEST) =20 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: =20 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 nol= ibc-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 nol= ibc-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 =20 libc-test: nolibc-test.c nolibc-test-linkage.c diff --git a/tools/testing/selftests/nolibc/run-tests.sh b/tools/testing/se= lftests/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=3D"$(realpath "${cache_dir}"/nolibc-tests/= )" perform_download=3D0 test_mode=3Dsystem werror=3D1 +staticpie=3D0 llvm=3D all_archs=3D( i386 x86_64 x32 @@ -31,7 +32,7 @@ all_archs=3D( ) archs=3D"${all_archs[@]}" =20 -TEMP=3D$(getopt -o 'j:d:c:b:a:m:pelh' -n "$0" -- "$@") +TEMP=3D$(getopt -o 'j:d:c:b:a:m:peslh' -n "$0" -- "$@") =20 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=3D0 shift; continue ;; + '-s') + staticpie=3D1 + shift; continue ;; '-l') llvm=3D1 shift; continue ;; @@ -171,6 +176,9 @@ test_arch() { if [ "$werror" -ne 0 ]; then CFLAGS_EXTRA=3D"$CFLAGS_EXTRA -Werror -Wl,--fatal-warnings" fi + if [ "$staticpie" -ne 0 ]; then + CFLAGS_EXTRA=3D"$CFLAGS_EXTRA -ggdb -fPIE -pie -Wl,--no-dynamic-linker -= Wl,-ztext -Wl,-zseparate-code" + fi MAKE=3D(make -f Makefile.nolibc -j"${nproc}" XARCH=3D"${arch}" CROSS_COMP= ILE=3D"${cross_compile}" LLVM=3D"${llvm}" O=3D"${build_dir}") =20 case "$test_mode" in --=20 2.51.0