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