|
|
84f64e |
commit e5d262effe3a87164308a3f37e61b32d0348692a
|
|
|
84f64e |
Author: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
|
|
|
84f64e |
Date: Fri Nov 30 18:05:32 2018 -0200
|
|
|
84f64e |
|
|
|
84f64e |
Fix _dl_profile_fixup data-dependency issue (Bug 23690)
|
|
|
84f64e |
|
|
|
84f64e |
There is a data-dependency between the fields of struct l_reloc_result
|
|
|
84f64e |
and the field used as the initialization guard. Users of the guard
|
|
|
84f64e |
expect writes to the structure to be observable when they also observe
|
|
|
84f64e |
the guard initialized. The solution for this problem is to use an acquire
|
|
|
84f64e |
and release load and store to ensure previous writes to the structure are
|
|
|
84f64e |
observable if the guard is initialized.
|
|
|
84f64e |
|
|
|
84f64e |
The previous implementation used DL_FIXUP_VALUE_ADDR (l_reloc_result->addr)
|
|
|
84f64e |
as the initialization guard, making it impossible for some architectures
|
|
|
84f64e |
to load and store it atomically, i.e. hppa and ia64, due to its larger size.
|
|
|
84f64e |
|
|
|
84f64e |
This commit adds an unsigned int to l_reloc_result to be used as the new
|
|
|
84f64e |
initialization guard of the struct, making it possible to load and store
|
|
|
84f64e |
it atomically in all architectures. The fix ensures that the values
|
|
|
84f64e |
observed in l_reloc_result are consistent and do not lead to crashes.
|
|
|
84f64e |
The algorithm is documented in the code in elf/dl-runtime.c
|
|
|
84f64e |
(_dl_profile_fixup). Not all data races have been eliminated.
|
|
|
84f64e |
|
|
|
84f64e |
Tested with build-many-glibcs and on powerpc, powerpc64, and powerpc64le.
|
|
|
84f64e |
|
|
|
84f64e |
[BZ #23690]
|
|
|
84f64e |
* elf/dl-runtime.c (_dl_profile_fixup): Guarantee memory
|
|
|
84f64e |
modification order when accessing reloc_result->addr.
|
|
|
84f64e |
* include/link.h (reloc_result): Add field init.
|
|
|
84f64e |
* nptl/Makefile (tests): Add tst-audit-threads.
|
|
|
84f64e |
(modules-names): Add tst-audit-threads-mod1 and
|
|
|
84f64e |
tst-audit-threads-mod2.
|
|
|
84f64e |
Add rules to build tst-audit-threads.
|
|
|
84f64e |
* nptl/tst-audit-threads-mod1.c: New file.
|
|
|
84f64e |
* nptl/tst-audit-threads-mod2.c: Likewise.
|
|
|
84f64e |
* nptl/tst-audit-threads.c: Likewise.
|
|
|
84f64e |
* nptl/tst-audit-threads.h: Likewise.
|
|
|
84f64e |
|
|
|
84f64e |
Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
|
|
|
84f64e |
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
|
|
|
84f64e |
|
|
|
84f64e |
(elf/dl-runtime.c adjusted here for lack of __builtin_expect cleanup,
|
|
|
84f64e |
nptl/Makefile for the usual test-related conflicts.)
|
|
|
84f64e |
|
|
|
84f64e |
diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
|
|
|
84f64e |
index a42e3c4924e067ba..3678a98c98d726f3 100644
|
|
|
84f64e |
--- a/elf/dl-runtime.c
|
|
|
84f64e |
+++ b/elf/dl-runtime.c
|
|
|
84f64e |
@@ -183,10 +183,36 @@ _dl_profile_fixup (
|
|
|
84f64e |
/* This is the address in the array where we store the result of previous
|
|
|
84f64e |
relocations. */
|
|
|
84f64e |
struct reloc_result *reloc_result = &l->l_reloc_result[reloc_index];
|
|
|
84f64e |
- DL_FIXUP_VALUE_TYPE *resultp = &reloc_result->addr;
|
|
|
84f64e |
|
|
|
84f64e |
- DL_FIXUP_VALUE_TYPE value = *resultp;
|
|
|
84f64e |
- if (DL_FIXUP_VALUE_CODE_ADDR (value) == 0)
|
|
|
84f64e |
+ /* CONCURRENCY NOTES:
|
|
|
84f64e |
+
|
|
|
84f64e |
+ Multiple threads may be calling the same PLT sequence and with
|
|
|
84f64e |
+ LD_AUDIT enabled they will be calling into _dl_profile_fixup to
|
|
|
84f64e |
+ update the reloc_result with the result of the lazy resolution.
|
|
|
84f64e |
+ The reloc_result guard variable is reloc_init, and we use
|
|
|
84f64e |
+ acquire/release loads and store to it to ensure that the results of
|
|
|
84f64e |
+ the structure are consistent with the loaded value of the guard.
|
|
|
84f64e |
+ This does not fix all of the data races that occur when two or more
|
|
|
84f64e |
+ threads read reloc_result->reloc_init with a value of zero and read
|
|
|
84f64e |
+ and write to that reloc_result concurrently. The expectation is
|
|
|
84f64e |
+ generally that while this is a data race it works because the
|
|
|
84f64e |
+ threads write the same values. Until the data races are fixed
|
|
|
84f64e |
+ there is a potential for problems to arise from these data races.
|
|
|
84f64e |
+ The reloc result updates should happen in parallel but there should
|
|
|
84f64e |
+ be an atomic RMW which does the final update to the real result
|
|
|
84f64e |
+ entry (see bug 23790).
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The following code uses reloc_result->init set to 0 to indicate if it is
|
|
|
84f64e |
+ the first time this object is being relocated, otherwise 1 which
|
|
|
84f64e |
+ indicates the object has already been relocated.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ Reading/Writing from/to reloc_result->reloc_init must not happen
|
|
|
84f64e |
+ before previous writes to reloc_result complete as they could
|
|
|
84f64e |
+ end-up with an incomplete struct. */
|
|
|
84f64e |
+ DL_FIXUP_VALUE_TYPE value;
|
|
|
84f64e |
+ unsigned int init = atomic_load_acquire (&reloc_result->init);
|
|
|
84f64e |
+
|
|
|
84f64e |
+ if (init == 0)
|
|
|
84f64e |
{
|
|
|
84f64e |
/* This is the first time we have to relocate this object. */
|
|
|
84f64e |
const ElfW(Sym) *const symtab
|
|
|
84f64e |
@@ -347,20 +373,32 @@ _dl_profile_fixup (
|
|
|
84f64e |
#endif
|
|
|
84f64e |
|
|
|
84f64e |
/* Store the result for later runs. */
|
|
|
84f64e |
- if (__builtin_expect (! GLRO(dl_bind_not), 1))
|
|
|
84f64e |
- *resultp = value;
|
|
|
84f64e |
+ if (__glibc_likely (! GLRO(dl_bind_not)))
|
|
|
84f64e |
+ {
|
|
|
84f64e |
+ reloc_result->addr = value;
|
|
|
84f64e |
+ /* Guarantee all previous writes complete before
|
|
|
84f64e |
+ init is updated. See CONCURRENCY NOTES earlier */
|
|
|
84f64e |
+ atomic_store_release (&reloc_result->init, 1);
|
|
|
84f64e |
+ }
|
|
|
84f64e |
+ init = 1;
|
|
|
84f64e |
}
|
|
|
84f64e |
+ else
|
|
|
84f64e |
+ value = reloc_result->addr;
|
|
|
84f64e |
|
|
|
84f64e |
/* By default we do not call the pltexit function. */
|
|
|
84f64e |
long int framesize = -1;
|
|
|
84f64e |
|
|
|
84f64e |
+
|
|
|
84f64e |
#ifdef SHARED
|
|
|
84f64e |
/* Auditing checkpoint: report the PLT entering and allow the
|
|
|
84f64e |
auditors to change the value. */
|
|
|
84f64e |
- if (DL_FIXUP_VALUE_CODE_ADDR (value) != 0 && GLRO(dl_naudit) > 0
|
|
|
84f64e |
+ if (GLRO(dl_naudit) > 0
|
|
|
84f64e |
/* Don't do anything if no auditor wants to intercept this call. */
|
|
|
84f64e |
&& (reloc_result->enterexit & LA_SYMB_NOPLTENTER) == 0)
|
|
|
84f64e |
{
|
|
|
84f64e |
+ /* Sanity check: DL_FIXUP_VALUE_CODE_ADDR (value) should have been
|
|
|
84f64e |
+ initialized earlier in this function or in another thread. */
|
|
|
84f64e |
+ assert (DL_FIXUP_VALUE_CODE_ADDR (value) != 0);
|
|
|
84f64e |
ElfW(Sym) *defsym = ((ElfW(Sym) *) D_PTR (reloc_result->bound,
|
|
|
84f64e |
l_info[DT_SYMTAB])
|
|
|
84f64e |
+ reloc_result->boundndx);
|
|
|
84f64e |
diff --git a/include/link.h b/include/link.h
|
|
|
84f64e |
index d7590640aa9285e5..22d020d833ae3a7c 100644
|
|
|
84f64e |
--- a/include/link.h
|
|
|
84f64e |
+++ b/include/link.h
|
|
|
84f64e |
@@ -206,6 +206,10 @@ struct link_map
|
|
|
84f64e |
unsigned int boundndx;
|
|
|
84f64e |
uint32_t enterexit;
|
|
|
84f64e |
unsigned int flags;
|
|
|
84f64e |
+ /* CONCURRENCY NOTE: This is used to guard the concurrent initialization
|
|
|
84f64e |
+ of the relocation result across multiple threads. See the more
|
|
|
84f64e |
+ detailed notes in elf/dl-runtime.c. */
|
|
|
84f64e |
+ unsigned int init;
|
|
|
84f64e |
} *l_reloc_result;
|
|
|
84f64e |
|
|
|
84f64e |
/* Pointer to the version information if available. */
|
|
|
84f64e |
diff --git a/nptl/Makefile b/nptl/Makefile
|
|
|
84f64e |
index cf47a6f097916766..1b9639f3566a63fd 100644
|
|
|
84f64e |
--- a/nptl/Makefile
|
|
|
84f64e |
+++ b/nptl/Makefile
|
|
|
84f64e |
@@ -298,7 +298,7 @@ tests += tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx5 \
|
|
|
84f64e |
endif
|
|
|
84f64e |
ifeq ($(build-shared),yes)
|
|
|
84f64e |
tests += tst-atfork2 tst-tls3 tst-tls4 tst-tls5 tst-_res1 tst-fini1 \
|
|
|
84f64e |
- tst-stackguard1
|
|
|
84f64e |
+ tst-stackguard1 tst-audit-threads
|
|
|
84f64e |
tests-nolibpthread += tst-fini1
|
|
|
84f64e |
ifeq ($(have-z-execstack),yes)
|
|
|
84f64e |
tests += tst-execstack
|
|
|
84f64e |
@@ -309,7 +309,7 @@ modules-names = tst-atfork2mod tst-tls3mod tst-tls4moda tst-tls4modb \
|
|
|
84f64e |
tst-tls5mod tst-tls5moda tst-tls5modb tst-tls5modc \
|
|
|
84f64e |
tst-tls5modd tst-tls5mode tst-tls5modf tst-stack4mod \
|
|
|
84f64e |
tst-_res1mod1 tst-_res1mod2 tst-execstack-mod tst-fini1mod \
|
|
|
84f64e |
- tst-join7mod
|
|
|
84f64e |
+ tst-join7mod tst-audit-threads-mod1 tst-audit-threads-mod2
|
|
|
84f64e |
extra-test-objs += $(addsuffix .os,$(strip $(modules-names))) tst-cleanup4aux.o
|
|
|
84f64e |
test-extras += $(modules-names) tst-cleanup4aux
|
|
|
84f64e |
test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
|
|
|
84f64e |
@@ -627,6 +627,14 @@ $(objpfx)tst-oddstacklimit.out: $(objpfx)tst-oddstacklimit $(objpfx)tst-basic1
|
|
|
84f64e |
$(run-program-prefix) $< --command '$(host-built-program-cmd)' > $@
|
|
|
84f64e |
endif
|
|
|
84f64e |
|
|
|
84f64e |
+# Protect against a build using -Wl,-z,now.
|
|
|
84f64e |
+LDFLAGS-tst-audit-threads-mod1.so = -Wl,-z,lazy
|
|
|
84f64e |
+LDFLAGS-tst-audit-threads-mod2.so = -Wl,-z,lazy
|
|
|
84f64e |
+LDFLAGS-tst-audit-threads = -Wl,-z,lazy
|
|
|
84f64e |
+$(objpfx)tst-audit-threads: $(objpfx)tst-audit-threads-mod2.so
|
|
|
84f64e |
+$(objpfx)tst-audit-threads.out: $(objpfx)tst-audit-threads-mod1.so
|
|
|
84f64e |
+tst-audit-threads-ENV = LD_AUDIT=$(objpfx)tst-audit-threads-mod1.so
|
|
|
84f64e |
+
|
|
|
84f64e |
# The tests here better do not run in parallel
|
|
|
84f64e |
ifneq ($(filter %tests,$(MAKECMDGOALS)),)
|
|
|
84f64e |
.NOTPARALLEL:
|
|
|
84f64e |
diff --git a/nptl/tst-audit-threads-mod1.c b/nptl/tst-audit-threads-mod1.c
|
|
|
84f64e |
new file mode 100644
|
|
|
84f64e |
index 0000000000000000..615d5ee5121962df
|
|
|
84f64e |
--- /dev/null
|
|
|
84f64e |
+++ b/nptl/tst-audit-threads-mod1.c
|
|
|
84f64e |
@@ -0,0 +1,74 @@
|
|
|
84f64e |
+/* Dummy audit library for test-audit-threads.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
84f64e |
+ This file is part of the GNU C Library.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
84f64e |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
84f64e |
+ License as published by the Free Software Foundation; either
|
|
|
84f64e |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
84f64e |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
84f64e |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
84f64e |
+ Lesser General Public License for more details.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
84f64e |
+ License along with the GNU C Library; if not, see
|
|
|
84f64e |
+ <http://www.gnu.org/licenses/>. */
|
|
|
84f64e |
+
|
|
|
84f64e |
+#include <elf.h>
|
|
|
84f64e |
+#include <link.h>
|
|
|
84f64e |
+#include <stdio.h>
|
|
|
84f64e |
+#include <assert.h>
|
|
|
84f64e |
+#include <string.h>
|
|
|
84f64e |
+
|
|
|
84f64e |
+/* We must use a dummy LD_AUDIT module to force the dynamic loader to
|
|
|
84f64e |
+ *not* update the real PLT, and instead use a cached value for the
|
|
|
84f64e |
+ lazy resolution result. It is the update of that cached value that
|
|
|
84f64e |
+ we are testing for correctness by doing this. */
|
|
|
84f64e |
+
|
|
|
84f64e |
+/* Library to be audited. */
|
|
|
84f64e |
+#define LIB "tst-audit-threads-mod2.so"
|
|
|
84f64e |
+/* CALLNUM is the number of retNum functions. */
|
|
|
84f64e |
+#define CALLNUM 7999
|
|
|
84f64e |
+
|
|
|
84f64e |
+#define CONCATX(a, b) __CONCAT (a, b)
|
|
|
84f64e |
+
|
|
|
84f64e |
+static int previous = 0;
|
|
|
84f64e |
+
|
|
|
84f64e |
+unsigned int
|
|
|
84f64e |
+la_version (unsigned int ver)
|
|
|
84f64e |
+{
|
|
|
84f64e |
+ return 1;
|
|
|
84f64e |
+}
|
|
|
84f64e |
+
|
|
|
84f64e |
+unsigned int
|
|
|
84f64e |
+la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
|
|
|
84f64e |
+{
|
|
|
84f64e |
+ return LA_FLG_BINDTO | LA_FLG_BINDFROM;
|
|
|
84f64e |
+}
|
|
|
84f64e |
+
|
|
|
84f64e |
+uintptr_t
|
|
|
84f64e |
+CONCATX(la_symbind, __ELF_NATIVE_CLASS) (ElfW(Sym) *sym,
|
|
|
84f64e |
+ unsigned int ndx,
|
|
|
84f64e |
+ uintptr_t *refcook,
|
|
|
84f64e |
+ uintptr_t *defcook,
|
|
|
84f64e |
+ unsigned int *flags,
|
|
|
84f64e |
+ const char *symname)
|
|
|
84f64e |
+{
|
|
|
84f64e |
+ const char * retnum = "retNum";
|
|
|
84f64e |
+ char * num = strstr (symname, retnum);
|
|
|
84f64e |
+ int n;
|
|
|
84f64e |
+ /* Validate if the symbols are getting called in the correct order.
|
|
|
84f64e |
+ This code is here to verify binutils does not optimize out the PLT
|
|
|
84f64e |
+ entries that require the symbol binding. */
|
|
|
84f64e |
+ if (num != NULL)
|
|
|
84f64e |
+ {
|
|
|
84f64e |
+ n = atoi (num);
|
|
|
84f64e |
+ assert (n >= previous);
|
|
|
84f64e |
+ assert (n <= CALLNUM);
|
|
|
84f64e |
+ previous = n;
|
|
|
84f64e |
+ }
|
|
|
84f64e |
+ return sym->st_value;
|
|
|
84f64e |
+}
|
|
|
84f64e |
diff --git a/nptl/tst-audit-threads-mod2.c b/nptl/tst-audit-threads-mod2.c
|
|
|
84f64e |
new file mode 100644
|
|
|
84f64e |
index 0000000000000000..f9817dd3dc7f4910
|
|
|
84f64e |
--- /dev/null
|
|
|
84f64e |
+++ b/nptl/tst-audit-threads-mod2.c
|
|
|
84f64e |
@@ -0,0 +1,22 @@
|
|
|
84f64e |
+/* Shared object with a huge number of functions for test-audit-threads.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
84f64e |
+ This file is part of the GNU C Library.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
84f64e |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
84f64e |
+ License as published by the Free Software Foundation; either
|
|
|
84f64e |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
84f64e |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
84f64e |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
84f64e |
+ Lesser General Public License for more details.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
84f64e |
+ License along with the GNU C Library; if not, see
|
|
|
84f64e |
+ <http://www.gnu.org/licenses/>. */
|
|
|
84f64e |
+
|
|
|
84f64e |
+/* Define all the retNumN functions in a library. */
|
|
|
84f64e |
+#define definenum
|
|
|
84f64e |
+#include "tst-audit-threads.h"
|
|
|
84f64e |
diff --git a/nptl/tst-audit-threads.c b/nptl/tst-audit-threads.c
|
|
|
84f64e |
new file mode 100644
|
|
|
84f64e |
index 0000000000000000..e4bf433bd85f3715
|
|
|
84f64e |
--- /dev/null
|
|
|
84f64e |
+++ b/nptl/tst-audit-threads.c
|
|
|
84f64e |
@@ -0,0 +1,97 @@
|
|
|
84f64e |
+/* Test multi-threading using LD_AUDIT.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
84f64e |
+ This file is part of the GNU C Library.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
84f64e |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
84f64e |
+ License as published by the Free Software Foundation; either
|
|
|
84f64e |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
84f64e |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
84f64e |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
84f64e |
+ Lesser General Public License for more details.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
84f64e |
+ License along with the GNU C Library; if not, see
|
|
|
84f64e |
+ <http://www.gnu.org/licenses/>. */
|
|
|
84f64e |
+
|
|
|
84f64e |
+/* This test uses a dummy LD_AUDIT library (test-audit-threads-mod1) and a
|
|
|
84f64e |
+ library with a huge number of functions in order to validate lazy symbol
|
|
|
84f64e |
+ binding with an audit library. We use one thread per CPU to test that
|
|
|
84f64e |
+ concurrent lazy resolution does not have any defects which would cause
|
|
|
84f64e |
+ the process to fail. We use an LD_AUDIT library to force the testing of
|
|
|
84f64e |
+ the relocation resolution caching code in the dynamic loader i.e.
|
|
|
84f64e |
+ _dl_runtime_profile and _dl_profile_fixup. */
|
|
|
84f64e |
+
|
|
|
84f64e |
+#include <support/xthread.h>
|
|
|
84f64e |
+#include <strings.h>
|
|
|
84f64e |
+#include <stdlib.h>
|
|
|
84f64e |
+#include <sys/sysinfo.h>
|
|
|
84f64e |
+
|
|
|
84f64e |
+static int do_test (void);
|
|
|
84f64e |
+
|
|
|
84f64e |
+/* This test usually takes less than 3s to run. However, there are cases that
|
|
|
84f64e |
+ take up to 30s. */
|
|
|
84f64e |
+#define TIMEOUT 60
|
|
|
84f64e |
+#define TEST_FUNCTION do_test ()
|
|
|
84f64e |
+#include "../test-skeleton.c"
|
|
|
84f64e |
+
|
|
|
84f64e |
+/* Declare the functions we are going to call. */
|
|
|
84f64e |
+#define externnum
|
|
|
84f64e |
+#include "tst-audit-threads.h"
|
|
|
84f64e |
+#undef externnum
|
|
|
84f64e |
+
|
|
|
84f64e |
+int num_threads;
|
|
|
84f64e |
+pthread_barrier_t barrier;
|
|
|
84f64e |
+
|
|
|
84f64e |
+void
|
|
|
84f64e |
+sync_all (int num)
|
|
|
84f64e |
+{
|
|
|
84f64e |
+ pthread_barrier_wait (&barrier);
|
|
|
84f64e |
+}
|
|
|
84f64e |
+
|
|
|
84f64e |
+void
|
|
|
84f64e |
+call_all_ret_nums (void)
|
|
|
84f64e |
+{
|
|
|
84f64e |
+ /* Call each function one at a time from all threads. */
|
|
|
84f64e |
+#define callnum
|
|
|
84f64e |
+#include "tst-audit-threads.h"
|
|
|
84f64e |
+#undef callnum
|
|
|
84f64e |
+}
|
|
|
84f64e |
+
|
|
|
84f64e |
+void *
|
|
|
84f64e |
+thread_main (void *unused)
|
|
|
84f64e |
+{
|
|
|
84f64e |
+ call_all_ret_nums ();
|
|
|
84f64e |
+ return NULL;
|
|
|
84f64e |
+}
|
|
|
84f64e |
+
|
|
|
84f64e |
+#define STR2(X) #X
|
|
|
84f64e |
+#define STR(X) STR2(X)
|
|
|
84f64e |
+
|
|
|
84f64e |
+static int
|
|
|
84f64e |
+do_test (void)
|
|
|
84f64e |
+{
|
|
|
84f64e |
+ int i;
|
|
|
84f64e |
+ pthread_t *threads;
|
|
|
84f64e |
+
|
|
|
84f64e |
+ num_threads = get_nprocs ();
|
|
|
84f64e |
+ if (num_threads <= 1)
|
|
|
84f64e |
+ num_threads = 2;
|
|
|
84f64e |
+
|
|
|
84f64e |
+ /* Used to synchronize all the threads after calling each retNumN. */
|
|
|
84f64e |
+ xpthread_barrier_init (&barrier, NULL, num_threads);
|
|
|
84f64e |
+
|
|
|
84f64e |
+ threads = (pthread_t *) xcalloc (num_threads, sizeof(pthread_t));
|
|
|
84f64e |
+ for (i = 0; i < num_threads; i++)
|
|
|
84f64e |
+ threads[i] = xpthread_create(NULL, thread_main, NULL);
|
|
|
84f64e |
+
|
|
|
84f64e |
+ for (i = 0; i < num_threads; i++)
|
|
|
84f64e |
+ xpthread_join(threads[i]);
|
|
|
84f64e |
+
|
|
|
84f64e |
+ free (threads);
|
|
|
84f64e |
+
|
|
|
84f64e |
+ return 0;
|
|
|
84f64e |
+}
|
|
|
84f64e |
diff --git a/nptl/tst-audit-threads.h b/nptl/tst-audit-threads.h
|
|
|
84f64e |
new file mode 100644
|
|
|
84f64e |
index 0000000000000000..1c9ecc08dfcd3e65
|
|
|
84f64e |
--- /dev/null
|
|
|
84f64e |
+++ b/nptl/tst-audit-threads.h
|
|
|
84f64e |
@@ -0,0 +1,92 @@
|
|
|
84f64e |
+/* Helper header for test-audit-threads.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
84f64e |
+ This file is part of the GNU C Library.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
84f64e |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
84f64e |
+ License as published by the Free Software Foundation; either
|
|
|
84f64e |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
84f64e |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
84f64e |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
84f64e |
+ Lesser General Public License for more details.
|
|
|
84f64e |
+
|
|
|
84f64e |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
84f64e |
+ License along with the GNU C Library; if not, see
|
|
|
84f64e |
+ <http://www.gnu.org/licenses/>. */
|
|
|
84f64e |
+
|
|
|
84f64e |
+/* We use this helper to create a large number of functions, all of
|
|
|
84f64e |
+ which will be resolved lazily and thus have their PLT updated.
|
|
|
84f64e |
+ This is done to provide enough functions that we can statistically
|
|
|
84f64e |
+ observe a thread vs. PLT resolution failure if one exists. */
|
|
|
84f64e |
+
|
|
|
84f64e |
+#define CONCAT(a, b) a ## b
|
|
|
84f64e |
+#define NUM(x, y) CONCAT (x, y)
|
|
|
84f64e |
+
|
|
|
84f64e |
+#define FUNC10(x) \
|
|
|
84f64e |
+ FUNC (NUM (x, 0)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 1)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 2)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 3)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 4)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 5)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 6)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 7)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 8)); \
|
|
|
84f64e |
+ FUNC (NUM (x, 9))
|
|
|
84f64e |
+
|
|
|
84f64e |
+#define FUNC100(x) \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 0)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 1)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 2)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 3)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 4)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 5)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 6)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 7)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 8)); \
|
|
|
84f64e |
+ FUNC10 (NUM (x, 9))
|
|
|
84f64e |
+
|
|
|
84f64e |
+#define FUNC1000(x) \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 0)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 1)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 2)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 3)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 4)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 5)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 6)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 7)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 8)); \
|
|
|
84f64e |
+ FUNC100 (NUM (x, 9))
|
|
|
84f64e |
+
|
|
|
84f64e |
+#define FUNC7000() \
|
|
|
84f64e |
+ FUNC1000 (1); \
|
|
|
84f64e |
+ FUNC1000 (2); \
|
|
|
84f64e |
+ FUNC1000 (3); \
|
|
|
84f64e |
+ FUNC1000 (4); \
|
|
|
84f64e |
+ FUNC1000 (5); \
|
|
|
84f64e |
+ FUNC1000 (6); \
|
|
|
84f64e |
+ FUNC1000 (7);
|
|
|
84f64e |
+
|
|
|
84f64e |
+#ifdef FUNC
|
|
|
84f64e |
+# undef FUNC
|
|
|
84f64e |
+#endif
|
|
|
84f64e |
+
|
|
|
84f64e |
+#ifdef externnum
|
|
|
84f64e |
+# define FUNC(x) extern int CONCAT (retNum, x) (void)
|
|
|
84f64e |
+#endif
|
|
|
84f64e |
+
|
|
|
84f64e |
+#ifdef definenum
|
|
|
84f64e |
+# define FUNC(x) int CONCAT (retNum, x) (void) { return x; }
|
|
|
84f64e |
+#endif
|
|
|
84f64e |
+
|
|
|
84f64e |
+#ifdef callnum
|
|
|
84f64e |
+# define FUNC(x) CONCAT (retNum, x) (); sync_all (x)
|
|
|
84f64e |
+#endif
|
|
|
84f64e |
+
|
|
|
84f64e |
+/* A value of 7000 functions is chosen as an arbitrarily large
|
|
|
84f64e |
+ number of functions that will allow us enough attempts to
|
|
|
84f64e |
+ verify lazy resolution operation. */
|
|
|
84f64e |
+FUNC7000 ();
|