public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Szabolcs Nagy via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 2/3] aarch64: Use generic argv adjustment in ld.so [BZ #23293]
Date: Wed, 13 Apr 2022 08:09:27 +0000	[thread overview]
Message-ID: <YlaFN+hKM0bISAMK@arm.com> (raw)
In-Reply-To: <877d7u75ms.fsf@oldenburg.str.redhat.com>

The 04/12/2022 16:12, Florian Weimer wrote:
> * 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.


i mean now the entire set of argv, env, auxv is moved in memory
so we can keep sp as is.

instead we could bump sp such that the first few argv is dropped.
the only thing needed for that to work is to handle the unaligned
sp in the _start code of the exe (sp can be immediately aligned
down after saving it into some other register).

however aligned sp at entry is now abi. (the elf entry does not
have to follow the c call abi so i think it could have been
otherwise).

> > +  argv = (char **) (sp + 1); /* Necessary aliasing violation.  */
> > +  p = sp + _dl_skip_args;
> > +  /* Shuffle argv down.  */
> > +  do
> > +    *++sp = *++p;
> > +  while (*p);
> 
> *p != NULL?
> 

will fix these.

> 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.

note: technically it should be (auxp->a_type != 0)
but i wanted to avoid dealing with elfxx_auxv_t
while moving auxv.

> > +
> > +  /* 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?

it can be removed if all targets use this adjustment code.
but e.g. x86_64 ld.so _start just bumps sp up by _dl_skip_args
and then aligns sp down in the _start of the exe.

i'm not against changing this (x86_64 would work too with arg
adjustment and generic code is better than custom solutions)

  parent reply	other threads:[~2022-04-13  8:09 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
2022-04-12 14:25     ` Florian Weimer
2022-04-13  8:09     ` Szabolcs Nagy [this message]
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=YlaFN+hKM0bISAMK@arm.com \
    --to=szabolcs.nagy@arm.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /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).