8a8cfb
commit 7db1fe38de21831d53ceab9ae83493d8d1aec601
8a8cfb
Author: Joseph Myers <joseph@codesourcery.com>
8a8cfb
Date:   Tue Oct 22 20:24:10 2019 +0000
8a8cfb
8a8cfb
    Fix testroot.pristine creation copying dynamic linker.
8a8cfb
    
8a8cfb
    This patch addresses an issue reported in
8a8cfb
    <https://sourceware.org/ml/libc-alpha/2019-07/msg00661.html> where the
8a8cfb
    creation of testroot.pristine, on encountering
8a8cfb
    LD_TRACE_LOADED_OBJECTS=1 of the form
8a8cfb
    
8a8cfb
            libc.so.6 => /scratch/jmyers/glibc/mbs/obj/glibc-8-0-mips64-linux-gnu-x86_64-linux-gnu/default/libc.so.6 (0x772dd000)
8a8cfb
            /lib32/ld.so.1 => /scratch/jmyers/glibc/mbs/obj/glibc-8-0-mips64-linux-gnu-x86_64-linux-gnu/default/elf/ld.so.1 (0x7747b000)
8a8cfb
    
8a8cfb
    tries to copy /lib32/ld.so.1 (which does not exist) into the testroot
8a8cfb
    instead of copying the path on the RHS of "=>", which does exist,
8a8cfb
    because the Makefile logic assumes that the path on such a line with
8a8cfb
    '/' should be copied, when if there are such paths on both the LHS and
8a8cfb
    the RHS of "=>", only the one on the RHS necessarily exists and so
8a8cfb
    only that should be copied.  The patch follows the approach suggested
8a8cfb
    by DJ in <https://sourceware.org/ml/libc-alpha/2019-07/msg00662.html>,
8a8cfb
    with the suggestion from Andreas in
8a8cfb
    <https://sourceware.org/ml/libc-alpha/2019-10/msg00514.html> of a
8a8cfb
    single sed command in place of pipeline of grep and three sed
8a8cfb
    commands.
8a8cfb
    
8a8cfb
    Tested for x86_64, with and without --enable-hardcoded-path-in-tests;
8a8cfb
    a previous version with multiple sed commands, implementing the same
8a8cfb
    logic, also tested for MIPS, with and without
8a8cfb
    --enable-hardcoded-path-in-tests, to confirm it fixes the original
8a8cfb
    problem.
8a8cfb
    
8a8cfb
    Co-authored-by: DJ Delorie <dj@redhat.com>
8a8cfb
8a8cfb
diff --git a/Makefile b/Makefile
8a8cfb
index d7e4be9..0711b97 100644
8a8cfb
--- a/Makefile
8a8cfb
+++ b/Makefile
8a8cfb
@@ -564,7 +564,7 @@ ifeq ($(run-built-tests),yes)
8a8cfb
 	for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1  \
8a8cfb
 		$(rtld-prefix) \
8a8cfb
 		$(objpfx)testroot.pristine/bin/sh \
8a8cfb
-	        | grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
8a8cfb
+	        | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
8a8cfb
 	  do \
8a8cfb
 	    test -d `dirname $(objpfx)testroot.pristine$$dso` || \
8a8cfb
 	      mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
8a8cfb
@@ -573,7 +573,7 @@ ifeq ($(run-built-tests),yes)
8a8cfb
 	for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1  \
8a8cfb
 		$(rtld-prefix) \
8a8cfb
 		$(objpfx)support/$(LINKS_DSO_PROGRAM) \
8a8cfb
-	        | grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
8a8cfb
+	        | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
8a8cfb
 	  do \
8a8cfb
 	    test -d `dirname $(objpfx)testroot.pristine$$dso` || \
8a8cfb
 	      mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\