public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Rui Ueyama <rui314@gmail.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Stefan Liebler <stli@linux.ibm.com>,
	libc-alpha@sourceware.org, schwab@linux-m68k.org
Subject: Re: [PATCH] Avoid padding in _init and _fini. [BZ #31042]
Date: Tue, 21 Nov 2023 22:20:16 +0900	[thread overview]
Message-ID: <CACKH++ZaZK=iNC3mRvhu6adjTsB+hya+PdiuOEOsosdm+tAOgA@mail.gmail.com> (raw)
In-Reply-To: <32facd79-fe5f-49cc-bf72-441a4f04f285@linaro.org>

On Tue, Nov 21, 2023 at 10:10 PM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 21/11/23 09:33, Stefan Liebler wrote:
> > The linker just concatenates the .init and .fini sections which
> > results in the complete _init and _fini functions. If needed the
> > linker adds padding bytes due to an alignment. GNU ld is adding
> > NOPs, which is fine.  But e.g. mold is adding traps which results
> > in broken _init and _fini functions.
>
> Shouldn't mold follow GNU ld and fill with NOPs? Otherwise, mold will
> only be able to link glibc installations with this fix.

Well, we do follow GNU ld because otherwise we can't link working
executables. That being said, eliminating the dependency to this
particular GNU ld's behavior is I think generally a good idea,
especially given that only .init and .fini depend on it and it is easy
to eliminate it from them.

> >
> > Thus this patch removes the alignment in .init and .fini sections
> > in crtn.S files.
> >
> > We keep the 4 byte function alignment in crti.S files. As the
> > assembler now also outputs the start of _init and _fini functions
> > as multiples of 4 byte, it perhaps has to fill it. Although GNU as
> > is using NOPs here, to be sure, we just keep the alignment with
> > 0x07 (=NOPs) at the end of crti.S.
> >
> > In order to avoid an obvious NOP slide in _fini, this patch also
> > uses an lg instead of lgr instruction. Then the emitted instructions
> > needs a multiple of 4 bytes.
> > ---
> >  sysdeps/s390/s390-64/crti.S | 2 +-
> >  sysdeps/s390/s390-64/crtn.S | 2 --
> >  2 files changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/sysdeps/s390/s390-64/crti.S b/sysdeps/s390/s390-64/crti.S
> > index 11ab75e8d9..4c8246da26 100644
> > --- a/sysdeps/s390/s390-64/crti.S
> > +++ b/sysdeps/s390/s390-64/crti.S
> > @@ -85,7 +85,7 @@ _init:
> >       .type   _fini,@function
> >  _fini:
> >       stmg    %r6,%r15,48(%r15)
> > -     lgr     %r1,%r15
> > +     lg      %r1,120(%r15)
> >       aghi    %r15,-160
> >       stg     %r1,0(%r15)
> >       larl    %r12,_GLOBAL_OFFSET_TABLE_
> > diff --git a/sysdeps/s390/s390-64/crtn.S b/sysdeps/s390/s390-64/crtn.S
> > index 0eabcb346c..6bb1bc9dcf 100644
> > --- a/sysdeps/s390/s390-64/crtn.S
> > +++ b/sysdeps/s390/s390-64/crtn.S
> > @@ -37,13 +37,11 @@
> >     corresponding to the prologues in crti.S. */
> >
> >       .section .init
> > -     .align  4
> >       lg      %r4,272(%r15)
> >       lmg     %r6,%r15,208(%r15)
> >       br      %r4
> >
> >       .section .fini
> > -     .align  4
> >       lg      %r4,272(%r15)
> >       lmg     %r6,%r15,208(%r15)
> >       br      %r4

  reply	other threads:[~2023-11-21 13:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 12:33 Stefan Liebler
2023-11-21 13:10 ` Adhemerval Zanella Netto
2023-11-21 13:20   ` Rui Ueyama [this message]
2023-11-21 15:47     ` Stefan Liebler
2023-11-21 15:57       ` Adhemerval Zanella Netto
2023-11-30 12:36         ` Stefan Liebler

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='CACKH++ZaZK=iNC3mRvhu6adjTsB+hya+PdiuOEOsosdm+tAOgA@mail.gmail.com' \
    --to=rui314@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@linux-m68k.org \
    --cc=stli@linux.ibm.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).