public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rui314 at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/31042] New: [s390x] .init and .fini padding
Date: Wed, 08 Nov 2023 04:12:43 +0000	[thread overview]
Message-ID: <bug-31042-131@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=31042

            Bug ID: 31042
           Summary: [s390x] .init and .fini padding
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: rui314 at gmail dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

I noticed this issue while developing the mold linker for the s390x
architecture.

The CRT files for glibc/s390x include .init and .fini sections, which contain
functions for initializing and finalizing a process, respectively. The linker
simply concatenates .init or .fini input sections into a single output section
for each. Upon process startup, the runtime branches to the start of .init as
though it were a single function. The final input .init section contains a ret
instruction to return to the caller.

In this setup, there should be no gaps between the input .init/.fini sections.
However, the .init/.fini sections in glibc/s390x may include trailing padding;
each input section is aligned to a 4-byte boundary, but they do not always end
on these boundaries. As a result, padding may occur between sections after the
linker concatenates them.

The linker can fill this padding with any value. GNU ld appears to use NOPs to
fill the gaps, which happens to work. However, I believe relying on it is an
incorrect approach, or at least a very fragile one.

To fix this issue, you could simply add an `.align 4` directive at the end of
each .init/.fini input section. This would prompt GAS to insert NOPs, ensuring
that each function ends at a 4-byte boundary.

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/s390/s390-64/crti.S;h=11ab75e8d95f86ff225f84673715ff457e8b63cd;hb=HEAD

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/s390/s390-64/crtn.S;h=0eabcb346caa843a4657c3fb23739bd7bf166091;hb=HEAD

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2023-11-08  4:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08  4:12 rui314 at gmail dot com [this message]
2023-11-08  4:27 ` [Bug libc/31042] " rui314 at gmail dot com
2023-11-08  9:41 ` schwab@linux-m68k.org
2023-11-08 11:33 ` rui314 at gmail dot com
2023-11-15 14:31 ` stli at linux dot ibm.com
2023-11-16  3:36 ` rui314 at gmail dot com
2023-11-30 12:36 ` stli at linux dot ibm.com
2023-11-30 16:30 ` fweimer at redhat dot com

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=bug-31042-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@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).