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