unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Jim Wilson <jimw@sifive.com>
Cc: Andreas Schwab <schwab@suse.de>,
	 GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] Introduce <elf-initfini.h> and ELF_INITFINI for all architectures
Date: Fri, 21 Feb 2020 13:41:37 +0100	[thread overview]
Message-ID: <87o8tsi03i.fsf@oldenburg2.str.redhat.com> (raw)
In-Reply-To: <CAFyWVab52TE_5Aj-R01J4x0HTBxms-KFsZ3YY7aAyi0nzEMNLA@mail.gmail.com> (Jim Wilson's message of "Thu, 20 Feb 2020 14:48:11 -0800")

* Jim Wilson:

> On Thu, Feb 20, 2020 at 10:53 AM Florian Weimer <fweimer@redhat.com> wrote:
>> That's because libc.so.6 still has DT_INIT, from which _environ and
>> other variables are set up.  I assumed binutils would convert that into
>> DT_INITARRAY because the architecture is not supposed to have DT_INIT.
>> Without that, it's hard to declare that there is no DT_INIT, and the
>> patch essentially breaks ABI (because DT_INIT processing is gone).
>
> DT_INIT is a function address.  DT_INITARRAY is a pointer to a table
> of addresses.  I don't see how the linker can easily convert between
> them.  We would have to increase the size of the init_array table at
> link time, and I don't think we have any linker support for that.
> Maybe we could modify the startfiles to put a weak reference to _init
> at the end of init_array, right before the zero that normally ends the
> list, and fix the linker to stop creating DT_INIT for _init.  But that
> sounds a little risky, and defeats the purpose of dropping support for
> _init to reduce code size.  I would prefer that glibc not create an
> _init function in the first place.

I'm not worried about glibc here.  It's easy to make glibc consistent
with itself.  The patch I posted seems to do the trick, without
regressing anywhere else.

What I don't know is whether this binutils bug has resulted in DT_INIT
being used *elsewhere*.  I don't have a RISC-V distribution to analyze,
so I really don't know.  Fedora RISC-V seems dead, this hasn't been
updated in a while:

  <https://dl.fedoraproject.org/pub/alt/risc-v/repo/fedora/rawhide/latest/riscv64/>

(I have existing tools for RPM-based distributions, so having one would
be most useful to me to check for DT_INIT references.)

>> But I'm no longer sure if RISC-V is actually an !ELF_INITFINI
>> architecture.
>
> gcc will not create .init sections.  Newlib does not create them or
> run them in the startfiles.  The linux kernel does not run DT_INIT.

The kernel never runs DT_INIT on any architecture as far as I know, but
currently released glibc does, even on RISC-V.

> That is probably why your patch failed for Andreas.

Yes, looks like it.

> But there is a problem with GNU ld which automatically creates DT_INIT
> when it sees a function called _init.  We missed that.  This is in
> target dependent code.  The default function name can be overridden
> but that isn't quite right for RISC-V either.  Maybe we should give a
> linker error if someone gives a _init or _fini function to the linker?
>  That way they get a link time error instead of a run-time error.

I would expect the toolchain to treat _init just like any other
function, so without DT_INIT support, it would turn into dead code.

Thanks,
Florian


  reply	other threads:[~2020-02-21 12:41 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-20 14:23 [PATCH] Introduce <elf-initfini.h> and ELF_INITFINI for all architectures Florian Weimer
2020-02-05 16:50 ` Adhemerval Zanella
2020-02-09  9:02   ` Florian Weimer
2020-02-18 14:13   ` Florian Weimer
2020-02-20 16:37 ` Andreas Schwab
2020-02-20 16:40   ` Florian Weimer
2020-02-20 16:56     ` Andreas Schwab
2020-02-20 17:11     ` Andreas Schwab
2020-02-20 18:48       ` Florian Weimer
2020-02-20 22:48         ` Jim Wilson
2020-02-21 12:41           ` Florian Weimer [this message]
2020-02-21 18:34             ` Florian Weimer
2020-02-21 21:11               ` Jim Wilson
2020-02-21 21:20             ` David Abdurachmanov
2020-02-24  9:13             ` Andreas Schwab
2020-02-24 12:31               ` Florian Weimer
2020-02-24  9:12         ` Andreas Schwab
2020-02-24 10:21           ` Florian Weimer
2020-02-26 19:10         ` ELF_INITFINI for ARC (was Re: [PATCH] Introduce <elf-initfini.h> and ELF_INITFINI for all architectures) Vineet Gupta
2020-02-26 19:27           ` Florian Weimer
2020-02-26 20:02             ` Vineet Gupta

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

  List information: https://www.gnu.org/software/libc/involved.html

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

  git send-email \
    --in-reply-to=87o8tsi03i.fsf@oldenburg2.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=jimw@sifive.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@suse.de \
    /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).