abe59f
commit 32612615c58b394c3eb09f020f31310797ad3854
abe59f
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
abe59f
Date:   Mon Jan 24 10:46:17 2022 -0300
abe59f
abe59f
    elf: Issue la_symbind for bind-now (BZ #23734)
abe59f
    
abe59f
    The audit symbind callback is not called for binaries built with
abe59f
    -Wl,-z,now or when LD_BIND_NOW=1 is used, nor the PLT tracking callbacks
abe59f
    (plt_enter and plt_exit) since this would change the expected
abe59f
    program semantics (where no PLT is expected) and would have performance
abe59f
    implications (such as for BZ#15533).
abe59f
    
abe59f
    LAV_CURRENT is also bumped to indicate the audit ABI change (where
abe59f
    la_symbind flags are set by the loader to indicate no possible PLT
abe59f
    trace).
abe59f
    
abe59f
    To handle powerpc64 ELFv1 function descriptor, _dl_audit_symbind
abe59f
    requires to know whether bind-now is used so the symbol value is
abe59f
    updated to function text segment instead of the OPD (for lazy binding
abe59f
    this is done by PPC64_LOAD_FUNCPTR on _dl_runtime_resolve).
abe59f
    
abe59f
    Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu,
abe59f
    powerpc64-linux-gnu.
abe59f
    
abe59f
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
abe59f
    Tested-by: Carlos O'Donell <carlos@redhat.com>
abe59f
abe59f
Conflicts:
abe59f
	elf/Makefile
abe59f
abe59f
diff --git a/bits/link_lavcurrent.h b/bits/link_lavcurrent.h
abe59f
index 44fbea1e8060997f..c48835d12b512355 100644
abe59f
--- a/bits/link_lavcurrent.h
abe59f
+++ b/bits/link_lavcurrent.h
abe59f
@@ -22,4 +22,4 @@
abe59f
 #endif
abe59f
 
abe59f
 /* Version numbers for la_version handshake interface.  */
abe59f
-#define LAV_CURRENT	1
abe59f
+#define LAV_CURRENT	2
abe59f
diff --git a/elf/Makefile b/elf/Makefile
abe59f
index 3f5f72257a5fbea4..78147ed2dbcaf4c0 100644
abe59f
--- a/elf/Makefile
abe59f
+++ b/elf/Makefile
abe59f
@@ -347,6 +347,12 @@ tests += \
abe59f
   tst-audit21 \
abe59f
   tst-audit22 \
abe59f
   tst-audit23 \
abe59f
+  tst-audit24a \
abe59f
+  tst-audit24b \
abe59f
+  tst-audit24c \
abe59f
+  tst-audit24d \
abe59f
+  tst-audit25a \
abe59f
+  tst-audit25b \
abe59f
   tst-audit8 \
abe59f
   tst-audit9 \
abe59f
   tst-auditmany \
abe59f
@@ -611,6 +617,18 @@ modules-names = \
abe59f
   tst-audit18mod \
abe59f
   tst-audit19bmod \
abe59f
   tst-audit23mod \
abe59f
+  tst-audit24amod1 \
abe59f
+  tst-audit24amod2 \
abe59f
+  tst-audit24bmod1 \
abe59f
+  tst-audit24bmod2 \
abe59f
+  tst-audit24dmod1 \
abe59f
+  tst-audit24dmod2 \
abe59f
+  tst-audit24dmod3 \
abe59f
+  tst-audit24dmod4 \
abe59f
+  tst-audit25mod1 \
abe59f
+  tst-audit25mod2 \
abe59f
+  tst-audit25mod3 \
abe59f
+  tst-audit25mod4 \
abe59f
   tst-auditlogmod-1 \
abe59f
   tst-auditlogmod-2 \
abe59f
   tst-auditlogmod-3 \
abe59f
@@ -636,6 +654,11 @@ modules-names = \
abe59f
   tst-auditmod21b \
abe59f
   tst-auditmod22 \
abe59f
   tst-auditmod23 \
abe59f
+  tst-auditmod24a \
abe59f
+  tst-auditmod24b \
abe59f
+  tst-auditmod24c \
abe59f
+  tst-auditmod24d \
abe59f
+  tst-auditmod25 \
abe59f
   tst-big-note-lib \
abe59f
   tst-deep1mod1 \
abe59f
   tst-deep1mod2 \
abe59f
@@ -831,7 +854,8 @@ modules-execstack-yes = tst-execstack-mod
abe59f
 extra-test-objs += $(addsuffix .os,$(strip $(modules-names)))
abe59f
 
abe59f
 # filtmod1.so has a special rule
abe59f
-modules-names-nobuild := filtmod1
abe59f
+modules-names-nobuild := filtmod1 \
abe59f
+			 tst-audit24bmod1 tst-audit24bmod2.so
abe59f
 
abe59f
 tests += $(tests-static)
abe59f
 
abe59f
@@ -2057,6 +2081,69 @@ $(objpfx)tst-audit23.out: $(objpfx)tst-auditmod23.so \
abe59f
 			  $(objpfx)tst-audit23mod.so
abe59f
 tst-audit23-ARGS = -- $(host-test-program-cmd)
abe59f
 
abe59f
+$(objpfx)tst-audit24a.out: $(objpfx)tst-auditmod24a.so
abe59f
+$(objpfx)tst-audit24a: $(objpfx)tst-audit24amod1.so \
abe59f
+		       $(objpfx)tst-audit24amod2.so
abe59f
+tst-audit24a-ENV = LD_AUDIT=$(objpfx)tst-auditmod24a.so
abe59f
+LDFLAGS-tst-audit24a = -Wl,-z,now
abe59f
+
abe59f
+$(objpfx)tst-audit24b.out: $(objpfx)tst-auditmod24b.so
abe59f
+$(objpfx)tst-audit24b: $(objpfx)tst-audit24bmod1.so \
abe59f
+		       $(objpfx)tst-audit24bmod2.so
abe59f
+$(objpfx)tst-audit24bmod1: $(objpfx)tst-audit24bmod2.so
abe59f
+# The test checks if a library without .gnu.version correctly calls the
abe59f
+# audit callbacks.  So it uses an explicit link rule to avoid linking
abe59f
+# against libc.so.
abe59f
+$(objpfx)tst-audit24bmod1.so: $(objpfx)tst-audit24bmod1.os
abe59f
+	$(CC) -nostdlib -nostartfiles -shared -o $@.new $(objpfx)tst-audit24bmod1.os \
abe59f
+	  -Wl,-z,now
abe59f
+	$(call after-link,$@.new)
abe59f
+	mv -f $@.new $@
abe59f
+CFLAGS-.os += $(call elide-stack-protector,.os,tst-audit24bmod1)
abe59f
+$(objpfx)tst-audit24bmod2.so: $(objpfx)tst-audit24bmod2.os
abe59f
+	$(CC) -nostdlib -nostartfiles -shared -o $@.new $(objpfx)tst-audit24bmod2.os
abe59f
+	$(call after-link,$@.new)
abe59f
+	mv -f $@.new $@
abe59f
+CFLAGS-.os += $(call elide-stack-protector,.os,tst-audit24bmod2)
abe59f
+tst-audit24b-ENV = LD_AUDIT=$(objpfx)tst-auditmod24b.so
abe59f
+LDFLAGS-tst-audit24b = -Wl,-z,now
abe59f
+
abe59f
+# Same as tst-audit24a, but tests LD_BIND_NOW
abe59f
+$(objpfx)tst-audit24c.out: $(objpfx)tst-auditmod24c.so
abe59f
+$(objpfx)tst-audit24c: $(objpfx)tst-audit24amod1.so \
abe59f
+		       $(objpfx)tst-audit24amod2.so
abe59f
+tst-audit24c-ENV = LD_BIND_NOW=1 LD_AUDIT=$(objpfx)tst-auditmod24c.so
abe59f
+LDFLAGS-tst-audit24b = -Wl,-z,lazy
abe59f
+
abe59f
+$(objpfx)tst-audit24d.out: $(objpfx)tst-auditmod24d.so
abe59f
+$(objpfx)tst-audit24d: $(objpfx)tst-audit24dmod1.so \
abe59f
+		       $(objpfx)tst-audit24dmod2.so
abe59f
+$(objpfx)tst-audit24dmod1.so: $(objpfx)tst-audit24dmod3.so
abe59f
+LDFLAGS-tst-audit24dmod1.so = -Wl,-z,now
abe59f
+$(objpfx)tst-audit24dmod2.so: $(objpfx)tst-audit24dmod4.so
abe59f
+LDFLAGS-tst-audit24dmod2.so = -Wl,-z,lazy
abe59f
+tst-audit24d-ENV = LD_AUDIT=$(objpfx)tst-auditmod24d.so
abe59f
+LDFLAGS-tst-audit24d = -Wl,-z,lazy
abe59f
+
abe59f
+$(objpfx)tst-audit25a.out: $(objpfx)tst-auditmod25.so
abe59f
+$(objpfx)tst-audit25a: $(objpfx)tst-audit25mod1.so \
abe59f
+		       $(objpfx)tst-audit25mod2.so \
abe59f
+		       $(objpfx)tst-audit25mod3.so \
abe59f
+		       $(objpfx)tst-audit25mod4.so
abe59f
+$(objpfx)tst-audit25mod1.so: $(objpfx)tst-audit25mod3.so
abe59f
+LDFLAGS-tst-audit25mod1.so = -Wl,-z,now
abe59f
+$(objpfx)tst-audit25mod2.so: $(objpfx)tst-audit25mod4.so
abe59f
+LDFLAGS-tst-audit25mod2.so = -Wl,-z,lazy
abe59f
+tst-audit25a-ARGS = -- $(host-test-program-cmd)
abe59f
+
abe59f
+$(objpfx)tst-audit25b.out: $(objpfx)tst-auditmod25.so
abe59f
+$(objpfx)tst-audit25b: $(objpfx)tst-audit25mod1.so \
abe59f
+		       $(objpfx)tst-audit25mod2.so \
abe59f
+		       $(objpfx)tst-audit25mod3.so \
abe59f
+		       $(objpfx)tst-audit25mod4.so
abe59f
+LDFLAGS-tst-audit25b = -Wl,-z,now
abe59f
+tst-audit25b-ARGS = -- $(host-test-program-cmd)
abe59f
+
abe59f
 # tst-sonamemove links against an older implementation of the library.
abe59f
 LDFLAGS-tst-sonamemove-linkmod1.so = \
abe59f
   -Wl,--version-script=tst-sonamemove-linkmod1.map \
abe59f
diff --git a/elf/dl-audit.c b/elf/dl-audit.c
abe59f
index 152712b12fed6de2..72a50717ef60a357 100644
abe59f
--- a/elf/dl-audit.c
abe59f
+++ b/elf/dl-audit.c
abe59f
@@ -178,16 +178,23 @@ _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result,
abe59f
 		   const ElfW(Sym) *defsym, DL_FIXUP_VALUE_TYPE *value,
abe59f
 		   lookup_t result)
abe59f
 {
abe59f
-  reloc_result->bound = result;
abe59f
-  /* Compute index of the symbol entry in the symbol table of the DSO with the
abe59f
-     definition.  */
abe59f
-  reloc_result->boundndx = (defsym - (ElfW(Sym) *) D_PTR (result,
abe59f
-							  l_info[DT_SYMTAB]));
abe59f
+  bool for_jmp_slot = reloc_result == NULL;
abe59f
+
abe59f
+  /* Compute index of the symbol entry in the symbol table of the DSO
abe59f
+     with the definition.  */
abe59f
+  unsigned int boundndx = defsym - (ElfW(Sym) *) D_PTR (result,
abe59f
+							l_info[DT_SYMTAB]);
abe59f
+  if (!for_jmp_slot)
abe59f
+    {
abe59f
+      reloc_result->bound = result;
abe59f
+      reloc_result->boundndx = boundndx;
abe59f
+    }
abe59f
 
abe59f
   if ((l->l_audit_any_plt | result->l_audit_any_plt) == 0)
abe59f
     {
abe59f
       /* Set all bits since this symbol binding is not interesting.  */
abe59f
-      reloc_result->enterexit = (1u << DL_NNS) - 1;
abe59f
+      if (!for_jmp_slot)
abe59f
+	reloc_result->enterexit = (1u << DL_NNS) - 1;
abe59f
       return;
abe59f
     }
abe59f
 
abe59f
@@ -199,12 +206,13 @@ _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result,
abe59f
      two bits.  */
abe59f
   assert (DL_NNS * 2 <= sizeof (reloc_result->flags) * 8);
abe59f
   assert ((LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT) == 3);
abe59f
-  reloc_result->enterexit = LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT;
abe59f
+  uint32_t enterexit = LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT;
abe59f
 
abe59f
   const char *strtab2 = (const void *) D_PTR (result, l_info[DT_STRTAB]);
abe59f
 
abe59f
   unsigned int flags = 0;
abe59f
   struct audit_ifaces *afct = GLRO(dl_audit);
abe59f
+  uintptr_t new_value = (uintptr_t) sym.st_value;
abe59f
   for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
abe59f
     {
abe59f
       /* XXX Check whether both DSOs must request action or only one */
abe59f
@@ -215,37 +223,41 @@ _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result,
abe59f
 	{
abe59f
 	  if (afct->symbind != NULL)
abe59f
 	    {
abe59f
-	      uintptr_t new_value = afct->symbind (&sym,
abe59f
-						   reloc_result->boundndx,
abe59f
-						   &l_state->cookie,
abe59f
-						   &result_state->cookie,
abe59f
-						   &flags,
abe59f
-						   strtab2 + defsym->st_name);
abe59f
+	      flags |= for_jmp_slot ? LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT
abe59f
+				    : 0;
abe59f
+	      new_value = afct->symbind (&sym, boundndx,
abe59f
+					 &l_state->cookie,
abe59f
+					 &result_state->cookie, &flags,
abe59f
+					 strtab2 + defsym->st_name);
abe59f
 	      if (new_value != (uintptr_t) sym.st_value)
abe59f
 		{
abe59f
 		  flags |= LA_SYMB_ALTVALUE;
abe59f
-		  sym.st_value = new_value;
abe59f
+		  sym.st_value = for_jmp_slot
abe59f
+		    ? DL_FIXUP_BINDNOW_ADDR_VALUE (new_value) : new_value;
abe59f
 		}
abe59f
 	    }
abe59f
 
abe59f
 	  /* Remember the results for every audit library and store a summary
abe59f
 	     in the first two bits.  */
abe59f
-	  reloc_result->enterexit &= flags & (LA_SYMB_NOPLTENTER
abe59f
-					      | LA_SYMB_NOPLTEXIT);
abe59f
-	  reloc_result->enterexit |= ((flags & (LA_SYMB_NOPLTENTER
abe59f
-						| LA_SYMB_NOPLTEXIT))
abe59f
-				      << ((cnt + 1) * 2));
abe59f
+	  enterexit &= flags & (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT);
abe59f
+	  enterexit |= ((flags & (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT))
abe59f
+			<< ((cnt + 1) * 2));
abe59f
 	}
abe59f
       else
abe59f
 	/* If the bind flags say this auditor is not interested, set the bits
abe59f
 	   manually.  */
abe59f
-	reloc_result->enterexit |= ((LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT)
abe59f
-				    << ((cnt + 1) * 2));
abe59f
+	enterexit |= ((LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT)
abe59f
+		      << ((cnt + 1) * 2));
abe59f
       afct = afct->next;
abe59f
     }
abe59f
 
abe59f
-  reloc_result->flags = flags;
abe59f
-  *value = DL_FIXUP_ADDR_VALUE (sym.st_value);
abe59f
+  if (!for_jmp_slot)
abe59f
+    {
abe59f
+      reloc_result->enterexit = enterexit;
abe59f
+      reloc_result->flags = flags;
abe59f
+    }
abe59f
+
abe59f
+  DL_FIXUP_BINDNOW_RELOC (value, new_value, sym.st_value);
abe59f
 }
abe59f
 
abe59f
 void
abe59f
diff --git a/elf/do-rel.h b/elf/do-rel.h
abe59f
index 0b04d1a0bf28b9f4..43c80e1c0067d9ca 100644
abe59f
--- a/elf/do-rel.h
abe59f
+++ b/elf/do-rel.h
abe59f
@@ -16,6 +16,8 @@
abe59f
    License along with the GNU C Library; if not, see
abe59f
    <http://www.gnu.org/licenses/>.  */
abe59f
 
abe59f
+#include <ldsodefs.h>
abe59f
+
abe59f
 /* This file may be included twice, to define both
abe59f
    `elf_dynamic_do_rel' and `elf_dynamic_do_rela'.  */
abe59f
 
abe59f
@@ -123,6 +125,10 @@ elf_dynamic_do_Rel (struct link_map *map, struct r_scope_elem *scope[],
abe59f
 
abe59f
 	  for (; r < end; ++r)
abe59f
 	    {
abe59f
+	      ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
abe59f
+	      const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (r->r_info)];
abe59f
+	      void *const r_addr_arg = (void *) (l_addr + r->r_offset);
abe59f
+	      const struct r_found_version *rversion = &map->l_versions[ndx];
abe59f
 #if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
abe59f
 	      if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
abe59f
 		{
abe59f
@@ -133,10 +139,19 @@ elf_dynamic_do_Rel (struct link_map *map, struct r_scope_elem *scope[],
abe59f
 		}
abe59f
 #endif
abe59f
 
abe59f
-	      ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
abe59f
-	      elf_machine_rel (map, scope, r, &symtab[ELFW(R_SYM) (r->r_info)],
abe59f
-			       &map->l_versions[ndx],
abe59f
-			       (void *) (l_addr + r->r_offset), skip_ifunc);
abe59f
+	      elf_machine_rel (map, scope, r, sym, rversion, r_addr_arg,
abe59f
+			       skip_ifunc);
abe59f
+#if defined SHARED && !defined RTLD_BOOTSTRAP
abe59f
+	      if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_JMP_SLOT
abe59f
+		  && GLRO(dl_naudit) > 0)
abe59f
+		{
abe59f
+		  struct link_map *sym_map
abe59f
+		    = RESOLVE_MAP (map, scope, &sym, rversion,
abe59f
+				   ELF_MACHINE_JMP_SLOT);
abe59f
+		  if (sym != NULL)
abe59f
+		    _dl_audit_symbind (map, NULL, sym, r_addr_arg, sym_map);
abe59f
+		}
abe59f
+#endif
abe59f
 	    }
abe59f
 
abe59f
 #if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
abe59f
@@ -158,17 +173,33 @@ elf_dynamic_do_Rel (struct link_map *map, struct r_scope_elem *scope[],
abe59f
       else
abe59f
 	{
abe59f
 	  for (; r < end; ++r)
abe59f
+	    {
abe59f
+	      const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (r->r_info)];
abe59f
+	      void *const r_addr_arg = (void *) (l_addr + r->r_offset);
abe59f
 # ifdef ELF_MACHINE_IRELATIVE
abe59f
-	    if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
abe59f
-	      {
abe59f
-		if (r2 == NULL)
abe59f
-		  r2 = r;
abe59f
-		end2 = r;
abe59f
-	      }
abe59f
-	    else
abe59f
+	      if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
abe59f
+		{
abe59f
+		  if (r2 == NULL)
abe59f
+		    r2 = r;
abe59f
+		  end2 = r;
abe59f
+		  continue;
abe59f
+		}
abe59f
 # endif
abe59f
-	      elf_machine_rel (map, scope, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
abe59f
-			       (void *) (l_addr + r->r_offset), skip_ifunc);
abe59f
+	      elf_machine_rel (map, scope, r, sym, NULL, r_addr_arg,
abe59f
+			       skip_ifunc);
abe59f
+# if defined SHARED && !defined RTLD_BOOTSTRAP
abe59f
+	      if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_JMP_SLOT
abe59f
+		  && GLRO(dl_naudit) > 0)
abe59f
+		{
abe59f
+		  struct link_map *sym_map
abe59f
+		    = RESOLVE_MAP (map, scope, &sym,
abe59f
+				   (struct r_found_version *) NULL,
abe59f
+				   ELF_MACHINE_JMP_SLOT);
abe59f
+		  if (sym != NULL)
abe59f
+		    _dl_audit_symbind (map, NULL , sym,r_addr_arg, sym_map);
abe59f
+		}
abe59f
+# endif
abe59f
+	    }
abe59f
 
abe59f
 # ifdef ELF_MACHINE_IRELATIVE
abe59f
 	  if (r2 != NULL)
abe59f
diff --git a/elf/sotruss-lib.c b/elf/sotruss-lib.c
abe59f
index f0a7e55599d76714..e1ac53f327a7571b 100644
abe59f
--- a/elf/sotruss-lib.c
abe59f
+++ b/elf/sotruss-lib.c
abe59f
@@ -17,6 +17,7 @@
abe59f
    License along with the GNU C Library; if not, see
abe59f
    <http://www.gnu.org/licenses/>.  */
abe59f
 
abe59f
+#include <err.h>
abe59f
 #include <error.h>
abe59f
 #include <fcntl.h>
abe59f
 #include <stdio.h>
abe59f
@@ -232,6 +233,12 @@ uintptr_t
abe59f
 la_symbind (Elf_Sym *sym, unsigned int ndx, uintptr_t *refcook,
abe59f
 	    uintptr_t *defcook, unsigned int *flags, const char *symname)
abe59f
 {
abe59f
+  if (*flags & LA_SYMB_NOPLTENTER)
abe59f
+    warnx ("cannot trace PLT enter (bind-now enabled)");
abe59f
+
abe59f
+  if (do_exit && *flags & LA_SYMB_NOPLTEXIT)
abe59f
+    warnx ("cannot trace PLT exit (bind-now enabled)");
abe59f
+
abe59f
   if (!do_exit)
abe59f
     *flags = LA_SYMB_NOPLTEXIT;
abe59f
 
abe59f
diff --git a/elf/tst-audit24a.c b/elf/tst-audit24a.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..a1781c9b45f18fa0
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24a.c
abe59f
@@ -0,0 +1,36 @@
abe59f
+/* LD_AUDIT test for la_symbind and bind-now.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <support/check.h>
abe59f
+#include <support/support.h>
abe59f
+
abe59f
+int tst_audit24amod1_func1 (void);
abe59f
+int tst_audit24amod1_func2 (void);
abe59f
+int tst_audit24amod2_func1 (void);
abe59f
+
abe59f
+int
abe59f
+do_test (void)
abe59f
+{
abe59f
+  TEST_COMPARE (tst_audit24amod1_func1 (), 1);
abe59f
+  TEST_COMPARE (tst_audit24amod1_func2 (), 2);
abe59f
+  TEST_COMPARE (tst_audit24amod2_func1 (), 10);
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+#include <support/test-driver.c>
abe59f
diff --git a/elf/tst-audit24amod1.c b/elf/tst-audit24amod1.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..0289a4abefbc7bbb
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24amod1.c
abe59f
@@ -0,0 +1,31 @@
abe59f
+/* Module used by tst-audit24a.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <stdlib.h>
abe59f
+
abe59f
+_Noreturn int
abe59f
+tst_audit24amod1_func1 (void)
abe59f
+{
abe59f
+  abort ();
abe59f
+}
abe59f
+
abe59f
+int
abe59f
+tst_audit24amod1_func2 (void)
abe59f
+{
abe59f
+  return 2;
abe59f
+}
abe59f
diff --git a/elf/tst-audit24amod2.c b/elf/tst-audit24amod2.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..1562afc9dfc1b9b3
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24amod2.c
abe59f
@@ -0,0 +1,25 @@
abe59f
+/* Module used by tst-audit24a.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <stdlib.h>
abe59f
+
abe59f
+_Noreturn int
abe59f
+tst_audit24amod2_func1 (void)
abe59f
+{
abe59f
+  abort ();
abe59f
+}
abe59f
diff --git a/elf/tst-audit24b.c b/elf/tst-audit24b.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..567bee52c27f4361
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24b.c
abe59f
@@ -0,0 +1,37 @@
abe59f
+/* LD_AUDIT test for la_symbind and bind-now.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+/* This is similar to tst-audit24a, with the difference this modules
abe59f
+   does not have the .gnu.version section header.  */
abe59f
+
abe59f
+#include <support/check.h>
abe59f
+#include <support/support.h>
abe59f
+
abe59f
+int tst_audit24bmod1_func1 (void);
abe59f
+int tst_audit24bmod1_func2 (void);
abe59f
+
abe59f
+int
abe59f
+do_test (void)
abe59f
+{
abe59f
+  TEST_COMPARE (tst_audit24bmod1_func1 (), 1);
abe59f
+  TEST_COMPARE (tst_audit24bmod1_func2 (), 2);
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+#include <support/test-driver.c>
abe59f
diff --git a/elf/tst-audit24bmod1.c b/elf/tst-audit24bmod1.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..57ce14a01bf72fb6
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24bmod1.c
abe59f
@@ -0,0 +1,31 @@
abe59f
+/* Module used by tst-audit24c.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+int tst_audit24bmod2_func1 (void);
abe59f
+
abe59f
+int
abe59f
+tst_audit24bmod1_func1 (void)
abe59f
+{
abe59f
+  return -1;
abe59f
+}
abe59f
+
abe59f
+int
abe59f
+tst_audit24bmod1_func2 (void)
abe59f
+{
abe59f
+  return tst_audit24bmod2_func1 ();
abe59f
+}
abe59f
diff --git a/elf/tst-audit24bmod2.c b/elf/tst-audit24bmod2.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..b298ce0a05bf2db2
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24bmod2.c
abe59f
@@ -0,0 +1,23 @@
abe59f
+/* Module used by tst-audit24b.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+int
abe59f
+tst_audit24bmod2_func1 (void)
abe59f
+{
abe59f
+  return -1;
abe59f
+}
abe59f
diff --git a/elf/tst-audit24c.c b/elf/tst-audit24c.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..46ed328756067276
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24c.c
abe59f
@@ -0,0 +1,2 @@
abe59f
+/* It tests LD_BIND_NOW=1 instead of linking with -Wl,-z,now  */
abe59f
+#include "tst-audit24a.c"
abe59f
diff --git a/elf/tst-audit24d.c b/elf/tst-audit24d.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..543f3b86a6bbdead
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24d.c
abe59f
@@ -0,0 +1,36 @@
abe59f
+/* LD_AUDIT test for la_symbind and bind-now.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <support/check.h>
abe59f
+#include <support/support.h>
abe59f
+
abe59f
+int tst_audit24dmod1_func1 (void);
abe59f
+int tst_audit24dmod1_func2 (void);
abe59f
+int tst_audit24dmod2_func1 (void);
abe59f
+
abe59f
+int
abe59f
+do_test (void)
abe59f
+{
abe59f
+  TEST_COMPARE (tst_audit24dmod1_func1 (), 1);
abe59f
+  TEST_COMPARE (tst_audit24dmod1_func2 (), 32);
abe59f
+  TEST_COMPARE (tst_audit24dmod2_func1 (), 10);
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+#include <support/test-driver.c>
abe59f
diff --git a/elf/tst-audit24dmod1.c b/elf/tst-audit24dmod1.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..e563f69d638ac3f5
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24dmod1.c
abe59f
@@ -0,0 +1,33 @@
abe59f
+/* Module used by tst-audit24d.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <stdlib.h>
abe59f
+
abe59f
+int tst_audit24dmod3_func1 (void);
abe59f
+
abe59f
+_Noreturn int
abe59f
+tst_audit24dmod1_func1 (void)
abe59f
+{
abe59f
+  abort ();
abe59f
+}
abe59f
+
abe59f
+int
abe59f
+tst_audit24dmod1_func2 (void)
abe59f
+{
abe59f
+  return 2 + tst_audit24dmod3_func1 ();;
abe59f
+}
abe59f
diff --git a/elf/tst-audit24dmod2.c b/elf/tst-audit24dmod2.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..03fe9381281e5790
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24dmod2.c
abe59f
@@ -0,0 +1,28 @@
abe59f
+/* Module for tst-audit24d.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <stdlib.h>
abe59f
+
abe59f
+int tst_audit24dmod4_func1 (void);
abe59f
+
abe59f
+_Noreturn int
abe59f
+tst_audit24dmod2_func1 (void)
abe59f
+{
abe59f
+  tst_audit24dmod4_func1 ();
abe59f
+  abort ();
abe59f
+}
abe59f
diff --git a/elf/tst-audit24dmod3.c b/elf/tst-audit24dmod3.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..106d517d2887d76c
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24dmod3.c
abe59f
@@ -0,0 +1,31 @@
abe59f
+/* Module for tst-audit24d.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <stdlib.h>
abe59f
+
abe59f
+_Noreturn int
abe59f
+tst_audit24dmod3_func1 (void)
abe59f
+{
abe59f
+  abort ();
abe59f
+}
abe59f
+
abe59f
+int
abe59f
+tst_audit24dmod3_func2 (void)
abe59f
+{
abe59f
+  return 4;
abe59f
+}
abe59f
diff --git a/elf/tst-audit24dmod4.c b/elf/tst-audit24dmod4.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..1da3b46917ba1083
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit24dmod4.c
abe59f
@@ -0,0 +1,25 @@
abe59f
+/* Module for tst-audit24d.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <stdlib.h>
abe59f
+
abe59f
+_Noreturn int
abe59f
+tst_audit24dmod4_func1 (void)
abe59f
+{
abe59f
+  abort ();
abe59f
+}
abe59f
diff --git a/elf/tst-audit25a.c b/elf/tst-audit25a.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..49173e862516e876
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit25a.c
abe59f
@@ -0,0 +1,129 @@
abe59f
+/* Check LD_AUDIT and LD_BIND_NOW.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <array_length.h>
abe59f
+#include <errno.h>
abe59f
+#include <getopt.h>
abe59f
+#include <limits.h>
abe59f
+#include <inttypes.h>
abe59f
+#include <string.h>
abe59f
+#include <stdlib.h>
abe59f
+#include <support/capture_subprocess.h>
abe59f
+#include <support/check.h>
abe59f
+#include <support/xstdio.h>
abe59f
+#include <support/support.h>
abe59f
+#include <sys/auxv.h>
abe59f
+
abe59f
+static int restart;
abe59f
+#define CMDLINE_OPTIONS \
abe59f
+  { "restart", no_argument, &restart, 1 },
abe59f
+
abe59f
+void tst_audit25mod1_func1 (void);
abe59f
+void tst_audit25mod1_func2 (void);
abe59f
+void tst_audit25mod2_func1 (void);
abe59f
+void tst_audit25mod2_func2 (void);
abe59f
+
abe59f
+static int
abe59f
+handle_restart (void)
abe59f
+{
abe59f
+  tst_audit25mod1_func1 ();
abe59f
+  tst_audit25mod1_func2 ();
abe59f
+  tst_audit25mod2_func1 ();
abe59f
+  tst_audit25mod2_func2 ();
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+static inline bool
abe59f
+startswith (const char *str, const char *pre)
abe59f
+{
abe59f
+  size_t lenpre = strlen (pre);
abe59f
+  size_t lenstr = strlen (str);
abe59f
+  return lenstr < lenpre ? false : memcmp (pre, str, lenpre) == 0;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+do_test (int argc, char *argv[])
abe59f
+{
abe59f
+  /* We must have either:
abe59f
+     - One or four parameters left if called initially:
abe59f
+       + path to ld.so         optional
abe59f
+       + "--library-path"      optional
abe59f
+       + the library path      optional
abe59f
+       + the application name  */
abe59f
+
abe59f
+  if (restart)
abe59f
+    return handle_restart ();
abe59f
+
abe59f
+  setenv ("LD_AUDIT", "tst-auditmod25.so", 0);
abe59f
+
abe59f
+  char *spargv[9];
abe59f
+  int i = 0;
abe59f
+  for (; i < argc - 1; i++)
abe59f
+    spargv[i] = argv[i + 1];
abe59f
+  spargv[i++] = (char *) "--direct";
abe59f
+  spargv[i++] = (char *) "--restart";
abe59f
+  spargv[i] = NULL;
abe59f
+  TEST_VERIFY_EXIT (i < array_length (spargv));
abe59f
+
abe59f
+  {
abe59f
+    struct support_capture_subprocess result
abe59f
+      = support_capture_subprogram (spargv[0], spargv);
abe59f
+    support_capture_subprocess_check (&result, "tst-audit25a", 0,
abe59f
+				      sc_allow_stderr);
abe59f
+
abe59f
+    /* tst-audit25a is build with -Wl,-z,lazy and tst-audit25mod1 with
abe59f
+       -Wl,-z,now; so only tst_audit25mod3_func1 should be expected to
abe59f
+       have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT.  */
abe59f
+    TEST_COMPARE_STRING (result.err.buffer,
abe59f
+			 "la_symbind: tst_audit25mod3_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod1_func1 0\n"
abe59f
+			 "la_symbind: tst_audit25mod1_func2 0\n"
abe59f
+			 "la_symbind: tst_audit25mod2_func1 0\n"
abe59f
+			 "la_symbind: tst_audit25mod4_func1 0\n"
abe59f
+			 "la_symbind: tst_audit25mod2_func2 0\n");
abe59f
+
abe59f
+    support_capture_subprocess_free (&result);
abe59f
+  }
abe59f
+
abe59f
+  {
abe59f
+    setenv ("LD_BIND_NOW", "1", 0);
abe59f
+    struct support_capture_subprocess result
abe59f
+      = support_capture_subprogram (spargv[0], spargv);
abe59f
+    support_capture_subprocess_check (&result, "tst-audit25a", 0,
abe59f
+				      sc_allow_stderr);
abe59f
+
abe59f
+    /* With LD_BIND_NOW all symbols are expected to have
abe59f
+       LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT.  Also the resolution
abe59f
+       order is done in breadth-first order.  */
abe59f
+    TEST_COMPARE_STRING (result.err.buffer,
abe59f
+			 "la_symbind: tst_audit25mod4_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod3_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod1_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod2_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod1_func2 1\n"
abe59f
+			 "la_symbind: tst_audit25mod2_func2 1\n");
abe59f
+
abe59f
+    support_capture_subprocess_free (&result);
abe59f
+  }
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+#define TEST_FUNCTION_ARGV do_test
abe59f
+#include <support/test-driver.c>
abe59f
diff --git a/elf/tst-audit25b.c b/elf/tst-audit25b.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..a56638d501f9bff5
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit25b.c
abe59f
@@ -0,0 +1,128 @@
abe59f
+/* Check LD_AUDIT and LD_BIND_NOW.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <errno.h>
abe59f
+#include <getopt.h>
abe59f
+#include <limits.h>
abe59f
+#include <inttypes.h>
abe59f
+#include <string.h>
abe59f
+#include <stdlib.h>
abe59f
+#include <support/capture_subprocess.h>
abe59f
+#include <support/check.h>
abe59f
+#include <support/xstdio.h>
abe59f
+#include <support/support.h>
abe59f
+#include <sys/auxv.h>
abe59f
+
abe59f
+static int restart;
abe59f
+#define CMDLINE_OPTIONS \
abe59f
+  { "restart", no_argument, &restart, 1 },
abe59f
+
abe59f
+void tst_audit25mod1_func1 (void);
abe59f
+void tst_audit25mod1_func2 (void);
abe59f
+void tst_audit25mod2_func1 (void);
abe59f
+void tst_audit25mod2_func2 (void);
abe59f
+
abe59f
+static int
abe59f
+handle_restart (void)
abe59f
+{
abe59f
+  tst_audit25mod1_func1 ();
abe59f
+  tst_audit25mod1_func2 ();
abe59f
+  tst_audit25mod2_func1 ();
abe59f
+  tst_audit25mod2_func2 ();
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+static inline bool
abe59f
+startswith (const char *str, const char *pre)
abe59f
+{
abe59f
+  size_t lenpre = strlen (pre);
abe59f
+  size_t lenstr = strlen (str);
abe59f
+  return lenstr >= lenpre && memcmp (pre, str, lenpre) == 0;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+do_test (int argc, char *argv[])
abe59f
+{
abe59f
+  /* We must have either:
abe59f
+     - One or four parameters left if called initially:
abe59f
+       + path to ld.so         optional
abe59f
+       + "--library-path"      optional
abe59f
+       + the library path      optional
abe59f
+       + the application name  */
abe59f
+
abe59f
+  if (restart)
abe59f
+    return handle_restart ();
abe59f
+
abe59f
+  setenv ("LD_AUDIT", "tst-auditmod25.so", 0);
abe59f
+
abe59f
+  char *spargv[9];
abe59f
+  int i = 0;
abe59f
+  for (; i < argc - 1; i++)
abe59f
+    spargv[i] = argv[i + 1];
abe59f
+  spargv[i++] = (char *) "--direct";
abe59f
+  spargv[i++] = (char *) "--restart";
abe59f
+  spargv[i] = NULL;
abe59f
+
abe59f
+  {
abe59f
+    struct support_capture_subprocess result
abe59f
+      = support_capture_subprogram (spargv[0], spargv);
abe59f
+    support_capture_subprocess_check (&result, "tst-audit25a", 0,
abe59f
+				      sc_allow_stderr);
abe59f
+
abe59f
+    /* tst-audit25a and tst-audit25mod1 are built with -Wl,-z,now, but
abe59f
+       tst-audit25mod2 is built with -Wl,-z,lazy.  So only
abe59f
+       tst_audit25mod4_func1 (called by tst_audit25mod2_func1) should not
abe59f
+       have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT.  */
abe59f
+    TEST_COMPARE_STRING (result.err.buffer,
abe59f
+			 "la_symbind: tst_audit25mod3_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod1_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod2_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod1_func2 1\n"
abe59f
+			 "la_symbind: tst_audit25mod2_func2 1\n"
abe59f
+			 "la_symbind: tst_audit25mod4_func1 0\n");
abe59f
+
abe59f
+    support_capture_subprocess_free (&result);
abe59f
+  }
abe59f
+
abe59f
+  {
abe59f
+    setenv ("LD_BIND_NOW", "1", 0);
abe59f
+    struct support_capture_subprocess result
abe59f
+      = support_capture_subprogram (spargv[0], spargv);
abe59f
+    support_capture_subprocess_check (&result, "tst-audit25a", 0,
abe59f
+				      sc_allow_stderr);
abe59f
+
abe59f
+    /* With LD_BIND_NOW all symbols are expected to have
abe59f
+       LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT.  Also the resolution
abe59f
+       order is done in breadth-first order.  */
abe59f
+    TEST_COMPARE_STRING (result.err.buffer,
abe59f
+			 "la_symbind: tst_audit25mod4_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod3_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod1_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod2_func1 1\n"
abe59f
+			 "la_symbind: tst_audit25mod1_func2 1\n"
abe59f
+			 "la_symbind: tst_audit25mod2_func2 1\n");
abe59f
+
abe59f
+    support_capture_subprocess_free (&result);
abe59f
+  }
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+#define TEST_FUNCTION_ARGV do_test
abe59f
+#include <support/test-driver.c>
abe59f
diff --git a/elf/tst-audit25mod1.c b/elf/tst-audit25mod1.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..a132e34a9b2cf51f
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit25mod1.c
abe59f
@@ -0,0 +1,30 @@
abe59f
+/* Module used by tst-audit25.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+void tst_audit25mod3_func1 (void);
abe59f
+
abe59f
+void
abe59f
+tst_audit25mod1_func1 (void)
abe59f
+{
abe59f
+  tst_audit25mod3_func1 ();
abe59f
+}
abe59f
+
abe59f
+void
abe59f
+tst_audit25mod1_func2 (void)
abe59f
+{
abe59f
+}
abe59f
diff --git a/elf/tst-audit25mod2.c b/elf/tst-audit25mod2.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..92da26fa80b202c2
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit25mod2.c
abe59f
@@ -0,0 +1,30 @@
abe59f
+/* Module used by tst-audit25.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+void tst_audit25mod4_func1 (void);
abe59f
+
abe59f
+void
abe59f
+tst_audit25mod2_func1 (void)
abe59f
+{
abe59f
+  tst_audit25mod4_func1 ();
abe59f
+}
abe59f
+
abe59f
+void
abe59f
+tst_audit25mod2_func2 (void)
abe59f
+{
abe59f
+}
abe59f
diff --git a/elf/tst-audit25mod3.c b/elf/tst-audit25mod3.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..af83e8919083adef
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit25mod3.c
abe59f
@@ -0,0 +1,22 @@
abe59f
+/* Module used by tst-audit25.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+void
abe59f
+tst_audit25mod3_func1 (void)
abe59f
+{
abe59f
+}
abe59f
diff --git a/elf/tst-audit25mod4.c b/elf/tst-audit25mod4.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..6cdf34357582da16
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-audit25mod4.c
abe59f
@@ -0,0 +1,22 @@
abe59f
+/* Module used by tst-audit25.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+void
abe59f
+tst_audit25mod4_func1 (void)
abe59f
+{
abe59f
+}
abe59f
diff --git a/elf/tst-auditmod24.h b/elf/tst-auditmod24.h
abe59f
new file mode 100644
abe59f
index 0000000000000000..5fdbfef12dac2b2a
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-auditmod24.h
abe59f
@@ -0,0 +1,29 @@
abe59f
+/* Auxiliary functions for tst-audit24x.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#ifndef _TST_AUDITMOD24_H
abe59f
+#define _TST_AUDITMOD24_H
abe59f
+
abe59f
+static void
abe59f
+test_symbind_flags (unsigned int flags)
abe59f
+{
abe59f
+  if ((flags & (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT)) == 0)
abe59f
+    abort ();
abe59f
+}
abe59f
+
abe59f
+#endif
abe59f
diff --git a/elf/tst-auditmod24a.c b/elf/tst-auditmod24a.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..d8e88f3984af1707
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-auditmod24a.c
abe59f
@@ -0,0 +1,114 @@
abe59f
+/* Audit modules for tst-audit24a.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <link.h>
abe59f
+#include <inttypes.h>
abe59f
+#include <stdlib.h>
abe59f
+#include <string.h>
abe59f
+#include <tst-auditmod24.h>
abe59f
+
abe59f
+#define AUDIT24_COOKIE     0x1
abe59f
+#define AUDIT24MOD1_COOKIE 0x2
abe59f
+#define AUDIT24MOD2_COOKIE 0x3
abe59f
+
abe59f
+#ifndef TEST_NAME
abe59f
+# define TEST_NAME "tst-audit24a"
abe59f
+#endif
abe59f
+#ifndef TEST_MOD
abe59f
+# define TEST_MOD TEST_NAME
abe59f
+#endif
abe59f
+#ifndef TEST_FUNC
abe59f
+# define TEST_FUNC "tst_audit24a"
abe59f
+#endif
abe59f
+
abe59f
+unsigned int
abe59f
+la_version (unsigned int version)
abe59f
+{
abe59f
+  return LAV_CURRENT;
abe59f
+}
abe59f
+
abe59f
+unsigned int
abe59f
+la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
abe59f
+{
abe59f
+  const char *p = strrchr (map->l_name, '/');
abe59f
+  const char *l_name = p == NULL ? TEST_NAME : p + 1;
abe59f
+
abe59f
+  uintptr_t ck = -1;
abe59f
+  if (strcmp (l_name, TEST_MOD "mod1.so") == 0)
abe59f
+    ck = AUDIT24MOD1_COOKIE;
abe59f
+  else if (strcmp (l_name, TEST_MOD "mod2.so") == 0)
abe59f
+    ck = AUDIT24MOD2_COOKIE;
abe59f
+  else if (strcmp (l_name, TEST_NAME) == 0)
abe59f
+    ck = AUDIT24_COOKIE;
abe59f
+
abe59f
+  *cookie = ck;
abe59f
+  return ck == -1 ? 0 : LA_FLG_BINDFROM | LA_FLG_BINDTO;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+tst_func1 (void)
abe59f
+{
abe59f
+  return 1;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+tst_func2 (void)
abe59f
+{
abe59f
+  return 10;
abe59f
+}
abe59f
+
abe59f
+#if __ELF_NATIVE_CLASS == 64
abe59f
+uintptr_t
abe59f
+la_symbind64 (Elf64_Sym *sym, unsigned int ndx,
abe59f
+	      uintptr_t *refcook, uintptr_t *defcook,
abe59f
+	      unsigned int *flags, const char *symname)
abe59f
+#else
abe59f
+uintptr_t
abe59f
+la_symbind32 (Elf32_Sym *sym, unsigned int ndx,
abe59f
+	      uintptr_t *refcook, uintptr_t *defcook,
abe59f
+	      unsigned int *flags, const char *symname)
abe59f
+#endif
abe59f
+{
abe59f
+  if (*refcook == AUDIT24_COOKIE)
abe59f
+    {
abe59f
+      if (*defcook == AUDIT24MOD1_COOKIE)
abe59f
+	{
abe59f
+	  /* Check if bind-now symbols are advertised to not call the PLT
abe59f
+	     hooks.  */
abe59f
+	  test_symbind_flags (*flags);
abe59f
+
abe59f
+	  if (strcmp (symname, TEST_FUNC "mod1_func1") == 0)
abe59f
+	    return (uintptr_t) tst_func1;
abe59f
+	  else if (strcmp (symname, TEST_FUNC "mod1_func2") == 0)
abe59f
+	    return sym->st_value;
abe59f
+	  abort ();
abe59f
+	}
abe59f
+      if (*defcook == AUDIT24MOD2_COOKIE
abe59f
+	  && (strcmp (symname, TEST_FUNC "mod2_func1") == 0))
abe59f
+	{
abe59f
+	  test_symbind_flags (*flags);
abe59f
+
abe59f
+	  return (uintptr_t) tst_func2;
abe59f
+	}
abe59f
+
abe59f
+      /* malloc functions.  */
abe59f
+      return sym->st_value;
abe59f
+    }
abe59f
+
abe59f
+  abort ();
abe59f
+}
abe59f
diff --git a/elf/tst-auditmod24b.c b/elf/tst-auditmod24b.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..e98f6d5ec528fe03
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-auditmod24b.c
abe59f
@@ -0,0 +1,104 @@
abe59f
+/* Audit modules for tst-audit24b.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <link.h>
abe59f
+#include <inttypes.h>
abe59f
+#include <stdlib.h>
abe59f
+#include <string.h>
abe59f
+#include <tst-auditmod24.h>
abe59f
+
abe59f
+#define TEST_NAME "tst-audit24b"
abe59f
+#define TEST_FUNC "tst_audit24b"
abe59f
+
abe59f
+#define AUDIT24_COOKIE     0x1
abe59f
+#define AUDIT24MOD1_COOKIE 0x2
abe59f
+#define AUDIT24MOD2_COOKIE 0x3
abe59f
+
abe59f
+unsigned int
abe59f
+la_version (unsigned int version)
abe59f
+{
abe59f
+  return LAV_CURRENT;
abe59f
+}
abe59f
+
abe59f
+unsigned int
abe59f
+la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
abe59f
+{
abe59f
+  const char *p = strrchr (map->l_name, '/');
abe59f
+  const char *l_name = p == NULL ? TEST_NAME : p + 1;
abe59f
+
abe59f
+  uintptr_t ck = -1;
abe59f
+  if (strcmp (l_name, TEST_NAME "mod1.so") == 0)
abe59f
+    ck = AUDIT24MOD1_COOKIE;
abe59f
+  else if (strcmp (l_name, TEST_NAME "mod2.so") == 0)
abe59f
+    ck = AUDIT24MOD2_COOKIE;
abe59f
+  else if (strcmp (l_name, TEST_NAME) == 0)
abe59f
+    ck = AUDIT24_COOKIE;
abe59f
+
abe59f
+  *cookie = ck;
abe59f
+  return ck == -1 ? 0 : LA_FLG_BINDFROM | LA_FLG_BINDTO;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+tst_func1 (void)
abe59f
+{
abe59f
+  return 1;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+tst_func2 (void)
abe59f
+{
abe59f
+  return 2;
abe59f
+}
abe59f
+
abe59f
+#if __ELF_NATIVE_CLASS == 64
abe59f
+uintptr_t
abe59f
+la_symbind64 (Elf64_Sym *sym, unsigned int ndx,
abe59f
+	      uintptr_t *refcook, uintptr_t *defcook,
abe59f
+	      unsigned int *flags, const char *symname)
abe59f
+#else
abe59f
+uintptr_t
abe59f
+la_symbind32 (Elf32_Sym *sym, unsigned int ndx,
abe59f
+	      uintptr_t *refcook, uintptr_t *defcook,
abe59f
+	      unsigned int *flags, const char *symname)
abe59f
+#endif
abe59f
+{
abe59f
+  if (*refcook == AUDIT24_COOKIE)
abe59f
+    {
abe59f
+      if (*defcook == AUDIT24MOD1_COOKIE)
abe59f
+	  {
abe59f
+	    if (strcmp (symname, TEST_FUNC "mod1_func1") == 0)
abe59f
+	      return (uintptr_t) tst_func1;
abe59f
+	    else if (strcmp (symname, TEST_FUNC "mod1_func2") == 0)
abe59f
+	      return sym->st_value;
abe59f
+	    abort ();
abe59f
+	  }
abe59f
+      /* malloc functions.  */
abe59f
+      return sym->st_value;
abe59f
+    }
abe59f
+  else if (*refcook == AUDIT24MOD1_COOKIE)
abe59f
+    {
abe59f
+      if (*defcook == AUDIT24MOD2_COOKIE
abe59f
+	  && (strcmp (symname, TEST_FUNC "mod2_func1") == 0))
abe59f
+	{
abe59f
+	  test_symbind_flags (*flags);
abe59f
+	  return (uintptr_t) tst_func2;
abe59f
+	}
abe59f
+    }
abe59f
+
abe59f
+  abort ();
abe59f
+}
abe59f
diff --git a/elf/tst-auditmod24c.c b/elf/tst-auditmod24c.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..67e62c9d332f48a7
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-auditmod24c.c
abe59f
@@ -0,0 +1,3 @@
abe59f
+#define TEST_NAME "tst-audit24c"
abe59f
+#define TEST_MOD  "tst-audit24a"
abe59f
+#include "tst-auditmod24a.c"
abe59f
diff --git a/elf/tst-auditmod24d.c b/elf/tst-auditmod24d.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..8c803ecc0a48f21b
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-auditmod24d.c
abe59f
@@ -0,0 +1,120 @@
abe59f
+/* Audit module for tst-audit24d.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <link.h>
abe59f
+#include <inttypes.h>
abe59f
+#include <stdlib.h>
abe59f
+#include <string.h>
abe59f
+#include <tst-auditmod24.h>
abe59f
+
abe59f
+#define AUDIT24_COOKIE     0x0
abe59f
+#define AUDIT24MOD1_COOKIE 0x1
abe59f
+#define AUDIT24MOD2_COOKIE 0x2
abe59f
+#define AUDIT24MOD3_COOKIE 0x3
abe59f
+#define AUDIT24MOD4_COOKIE 0x4
abe59f
+
abe59f
+unsigned int
abe59f
+la_version (unsigned int version)
abe59f
+{
abe59f
+  return LAV_CURRENT;
abe59f
+}
abe59f
+
abe59f
+unsigned int
abe59f
+la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
abe59f
+{
abe59f
+  const char *p = strrchr (map->l_name, '/');
abe59f
+  const char *l_name = p == NULL ? "tst-audit24d" : p + 1;
abe59f
+
abe59f
+  uintptr_t ck = -1;
abe59f
+  if (strcmp (l_name, "tst-audit24dmod1.so") == 0)
abe59f
+    ck = AUDIT24MOD1_COOKIE;
abe59f
+  else if (strcmp (l_name, "tst-audit24dmod2.so") == 0)
abe59f
+    ck = AUDIT24MOD2_COOKIE;
abe59f
+  else if (strcmp (l_name, "tst-audit24dmod3.so") == 0)
abe59f
+    ck = AUDIT24MOD3_COOKIE;
abe59f
+  else if (strcmp (l_name, "tst-audit24dmod.so") == 0)
abe59f
+    ck = AUDIT24MOD4_COOKIE;
abe59f
+  else if (strcmp (l_name, "tst-audit24d") == 0)
abe59f
+    ck = AUDIT24_COOKIE;
abe59f
+
abe59f
+  *cookie = ck;
abe59f
+  return ck == -1 ? 0 : LA_FLG_BINDFROM | LA_FLG_BINDTO;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+tst_audit24dmod1_func1 (void)
abe59f
+{
abe59f
+  return 1;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+tst_audit24dmod2_func1 (void)
abe59f
+{
abe59f
+  return 10;
abe59f
+}
abe59f
+
abe59f
+static int
abe59f
+tst_audit24dmod3_func1 (void)
abe59f
+{
abe59f
+  return 30;
abe59f
+}
abe59f
+
abe59f
+#include <stdio.h>
abe59f
+
abe59f
+#if __ELF_NATIVE_CLASS == 64
abe59f
+uintptr_t
abe59f
+la_symbind64 (Elf64_Sym *sym, unsigned int ndx,
abe59f
+	      uintptr_t *refcook, uintptr_t *defcook,
abe59f
+	      unsigned int *flags, const char *symname)
abe59f
+#else
abe59f
+uintptr_t
abe59f
+la_symbind32 (Elf32_Sym *sym, unsigned int ndx,
abe59f
+	      uintptr_t *refcook, uintptr_t *defcook,
abe59f
+	      unsigned int *flags, const char *symname)
abe59f
+#endif
abe59f
+{
abe59f
+  if (*refcook == AUDIT24_COOKIE)
abe59f
+    {
abe59f
+      if (*defcook == AUDIT24MOD1_COOKIE)
abe59f
+	  {
abe59f
+	    if (strcmp (symname, "tst_audit24dmod1_func1") == 0)
abe59f
+	      return (uintptr_t) tst_audit24dmod1_func1;
abe59f
+	    else if (strcmp (symname, "tst_audit24dmod1_func2") == 0)
abe59f
+	      return sym->st_value;
abe59f
+	    abort ();
abe59f
+	  }
abe59f
+      if (*defcook == AUDIT24MOD2_COOKIE
abe59f
+	  && (strcmp (symname, "tst_audit24dmod2_func1") == 0))
abe59f
+	return (uintptr_t) tst_audit24dmod2_func1;
abe59f
+
abe59f
+      /* malloc functions.  */
abe59f
+      return sym->st_value;
abe59f
+    }
abe59f
+  else if (*refcook == AUDIT24MOD1_COOKIE)
abe59f
+    {
abe59f
+      if (*defcook == AUDIT24MOD3_COOKIE
abe59f
+	  && strcmp (symname, "tst_audit24dmod3_func1") == 0)
abe59f
+	{
abe59f
+	  test_symbind_flags (*flags);
abe59f
+
abe59f
+	  return (uintptr_t) tst_audit24dmod3_func1;
abe59f
+	}
abe59f
+    }
abe59f
+
abe59f
+  abort ();
abe59f
+}
abe59f
diff --git a/elf/tst-auditmod25.c b/elf/tst-auditmod25.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..526f5c54bc2c3b8c
abe59f
--- /dev/null
abe59f
+++ b/elf/tst-auditmod25.c
abe59f
@@ -0,0 +1,79 @@
abe59f
+/* Audit modules for tst-audit25a.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <link.h>
abe59f
+#include <inttypes.h>
abe59f
+#include <stdlib.h>
abe59f
+#include <string.h>
abe59f
+#include <stdio.h>
abe59f
+
abe59f
+#define AUDIT25_COOKIE     0x1
abe59f
+#define AUDIT25MOD1_COOKIE 0x2
abe59f
+#define AUDIT25MOD2_COOKIE 0x3
abe59f
+#define AUDIT25MOD3_COOKIE 0x2
abe59f
+#define AUDIT25MOD4_COOKIE 0x3
abe59f
+
abe59f
+#define TEST_NAME "tst-audit25"
abe59f
+#define TEST_MOD  "tst-audit25"
abe59f
+#define TEST_FUNC "tst_audit25"
abe59f
+
abe59f
+unsigned int
abe59f
+la_version (unsigned int version)
abe59f
+{
abe59f
+  return LAV_CURRENT;
abe59f
+}
abe59f
+
abe59f
+unsigned int
abe59f
+la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
abe59f
+{
abe59f
+  const char *p = strrchr (map->l_name, '/');
abe59f
+  const char *l_name = p == NULL ? TEST_NAME : p + 1;
abe59f
+
abe59f
+  uintptr_t ck = -1;
abe59f
+  if (strcmp (l_name, TEST_MOD "mod1.so") == 0)
abe59f
+    ck = AUDIT25MOD1_COOKIE;
abe59f
+  else if (strcmp (l_name, TEST_MOD "mod2.so") == 0)
abe59f
+    ck = AUDIT25MOD2_COOKIE;
abe59f
+  else if (strcmp (l_name, TEST_MOD "mod3.so") == 0)
abe59f
+    ck = AUDIT25MOD3_COOKIE;
abe59f
+  else if (strcmp (l_name, TEST_MOD "mod4.so") == 0)
abe59f
+    ck = AUDIT25MOD4_COOKIE;
abe59f
+  else if (strncmp (l_name, TEST_NAME, strlen (TEST_NAME)) == 0)
abe59f
+    ck = AUDIT25_COOKIE;
abe59f
+
abe59f
+  *cookie = ck;
abe59f
+  return ck == -1 ? 0 : LA_FLG_BINDFROM | LA_FLG_BINDTO;
abe59f
+}
abe59f
+
abe59f
+#if __ELF_NATIVE_CLASS == 64
abe59f
+uintptr_t
abe59f
+la_symbind64 (Elf64_Sym *sym, unsigned int ndx,
abe59f
+	      uintptr_t *refcook, uintptr_t *defcook,
abe59f
+	      unsigned int *flags, const char *symname)
abe59f
+#else
abe59f
+uintptr_t
abe59f
+la_symbind32 (Elf32_Sym *sym, unsigned int ndx,
abe59f
+	      uintptr_t *refcook, uintptr_t *defcook,
abe59f
+	      unsigned int *flags, const char *symname)
abe59f
+#endif
abe59f
+{
abe59f
+  if (*refcook != -1 && *defcook != -1)
abe59f
+    fprintf (stderr, "la_symbind: %s %u\n", symname,
abe59f
+	     *flags & (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT) ? 1 : 0);
abe59f
+  return sym->st_value;
abe59f
+}
abe59f
diff --git a/sysdeps/generic/dl-lookupcfg.h b/sysdeps/generic/dl-lookupcfg.h
abe59f
index e7d37170147aba83..7412c6391b0c3e02 100644
abe59f
--- a/sysdeps/generic/dl-lookupcfg.h
abe59f
+++ b/sysdeps/generic/dl-lookupcfg.h
abe59f
@@ -26,3 +26,6 @@
abe59f
 #define DL_FIXUP_VALUE_CODE_ADDR(value) (value)
abe59f
 #define DL_FIXUP_VALUE_ADDR(value) (value)
abe59f
 #define DL_FIXUP_ADDR_VALUE(addr) (addr)
abe59f
+#define DL_FIXUP_BINDNOW_ADDR_VALUE(addr) (addr)
abe59f
+#define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value) \
abe59f
+  (*value) = st_value;
abe59f
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
abe59f
index 73f4863fd43922b9..d4f70211c34d1c59 100644
abe59f
--- a/sysdeps/generic/ldsodefs.h
abe59f
+++ b/sysdeps/generic/ldsodefs.h
abe59f
@@ -1299,7 +1299,10 @@ void _dl_audit_objclose (struct link_map *l)
abe59f
 /* Call the la_preinit from the audit modules for the link_map L.  */
abe59f
 void _dl_audit_preinit (struct link_map *l);
abe59f
 
abe59f
-/* Call the la_symbind{32,64} from the audit modules for the link_map L.  */
abe59f
+/* Call the la_symbind{32,64} from the audit modules for the link_map L.  If
abe59f
+   RELOC_RESULT is NULL it assumes the symbol to be bind-now and will set
abe59f
+   the flags with LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT prior calling
abe59f
+   la_symbind{32,64}.  */
abe59f
 void _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result,
abe59f
 			const ElfW(Sym) *defsym, DL_FIXUP_VALUE_TYPE *value,
abe59f
 			lookup_t result)
abe59f
diff --git a/sysdeps/hppa/dl-lookupcfg.h b/sysdeps/hppa/dl-lookupcfg.h
abe59f
index 38db345936cb6335..c3fea1fe5776b17a 100644
abe59f
--- a/sysdeps/hppa/dl-lookupcfg.h
abe59f
+++ b/sysdeps/hppa/dl-lookupcfg.h
abe59f
@@ -80,3 +80,6 @@ void attribute_hidden _dl_unmap (struct link_map *map);
abe59f
 #define DL_FIXUP_VALUE_CODE_ADDR(value) ((value).ip)
abe59f
 #define DL_FIXUP_VALUE_ADDR(value) ((uintptr_t) &(value))
abe59f
 #define DL_FIXUP_ADDR_VALUE(addr) (*(struct fdesc *) (addr))
abe59f
+#define DL_FIXUP_BINDNOW_ADDR_VALUE(addr) (addr)
abe59f
+#define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value) \
abe59f
+  (*value) = *(struct fdesc *) (st_value)
abe59f
diff --git a/sysdeps/ia64/dl-lookupcfg.h b/sysdeps/ia64/dl-lookupcfg.h
abe59f
index 48f91202c43f8fda..97ad4b70794135a2 100644
abe59f
--- a/sysdeps/ia64/dl-lookupcfg.h
abe59f
+++ b/sysdeps/ia64/dl-lookupcfg.h
abe59f
@@ -74,3 +74,6 @@ extern void attribute_hidden _dl_unmap (struct link_map *map);
abe59f
 
abe59f
 #define DL_FIXUP_VALUE_ADDR(value) ((uintptr_t) &(value))
abe59f
 #define DL_FIXUP_ADDR_VALUE(addr) (*(struct fdesc *) (addr))
abe59f
+#define DL_FIXUP_BINDNOW_ADDR_VALUE(addr) (addr)
abe59f
+#define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value) \
abe59f
+  (*value) = *(struct fdesc *) (st_value)
abe59f
diff --git a/sysdeps/powerpc/dl-lookupcfg.h b/sysdeps/powerpc/dl-lookupcfg.h
abe59f
new file mode 100644
abe59f
index 0000000000000000..25abcc1d12b15bfc
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/powerpc/dl-lookupcfg.h
abe59f
@@ -0,0 +1,39 @@
abe59f
+/* Configuration of lookup functions.  PowerPC version.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#define DL_FIXUP_VALUE_TYPE ElfW(Addr)
abe59f
+#define DL_FIXUP_MAKE_VALUE(map, addr) (addr)
abe59f
+#define DL_FIXUP_VALUE_CODE_ADDR(value) (value)
abe59f
+#define DL_FIXUP_VALUE_ADDR(value) (value)
abe59f
+#define DL_FIXUP_ADDR_VALUE(addr) (addr)
abe59f
+#if __WORDSIZE == 64 && _CALL_ELF == 1
abe59f
+/* We need to correctly set the audit modules value for bind-now.  */
abe59f
+# define DL_FIXUP_BINDNOW_ADDR_VALUE(addr) \
abe59f
+ (((Elf64_FuncDesc *)(addr))->fd_func)
abe59f
+# define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value)	\
abe59f
+ ({								\
abe59f
+    Elf64_FuncDesc *opd = (Elf64_FuncDesc *) (value);		\
abe59f
+    opd->fd_func = (st_value);					\
abe59f
+    if ((new_value) != (uintptr_t) (st_value))			\
abe59f
+     opd->fd_toc = ((Elf64_FuncDesc *)(new_value))->fd_toc;	\
abe59f
+  })
abe59f
+#else
abe59f
+# define DL_FIXUP_BINDNOW_ADDR_VALUE(addr) (addr)
abe59f
+# define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value)	\
abe59f
+  (*value) = st_value;
abe59f
+#endif