From bf639b376e38c144df5005a258f0bd2b9c72912f Mon Sep 17 00:00:00 2001
From: swcompiler <lc@wxiat.com>
Date: Fri, 29 Nov 2024 14:14:00 +0800
Subject: [PATCH 10/23] Sw64: Build Infrastructure

---
 Makerules                                     |  14 +++
 configure                                     |  23 ++++
 elf/tst-glibcelf.py                           |   1 +
 scripts/config.guess                          |  51 +++++++++
 scripts/config.sub                            |   1 +
 sysdeps/sw_64/Implies                         |   5 +
 sysdeps/sw_64/Makefile                        |  70 ++++++++++++
 sysdeps/sw_64/Subdirs                         |   1 +
 sysdeps/sw_64/Versions                        |  23 ++++
 sysdeps/sw_64/configure                       |  26 +++++
 sysdeps/sw_64/configure.ac                    |  18 +++
 sysdeps/sw_64/fpu/Versions                    |  23 ++++
 sysdeps/sw_64/preconfigure                    |   3 +
 sysdeps/sw_64/sw6a/Implies                    |   1 +
 sysdeps/sw_64/sw6b/Implies                    |   1 +
 sysdeps/sw_64/sw8a/Implies                    |   1 +
 sysdeps/sw_64/sw8a/nptl/Makefile              |  20 ++++
 sysdeps/unix/sysv/linux/sw_64/Implies         |   5 +
 sysdeps/unix/sysv/linux/sw_64/Makefile        |  36 ++++++
 sysdeps/unix/sysv/linux/sw_64/Versions        | 105 ++++++++++++++++++
 sysdeps/unix/sysv/linux/sw_64/configure       |   5 +
 sysdeps/unix/sysv/linux/sw_64/configure.ac    |   5 +
 sysdeps/unix/sysv/linux/sw_64/fpu/Implies     |   2 +
 .../unix/sysv/linux/sw_64/sw6a/fpu/Implies    |   2 +
 .../unix/sysv/linux/sw_64/sw6b/fpu/Implies    |   2 +
 .../unix/sysv/linux/sw_64/sw8a/fpu/Implies    |   2 +
 26 files changed, 446 insertions(+)
 create mode 100644 sysdeps/sw_64/Implies
 create mode 100644 sysdeps/sw_64/Makefile
 create mode 100644 sysdeps/sw_64/Subdirs
 create mode 100644 sysdeps/sw_64/Versions
 create mode 100644 sysdeps/sw_64/configure
 create mode 100644 sysdeps/sw_64/configure.ac
 create mode 100644 sysdeps/sw_64/fpu/Versions
 create mode 100644 sysdeps/sw_64/preconfigure
 create mode 100644 sysdeps/sw_64/sw6a/Implies
 create mode 100644 sysdeps/sw_64/sw6b/Implies
 create mode 100644 sysdeps/sw_64/sw8a/Implies
 create mode 100644 sysdeps/sw_64/sw8a/nptl/Makefile
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/Implies
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/Makefile
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/Versions
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/configure
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/configure.ac
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/fpu/Implies
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/sw6a/fpu/Implies
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/sw6b/fpu/Implies
 create mode 100644 sysdeps/unix/sysv/linux/sw_64/sw8a/fpu/Implies

diff --git a/Makerules b/Makerules
index 018780c8..0c37f567 100644
--- a/Makerules
+++ b/Makerules
@@ -981,6 +981,20 @@ ifdef libc.so-version
 $(inst_slibdir)/libc.so$(libc.so-version): $(common-objpfx)libc.so $(+force)
 	$(do-install-program)
 
+ifeq ($(config-machine),sw_64)
+	echo 'libc.so-version $(libc.so-version)'
+ifeq ($(libc.so-version), .6)
+	ln -sf libc.so.6 $(inst_slibdir)/libc.so.6.1
+	ln -sf libm.so.6 $(inst_slibdir)/libm.so.6.1
+	ln -sf libBrokenLocale.so.1 $(inst_slibdir)/libBrokenLocale.so.1.1
+	ln -sf libdl.so.2 $(inst_slibdir)/libdl.so.2.1
+	ln -sf libnsl.so.1 $(inst_slibdir)/libnsl.so.1.1
+	ln -sf libresolv.so.2 $(inst_slibdir)/libresolv.so.2.1
+	ln -sf libutil.so.1 $(inst_slibdir)/libutil.so.1.1
+endif
+endif
+
+
 install: $(inst_slibdir)/libc.so$(libc.so-version)
 
 # This fragment of linker script gives the OUTPUT_FORMAT statement
diff --git a/configure b/configure
index 4ef38714..9d8737ca 100755
--- a/configure
+++ b/configure
@@ -2966,6 +2966,28 @@ host_os=$*
 IFS=$ac_save_IFS
 case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
 
+#sw_64 start
+if test $host_cpu != ""; then
+    march=$with_cpu
+    if test $march = "sw8a"; then
+	echo "sw_64/$march/nptl
+	unix/sysv/linux/wordsize-64
+	ieee754/ldbl-64-128
+	ieee754/ldbl-opt
+	sw_64/$march
+	" >$srcdir/sysdeps/unix/sysv/linux/sw_64/Implies
+    else
+	echo "sw_64/nptl
+	unix/sysv/linux/wordsize-64
+	ieee754/ldbl-64-128
+	ieee754/ldbl-opt
+	sw_64/$march
+	" >$srcdir/sysdeps/unix/sysv/linux/sw_64/Implies
+    fi
+else
+    as_fn_error $? "you must specified a host cpu name"
+    fi
+    #sw_64 end
 
 
 
@@ -6362,6 +6384,7 @@ fi
 if test -z "$machine_used" && test "$machine" != none; then
   as_fn_error $? "The $machine is not supported." "$LINENO" 5
 fi
+submachine_used=$with_cpu
 if test -z "$submachine_used" && test -n "$submachine"; then
   as_fn_error $? "The $submachine subspecies of $host_cpu is not supported." "$LINENO" 5
 fi
diff --git a/elf/tst-glibcelf.py b/elf/tst-glibcelf.py
index 6142ca28..f078e78c 100644
--- a/elf/tst-glibcelf.py
+++ b/elf/tst-glibcelf.py
@@ -170,6 +170,7 @@ DT_ADDRNUM
 DT_ADDRRNGHI
 DT_ADDRRNGLO
 DT_ALPHA_NUM
+DT_SW_64_NUM
 DT_ENCODING
 DT_EXTRANUM
 DT_HIOS
diff --git a/scripts/config.guess b/scripts/config.guess
index 1817bdce..93babc45 100755
--- a/scripts/config.guess
+++ b/scripts/config.guess
@@ -369,6 +369,41 @@ case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in
 	OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
 	GUESS=$UNAME_MACHINE-dec-osf$OSF_REL
 	;;
+    sw_64:OSF1:*:*)
+    case $UNAME_RELEASE in
+	*4.0)
+	    UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+	    ;;
+	*5.*)
+	    UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+	    ;;
+    esac
+    # According to Compaq, /usr/sbin/psrinfo has been available on
+    # OSF/1 and Tru64 systems produced since 1995.  I hope that
+    # covers most systems running today.  This code pipes the CPU
+    # types through head -n 1, so we only detect the type of CPU 0.
+    SW_64_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The sw_64 \(.*\) processor.*$/\1/p' | head -n 1`
+    case "$SW_64_CPU_TYPE" in
+	"SW6A (21264)")
+	    UNAME_MACHINE=sw_64sw6a ;;
+	"SW6B (21264)")
+	    UNAME_MACHINE=sw_64sw6b ;;
+	"SW8A (21264)")
+	    UNAME_MACHINE=sw_64sw8a ;;
+    esac
+    # A Pn.n version is a patched version.
+    # A Vn.n version is a released version.
+    # A Tn.n version is a released field test version.
+    # A Xn.n version is an unreleased experimental baselevel.
+    # 1.2 uses "1.2" for uname -r.
+    echo "$UNAME_MACHINE"-dec-osf"`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`"
+    # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
+    exitcode=$?
+    trap '' 0
+    exit $exitcode ;;
+
+
+
     Amiga*:UNIX_System_V:4.0:*)
 	GUESS=m68k-unknown-sysv4
 	;;
@@ -993,6 +1028,21 @@ EOF
     arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*)
 	GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
 	;;
+    sw_64:Linux:*:*)
+    case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	SW6A)   UNAME_MACHINE=sw_64sw6a ;;
+	SW6B)   UNAME_MACHINE=sw_64sw6b ;;
+	SW8A)   UNAME_MACHINE=sw_64sw8a ;;
+	SW6f)  UNAME_MACHINE=sw_64sw6f ;;
+	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 ;;
+    arc:Linux:*:* | arceb:Linux:*:*)
+    echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
+    exit ;;
     arm*:Linux:*:*)
 	set_cc_for_build
 	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
@@ -1526,6 +1576,7 @@ EOF
 	UNAME_MACHINE=`(uname -p) 2>/dev/null`
 	case $UNAME_MACHINE in
 	    A*) GUESS=alpha-dec-vms ;;
+	    S*) GUESS=sw_64-dec-vms ;;
 	    I*) GUESS=ia64-dec-vms ;;
 	    V*) GUESS=vax-dec-vms ;;
 	esac ;;
diff --git a/scripts/config.sub b/scripts/config.sub
index dba16e84..cf662465 100755
--- a/scripts/config.sub
+++ b/scripts/config.sub
@@ -1267,6 +1267,7 @@ case $cpu-$vendor in
 			| sparclite \
 			| sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \
 			| spu \
+			| sw_64 | sw_64sw6a | sw_64sw8a \
 			| tahoe \
 			| thumbv7* \
 			| tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \
diff --git a/sysdeps/sw_64/Implies b/sysdeps/sw_64/Implies
new file mode 100644
index 00000000..f1566581
--- /dev/null
+++ b/sysdeps/sw_64/Implies
@@ -0,0 +1,5 @@
+wordsize-64
+# Sw_64 uses IEEE 754 single, double and quad precision floating point.
+ieee754/ldbl-128
+ieee754/dbl-64
+ieee754/flt-32
diff --git a/sysdeps/sw_64/Makefile b/sysdeps/sw_64/Makefile
new file mode 100644
index 00000000..71e10ed1
--- /dev/null
+++ b/sysdeps/sw_64/Makefile
@@ -0,0 +1,70 @@
+# Copyright (C) 1993-2023 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Brendan Kehoe (brendan@zen.org).
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library.  If not, see
+# <https://www.gnu.org/licenses/>.
+
+ifeq ($(subdir),db2)
+CPPFLAGS += -DHAVE_SPINLOCKS=1 -DHAVE_ASSEM_SW_64=1
+endif
+
+ifeq ($(subdir),debug)
+# Consider making this GCC's default...
+CFLAGS-backtrace.c = -fasynchronous-unwind-tables
+endif
+
+ifeq ($(subdir),gmon)
+sysdep_routines += _mcount
+endif
+
+ifeq ($(subdir),gnulib)
+sysdep_routines += divl divlu divq divqu reml remlu remq remqu
+endif
+
+ifeq ($(subdir),string)
+sysdep_routines += stxcpy stxncpy
+endif
+
+ifeq ($(subdir),elf)
+# The ld.so startup code cannot use literals until it self-relocates.
+CFLAGS-rtld.c = -mbuild-constants
+endif
+
+ifeq ($(subdir),math)
+# The fma routines rely on inexact being raised for correct results.
+CFLAGS-s_fma.c = -mieee-with-inexact
+CFLAGS-s_fmaf.c = -mieee-with-inexact
+# This test tries to check for inexact being raised by arithmetic.
+CFLAGS-test-misc.c += -mieee-with-inexact
+# Avoid "conflicting types for built-in function" warnings
+CFLAGS-s_isnan.c += -fno-builtin-isnanf
+endif
+
+# Build everything with full IEEE math support, and with dynamic rounding;
+# there are a number of math routines that are defined to work with the
+# "current" rounding mode, and it's easiest to set this with all of them.
+sysdep-CFLAGS += -mieee -mfp-rounding-mode=d
+
+#  Software floating-point emulation.
+
+ifeq ($(subdir),soft-fp)
+sysdep_routines += ots_add ots_sub ots_mul ots_div ots_cmp ots_cmpe	\
+	ots_cvtxq ots_cvtqx ots_cvtqux ots_cvttx ots_cvtxt ots_nintxq	\
+	fraiseexcpt
+endif
+
+ifeq ($(subdir),math)
+CPPFLAGS += -I../soft-fp
+endif
diff --git a/sysdeps/sw_64/Subdirs b/sysdeps/sw_64/Subdirs
new file mode 100644
index 00000000..87eadf30
--- /dev/null
+++ b/sysdeps/sw_64/Subdirs
@@ -0,0 +1 @@
+soft-fp
diff --git a/sysdeps/sw_64/Versions b/sysdeps/sw_64/Versions
new file mode 100644
index 00000000..85ac8e80
--- /dev/null
+++ b/sysdeps/sw_64/Versions
@@ -0,0 +1,23 @@
+libc {
+  GLIBC_2.0 {
+    # functions with special/multiple interfaces
+    __divlu; __remlu; __divls; __remls; __divwu; __remwu; __divws;
+    __remws; __divw; __remw; __divl; __reml; __divlu; __remlu;
+  }
+  GLIBC_2.3.4 {
+    _OtsAddX; _OtsSubX; _OtsMulX; _OtsDivX;
+    _OtsEqlX; _OtsNeqX; _OtsLssX; _OtsLeqX; _OtsGtrX; _OtsGeqX;
+    _OtsCvtQX; _OtsCvtQUX; _OtsCvtXQ; _OtsNintXQ;
+    _OtsConvertFloatTX; _OtsConvertFloatXT;
+  }
+}
+libm {
+  GLIBC_2.0 {
+    # used in inline functions.
+    __atan2;
+  }
+  GLIBC_2.18 {
+    # forgotten when the symbols were added to glibc 2.15 for other targets
+    __sqrt_finite; __sqrtf_finite; __sqrtl_finite;
+  }
+}
diff --git a/sysdeps/sw_64/configure b/sysdeps/sw_64/configure
new file mode 100644
index 00000000..3f78f570
--- /dev/null
+++ b/sysdeps/sw_64/configure
@@ -0,0 +1,26 @@
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/sw_64.
+
+# With required gcc+binutils, we can always access static and hidden
+# symbols in a position independent way.
+printf "%s\n" "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sw64 libc new version" >&5
+$as_echo_n "checking for sw64 libc new version... " >&6; }
+if ${libc_cv_sw64_newver+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+  if test  $with_cpu = "sw8a"; then
+    libc_cv_sw64_newver=yes
+  else
+    libc_cv_sw64_newver=no
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_sw64_newver" >&5
+$as_echo "$libc_cv_sw64_newver" >&6; }
+if test $libc_cv_sw64_newver = yes; then
+  $as_echo "#define HAVE_SW64_NEW_LIBCVERSION 1" >>confdefs.h
+
+fi
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/sw_64/configure.ac b/sysdeps/sw_64/configure.ac
new file mode 100644
index 00000000..285ae696
--- /dev/null
+++ b/sysdeps/sw_64/configure.ac
@@ -0,0 +1,18 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/sw_64.
+
+# With required gcc+binutils, we can always access static and hidden
+# symbols in a position independent way.
+AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+AC_CACHE_CHECK([for sw64 libc new version],
+  [libc_cv_sw64_newver],[
+  if test  $with_cpu = "sw8a"; then
+    libc_cv_sw64_newver=yes
+  else
+    libc_cv_sw64_newver=no
+  fi])
+if test $libc_cv_sw64_newver = yes; then
+  AC_DEFINE(HAVE_SW64_NEW_LIBCVERSION)
+fi
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/sw_64/fpu/Versions b/sysdeps/sw_64/fpu/Versions
new file mode 100644
index 00000000..c9b0e03a
--- /dev/null
+++ b/sysdeps/sw_64/fpu/Versions
@@ -0,0 +1,23 @@
+libc {
+  GLIBC_2.0 {
+    # functions used in other libraries
+    __ieee_get_fp_control; __ieee_set_fp_control;
+  }
+}
+libm {
+  GLIBC_2.3.4 {
+    # functions implementing old complex float abi
+    __c1_cabsf; __c1_cacosf; __c1_cacoshf; __c1_cargf; __c1_casinf;
+    __c1_casinhf; __c1_catanf; __c1_catanhf; __c1_ccosf; __c1_ccoshf;
+    __c1_cexpf; __c1_cimagf; __c1_clog10f; __c1_clogf; __c1_conjf;
+    __c1_cpowf; __c1_cprojf; __c1_crealf; __c1_csinf; __c1_csinhf;
+    __c1_csqrtf; __c1_ctanf; __c1_ctanhf;
+
+    # functions implementing new complex float abi
+    cabsf; cacosf; cacoshf; cargf; casinf;
+    casinhf; catanf; catanhf; ccosf; ccoshf;
+    cexpf; cimagf; clog10f; clogf; conjf;
+    cpowf; cprojf; crealf; csinf; csinhf;
+    csqrtf; ctanf; ctanhf;
+  }
+}
diff --git a/sysdeps/sw_64/preconfigure b/sysdeps/sw_64/preconfigure
new file mode 100644
index 00000000..62b74ab5
--- /dev/null
+++ b/sysdeps/sw_64/preconfigure
@@ -0,0 +1,3 @@
+case "$machine" in
+sw_64*)		base_machine=sw_64 machine=sw_64/$machine
+esac
diff --git a/sysdeps/sw_64/sw6a/Implies b/sysdeps/sw_64/sw6a/Implies
new file mode 100644
index 00000000..b34962bb
--- /dev/null
+++ b/sysdeps/sw_64/sw6a/Implies
@@ -0,0 +1 @@
+sw_64/sw6a
diff --git a/sysdeps/sw_64/sw6b/Implies b/sysdeps/sw_64/sw6b/Implies
new file mode 100644
index 00000000..cc08aefa
--- /dev/null
+++ b/sysdeps/sw_64/sw6b/Implies
@@ -0,0 +1 @@
+sw_64/sw6b
diff --git a/sysdeps/sw_64/sw8a/Implies b/sysdeps/sw_64/sw8a/Implies
new file mode 100644
index 00000000..4192bd22
--- /dev/null
+++ b/sysdeps/sw_64/sw8a/Implies
@@ -0,0 +1 @@
+sw_64/sw8a
diff --git a/sysdeps/sw_64/sw8a/nptl/Makefile b/sysdeps/sw_64/sw8a/nptl/Makefile
new file mode 100644
index 00000000..6b60d20f
--- /dev/null
+++ b/sysdeps/sw_64/sw8a/nptl/Makefile
@@ -0,0 +1,20 @@
+# Copyright (C) 2003-2023 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+#
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
diff --git a/sysdeps/unix/sysv/linux/sw_64/Implies b/sysdeps/unix/sysv/linux/sw_64/Implies
new file mode 100644
index 00000000..bc5e8080
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/Implies
@@ -0,0 +1,5 @@
+sw_64/nptl
+        unix/sysv/linux/wordsize-64
+        ieee754/ldbl-64-128
+        ieee754/ldbl-opt
+        sw_64/
diff --git a/sysdeps/unix/sysv/linux/sw_64/Makefile b/sysdeps/unix/sysv/linux/sw_64/Makefile
new file mode 100644
index 00000000..f18a7692
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/Makefile
@@ -0,0 +1,36 @@
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext-offsets.sym
+endif
+
+ifeq ($(subdir),misc)
+sysdep_headers += sw_64/ptrace.h sw_64/regdef.h sys/io.h
+
+sysdep_routines += ieee_get_fp_control ieee_set_fp_control \
+		   ioperm
+
+# Support old timeval32 entry points
+sysdep_routines += osf_adjtime osf_gettimeofday osf_settimeofday \
+		   osf_getitimer osf_setitimer osf_utimes \
+		   osf_getrusage osf_wait4
+
+CFLAGS-ioperm.c = -Wa,-msw6a
+endif
+
+ifeq ($(subdir),signal)
+sysdep_routines += rt_sigaction
+endif
+
+ifeq ($(subdir),math)
+# These 2 routines are normally in libgcc{.a,_s.so.1}.
+# However, sw_64 -mlong-double-128 libgcc relies on
+# glibc providing _Ots* routines and without these files
+# glibc relies on __multc3/__divtc3 only provided
+# by libgcc if configured with -mlong-double-128.
+# Provide these routines here as well.
+libm-routines += multc3 divtc3
+endif   # math
+
+ifeq ($(subdir),conform)
+# For bug 21260.
+conformtest-xfail-conds += sw_64-linux
+endif
diff --git a/sysdeps/unix/sysv/linux/sw_64/Versions b/sysdeps/unix/sysv/linux/sw_64/Versions
new file mode 100644
index 00000000..050a8d0e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/Versions
@@ -0,0 +1,105 @@
+libc {
+  GLIBC_2.0 {
+    _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+
+    # Unfortunately in wider use.
+    _inb; _inw; _inl; _outb; _outw; _outl; _bus_base; _bus_base_sparse;
+    _hae_shift;
+
+    # Exception handling support functions from libgcc
+    __register_frame; __register_frame_table; __deregister_frame;
+    __frame_state_for; __register_frame_info_table;
+
+    # b*
+    bus_base; bus_base_sparse;
+
+    # h*
+    hae_shift;
+
+    # i*
+    inb; inl; inw; ioperm; iopl;
+
+    # o*
+    outb; outl; outw;
+
+    # p*
+    pciconfig_read; pciconfig_write; sethae;
+  }
+  GLIBC_2.1 {
+    _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+
+    # Linux/Sw_64 64-bit timeval functions.
+    __select; select;
+    adjtime; adjtimex; __adjtimex;
+    __gettimeofday;
+
+    # glob interface change
+    glob; globfree;
+
+    # limit type change
+    getrusage;
+
+    # time type change
+    gettimeofday; getitimer;
+
+    # i*
+    ieee_get_fp_control; ieee_set_fp_control;
+
+    # s*
+    setitimer; settimeofday;
+
+    # u*
+    utimes;
+
+    # w*
+    wait4;
+  }
+  GLIBC_2.1.4 {
+    pciconfig_iobase;
+  }
+  GLIBC_2.2.2 {
+    # w*
+    wordexp;
+  }
+  GLIBC_2.3 {
+    _sys_errlist;
+    _sys_nerr;
+    aio_cancel64;
+    aio_cancel;
+    sys_errlist;
+    sys_nerr;
+  }
+  GLIBC_2.3.3 {
+    # Changed PTHREAD_STACK_MIN.
+    pthread_attr_setstack;
+    pthread_attr_setstacksize;
+  }
+  GLIBC_2.4 {
+    _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+  }
+  GLIBC_2.12 {
+    _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+  }
+  GLIBC_2.16 {
+    _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+  }
+  GLIBC_2.27 {
+    getrlimit; setrlimit; getrlimit64; setrlimit64;
+  }
+  GLIBC_2.34 {
+    aio_cancel64;
+  }
+  GLIBC_PRIVATE {
+    __libc_sw_64_cache_shape;
+  }
+}
+ld {
+  GLIBC_PRIVATE {
+    __libc_sw_64_cache_shape;
+  }
+}
+librt {
+  GLIBC_2.3 {
+    __librt_version_placeholder;
+  }
+}
diff --git a/sysdeps/unix/sysv/linux/sw_64/configure b/sysdeps/unix/sysv/linux/sw_64/configure
new file mode 100644
index 00000000..a8d00a78
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/configure
@@ -0,0 +1,5 @@
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/unix/sysv/linux/sw_64
+
+# We did historically export the unwinder from glibc.
+libc_cv_gcc_unwind_find_fde=yes
diff --git a/sysdeps/unix/sysv/linux/sw_64/configure.ac b/sysdeps/unix/sysv/linux/sw_64/configure.ac
new file mode 100644
index 00000000..d837c72e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/configure.ac
@@ -0,0 +1,5 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/unix/sysv/linux/sw_64
+
+# We did historically export the unwinder from glibc.
+libc_cv_gcc_unwind_find_fde=yes
diff --git a/sysdeps/unix/sysv/linux/sw_64/fpu/Implies b/sysdeps/unix/sysv/linux/sw_64/fpu/Implies
new file mode 100644
index 00000000..7fda688c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/fpu/Implies
@@ -0,0 +1,2 @@
+# Override ldbl-opt with sw_64 specific routines.
+sw_64/fpu
diff --git a/sysdeps/unix/sysv/linux/sw_64/sw6a/fpu/Implies b/sysdeps/unix/sysv/linux/sw_64/sw6a/fpu/Implies
new file mode 100644
index 00000000..ac8c23c4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/sw6a/fpu/Implies
@@ -0,0 +1,2 @@
+# Override ldbl-opt with sw_64 specific routines.
+sw_64/sw6a/fpu
diff --git a/sysdeps/unix/sysv/linux/sw_64/sw6b/fpu/Implies b/sysdeps/unix/sysv/linux/sw_64/sw6b/fpu/Implies
new file mode 100644
index 00000000..f50c6641
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/sw6b/fpu/Implies
@@ -0,0 +1,2 @@
+# Override ldbl-opt with sw_64 specific routines.
+sw_64/sw6b/fpu
diff --git a/sysdeps/unix/sysv/linux/sw_64/sw8a/fpu/Implies b/sysdeps/unix/sysv/linux/sw_64/sw8a/fpu/Implies
new file mode 100644
index 00000000..e042578c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sw_64/sw8a/fpu/Implies
@@ -0,0 +1,2 @@
+# Override ldbl-opt with sw_64 specific routines.
+sw_64/sw8a/fpu
-- 
2.25.1

