[RFC PATCH v2 01/10] elf: Add relocation types used by nolibc

Daniel Palmer posted 10 patches 4 days, 3 hours ago
[RFC PATCH v2 01/10] elf: Add relocation types used by nolibc
Posted by Daniel Palmer 4 days, 3 hours ago
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 <daniel@thingy.jp>
---
 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 @@
 
 #include <linux/types.h>
 #include <linux/elf-em.h>
+#include <linux/elf-r.h>
 
 /* 32-bit ELF base types. */
 typedef __u32	Elf32_Addr;
-- 
2.51.0
Re: [RFC PATCH v2 01/10] elf: Add relocation types used by nolibc
Posted by Willy Tarreau 1 day ago
On Wed, Feb 04, 2026 at 09:45:33PM +0900, Daniel Palmer wrote:
> 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 <daniel@thingy.jp>
> ---
>  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

Maybe a comment indicating where to find these values would be helpful
for future architectures ?

Willy