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