All of lore.kernel.org
 help / color / mirror / Atom feed
* ELF_INITFINI for ARC (was Re: [PATCH] Introduce <elf-initfini.h> and ELF_INITFINI for all architectures)
       [not found]       ` <87r1ypdrhj.fsf@oldenburg2.str.redhat.com>
@ 2020-02-26 19:10         ` Vineet Gupta
  2020-02-26 19:27           ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Vineet Gupta @ 2020-02-26 19:10 UTC (permalink / raw)
  To: Florian Weimer, Andreas Schwab; +Cc: Alistair Francis, arcml, libc-alpha

Hi Florian,

On 2/20/20 10:48 AM, Florian Weimer wrote:
> * Andreas Schwab:
> 
>> environ is empty.
> 
> 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).
> 
> This should fix the breakage:
> 
> Subject: Use ELF constructor instead of _init in libc.so
> 
> On !ELF_INITFINI architectures, _init is no longer called by the dynamic
> linker.  We can use an ELF constructor instead because the constructor
> order does not matter.  (The other constructors are used to set up libio
> vtable bypasses and do not depend on this initialization routine.)
> 
> diff --git a/csu/init-first.c b/csu/init-first.c
> index 1cd8a75098..1fa1633657 100644
> --- a/csu/init-first.c
> +++ b/csu/init-first.c
> @@ -46,9 +46,8 @@ __libc_init_first (int argc, char **argv, char **envp)
>    /* For DSOs we do not need __libc_init_first but instead _init.  */
>  }
>  
> -void
> -attribute_hidden
> -_init (int argc, char **argv, char **envp)
> +static void __attribute__ ((constructor))
> +init (int argc, char **argv, char **envp)
>  {
>  #endif
>  

This (or lack thereof) turned out to be the nasty busbox sh crash (and kernel init
panic) on ARC based off rebased upstream (latest RV32 from Alistair) containing
the original patch f4349837d93b4df. I tried this fixup and it seems to work. The
DT_INIT entry goes away and init does run as part of init_array.

It seems that commit also removed init_array from sysdeps/{riscv,csky}/Implies -
so newer arches. I suppose I need to do that for ARC as well - but could you
please explain (or point to documentation) which explains how this the Implies
stuff works.

> But I'm no longer sure if RISC-V is actually an !ELF_INITFINI
> architecture.

And an arch is !ELF_INITFINI if it supports initarray ?
I did switch ARC gcc [1] / binutils [2]to initarray last year

[1] http://lists.infradead.org/pipermail/linux-snps-arc/2019-January/005318.html
[2] http://lists.infradead.org/pipermail/linux-snps-arc/2019-February/005388.html

Thx,
-Vineet
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ELF_INITFINI for ARC (was Re: [PATCH] Introduce <elf-initfini.h> and ELF_INITFINI for all architectures)
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2020-02-26 19:27 UTC (permalink / raw)
  To: Vineet Gupta; +Cc: Andreas Schwab, Alistair Francis, arcml, libc-alpha

* Vineet Gupta:

> It seems that commit also removed init_array from
> sysdeps/{riscv,csky}/Implies - so newer arches. I suppose I need to do
> that for ARC as well - but could you please explain (or point to
> documentation) which explains how this the Implies stuff works.

You are very lucky.  The mechanism is explained in the section Porting
the GNU C Library in the manual:

  <https://www.gnu.org/software/libc/manual/html_node/Porting.html>

It's one of the few aspects of our build systems that's documented.

However, in commit f4349837d93b4dfe9ba09791e280ee2d6c99919f ("Introduce
<elf-initfini.h> and ELF_INITFINI for all architectures") I replaced the
use of the implies mechanism with a new header file, <elf-initfini.h>.
This allows us to control the default for new targets in a more explicit
way.  Previously, new ports had to include initarray explicitly, and we
know from past experience (the lack of removal of the sysctl function
comes to my mind) that this does not work.

>> But I'm no longer sure if RISC-V is actually an !ELF_INITFINI
>> architecture.
>
> And an arch is !ELF_INITFINI if it supports initarray ?

Not necessarily.  glibc always supports DT_INITARRAY for all targets,
but on some targets, it is necessary to honor DT_INIT/DT_FINI for legacy
binaries at least.  (I hope no targets are left where binutils produces
DT_INIT for regular ELF constructors, but I haven't checked.)

> I did switch ARC gcc [1] / binutils [2]to initarray last year
>
> [1] http://lists.infradead.org/pipermail/linux-snps-arc/2019-January/005318.html
> [2] http://lists.infradead.org/pipermail/linux-snps-arc/2019-February/005388.html

I haven't followed the ARC contribution process closely, sorry.  Do you
plan to contribute the port with a GLIBC_2.32 ABI baseline, or do you
want to support older binaries for an earlier non-upstream port,
backdating the baseline?

This matters because in the GLIBC_2.32 case, old binaries will not work
anyway, so we may as well require that they are rebuilt without
DT_INIT/DT_FINI.  In this case, the glibc master defaults should work.

If you want to support old binaries (which use older symbol versions
such as GLIBC_2.17), it may make sense to keep DT_INIT/DT_FINI support
as well.  To achieve this, you need to add an <elf-initifini.h> header
file with

/* Enable DT_INIT/DT_FINI support.  */
#define ELF_INITFINI 1

and keep the crti.S and crtn.S files you already have.

Thanks,
Florian


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ELF_INITFINI for ARC (was Re: [PATCH] Introduce <elf-initfini.h> and ELF_INITFINI for all architectures)
  2020-02-26 19:27           ` Florian Weimer
@ 2020-02-26 20:02             ` Vineet Gupta
  0 siblings, 0 replies; 3+ messages in thread
From: Vineet Gupta @ 2020-02-26 20:02 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Andreas Schwab, Alistair Francis, arcml, libc-alpha

On 2/26/20 11:27 AM, Florian Weimer wrote:

> I haven't followed the ARC contribution process closely, sorry.  Do you
> plan to contribute the port with a GLIBC_2.32 ABI baseline, or do you
> want to support older binaries for an earlier non-upstream port,
> backdating the baseline?

No we don't need to support old binaries: 2.32 will be baseline

> This matters because in the GLIBC_2.32 case, old binaries will not work
> anyway, so we may as well require that they are rebuilt without
> DT_INIT/DT_FINI.  In this case, the glibc master defaults should work.

Understood !

> If you want to support old binaries (which use older symbol versions
> such as GLIBC_2.17), it may make sense to keep DT_INIT/DT_FINI support
> as well.  To achieve this, you need to add an <elf-initifini.h> header
> file with
> 
> /* Enable DT_INIT/DT_FINI support.  */
> #define ELF_INITFINI 1
> 
> and keep the crti.S and crtn.S files you already have.

Per the review comments on ARC port last year [1], I was advised to remove the ARC
specific crt*.S so those are anyhow gone.

[1] https://sourceware.org/ml/libc-alpha/2019-01/msg00654.html
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-26 20:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87zhfngjot.fsf@oldenburg2.str.redhat.com>
     [not found] ` <mvm36b51ahf.fsf@suse.de>
     [not found]   ` <871rqpfc07.fsf@oldenburg2.str.redhat.com>
     [not found]     ` <mvmmu9dyyi8.fsf@suse.de>
     [not found]       ` <87r1ypdrhj.fsf@oldenburg2.str.redhat.com>
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.