public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Szabolcs Nagy via Libc-alpha <libc-alpha@sourceware.org>
Cc: Szabolcs Nagy <szabolcs.nagy@arm.com>
Subject: Re: [PATCH 2/3] aarch64: Use generic argv adjustment in ld.so [BZ #23293]
Date: Tue, 12 Apr 2022 16:12:11 +0200	[thread overview]
Message-ID: <877d7u75ms.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <6b8ed2f8c240e8d2ee4386e423a4765c39aa56ef.1649767418.git.szabolcs.nagy@arm.com> (Szabolcs Nagy via Libc-alpha's message of "Tue, 12 Apr 2022 13:55:30 +0100")

* Szabolcs Nagy via Libc-alpha:

> A seemingly simpler approach is to deal with unaligned sp in crt1.o,
> i.e. align sp in the entry point of the exe before __libc_start_main
> and pass unaligned sp from ld.so after updating argc (like it is done
> on x86), however this is not a backward compatible solution, new ld.so
> would not work with old exe on targets where old crt1 does not align.

I do not understand this comment.  Main executable crt1 runs after this
code in ld.so.  ld.so has a custom crt1 equivalent in a <dl-machine.h>
assembler fragment.

> diff --git a/elf/rtld.c b/elf/rtld.c
> index 19e328f89e..c08f7ed9e2 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -1311,6 +1311,58 @@ rtld_setup_main_map (struct link_map *main_map)
>    return has_interp;
>  }
>  
> +#ifdef DL_NEED_START_ARGS_ADJUST
> +static void
> +_dl_start_args_adjust (void)
> +{
> +  void **sp;
> +  void **p;
> +  long argc;
> +  char **argv;
> +  ElfW(auxv_t) *auxv;
> +
> +  if (_dl_skip_args == 0)
> +    return;
> +
> +  sp = _dl_start_argptr;
> +
> +  /* Adjust argc on stack.  */
> +  argc = (long) sp[0] - _dl_skip_args;
> +  sp[0] = (void *) argc;
> +
> +  argv = (char **) (sp + 1); /* Necessary aliasing violation.  */
> +  p = sp + _dl_skip_args;
> +  /* Shuffle argv down.  */
> +  do
> +    *++sp = *++p;
> +  while (*p);

*p != NULL?

This looks like a memmove.  Maybe this will need
-fno-tree-loop-distribute-patterns in the future?

> +  /* Shuffle envp down.  */
> +  do
> +    *++sp = *++p;
> +  while (*p);

Likewise.

> +  auxv = (ElfW(auxv_t) *) (sp + 1); /* Necessary aliasing violation.  */
> +  /* Shuffle auxv down. */
> +  void *a, *b; /* Use a pair of pointers for an auxv entry.  */
> +  do
> +    {
> +      a = *++p;
> +      b = *++p;
> +      *++sp = a;
> +      *++sp = b;
> +    }
> +  while (a);

Likewise.

> +
> +  /* Update globals in rtld.  */
> +  _dl_argv = argv;
> +  _environ = argv + argc + 1;
> +  GLRO(dl_auxv) = auxv;
> +  /* No longer need to skip args.  */
> +  _dl_skip_args = 0;
> +}
> +#endif

Maybe we can remove _dl_skip_args completely?

Thanks,
Florian


  reply	other threads:[~2022-04-12 14:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12 12:55 [PATCH 0/3] Args adjustment with ./ld.so exe " Szabolcs Nagy
2022-04-12 12:55 ` [PATCH 1/3] Remove _dl_skip_args_internal declaration Szabolcs Nagy
2022-04-12 13:40   ` Florian Weimer
2022-04-12 13:51   ` Andreas Schwab
2022-04-12 12:55 ` [PATCH 2/3] aarch64: Use generic argv adjustment in ld.so [BZ #23293] Szabolcs Nagy
2022-04-12 14:12   ` Florian Weimer [this message]
2022-04-12 14:25     ` Florian Weimer
2022-04-13  8:09     ` Szabolcs Nagy
2022-04-12 12:55 ` [PATCH 3/3] aarch64: Move ld.so _start to separate file Szabolcs Nagy
2022-04-12 14:11   ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877d7u75ms.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=szabolcs.nagy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).