From 70819a18bf9c452d229e587e03b26bfa44f10686 Mon Sep 17 00:00:00 2001
From: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Date: Thu, 8 Aug 2019 14:17:25 +0100
Subject: Static PatchELF only built when static C library exists

Until now, when building PatchELF, we would always require that it be done
statically. However, some systems don't have a static C library available
for linking. This cause a crash in the static building of PatchELF. But a
static PatchELF is necessary for correcting RPATH in GCC's outputs.

With this commit, in the configure script we check if a static C library is
linkable for the compiler. If it isn't then `host_cc' will be set to 1 and
GCC won't be built. We also pass the result of this test to `basic.mk'
(through `good_static_lib'), so if a static C library isn't available, it
builds a dynamically linked PatchELF.

This bug was reported by Elham Saremi.
---
 reproduce/software/make/basic.mk | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

(limited to 'reproduce/software/make')

diff --git a/reproduce/software/make/basic.mk b/reproduce/software/make/basic.mk
index 4e6d5fa..04edf1a 100644
--- a/reproduce/software/make/basic.mk
+++ b/reproduce/software/make/basic.mk
@@ -546,14 +546,17 @@ $(ibidir)/readline: $(tdir)/readline-$(readline-version).tar.gz \
 	                SHLIB_LIBS="-lncursesw" -j$(numthreads)) \
 	&& echo "GNU Readline $(readline-version)" > $@
 
-# Patchelf has to be built statically because it links with the C++
-# standard library. Therefore while fixing rpath in `libstdc++' with
-# Patchelf we can have a segmentation fault. Note that Patchelf is only for
-# GNU/Linux systems, so there is no problem with having the `-static' flag
-# in LDFLAGS.
+# When we have a static C library, PatchELF will be built statically. This
+# is because PatchELF links with the C++ standard library. But we need to
+# run PatchELF later on `libstdc++'! This circular dependency can cause a
+# crash, so when PatchELF can't be built statically, we won't build GCC
+# either, see the `configure.sh' script where we define `good_static_libc'
+# for more.
 $(ibidir)/patchelf: $(tdir)/patchelf-$(patchelf-version).tar.gz \
                     $(ibidir)/make
-	export LDFLAGS="$$LDFLAGS -static"; \
+	if [ $(good_static_libc) = 1 ]; then \
+	  export LDFLAGS="$$LDFLAGS -static"; \
+	fi; \
 	$(call gbuild, $<, patchelf-$(patchelf-version), static) \
 	&& echo "PatchELF $(patchelf-version)" > $@
 
@@ -595,7 +598,7 @@ needpatchelf = $(ibidir)/patchelf
 endif
 $(ibidir)/bash: $(tdir)/bash-$(bash-version).tar.lz \
                 $(ibidir)/readline                  \
-                $(needpatchelf)
+                | $(needpatchelf)
 
         # Delete the (possibly) existing Bash executable.
 	rm -f $(ibdir)/bash
-- 
cgit v1.2.1