aboutsummaryrefslogtreecommitdiff
path: root/csu
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2020-04-24 22:31:15 +0200
committerFlorian Weimer <fweimer@redhat.com>2020-04-24 22:32:09 +0200
commitec935dea6332cb22f9881cd1162bad156173f4b0 (patch)
treefb49cc7ca93492277c35b413626ee5fb1c6e37b9 /csu
parent50a2d83c08a94a10f88a1fedeb7a6e3667a6b732 (diff)
downloadglibc-ec935dea6332cb22f9881cd1162bad156173f4b0.zip
glibc-ec935dea6332cb22f9881cd1162bad156173f4b0.tar.gz
glibc-ec935dea6332cb22f9881cd1162bad156173f4b0.tar.bz2
elf: Implement __libc_early_init
This function is defined in libc.so, and the dynamic loader calls right after relocation has been finished, before any ELF constructors or the preinit function is invoked. It is also used in the static build for initializing parts of the static libc. To locate __libc_early_init, a direct symbol lookup function is used, _dl_lookup_direct. It does not search the entire symbol scope and consults merely a single link map. This function could also be used to implement lookups in the vDSO (as an optimization). A per-namespace variable (libc_map) is added for locating libc.so, to avoid repeated traversals of the search scope. It is similar to GL(dl_initfirst). An alternative would have been to thread a context argument from _dl_open down to _dl_map_object_from_fd (where libc.so is identified). This could have avoided the global variable, but the change would be larger as a result. It would not have been possible to use this to replace GL(dl_initfirst) because that global variable is used to pass the function pointer past the stack switch from dl_main to the main program. Replacing that requires adding a new argument to _dl_init, which in turn needs changes to the architecture-specific libc.so startup code written in assembler. __libc_early_init should not be used to replace _dl_var_init (as it exists today on some architectures). Instead, _dl_lookup_direct should be used to look up a new variable symbol in libc.so, and that should then be initialized from the dynamic loader, immediately after the object has been loaded in _dl_map_object_from_fd (before relocation is run). This way, more IFUNC resolvers which depend on these variables will work. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'csu')
-rw-r--r--csu/init-first.c4
-rw-r--r--csu/libc-start.c5
2 files changed, 5 insertions, 4 deletions
diff --git a/csu/init-first.c b/csu/init-first.c
index 264e6f3..d214af7 100644
--- a/csu/init-first.c
+++ b/csu/init-first.c
@@ -16,7 +16,6 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -75,9 +74,6 @@ _init_first (int argc, char **argv, char **envp)
__init_misc (argc, argv, envp);
- /* Initialize ctype data. */
- __ctype_init ();
-
#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
__libc_global_ctors ();
#endif
diff --git a/csu/libc-start.c b/csu/libc-start.c
index 12468c5..ccc743c 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -22,6 +22,7 @@
#include <ldsodefs.h>
#include <exit-thread.h>
#include <libc-internal.h>
+#include <elf/libc-early-init.h>
#include <elf/dl-tunables.h>
@@ -238,6 +239,10 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
__cxa_atexit ((void (*) (void *)) rtld_fini, NULL, NULL);
#ifndef SHARED
+ /* Perform early initialization. In the shared case, this function
+ is called from the dynamic loader as early as possible. */
+ __libc_early_init ();
+
/* Call the initializer of the libc. This is only needed here if we
are compiling for the static library in which case we haven't
run the constructors in `_dl_start_user'. */