diff mbox series

[v2,12/14] LoongArch: Build Infastructure

Message ID 20211231064455.1030051-13-caiyinyu@loongson.cn
State New
Headers show
Series GLIBC LoongArch PATCHES | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

caiyinyu Dec. 31, 2021, 6:44 a.m. UTC
---
 sysdeps/loongarch/Implies                     |   5 +
 sysdeps/loongarch/Makefile                    |  15 ++
 sysdeps/loongarch/configure                   |   4 +
 sysdeps/loongarch/configure.ac                |   6 +
 sysdeps/loongarch/lp64/Implies-after          |   1 +
 sysdeps/loongarch/nptl/Makefile               |  26 +++
 sysdeps/loongarch/preconfigure                |  47 +++++
 sysdeps/loongarch/sys/regdef.h                |  98 +++++++++
 sysdeps/unix/sysv/linux/loongarch/Implies     |   1 +
 sysdeps/unix/sysv/linux/loongarch/Makefile    |  11 +
 sysdeps/unix/sysv/linux/loongarch/configure   | 199 ++++++++++++++++++
 .../unix/sysv/linux/loongarch/configure.ac    |  27 +++
 .../unix/sysv/linux/loongarch/ldd-rewrite.sed |   3 +
 .../unix/sysv/linux/loongarch/lp64/Implies    |   3 +
 .../unix/sysv/linux/loongarch/shlib-versions  |   7 +
 15 files changed, 453 insertions(+)
 create mode 100644 sysdeps/loongarch/Implies
 create mode 100644 sysdeps/loongarch/Makefile
 create mode 100644 sysdeps/loongarch/configure
 create mode 100644 sysdeps/loongarch/configure.ac
 create mode 100644 sysdeps/loongarch/lp64/Implies-after
 create mode 100644 sysdeps/loongarch/nptl/Makefile
 create mode 100644 sysdeps/loongarch/preconfigure
 create mode 100644 sysdeps/loongarch/sys/regdef.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/Implies
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/Makefile
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/configure
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/configure.ac
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/Implies
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/shlib-versions

Comments

Adhemerval Zanella Jan. 4, 2022, 2:33 p.m. UTC | #1
On 31/12/2021 03:44, caiyinyu wrote:
> diff --git a/sysdeps/loongarch/nptl/Makefile b/sysdeps/loongarch/nptl/Makefile
> new file mode 100644
> index 0000000000..c6c773b179
> --- /dev/null
> +++ b/sysdeps/loongarch/nptl/Makefile
> @@ -0,0 +1,26 @@
> +# Makefile for sysdeps/loongarch/nptl.
> +# Copyright (C) 2021 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
> +# <https://www.gnu.org/licenses/>.
> +
> +ifeq ($(subdir),csu)
> +gen-as-const-headers += tcb-offsets.sym
> +endif
> +
> +ifeq ($(subdir),nptl)
> +libpthread-sysdep_routines += nptl-sysdep
> +libpthread-shared-only-routines += nptl-sysdep
> +endif

You should not need the nptl-sysdep, the tcb-offsets.h should be suffice.

> diff --git a/sysdeps/loongarch/preconfigure b/sysdeps/loongarch/preconfigure
> new file mode 100644
> index 0000000000..19983538ed
> --- /dev/null
> +++ b/sysdeps/loongarch/preconfigure
> @@ -0,0 +1,47 @@
> +case "$machine" in
> +loongarch*)
> +
> +    grlen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __loongarch_grlen \(.*\)/\1/p'`
> +    float_abi=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __loongarch_\(soft\|single\|double\)_float.*/\1/p'`
> +
> +    with_fp_cond="!defined __loongarch_soft_float"
> +
> +    case "$float_abi" in
> +    soft)
> +	abi_flen=0
> +	echo "loongarch does not yet support soft floating-point  ABI!!" >&2

Extra whitespace here.

> +	exit 1
> +	;;
> +    single)
> +	echo "glibc does not yet support the single floating-point ABI" >&2
> +	exit 1
> +	;;
> +    double)
> +	abi_flen=64
> +	;;
> +    *)
> +	echo "Unable to determine floating-point ABI" >&2
> +	exit 1
> +	;;
> +    esac
> +
> +    case "$grlen" in
> +    32)
> +	echo "loongarch does not yet support ilp32 ABI!!" >&2
> +	;;
> +    64)
> +	machine=loongarch/lp64
> +	;;
> +    *)
> +	echo "Unable to determine GRLEN" >&2
> +	exit 1
> +	;;
> +    esac
> +
> +    $as_echo "#define LOONGARCH_ABI_GRLEN $grlen" >>confdefs.h
> +    $as_echo "#define LOONGARCH_ABI_FRLEN $abi_flen" >>confdefs.h
> +
> +    base_machine=loongarch
> +    ;;
> +esac
> +
> diff --git a/sysdeps/loongarch/sys/regdef.h b/sysdeps/loongarch/sys/regdef.h
> new file mode 100644
> index 0000000000..f53447db62
> --- /dev/null
> +++ b/sysdeps/loongarch/sys/regdef.h
> @@ -0,0 +1,98 @@
> +/* Register Macro definitions
> +   Copyright (C) 2021 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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#ifndef _SYS_REGDEF_H
> +#define _SYS_REGDEF_H
> +
> +#ifdef __loongarch_lp64
> +#define zero $r0
> +#define ra $r1
> +#define tp $r2
> +#define sp $r3
> +#define a0 $r4
> +#define a1 $r5
> +#define a2 $r6
> +#define a3 $r7
> +#define a4 $r8
> +#define a5 $r9
> +#define a6 $r10
> +#define a7 $r11
> +#define v0 $r4
> +#define v1 $r5
> +#define t0 $r12
> +#define t1 $r13
> +#define t2 $r14
> +#define t3 $r15
> +#define t4 $r16
> +#define t5 $r17
> +#define t6 $r18
> +#define t7 $r19
> +#define t8 $r20
> +#define x $r21
> +#define fp $r22
> +#define s0 $r23
> +#define s1 $r24
> +#define s2 $r25
> +#define s3 $r26
> +#define s4 $r27
> +#define s5 $r28
> +#define s6 $r29
> +#define s7 $r30
> +#define s8 $r31
> +
> +#define fa0 $f0
> +#define fa1 $f1
> +#define fa2 $f2
> +#define fa3 $f3
> +#define fa4 $f4
> +#define fa5 $f5
> +#define fa6 $f6
> +#define fa7 $f7
> +#define fv0 $f0
> +#define fv1 $f1
> +#define ft0 $f8
> +#define ft1 $f9
> +#define ft2 $f10
> +#define ft3 $f11
> +#define ft4 $f12
> +#define ft5 $f13
> +#define ft6 $f14
> +#define ft7 $f15
> +#define ft8 $f16
> +#define ft9 $f17
> +#define ft10 $f18
> +#define ft11 $f19
> +#define ft12 $f20
> +#define ft13 $f21
> +#define ft14 $f22
> +#define ft15 $f23
> +#define fs0 $f24
> +#define fs1 $f25
> +#define fs2 $f26
> +#define fs3 $f27
> +#define fs4 $f28
> +#define fs5 $f29
> +#define fs6 $f30
> +#define fs7 $f31
> +
> +#else
> +#error "32bit LoongArch systems are not supported"
> +#endif
> +
> +#endif /* _SYS_REGDEF_H */
> diff --git a/sysdeps/unix/sysv/linux/loongarch/Implies b/sysdeps/unix/sysv/linux/loongarch/Implies
> new file mode 100644
> index 0000000000..e52b1ac310
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/Implies
> @@ -0,0 +1 @@
> +loongarch/nptl

Why do you need this Imply folder?

> diff --git a/sysdeps/unix/sysv/linux/loongarch/Makefile b/sysdeps/unix/sysv/linux/loongarch/Makefile
> new file mode 100644
> index 0000000000..99ac734f91
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/Makefile
> @@ -0,0 +1,11 @@
> +ifeq ($(subdir),elf)
> +ifeq ($(build-shared),yes)
> +# This is needed for DSO loading from static binaries.
> +sysdep-dl-routines += dl-static
> +endif
> +endif
> +

There is no need of this file.

> +ifeq ($(subdir),stdlib)
> +gen-as-const-headers += ucontext_i.sym
> +endif
> +
> diff --git a/sysdeps/unix/sysv/linux/loongarch/configure b/sysdeps/unix/sysv/linux/loongarch/configure
> new file mode 100644
> index 0000000000..f4adec4ed9
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/configure
> @@ -0,0 +1,199 @@
> +# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
> + # Local configure fragment for sysdeps/unix/sysv/linux/loongarch.
> +
> +arch_minimum_kernel=5.15.0
> +
> +libc_cv_loongarch_int_abi=no
> +
> +
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
> +$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
> +if ${ac_cv_path_GREP+:} false; then :
> +  $as_echo_n "(cached) " >&6
> +else
> +  if test -z "$GREP"; then
> +  ac_path_GREP_found=false
> +  # Loop through the user's path and test for each of PROGNAME-LIST
> +  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
> +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
> +do
> +  IFS=$as_save_IFS
> +  test -z "$as_dir" && as_dir=.
> +    for ac_prog in grep ggrep; do
> +    for ac_exec_ext in '' $ac_executable_extensions; do
> +      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
> +      as_fn_executable_p "$ac_path_GREP" || continue
> +# Check for GNU ac_path_GREP and select it if it is found.
> +  # Check for GNU $ac_path_GREP
> +case `"$ac_path_GREP" --version 2>&1` in
> +*GNU*)
> +  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
> +*)
> +  ac_count=0
> +  $as_echo_n 0123456789 >"conftest.in"
> +  while :
> +  do
> +    cat "conftest.in" "conftest.in" >"conftest.tmp"
> +    mv "conftest.tmp" "conftest.in"
> +    cp "conftest.in" "conftest.nl"
> +    $as_echo 'GREP' >> "conftest.nl"
> +    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
> +    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
> +    as_fn_arith $ac_count + 1 && ac_count=$as_val
> +    if test $ac_count -gt ${ac_path_GREP_max-0}; then
> +      # Best one so far, save it but keep looking for a better one
> +      ac_cv_path_GREP="$ac_path_GREP"
> +      ac_path_GREP_max=$ac_count
> +    fi
> +    # 10*(2^10) chars as input seems more than enough
> +    test $ac_count -gt 10 && break
> +  done
> +  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
> +esac
> +
> +      $ac_path_GREP_found && break 3
> +    done
> +  done
> +  done
> +IFS=$as_save_IFS
> +  if test -z "$ac_cv_path_GREP"; then
> +    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
> +  fi
> +else
> +  ac_cv_path_GREP=$GREP
> +fi
> +
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
> +$as_echo "$ac_cv_path_GREP" >&6; }
> + GREP="$ac_cv_path_GREP"
> +
> +
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
> +$as_echo_n "checking for egrep... " >&6; }
> +if ${ac_cv_path_EGREP+:} false; then :
> +  $as_echo_n "(cached) " >&6
> +else
> +  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
> +   then ac_cv_path_EGREP="$GREP -E"
> +   else
> +     if test -z "$EGREP"; then
> +  ac_path_EGREP_found=false
> +  # Loop through the user's path and test for each of PROGNAME-LIST
> +  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
> +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
> +do
> +  IFS=$as_save_IFS
> +  test -z "$as_dir" && as_dir=.
> +    for ac_prog in egrep; do
> +    for ac_exec_ext in '' $ac_executable_extensions; do
> +      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
> +      as_fn_executable_p "$ac_path_EGREP" || continue
> +# Check for GNU ac_path_EGREP and select it if it is found.
> +  # Check for GNU $ac_path_EGREP
> +case `"$ac_path_EGREP" --version 2>&1` in
> +*GNU*)
> +  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
> +*)
> +  ac_count=0
> +  $as_echo_n 0123456789 >"conftest.in"
> +  while :
> +  do
> +    cat "conftest.in" "conftest.in" >"conftest.tmp"
> +    mv "conftest.tmp" "conftest.in"
> +    cp "conftest.in" "conftest.nl"
> +    $as_echo 'EGREP' >> "conftest.nl"
> +    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
> +    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
> +    as_fn_arith $ac_count + 1 && ac_count=$as_val
> +    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
> +      # Best one so far, save it but keep looking for a better one
> +      ac_cv_path_EGREP="$ac_path_EGREP"
> +      ac_path_EGREP_max=$ac_count
> +    fi
> +    # 10*(2^10) chars as input seems more than enough
> +    test $ac_count -gt 10 && break
> +  done
> +  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
> +esac
> +
> +      $ac_path_EGREP_found && break 3
> +    done
> +  done
> +  done
> +IFS=$as_save_IFS
> +  if test -z "$ac_cv_path_EGREP"; then
> +    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
> +  fi
> +else
> +  ac_cv_path_EGREP=$EGREP
> +fi
> +
> +   fi
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
> +$as_echo "$ac_cv_path_EGREP" >&6; }
> + EGREP="$ac_cv_path_EGREP"
> +
> +
> +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> +/* end confdefs.h.  */
> +__SIZEOF_INT__ __SIZEOF_LONG__ __SIZEOF_POINTER__
> +
> +_ACEOF
> +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
> +  $EGREP "4 4 4" >/dev/null 2>&1; then :
> +  libc_cv_loongarch_int_abi=lp32
> +fi
> +rm -f conftest*
> +
> +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> +/* end confdefs.h.  */
> +__SIZEOF_INT__ __SIZEOF_LONG__ __SIZEOF_POINTER__
> +
> +_ACEOF
> +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
> +  $EGREP "4 8 8" >/dev/null 2>&1; then :
> +  libc_cv_loongarch_int_abi=lp64
> +fi
> +rm -f conftest*
> +
> +if test $libc_cv_loongarch_int_abi = no; then
> +  as_fn_error $? "Unable to determine integer ABI" "$LINENO" 5
> +fi
> +
> +config_vars="$config_vars
> +default-abi = $libc_cv_loongarch_int_abi"
> +
> +case $libc_cv_loongarch_int_abi in
> +lp32)
> +  test -n "$libc_cv_slibdir" ||
> +case "$prefix" in
> +/usr | /usr/)
> +  libc_cv_slibdir='/lib32'
> +  libc_cv_rtlddir='/lib32'
> +  if test "$libdir" = '${exec_prefix}/lib'; then
> +    libdir='${exec_prefix}/lib32';
> +    # Locale data can be shared between 32-bit and 64-bit libraries.
> +    libc_cv_complocaledir='${exec_prefix}/lib/locale'
> +  fi
> +  ;;
> +esac
> +  ;;
> +lp64)
> +  test -n "$libc_cv_slibdir" ||
> +case "$prefix" in
> +/usr | /usr/)
> +  libc_cv_slibdir='/lib64'
> +  libc_cv_rtlddir='/lib64'
> +  if test "$libdir" = '${exec_prefix}/lib'; then
> +    libdir='${exec_prefix}/lib64';
> +    # Locale data can be shared between 32-bit and 64-bit libraries.
> +    libc_cv_complocaledir='${exec_prefix}/lib/locale'
> +  fi
> +  ;;
> +esac
> +  ;;
> +esac
> +
> +ldd_rewrite_script=sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
> diff --git a/sysdeps/unix/sysv/linux/loongarch/configure.ac b/sysdeps/unix/sysv/linux/loongarch/configure.ac
> new file mode 100644
> index 0000000000..25fda13b09
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/configure.ac
> @@ -0,0 +1,27 @@
> +sinclude(./aclocal.m4)dnl Autoconf lossage
> +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
> +# Local configure fragment for sysdeps/unix/sysv/linux/loongarch.
> +
> +arch_minimum_kernel=5.15.0
> +
> +libc_cv_loongarch_int_abi=no
> +AC_EGREP_CPP(4 4 4, [__SIZEOF_INT__ __SIZEOF_LONG__ __SIZEOF_POINTER__
> +  ], libc_cv_loongarch_int_abi=ilp32)
> +AC_EGREP_CPP(4 8 8, [__SIZEOF_INT__ __SIZEOF_LONG__ __SIZEOF_POINTER__
> +  ], libc_cv_loongarch_int_abi=lp64)
> +if test $libc_cv_loongarch_int_abi = no; then
> +  AC_MSG_ERROR([Unable to determine integer ABI])
> +fi
> +
> +LIBC_CONFIG_VAR([default-abi], [$libc_cv_loongarch_int_abi])
> +
> +case $libc_cv_loongarch_int_abi in
> +ilp32)
> +  LIBC_SLIBDIR_RTLDDIR([lib32], [lib32])
> +  ;;
> +lp64)
> +  LIBC_SLIBDIR_RTLDDIR([lib64], [lib64])
> +  ;;
> +esac
> +
> +ldd_rewrite_script=sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed

So is the idea to evetually support ILP32 as well? My understanding it
is not currently supported, so I think it should not be handled it
yet.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed b/sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
> new file mode 100644
> index 0000000000..d42a13e08c
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
> @@ -0,0 +1,3 @@
> +/LD_TRACE_LOADED_OBJECTS=1/a\
> +add_env="$add_env LD_LIBRARY_VERSION=\\$verify_out"
> +s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|32\)\(/[^/]*\)\(-loongarch\)\(64\|32\)\(\.so\.[0-9.]*\)[[:blank:]]*$_\1"\2\4\7 \264\4-loongarch64\7 \232\4-loongarch32\7"_
> diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/Implies b/sysdeps/unix/sysv/linux/loongarch/lp64/Implies
> new file mode 100644
> index 0000000000..117c2b8efe
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/Implies
> @@ -0,0 +1,3 @@
> +unix/sysv/linux/loongarch
> +unix/sysv/linux/generic
> +unix/sysv/linux/wordsize-64
> diff --git a/sysdeps/unix/sysv/linux/loongarch/shlib-versions b/sysdeps/unix/sysv/linux/loongarch/shlib-versions
> new file mode 100644
> index 0000000000..aa9257fc61
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/shlib-versions
> @@ -0,0 +1,7 @@
> +DEFAULT		GLIBC_2.35
> +
> +%if LOONGARCH_ABI_GRLEN == 64 && LOONGARCH_ABI_FRLEN == 64
> +ld=ld-linux-loongarch-lp64d.so.1
> +%else
> +%error cannot determine ABI
> +%endif
diff mbox series

Patch

diff --git a/sysdeps/loongarch/Implies b/sysdeps/loongarch/Implies
new file mode 100644
index 0000000000..c88325b8be
--- /dev/null
+++ b/sysdeps/loongarch/Implies
@@ -0,0 +1,5 @@ 
+init_array
+
+ieee754/ldbl-128
+ieee754/dbl-64
+ieee754/flt-32
diff --git a/sysdeps/loongarch/Makefile b/sysdeps/loongarch/Makefile
new file mode 100644
index 0000000000..41c3449670
--- /dev/null
+++ b/sysdeps/loongarch/Makefile
@@ -0,0 +1,15 @@ 
+ifeq ($(subdir),misc)
+sysdep_headers += sys/asm.h
+endif
+
+# LoongArch's assembler also needs to know about PIC as it changes the
+# definition of some assembler macros.
+ASFLAGS-.os += $(pic-ccflag)
+
+abi-variants := lp64
+
+ifeq (,$(filter $(default-abi),$(abi-variants)))
+$(error Unknown ABI $(default-abi), must be one of $(abi-variants))
+endif
+
+abi-lp64-condition    := defined __loongarch_lp64
diff --git a/sysdeps/loongarch/configure b/sysdeps/loongarch/configure
new file mode 100644
index 0000000000..1e5abf81a7
--- /dev/null
+++ b/sysdeps/loongarch/configure
@@ -0,0 +1,4 @@ 
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/loongarch/elf.
+
+#AC_DEFINE(PI_STATIC_AND_HIDDEN)
diff --git a/sysdeps/loongarch/configure.ac b/sysdeps/loongarch/configure.ac
new file mode 100644
index 0000000000..67b46ce048
--- /dev/null
+++ b/sysdeps/loongarch/configure.ac
@@ -0,0 +1,6 @@ 
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/loongarch/elf.
+
+dnl It is always possible to access static and hidden symbols in an
+dnl position independent way.
+#AC_DEFINE(PI_STATIC_AND_HIDDEN)
diff --git a/sysdeps/loongarch/lp64/Implies-after b/sysdeps/loongarch/lp64/Implies-after
new file mode 100644
index 0000000000..a8cae95f9d
--- /dev/null
+++ b/sysdeps/loongarch/lp64/Implies-after
@@ -0,0 +1 @@ 
+wordsize-64
diff --git a/sysdeps/loongarch/nptl/Makefile b/sysdeps/loongarch/nptl/Makefile
new file mode 100644
index 0000000000..c6c773b179
--- /dev/null
+++ b/sysdeps/loongarch/nptl/Makefile
@@ -0,0 +1,26 @@ 
+# Makefile for sysdeps/loongarch/nptl.
+# Copyright (C) 2021 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
+# <https://www.gnu.org/licenses/>.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
+
+ifeq ($(subdir),nptl)
+libpthread-sysdep_routines += nptl-sysdep
+libpthread-shared-only-routines += nptl-sysdep
+endif
diff --git a/sysdeps/loongarch/preconfigure b/sysdeps/loongarch/preconfigure
new file mode 100644
index 0000000000..19983538ed
--- /dev/null
+++ b/sysdeps/loongarch/preconfigure
@@ -0,0 +1,47 @@ 
+case "$machine" in
+loongarch*)
+
+    grlen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __loongarch_grlen \(.*\)/\1/p'`
+    float_abi=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __loongarch_\(soft\|single\|double\)_float.*/\1/p'`
+
+    with_fp_cond="!defined __loongarch_soft_float"
+
+    case "$float_abi" in
+    soft)
+	abi_flen=0
+	echo "loongarch does not yet support soft floating-point  ABI!!" >&2
+	exit 1
+	;;
+    single)
+	echo "glibc does not yet support the single floating-point ABI" >&2
+	exit 1
+	;;
+    double)
+	abi_flen=64
+	;;
+    *)
+	echo "Unable to determine floating-point ABI" >&2
+	exit 1
+	;;
+    esac
+
+    case "$grlen" in
+    32)
+	echo "loongarch does not yet support ilp32 ABI!!" >&2
+	;;
+    64)
+	machine=loongarch/lp64
+	;;
+    *)
+	echo "Unable to determine GRLEN" >&2
+	exit 1
+	;;
+    esac
+
+    $as_echo "#define LOONGARCH_ABI_GRLEN $grlen" >>confdefs.h
+    $as_echo "#define LOONGARCH_ABI_FRLEN $abi_flen" >>confdefs.h
+
+    base_machine=loongarch
+    ;;
+esac
+
diff --git a/sysdeps/loongarch/sys/regdef.h b/sysdeps/loongarch/sys/regdef.h
new file mode 100644
index 0000000000..f53447db62
--- /dev/null
+++ b/sysdeps/loongarch/sys/regdef.h
@@ -0,0 +1,98 @@ 
+/* Register Macro definitions
+   Copyright (C) 2021 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
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _SYS_REGDEF_H
+#define _SYS_REGDEF_H
+
+#ifdef __loongarch_lp64
+#define zero $r0
+#define ra $r1
+#define tp $r2
+#define sp $r3
+#define a0 $r4
+#define a1 $r5
+#define a2 $r6
+#define a3 $r7
+#define a4 $r8
+#define a5 $r9
+#define a6 $r10
+#define a7 $r11
+#define v0 $r4
+#define v1 $r5
+#define t0 $r12
+#define t1 $r13
+#define t2 $r14
+#define t3 $r15
+#define t4 $r16
+#define t5 $r17
+#define t6 $r18
+#define t7 $r19
+#define t8 $r20
+#define x $r21
+#define fp $r22
+#define s0 $r23
+#define s1 $r24
+#define s2 $r25
+#define s3 $r26
+#define s4 $r27
+#define s5 $r28
+#define s6 $r29
+#define s7 $r30
+#define s8 $r31
+
+#define fa0 $f0
+#define fa1 $f1
+#define fa2 $f2
+#define fa3 $f3
+#define fa4 $f4
+#define fa5 $f5
+#define fa6 $f6
+#define fa7 $f7
+#define fv0 $f0
+#define fv1 $f1
+#define ft0 $f8
+#define ft1 $f9
+#define ft2 $f10
+#define ft3 $f11
+#define ft4 $f12
+#define ft5 $f13
+#define ft6 $f14
+#define ft7 $f15
+#define ft8 $f16
+#define ft9 $f17
+#define ft10 $f18
+#define ft11 $f19
+#define ft12 $f20
+#define ft13 $f21
+#define ft14 $f22
+#define ft15 $f23
+#define fs0 $f24
+#define fs1 $f25
+#define fs2 $f26
+#define fs3 $f27
+#define fs4 $f28
+#define fs5 $f29
+#define fs6 $f30
+#define fs7 $f31
+
+#else
+#error "32bit LoongArch systems are not supported"
+#endif
+
+#endif /* _SYS_REGDEF_H */
diff --git a/sysdeps/unix/sysv/linux/loongarch/Implies b/sysdeps/unix/sysv/linux/loongarch/Implies
new file mode 100644
index 0000000000..e52b1ac310
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/Implies
@@ -0,0 +1 @@ 
+loongarch/nptl
diff --git a/sysdeps/unix/sysv/linux/loongarch/Makefile b/sysdeps/unix/sysv/linux/loongarch/Makefile
new file mode 100644
index 0000000000..99ac734f91
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/Makefile
@@ -0,0 +1,11 @@ 
+ifeq ($(subdir),elf)
+ifeq ($(build-shared),yes)
+# This is needed for DSO loading from static binaries.
+sysdep-dl-routines += dl-static
+endif
+endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+endif
+
diff --git a/sysdeps/unix/sysv/linux/loongarch/configure b/sysdeps/unix/sysv/linux/loongarch/configure
new file mode 100644
index 0000000000..f4adec4ed9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/configure
@@ -0,0 +1,199 @@ 
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/unix/sysv/linux/loongarch.
+
+arch_minimum_kernel=5.15.0
+
+libc_cv_loongarch_int_abi=no
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if ${ac_cv_path_GREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$GREP"; then
+  ac_path_GREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in grep ggrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_GREP" || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+  # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'GREP' >> "conftest.nl"
+    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_GREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_GREP="$ac_path_GREP"
+      ac_path_GREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_GREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_GREP"; then
+    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if ${ac_cv_path_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     if test -z "$EGREP"; then
+  ac_path_EGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_EGREP" || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_EGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_EGREP"; then
+    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_EGREP=$EGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+__SIZEOF_INT__ __SIZEOF_LONG__ __SIZEOF_POINTER__
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "4 4 4" >/dev/null 2>&1; then :
+  libc_cv_loongarch_int_abi=lp32
+fi
+rm -f conftest*
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+__SIZEOF_INT__ __SIZEOF_LONG__ __SIZEOF_POINTER__
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "4 8 8" >/dev/null 2>&1; then :
+  libc_cv_loongarch_int_abi=lp64
+fi
+rm -f conftest*
+
+if test $libc_cv_loongarch_int_abi = no; then
+  as_fn_error $? "Unable to determine integer ABI" "$LINENO" 5
+fi
+
+config_vars="$config_vars
+default-abi = $libc_cv_loongarch_int_abi"
+
+case $libc_cv_loongarch_int_abi in
+lp32)
+  test -n "$libc_cv_slibdir" ||
+case "$prefix" in
+/usr | /usr/)
+  libc_cv_slibdir='/lib32'
+  libc_cv_rtlddir='/lib32'
+  if test "$libdir" = '${exec_prefix}/lib'; then
+    libdir='${exec_prefix}/lib32';
+    # Locale data can be shared between 32-bit and 64-bit libraries.
+    libc_cv_complocaledir='${exec_prefix}/lib/locale'
+  fi
+  ;;
+esac
+  ;;
+lp64)
+  test -n "$libc_cv_slibdir" ||
+case "$prefix" in
+/usr | /usr/)
+  libc_cv_slibdir='/lib64'
+  libc_cv_rtlddir='/lib64'
+  if test "$libdir" = '${exec_prefix}/lib'; then
+    libdir='${exec_prefix}/lib64';
+    # Locale data can be shared between 32-bit and 64-bit libraries.
+    libc_cv_complocaledir='${exec_prefix}/lib/locale'
+  fi
+  ;;
+esac
+  ;;
+esac
+
+ldd_rewrite_script=sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
diff --git a/sysdeps/unix/sysv/linux/loongarch/configure.ac b/sysdeps/unix/sysv/linux/loongarch/configure.ac
new file mode 100644
index 0000000000..25fda13b09
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/configure.ac
@@ -0,0 +1,27 @@ 
+sinclude(./aclocal.m4)dnl Autoconf lossage
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/unix/sysv/linux/loongarch.
+
+arch_minimum_kernel=5.15.0
+
+libc_cv_loongarch_int_abi=no
+AC_EGREP_CPP(4 4 4, [__SIZEOF_INT__ __SIZEOF_LONG__ __SIZEOF_POINTER__
+  ], libc_cv_loongarch_int_abi=ilp32)
+AC_EGREP_CPP(4 8 8, [__SIZEOF_INT__ __SIZEOF_LONG__ __SIZEOF_POINTER__
+  ], libc_cv_loongarch_int_abi=lp64)
+if test $libc_cv_loongarch_int_abi = no; then
+  AC_MSG_ERROR([Unable to determine integer ABI])
+fi
+
+LIBC_CONFIG_VAR([default-abi], [$libc_cv_loongarch_int_abi])
+
+case $libc_cv_loongarch_int_abi in
+ilp32)
+  LIBC_SLIBDIR_RTLDDIR([lib32], [lib32])
+  ;;
+lp64)
+  LIBC_SLIBDIR_RTLDDIR([lib64], [lib64])
+  ;;
+esac
+
+ldd_rewrite_script=sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
diff --git a/sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed b/sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
new file mode 100644
index 0000000000..d42a13e08c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
@@ -0,0 +1,3 @@ 
+/LD_TRACE_LOADED_OBJECTS=1/a\
+add_env="$add_env LD_LIBRARY_VERSION=\\$verify_out"
+s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|32\)\(/[^/]*\)\(-loongarch\)\(64\|32\)\(\.so\.[0-9.]*\)[[:blank:]]*$_\1"\2\4\7 \264\4-loongarch64\7 \232\4-loongarch32\7"_
diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/Implies b/sysdeps/unix/sysv/linux/loongarch/lp64/Implies
new file mode 100644
index 0000000000..117c2b8efe
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/lp64/Implies
@@ -0,0 +1,3 @@ 
+unix/sysv/linux/loongarch
+unix/sysv/linux/generic
+unix/sysv/linux/wordsize-64
diff --git a/sysdeps/unix/sysv/linux/loongarch/shlib-versions b/sysdeps/unix/sysv/linux/loongarch/shlib-versions
new file mode 100644
index 0000000000..aa9257fc61
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/shlib-versions
@@ -0,0 +1,7 @@ 
+DEFAULT		GLIBC_2.35
+
+%if LOONGARCH_ABI_GRLEN == 64 && LOONGARCH_ABI_FRLEN == 64
+ld=ld-linux-loongarch-lp64d.so.1
+%else
+%error cannot determine ABI
+%endif