Re: [RFC PATCH v2 05/10] tools/nolibc: x86: Add relocation support

From: Thomas Weißschuh

Date: Mon Feb 16 2026 - 16:06:15 EST


On 2026-02-04 21:45:37+0900, Daniel Palmer wrote:
> Add relocation support for x86, both 32bit and 64bit (including x32).
>
> Signed-off-by: Daniel Palmer <daniel@xxxxxxxxx>
> ---
> 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-x86.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
>
> +#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

This preprocessor soup would be easier to read like this:

/* x86_64 and x32 */
#if defined(__x86_64__) && defined(R_AMD64_RELATIVE)
#define _NOLIBC_ARCH_HAS_RELOC
#endif

/* x32 uses ELF32 */
#if defined(__x86_64__) && defined(__ILP32__)
#define _NOLIBC_ARCH_ELF32
#endif

/* i386 */
#if !defined(__x86_64__) && defined(R_386_RELATIVE)
#define _NOLIBC_ARCH_HAS_RELOC
#define _NOLIBC_ARCH_ELF32
#define _NOLIBC_ARCH_ELF_REL
#endif

The code style for nolibc nowadays is 'defined(FOO)' over '#ifdef FOO'.

> +
> #include "compiler.h"
> #include "crt.h"
> +#include "reloc.h"
>
> #if !defined(__x86_64__)
>
> @@ -158,6 +179,22 @@
> })

(...)