ELF_INITFINI for ARC (was Re: [PATCH] Introduce <elf-initfini.h> and ELF_INITFINI for all architectures)
Hi Florian,
Quoted 25 lines · Florian Weimer
* Andreas Schwab:
Quoted 1 line
environ is empty.
That's because libc.so.6 still has
DT_INIT, from which_environand other variables are set up. I assumed binutils would convert that intoDT_INITARRAYbecause the architecture is not supposed to haveDT_INIT. Without that, it's hard to declare that there is noDT_INIT, and the patch essentially breaks ABI (becauseDT_INITprocessing is gone).This should fix the breakage:
Subject: Use ELF constructor instead of
_initin libc.soOn !ELF_INITFINI architectures,
_initis 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.)csu/init-first.c +0
-0@@ -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. */
csu/init-first.c __libc_init_first (int argc, char **argv, char **envp) · line 53
Quoted 10 lines
csu/init-first.c +2
-3} -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.
Quoted 2 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
* Vineet Gupta:
Quoted 4 lines
It seems that commit also removed
init_arrayfrom 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.
Quoted 4 lines
Quoted 2 lines
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.)
Quoted 4 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Quoted 4 lines · Florian Weimer
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
Quoted 3 lines
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 !
Quoted 9 lines
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. */
#defineELF_INITFINI1and keep the
crti.Sandcrtn.Sfiles 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 [email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc