b1dca6
commit b2af6fb2ed23930c148bae382ca85fad4d1cf32e
b1dca6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
b1dca6
Date:   Tue Apr 30 16:11:57 2019 -0300
b1dca6
b1dca6
    elf: Fix elf/tst-pldd with --enable-hardcoded-path-in-tests (BZ#24506)
b1dca6
    
b1dca6
    The elf/tst-pldd (added by 1a4c27355e146 to fix BZ#18035) test does
b1dca6
    not expect the hardcoded paths that are output by pldd when the test
b1dca6
    is built with --enable-hardcoded-path-in-tests.  Instead of showing
b1dca6
    the ABI installed library names for loader and libc (such as
b1dca6
    ld-linux-x86-64.so.2 and libc.so.6 for x86_64), pldd shows the default
b1dca6
    built ld.so and libc.so.
b1dca6
    
b1dca6
    It makes the tests fail with an invalid expected loader/libc name.
b1dca6
    
b1dca6
    This patch fixes the elf-pldd test by adding the canonical ld.so and
b1dca6
    libc.so names in the expected list of possible outputs when parsing
b1dca6
    the result output from pldd.  The test now handles both default
b1dca6
    build and --enable-hardcoded-path-in-tests option.
b1dca6
    
b1dca6
    Checked on x86_64-linux-gnu (built with and without
b1dca6
    --enable-hardcoded-path-in-tests) and i686-linux-gnu.
b1dca6
    
b1dca6
            * elf/tst-pldd.c (in_str_list): New function.
b1dca6
            (do_test): Add default names for ld and libc as one option.
b1dca6
    
b1dca6
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
b1dca6
b1dca6
Conflicts:
b1dca6
	elf/tst-pldd.c
b1dca6
	  (Original backport uses spaces instead of tabs.)
b1dca6
b1dca6
diff --git a/elf/tst-pldd.c b/elf/tst-pldd.c
b1dca6
index 0f51c95935ffb2cf..40abee9efb9e7484 100644
b1dca6
--- a/elf/tst-pldd.c
b1dca6
+++ b/elf/tst-pldd.c
b1dca6
@@ -20,7 +20,6 @@
b1dca6
 #include <string.h>
b1dca6
 #include <unistd.h>
b1dca6
 #include <stdint.h>
b1dca6
-#include <libgen.h>
b1dca6
 #include <stdbool.h>
b1dca6
 
b1dca6
 #include <array_length.h>
b1dca6
@@ -39,6 +38,15 @@ target_process (void *arg)
b1dca6
 /* The test runs in a container because pldd does not support tracing
b1dca6
    a binary started by the loader iself (as with testrun.sh).  */
b1dca6
 
b1dca6
+static bool
b1dca6
+in_str_list (const char *libname, const char *const strlist[])
b1dca6
+{
b1dca6
+  for (const char *const *str = strlist; *str != NULL; str++)
b1dca6
+    if (strcmp (libname, *str) == 0)
b1dca6
+      return true;
b1dca6
+  return false;
b1dca6
+}
b1dca6
+
b1dca6
 static int
b1dca6
 do_test (void)
b1dca6
 {
b1dca6
@@ -82,26 +90,32 @@ do_test (void)
b1dca6
       {
b1dca6
        /* Ignore vDSO.  */
b1dca6
         if (buffer[0] != '/')
b1dca6
-         continue;
b1dca6
-
b1dca6
-       /* Remove newline so baseline (buffer) can compare against the
b1dca6
-          LD_SO and LIBC_SO macros unmodified.  */
b1dca6
-       if (buffer[strlen(buffer)-1] == '\n')
b1dca6
-         buffer[strlen(buffer)-1] = '\0';
b1dca6
-
b1dca6
-       if (strcmp (basename (buffer), LD_SO) == 0)
b1dca6
-         {
b1dca6
-           TEST_COMPARE (interpreter_found, false);
b1dca6
-           interpreter_found = true;
b1dca6
-           continue;
b1dca6
-         }
b1dca6
-
b1dca6
-       if (strcmp (basename (buffer), LIBC_SO) == 0)
b1dca6
-         {
b1dca6
-           TEST_COMPARE (libc_found, false);
b1dca6
-           libc_found = true;
b1dca6
-           continue;
b1dca6
-         }
b1dca6
+	  continue;
b1dca6
+
b1dca6
+	/* Remove newline so baseline (buffer) can compare against the
b1dca6
+	   LD_SO and LIBC_SO macros unmodified.  */
b1dca6
+	if (buffer[strlen(buffer)-1] == '\n')
b1dca6
+	  buffer[strlen(buffer)-1] = '\0';
b1dca6
+
b1dca6
+	const char *libname = basename (buffer);
b1dca6
+
b1dca6
+	/* It checks for default names in case of build configure with
b1dca6
+	   --enable-hardcoded-path-in-tests (BZ #24506).  */
b1dca6
+	if (in_str_list (libname,
b1dca6
+			 (const char *const []) { "ld.so", LD_SO, NULL }))
b1dca6
+	  {
b1dca6
+	    TEST_COMPARE (interpreter_found, false);
b1dca6
+	    interpreter_found = true;
b1dca6
+	    continue;
b1dca6
+	  }
b1dca6
+
b1dca6
+	if (in_str_list (libname,
b1dca6
+			 (const char *const []) { "libc.so", LIBC_SO, NULL }))
b1dca6
+	  {
b1dca6
+	    TEST_COMPARE (libc_found, false);
b1dca6
+	    libc_found = true;
b1dca6
+	    continue;
b1dca6
+	  }
b1dca6
       }
b1dca6
     TEST_COMPARE (interpreter_found, true);
b1dca6
     TEST_COMPARE (libc_found, true);