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