diff mbox

[11/29,AARCH64] Use PTR_REG in crti.S.

Message ID 1414396793-9005-12-git-send-email-apinski@cavium.com
State New
Headers show

Commit Message

Andrew Pinski Oct. 27, 2014, 7:59 a.m. UTC
call_weak_fn loads from a pointer, so use PTR_REG so the load
is 32bits for ILP32.

* sysdeps/aarch64/crti.S: Include sysdep.h
(call_weak_fn): Use PTR_REG when loading from
PREINIT_FUNCTION.

AARCH64: Make RTLD_START paramatizable

Make RTLD_START paramatizable for ILP32 and LP64 usage and provides common
code between ILP32.

* sysdeps/aarch64/dl-machine.h (RTLD_START): Rename to ...
(RTLD_START_1): This and add PTR, PTR_SIZE_LOG, and PTR_SP arguments.
(RTLD_START): New macro which uses RTLD_START_1.
---
 sysdeps/aarch64/crti.S       |    3 +-
 sysdeps/aarch64/dl-machine.h |  130 ++++++++++++++++++++++--------------------
 2 files changed, 70 insertions(+), 63 deletions(-)

Comments

Will Newton Nov. 18, 2014, 12:09 p.m. UTC | #1
On 27 October 2014 07:59, Andrew Pinski <apinski@cavium.com> wrote:
> call_weak_fn loads from a pointer, so use PTR_REG so the load
> is 32bits for ILP32.
>
> * sysdeps/aarch64/crti.S: Include sysdep.h
> (call_weak_fn): Use PTR_REG when loading from
> PREINIT_FUNCTION.
>
> AARCH64: Make RTLD_START paramatizable
>
> Make RTLD_START paramatizable for ILP32 and LP64 usage and provides common
> code between ILP32.
>
> * sysdeps/aarch64/dl-machine.h (RTLD_START): Rename to ...
> (RTLD_START_1): This and add PTR, PTR_SIZE_LOG, and PTR_SP arguments.
> (RTLD_START): New macro which uses RTLD_START_1.
> ---
>  sysdeps/aarch64/crti.S       |    3 +-
>  sysdeps/aarch64/dl-machine.h |  130 ++++++++++++++++++++++--------------------
>  2 files changed, 70 insertions(+), 63 deletions(-)

This looks ok to me.

> diff --git a/sysdeps/aarch64/crti.S b/sysdeps/aarch64/crti.S
> index 2db7b67..d31bb50 100644
> --- a/sysdeps/aarch64/crti.S
> +++ b/sysdeps/aarch64/crti.S
> @@ -39,6 +39,7 @@
>     they can be called as functions.  The symbols _init and _fini are
>     magic and cause the linker to emit DT_INIT and DT_FINI.  */
>
> +#include <sysdep.h>
>  #include <libc-symbols.h>
>
>  #ifndef PREINIT_FUNCTION
> @@ -60,7 +61,7 @@
>         .type   call_weak_fn, %function
>  call_weak_fn:
>         adrp    x0, :got:PREINIT_FUNCTION
> -       ldr     x0, [x0, #:got_lo12:PREINIT_FUNCTION]
> +       ldr     PTR_REG(0), [x0, #:got_lo12:PREINIT_FUNCTION]
>         cbz     x0, 1f
>         b       PREINIT_FUNCTION
>  1:
> diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h
> index 4317669..6e041b1 100644
> --- a/sysdeps/aarch64/dl-machine.h
> +++ b/sysdeps/aarch64/dl-machine.h
> @@ -123,68 +123,74 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
>  /* Initial entry point for the dynamic linker. The C function
>     _dl_start is the real entry point, its return value is the user
>     program's entry point */
> +#ifdef __LP64__
> +#define RTLD_START RTLD_START_1("x", "3", "sp")
> +#else
> +#define RTLD_START RTLD_START_1("w", "2", "wsp")
> +#endif
> +
>
> -#define RTLD_START asm ("\
> -.text                                                          \n\
> -.globl _start                                                  \n\
> -.type _start, %function                                                \n\
> -.globl _dl_start_user                                          \n\
> -.type _dl_start_user, %function                                        \n\
> -_start:                                                                \n\
> -       mov     x0,     sp                                      \n\
> -       bl      _dl_start                                       \n\
> -       // returns user entry point in x0                       \n\
> -       mov     x21, x0                                         \n\
> -_dl_start_user:                                                        \n\
> -       // get the original arg count                           \n\
> -       ldr     x1, [sp]                                        \n\
> -       // get the argv address                                 \n\
> -       add     x2, sp, #8                                      \n\
> -       // get _dl_skip_args to see if we were                  \n\
> -       // invoked as an executable                             \n\
> -       adrp    x4, _dl_skip_args                               \n\
> -        ldr    w4, [x4, #:lo12:_dl_skip_args]                  \n\
> -       // do we need to adjust argc/argv                       \n\
> -        cmp    w4, 0                                           \n\
> -       beq     .L_done_stack_adjust                            \n\
> -       // subtract _dl_skip_args from original arg count       \n\
> -       sub     x1, x1, x4                                      \n\
> -       // store adjusted argc back to stack                    \n\
> -       str     x1, [sp]                                        \n\
> -       // find the first unskipped argument                    \n\
> -       mov     x3, x2                                          \n\
> -       add     x4, x2, x4, lsl #3                              \n\
> -       // shuffle argv down                                    \n\
> -1:     ldr     x5, [x4], #8                                    \n\
> -       str     x5, [x3], #8                                    \n\
> -       cmp     x5, #0                                          \n\
> -       bne     1b                                              \n\
> -       // shuffle envp down                                    \n\
> -1:     ldr     x5, [x4], #8                                    \n\
> -       str     x5, [x3], #8                                    \n\
> -       cmp     x5, #0                                          \n\
> -       bne     1b                                              \n\
> -       // shuffle auxv down                                    \n\
> -1:     ldp     x0, x5, [x4, #16]!                              \n\
> -       stp     x0, x5, [x3], #16                               \n\
> -       cmp     x0, #0                                          \n\
> -       bne     1b                                              \n\
> -       // Update _dl_argv                                      \n\
> -       adrp    x3, _dl_argv                                    \n\
> -       str     x2, [x3, #:lo12:_dl_argv]                       \n\
> -.L_done_stack_adjust:                                          \n\
> -       // compute envp                                         \n\
> -       add     x3, x2, x1, lsl #3                              \n\
> -       add     x3, x3, #8                                      \n\
> -       adrp    x16, _rtld_local                                \n\
> -        add    x16, x16, #:lo12:_rtld_local                    \n\
> -        ldr    x0, [x16]                                       \n\
> -       bl      _dl_init_internal                               \n\
> -       // load the finalizer function                          \n\
> -       adrp    x0, _dl_fini                                    \n\
> -       add     x0, x0, #:lo12:_dl_fini                         \n\
> -       // jump to the user_s entry point                       \n\
> -       br      x21                                             \n\
> +#define RTLD_START_1(PTR, PTR_SIZE_LOG, PTR_SP) asm ("\
> +.text                                                                  \n\
> +.globl _start                                                          \n\
> +.type _start, %function                                                        \n\
> +.globl _dl_start_user                                                  \n\
> +.type _dl_start_user, %function                                                \n\
> +_start:                                                                        \n\
> +       mov     " PTR "0, " PTR_SP "                                    \n\
> +       bl      _dl_start                                               \n\
> +       // returns user entry point in x0                               \n\
> +       mov     x21, x0                                                 \n\
> +_dl_start_user:                                                                \n\
> +       // get the original arg count                                   \n\
> +       ldr     " PTR "1, [sp]                                          \n\
> +       // get the argv address                                         \n\
> +       add     " PTR "2, " PTR_SP ", #(1<<"  PTR_SIZE_LOG ")           \n\
> +       // get _dl_skip_args to see if we were                          \n\
> +       // invoked as an executable                                     \n\
> +       adrp    x4, _dl_skip_args                                       \n\
> +        ldr    w4, [x4, #:lo12:_dl_skip_args]                          \n\
> +       // do we need to adjust argc/argv                               \n\
> +        cmp    w4, 0                                                   \n\
> +       beq     .L_done_stack_adjust                                    \n\
> +       // subtract _dl_skip_args from original arg count               \n\
> +       sub     " PTR "1, " PTR "1, " PTR "4                            \n\
> +       // store adjusted argc back to stack                            \n\
> +       str     " PTR "1, [sp]                                          \n\
> +       // find the first unskipped argument                            \n\
> +       mov     " PTR "3, " PTR "2                                      \n\
> +       add     " PTR "4, " PTR "2, " PTR "4, lsl #" PTR_SIZE_LOG "     \n\
> +       // shuffle argv down                                            \n\
> +1:     ldr     " PTR "5, [x4], #(1<<"  PTR_SIZE_LOG ")                 \n\
> +       str     " PTR "5, [x3], #(1<<"  PTR_SIZE_LOG ")                 \n\
> +       cmp     " PTR "5, #0                                            \n\
> +       bne     1b                                                      \n\
> +       // shuffle envp down                                            \n\
> +1:     ldr     " PTR "5, [x4], #(1<<"  PTR_SIZE_LOG ")                 \n\
> +       str     " PTR "5, [x3], #(1<<"  PTR_SIZE_LOG ")                 \n\
> +       cmp     " PTR "5, #0                                            \n\
> +       bne     1b                                                      \n\
> +       // shuffle auxv down                                            \n\
> +1:     ldp     " PTR "0, " PTR "5, [x4, #(2<<"  PTR_SIZE_LOG ")]!      \n\
> +       stp     " PTR "0, " PTR "5, [x3], #(2<<"  PTR_SIZE_LOG ")       \n\
> +       cmp     " PTR "0, #0                                            \n\
> +       bne     1b                                                      \n\
> +       // Update _dl_argv                                              \n\
> +       adrp    x3, _dl_argv                                            \n\
> +       str     " PTR "2, [x3, #:lo12:_dl_argv]                         \n\
> +.L_done_stack_adjust:                                                  \n\
> +       // compute envp                                                 \n\
> +       add     " PTR "3, " PTR "2, " PTR "1, lsl #" PTR_SIZE_LOG "     \n\
> +       add     " PTR "3, " PTR "3, #(1<<"  PTR_SIZE_LOG ")             \n\
> +       adrp    x16, _rtld_local                                        \n\
> +        add    " PTR "16, " PTR "16, #:lo12:_rtld_local                \n\
> +        ldr    " PTR "0, [x16]                                         \n\
> +       bl      _dl_init_internal                                       \n\
> +       // load the finalizer function                                  \n\
> +       adrp    x0, _dl_fini                                            \n\
> +       add     " PTR "0, " PTR "0, #:lo12:_dl_fini                     \n\
> +       // jump to the user_s entry point                               \n\
> +       br      x21                                                     \n\
>  ");
>
>  #define elf_machine_type_class(type)                           \
> --
> 1.7.2.5
>
diff mbox

Patch

diff --git a/sysdeps/aarch64/crti.S b/sysdeps/aarch64/crti.S
index 2db7b67..d31bb50 100644
--- a/sysdeps/aarch64/crti.S
+++ b/sysdeps/aarch64/crti.S
@@ -39,6 +39,7 @@ 
    they can be called as functions.  The symbols _init and _fini are
    magic and cause the linker to emit DT_INIT and DT_FINI.  */
 
+#include <sysdep.h>
 #include <libc-symbols.h>
 
 #ifndef PREINIT_FUNCTION
@@ -60,7 +61,7 @@ 
 	.type	call_weak_fn, %function
 call_weak_fn:
 	adrp	x0, :got:PREINIT_FUNCTION
-	ldr	x0, [x0, #:got_lo12:PREINIT_FUNCTION]
+	ldr	PTR_REG(0), [x0, #:got_lo12:PREINIT_FUNCTION]
 	cbz	x0, 1f
 	b	PREINIT_FUNCTION
 1:
diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h
index 4317669..6e041b1 100644
--- a/sysdeps/aarch64/dl-machine.h
+++ b/sysdeps/aarch64/dl-machine.h
@@ -123,68 +123,74 @@  elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
 /* Initial entry point for the dynamic linker. The C function
    _dl_start is the real entry point, its return value is the user
    program's entry point */
+#ifdef __LP64__
+#define RTLD_START RTLD_START_1("x", "3", "sp")
+#else
+#define RTLD_START RTLD_START_1("w", "2", "wsp")
+#endif
+
 
-#define RTLD_START asm ("\
-.text								\n\
-.globl _start							\n\
-.type _start, %function						\n\
-.globl _dl_start_user						\n\
-.type _dl_start_user, %function					\n\
-_start:								\n\
-	mov	x0,	sp					\n\
-	bl	_dl_start					\n\
-	// returns user entry point in x0			\n\
-	mov	x21, x0						\n\
-_dl_start_user:							\n\
-	// get the original arg count				\n\
-	ldr	x1, [sp]					\n\
-	// get the argv address					\n\
-	add	x2, sp, #8					\n\
-	// get _dl_skip_args to see if we were			\n\
-	// invoked as an executable				\n\
-	adrp	x4, _dl_skip_args				\n\
-        ldr	w4, [x4, #:lo12:_dl_skip_args]			\n\
-	// do we need to adjust argc/argv			\n\
-        cmp	w4, 0						\n\
-	beq	.L_done_stack_adjust				\n\
-	// subtract _dl_skip_args from original arg count	\n\
-	sub	x1, x1, x4					\n\
-	// store adjusted argc back to stack			\n\
-	str	x1, [sp]					\n\
-	// find the first unskipped argument			\n\
-	mov	x3, x2						\n\
-	add	x4, x2, x4, lsl #3				\n\
-	// shuffle argv down					\n\
-1:	ldr	x5, [x4], #8					\n\
-	str	x5, [x3], #8					\n\
-	cmp	x5, #0						\n\
-	bne	1b						\n\
-	// shuffle envp down					\n\
-1:	ldr	x5, [x4], #8					\n\
-	str	x5, [x3], #8					\n\
-	cmp	x5, #0						\n\
-	bne	1b						\n\
-	// shuffle auxv down					\n\
-1:	ldp	x0, x5, [x4, #16]!				\n\
-	stp	x0, x5, [x3], #16				\n\
-	cmp	x0, #0						\n\
-	bne	1b						\n\
-	// Update _dl_argv					\n\
-	adrp	x3, _dl_argv					\n\
-	str	x2, [x3, #:lo12:_dl_argv]			\n\
-.L_done_stack_adjust:						\n\
-	// compute envp						\n\
-	add	x3, x2, x1, lsl #3				\n\
-	add	x3, x3, #8					\n\
-	adrp	x16, _rtld_local				\n\
-        add	x16, x16, #:lo12:_rtld_local			\n\
-        ldr	x0, [x16]					\n\
-	bl	_dl_init_internal				\n\
-	// load the finalizer function				\n\
-	adrp	x0, _dl_fini					\n\
-	add	x0, x0, #:lo12:_dl_fini				\n\
-	// jump to the user_s entry point			\n\
-	br      x21						\n\
+#define RTLD_START_1(PTR, PTR_SIZE_LOG, PTR_SP) asm ("\
+.text									\n\
+.globl _start								\n\
+.type _start, %function							\n\
+.globl _dl_start_user							\n\
+.type _dl_start_user, %function						\n\
+_start:									\n\
+	mov	" PTR "0, " PTR_SP "					\n\
+	bl	_dl_start						\n\
+	// returns user entry point in x0				\n\
+	mov	x21, x0							\n\
+_dl_start_user:								\n\
+	// get the original arg count					\n\
+	ldr	" PTR "1, [sp]						\n\
+	// get the argv address						\n\
+	add	" PTR "2, " PTR_SP ", #(1<<"  PTR_SIZE_LOG ")		\n\
+	// get _dl_skip_args to see if we were				\n\
+	// invoked as an executable					\n\
+	adrp	x4, _dl_skip_args					\n\
+        ldr	w4, [x4, #:lo12:_dl_skip_args]				\n\
+	// do we need to adjust argc/argv				\n\
+        cmp	w4, 0							\n\
+	beq	.L_done_stack_adjust					\n\
+	// subtract _dl_skip_args from original arg count		\n\
+	sub	" PTR "1, " PTR "1, " PTR "4				\n\
+	// store adjusted argc back to stack				\n\
+	str	" PTR "1, [sp]						\n\
+	// find the first unskipped argument				\n\
+	mov	" PTR "3, " PTR "2					\n\
+	add	" PTR "4, " PTR "2, " PTR "4, lsl #" PTR_SIZE_LOG "	\n\
+	// shuffle argv down						\n\
+1:	ldr	" PTR "5, [x4], #(1<<"  PTR_SIZE_LOG ")			\n\
+	str	" PTR "5, [x3], #(1<<"  PTR_SIZE_LOG ")			\n\
+	cmp	" PTR "5, #0						\n\
+	bne	1b							\n\
+	// shuffle envp down						\n\
+1:	ldr	" PTR "5, [x4], #(1<<"  PTR_SIZE_LOG ")			\n\
+	str	" PTR "5, [x3], #(1<<"  PTR_SIZE_LOG ")			\n\
+	cmp	" PTR "5, #0						\n\
+	bne	1b							\n\
+	// shuffle auxv down						\n\
+1:	ldp	" PTR "0, " PTR "5, [x4, #(2<<"  PTR_SIZE_LOG ")]!	\n\
+	stp	" PTR "0, " PTR "5, [x3], #(2<<"  PTR_SIZE_LOG ")	\n\
+	cmp	" PTR "0, #0						\n\
+	bne	1b							\n\
+	// Update _dl_argv						\n\
+	adrp	x3, _dl_argv						\n\
+	str	" PTR "2, [x3, #:lo12:_dl_argv]				\n\
+.L_done_stack_adjust:							\n\
+	// compute envp							\n\
+	add	" PTR "3, " PTR "2, " PTR "1, lsl #" PTR_SIZE_LOG "	\n\
+	add	" PTR "3, " PTR "3, #(1<<"  PTR_SIZE_LOG ")		\n\
+	adrp	x16, _rtld_local					\n\
+        add	" PTR "16, " PTR "16, #:lo12:_rtld_local		\n\
+        ldr	" PTR "0, [x16]						\n\
+	bl	_dl_init_internal					\n\
+	// load the finalizer function					\n\
+	adrp	x0, _dl_fini						\n\
+	add	" PTR "0, " PTR "0, #:lo12:_dl_fini			\n\
+	// jump to the user_s entry point				\n\
+	br      x21							\n\
 ");
 
 #define elf_machine_type_class(type)				\