* [PATCH 00/17] Remove _dl_skip_args
@ 2022-05-26 16:49 Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 01/17] alpha: Remove _dl_skip_args usage Adhemerval Zanella
` (17 more replies)
0 siblings, 18 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Both ad43cac44a686 (rtld: Use generic argv adjustment in ld.so [BZ
#23293]) and 86147bbeec25624 (rtld: Remove DL_ARGV_NOT_RELRO and make
_dl_skip_args const) broke both hppa (BZ# 29165) and nios2 (BZ# 29187)
because different than aarch64, the patch did not adjust the
architectures for the new internal semantics.
This patchset adjust the remaining architectures to remove the
_dl_skip_args usage and fix both hppa and nios2.
I checked on alpha, arm, microblaze, mips, nios2, or1k, riscv, and
sh4 with a simple test to check if argc, argv, and envp are the
expected ones on both the constructor and on main program.
I also run a full native make check for aarch64, hppa, i686, ia64,
powerpc, s390, sparc, and x86_64.
The onle architectures that I could not actually test are arc and
csky.
Adhemerval Zanella (17):
alpha: Remove _dl_skip_args usage
arm: Remove _dl_skip_args usage
arc: Remove _dl_skip_args usage
csky: Remove _dl_skip_args usage
hppa: Remove _dl_skip_args usage (BZ# 29165)
i686: Remove _dl_skip_args usage
ia64: Remove _dl_skip_args usage
m68k: Remove _dl_skip_args usage
microblaze: Remove _dl_skip_args usage
mips: Remove _dl_skip_args usage
nios2: Remove _dl_skip_args usage (BZ# 29187)
riscv: Remove _dl_skip_args usage
s390: Remove _dl_skip_args usage
sh: Remove _dl_skip_args usage
sparc: Remove _dl_skip_args usage
x86_64: Remove _dl_skip_args usage
elf: Remove _dl_skip_args
elf/rtld.c | 2 -
sysdeps/alpha/dl-machine.h | 41 -----------------
sysdeps/arc/dl-machine.h | 17 +-------
sysdeps/arm/dl-machine.h | 39 -----------------
sysdeps/csky/dl-machine.h | 19 +-------
sysdeps/generic/ldsodefs.h | 4 --
sysdeps/hppa/dl-machine.h | 28 +++++-------
sysdeps/i386/dl-machine.h | 13 +-----
sysdeps/ia64/dl-machine.h | 70 ++++++------------------------
sysdeps/m68k/dl-machine.h | 9 +---
sysdeps/mach/hurd/dl-sysdep.c | 1 -
sysdeps/microblaze/dl-machine.h | 5 ---
sysdeps/mips/dl-machine.h | 31 +------------
sysdeps/nios2/dl-machine.h | 50 +++++----------------
sysdeps/riscv/dl-machine.h | 12 -----
sysdeps/s390/s390-32/dl-machine.h | 46 --------------------
sysdeps/s390/s390-64/dl-machine.h | 16 -------
sysdeps/sh/dl-machine.h | 16 +------
sysdeps/sparc/sparc32/dl-machine.h | 43 +-----------------
sysdeps/sparc/sparc64/dl-machine.h | 40 +----------------
sysdeps/x86_64/dl-machine.h | 13 +-----
sysdeps/x86_64/x32/dl-machine.h | 12 +----
22 files changed, 52 insertions(+), 475 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 01/17] alpha: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 02/17] arm: " Adhemerval Zanella
` (16 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. It makes the fixup_stack branch ununsed.
Checked with qemu-user that arguments are correctly passed on both
constructors and main program.
---
sysdeps/alpha/dl-machine.h | 41 --------------------------------------
1 file changed, 41 deletions(-)
diff --git a/sysdeps/alpha/dl-machine.h b/sysdeps/alpha/dl-machine.h
index ccee972c96..f0ba8e88af 100644
--- a/sysdeps/alpha/dl-machine.h
+++ b/sysdeps/alpha/dl-machine.h
@@ -156,12 +156,6 @@ _dl_start_user: \n\
.prologue 0 \n\
/* Save the user entry point address in s0. */ \n\
mov $0, $9 \n\
- /* See if we were run as a command with the executable \n\
- file name as an extra leading argument. */ \n\
- ldah $1, _dl_skip_args($gp) !gprelhigh \n\
- ldl $1, _dl_skip_args($1) !gprellow \n\
- bne $1, $fixup_stack \n\
-$fixup_stack_ret: \n\
/* The special initializer gets called with the stack \n\
just as the application's entry point will see it; \n\
it can switch stacks if it moves these contents \n\
@@ -182,41 +176,6 @@ $fixup_stack_ret: \n\
/* Jump to the user's entry point. */ \n\
mov $9, $27 \n\
jmp ($9) \n\
-$fixup_stack: \n\
- /* Adjust the stack pointer to skip _dl_skip_args words.\n\
- This involves copying everything down, since the \n\
- stack pointer must always be 16-byte aligned. */ \n\
- ldah $7, __GI__dl_argv($gp) !gprelhigh \n\
- ldq $2, 0($sp) \n\
- ldq $5, __GI__dl_argv($7) !gprellow \n\
- subq $31, $1, $6 \n\
- subq $2, $1, $2 \n\
- s8addq $6, $5, $5 \n\
- mov $sp, $4 \n\
- s8addq $1, $sp, $3 \n\
- stq $2, 0($sp) \n\
- stq $5, __GI__dl_argv($7) !gprellow \n\
- /* Copy down argv. */ \n\
-0: ldq $5, 8($3) \n\
- addq $4, 8, $4 \n\
- addq $3, 8, $3 \n\
- stq $5, 0($4) \n\
- bne $5, 0b \n\
- /* Copy down envp. */ \n\
-1: ldq $5, 8($3) \n\
- addq $4, 8, $4 \n\
- addq $3, 8, $3 \n\
- stq $5, 0($4) \n\
- bne $5, 1b \n\
- /* Copy down auxiliary table. */ \n\
-2: ldq $5, 8($3) \n\
- ldq $6, 16($3) \n\
- addq $4, 16, $4 \n\
- addq $3, 16, $3 \n\
- stq $5, -8($4) \n\
- stq $6, 0($4) \n\
- bne $5, 2b \n\
- br $fixup_stack_ret \n\
.end _dl_start_user \n\
.set noat \n\
.previous");
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 02/17] arm: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 01/17] alpha: Remove _dl_skip_args usage Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 03/17] arc: " Adhemerval Zanella
` (15 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. It makes the _fixup_stack branch ununsed.
Checked with qemu-user that arguments are correctly passed on both
constructors and main program.
---
sysdeps/arm/dl-machine.h | 39 ---------------------------------------
1 file changed, 39 deletions(-)
diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
index 2a7f795e46..6a422713bd 100644
--- a/sysdeps/arm/dl-machine.h
+++ b/sysdeps/arm/dl-machine.h
@@ -130,9 +130,6 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
_start:\n\
@ we are PIC code, so get global offset table\n\
ldr sl, .L_GET_GOT\n\
- @ See if we were run as a command with the executable file\n\
- @ name as an extra leading argument.\n\
- ldr r4, .L_SKIP_ARGS\n\
@ at start time, all the args are on the stack\n\
mov r0, sp\n\
bl _dl_start\n\
@@ -147,10 +144,6 @@ _dl_start_user:\n\
ldr r1, [sp]\n\
@ get the argv address\n\
add r2, sp, #4\n\
- @ Fix up the stack if necessary.\n\
- cmp r4, #0\n\
- bne .L_fixup_stack\n\
-.L_done_fixup:\n\
@ compute envp\n\
add r3, r2, r1, lsl #2\n\
add r3, r3, #4\n\
@@ -164,41 +157,9 @@ _dl_start_user:\n\
add r0, sl, r0\n\
@ jump to the user_s entry point\n\
" BX(r6) "\n\
-\n\
- @ iWMMXt and EABI targets require the stack to be eight byte\n\
- @ aligned - shuffle arguments etc.\n\
-.L_fixup_stack:\n\
- @ subtract _dl_skip_args from original arg count\n\
- sub r1, r1, r4\n\
- @ store the new argc in the new stack location\n\
- str r1, [sp]\n\
- @ find the first unskipped argument\n\
- mov r3, r2\n\
- add r4, r2, r4, lsl #2\n\
- @ shuffle argv down\n\
-1: ldr r5, [r4], #4\n\
- str r5, [r3], #4\n\
- cmp r5, #0\n\
- bne 1b\n\
- @ shuffle envp down\n\
-1: ldr r5, [r4], #4\n\
- str r5, [r3], #4\n\
- cmp r5, #0\n\
- bne 1b\n\
- @ shuffle auxv down\n\
-1: ldmia r4!, {r0, r5}\n\
- stmia r3!, {r0, r5}\n\
- cmp r0, #0\n\
- bne 1b\n\
- @ Update _dl_argv\n\
- ldr r3, .L_ARGV\n\
- str r2, [sl, r3]\n\
- b .L_done_fixup\n\
\n\
.L_GET_GOT:\n\
.word _GLOBAL_OFFSET_TABLE_ - .L_GET_GOT\n\
-.L_SKIP_ARGS:\n\
- .word _dl_skip_args(GOTOFF)\n\
.L_FINI_PROC:\n\
.word _dl_fini(GOTOFF)\n\
.L_ARGV:\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 03/17] arc: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 01/17] alpha: Remove _dl_skip_args usage Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 02/17] arm: " Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 04/17] csky: " Adhemerval Zanella
` (14 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
---
sysdeps/arc/dl-machine.h | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/sysdeps/arc/dl-machine.h b/sysdeps/arc/dl-machine.h
index 4ac3848557..c6ad232384 100644
--- a/sysdeps/arc/dl-machine.h
+++ b/sysdeps/arc/dl-machine.h
@@ -161,29 +161,16 @@ __start: \n\
bl.d _dl_start \n\
mov_s r0, sp /* pass ptr to aux vector tbl. */ \n\
mov r13, r0 /* safekeep app elf entry point. */ \n\
- \n\
- /* (2). If ldso ran with executable as arg. */ \n\
- /* skip the extra args calc by dl_start. */ \n\
ld_s r1, [sp] /* orig argc. */ \n\
- ld r12, [pcl, _dl_skip_args@pcl] \n\
- breq r12, 0, 1f \n\
\n\
- add2 sp, sp, r12 /* discard argv entries from stack. */ \n\
- sub_s r1, r1, r12 /* adjusted argc on stack. */ \n\
- st_s r1, [sp] \n\
- add r2, sp, 4 \n\
- /* intermediate LD for ST emcoding limitations. */ \n\
- ld r3, [pcl, _dl_argv@gotpc] \n\
- st r2, [r3] \n\
-1: \n\
- /* (3). call preinit stuff. */ \n\
+ /* (2). call preinit stuff. */ \n\
ld r0, [pcl, _rtld_local@pcl] \n\
add r2, sp, 4 ; argv \n\
add2 r3, r2, r1 \n\
add r3, r3, 4 ; env \n\
bl _dl_init@plt \n\
\n\
- /* (4) call app elf entry point. */ \n\
+ /* (3) call app elf entry point. */ \n\
add r0, pcl, _dl_fini@pcl \n\
j [r13] \n\
\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 04/17] csky: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (2 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 03/17] arc: " Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165) Adhemerval Zanella
` (13 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. It makes the fixup_stack branch ununsed.
---
sysdeps/csky/dl-machine.h | 19 +------------------
1 file changed, 1 insertion(+), 18 deletions(-)
diff --git a/sysdeps/csky/dl-machine.h b/sysdeps/csky/dl-machine.h
index f81448a141..48787ce3c7 100644
--- a/sysdeps/csky/dl-machine.h
+++ b/sysdeps/csky/dl-machine.h
@@ -113,11 +113,7 @@ _start:\n\
addu t1, gb\n\
jsr t1\n\
_dl_start_user:\n\
- /* get _dl_skip_args */ \n\
- lrw r11, _dl_skip_args@GOTOFF\n\
- addu r11, gb\n\
- ldw r11, (r11, 0)\n\
- /* store program entry address in r11 */ \n\
+ /* store program entry address in r10 */ \n\
mov r10, a0\n\
/* Get argc */\n\
ldw a1, (sp, 0)\n\
@@ -125,8 +121,6 @@ _dl_start_user:\n\
mov a2, sp\n\
addi a2, 4\n\
cmpnei r11, 0\n\
- bt .L_fixup_stack\n\
-.L_done_fixup:\n\
mov a3, a1\n\
lsli a3, 2\n\
add a3, a2\n\
@@ -141,17 +135,6 @@ _dl_start_user:\n\
lrw a0, _dl_fini@GOTOFF\n\
addu a0, gb\n\
jmp r10\n\
-.L_fixup_stack:\n\
- subu a1, r11\n\
- lsli r11, 2\n\
- addu sp, r11\n\
- stw a1, (sp, 0)\n\
- mov a2, sp\n\
- addi a2, 4\n\
- lrw a3, _dl_argv@GOTOFF\n\
- addu a3, gb\n\
- stw a2, (a3, 0)\n\
- br .L_done_fixup\n\
");
/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165)
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (3 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 04/17] csky: " Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 18:14 ` Florian Weimer
2022-05-26 16:49 ` [PATCH 06/17] i686: Remove _dl_skip_args usage Adhemerval Zanella
` (12 subsequent siblings)
17 siblings, 1 reply; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Different than other architectures, hppa creates an unrelated stack
frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
is not done on the argc/argv saved/restore by _dl_start_user.
Instead load _dl_argc and _dl_argv directlty instead of adjust them
using _dl_skip_args value.
Checked on hppa-linux-gnu.
---
sysdeps/hppa/dl-machine.h | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h
index 8c0ca32fc6..7d7230a291 100644
--- a/sysdeps/hppa/dl-machine.h
+++ b/sysdeps/hppa/dl-machine.h
@@ -415,10 +415,8 @@ asm ( \
So, obviously, we can't just pass %sp to _dl_start. That's \
okay, argv-4 will do just fine. \
\
- The pleasant part of this is that if we need to skip \
- arguments we can just decrement argc and move argv, because \
- the stack pointer is utterly unrelated to the location of \
- the environment and argument vectors. */ \
+ It also mean that to get the correct argc and argv if the \
+ program is ld.so it requires to read _dl_argc and _dl_argv. */\
\
/* This is always within range so we'll be okay. */ \
" bl _dl_start,%rp\n" \
@@ -430,22 +428,18 @@ asm ( \
/* Save the entry point in %r3. */ \
" copy %ret0,%r3\n" \
\
- /* See if we were called as a command with the executable file \
- name as an extra leading argument. */ \
-" addil LT'_dl_skip_args,%r19\n" \
-" ldw RT'_dl_skip_args(%r1),%r20\n" \
-" ldw 0(%r20),%r20\n" \
- \
-" ldw -40(%sp),%r25\n" /* argc */ \
-" comib,= 0,%r20,.Lnofix\n" /* FIXME: Mispredicted branch */\
-" ldw -44(%sp),%r24\n" /* argv (delay slot) */ \
- \
-" sub %r25,%r20,%r25\n" \
+ /* Load argc and store the argc if the loader changes it. */ \
+" addil LT'_dl_argc,%r19\n" \
+" ldw RT'_dl_argc(%r1),%r20\n" \
+" ldw 0(%r20),%r25\n" \
" stw %r25,-40(%sp)\n" \
-" sh2add %r20,%r24,%r24\n" \
+ \
+ /* Same for argv. */ \
+" addil LT'_dl_argv,%r19\n" \
+" ldw RT'_dl_argv(%r1),%r20\n" \
+" ldw 0(%r20),%r24\n" \
" stw %r24,-44(%sp)\n" \
\
-".Lnofix:\n" \
/* Call _dl_init(main_map, argc, argv, envp). */ \
" addil LT'_rtld_local,%r19\n" \
" ldw RT'_rtld_local(%r1),%r26\n" \
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 06/17] i686: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (4 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165) Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 20:53 ` H.J. Lu
2022-05-26 16:49 ` [PATCH 07/17] ia64: " Adhemerval Zanella
` (11 subsequent siblings)
17 siblings, 1 reply; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked on i686-linux-gnu.
---
sysdeps/i386/dl-machine.h | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
index 1f8d734215..8779983c8c 100644
--- a/sysdeps/i386/dl-machine.h
+++ b/sysdeps/i386/dl-machine.h
@@ -143,17 +143,8 @@ _dl_start_user:\n\
# Point %ebx at the GOT.\n\
call 0b\n\
addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
- # See if we were run as a command with the executable file\n\
- # name as an extra leading argument.\n\
- movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
- # Pop the original argument count.\n\
- popl %edx\n\
- # Adjust the stack pointer to skip _dl_skip_args words.\n\
- leal (%esp,%eax,4), %esp\n\
- # Subtract _dl_skip_args from argc.\n\
- subl %eax, %edx\n\
- # Push argc back on the stack.\n\
- push %edx\n\
+ # Read the original argument count.\n\
+ movl (%esp), %edx\n\
# The special initializer gets called with the stack just\n\
# as the application's entry point will see it; it can\n\
# switch stacks if it moves these contents over.\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 07/17] ia64: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (5 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 06/17] i686: Remove _dl_skip_args usage Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 08/17] m68k: " Adhemerval Zanella
` (10 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.
The startup code is changed to read the _dl_argc and _dl_argv values,
and envp is calculated from argc and argv.
Checked on ia64-linux-gnu.
---
sysdeps/ia64/dl-machine.h | 70 ++++++++-------------------------------
1 file changed, 14 insertions(+), 56 deletions(-)
diff --git a/sysdeps/ia64/dl-machine.h b/sysdeps/ia64/dl-machine.h
index 20e586aa35..704dbd1f8c 100644
--- a/sysdeps/ia64/dl-machine.h
+++ b/sysdeps/ia64/dl-machine.h
@@ -201,81 +201,39 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
" .save ar.pfs, r32\n" \
" .body\n" \
" { .mii\n" \
-" addl r3 = @gprel(_dl_skip_args), gp\n" \
-" adds r11 = 24, sp /* Load the address of argv. */\n" \
" /* Save the pointer to the user entry point fptr in loc2. */\n" \
" mov loc2 = ret0\n" \
+" addl r2 = @ltoff(_dl_argc), gp\n" \
" ;;\n" \
" }\n" \
" { .mii\n" \
-" ld4 r3 = [r3]\n" \
-" adds r10 = 16, sp /* Load the address of argc. */\n" \
-" mov out2 = r11\n" \
-" ;;\n" \
-" /* See if we were run as a command with the executable file\n" \
-" name as an extra leading argument. If so, adjust the argv\n" \
-" pointer to skip _dl_skip_args words.\n" \
-" Note that _dl_skip_args is an integer, not a long - Jes\n" \
-"\n" \
-" The stack pointer has to be 16 byte aligned. We cannot simply\n" \
-" addjust the stack pointer. We have to move the whole argv and\n" \
-" envp and adjust _dl_argv by _dl_skip_args. H.J. */\n" \
-" }\n" \
-" { .mib\n" \
-" ld8 out1 = [r10] /* is argc actually stored as a long\n" \
-" or as an int? */\n" \
-" addl r2 = @ltoff(_dl_argv), gp\n" \
+" ld8 out1 = [r2] /* Get the _dl_argc address. */\n" \
+" addl r3 = @ltoff(_dl_argv), gp\n" \
" ;;\n" \
" }\n" \
" { .mmi\n" \
-" ld8 r2 = [r2] /* Get the address of _dl_argv. */\n" \
-" sub out1 = out1, r3 /* Get the new argc. */\n" \
-" shladd r3 = r3, 3, r0\n" \
-" ;;\n" \
-" }\n" \
-" {\n" \
-" .mib\n" \
-" ld8 r17 = [r2] /* Get _dl_argv. */\n" \
-" add r15 = r11, r3 /* The address of the argv we move */\n" \
-" ;;\n" \
-" }\n" \
-" /* ??? Could probably merge these two loops into 3 bundles.\n" \
-" using predication to control which set of copies we're on. */\n" \
-"1: /* Copy argv. */\n" \
-" { .mfi\n" \
-" ld8 r16 = [r15], 8 /* Load the value in the old argv. */\n" \
+" ld8 out2 = [r3] /* Get the _dl_argv address. */\n" \
+" ld8 out1 = [out1] /* Get the adjusted _dl_argc. */\n" \
+" addl r2 = @gprel(_rtld_local), gp\n" \
" ;;\n" \
" }\n" \
-" { .mib\n" \
-" st8 [r11] = r16, 8 /* Store it in the new argv. */\n" \
-" cmp.ne p6, p7 = 0, r16\n" \
-"(p6) br.cond.dptk.few 1b\n" \
+" { .mmi\n" \
+" sxt4 out3 = out1 /* envp = argv + argc + 1 */\n" \
" ;;\n" \
" }\n" \
" { .mmi\n" \
-" mov out3 = r11\n" \
-" sub r17 = r17, r3 /* Substract _dl_skip_args. */\n" \
-" addl out0 = @gprel(_rtld_local), gp\n" \
-" }\n" \
-"1: /* Copy env. */\n" \
-" { .mfi\n" \
-" ld8 r16 = [r15], 8 /* Load the value in the old env. */\n" \
+" adds out3 = 1, out3\n" \
" ;;\n" \
" }\n" \
-" { .mib\n" \
-" st8 [r11] = r16, 8 /* Store it in the new env. */\n" \
-" cmp.ne p6, p7 = 0, r16\n" \
-"(p6) br.cond.dptk.few 1b\n" \
+" { .mmi\n" \
+" ld8 out2 = [out2] /* Get the adjusted _dl_argv. */\n" \
+" shladd out3 = out3, 3, r0\n" \
" ;;\n" \
" }\n" \
" { .mmb\n" \
-" st8 [r10] = out1 /* Record the new argc. */\n" \
-" ld8 out0 = [out0] /* get the linkmap */\n" \
-" }\n" \
-" { .mmb\n" \
-" st8 [r2] = r17 /* Load the new _dl_argv. */\n" \
+" add out3 = out3, out2\n" \
+" ld8 out0 = [r2] /* Get the linkmap. */\n" \
" br.call.sptk.many b0 = _dl_init#\n" \
-" ;;\n" \
" }\n" \
" /* Pass our finalizer function to the user,\n" \
" and jump to the user's entry point. */\n" \
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 08/17] m68k: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (6 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 07/17] ia64: " Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 17:18 ` Andreas Schwab
2022-05-26 16:49 ` [PATCH 09/17] microblaze: " Adhemerval Zanella
` (9 subsequent siblings)
17 siblings, 1 reply; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked with qemu-user that arguments are correctly passed on both
constructors and main program.
---
sysdeps/m68k/dl-machine.h | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/sysdeps/m68k/dl-machine.h b/sysdeps/m68k/dl-machine.h
index bb51b4198c..4204fa3df8 100644
--- a/sysdeps/m68k/dl-machine.h
+++ b/sysdeps/m68k/dl-machine.h
@@ -142,15 +142,10 @@ _start:\n\
_dl_start_user:\n\
| Save the user entry point address in %a4.\n\
move.l %d0, %a4\n\
- | See if we were run as a command with the executable file\n\
- | name as an extra leading argument.\n\
- " PCREL_OP ("move.l", "_dl_skip_args", "%d0", "%d0", "%pc") "\n\
| Pop the original argument count\n\
move.l (%sp)+, %d1\n\
- | Subtract _dl_skip_args from it.\n\
- sub.l %d0, %d1\n\
- | Adjust the stack pointer to skip _dl_skip_args words.\n\
- lea (%sp, %d0*4), %sp\n\
+ | Adjust the stack pointer to skip the loaders arguments.\n\
+ lea (%sp), %sp\n\
| Push back the modified argument count.\n\
move.l %d1, -(%sp)\n\
# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 09/17] microblaze: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (7 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 08/17] m68k: " Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 10/17] mips: " Adhemerval Zanella
` (8 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked with qemu-user that arguments are correctly passed on both
constructors and main program.
---
sysdeps/microblaze/dl-machine.h | 5 -----
1 file changed, 5 deletions(-)
diff --git a/sysdeps/microblaze/dl-machine.h b/sysdeps/microblaze/dl-machine.h
index fd996d6ff1..e6e4e13fa2 100644
--- a/sysdeps/microblaze/dl-machine.h
+++ b/sysdeps/microblaze/dl-machine.h
@@ -117,12 +117,7 @@ _start:\n\
_dl_start_user:\n\
mfs r20,rpc\n\
addik r20,r20,_GLOBAL_OFFSET_TABLE_+8\n\
- lwi r4,r20,_dl_skip_args@GOTOFF\n\
lwi r5,r1,24\n\
- rsubk r5,r4,r5\n\
- addk r4,r4,r4\n\
- addk r4,r4,r4\n\
- addk r1,r1,r4\n\
swi r5,r1,24\n\
swi r3,r1,20\n\
addk r6,r5,r0\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 10/17] mips: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (8 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 09/17] microblaze: " Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 11/17] nios2: Remove _dl_skip_args usage (BZ# 29187) Adhemerval Zanella
` (7 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked with qemu-user that arguments are correctly passed on both
constructors and main program.
---
sysdeps/mips/dl-machine.h | 31 ++-----------------------------
1 file changed, 2 insertions(+), 29 deletions(-)
diff --git a/sysdeps/mips/dl-machine.h b/sysdeps/mips/dl-machine.h
index 9105b5b75c..b68066d430 100644
--- a/sysdeps/mips/dl-machine.h
+++ b/sysdeps/mips/dl-machine.h
@@ -278,20 +278,7 @@ do { \
move $16, $28\n\
# Save the user entry point address in a saved register.\n\
move $17, $2\n\
- # See if we were run as a command with the executable file\n\
- # name as an extra leading argument.\n\
- lw $2, _dl_skip_args\n\
- beq $2, $0, 1f\n\
- # Load the original argument count.\n\
- " STRINGXP(PTR_L) " $4, 0($29)\n\
- # Subtract _dl_skip_args from it.\n\
- subu $4, $2\n\
- # Adjust the stack pointer to skip _dl_skip_args words.\n\
- sll $2, " STRINGXP (PTRLOG) "\n\
- " STRINGXP(PTR_ADDU) " $29, $2\n\
- # Save back the modified argument count.\n\
- " STRINGXP(PTR_S) " $4, 0($29)\n\
-1: # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
+ # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
" STRINGXP(PTR_L) " $4, _rtld_local\n\
" STRINGXP(PTR_L) /* or lw??? fixme */ " $5, 0($29)\n\
" STRINGXP(PTR_LA) " $6, " STRINGXP (PTRSIZE) "($29)\n\
@@ -352,21 +339,7 @@ do { \
addu $16, $4\n\
move $17, $2\n\
move $28, $16\n\
- lw $4, %got(_dl_skip_args)($16)\n\
- lw $4, 0($4)\n\
- beqz $4, 1f\n\
- # Load the original argument count.\n\
- lw $5, 0($sp)\n\
- # Subtract _dl_skip_args from it.\n\
- subu $5, $4\n\
- # Adjust the stack pointer to skip _dl_skip_args words.\n\
- sll $4, " STRINGXP (PTRLOG) "\n\
- move $6, $sp\n\
- addu $6, $4\n\
- move $sp, $6\n\
- # Save back the modified argument count.\n\
- sw $5, 0($sp)\n\
-1: # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
+ # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
lw $4, %got(_rtld_local)($16)\n\
lw $4, 0($4)\n\
lw $5, 0($sp)\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 11/17] nios2: Remove _dl_skip_args usage (BZ# 29187)
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (9 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 10/17] mips: " Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 12/17] riscv: Remove _dl_skip_args usage Adhemerval Zanella
` (6 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked with qemu-user that arguments are correctly passed on both
constructors and main program.
---
sysdeps/nios2/dl-machine.h | 50 ++++++++------------------------------
1 file changed, 10 insertions(+), 40 deletions(-)
diff --git a/sysdeps/nios2/dl-machine.h b/sysdeps/nios2/dl-machine.h
index 80de6fd041..9a35cf4160 100644
--- a/sysdeps/nios2/dl-machine.h
+++ b/sysdeps/nios2/dl-machine.h
@@ -128,53 +128,23 @@ _start:\n\
ldw r8, %call(_dl_nios2_get_gp_value)(r22)\n\
callr r8\n\
mov gp, r2\n\
-\n\
- /* Find the number of arguments to skip. */\n\
- ldw r8, %got(_dl_skip_args)(r22)\n\
- ldw r8, 0(r8)\n\
\n\
/* Find the main_map from the GOT. */\n\
ldw r4, %got(_rtld_local)(r22)\n\
ldw r4, 0(r4)\n\
\n\
- /* Find argc. */\n\
- ldw r5, 0(sp)\n\
- sub r5, r5, r8\n\
- stw r5, 0(sp)\n\
-\n\
- /* Find the first unskipped argument. */\n\
- slli r8, r8, 2\n\
- addi r6, sp, 4\n\
- add r9, r6, r8\n\
- mov r10, r6\n\
-\n\
- /* Shuffle argv down. */\n\
-3: ldw r11, 0(r9)\n\
- stw r11, 0(r10)\n\
- addi r9, r9, 4\n\
- addi r10, r10, 4\n\
- bne r11, zero, 3b\n\
+ /* Load adjusted argc. */\n\
+ ldw r2, %got(_dl_argc)(r22)\n\
+ ldw r5, 0(r2)\n\
\n\
- /* Shuffle envp down. */\n\
- mov r7, r10\n\
-4: ldw r11, 0(r9)\n\
- stw r11, 0(r10)\n\
- addi r9, r9, 4\n\
- addi r10, r10, 4\n\
- bne r11, zero, 4b\n\
-\n\
- /* Shuffle auxv down. */\n\
-5: ldw r11, 4(r9)\n\
- stw r11, 4(r10)\n\
- ldw r11, 0(r9)\n\
- stw r11, 0(r10)\n\
- addi r9, r9, 8\n\
- addi r10, r10, 8\n\
- bne r11, zero, 5b\n\
-\n\
- /* Update _dl_argv. */\n\
+ /* Load adjsuted argv. */\n\
ldw r2, %got(_dl_argv)(r22)\n\
- stw r6, 0(r2)\n\
+ ldw r6, 0(r2)\n\
+\n\
+ /* envp = argv + argc + 1 */\n\
+ addi r7, r5, 1\n\
+ slli r7, r7, 2\n\
+ add r7, r7, r6\n\
\n\
/* Call _dl_init through the PLT. */\n\
ldw r8, %call(_dl_init)(r22)\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 12/17] riscv: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (10 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 11/17] nios2: Remove _dl_skip_args usage (BZ# 29187) Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 13/17] s390: " Adhemerval Zanella
` (5 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked with qemu-user that arguments are correctly passed on both
constructors and main program.
---
sysdeps/riscv/dl-machine.h | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
index 4912735c2b..ba02f17431 100644
--- a/sysdeps/riscv/dl-machine.h
+++ b/sysdeps/riscv/dl-machine.h
@@ -107,18 +107,6 @@ elf_machine_dynamic (void)
" _RTLD_PROLOGUE (_dl_start_user) "\
# Stash user entry point in s0.\n\
mv s0, a0\n\
- # See if we were run as a command with the executable file\n\
- # name as an extra leading argument.\n\
- lw a0, _dl_skip_args\n\
- # Load the original argument count.\n\
- " STRINGXP (REG_L) " a1, 0(sp)\n\
- # Subtract _dl_skip_args from it.\n\
- sub a1, a1, a0\n\
- # Adjust the stack pointer to skip _dl_skip_args words.\n\
- sll a0, a0, " STRINGXP (PTRLOG) "\n\
- add sp, sp, a0\n\
- # Save back the modified argument count.\n\
- " STRINGXP (REG_S) " a1, 0(sp)\n\
# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
" STRINGXP (REG_L) " a0, _rtld_local\n\
add a2, sp, " STRINGXP (SZREG) "\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 13/17] s390: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (11 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 12/17] riscv: Remove _dl_skip_args usage Adhemerval Zanella
@ 2022-05-26 16:49 ` Adhemerval Zanella
2022-05-26 16:50 ` [PATCH 14/17] sh: " Adhemerval Zanella
` (4 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:49 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked on s390x-linux-gnu and s390-linux-gnu.
---
sysdeps/s390/s390-32/dl-machine.h | 46 -------------------------------
sysdeps/s390/s390-64/dl-machine.h | 16 -----------
2 files changed, 62 deletions(-)
diff --git a/sysdeps/s390/s390-32/dl-machine.h b/sysdeps/s390/s390-32/dl-machine.h
index 4392abb355..b69787b0ad 100644
--- a/sysdeps/s390/s390-32/dl-machine.h
+++ b/sysdeps/s390/s390-32/dl-machine.h
@@ -186,52 +186,6 @@ _dl_start_user:\n\
# Point %r12 at the GOT.\n\
l %r12,.Ladr0-.Llit(%r13)\n\
ar %r12,%r13\n\
- # See if we were run as a command with the executable file\n\
- # name as an extra leading argument.\n\
- l %r1,_dl_skip_args@GOT(%r12)\n\
- l %r1,0(%r1) # load _dl_skip_args\n\
- ltr %r1,%r1\n\
- je 4f # Skip the arg adjustment if there were none.\n\
- # Get the original argument count.\n\
- l %r0,96(%r15)\n\
- # Subtract _dl_skip_args from it.\n\
- sr %r0,%r1\n\
- # Store back the modified argument count.\n\
- st %r0,96(%r15)\n\
- # Copy argv and envp forward to account for skipped argv entries.\n\
- # We skipped at least one argument or we would not get here.\n\
- la %r6,100(%r15) # Destination pointer i.e. &argv[0]\n\
- lr %r5,%r6\n\
- lr %r0,%r1\n\
- sll %r0,2\n # Number of skipped bytes.\n\
- ar %r5,%r0 # Source pointer = Dest + Skipped args.\n\
- # argv copy loop:\n\
-1: l %r7,0(%r5) # Load a word from the source.\n\
- st %r7,0(%r6) # Store the word in the destination.\n\
- ahi %r5,4\n\
- ahi %r6,4\n\
- ltr %r7,%r7\n\
- jne 1b # Stop after copying the NULL.\n\
- # envp copy loop:\n\
-2: l %r7,0(%r5) # Load a word from the source.\n\
- st %r7,0(%r6) # Store the word in the destination.\n\
- ahi %r5,4\n\
- ahi %r6,4\n\
- ltr %r7,%r7\n\
- jne 2b # Stop after copying the NULL.\n\
- # Now we have to zero out the envp entries after NULL to allow\n\
- # start.S to properly find auxv by skipping zeroes.\n\
- # zero out loop:\n\
- lhi %r7,0\n\
-3: st %r7,0(%r6) # Store zero.\n\
- ahi %r6,4 # Advance dest pointer.\n\
- ahi %r1,-1 # Subtract one from the word count.\n\
- ltr %r1,%r1\n\
- jne 3b # Keep copying if the word count is non-zero.\n\
- # Adjust _dl_argv\n\
- la %r6,100(%r15)\n\
- l %r1,_dl_argv@GOT(%r12)\n\
- st %r6,0(%r1)\n\
# The special initializer gets called with the stack just\n\
# as the application's entry point will see it; it can\n\
# switch stacks if it moves these contents over.\n\
diff --git a/sysdeps/s390/s390-64/dl-machine.h b/sysdeps/s390/s390-64/dl-machine.h
index 7a94b3a7a6..74be0552dc 100644
--- a/sysdeps/s390/s390-64/dl-machine.h
+++ b/sysdeps/s390/s390-64/dl-machine.h
@@ -167,22 +167,6 @@ _dl_start_user:\n\
lgr %r8,%r2\n\
# Point %r12 at the GOT.\n\
larl %r12,_GLOBAL_OFFSET_TABLE_\n\
- # See if we were run as a command with the executable file\n\
- # name as an extra leading argument.\n\
- lghi %r1,_dl_skip_args@GOT\n\
- lg %r1,0(%r1,%r12)\n\
- lgf %r1,0(%r1) # load _dl_skip_args\n\
- # Get the original argument count.\n\
- lg %r0,160(%r15)\n\
- # Subtract _dl_skip_args from it.\n\
- sgr %r0,%r1\n\
- # Adjust the stack pointer to skip _dl_skip_args words.\n\
- sllg %r1,%r1,3\n\
- agr %r15,%r1\n\
- # Set the back chain to zero again\n\
- xc 0(8,%r15),0(%r15)\n\
- # Store back the modified argument count.\n\
- stg %r0,160(%r15)\n\
# The special initializer gets called with the stack just\n\
# as the application's entry point will see it; it can\n\
# switch stacks if it moves these contents over.\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 14/17] sh: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (12 preceding siblings ...)
2022-05-26 16:49 ` [PATCH 13/17] s390: " Adhemerval Zanella
@ 2022-05-26 16:50 ` Adhemerval Zanella
2022-05-26 16:50 ` [PATCH 15/17] sparc: " Adhemerval Zanella
` (3 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:50 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked with qemu-user that arguments are correctly passed on both
constructors and main program.
---
sysdeps/sh/dl-machine.h | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h
index 8b08a1fc47..99eb239408 100644
--- a/sysdeps/sh/dl-machine.h
+++ b/sysdeps/sh/dl-machine.h
@@ -149,20 +149,8 @@ _dl_start_user:\n\
add r0,r12\n\
.align 2\n\
1: .long _GLOBAL_OFFSET_TABLE_\n\
-2: ! See if we were run as a command with the executable file\n\
- ! name as an extra leading argument.\n\
- mov.l .L_dl_skip_args,r0\n\
- mov.l @(r0,r12),r0\n\
- mov.l @r0,r0\n\
- ! Get the original argument count.\n\
+2: ! Get the original argument count.\n\
mov.l @r15,r5\n\
- ! Subtract _dl_skip_args from it.\n\
- sub r0,r5\n\
- ! Adjust the stack pointer to skip _dl_skip_args words.\n\
- shll2 r0\n\
- add r0,r15\n\
- ! Store back the modified argument count.\n\
- mov.l r5,@r15\n\
! Compute argv address and envp.\n\
mov r15,r6\n\
add #4,r6\n\
@@ -188,8 +176,6 @@ _dl_start_user:\n\
.align 2\n\
.L_dl_start:\n\
.long _dl_start@PLT\n\
-.L_dl_skip_args:\n\
- .long _dl_skip_args@GOT\n\
.L_dl_init:\n\
.long _dl_init@PLT\n\
.L_dl_loaded:\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 15/17] sparc: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (13 preceding siblings ...)
2022-05-26 16:50 ` [PATCH 14/17] sh: " Adhemerval Zanella
@ 2022-05-26 16:50 ` Adhemerval Zanella
2022-05-26 16:50 ` [PATCH 16/17] x86_64: " Adhemerval Zanella
` (2 subsequent siblings)
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:50 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked on sparc64-linux-gnu and sparcv9-linux-gnu.
---
sysdeps/sparc/sparc32/dl-machine.h | 43 ++----------------------------
sysdeps/sparc/sparc64/dl-machine.h | 40 ++-------------------------
2 files changed, 4 insertions(+), 79 deletions(-)
diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h
index 8c2408b1e6..8baf45be52 100644
--- a/sysdeps/sparc/sparc32/dl-machine.h
+++ b/sysdeps/sparc/sparc32/dl-machine.h
@@ -196,48 +196,9 @@ _dl_start_user:\n\
add %l7, %o7, %l7\n\
/* Save the user entry point address in %l0 */\n\
mov %o0, %l0\n\
- /* See if we were run as a command with the executable file name as an\n\
- extra leading argument. If so, adjust the contents of the stack. */\n\
- " RTLD_GOT_ADDRESS(%l7, %g2, _dl_skip_args) "\n\
- ld [%g2], %i0\n\
- tst %i0\n\
- beq 3f\n\
- ld [%sp+22*4], %i5 /* load argc */\n\
- /* Find out how far to shift. */\n\
- " RTLD_GOT_ADDRESS(%l7, %l3, _dl_argv) "\n\
- sub %i5, %i0, %i5\n\
- ld [%l3], %l4\n\
- sll %i0, 2, %i2\n\
- st %i5, [%sp+22*4]\n\
- sub %l4, %i2, %l4\n\
- add %sp, 23*4, %i1\n\
- add %i1, %i2, %i2\n\
- st %l4, [%l3]\n\
- /* Copy down argv */\n\
-21: ld [%i2], %i3\n\
- add %i2, 4, %i2\n\
- tst %i3\n\
- st %i3, [%i1]\n\
- bne 21b\n\
- add %i1, 4, %i1\n\
- /* Copy down env */\n\
-22: ld [%i2], %i3\n\
- add %i2, 4, %i2\n\
- tst %i3\n\
- st %i3, [%i1]\n\
- bne 22b\n\
- add %i1, 4, %i1\n\
- /* Copy down auxiliary table. */\n\
-23: ld [%i2], %i3\n\
- ld [%i2+4], %i4\n\
- add %i2, 8, %i2\n\
- tst %i3\n\
- st %i3, [%i1]\n\
- st %i4, [%i1+4]\n\
- bne 23b\n\
- add %i1, 8, %i1\n\
+ ld [%sp+22*4], %i5 /* load argc */\n\
/* %o0 = _dl_loaded, %o1 = argc, %o2 = argv, %o3 = envp. */\n\
-3: " RTLD_GOT_ADDRESS(%l7, %o0, _rtld_local) "\n\
+ " RTLD_GOT_ADDRESS(%l7, %o0, _rtld_local) "\n\
add %sp, 23*4, %o2\n\
sll %i5, 2, %o3\n\
add %o3, 4, %o3\n\
diff --git a/sysdeps/sparc/sparc64/dl-machine.h b/sysdeps/sparc/sparc64/dl-machine.h
index 8c4bab14fc..d34d9aa470 100644
--- a/sysdeps/sparc/sparc64/dl-machine.h
+++ b/sysdeps/sparc/sparc64/dl-machine.h
@@ -245,45 +245,9 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
" add %l7, %o7, %l7\n" \
" /* Save the user entry point address in %l0. */\n" \
" mov %o0, %l0\n" \
-" /* See if we were run as a command with the executable file name as an\n" \
-" extra leading argument. If so, we must shift things around since we\n" \
-" must keep the stack doubleword aligned. */\n" \
- RTLD_GOT_ADDRESS(%l7, %g5, _dl_skip_args) \
-" ld [%g5], %i0\n" \
-" brz,pt %i0, 2f\n" \
-" ldx [%sp + " __S(STACK_BIAS) " + 22*8], %i5\n" \
-" /* Find out how far to shift. */\n" \
-" sub %i5, %i0, %i5\n" \
-" sllx %i0, 3, %l6\n" \
- RTLD_GOT_ADDRESS(%l7, %l4, _dl_argv) \
-" stx %i5, [%sp + " __S(STACK_BIAS) " + 22*8]\n" \
-" add %sp, " __S(STACK_BIAS) " + 23*8, %i1\n" \
-" add %i1, %l6, %i2\n" \
-" ldx [%l4], %l5\n" \
-" /* Copy down argv. */\n" \
-"12: ldx [%i2], %i3\n" \
-" add %i2, 8, %i2\n" \
-" stx %i3, [%i1]\n" \
-" brnz,pt %i3, 12b\n" \
-" add %i1, 8, %i1\n" \
-" sub %l5, %l6, %l5\n" \
-" /* Copy down envp. */\n" \
-"13: ldx [%i2], %i3\n" \
-" add %i2, 8, %i2\n" \
-" stx %i3, [%i1]\n" \
-" brnz,pt %i3, 13b\n" \
-" add %i1, 8, %i1\n" \
-" /* Copy down auxiliary table. */\n" \
-"14: ldx [%i2], %i3\n" \
-" ldx [%i2 + 8], %i4\n" \
-" add %i2, 16, %i2\n" \
-" stx %i3, [%i1]\n" \
-" stx %i4, [%i1 + 8]\n" \
-" brnz,pt %i3, 14b\n" \
-" add %i1, 16, %i1\n" \
-" stx %l5, [%l4]\n" \
+" ldx [%sp + " __S(STACK_BIAS) " + 22*8], %i5\n" \
" /* %o0 = _dl_loaded, %o1 = argc, %o2 = argv, %o3 = envp. */\n" \
-"2:\t" RTLD_GOT_ADDRESS(%l7, %o0, _rtld_local) \
+"" RTLD_GOT_ADDRESS(%l7, %o0, _rtld_local) \
" sllx %i5, 3, %o3\n" \
" add %sp, " __S(STACK_BIAS) " + 23*8, %o2\n" \
" add %o3, 8, %o3\n" \
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 16/17] x86_64: Remove _dl_skip_args usage
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (14 preceding siblings ...)
2022-05-26 16:50 ` [PATCH 15/17] sparc: " Adhemerval Zanella
@ 2022-05-26 16:50 ` Adhemerval Zanella
2022-05-26 20:52 ` H.J. Lu
2022-05-26 16:50 ` [PATCH 17/17] elf: Remove _dl_skip_args Adhemerval Zanella
2022-05-30 13:32 ` [PATCH 00/17] " Carlos O'Donell
17 siblings, 1 reply; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:50 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0. So there is no need to adjust the argc or argv.
Checked on x86_64-linux-gnu and i686-linux-gnu.
---
sysdeps/x86_64/dl-machine.h | 13 ++-----------
sysdeps/x86_64/x32/dl-machine.h | 12 +-----------
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
index c70af7ab1e..e33ca2cc1a 100644
--- a/sysdeps/x86_64/dl-machine.h
+++ b/sysdeps/x86_64/dl-machine.h
@@ -140,17 +140,8 @@ _start:\n\
_dl_start_user:\n\
# Save the user entry point address in %r12.\n\
movq %rax, %r12\n\
- # See if we were run as a command with the executable file\n\
- # name as an extra leading argument.\n\
- movl _dl_skip_args(%rip), %eax\n\
- # Pop the original argument count.\n\
- popq %rdx\n\
- # Adjust the stack pointer to skip _dl_skip_args words.\n\
- leaq (%rsp,%rax,8), %rsp\n\
- # Subtract _dl_skip_args from argc.\n\
- subl %eax, %edx\n\
- # Push argc back on the stack.\n\
- pushq %rdx\n\
+ # Read the original argument count.\n\
+ movq (%rsp), %rdx\n\
# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\
# argc -> rsi\n\
movq %rdx, %rsi\n\
diff --git a/sysdeps/x86_64/x32/dl-machine.h b/sysdeps/x86_64/x32/dl-machine.h
index 331374069e..681016c8d8 100644
--- a/sysdeps/x86_64/x32/dl-machine.h
+++ b/sysdeps/x86_64/x32/dl-machine.h
@@ -45,18 +45,8 @@ _start:\n\
_dl_start_user:\n\
# Save the user entry point address in %r12.\n\
movl %eax, %r12d\n\
- # See if we were run as a command with the executable file\n\
- # name as an extra leading argument.\n\
- movl _dl_skip_args(%rip), %eax\n\
- # Pop the original argument count.\n\
+ # Read the original argument count.\n\
movl (%rsp), %edx\n\
- # Adjust the stack pointer to skip _dl_skip_args words.\n\
- lea 4(%rsp,%rax,4), %esp\n\
- # Subtract _dl_skip_args from argc.\n\
- subl %eax, %edx\n\
- # Push argc back on the stack.\n\
- subl $4, %esp\n\
- movl %edx, (%rsp)\n\
# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\
# argc -> rsi\n\
movl %edx, %esi\n\
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 17/17] elf: Remove _dl_skip_args
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (15 preceding siblings ...)
2022-05-26 16:50 ` [PATCH 16/17] x86_64: " Adhemerval Zanella
@ 2022-05-26 16:50 ` Adhemerval Zanella
2022-05-30 13:32 ` [PATCH 00/17] " Carlos O'Donell
17 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 16:50 UTC (permalink / raw)
To: libc-alpha, Szabolcs Nagy
Now that no architecture uses it anymore.
---
elf/rtld.c | 2 --
sysdeps/generic/ldsodefs.h | 4 ----
sysdeps/mach/hurd/dl-sysdep.c | 1 -
3 files changed, 7 deletions(-)
diff --git a/elf/rtld.c b/elf/rtld.c
index 069940d73f..f5a3d1968f 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -158,8 +158,6 @@ static void process_envvars (struct dl_main_state *state);
int _dl_argc attribute_relro attribute_hidden;
char **_dl_argv attribute_relro = NULL;
-/* Always 0, only kept for not-yet-updated target start code. */
-const unsigned int _dl_skip_args attribute_hidden;
rtld_hidden_data_def (_dl_argv)
#ifndef THREAD_SET_STACK_GUARD
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 6716e1f382..446d12a68c 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -755,10 +755,6 @@ rtld_hidden_proto (__libc_stack_end)
extern int _dl_argc attribute_hidden attribute_relro;
extern char **_dl_argv attribute_relro;
rtld_hidden_proto (_dl_argv)
-#if IS_IN (rtld)
-/* Always 0, only kept for not-yet-updated target start code. */
-extern const unsigned int _dl_skip_args attribute_hidden;
-#endif
#define rtld_progname _dl_argv[0]
/* Flag set at startup and cleared when the last initializer has run. */
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 8373962e62..f23fdee058 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -139,7 +139,6 @@ _dl_sysdep_start (void **start_argptr,
mach_port_t memobj;
error_t err;
- ++_dl_skip_args;
--_dl_argc;
p = _dl_argv++[1] + 1;
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 08/17] m68k: Remove _dl_skip_args usage
2022-05-26 16:49 ` [PATCH 08/17] m68k: " Adhemerval Zanella
@ 2022-05-26 17:18 ` Andreas Schwab
2022-05-26 17:23 ` Adhemerval Zanella
0 siblings, 1 reply; 30+ messages in thread
From: Andreas Schwab @ 2022-05-26 17:18 UTC (permalink / raw)
To: Adhemerval Zanella via Libc-alpha; +Cc: Szabolcs Nagy, Adhemerval Zanella
On Mai 26 2022, Adhemerval Zanella via Libc-alpha wrote:
> + lea (%sp), %sp\n\
That's a no-op.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 08/17] m68k: Remove _dl_skip_args usage
2022-05-26 17:18 ` Andreas Schwab
@ 2022-05-26 17:23 ` Adhemerval Zanella
0 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 17:23 UTC (permalink / raw)
To: Andreas Schwab, Adhemerval Zanella via Libc-alpha; +Cc: Szabolcs Nagy
On 26/05/2022 14:18, Andreas Schwab wrote:
> On Mai 26 2022, Adhemerval Zanella via Libc-alpha wrote:
>
>> + lea (%sp), %sp\n\
>
> That's a no-op.
>
Thansk, I will remove it.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165)
2022-05-26 16:49 ` [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165) Adhemerval Zanella
@ 2022-05-26 18:14 ` Florian Weimer
2022-05-26 18:23 ` Adhemerval Zanella
0 siblings, 1 reply; 30+ messages in thread
From: Florian Weimer @ 2022-05-26 18:14 UTC (permalink / raw)
To: Adhemerval Zanella via Libc-alpha
Cc: Szabolcs Nagy, Adhemerval Zanella, danglin
* Adhemerval Zanella via Libc-alpha:
> Different than other architectures, hppa creates an unrelated stack
> frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
> is not done on the argc/argv saved/restore by _dl_start_user.
>
> Instead load _dl_argc and _dl_argv directlty instead of adjust them
> using _dl_skip_args value.
>
> Checked on hppa-linux-gnu.
Does this fix bug 29165? If yes, it should say so on the commit
message.
Thanks,
Florian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165)
2022-05-26 18:14 ` Florian Weimer
@ 2022-05-26 18:23 ` Adhemerval Zanella
2022-05-26 18:34 ` Florian Weimer
2022-05-26 18:58 ` John David Anglin
0 siblings, 2 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 18:23 UTC (permalink / raw)
To: Florian Weimer, Adhemerval Zanella via Libc-alpha; +Cc: Szabolcs Nagy, danglin
On 26/05/2022 15:14, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
>
>> Different than other architectures, hppa creates an unrelated stack
>> frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
>> is not done on the argc/argv saved/restore by _dl_start_user.
>>
>> Instead load _dl_argc and _dl_argv directlty instead of adjust them
>> using _dl_skip_args value.
>>
>> Checked on hppa-linux-gnu.
>
> Does this fix bug 29165? If yes, it should say so on the commit
> message.
It does, I assumed the title was suffice. I will add a note in the
commit itself.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165)
2022-05-26 18:23 ` Adhemerval Zanella
@ 2022-05-26 18:34 ` Florian Weimer
2022-05-26 18:58 ` John David Anglin
1 sibling, 0 replies; 30+ messages in thread
From: Florian Weimer @ 2022-05-26 18:34 UTC (permalink / raw)
To: Adhemerval Zanella
Cc: Adhemerval Zanella via Libc-alpha, Szabolcs Nagy, danglin
* Adhemerval Zanella:
> On 26/05/2022 15:14, Florian Weimer wrote:
>> * Adhemerval Zanella via Libc-alpha:
>>
>>> Different than other architectures, hppa creates an unrelated stack
>>> frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
>>> is not done on the argc/argv saved/restore by _dl_start_user.
>>>
>>> Instead load _dl_argc and _dl_argv directlty instead of adjust them
>>> using _dl_skip_args value.
>>>
>>> Checked on hppa-linux-gnu.
>>
>> Does this fix bug 29165? If yes, it should say so on the commit
>> message.
>
> It does, I assumed the title was suffice. I will add a note in the
> commit itself.
Sorry, I missed that. 8-( Commit subject is sufficient.
Thanks for fixing it.
Florian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165)
2022-05-26 18:23 ` Adhemerval Zanella
2022-05-26 18:34 ` Florian Weimer
@ 2022-05-26 18:58 ` John David Anglin
2022-05-26 23:10 ` Adhemerval Zanella
1 sibling, 1 reply; 30+ messages in thread
From: John David Anglin @ 2022-05-26 18:58 UTC (permalink / raw)
To: Adhemerval Zanella, Florian Weimer, Adhemerval Zanella via Libc-alpha
Cc: Szabolcs Nagy, danglin
On 2022-05-26 2:23 p.m., Adhemerval Zanella wrote:
>
> On 26/05/2022 15:14, Florian Weimer wrote:
>> * Adhemerval Zanella via Libc-alpha:
>>
>>> Different than other architectures, hppa creates an unrelated stack
>>> frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
>>> is not done on the argc/argv saved/restore by _dl_start_user.
>>>
>>> Instead load _dl_argc and _dl_argv directlty instead of adjust them
>>> using _dl_skip_args value.
>>>
>>> Checked on hppa-linux-gnu.
>> Does this fix bug 29165? If yes, it should say so on the commit
>> message.
> It does, I assumed the title was suffice. I will add a note in the
> commit itself.
This comment could be improved:
> + It also mean that to get the correct argc and argv if the \
> + program is ld.so it requires to read _dl_argc and _dl_argv. */\
"mean" should be "means" and the wording is somewhat stilted.
--
John David Anglin dave.anglin@bell.net
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 16/17] x86_64: Remove _dl_skip_args usage
2022-05-26 16:50 ` [PATCH 16/17] x86_64: " Adhemerval Zanella
@ 2022-05-26 20:52 ` H.J. Lu
0 siblings, 0 replies; 30+ messages in thread
From: H.J. Lu @ 2022-05-26 20:52 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: GNU C Library, Szabolcs Nagy
On Thu, May 26, 2022 at 10:02 AM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Since ad43cac44a the generic code already shuffles the argv/envp/auxv
> on the stack to remove the ld.so own arguments and thus _dl_skip_args
> is always 0. So there is no need to adjust the argc or argv.
>
> Checked on x86_64-linux-gnu and i686-linux-gnu.
> ---
> sysdeps/x86_64/dl-machine.h | 13 ++-----------
> sysdeps/x86_64/x32/dl-machine.h | 12 +-----------
> 2 files changed, 3 insertions(+), 22 deletions(-)
>
> diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
> index c70af7ab1e..e33ca2cc1a 100644
> --- a/sysdeps/x86_64/dl-machine.h
> +++ b/sysdeps/x86_64/dl-machine.h
> @@ -140,17 +140,8 @@ _start:\n\
> _dl_start_user:\n\
> # Save the user entry point address in %r12.\n\
> movq %rax, %r12\n\
> - # See if we were run as a command with the executable file\n\
> - # name as an extra leading argument.\n\
> - movl _dl_skip_args(%rip), %eax\n\
> - # Pop the original argument count.\n\
> - popq %rdx\n\
> - # Adjust the stack pointer to skip _dl_skip_args words.\n\
> - leaq (%rsp,%rax,8), %rsp\n\
> - # Subtract _dl_skip_args from argc.\n\
> - subl %eax, %edx\n\
> - # Push argc back on the stack.\n\
> - pushq %rdx\n\
> + # Read the original argument count.\n\
> + movq (%rsp), %rdx\n\
> # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\
> # argc -> rsi\n\
> movq %rdx, %rsi\n\
> diff --git a/sysdeps/x86_64/x32/dl-machine.h b/sysdeps/x86_64/x32/dl-machine.h
> index 331374069e..681016c8d8 100644
> --- a/sysdeps/x86_64/x32/dl-machine.h
> +++ b/sysdeps/x86_64/x32/dl-machine.h
> @@ -45,18 +45,8 @@ _start:\n\
> _dl_start_user:\n\
> # Save the user entry point address in %r12.\n\
> movl %eax, %r12d\n\
> - # See if we were run as a command with the executable file\n\
> - # name as an extra leading argument.\n\
> - movl _dl_skip_args(%rip), %eax\n\
> - # Pop the original argument count.\n\
> + # Read the original argument count.\n\
> movl (%rsp), %edx\n\
> - # Adjust the stack pointer to skip _dl_skip_args words.\n\
> - lea 4(%rsp,%rax,4), %esp\n\
> - # Subtract _dl_skip_args from argc.\n\
> - subl %eax, %edx\n\
> - # Push argc back on the stack.\n\
> - subl $4, %esp\n\
> - movl %edx, (%rsp)\n\
> # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\
> # argc -> rsi\n\
> movl %edx, %esi\n\
> --
> 2.34.1
>
LGTM.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Thanks.
--
H.J.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 06/17] i686: Remove _dl_skip_args usage
2022-05-26 16:49 ` [PATCH 06/17] i686: Remove _dl_skip_args usage Adhemerval Zanella
@ 2022-05-26 20:53 ` H.J. Lu
0 siblings, 0 replies; 30+ messages in thread
From: H.J. Lu @ 2022-05-26 20:53 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: GNU C Library, Szabolcs Nagy
On Thu, May 26, 2022 at 9:54 AM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Since ad43cac44a the generic code already shuffles the argv/envp/auxv
> on the stack to remove the ld.so own arguments and thus _dl_skip_args
> is always 0. So there is no need to adjust the argc or argv.
>
> Checked on i686-linux-gnu.
> ---
> sysdeps/i386/dl-machine.h | 13 ++-----------
> 1 file changed, 2 insertions(+), 11 deletions(-)
>
> diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
> index 1f8d734215..8779983c8c 100644
> --- a/sysdeps/i386/dl-machine.h
> +++ b/sysdeps/i386/dl-machine.h
> @@ -143,17 +143,8 @@ _dl_start_user:\n\
> # Point %ebx at the GOT.\n\
> call 0b\n\
> addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
> - # See if we were run as a command with the executable file\n\
> - # name as an extra leading argument.\n\
> - movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
> - # Pop the original argument count.\n\
> - popl %edx\n\
> - # Adjust the stack pointer to skip _dl_skip_args words.\n\
> - leal (%esp,%eax,4), %esp\n\
> - # Subtract _dl_skip_args from argc.\n\
> - subl %eax, %edx\n\
> - # Push argc back on the stack.\n\
> - push %edx\n\
> + # Read the original argument count.\n\
> + movl (%esp), %edx\n\
> # The special initializer gets called with the stack just\n\
> # as the application's entry point will see it; it can\n\
> # switch stacks if it moves these contents over.\n\
> --
> 2.34.1
>
LGTM.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Thanks.
--
H.J.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165)
2022-05-26 18:58 ` John David Anglin
@ 2022-05-26 23:10 ` Adhemerval Zanella
2022-05-27 0:01 ` John David Anglin
0 siblings, 1 reply; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-26 23:10 UTC (permalink / raw)
To: John David Anglin, Florian Weimer, Adhemerval Zanella via Libc-alpha
Cc: Szabolcs Nagy, danglin
On 26/05/2022 15:58, John David Anglin wrote:
> On 2022-05-26 2:23 p.m., Adhemerval Zanella wrote:
>>
>> On 26/05/2022 15:14, Florian Weimer wrote:
>>> * Adhemerval Zanella via Libc-alpha:
>>>
>>>> Different than other architectures, hppa creates an unrelated stack
>>>> frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
>>>> is not done on the argc/argv saved/restore by _dl_start_user.
>>>>
>>>> Instead load _dl_argc and _dl_argv directlty instead of adjust them
>>>> using _dl_skip_args value.
>>>>
>>>> Checked on hppa-linux-gnu.
>>> Does this fix bug 29165? If yes, it should say so on the commit
>>> message.
>> It does, I assumed the title was suffice. I will add a note in the
>> commit itself.
> This comment could be improved:
>
>> + It also mean that to get the correct argc and argv if the \
>> + program is ld.so it requires to read _dl_argc and _dl_argv. */\
>
> "mean" should be "means" and the wording is somewhat stilted.
>
Indeed it sounds strange, I have changed to:
Also, the loader will adjust argc, argv, env, and aux vectors \
directly on the stack to remove any arguments used for direct \
loader invocation. So it requires to use _dl_argc and \
_dl_argv instead of reload them from previous saved area. */ \
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165)
2022-05-26 23:10 ` Adhemerval Zanella
@ 2022-05-27 0:01 ` John David Anglin
2022-05-27 12:23 ` Adhemerval Zanella
0 siblings, 1 reply; 30+ messages in thread
From: John David Anglin @ 2022-05-27 0:01 UTC (permalink / raw)
To: Adhemerval Zanella, Florian Weimer, Adhemerval Zanella via Libc-alpha
Cc: Szabolcs Nagy, danglin
On 2022-05-26 7:10 p.m., Adhemerval Zanella wrote:
>
> On 26/05/2022 15:58, John David Anglin wrote:
>> On 2022-05-26 2:23 p.m., Adhemerval Zanella wrote:
>>> On 26/05/2022 15:14, Florian Weimer wrote:
>>>> * Adhemerval Zanella via Libc-alpha:
>>>>
>>>>> Different than other architectures, hppa creates an unrelated stack
>>>>> frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
>>>>> is not done on the argc/argv saved/restore by _dl_start_user.
>>>>>
>>>>> Instead load _dl_argc and _dl_argv directlty instead of adjust them
>>>>> using _dl_skip_args value.
>>>>>
>>>>> Checked on hppa-linux-gnu.
>>>> Does this fix bug 29165? If yes, it should say so on the commit
>>>> message.
>>> It does, I assumed the title was suffice. I will add a note in the
>>> commit itself.
>> This comment could be improved:
>>
>>> + It also mean that to get the correct argc and argv if the \
>>> + program is ld.so it requires to read _dl_argc and _dl_argv. */\
>> "mean" should be "means" and the wording is somewhat stilted.
>>
> Indeed it sounds strange, I have changed to:
>
> Also, the loader will adjust argc, argv, env, and aux vectors \
> directly on the stack to remove any arguments used for direct \
> loader invocation. So it requires to use _dl_argc and \
> _dl_argv instead of reload them from previous saved area. */ \
This comment is improved but I would move it before the instructions to load _dl_argc
and _dl_argc in _dl_start_user.
It is better to use present tense:
The loader adjusts argc, argv, env, and the aux vectors \
directly on the stack to remove any arguments used for direct \
loader invocation. Thus, argc and argv must be reloaded from \
from _dl_argc and _dl_argv. */
In looking at the code, I think we can remove the following instructions:
> /* Save the relevant arguments (yes, those are the correct \
> registers, the kernel is weird) in their stack slots. */ \
> " stw %r25,-40(%sp)\n" /* argc */ \
> " stw %r24,-44(%sp)\n" /* argv */ \
The saved values are no longer used as far as I can tell.
Dave
--
John David Anglin dave.anglin@bell.net
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165)
2022-05-27 0:01 ` John David Anglin
@ 2022-05-27 12:23 ` Adhemerval Zanella
0 siblings, 0 replies; 30+ messages in thread
From: Adhemerval Zanella @ 2022-05-27 12:23 UTC (permalink / raw)
To: John David Anglin, Florian Weimer, Adhemerval Zanella via Libc-alpha
Cc: Szabolcs Nagy, danglin
On 26/05/2022 21:01, John David Anglin wrote:
> On 2022-05-26 7:10 p.m., Adhemerval Zanella wrote:
>>
>> On 26/05/2022 15:58, John David Anglin wrote:
>>> On 2022-05-26 2:23 p.m., Adhemerval Zanella wrote:
>>>> On 26/05/2022 15:14, Florian Weimer wrote:
>>>>> * Adhemerval Zanella via Libc-alpha:
>>>>>
>>>>>> Different than other architectures, hppa creates an unrelated stack
>>>>>> frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
>>>>>> is not done on the argc/argv saved/restore by _dl_start_user.
>>>>>>
>>>>>> Instead load _dl_argc and _dl_argv directlty instead of adjust them
>>>>>> using _dl_skip_args value.
>>>>>>
>>>>>> Checked on hppa-linux-gnu.
>>>>> Does this fix bug 29165? If yes, it should say so on the commit
>>>>> message.
>>>> It does, I assumed the title was suffice. I will add a note in the
>>>> commit itself.
>>> This comment could be improved:
>>>
>>>> + It also mean that to get the correct argc and argv if the \
>>>> + program is ld.so it requires to read _dl_argc and _dl_argv. */\
>>> "mean" should be "means" and the wording is somewhat stilted.
>>>
>> Indeed it sounds strange, I have changed to:
>>
>> Also, the loader will adjust argc, argv, env, and aux vectors \
>> directly on the stack to remove any arguments used for direct \
>> loader invocation. So it requires to use _dl_argc and \
>> _dl_argv instead of reload them from previous saved area. */ \
> This comment is improved but I would move it before the instructions to load _dl_argc
> and _dl_argc in _dl_start_user.
>
> It is better to use present tense:
>
> The loader adjusts argc, argv, env, and the aux vectors \
> directly on the stack to remove any arguments used for direct \
> loader invocation. Thus, argc and argv must be reloaded from \
> from _dl_argc and _dl_argv. */
Ack.
>
> In looking at the code, I think we can remove the following instructions:
>
>> /* Save the relevant arguments (yes, those are the correct \
>> registers, the kernel is weird) in their stack slots. */ \
>> " stw %r25,-40(%sp)\n" /* argc */ \
>> " stw %r24,-44(%sp)\n" /* argv */ \
>
> The saved values are no longer used as far as I can tell.
Indeed, I removed them.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 00/17] Remove _dl_skip_args
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
` (16 preceding siblings ...)
2022-05-26 16:50 ` [PATCH 17/17] elf: Remove _dl_skip_args Adhemerval Zanella
@ 2022-05-30 13:32 ` Carlos O'Donell
17 siblings, 0 replies; 30+ messages in thread
From: Carlos O'Donell @ 2022-05-30 13:32 UTC (permalink / raw)
To: Adhemerval Zanella, libc-alpha, Szabolcs Nagy
On 5/26/22 12:49, Adhemerval Zanella via Libc-alpha wrote:
> Both ad43cac44a686 (rtld: Use generic argv adjustment in ld.so [BZ
> #23293]) and 86147bbeec25624 (rtld: Remove DL_ARGV_NOT_RELRO and make
> _dl_skip_args const) broke both hppa (BZ# 29165) and nios2 (BZ# 29187)
> because different than aarch64, the patch did not adjust the
> architectures for the new internal semantics.
>
> This patchset adjust the remaining architectures to remove the
> _dl_skip_args usage and fix both hppa and nios2.
>
> I checked on alpha, arm, microblaze, mips, nios2, or1k, riscv, and
> sh4 with a simple test to check if argc, argv, and envp are the
> expected ones on both the constructor and on main program.
>
> I also run a full native make check for aarch64, hppa, i686, ia64,
> powerpc, s390, sparc, and x86_64.
>
> The onle architectures that I could not actually test are arc and
> csky.
The entire series looks good to me. We should push this given that we have several
machine maintainer reviews. The i686, x86_64, aarch64, s390x, and ppc64le changes
all looks good.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> Adhemerval Zanella (17):
> alpha: Remove _dl_skip_args usage
> arm: Remove _dl_skip_args usage
> arc: Remove _dl_skip_args usage
> csky: Remove _dl_skip_args usage
> hppa: Remove _dl_skip_args usage (BZ# 29165)
> i686: Remove _dl_skip_args usage
> ia64: Remove _dl_skip_args usage
> m68k: Remove _dl_skip_args usage
> microblaze: Remove _dl_skip_args usage
> mips: Remove _dl_skip_args usage
> nios2: Remove _dl_skip_args usage (BZ# 29187)
> riscv: Remove _dl_skip_args usage
> s390: Remove _dl_skip_args usage
> sh: Remove _dl_skip_args usage
> sparc: Remove _dl_skip_args usage
> x86_64: Remove _dl_skip_args usage
> elf: Remove _dl_skip_args
>
> elf/rtld.c | 2 -
> sysdeps/alpha/dl-machine.h | 41 -----------------
> sysdeps/arc/dl-machine.h | 17 +-------
> sysdeps/arm/dl-machine.h | 39 -----------------
> sysdeps/csky/dl-machine.h | 19 +-------
> sysdeps/generic/ldsodefs.h | 4 --
> sysdeps/hppa/dl-machine.h | 28 +++++-------
> sysdeps/i386/dl-machine.h | 13 +-----
> sysdeps/ia64/dl-machine.h | 70 ++++++------------------------
> sysdeps/m68k/dl-machine.h | 9 +---
> sysdeps/mach/hurd/dl-sysdep.c | 1 -
> sysdeps/microblaze/dl-machine.h | 5 ---
> sysdeps/mips/dl-machine.h | 31 +------------
> sysdeps/nios2/dl-machine.h | 50 +++++----------------
> sysdeps/riscv/dl-machine.h | 12 -----
> sysdeps/s390/s390-32/dl-machine.h | 46 --------------------
> sysdeps/s390/s390-64/dl-machine.h | 16 -------
> sysdeps/sh/dl-machine.h | 16 +------
> sysdeps/sparc/sparc32/dl-machine.h | 43 +-----------------
> sysdeps/sparc/sparc64/dl-machine.h | 40 +----------------
> sysdeps/x86_64/dl-machine.h | 13 +-----
> sysdeps/x86_64/x32/dl-machine.h | 12 +----
> 22 files changed, 52 insertions(+), 475 deletions(-)
>
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2022-05-30 13:32 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26 16:49 [PATCH 00/17] Remove _dl_skip_args Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 01/17] alpha: Remove _dl_skip_args usage Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 02/17] arm: " Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 03/17] arc: " Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 04/17] csky: " Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 05/17] hppa: Remove _dl_skip_args usage (BZ# 29165) Adhemerval Zanella
2022-05-26 18:14 ` Florian Weimer
2022-05-26 18:23 ` Adhemerval Zanella
2022-05-26 18:34 ` Florian Weimer
2022-05-26 18:58 ` John David Anglin
2022-05-26 23:10 ` Adhemerval Zanella
2022-05-27 0:01 ` John David Anglin
2022-05-27 12:23 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 06/17] i686: Remove _dl_skip_args usage Adhemerval Zanella
2022-05-26 20:53 ` H.J. Lu
2022-05-26 16:49 ` [PATCH 07/17] ia64: " Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 08/17] m68k: " Adhemerval Zanella
2022-05-26 17:18 ` Andreas Schwab
2022-05-26 17:23 ` Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 09/17] microblaze: " Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 10/17] mips: " Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 11/17] nios2: Remove _dl_skip_args usage (BZ# 29187) Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 12/17] riscv: Remove _dl_skip_args usage Adhemerval Zanella
2022-05-26 16:49 ` [PATCH 13/17] s390: " Adhemerval Zanella
2022-05-26 16:50 ` [PATCH 14/17] sh: " Adhemerval Zanella
2022-05-26 16:50 ` [PATCH 15/17] sparc: " Adhemerval Zanella
2022-05-26 16:50 ` [PATCH 16/17] x86_64: " Adhemerval Zanella
2022-05-26 20:52 ` H.J. Lu
2022-05-26 16:50 ` [PATCH 17/17] elf: Remove _dl_skip_args Adhemerval Zanella
2022-05-30 13:32 ` [PATCH 00/17] " Carlos O'Donell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).