]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
csu: Use ELF constructor instead of _init in libc.so
authorFlorian Weimer <fweimer@redhat.com>
Mon, 24 Feb 2020 10:50:24 +0000 (11:50 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 25 Feb 2020 13:58:52 +0000 (14:58 +0100)
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.)

csu/init-first.c
elf/soinit.c
include/libc-internal.h

index 1cd8a75098547ec30def6fb01521b901712ad8c2..264e6f348dc69bc3376a6a3141ed0416b5844351 100644 (file)
@@ -43,12 +43,11 @@ void
 __libc_init_first (int argc, char **argv, char **envp)
 {
 #ifdef SHARED
-  /* For DSOs we do not need __libc_init_first but instead _init.  */
+  /* For DSOs we do not need __libc_init_first but an ELF constructor.  */
 }
 
-void
-attribute_hidden
-_init (int argc, char **argv, char **envp)
+static void __attribute__ ((constructor))
+_init_first (int argc, char **argv, char **envp)
 {
 #endif
 
@@ -86,8 +85,9 @@ _init (int argc, char **argv, char **envp)
 
 /* This function is defined here so that if this file ever gets into
    ld.so we will get a link error.  Having this file silently included
-   in ld.so causes disaster, because the _init definition above will
-   cause ld.so to gain an init function, which is not a cool thing. */
+   in ld.so causes disaster, because the _init_first definition above
+   will cause ld.so to gain an ELF constructor, which is not a cool
+   thing. */
 
 extern void _dl_start (void) __attribute__ ((noreturn));
 
index fe9935732b2dcc3d71b5c0f2e52c32efc642d160..538eb68186f6bb4824e6ed8ffa6e1bc450678ed7 100644 (file)
@@ -20,7 +20,7 @@ run_hooks (void (*const list[]) (void))
     (**list) ();
 }
 
-/* This function will be called from _init in init-first.c.  */
+/* This function will be called from _init_first in init-first.c.  */
 void
 __libc_global_ctors (void)
 {
index fcd21468c0260034ae8a0222d7b7ef661f957664..4c74f6ba60a7dfcab49b5d54f21862913102ca1a 100644 (file)
@@ -24,7 +24,7 @@
 /* Initialize the `__libc_enable_secure' flag.  */
 extern void __libc_init_secure (void);
 
-/* This function will be called from _init in init-first.c.  */
+/* This function will be called from _init_first in init-first.c.  */
 extern void __libc_global_ctors (void);
 
 /* Discover the tick frequency of the machine if something goes wrong,