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