public inbox for libc-stable@sourceware.org
 help / color / mirror / Atom feed
* [Backport 2.29/2.28] elf: Fix elf/tst-pldd with --enable-hardcoded-path-in-tests (BZ#24506)
@ 2024-05-10 14:52 H.J. Lu
  0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2024-05-10 14:52 UTC (permalink / raw)
  To: libc-stable; +Cc: Adhemerval Zanella, Carlos O'Donell

From: Adhemerval Zanella <adhemerval.zanella@linaro.org>

The elf/tst-pldd (added by 1a4c27355e146 to fix BZ#18035) test does
not expect the hardcoded paths that are output by pldd when the test
is built with --enable-hardcoded-path-in-tests.  Instead of showing
the ABI installed library names for loader and libc (such as
ld-linux-x86-64.so.2 and libc.so.6 for x86_64), pldd shows the default
built ld.so and libc.so.

It makes the tests fail with an invalid expected loader/libc name.

This patch fixes the elf-pldd test by adding the canonical ld.so and
libc.so names in the expected list of possible outputs when parsing
the result output from pldd.  The test now handles both default
build and --enable-hardcoded-path-in-tests option.

Checked on x86_64-linux-gnu (built with and without
--enable-hardcoded-path-in-tests) and i686-linux-gnu.

	* elf/tst-pldd.c (in_str_list): New function.
	(do_test): Add default names for ld and libc as one option.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit b2af6fb2ed23930c148bae382ca85fad4d1cf32e)
---
 elf/tst-pldd.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/elf/tst-pldd.c b/elf/tst-pldd.c
index ed19cedd05..2a9f58936f 100644
--- a/elf/tst-pldd.c
+++ b/elf/tst-pldd.c
@@ -20,7 +20,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdint.h>
-#include <libgen.h>
 #include <stdbool.h>
 
 #include <array_length.h>
@@ -39,6 +38,15 @@ target_process (void *arg)
 /* The test runs in a container because pldd does not support tracing
    a binary started by the loader iself (as with testrun.sh).  */
 
+static bool
+in_str_list (const char *libname, const char *const strlist[])
+{
+  for (const char *const *str = strlist; *str != NULL; str++)
+    if (strcmp (libname, *str) == 0)
+      return true;
+  return false;
+}
+
 static int
 do_test (void)
 {
@@ -89,14 +97,20 @@ do_test (void)
 	if (buffer[strlen(buffer)-1] == '\n')
 	  buffer[strlen(buffer)-1] = '\0';
 
-	if (strcmp (basename (buffer), LD_SO) == 0)
+	const char *libname = basename (buffer);
+
+	/* It checks for default names in case of build configure with
+	   --enable-hardcoded-path-in-tests (BZ #24506).  */
+	if (in_str_list (libname,
+			 (const char *const []) { "ld.so", LD_SO, NULL }))
 	  {
 	    TEST_COMPARE (interpreter_found, false);
 	    interpreter_found = true;
 	    continue;
 	  }
 
-	if (strcmp (basename (buffer), LIBC_SO) == 0)
+	if (in_str_list (libname,
+			 (const char *const []) { "libc.so", LIBC_SO, NULL }))
 	  {
 	    TEST_COMPARE (libc_found, false);
 	    libc_found = true;
-- 
2.45.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-10 14:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-10 14:52 [Backport 2.29/2.28] elf: Fix elf/tst-pldd with --enable-hardcoded-path-in-tests (BZ#24506) H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).