[PATCH 2/6] AArch64: Remove PTR_REG defines

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Fri Feb 21 16:31:24 GMT 2025



On 20/02/25 17:02, Wilco Dijkstra wrote:
> 
> Remove PTR_REG defines.
> 
> OK for commit?


LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> 
> ---
> 
> diff --git a/sysdeps/aarch64/crti.S b/sysdeps/aarch64/crti.S
> index 80da5dced3f9a0f0af107caafd63477f5c618f7e..0c3ee404003926f4058a6f0c5aaf80be75ed1ddd 100644
> --- a/sysdeps/aarch64/crti.S
> +++ b/sysdeps/aarch64/crti.S
> @@ -61,7 +61,7 @@
>  	.type	call_weak_fn, %function
>  call_weak_fn:
>  	adrp	x0, :got:PREINIT_FUNCTION
> -	ldr	PTR_REG (0), [x0, #:got_lo12:PREINIT_FUNCTION]
> +	ldr	x0, [x0, #:got_lo12:PREINIT_FUNCTION]
>  	cbz	x0, 1f
>  	b	PREINIT_FUNCTION
>  1:
> diff --git a/sysdeps/aarch64/dl-start.S b/sysdeps/aarch64/dl-start.S
> index b26549bd3159fd179566f2ae4f1e545fc5b8f671..2ccc219f1efe81e04379f148c86bf7c5a59c3353 100644
> --- a/sysdeps/aarch64/dl-start.S
> +++ b/sysdeps/aarch64/dl-start.S
> @@ -30,11 +30,11 @@ ENTRY (_start)
>  	mov	x0, sp
>  	bl	_dl_start
>  	/* Returns user entry point in x0.  */
> -	mov	PTR_REG (21), PTR_REG (0)
> +	mov	x21, x0
>  
>  	/* Use GL(dl_aarch64_gcs) to set the shadow stack status.  */
>  	adrp	x16, _rtld_local
> -	add	PTR_REG (16), PTR_REG (16), :lo12:_rtld_local
> +	add	x16, x16, :lo12:_rtld_local
>  	ldr	x1, [x16, GL_DL_AARCH64_GCS_OFFSET]
>  	cbz	x1, L(skip_gcs_enable)
>  
> @@ -56,18 +56,18 @@ L(skip_gcs_enable):
>  .type _dl_start_user, %function
>  _dl_start_user:
>  	/* Get argc.  */
> -	ldr	PTR_REG (1), [sp]
> +	ldr	x1, [sp]
>  	/* Get argv.  */
> -	add	x2, sp, PTR_SIZE
> +	add	x2, sp, 8
>  	/* Compute envp.  */
> -	add	PTR_REG (3), PTR_REG (2), PTR_REG (1), lsl PTR_LOG_SIZE
> -	add	PTR_REG (3), PTR_REG (3), PTR_SIZE
> +	add	x3, x2, x1, lsl 3
> +	add	x3, x3, 8
>  	/* Run the init functions of the loaded modules.  */
> -	ldr	PTR_REG (0), [x16]
> +	ldr	x0, [x16]
>  	bl	_dl_init
>  	/* Load the finalizer function.  */
>  	adrp	x0, _dl_fini
> -	add	PTR_REG (0), PTR_REG (0), :lo12:_dl_fini
> +	add	x0, x0, :lo12:_dl_fini
>  	/* Jump to the user's entry point.  */
>  	mov	x16, x21
>  	br	x16
> diff --git a/sysdeps/aarch64/dl-tlsdesc.S b/sysdeps/aarch64/dl-tlsdesc.S
> index 76048950c0f2dade927e58562320508f3e89f962..68afc443f715fa41d0d6d66b35f545fc9be79e8b 100644
> --- a/sysdeps/aarch64/dl-tlsdesc.S
> +++ b/sysdeps/aarch64/dl-tlsdesc.S
> @@ -75,7 +75,7 @@
>  	.align 2
>  _dl_tlsdesc_return:
>  	BTI_C
> -	ldr	PTR_REG (0), [x0, #PTR_SIZE]
> +	ldr	x0, [x0, 8]
>  	RET
>  	cfi_endproc
>  	.size	_dl_tlsdesc_return, .-_dl_tlsdesc_return
> @@ -98,9 +98,9 @@ _dl_tlsdesc_undefweak:
>  	BTI_C
>  	str	x1, [sp, #-16]!
>  	cfi_adjust_cfa_offset (16)
> -	ldr	PTR_REG (0), [x0, #PTR_SIZE]
> +	ldr	x0, [x0, 8]
>  	mrs	x1, tpidr_el0
> -	sub	PTR_REG (0), PTR_REG (0), PTR_REG (1)
> +	sub	x0, x0, x1
>  	ldr	x1, [sp], #16
>  	cfi_adjust_cfa_offset (-16)
>  	RET
> @@ -155,21 +155,21 @@ _dl_tlsdesc_dynamic:
>  	cfi_rel_offset (x4, 24)
>  
>  	mrs	x4, tpidr_el0
> -	ldr	PTR_REG (1), [x0,#TLSDESC_ARG]
> -	ldr	PTR_REG (0), [x4,#TCBHEAD_DTV]
> -	ldr	PTR_REG (3), [x1,#TLSDESC_GEN_COUNT]
> -	ldr	PTR_REG (2), [x0,#DTV_COUNTER]
> -	cmp	PTR_REG (3), PTR_REG (2)
> +	ldr	x1, [x0, TLSDESC_ARG]
> +	ldr	x0, [x4, TCBHEAD_DTV]
> +	ldr	x3, [x1, TLSDESC_GEN_COUNT]
> +	ldr	x2, [x0, DTV_COUNTER]
> +	cmp	x3, x2
>  	b.hi	2f
>  	/* Load r2 = td->tlsinfo.ti_module and r3 = td->tlsinfo.ti_offset.  */
> -	ldp	PTR_REG (2), PTR_REG (3), [x1,#TLSDESC_MODID]
> -	add	PTR_REG (0), PTR_REG (0), PTR_REG (2), lsl #(PTR_LOG_SIZE + 1)
> -	ldr	PTR_REG (0), [x0] /* Load val member of DTV entry.  */
> -	cmp	PTR_REG (0), #TLS_DTV_UNALLOCATED
> +	ldp	x2, x3, [x1, TLSDESC_MODID]
> +	add	x0, x0, x2, lsl 4
> +	ldr	x0, [x0] /* Load val member of DTV entry.  */
> +	cmp	x0, TLS_DTV_UNALLOCATED
>  	b.eq	2f
>  	cfi_remember_state
> -	sub	PTR_REG (3), PTR_REG (3), PTR_REG (4)
> -	add	PTR_REG (0), PTR_REG (0), PTR_REG (3)
> +	sub	x3, x3, x4
> +	add	x0, x0, x3
>  1:
>  	ldp	 x3,  x4, [sp, #16]
>  	ldp	 x1,  x2, [sp], #32
> @@ -220,7 +220,7 @@ _dl_tlsdesc_dynamic:
>  	bl	HIDDEN_JUMPTARGET(__tls_get_addr)
>  
>  	mrs	x1, tpidr_el0
> -	sub	PTR_REG (0), PTR_REG (0), PTR_REG (1)
> +	sub	x0, x0, x1
>  
>  	RESTORE_Q_REGISTERS
>  
> diff --git a/sysdeps/aarch64/dl-trampoline.S b/sysdeps/aarch64/dl-trampoline.S
> index e9fce9ac4c34ebf15331dc9d43e3e2d5d120eed1..d6bed96d6126fdbca6f511b8e8e71bd266005364 100644
> --- a/sysdeps/aarch64/dl-trampoline.S
> +++ b/sysdeps/aarch64/dl-trampoline.S
> @@ -22,12 +22,11 @@
>  #include "dl-link.h"
>  
>  #define ip0 x16
> -#define ip0l PTR_REG (16)
>  #define ip1 x17
>  #define lr  x30
>  
>  /* RELA relocatons are 3 pointers */
> -#define RELA_SIZE (PTR_SIZE * 3)
> +#define RELA_SIZE 24
>  
>  	.text
>  	.globl _dl_runtime_resolve
> @@ -85,7 +84,7 @@ _dl_runtime_resolve:
>  	cfi_rel_offset (q1, 80+7*16)
>  
>  	/* Get pointer to linker struct.  */
> -	ldr	PTR_REG (0), [ip0, #-PTR_SIZE]
> +	ldr	x0, [ip0, -8]
>  
>  	/* Prepare to call _dl_fixup().  */
>  	ldr	x1, [sp, 80+8*16]	/* Recover &PLTGOT[n] */
> @@ -209,7 +208,7 @@ _dl_runtime_profile:
>  	stp	x0, x1, [x29, #OFFSET_RG + DL_OFFSET_RG_SP]
>  
>  	/* Get pointer to linker struct.  */
> -	ldr	PTR_REG (0), [ip0, #-PTR_SIZE]
> +	ldr	x0, [ip0, -8]
>  
>  	/* Prepare to call _dl_profile_fixup().  */
>  	ldr	x1, [x29, OFFSET_PLTGOTN]	/* Recover &PLTGOT[n] */
> @@ -228,8 +227,8 @@ _dl_runtime_profile:
>  	add	x4, x29, #OFFSET_FS		/* address of framesize */
>  	bl	_dl_profile_fixup
>  
> -	ldr	ip0l, [x29, #OFFSET_FS]		/* framesize == 0 */
> -	cmp	ip0l, #0
> +	ldr	ip0, [x29, #OFFSET_FS]		/* framesize == 0 */
> +	cmp	ip0, #0
>  	bge	1f
>  	cfi_remember_state
>  
> @@ -271,7 +270,7 @@ _dl_runtime_profile:
>  1:
>  	/* The new frame size is in ip0.  */
>  
> -	sub	PTR_REG (1), PTR_REG (29), ip0l
> +	sub	x1, x29, ip0
>  	and	sp, x1, #0xfffffffffffffff0
>  
>  	str	x0, [x29, #OFFSET_T1]
> diff --git a/sysdeps/aarch64/start.S b/sysdeps/aarch64/start.S
> index ef6b5ad686c87bd51f65bef6db43ff935d666a7e..544e397c509ab7f1a4b59991f57209ec57f55b1d 100644
> --- a/sysdeps/aarch64/start.S
> +++ b/sysdeps/aarch64/start.S
> @@ -70,8 +70,8 @@ ENTRY(_start)
>  	mov	x5, x0
>  
>  	/* Load argc and a pointer to argv */
> -	ldr	PTR_REG (1), [sp, #0]
> -	add	x2, sp, #PTR_SIZE
> +	ldr	x1, [sp, #0]
> +	add	x2, sp, 8
>  
>  	/* Setup stack limit in argument register */
>  	mov	x6, sp
> @@ -79,14 +79,16 @@ ENTRY(_start)
>  #ifdef PIC
>  # ifdef SHARED
>          adrp    x0, :got:main
> -	ldr     PTR_REG (0), [x0, #:got_lo12:main]
> +	ldr     x0, [x0, #:got_lo12:main]
>  # else
>  	adrp	x0, __wrap_main
>  	add	x0, x0, :lo12:__wrap_main
>  # endif
>  #else
> -	/* Set up the other arguments in registers */
> -	MOVL (0, main)
> +	movz    x0, :abs_g3:main
> +	movk    x0, :abs_g2_nc:main
> +	movk    x0, :abs_g1_nc:main
> +	movk    x0, :abs_g0_nc:main
>  #endif
>  	mov	x3, #0		/* Used to be init.  */
>  	mov	x4, #0		/* Used to be fini.  */
> diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h
> index 036eb125274e6ec4052f0bf0eb7a5daf889444b5..b4aa191dea39c219c2e0d6456111cfeef2e706e6 100644
> --- a/sysdeps/aarch64/sysdep.h
> +++ b/sysdeps/aarch64/sysdep.h
> @@ -21,21 +21,7 @@
>  
>  #include <sysdeps/generic/sysdep.h>
>  
> -#ifdef __LP64__
>  # define AARCH64_R(NAME)	R_AARCH64_ ## NAME
> -# define PTR_REG(n)		x##n
> -# define PTR_LOG_SIZE		3
> -# define PTR_ARG(n)
> -# define SIZE_ARG(n)
> -#else
> -# define AARCH64_R(NAME)	R_AARCH64_P32_ ## NAME
> -# define PTR_REG(n)		w##n
> -# define PTR_LOG_SIZE		2
> -# define PTR_ARG(n)		mov     w##n, w##n
> -# define SIZE_ARG(n)		mov     w##n, w##n
> -#endif
> -
> -#define PTR_SIZE	(1<<PTR_LOG_SIZE)
>  
>  #ifndef __ASSEMBLER__
>  /* Strip pointer authentication code from pointer p.  */
> @@ -199,28 +185,14 @@ GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_GCS)
>     Note R and T are register numbers and not register names.  */
>  #define LDST_PCREL(OP, R, T, EXPR)			\
>  	adrp	x##T, EXPR;				\
> -	OP	PTR_REG (R), [x##T, #:lo12:EXPR];	\
> +	OP	x##R, [x##T, #:lo12:EXPR];	\
>  
>  /* Load or store to/from a got-relative EXPR into/from R, using T.
>     Note R and T are register numbers and not register names.  */
>  #define LDST_GLOBAL(OP, R, T,  EXPR)			\
>  	adrp	x##T, :got:EXPR;			\
> -	ldr	PTR_REG (T), [x##T, #:got_lo12:EXPR];	\
> -	OP	PTR_REG (R), [x##T];
> -
> -/* Load an immediate into R.
> -   Note R is a register number and not a register name.  */
> -#ifdef __LP64__
> -# define MOVL(R, NAME)					\
> -	movz	PTR_REG (R), #:abs_g3:NAME;		\
> -	movk	PTR_REG (R), #:abs_g2_nc:NAME;		\
> -	movk	PTR_REG (R), #:abs_g1_nc:NAME;		\
> -	movk	PTR_REG (R), #:abs_g0_nc:NAME;
> -#else
> -# define MOVL(R, NAME)					\
> -	movz	PTR_REG (R), #:abs_g1:NAME;		\
> -	movk	PTR_REG (R), #:abs_g0_nc:NAME;
> -#endif
> +	ldr	x##T, [x##T, #:got_lo12:EXPR];	\
> +	OP	x##R, [x##T];
>  
>  /* Since C identifiers are not normally prefixed with an underscore
>     on this system, the asm identifier `syscall_error' intrudes on the
> diff --git a/sysdeps/unix/sysv/linux/aarch64/getcontext.S b/sysdeps/unix/sysv/linux/aarch64/getcontext.S
> index 6e7fc241f5c7e7e646bf10e750293f8525721c42..b6e64e50533d00ad66b45c7ab0224325c24db0d7 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/getcontext.S
> +++ b/sysdeps/unix/sysv/linux/aarch64/getcontext.S
> @@ -105,7 +105,7 @@ L(gcs_done):
>  
>  	/* Grab the signal mask */
>  	/* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
> -	add	PTR_REG (2), PTR_REG (0), #UCONTEXT_SIGMASK
> +	add	x2, x0, UCONTEXT_SIGMASK
>  	mov	x0, SIG_BLOCK
>  	mov	x1, 0
>  	mov	x3, _NSIG8
> 



More information about the Libc-alpha mailing list