From e7570f4131a6af9405af7b4fd1c31de807e7cf68 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 16 Dec 2020 15:09:52 +0100 Subject: Replace __libc_multiple_libcs with __libc_initial flag Change sbrk to fail for !__libc_initial (in the generic implementation). As a result, sbrk is (relatively) safe to use for the __libc_initial case (from the main libc). It is therefore no longer necessary to avoid using it in that case (or updating the brk cache), and the __libc_initial flag does not need to be updated as part of dlmopen or static dlopen. As before, direct brk system calls on Linux may lead to memory corruption. Reviewed-by: Adhemerval Zanella --- elf/dl-open.c | 6 ------ elf/dl-sysdep.c | 2 -- elf/libc_early_init.c | 9 +++++++++ 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'elf') diff --git a/elf/dl-open.c b/elf/dl-open.c index 8769e47051..6710ea04cd 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -787,12 +787,6 @@ dl_open_worker (void *a) if (mode & RTLD_GLOBAL) add_to_global_update (new); -#ifndef SHARED - /* We must be the static _dl_open in libc.a. A static program that - has loaded a dynamic object now has competition. */ - __libc_multiple_libcs = 1; -#endif - /* Let the user know about the opencount. */ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES)) _dl_debug_printf ("opening file=%s [%lu]; direct_opencount=%u\n\n", diff --git a/elf/dl-sysdep.c b/elf/dl-sysdep.c index 854570821c..6cc4a76560 100644 --- a/elf/dl-sysdep.c +++ b/elf/dl-sysdep.c @@ -58,8 +58,6 @@ ElfW(Addr) _dl_base_addr; #endif int __libc_enable_secure attribute_relro = 0; rtld_hidden_data_def (__libc_enable_secure) -int __libc_multiple_libcs = 0; /* Defining this here avoids the inclusion - of init-first. */ /* This variable contains the lowest stack address ever used. */ void *__libc_stack_end attribute_relro = NULL; rtld_hidden_data_def(__libc_stack_end) diff --git a/elf/libc_early_init.c b/elf/libc_early_init.c index 725ab2f811..28c6adca10 100644 --- a/elf/libc_early_init.c +++ b/elf/libc_early_init.c @@ -18,8 +18,13 @@ #include #include +#include #include +#ifdef SHARED +_Bool __libc_initial; +#endif + void __libc_early_init (_Bool initial) { @@ -28,4 +33,8 @@ __libc_early_init (_Bool initial) /* Only the outer namespace is marked as single-threaded. */ __libc_single_threaded = initial; + +#ifdef SHARED + __libc_initial = initial; +#endif } -- cgit 1.4.1