From 775fc036e0091f05ff56e41b855bc416b9ed36c8 Mon Sep 17 00:00:00 2001
From: Boud Roukema <boud@cosmo.torun.pl>
Date: Fri, 1 Oct 2021 03:35:22 +0200
Subject: Configuration: GCC not linking to system libunwind (crashed GCC's
 build)

This commit provides a hack/correction to the unwrapped GCC source files
that sym-links the generic file 'libgcc/unwind-generic.h' to the two
directories in which a file includes "unwind.h" or <unwind.h>. The aim is
that the gcc compilation system uses this header file from the internal gcc
source files instead of searching for a system-level file 'unwind.h'.

This commit also unaliases two 'ls' commands in some build recipes of
'basic.mk' in case the host system (normally at user level) has aliased the
command to something like 'ls -F'. In the situation that sometimes occurs
of library files being given executable status, the '-F' decorative option
could lead to an asterisk being included in a string that is not expected
to contain asterisks. If the system shell does not contain the 'alias'
command at all, then a fallback of 'true' should provide safe
behaviour. The notation of the 'sed' command is also clarified.

This solves bug #61240: https://savannah.nongnu.org/bugs/index.php?61240
---
 reproduce/software/make/basic.mk | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/reproduce/software/make/basic.mk b/reproduce/software/make/basic.mk
index 0d114db..6910593 100644
--- a/reproduce/software/make/basic.mk
+++ b/reproduce/software/make/basic.mk
@@ -461,9 +461,10 @@ $(ibidir)/ncurses-$(ncurses-version): $(ibidir)/patchelf-$(patchelf-version)
 	if [ x$(on_mac_os) = xyes ]; then so="dylib"; else so="so"; fi
 	if [ -f $(ildir)/libncursesw.$$so ]; then
 
+	  unalias ls || true # avoid decorated 'ls' commands with extra characters
 	  sov=$$(ls -l $(ildir)/libncursesw* \
 	               | awk '/^-/{print $$NF}' \
-	               | sed -e's|'$(ildir)/libncursesw.'||')
+	               | sed -e "s;$(ildir)/libncursesw\.;;")
 
 	  cd "$(ildir)"
 	  for lib in ncurses ncurses++ form panel menu; do
@@ -690,6 +691,7 @@ $(ibidir)/coreutils-$(coreutils-version): \
         # Fix RPATH if necessary.
 	if [ -f $(ibdir)/patchelf ]; then
 	  make SHELL=$(ibdir)/bash install DESTDIR=junkinst
+	  unalias ls || true # avoid decorated 'ls' commands with extra characters
 	  instprogs=$$(ls junkinst/$(ibdir))
 	  for f in $$instprogs; do
 	    $(ibdir)/patchelf --set-rpath $(ildir) $(ibdir)/$$f
@@ -1415,6 +1417,13 @@ $(ibidir)/gcc-$(gcc-version): $(ibidir)/binutils-$(binutils-version)
 	    ln -s $$odir/gcc-$(gcc-version) $(ddir)/gcc-$(gcc-version)
 	  fi
 	  cd gcc-$(gcc-version)
+
+          # Handle bug https://savannah.nongnu.org/bugs/index.php?61240 in
+          # which gcc preferentially uses a system-level 'unwind' library
+          # rather than using its own one.
+	  ln -sf ../../libgcc/unwind-generic.h libstdc++-v3/libsupc++/unwind.h
+	  ln -sf ../libgcc/unwind-generic.h libitm/unwind.h
+
 	  mkdir build
 	  cd build
 
-- 
cgit v1.2.1