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