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