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