diff options
| author | Florian Weimer <fweimer@redhat.com> | 2020-05-20 15:40:35 +0200 |
|---|---|---|
| committer | Florian Weimer <fweimer@redhat.com> | 2020-07-06 11:15:58 +0200 |
| commit | 706ad1e7af37be1d25fc2359bda006d31fe0d11b (patch) | |
| tree | d06e6a96c1d319a1d27fa6b6e87cfadf8bd6ef08 | |
| parent | 8f4632deb3545b2949cec5454afc3cb21a0024ea (diff) | |
| download | glibc-706ad1e7af37be1d25fc2359bda006d31fe0d11b.tar.xz glibc-706ad1e7af37be1d25fc2359bda006d31fe0d11b.zip | |
Add the __libc_single_threaded variable
The variable is placed in libc.so, and it can be true only in
an outer libc, not libcs loaded via dlmopen or static dlopen.
Since thread creation from inner namespaces does not work,
pthread_create can update __libc_single_threaded directly.
Using __libc_early_init and its initial flag, implementation of this
variable is very straightforward. A future version may reset the flag
during fork (but not in an inner namespace), or after joining all
threads except one.
Reviewed-by: DJ Delorie <dj@redhat.com>
51 files changed, 663 insertions, 8 deletions
@@ -41,6 +41,12 @@ Major new features: The GNU C Library manual has details on integration of Restartable Sequences. +* The GNU C Library now provides the header file <sys/single_threaded.h> + which declares the variable __libc_single_threaded. Applications are + encouraged to use this variable for single-thread optimizations, + instead of weak references to symbols historically defined in + libpthread. + Deprecated and removed features, and other changes affecting compatibility: * The deprecated <sys/sysctl.h> header and the sysctl function have been diff --git a/elf/Makefile b/elf/Makefile index 6fe1df90bb..81a696c3ef 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -155,7 +155,9 @@ endif tests-static-normal := tst-leaks1-static tst-array1-static tst-array5-static \ tst-dl-iter-static \ tst-tlsalign-static tst-tlsalign-extern-static \ - tst-linkall-static tst-env-setuid tst-env-setuid-tunables + tst-linkall-static tst-env-setuid tst-env-setuid-tunables \ + tst-single_threaded-static tst-single_threaded-pthread-static + tests-static-internal := tst-tls1-static tst-tls2-static \ tst-ptrguard1-static tst-stackguard1-static \ tst-tls1-static-non-pie tst-libc_dlvsym-static @@ -174,9 +176,11 @@ tests-internal := tst-tls1 tst-tls2 $(tests-static-internal) tests-static := $(tests-static-normal) $(tests-static-internal) ifeq (yes,$(build-shared)) -tests-static += tst-tls9-static -tst-tls9-static-ENV = \ - LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)dlfcn +tests-static += tst-tls9-static tst-single_threaded-static-dlopen +static-dlopen-environment = \ + LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)dlfcn +tst-tls9-static-ENV = $(static-dlopen-environment) +tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment) tests += restest1 preloadtest loadfail multiload origtest resolvfail \ constload1 order noload filter \ @@ -204,7 +208,8 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-dlopen-self tst-auditmany tst-initfinilazyfail tst-dlopenfail \ tst-dlopenfail-2 \ tst-filterobj tst-filterobj-dlopen tst-auxobj tst-auxobj-dlopen \ - tst-audit14 tst-audit15 tst-audit16 + tst-audit14 tst-audit15 tst-audit16 \ + tst-single_threaded tst-single_threaded-pthread # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -317,7 +322,9 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ tst-dlopenfailmod1 tst-dlopenfaillinkmod tst-dlopenfailmod2 \ tst-dlopenfailmod3 tst-ldconfig-ld-mod \ tst-filterobj-flt tst-filterobj-aux tst-filterobj-filtee \ - tst-auditlogmod-1 tst-auditlogmod-2 tst-auditlogmod-3 + tst-auditlogmod-1 tst-auditlogmod-2 tst-auditlogmod-3 \ + tst-single_threaded-mod1 tst-single_threaded-mod2 \ + tst-single_threaded-mod3 tst-single_threaded-mod4 # Most modules build with _ISOMAC defined, but those filtered out # depend on internal headers. modules-names-tests = $(filter-out ifuncmod% tst-libc_dlvsym-dso tst-tlsmod%,\ @@ -1748,3 +1755,17 @@ $(objpfx)tst-auxobj: $(objpfx)tst-filterobj-aux.so $(objpfx)tst-auxobj-dlopen: $(libdl) $(objpfx)tst-auxobj.out: $(objpfx)tst-filterobj-filtee.so $(objpfx)tst-auxobj-dlopen.out: $(objpfx)tst-filterobj-filtee.so + +$(objpfx)tst-single_threaded: $(objpfx)tst-single_threaded-mod1.so $(libdl) +$(objpfx)tst-single_threaded.out: \ + $(objpfx)tst-single_threaded-mod2.so $(objpfx)tst-single_threaded-mod3.so +$(objpfx)tst-single_threaded-static-dlopen: \ + $(objpfx)tst-single_threaded-mod1.o $(common-objpfx)dlfcn/libdl.a +$(objpfx)tst-single_threaded-static-dlopen.out: \ + $(objpfx)tst-single_threaded-mod2.so +$(objpfx)tst-single_threaded-pthread: \ + $(objpfx)tst-single_threaded-mod1.so $(libdl) $(shared-thread-library) +$(objpfx)tst-single_threaded-pthread.out: \ + $(objpfx)tst-single_threaded-mod2.so $(objpfx)tst-single_threaded-mod3.so \ + $(objpfx)tst-single_threaded-mod4.so +$(objpfx)tst-single_threaded-pthread-static: $(static-thread-library) diff --git a/elf/libc_early_init.c b/elf/libc_early_init.c index f0fcf6448e..86da66d5e0 100644 --- a/elf/libc_early_init.c +++ b/elf/libc_early_init.c @@ -19,13 +19,18 @@ #include <ctype.h> #include <libc-early-init.h> #include <rseq-internal.h> +#include <sys/single_threaded.h> void __libc_early_init (_Bool initial) { /* Initialize ctype data. */ __ctype_init (); + /* Register rseq ABI to the kernel for the main program's libc. */ if (initial) rseq_register_current_thread (); + + /* Only the outer namespace is marked as single-threaded. */ + __libc_single_threaded = initial; } diff --git a/elf/tst-single_threaded-mod1.c b/elf/tst-single_threaded-mod1.c new file mode 100644 index 0000000000..a66de65679 --- /dev/null +++ b/elf/tst-single_threaded-mod1.c @@ -0,0 +1,25 @@ +/* Test support for single-thread optimizations. Shared object 1. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sys/single_threaded.h> + +_Bool +single_threaded_1 (void) +{ + return __libc_single_threaded; +} diff --git a/elf/tst-single_threaded-mod2.c b/elf/tst-single_threaded-mod2.c new file mode 100644 index 0000000000..74d1e2a6f4 --- /dev/null +++ b/elf/tst-single_threaded-mod2.c @@ -0,0 +1,25 @@ +/* Test support for single-thread optimizations. Shared object 2. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sys/single_threaded.h> + +_Bool +single_threaded_2 (void) +{ + return __libc_single_threaded; +} diff --git a/elf/tst-single_threaded-mod3.c b/elf/tst-single_threaded-mod3.c new file mode 100644 index 0000000000..ac5e49cfa5 --- /dev/null +++ b/elf/tst-single_threaded-mod3.c @@ -0,0 +1,25 @@ +/* Test support for single-thread optimizations. Shared object 3. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sys/single_threaded.h> + +_Bool +single_threaded_3 (void) +{ + return __libc_single_threaded; +} diff --git a/elf/tst-single_threaded-mod4.c b/elf/tst-single_threaded-mod4.c new file mode 100644 index 0000000000..9f3a8ecef1 --- /dev/null +++ b/elf/tst-single_threaded-mod4.c @@ -0,0 +1,25 @@ +/* Test support for single-thread optimizations. Shared object 4. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sys/single_threaded.h> + +_Bool +single_threaded_4 (void) +{ |
