From 2f3bec93b49804f8d6651478d1675e8f46668029 Mon Sep 17 00:00:00 2001
From: wangyuhang <wangyuhang27@huawei.com>
Date: Mon, 17 Jul 2023 16:07:51 +0800
Subject: [PATCH] bash-5.1-sw.patch

---
 configure             | 3 ++-
 configure.ac          | 1 +
 general.h             | 2 +-
 lib/intl/dcigettext.c | 2 +-
 m4/host-cpu-c-abi.m4  | 9 +++++++++
 m4/intdiv0.m4         | 2 +-
 support/config.guess  | 8 ++++++++
 support/config.sub    | 1 +
 8 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 4731375..e4c6de3 100755
--- a/configure
+++ b/configure
@@ -3271,6 +3271,7 @@ opt_with_installed_readline=no
 case "${host_cpu}-${host_os}" in
 # mostly obsolete platforms
 alpha*-*)	opt_bash_malloc=no ;;	# alpha running osf/1 or linux
+sw_64*-*)	opt_bash_malloc=no ;;	# sw_64 running osf/1 or linux
 *[Cc]ray*-*)	opt_bash_malloc=no ;;	# Crays
 *-osf1*)	opt_bash_malloc=no ;;	# other osf/1 machines
 *-dgux*)	opt_bash_malloc=no ;;	# DG/UX machines
@@ -8490,7 +8491,7 @@ then :
 
             # Guess based on the CPU.
             case "$host_cpu" in
-              alpha* | i[34567]86 | x86_64 | m68k | s390*)
+              sw_64* | alpha* | i[34567]86 | x86_64 | m68k | s390*)
                 gt_cv_int_divbyzero_sigfpe="guessing yes";;
               *)
                 gt_cv_int_divbyzero_sigfpe="guessing no";;
diff --git a/configure.ac b/configure.ac
index 6619788..5cd5a3c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,7 @@ dnl look in the NOTES file for more
 case "${host_cpu}-${host_os}" in
 # mostly obsolete platforms
 alpha*-*)	opt_bash_malloc=no ;;	# alpha running osf/1 or linux
+sw_64*-*)	opt_bash_malloc=no ;;	# sw_64 running osf/1 or linux
 *[[Cc]]ray*-*)	opt_bash_malloc=no ;;	# Crays
 *-osf1*)	opt_bash_malloc=no ;;	# other osf/1 machines
 *-dgux*)	opt_bash_malloc=no ;;	# DG/UX machines
diff --git a/general.h b/general.h
index 8064c50..2505694 100644
--- a/general.h
+++ b/general.h
@@ -57,7 +57,7 @@
 /* Hardly used anymore */
 #define pointer_to_int(x)	(int)((char *)x - (char *)0)
 
-#if defined (alpha) && defined (__GNUC__) && !defined (strchr) && !defined (__STDC__)
+#if (defined (alpha) || defined (sw_64)) && defined (__GNUC__) && !defined (strchr) && !defined (__STDC__)
 extern char *strchr (), *strrchr ();
 #endif
 
diff --git a/lib/intl/dcigettext.c b/lib/intl/dcigettext.c
index c0f347e..8abf933 100644
--- a/lib/intl/dcigettext.c
+++ b/lib/intl/dcigettext.c
@@ -74,7 +74,7 @@ extern int errno;
 #ifdef _LIBC
   /* Guess whether integer division by zero raises signal SIGFPE.
      Set to 1 only if you know for sure.  In case of doubt, set to 0.  */
-# if defined __alpha__ || defined __arm__ || defined __i386__ \
+# if defined __alpha__ || defined __sw_64__ || defined __arm__ || defined __i386__ \
      || defined __m68k__ || defined __s390__
 #  define INTDIV0_RAISES_SIGFPE 1
 # else
diff --git a/m4/host-cpu-c-abi.m4 b/m4/host-cpu-c-abi.m4
index 4407296..057dfe3 100644
--- a/m4/host-cpu-c-abi.m4
+++ b/m4/host-cpu-c-abi.m4
@@ -90,6 +90,12 @@ changequote([,])dnl
            [gl_cv_host_cpu_c_abi=i386])
          ;;
 
+changequote(,)dnl
+       sw_64* )
+changequote([,])dnl
+         gl_cv_host_cpu_c_abi=sw_64
+         ;;
+
 changequote(,)dnl
        alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] )
 changequote([,])dnl
@@ -355,6 +361,9 @@ EOF
 #ifndef __x86_64__
 #undef __x86_64__
 #endif
+#ifndef __sw_64__
+#undef __sw_64__
+#endif
 #ifndef __alpha__
 #undef __alpha__
 #endif
diff --git a/m4/intdiv0.m4 b/m4/intdiv0.m4
index 40dd43b..198700a 100644
--- a/m4/intdiv0.m4
+++ b/m4/intdiv0.m4
@@ -69,7 +69,7 @@ int main ()
             # Guess based on the CPU.
 changequote(,)dnl
             case "$host_cpu" in
-              alpha* | i[34567]86 | x86_64 | m68k | s390*)
+              sw_64* | alpha* | i[34567]86 | x86_64 | m68k | s390*)
                 gt_cv_int_divbyzero_sigfpe="guessing yes";;
               *)
                 gt_cv_int_divbyzero_sigfpe="guessing no";;
diff --git a/support/config.guess b/support/config.guess
index 7f76b62..f8d09d9 100644
--- a/support/config.guess
+++ b/support/config.guess
@@ -976,6 +976,14 @@ EOF
 	UNAME_MACHINE=aarch64_be
 	GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
 	;;
+    sw_64:Linux:*:*)
+	case $(sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null) in
+	  sw)   UNAME_MACHINE=sw_64 ;;
+	esac
+	objdump --private-headers /bin/sh | grep -q ld.so.1
+	if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
+	echo "$UNAME_MACHINE"-sunway-linux-"$LIBC"
+	exit ;;
     alpha:Linux:*:*)
 	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in
 	  EV5)   UNAME_MACHINE=alphaev5 ;;
diff --git a/support/config.sub b/support/config.sub
index 9b62e37..1dc8d91 100644
--- a/support/config.sub
+++ b/support/config.sub
@@ -1182,6 +1182,7 @@ case $cpu-$vendor in
 			| a29k \
 			| aarch64 | aarch64_be \
 			| abacus \
+			| sw_64 \
 			| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \
 			| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \
 			| alphapca5[67] | alpha64pca5[67] \
-- 
2.33.0

