public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v7 00/13] GLIBC LoongArch PATCHES
@ 2022-07-19  1:20 caiyinyu
  2022-07-19  1:20 ` [PATCH v7 01/13] LoongArch: Add LoongArch entries to config.h.in caiyinyu
                   ` (9 more replies)
  0 siblings, 10 replies; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

Hello, these are LoongArch patches v7, and we really need your futher suggestions:

There are 6 parts in total.

1. HISTORY:
LoongArch patches v1: https://sourceware.org/pipermail/libc-alpha/2021-August/130262.html
LoongArch patches v2: https://sourceware.org/pipermail/libc-alpha/2021-December/134811.html
LoongArch patches v3: https://sourceware.org/pipermail/libc-alpha/2022-April/137888.html
LoongArch patches v4: https://sourceware.org/pipermail/libc-alpha/2022-May/subject.html
LoongArch patches v5: https://sourceware.org/pipermail/libc-alpha/2022-June/139262.html
LoongArch patches v6: https://sourceware.org/pipermail/libc-alpha/2022-July/140446.html

2. LoongArch-Doc:  https://github.com/loongson/LoongArch-Documentation

We add new section: procedure calling convention.
https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_procedure_calling_convention


3. Linux kernel, GCC and Binutils Loongarch parts have been into GNU Open Source community.


4. From Adhemerval Zanella Netto:
> I finished my review for the port and it looks ok in general, however there
> some pieces that would require a v7:
>
>   1. Add R_LARCH_NONE handling on bootstrap, binutils 2.38 does generated it
>      and from previous discussion it should be considered a missed
>      optimizations instead of a linker error.

    R_LARCH_NONE handling has been added on bootstrap.
>
>   2. Remove the __loongarch_soft_float parts, since there is no support for
>      soft floating-point.

    All __loongarch_soft_float removed.
>
>   3. Remove sysdeps/unix/sysv/linux/loongarch/ldconfig.h, this file is not
>      required.

    This file has been removed.
>
>   4. Some minor style issues.

    See previous emails.
    https://sourceware.org/pipermail/libc-alpha/2022-July/thread.html
>
>   5. Either remove HAVE_GETTIMEOFDAY_VSYSCALL or add a gettimeofday ifunc
>      optimization.

    Removed now.
>
> The only part really prevent port inclusion is 1.  I am also assuming ifunc
> is support (at least you have added support on the Linux ABI part) with
> binutils 2.38.  If not, you will need to remove support until you fix it on
> binutils.
>
> And also, you need to check and report the test results using the expected
> defined release branches, using out-of-tree branches are not acceptable for
> inclusion.

5. There are some new changes:
>>>>>>>>>>>>>>>>>>>>>>>>>

diff --git a/sysdeps/loongarch/e_sqrtl.c b/sysdeps/loongarch/e_sqrtl.c
index 5eb8cc8adb..020c8911e6 100644
--- a/sysdeps/loongarch/e_sqrtl.c
+++ b/sysdeps/loongarch/e_sqrtl.c
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <soft-fp/soft-fp.h>
 #include <soft-fp/quad.h>
+#include <libm-alias-finite.h>
 
 long double
 __ieee754_sqrtl (const long double a)
@@ -35,4 +36,4 @@ __ieee754_sqrtl (const long double a)
   FP_HANDLE_EXCEPTIONS;
   return c;
 }
-strong_alias (__ieee754_sqrtl, __sqrtl_finite)
+libm_alias_finite (__ieee754_sqrtl, __sqrtl)
diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/libm.abilist b/sysdeps/unix/sysv/linux/loongarch/lp64/libm.abilist
index 6ddb86edef..b3dbd00001 100644
--- a/sysdeps/unix/sysv/linux/loongarch/lp64/libm.abilist
+++ b/sysdeps/unix/sysv/linux/loongarch/lp64/libm.abilist
@@ -17,7 +17,6 @@ GLIBC_2.36 __signbit F
 GLIBC_2.36 __signbitf F
 GLIBC_2.36 __signbitl F
 GLIBC_2.36 __signgam D 0x4
-GLIBC_2.36 __sqrtl_finite F
 GLIBC_2.36 acos F
 GLIBC_2.36 acosf F
 GLIBC_2.36 acosf128 F

diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
index 9e7e360125..da9b905900 100755
--- a/scripts/build-many-glibcs.py
+++ b/scripts/build-many-glibcs.py
@@ -220,7 +220,7 @@ class Context(object):
                         binutils_cfg=['--enable-obsolete'])
         self.add_config(arch='loongarch64',
                         os_name='linux-gnu',
-                        variant='hard',
+                        variant='lp64d',
                         gcc_cfg=['--with-abi=lp64d','--disable-multilib'])
         self.add_config(arch='m68k',
                         os_name='linux-gnu',

<<<<<<<<<<<<<<<<<<<<<<<<


6. Test result: all passed (ifunc disable).

Test with:
  Linux-5.19-rc4, Binutils-2.38, and GCC-12.1.
  glibc: https://github.com/loongson/glibc/tree/loongarch_2_36_upstream_v7

Result (ifunc disable):
XPASS: conform/UNIX98/ndbm.h/linknamespace
XPASS: conform/XOPEN2K/ndbm.h/linknamespace
XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
XPASS: conform/XPG42/ndbm.h/linknamespace
UNSUPPORTED: crypt/cert
UNSUPPORTED: elf/tst-env-setuid
UNSUPPORTED: elf/tst-env-setuid-tunables
XPASS: elf/tst-protected1a
XPASS: elf/tst-protected1b
UNSUPPORTED: elf/tst-valgrind-smoke
UNSUPPORTED: misc/tst-adjtimex
UNSUPPORTED: misc/tst-clock_adjtime
UNSUPPORTED: misc/tst-ntp_adjtime
UNSUPPORTED: misc/tst-pkey
UNSUPPORTED: misc/tst-rseq
UNSUPPORTED: misc/tst-rseq-disable
UNSUPPORTED: nptl/test-cond-printers
UNSUPPORTED: nptl/test-condattr-printers
UNSUPPORTED: nptl/test-mutex-printers
UNSUPPORTED: nptl/test-mutexattr-printers
UNSUPPORTED: nptl/test-rwlock-printers
UNSUPPORTED: nptl/test-rwlockattr-printers
UNSUPPORTED: nptl/tst-pthread-gdb-attach
UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
UNSUPPORTED: nptl/tst-rseq-nptl
UNSUPPORTED: stdlib/tst-secure-getenv
UNSUPPORTED: time/tst-clock_settime
UNSUPPORTED: time/tst-settimeofday
Summary of test results:
   4535 PASS
     22 UNSUPPORTED
     12 XFAIL
      6 XPASS


caiyinyu (13):
  LoongArch: Add LoongArch entries to config.h.in
  LoongArch: Add relocations and ELF flags to elf.h and
    scripts/glibcelf.py
  LoongArch: ABI Implementation
  LoongArch: Thread-Local Storage Support
  LoongArch: Generic <math.h> and soft-fp Routines
  LoongArch: Atomic and Locking Routines
  LoongArch: Linux Syscall Interface
  LoongArch: Linux ABI
  LoongArch: Add ABI Lists
  LoongArch: Build Infastructure
  LoongArch: Hard Float Support
  LoongArch: Update build-many-glibcs.py for the LoongArch Port.
  LoongArch: Update NEWS and README for the LoongArch port.

 NEWS                                          |    8 +
 README                                        |    1 +
 config.h.in                                   |    6 +
 elf/elf.h                                     |   68 +-
 manual/math.texi                              |    2 +-
 scripts/build-many-glibcs.py                  |    5 +
 scripts/glibcelf.py                           |    3 +-
 sysdeps/loongarch/Implies                     |    3 +
 sysdeps/loongarch/Makefile                    |   15 +
 sysdeps/loongarch/__longjmp.S                 |   50 +
 sysdeps/loongarch/abort-instr.h               |    2 +
 sysdeps/loongarch/bits/endianness.h           |   11 +
 sysdeps/loongarch/bits/fenv.h                 |   90 +
 sysdeps/loongarch/bits/link.h                 |   58 +
 sysdeps/loongarch/bits/setjmp.h               |   39 +
 sysdeps/loongarch/bsd-_setjmp.c               |    1 +
 sysdeps/loongarch/bsd-setjmp.c                |    1 +
 sysdeps/loongarch/configure                   |    5 +
 sysdeps/loongarch/configure.ac                |    6 +
 sysdeps/loongarch/dl-irel.h                   |   54 +
 sysdeps/loongarch/dl-machine.h                |  288 +++
 sysdeps/loongarch/dl-tls.h                    |   46 +
 sysdeps/loongarch/dl-trampoline.S             |   83 +
 sysdeps/loongarch/e_sqrtl.c                   |   39 +
 sysdeps/loongarch/fpu/fclrexcpt.c             |   46 +
 sysdeps/loongarch/fpu/fedisblxcpt.c           |   39 +
 sysdeps/loongarch/fpu/feenablxcpt.c           |   39 +
 sysdeps/loongarch/fpu/fegetenv.c              |   31 +
 sysdeps/loongarch/fpu/fegetexcept.c           |   32 +
 sysdeps/loongarch/fpu/fegetmode.c             |   27 +
 sysdeps/loongarch/fpu/fegetround.c            |   33 +
 sysdeps/loongarch/fpu/feholdexcpt.c           |   40 +
 sysdeps/loongarch/fpu/fenv_libc.h             |   30 +
 sysdeps/loongarch/fpu/fesetenv.c              |   42 +
 sysdeps/loongarch/fpu/fesetexcept.c           |   32 +
 sysdeps/loongarch/fpu/fesetmode.c             |   38 +
 sysdeps/loongarch/fpu/fesetround.c            |   44 +
 sysdeps/loongarch/fpu/feupdateenv.c           |   43 +
 sysdeps/loongarch/fpu/fgetexcptflg.c          |   38 +
 sysdeps/loongarch/fpu/fraiseexcpt.c           |   80 +
 sysdeps/loongarch/fpu/fsetexcptflg.c          |   41 +
 sysdeps/loongarch/fpu/ftestexcept.c           |   32 +
 .../loongarch/fpu/math-use-builtins-sqrt.h    |    4 +
 sysdeps/loongarch/fpu_control.h               |   90 +
 sysdeps/loongarch/hp-timing.h                 |   42 +
 sysdeps/loongarch/jmpbuf-offsets.h            |   22 +
 sysdeps/loongarch/jmpbuf-unwind.h             |   45 +
 sysdeps/loongarch/ldsodefs.h                  |   41 +
 sysdeps/loongarch/libc-tls.c                  |   32 +
 sysdeps/loongarch/linkmap.h                   |   22 +
 sysdeps/loongarch/lp64/Implies-after          |    1 +
 sysdeps/loongarch/lp64/libm-test-ulps         | 1412 +++++++++++
 sysdeps/loongarch/lp64/libm-test-ulps-name    |    1 +
 sysdeps/loongarch/machine-gmon.h              |   37 +
 sysdeps/loongarch/math_private.h              |  248 ++
 sysdeps/loongarch/nptl/pthreaddef.h           |   32 +
 sysdeps/loongarch/nptl/tls.h                  |  138 ++
 sysdeps/loongarch/preconfigure                |   53 +
 sysdeps/loongarch/preconfigure.ac             |   47 +
 sysdeps/loongarch/setjmp.S                    |   64 +
 sysdeps/loongarch/sfp-machine.h               |  102 +
 sysdeps/loongarch/sotruss-lib.c               |   50 +
 sysdeps/loongarch/stackinfo.h                 |   33 +
 sysdeps/loongarch/start.S                     |   66 +
 sysdeps/loongarch/sys/asm.h                   |   59 +
 sysdeps/loongarch/sys/ifunc.h                 |   30 +
 sysdeps/loongarch/sys/regdef.h                |   93 +
 sysdeps/loongarch/tininess.h                  |    1 +
 sysdeps/loongarch/tst-audit.h                 |   23 +
 sysdeps/unix/sysv/linux/loongarch/Implies     |    1 +
 sysdeps/unix/sysv/linux/loongarch/Makefile    |    4 +
 .../unix/sysv/linux/loongarch/arch-syscall.h  |  301 +++
 .../sysv/linux/loongarch/atomic-machine.h     |  147 ++
 .../unix/sysv/linux/loongarch/bits/fcntl.h    |   61 +
 .../unix/sysv/linux/loongarch/bits/procfs.h   |   52 +
 .../linux/loongarch/bits/pthread_stack_min.h  |   20 +
 .../unix/sysv/linux/loongarch/bits/sigstack.h |   32 +
 sysdeps/unix/sysv/linux/loongarch/clone.S     |   96 +
 sysdeps/unix/sysv/linux/loongarch/clone3.S    |   83 +
 sysdeps/unix/sysv/linux/loongarch/configure   |  174 ++
 .../unix/sysv/linux/loongarch/configure.ac    |   22 +
 .../unix/sysv/linux/loongarch/getcontext.S    |   59 +
 .../unix/sysv/linux/loongarch/ldd-rewrite.sed |    1 +
 .../unix/sysv/linux/loongarch/localplt.data   |   12 +
 .../unix/sysv/linux/loongarch/lp64/Implies    |    3 +
 .../sysv/linux/loongarch/lp64/c++-types.data  |   67 +
 .../unix/sysv/linux/loongarch/lp64/ld.abilist |    8 +
 .../loongarch/lp64/libBrokenLocale.abilist    |    1 +
 .../sysv/linux/loongarch/lp64/libc.abilist    | 2153 +++++++++++++++++
 .../loongarch/lp64/libc_malloc_debug.abilist  |   26 +
 .../linux/loongarch/lp64/libcrypt.abilist     |    2 +
 .../sysv/linux/loongarch/lp64/libm.abilist    | 1030 ++++++++
 .../linux/loongarch/lp64/libpthread.abilist   |    0
 .../linux/loongarch/lp64/libresolv.abilist    |   55 +
 .../sysv/linux/loongarch/lp64/librt.abilist   |    0
 .../linux/loongarch/lp64/libthread_db.abilist |   40 +
 .../unix/sysv/linux/loongarch/makecontext.c   |   81 +
 .../unix/sysv/linux/loongarch/setcontext.S    |  100 +
 .../unix/sysv/linux/loongarch/shlib-versions  |    7 +
 .../sysv/linux/loongarch/sigcontextinfo.h     |   32 +
 .../unix/sysv/linux/loongarch/swapcontext.S   |   95 +
 .../unix/sysv/linux/loongarch/sys/ucontext.h  |   61 +
 sysdeps/unix/sysv/linux/loongarch/sys/user.h  |   42 +
 sysdeps/unix/sysv/linux/loongarch/sysdep.S    |   53 +
 sysdeps/unix/sysv/linux/loongarch/sysdep.h    |  320 +++
 .../sysv/linux/loongarch/ucontext-macros.h    |   32 +
 .../unix/sysv/linux/loongarch/ucontext_i.sym  |   31 +
 sysdeps/unix/sysv/linux/loongarch/vfork.S     |   50 +
 108 files changed, 9730 insertions(+), 3 deletions(-)
 create mode 100644 sysdeps/loongarch/Implies
 create mode 100644 sysdeps/loongarch/Makefile
 create mode 100644 sysdeps/loongarch/__longjmp.S
 create mode 100644 sysdeps/loongarch/abort-instr.h
 create mode 100644 sysdeps/loongarch/bits/endianness.h
 create mode 100644 sysdeps/loongarch/bits/fenv.h
 create mode 100644 sysdeps/loongarch/bits/link.h
 create mode 100644 sysdeps/loongarch/bits/setjmp.h
 create mode 100644 sysdeps/loongarch/bsd-_setjmp.c
 create mode 100644 sysdeps/loongarch/bsd-setjmp.c
 create mode 100644 sysdeps/loongarch/configure
 create mode 100644 sysdeps/loongarch/configure.ac
 create mode 100644 sysdeps/loongarch/dl-irel.h
 create mode 100644 sysdeps/loongarch/dl-machine.h
 create mode 100644 sysdeps/loongarch/dl-tls.h
 create mode 100644 sysdeps/loongarch/dl-trampoline.S
 create mode 100644 sysdeps/loongarch/e_sqrtl.c
 create mode 100644 sysdeps/loongarch/fpu/fclrexcpt.c
 create mode 100644 sysdeps/loongarch/fpu/fedisblxcpt.c
 create mode 100644 sysdeps/loongarch/fpu/feenablxcpt.c
 create mode 100644 sysdeps/loongarch/fpu/fegetenv.c
 create mode 100644 sysdeps/loongarch/fpu/fegetexcept.c
 create mode 100644 sysdeps/loongarch/fpu/fegetmode.c
 create mode 100644 sysdeps/loongarch/fpu/fegetround.c
 create mode 100644 sysdeps/loongarch/fpu/feholdexcpt.c
 create mode 100644 sysdeps/loongarch/fpu/fenv_libc.h
 create mode 100644 sysdeps/loongarch/fpu/fesetenv.c
 create mode 100644 sysdeps/loongarch/fpu/fesetexcept.c
 create mode 100644 sysdeps/loongarch/fpu/fesetmode.c
 create mode 100644 sysdeps/loongarch/fpu/fesetround.c
 create mode 100644 sysdeps/loongarch/fpu/feupdateenv.c
 create mode 100644 sysdeps/loongarch/fpu/fgetexcptflg.c
 create mode 100644 sysdeps/loongarch/fpu/fraiseexcpt.c
 create mode 100644 sysdeps/loongarch/fpu/fsetexcptflg.c
 create mode 100644 sysdeps/loongarch/fpu/ftestexcept.c
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-sqrt.h
 create mode 100644 sysdeps/loongarch/fpu_control.h
 create mode 100644 sysdeps/loongarch/hp-timing.h
 create mode 100644 sysdeps/loongarch/jmpbuf-offsets.h
 create mode 100644 sysdeps/loongarch/jmpbuf-unwind.h
 create mode 100644 sysdeps/loongarch/ldsodefs.h
 create mode 100644 sysdeps/loongarch/libc-tls.c
 create mode 100644 sysdeps/loongarch/linkmap.h
 create mode 100644 sysdeps/loongarch/lp64/Implies-after
 create mode 100644 sysdeps/loongarch/lp64/libm-test-ulps
 create mode 100644 sysdeps/loongarch/lp64/libm-test-ulps-name
 create mode 100644 sysdeps/loongarch/machine-gmon.h
 create mode 100644 sysdeps/loongarch/math_private.h
 create mode 100644 sysdeps/loongarch/nptl/pthreaddef.h
 create mode 100644 sysdeps/loongarch/nptl/tls.h
 create mode 100644 sysdeps/loongarch/preconfigure
 create mode 100644 sysdeps/loongarch/preconfigure.ac
 create mode 100644 sysdeps/loongarch/setjmp.S
 create mode 100644 sysdeps/loongarch/sfp-machine.h
 create mode 100644 sysdeps/loongarch/sotruss-lib.c
 create mode 100644 sysdeps/loongarch/stackinfo.h
 create mode 100644 sysdeps/loongarch/start.S
 create mode 100644 sysdeps/loongarch/sys/asm.h
 create mode 100644 sysdeps/loongarch/sys/ifunc.h
 create mode 100644 sysdeps/loongarch/sys/regdef.h
 create mode 100644 sysdeps/loongarch/tininess.h
 create mode 100644 sysdeps/loongarch/tst-audit.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/arch-syscall.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/atomic-machine.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/procfs.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone3.S
 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/getcontext.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/localplt.data
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/Implies
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/c++-types.data
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/ld.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/libBrokenLocale.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/libc_malloc_debug.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/libcrypt.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/libm.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/libpthread.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/libresolv.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/librt.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/libthread_db.abilist
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/makecontext.c
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/setcontext.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/shlib-versions
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/swapcontext.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sys/user.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sysdep.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/vfork.S

-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v7 01/13] LoongArch: Add LoongArch entries to config.h.in
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
@ 2022-07-19  1:20 ` caiyinyu
  2022-07-21 21:02   ` Adhemerval Zanella Netto
  2022-07-19  1:20 ` [PATCH v7 02/13] LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py caiyinyu
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

---
 config.h.in | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/config.h.in b/config.h.in
index bf316439a0..43d32518ab 100644
--- a/config.h.in
+++ b/config.h.in
@@ -132,6 +132,12 @@
 /* RISC-V floating-point ABI for ld.so.  */
 #undef RISCV_ABI_FLEN
 
+/* LOONGARCH integer ABI for ld.so.  */
+#undef LOONGARCH_ABI_GRLEN
+
+/* LOONGARCH floating-point ABI for ld.so.  */
+#undef LOONGARCH_ABI_FRLEN
+
 /* Linux specific: minimum supported kernel version.  */
 #undef	__LINUX_KERNEL_VERSION
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v7 02/13] LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
  2022-07-19  1:20 ` [PATCH v7 01/13] LoongArch: Add LoongArch entries to config.h.in caiyinyu
@ 2022-07-19  1:20 ` caiyinyu
  2022-07-21 21:02   ` Adhemerval Zanella Netto
  2022-07-19  1:20 ` [PATCH v7 03/13] LoongArch: ABI Implementation caiyinyu
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

---
 elf/elf.h           | 68 ++++++++++++++++++++++++++++++++++++++++++++-
 scripts/glibcelf.py |  3 +-
 2 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/elf/elf.h b/elf/elf.h
index 2b5c2c5fb6..02a1b3f52f 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -358,8 +358,9 @@ typedef struct
 
 #define EM_BPF		247	/* Linux BPF -- in-kernel virtual machine */
 #define EM_CSKY		252     /* C-SKY */
+#define EM_LOONGARCH	258	/* LoongArch */
 
-#define EM_NUM		253
+#define EM_NUM		259
 
 /* Old spellings/synonyms.  */
 
@@ -4083,6 +4084,71 @@ enum
 #define R_NDS32_TLS_TPOFF	102
 #define R_NDS32_TLS_DESC	119
 
+/* LoongArch ELF Flags */
+#define EF_LARCH_ABI    	0x07
+#define EF_LARCH_ABI_LP64D	0x03
+
+/* LoongArch specific dynamic relocations */
+#define R_LARCH_NONE		0
+#define R_LARCH_32		1
+#define R_LARCH_64		2
+#define R_LARCH_RELATIVE	3
+#define R_LARCH_COPY		4
+#define R_LARCH_JUMP_SLOT	5
+#define R_LARCH_TLS_DTPMOD32	6
+#define R_LARCH_TLS_DTPMOD64	7
+#define R_LARCH_TLS_DTPREL32	8
+#define R_LARCH_TLS_DTPREL64	9
+#define R_LARCH_TLS_TPREL32	10
+#define R_LARCH_TLS_TPREL64	11
+#define R_LARCH_IRELATIVE	12
+
+/* Reserved for future relocs that the dynamic linker must understand.  */
+
+/* used by the static linker for relocating .text.  */
+#define R_LARCH_MARK_LA  20
+#define R_LARCH_MARK_PCREL  21
+#define R_LARCH_SOP_PUSH_PCREL  22
+#define R_LARCH_SOP_PUSH_ABSOLUTE  23
+#define R_LARCH_SOP_PUSH_DUP  24
+#define R_LARCH_SOP_PUSH_GPREL  25
+#define R_LARCH_SOP_PUSH_TLS_TPREL  26
+#define R_LARCH_SOP_PUSH_TLS_GOT  27
+#define R_LARCH_SOP_PUSH_TLS_GD  28
+#define R_LARCH_SOP_PUSH_PLT_PCREL  29
+#define R_LARCH_SOP_ASSERT  30
+#define R_LARCH_SOP_NOT  31
+#define R_LARCH_SOP_SUB  32
+#define R_LARCH_SOP_SL  33
+#define R_LARCH_SOP_SR  34
+#define R_LARCH_SOP_ADD  35
+#define R_LARCH_SOP_AND  36
+#define R_LARCH_SOP_IF_ELSE  37
+#define R_LARCH_SOP_POP_32_S_10_5  38
+#define R_LARCH_SOP_POP_32_U_10_12  39
+#define R_LARCH_SOP_POP_32_S_10_12  40
+#define R_LARCH_SOP_POP_32_S_10_16  41
+#define R_LARCH_SOP_POP_32_S_10_16_S2  42
+#define R_LARCH_SOP_POP_32_S_5_20  43
+#define R_LARCH_SOP_POP_32_S_0_5_10_16_S2  44
+#define R_LARCH_SOP_POP_32_S_0_10_10_16_S2  45
+#define R_LARCH_SOP_POP_32_U  46
+
+/* used by the static linker for relocating non .text.  */
+#define R_LARCH_ADD8  47
+#define R_LARCH_ADD16  48
+#define R_LARCH_ADD24  49
+#define R_LARCH_ADD32  50
+#define R_LARCH_ADD64  51
+#define R_LARCH_SUB8  52
+#define R_LARCH_SUB16  53
+#define R_LARCH_SUB24  54
+#define R_LARCH_SUB32  55
+#define R_LARCH_SUB64  56
+#define R_LARCH_GNU_VTINHERIT  57
+#define R_LARCH_GNU_VTENTRY  58
+
+
 /* ARCompact/ARCv2 specific relocs.  */
 #define R_ARC_NONE		0x0
 #define R_ARC_8			0x1
diff --git a/scripts/glibcelf.py b/scripts/glibcelf.py
index 47f95d07ba..de0509130e 100644
--- a/scripts/glibcelf.py
+++ b/scripts/glibcelf.py
@@ -252,7 +252,8 @@ class Machine(_OpenIntEnum):
     EM_RISCV = 243
     EM_BPF = 247
     EM_CSKY = 252
-    EM_NUM = 253
+    EM_LOONGARCH = 258
+    EM_NUM = 259
     EM_ALPHA = 0x9026
 
 class Et(_OpenIntEnum):
-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v7 03/13] LoongArch: ABI Implementation
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
  2022-07-19  1:20 ` [PATCH v7 01/13] LoongArch: Add LoongArch entries to config.h.in caiyinyu
  2022-07-19  1:20 ` [PATCH v7 02/13] LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py caiyinyu
@ 2022-07-19  1:20 ` caiyinyu
  2022-07-20 12:29   ` Adhemerval Zanella Netto
  2022-07-19  1:20 ` [PATCH v7 04/13] LoongArch: Thread-Local Storage Support caiyinyu
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

---
 sysdeps/loongarch/__longjmp.S       |  50 +++++
 sysdeps/loongarch/bits/endianness.h |  11 ++
 sysdeps/loongarch/bits/link.h       |  58 ++++++
 sysdeps/loongarch/bits/setjmp.h     |  39 ++++
 sysdeps/loongarch/bsd-_setjmp.c     |   1 +
 sysdeps/loongarch/bsd-setjmp.c      |   1 +
 sysdeps/loongarch/dl-machine.h      | 288 ++++++++++++++++++++++++++++
 sysdeps/loongarch/dl-trampoline.S   |  83 ++++++++
 sysdeps/loongarch/jmpbuf-offsets.h  |  22 +++
 sysdeps/loongarch/jmpbuf-unwind.h   |  45 +++++
 sysdeps/loongarch/ldsodefs.h        |  41 ++++
 sysdeps/loongarch/linkmap.h         |  22 +++
 sysdeps/loongarch/machine-gmon.h    |  37 ++++
 sysdeps/loongarch/setjmp.S          |  64 +++++++
 sysdeps/loongarch/sotruss-lib.c     |  50 +++++
 sysdeps/loongarch/start.S           |  66 +++++++
 sysdeps/loongarch/sys/asm.h         |  59 ++++++
 sysdeps/loongarch/tst-audit.h       |  23 +++
 18 files changed, 960 insertions(+)
 create mode 100644 sysdeps/loongarch/__longjmp.S
 create mode 100644 sysdeps/loongarch/bits/endianness.h
 create mode 100644 sysdeps/loongarch/bits/link.h
 create mode 100644 sysdeps/loongarch/bits/setjmp.h
 create mode 100644 sysdeps/loongarch/bsd-_setjmp.c
 create mode 100644 sysdeps/loongarch/bsd-setjmp.c
 create mode 100644 sysdeps/loongarch/dl-machine.h
 create mode 100644 sysdeps/loongarch/dl-trampoline.S
 create mode 100644 sysdeps/loongarch/jmpbuf-offsets.h
 create mode 100644 sysdeps/loongarch/jmpbuf-unwind.h
 create mode 100644 sysdeps/loongarch/ldsodefs.h
 create mode 100644 sysdeps/loongarch/linkmap.h
 create mode 100644 sysdeps/loongarch/machine-gmon.h
 create mode 100644 sysdeps/loongarch/setjmp.S
 create mode 100644 sysdeps/loongarch/sotruss-lib.c
 create mode 100644 sysdeps/loongarch/start.S
 create mode 100644 sysdeps/loongarch/sys/asm.h
 create mode 100644 sysdeps/loongarch/tst-audit.h

diff --git a/sysdeps/loongarch/__longjmp.S b/sysdeps/loongarch/__longjmp.S
new file mode 100644
index 0000000000..37e7384413
--- /dev/null
+++ b/sysdeps/loongarch/__longjmp.S
@@ -0,0 +1,50 @@
+/* longjmp.
+   Copyright (C) 2022 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/>.  */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+ENTRY (__longjmp)
+	REG_L ra, a0, 0*SZREG
+	REG_L sp, a0, 1*SZREG
+	REG_L x,  a0, 2*SZREG
+	REG_L fp, a0, 3*SZREG
+	REG_L s0, a0, 4*SZREG
+	REG_L s1, a0, 5*SZREG
+	REG_L s2, a0, 6*SZREG
+	REG_L s3, a0, 7*SZREG
+	REG_L s4, a0, 8*SZREG
+	REG_L s5, a0, 9*SZREG
+	REG_L s6, a0, 10*SZREG
+	REG_L s7, a0, 11*SZREG
+	REG_L s8, a0, 12*SZREG
+
+	FREG_L $f24, a0, 13*SZREG + 0*SZFREG
+	FREG_L $f25, a0, 13*SZREG + 1*SZFREG
+	FREG_L $f26, a0, 13*SZREG + 2*SZFREG
+	FREG_L $f27, a0, 13*SZREG + 3*SZFREG
+	FREG_L $f28, a0, 13*SZREG + 4*SZFREG
+	FREG_L $f29, a0, 13*SZREG + 5*SZFREG
+	FREG_L $f30, a0, 13*SZREG + 6*SZFREG
+	FREG_L $f31, a0, 13*SZREG + 7*SZFREG
+
+	sltui	a0,a1,1
+	ADD	a0, a0, a1	 # a0 = (a1 == 0) ? 1 : a1
+	jirl	zero,ra,0
+
+END (__longjmp)
diff --git a/sysdeps/loongarch/bits/endianness.h b/sysdeps/loongarch/bits/endianness.h
new file mode 100644
index 0000000000..7290be7b18
--- /dev/null
+++ b/sysdeps/loongarch/bits/endianness.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+#error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* LoongArch is little-endian.  */
+#define __BYTE_ORDER __LITTLE_ENDIAN
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/loongarch/bits/link.h b/sysdeps/loongarch/bits/link.h
new file mode 100644
index 0000000000..05c91575e9
--- /dev/null
+++ b/sysdeps/loongarch/bits/link.h
@@ -0,0 +1,58 @@
+/* Machine-specific declarations for dynamic linker interface.
+   Copyright (C) 2022 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 _LINK_H
+#error "Never include <bits/link.h> directly; use <link.h> instead."
+#endif
+
+typedef struct La_loongarch_regs
+{
+  unsigned long int lr_reg[8]; /* a0 - a7 */
+  double lr_fpreg[8];	       /* fa0 - fa7 */
+  unsigned long int lr_ra;
+  unsigned long int lr_sp;
+} La_loongarch_regs;
+
+/* Return values for calls from PLT on LoongArch.  */
+typedef struct La_loongarch_retval
+{
+  unsigned long int lrv_a0;
+  unsigned long int lrv_a1;
+  double lrv_fa0;
+  double lrv_fa1;
+} La_loongarch_retval;
+
+__BEGIN_DECLS
+
+extern ElfW (Addr) la_loongarch_gnu_pltenter (ElfW (Sym) *__sym,
+					      unsigned int __ndx,
+					      uintptr_t *__refcook,
+					      uintptr_t *__defcook,
+					      La_loongarch_regs *__regs,
+					      unsigned int *__flags,
+					      const char *__symname,
+					      long int *__framesizep);
+extern unsigned int la_loongarch_gnu_pltexit (ElfW (Sym) *__sym,
+					      unsigned int __ndx,
+					      uintptr_t *__refcook,
+					      uintptr_t *__defcook,
+					      const La_loongarch_regs *__inregs,
+					      La_loongarch_retval *__outregs,
+					      const char *__symname);
+
+__END_DECLS
diff --git a/sysdeps/loongarch/bits/setjmp.h b/sysdeps/loongarch/bits/setjmp.h
new file mode 100644
index 0000000000..42f8fa7657
--- /dev/null
+++ b/sysdeps/loongarch/bits/setjmp.h
@@ -0,0 +1,39 @@
+/* Define the machine-dependent type `jmp_buf'.
+   Copyright (C) 2022 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 _LOONGARCH_BITS_SETJMP_H
+#define _LOONGARCH_BITS_SETJMP_H
+
+typedef struct __jmp_buf_internal_tag
+{
+  /* Program counter.  */
+  long int __pc;
+  /* Stack pointer.  */
+  long int __sp;
+  /* Reserved */
+  long int __x;
+  /* Frame pointer.  */
+  long int __fp;
+  /* Callee-saved registers.  */
+  long int __regs[9];
+  /* Callee-saved floating point registers.  */
+  double __fpregs[8];
+
+} __jmp_buf[1];
+
+#endif /* _LOONGARCH_BITS_SETJMP_H */
diff --git a/sysdeps/loongarch/bsd-_setjmp.c b/sysdeps/loongarch/bsd-_setjmp.c
new file mode 100644
index 0000000000..32f49441c3
--- /dev/null
+++ b/sysdeps/loongarch/bsd-_setjmp.c
@@ -0,0 +1 @@
+/* _setjmp is implemented in setjmp.S.  */
diff --git a/sysdeps/loongarch/bsd-setjmp.c b/sysdeps/loongarch/bsd-setjmp.c
new file mode 100644
index 0000000000..45fd802aac
--- /dev/null
+++ b/sysdeps/loongarch/bsd-setjmp.c
@@ -0,0 +1 @@
+/* setjmp is implemented in setjmp.S.  */
diff --git a/sysdeps/loongarch/dl-machine.h b/sysdeps/loongarch/dl-machine.h
new file mode 100644
index 0000000000..c69c72d0ff
--- /dev/null
+++ b/sysdeps/loongarch/dl-machine.h
@@ -0,0 +1,288 @@
+/* Machine-dependent ELF dynamic relocation inline functions.
+   Copyright (C) 2022 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 dl_machine_h
+#define dl_machine_h
+
+#define ELF_MACHINE_NAME "LoongArch"
+
+#include <entry.h>
+#include <elf/elf.h>
+#include <sys/asm.h>
+#include <dl-tls.h>
+#include <dl-static-tls.h>
+#include <dl-machine-rel.h>
+
+#ifndef _RTLD_PROLOGUE
+# define _RTLD_PROLOGUE(entry)					\
+	".globl\t" __STRING (entry) "\n\t"			\
+	".type\t" __STRING (entry) ", @function\n\t"		\
+	CFI_STARTPROC "\n"					\
+	__STRING (entry) ":\n"
+#endif
+
+#ifndef _RTLD_EPILOGUE
+# define _RTLD_EPILOGUE(entry)					\
+	CFI_ENDPROC "\n\t"					\
+	".size\t" __STRING (entry) ", . - " __STRING (entry) "\n"
+#endif
+
+#define ELF_MACHINE_JMP_SLOT R_LARCH_JUMP_SLOT
+#define ELF_MACHINE_IRELATIVE R_LARCH_IRELATIVE
+
+#define elf_machine_type_class(type)				\
+  ((ELF_RTYPE_CLASS_PLT *((type) == ELF_MACHINE_JMP_SLOT))	\
+   | (ELF_RTYPE_CLASS_COPY *((type) == R_LARCH_COPY)))
+
+#define ELF_MACHINE_NO_REL 1
+#define ELF_MACHINE_NO_RELA 0
+
+/* Return nonzero iff ELF header is compatible with the running host.  */
+static inline int
+elf_machine_matches_host (const ElfW (Ehdr) *ehdr)
+{
+  /* We can only run LoongArch binaries.  */
+  if (ehdr->e_machine != EM_LOONGARCH)
+    return 0;
+
+  return 1;
+}
+
+/* Return the run-time load address of the shared object.  */
+static inline ElfW (Addr) elf_machine_load_address (void)
+{
+  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
+  return (ElfW(Addr)) &__ehdr_start;
+}
+
+/* Return the link-time address of _DYNAMIC.  */
+static inline ElfW (Addr) elf_machine_dynamic (void)
+{
+  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+  return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
+}
+
+/* Initial entry point code for the dynamic linker.
+   The C function `_dl_start' is the real entry point;
+   its return value is the user program's entry point.  */
+
+#define RTLD_START asm (\
+	".text\n\
+	" _RTLD_PROLOGUE (ENTRY_POINT) "\
+	.cfi_label .Ldummy   \n\
+	" CFI_UNDEFINED (1) "   \n\
+	or	$a0, $sp, $zero   \n\
+	bl	_dl_start   \n\
+	# Stash user entry point in s0.   \n\
+	or	$s0, $v0, $zero   \n\
+	# Load the original argument count.   \n\
+	ld.d	$a1, $sp, 0   \n\
+	# Call _dl_init (struct link_map *main_map, int argc, \
+			 char **argv, char **env)    \n\
+	la	$a0, _rtld_local   \n\
+	ld.d	$a0, $a0, 0   \n\
+	addi.d	$a2, $sp, 8   \n\
+	slli.d	$a3, $a1, 3   \n\
+	add.d	$a3, $a3, $a2   \n\
+	addi.d	$a3, $a3, 8   \n\
+	# Stash the stack pointer in s1.\n\
+	or	$s1, $sp, $zero	\n\
+	# Adjust $sp for 16-aligned   \n\
+	bstrins.d	$sp, $zero, 3, 0  \n\
+	# Call the function to run the initializers.   \n\
+	bl	_dl_init   \n\
+	# Restore the stack pointer for _start.\n\
+	or	$sp, $s1, $zero	 \n\
+	# Pass our finalizer function to _start.   \n\
+	la	$a0, _dl_fini   \n\
+	# Jump to the user entry point.   \n\
+	jirl	$zero, $s0, 0   \n\
+	" _RTLD_EPILOGUE (ENTRY_POINT) "\
+	.previous");
+
+/* Names of the architecture-specific auditing callback functions.  */
+#define ARCH_LA_PLTENTER loongarch_gnu_pltenter
+#define ARCH_LA_PLTEXIT loongarch_gnu_pltexit
+
+/* Bias .got.plt entry by the offset requested by the PLT header.  */
+#define elf_machine_plt_value(map, reloc, value) (value)
+
+static inline ElfW (Addr)
+elf_machine_fixup_plt (struct link_map *map, lookup_t t,
+			 const ElfW (Sym) *refsym, const ElfW (Sym) *sym,
+			 const ElfW (Rela) *reloc, ElfW (Addr) *reloc_addr,
+			 ElfW (Addr) value)
+{
+  return *reloc_addr = value;
+}
+
+#endif /* !dl_machine_h */
+
+#ifdef RESOLVE_MAP
+
+/* Perform a relocation described by R_INFO at the location pointed to
+   by RELOC_ADDR.  SYM is the relocation symbol specified by R_INFO and
+   MAP is the object containing the reloc.  */
+
+static inline void __attribute__ ((always_inline))
+elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
+		  const ElfW (Rela) *reloc,
+		  const ElfW (Sym) *sym,
+		  const struct r_found_version *version,
+		  void *const reloc_addr, int skip_ifunc)
+{
+  ElfW (Addr) r_info = reloc->r_info;
+  const unsigned long int r_type = ELFW (R_TYPE) (r_info);
+  ElfW (Addr) *addr_field = (ElfW (Addr) *) reloc_addr;
+  const ElfW (Sym) *const __attribute__ ((unused)) refsym = sym;
+  struct link_map *sym_map = RESOLVE_MAP (map, scope, &sym, version, r_type);
+  ElfW (Addr) value = 0;
+  if (sym_map != NULL)
+    value = SYMBOL_ADDRESS (sym_map, sym, true) + reloc->r_addend;
+
+  if (sym != NULL
+      && __glibc_unlikely (ELFW (ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)
+      && __glibc_likely (sym->st_shndx != SHN_UNDEF)
+      && __glibc_likely (!skip_ifunc))
+    value = ((ElfW (Addr) (*) (int)) value) (GLRO (dl_hwcap));
+
+  switch (r_type)
+    {
+
+    case R_LARCH_JUMP_SLOT:
+    case __WORDSIZE == 64 ? R_LARCH_64:
+    R_LARCH_32:
+      *addr_field = value;
+      break;
+
+    case R_LARCH_NONE:
+      break;
+
+#ifndef RTLD_BOOTSTRAP
+    case __WORDSIZE == 64 ? R_LARCH_TLS_DTPMOD64:
+    R_LARCH_TLS_DTPMOD32:
+      *addr_field = sym_map->l_tls_modid;
+      break;
+
+    case __WORDSIZE == 64 ? R_LARCH_TLS_DTPREL64:
+    R_LARCH_TLS_DTPREL32:
+      *addr_field = TLS_DTPREL_VALUE (sym) + reloc->r_addend;
+      break;
+
+    case __WORDSIZE == 64 ? R_LARCH_TLS_TPREL64:
+    R_LARCH_TLS_TPREL32:
+      CHECK_STATIC_TLS (map, sym_map);
+      *addr_field = TLS_TPREL_VALUE (sym_map, sym) + reloc->r_addend;
+      break;
+
+    case R_LARCH_COPY:
+      {
+	  if (sym == NULL)
+	    /* This can happen in trace mode if an object could not be
+	       found.  */
+	    break;
+	  if (__glibc_unlikely (sym->st_size > refsym->st_size)
+	      || (__glibc_unlikely (sym->st_size < refsym->st_size)
+		&& GLRO(dl_verbose)))
+	  {
+	    const char *strtab;
+
+	    strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
+	    _dl_error_printf ("\
+%s: Symbol `%s' has different size in shared object, consider re-linking\n",
+	    rtld_progname ?: "<program name unknown>",
+	    strtab + refsym->st_name);
+	  }
+	  memcpy (reloc_addr, (void *) value,
+		  MIN (sym->st_size, refsym->st_size));
+	    break;
+      }
+
+    case R_LARCH_RELATIVE:
+      *addr_field = map->l_addr + reloc->r_addend;
+      break;
+
+    case R_LARCH_IRELATIVE:
+      value = map->l_addr + reloc->r_addend;
+      if (__glibc_likely (!skip_ifunc))
+	value = ((ElfW (Addr) (*) (void)) value) ();
+      *addr_field = value;
+      break;
+
+#endif
+
+    default:
+      _dl_reloc_bad_type (map, r_type, 0);
+      break;
+    }
+}
+
+static inline void __attribute__ ((always_inline))
+elf_machine_rela_relative (ElfW (Addr) l_addr, const ElfW (Rela) *reloc,
+			   void *const reloc_addr)
+{
+  *(ElfW (Addr) *) reloc_addr = l_addr + reloc->r_addend;
+}
+
+static inline void __attribute__ ((always_inline))
+elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
+		      ElfW (Addr) l_addr,
+		      const ElfW (Rela) *reloc, int skip_ifunc)
+{
+  ElfW (Addr) *const reloc_addr = (void *) (l_addr + reloc->r_offset);
+  const unsigned int r_type = ELFW (R_TYPE) (reloc->r_info);
+
+  /* Check for unexpected PLT reloc type.  */
+  if (__glibc_likely (r_type == R_LARCH_JUMP_SLOT))
+    {
+      if (__glibc_unlikely (map->l_mach.plt == 0))
+	{
+	  if (l_addr)
+	    *reloc_addr += l_addr;
+	}
+      else
+	*reloc_addr = map->l_mach.plt;
+    }
+  else
+    _dl_reloc_bad_type (map, r_type, 1);
+}
+
+/* Set up the loaded object described by L so its stub function
+   will jump to the on-demand fixup code __dl_runtime_resolve.  */
+
+static inline int __attribute__ ((always_inline))
+elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
+			   int lazy, int profile)
+{
+#ifndef RTLD_BOOTSTRAP
+  /* If using PLTs, fill in the first two entries of .got.plt.  */
+  if (l->l_info[DT_JMPREL])
+    {
+      extern void _dl_runtime_resolve (void)
+	__attribute__ ((visibility ("hidden")));
+      ElfW (Addr) *gotplt = (ElfW (Addr) *) D_PTR (l, l_info[DT_PLTGOT]);
+      gotplt[0] = (ElfW (Addr)) & _dl_runtime_resolve;
+      gotplt[1] = (ElfW (Addr)) l;
+    }
+#endif
+
+  return lazy;
+}
+
+#endif /* RESOLVE_MAP */
diff --git a/sysdeps/loongarch/dl-trampoline.S b/sysdeps/loongarch/dl-trampoline.S
new file mode 100644
index 0000000000..ad8ab0fda7
--- /dev/null
+++ b/sysdeps/loongarch/dl-trampoline.S
@@ -0,0 +1,83 @@
+/* PLT trampolines.
+   Copyright (C) 2022 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/>.  */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+/* Assembler veneer called from the PLT header code for lazy loading.
+   The PLT header passes its own args in t0-t2.  */
+
+# define FRAME_SIZE (-((-10 * SZREG - 8 * SZFREG) & ALMASK))
+
+ENTRY (_dl_runtime_resolve)
+
+	/* Save arguments to stack. */
+	ADDI	sp, sp, -FRAME_SIZE
+
+	REG_S	ra, sp, 9*SZREG
+	REG_S	a0, sp, 1*SZREG
+	REG_S	a1, sp, 2*SZREG
+	REG_S	a2, sp, 3*SZREG
+	REG_S	a3, sp, 4*SZREG
+	REG_S	a4, sp, 5*SZREG
+	REG_S	a5, sp, 6*SZREG
+	REG_S	a6, sp, 7*SZREG
+	REG_S	a7, sp, 8*SZREG
+
+	FREG_S	fa0, sp, 10*SZREG + 0*SZFREG
+	FREG_S	fa1, sp, 10*SZREG + 1*SZFREG
+	FREG_S	fa2, sp, 10*SZREG + 2*SZFREG
+	FREG_S	fa3, sp, 10*SZREG + 3*SZFREG
+	FREG_S	fa4, sp, 10*SZREG + 4*SZFREG
+	FREG_S	fa5, sp, 10*SZREG + 5*SZFREG
+	FREG_S	fa6, sp, 10*SZREG + 6*SZFREG
+	FREG_S	fa7, sp, 10*SZREG + 7*SZFREG
+
+	/* Update .got.plt and obtain runtime address of callee */
+	SLLI	a1, t1, 1
+	or	a0, t0, zero
+	ADD	a1, a1, t1
+	la	a2, _dl_fixup
+	jirl	ra, a2, 0
+	or	t1, v0, zero
+
+	/* Restore arguments from stack. */
+	REG_L	ra, sp, 9*SZREG
+	REG_L	a0, sp, 1*SZREG
+	REG_L	a1, sp, 2*SZREG
+	REG_L	a2, sp, 3*SZREG
+	REG_L	a3, sp, 4*SZREG
+	REG_L	a4, sp, 5*SZREG
+	REG_L	a5, sp, 6*SZREG
+	REG_L	a6, sp, 7*SZREG
+	REG_L	a7, sp, 8*SZREG
+
+	FREG_L	fa0, sp, 10*SZREG + 0*SZFREG
+	FREG_L	fa1, sp, 10*SZREG + 1*SZFREG
+	FREG_L	fa2, sp, 10*SZREG + 2*SZFREG
+	FREG_L	fa3, sp, 10*SZREG + 3*SZFREG
+	FREG_L	fa4, sp, 10*SZREG + 4*SZFREG
+	FREG_L	fa5, sp, 10*SZREG + 5*SZFREG
+	FREG_L	fa6, sp, 10*SZREG + 6*SZFREG
+	FREG_L	fa7, sp, 10*SZREG + 7*SZFREG
+
+	ADDI	sp, sp, FRAME_SIZE
+
+	/* Invoke the callee. */
+	jirl		zero, t1, 0
+END (_dl_runtime_resolve)
diff --git a/sysdeps/loongarch/jmpbuf-offsets.h b/sysdeps/loongarch/jmpbuf-offsets.h
new file mode 100644
index 0000000000..a4b8ea690e
--- /dev/null
+++ b/sysdeps/loongarch/jmpbuf-offsets.h
@@ -0,0 +1,22 @@
+/* Private macros for accessing __jmp_buf contents.
+   Copyright (C) 2022 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/>.  */
+
+#include <jmpbuf-unwind.h>
+
+/* Helper for generic ____longjmp_chk().  */
+#define JB_FRAME_ADDRESS(buf) ((void *) _jmpbuf_sp (buf))
diff --git a/sysdeps/loongarch/jmpbuf-unwind.h b/sysdeps/loongarch/jmpbuf-unwind.h
new file mode 100644
index 0000000000..6fa509151d
--- /dev/null
+++ b/sysdeps/loongarch/jmpbuf-unwind.h
@@ -0,0 +1,45 @@
+/* Examine __jmp_buf for unwinding frames.
+   Copyright (C) 2022 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/>.  */
+
+#include <setjmp.h>
+#include <stdint.h>
+#include <unwind.h>
+#include <sysdep.h>
+
+/* Test if longjmp to JMPBUF would unwind the frame
+   containing a local variable at ADDRESS.  */
+#define _JMPBUF_UNWINDS(jmpbuf, address, demangle) \
+  ((void *) (address) < (void *) demangle ((jmpbuf)[0].__sp))
+
+#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
+  _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+
+static inline uintptr_t __attribute__ ((unused)) _jmpbuf_sp (__jmp_buf regs)
+{
+  uintptr_t sp = regs[0].__sp;
+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif
+  return sp;
+}
+
+#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
+  ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
+
+/* We use the normal longjmp for unwinding.  */
+#define __libc_unwind_longjmp(buf, val) __libc_longjmp (buf, val)
diff --git a/sysdeps/loongarch/ldsodefs.h b/sysdeps/loongarch/ldsodefs.h
new file mode 100644
index 0000000000..36b1b25b9f
--- /dev/null
+++ b/sysdeps/loongarch/ldsodefs.h
@@ -0,0 +1,41 @@
+/* Run-time dynamic linker data structures for loaded ELF shared objects.
+   Copyright (C) 2022 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 _LOONGARCH_LDSODEFS_H
+#define _LOONGARCH_LDSODEFS_H 1
+
+#include <elf.h>
+
+struct La_loongarch_regs;
+struct La_loongarch_retval;
+
+#define ARCH_PLTENTER_MEMBERS \
+  ElfW (Addr) (*loongarch_gnu_pltenter) (ElfW (Sym) *, unsigned int, \
+					 uintptr_t *, uintptr_t *, \
+					 const struct La_loongarch_regs *, \
+					 unsigned int *, const char *name, \
+					 long int *framesizep);
+
+#define ARCH_PLTEXIT_MEMBERS \
+  unsigned int (*loongarch_gnu_pltexit) (ElfW (Sym) *, unsigned int, \
+		uintptr_t *, uintptr_t *, const struct La_loongarch_regs *, \
+		struct La_loongarch_retval *, const char *);
+
+#include_next <ldsodefs.h>
+
+#endif
diff --git a/sysdeps/loongarch/linkmap.h b/sysdeps/loongarch/linkmap.h
new file mode 100644
index 0000000000..bbba73ed70
--- /dev/null
+++ b/sysdeps/loongarch/linkmap.h
@@ -0,0 +1,22 @@
+/* Definition of link_map_machine.
+   Copyright (C) 2022 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/>.  */
+
+struct link_map_machine
+{
+  ElfW (Addr) plt; /* Address of .plt.  */
+};
diff --git a/sysdeps/loongarch/machine-gmon.h b/sysdeps/loongarch/machine-gmon.h
new file mode 100644
index 0000000000..4a3cdd964e
--- /dev/null
+++ b/sysdeps/loongarch/machine-gmon.h
@@ -0,0 +1,37 @@
+/* LoongArch definitions for profiling support.
+   Copyright (C) 2022 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/>.  */
+
+/* Accept 'frompc' address as argument from the function that calls
+   _mcount for profiling.  Use  __builtin_return_address (0)
+   for the 'selfpc' address.  */
+
+#include <sysdep.h>
+
+static void mcount_internal (unsigned long int frompc,
+			     unsigned long int selfpc);
+
+#define _MCOUNT_DECL(frompc, selfpc) \
+  static inline void mcount_internal (unsigned long int frompc, \
+				      unsigned long int selfpc)
+
+#define MCOUNT \
+  void _mcount (void *frompc) \
+  { \
+    mcount_internal ((unsigned long int) frompc, \
+		     (unsigned long int) RETURN_ADDRESS (0)); \
+  }
diff --git a/sysdeps/loongarch/setjmp.S b/sysdeps/loongarch/setjmp.S
new file mode 100644
index 0000000000..3afb9f3948
--- /dev/null
+++ b/sysdeps/loongarch/setjmp.S
@@ -0,0 +1,64 @@
+/* setjmp for LoongArch.
+   Copyright (C) 2022 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/>.  */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+ENTRY (_setjmp)
+	li.w		a1,0
+	b		HIDDEN_JUMPTARGET (__sigsetjmp)
+END (_setjmp)
+
+ENTRY (setjmp)
+	li.w		a1,1
+END (setjmp)
+
+ENTRY (__sigsetjmp)
+	REG_S ra, a0, 0*SZREG
+	REG_S sp, a0, 1*SZREG
+	REG_S x,  a0, 2*SZREG
+	REG_S fp, a0, 3*SZREG
+	REG_S s0, a0, 4*SZREG
+	REG_S s1, a0, 5*SZREG
+	REG_S s2, a0, 6*SZREG
+	REG_S s3, a0, 7*SZREG
+	REG_S s4, a0, 8*SZREG
+	REG_S s5, a0, 9*SZREG
+	REG_S s6, a0, 10*SZREG
+	REG_S s7, a0, 11*SZREG
+	REG_S s8, a0, 12*SZREG
+
+	FREG_S $f24, a0, 13*SZREG + 0*SZFREG
+	FREG_S $f25, a0, 13*SZREG + 1*SZFREG
+	FREG_S $f26, a0, 13*SZREG + 2*SZFREG
+	FREG_S $f27, a0, 13*SZREG + 3*SZFREG
+	FREG_S $f28, a0, 13*SZREG + 4*SZFREG
+	FREG_S $f29, a0, 13*SZREG + 5*SZFREG
+	FREG_S $f30, a0, 13*SZREG + 6*SZFREG
+	FREG_S $f31, a0, 13*SZREG + 7*SZFREG
+
+#if !IS_IN (libc) && IS_IN(rtld)
+	li.w		v0, 0
+	jirl		zero,ra,0
+#else
+	b		__sigjmp_save
+#endif
+END (__sigsetjmp)
+
+hidden_def (__sigsetjmp)
+weak_alias (_setjmp, __GI__setjmp)
diff --git a/sysdeps/loongarch/sotruss-lib.c b/sysdeps/loongarch/sotruss-lib.c
new file mode 100644
index 0000000000..ce752785f6
--- /dev/null
+++ b/sysdeps/loongarch/sotruss-lib.c
@@ -0,0 +1,50 @@
+/* Override generic sotruss-lib.c to define actual functions for LoongArch.
+   Copyright (C) 2022 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/>.  */
+
+#define HAVE_ARCH_PLTENTER
+#define HAVE_ARCH_PLTEXIT
+
+#include <elf/sotruss-lib.c>
+
+ElfW (Addr)
+la_loongarch_gnu_pltenter (ElfW (Sym) *sym __attribute__ ((unused)),
+			   unsigned int ndx __attribute__ ((unused)),
+			   uintptr_t *refcook, uintptr_t *defcook,
+			   La_loongarch_regs *regs, unsigned int *flags,
+			   const char *symname, long int *framesizep)
+{
+  print_enter (refcook, defcook, symname, regs->lr_reg[0], regs->lr_reg[1],
+		   regs->lr_reg[2], *flags);
+
+  /* No need to copy anything, we will not need the parameters in any case.  */
+  *framesizep = 0;
+
+  return sym->st_value;
+}
+
+unsigned int
+la_loongarch_gnu_pltexit (ElfW (Sym) *sym, unsigned int ndx,
+			  uintptr_t *refcook, uintptr_t *defcook,
+			  const struct La_loongarch_regs *inregs,
+			  struct La_loongarch_retval *outregs,
+			  const char *symname)
+{
+  print_exit (refcook, defcook, symname, outregs->lrv_a0);
+
+  return 0;
+}
diff --git a/sysdeps/loongarch/start.S b/sysdeps/loongarch/start.S
new file mode 100644
index 0000000000..280b5fab8c
--- /dev/null
+++ b/sysdeps/loongarch/start.S
@@ -0,0 +1,66 @@
+/* Startup code compliant to the ELF LoongArch ABI.
+   Copyright (C) 2022 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/>.  */
+
+#define __ASSEMBLY__ 1
+#include <entry.h>
+#include <sys/asm.h>
+
+/* The entry point's job is to call __libc_start_main.  Per the ABI,
+   a0 contains the address of a function to be passed to atexit.
+   __libc_start_main wants this in a5.  */
+
+/*
+int
+__libc_start_main (int (*main) (int, char **, char **),
+		   int argc,
+		   char **argv,
+		   __typeof (main) init,
+		   void (*fini) (void),
+		   void (*rtld_fini) (void),
+		   void *stack_end);
+ */
+
+ENTRY (ENTRY_POINT)
+
+/* Terminate call stack by noting ra is undefined.  Use a dummy
+   .cfi_label to force starting the FDE.  */
+	.cfi_label .Ldummy
+	cfi_undefined (1)
+	or		a5, a0, zero /* rtld_fini */
+
+/* We must get symbol main through GOT table, since main may not be local.
+   For instance: googletest defines main in dynamic library.  */
+	la.got		a0, t0, main
+	REG_L		a1, sp, 0
+	ADDI		a2, sp, SZREG
+
+	/* Adjust $sp for 16-aligned */
+	BSTRINS		sp, zero, 3, 0
+
+	move		a3, zero /* used to be init */
+	move		a4, zero /* used to be fini */
+	or		a6, sp, zero /* stack_end */
+
+	la.got		ra, t0, __libc_start_main
+	jirl		ra, ra, 0
+
+	la.got		ra, t0, abort
+	jirl		ra, ra, 0
+END (ENTRY_POINT)
+
diff --git a/sysdeps/loongarch/sys/asm.h b/sysdeps/loongarch/sys/asm.h
new file mode 100644
index 0000000000..b41ee59694
--- /dev/null
+++ b/sysdeps/loongarch/sys/asm.h
@@ -0,0 +1,59 @@
+/* Miscellaneous macros.
+   Copyright (C) 2022 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_ASM_H
+#define _SYS_ASM_H
+
+#include <sys/regdef.h>
+#include <sysdeps/generic/sysdep.h>
+
+/* Macros to handle different pointer/register sizes for 32/64-bit code.  */
+#define SZREG 8
+#define SZFREG 8
+#define REG_L ld.d
+#define REG_S st.d
+#define SRLI srli.d
+#define SLLI slli.d
+#define ADDI addi.d
+#define ADD  add.d
+#define BSTRINS  bstrins.d
+#define LI  li.d
+#define FREG_L fld.d
+#define FREG_S fst.d
+
+/* Declare leaf routine.  */
+#define LEAF(symbol) \
+  .text; \
+  .globl symbol; \
+  .align 3; \
+  cfi_startproc; \
+  .type symbol, @function; \
+  symbol:
+
+#define ENTRY(symbol) LEAF (symbol)
+
+/* Mark end of function.  */
+#undef END
+#define END(function) \
+  cfi_endproc; \
+  .size function, .- function;
+
+/* Stack alignment.  */
+#define ALMASK ~15
+
+#endif /* sys/asm.h */
diff --git a/sysdeps/loongarch/tst-audit.h b/sysdeps/loongarch/tst-audit.h
new file mode 100644
index 0000000000..e71948c86e
--- /dev/null
+++ b/sysdeps/loongarch/tst-audit.h
@@ -0,0 +1,23 @@
+/* Definitions for testing PLT entry/exit auditing.
+   Copyright (C) 2022 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/>.  */
+
+#define pltenter la_loongarch_gnu_pltenter
+#define pltexit la_loongarch_gnu_pltexit
+#define La_regs La_loongarch_regs
+#define La_retval La_loongarch_retval
+#define int_retval lrv_a0
-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v7 04/13] LoongArch: Thread-Local Storage Support
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
                   ` (2 preceding siblings ...)
  2022-07-19  1:20 ` [PATCH v7 03/13] LoongArch: ABI Implementation caiyinyu
@ 2022-07-19  1:20 ` caiyinyu
  2022-07-20 14:34   ` Adhemerval Zanella Netto
  2022-07-19  1:20 ` [PATCH v7 05/13] LoongArch: Generic <math.h> and soft-fp Routines caiyinyu
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

---
 sysdeps/loongarch/dl-tls.h    |  46 ++++++++++++
 sysdeps/loongarch/libc-tls.c  |  32 ++++++++
 sysdeps/loongarch/nptl/tls.h  | 138 ++++++++++++++++++++++++++++++++++
 sysdeps/loongarch/stackinfo.h |  33 ++++++++
 4 files changed, 249 insertions(+)
 create mode 100644 sysdeps/loongarch/dl-tls.h
 create mode 100644 sysdeps/loongarch/libc-tls.c
 create mode 100644 sysdeps/loongarch/nptl/tls.h
 create mode 100644 sysdeps/loongarch/stackinfo.h

diff --git a/sysdeps/loongarch/dl-tls.h b/sysdeps/loongarch/dl-tls.h
new file mode 100644
index 0000000000..f82edcae76
--- /dev/null
+++ b/sysdeps/loongarch/dl-tls.h
@@ -0,0 +1,46 @@
+/* Thread-local storage handling in the ELF dynamic linker.
+   Copyright (C) 2022 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/>.  */
+
+/* Type used for the representation of TLS information in the GOT.  */
+typedef struct
+{
+  unsigned long int ti_module;
+  unsigned long int ti_offset;
+} tls_index;
+
+/* The thread pointer points to the first static TLS block.  */
+#define TLS_TP_OFFSET 0
+
+/* Dynamic thread vector pointers point to the start of each
+   TLS block.  */
+#define TLS_DTV_OFFSET 0
+
+/* Compute the value for a GOTTPREL reloc.  */
+#define TLS_TPREL_VALUE(sym_map, sym) \
+  ((sym_map)->l_tls_offset + (sym)->st_value - TLS_TP_OFFSET)
+
+/* Compute the value for a DTPREL reloc.  */
+#define TLS_DTPREL_VALUE(sym) ((sym)->st_value - TLS_DTV_OFFSET)
+
+extern void *__tls_get_addr (tls_index *ti);
+
+#define GET_ADDR_OFFSET (ti->ti_offset + TLS_DTV_OFFSET)
+#define __TLS_GET_ADDR(__ti) (__tls_get_addr (__ti) - TLS_DTV_OFFSET)
+
+/* Value used for dtv entries for which the allocation is delayed.  */
+#define TLS_DTV_UNALLOCATED ((void *) -1l)
diff --git a/sysdeps/loongarch/libc-tls.c b/sysdeps/loongarch/libc-tls.c
new file mode 100644
index 0000000000..9285d11a7b
--- /dev/null
+++ b/sysdeps/loongarch/libc-tls.c
@@ -0,0 +1,32 @@
+/* Thread-local storage handling in the ELF dynamic linker.
+   Copyright (C) 2022 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/>.  */
+
+#include <csu/libc-tls.c>
+#include <dl-tls.h>
+
+/* On LoongArch, linker optimizations are not required, so __tls_get_addr
+   can be called even in statically linked binaries.  In this case module
+   must be always 1 and PT_TLS segment exist in the binary, otherwise it
+   would not link.  */
+
+void *
+__tls_get_addr (tls_index *ti)
+{
+  dtv_t *dtv = THREAD_DTV ();
+  return (char *) dtv[1].pointer.val + GET_ADDR_OFFSET;
+}
diff --git a/sysdeps/loongarch/nptl/tls.h b/sysdeps/loongarch/nptl/tls.h
new file mode 100644
index 0000000000..3b271c4b60
--- /dev/null
+++ b/sysdeps/loongarch/nptl/tls.h
@@ -0,0 +1,138 @@
+/* Definition for thread-local data handling.
+   Copyright (C) 2022 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 _LOONGARCH_TLS_H
+#define _LOONGARCH_TLS_H 1
+
+#include <dl-sysdep.h>
+
+#ifndef __ASSEMBLER__
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <dl-dtv.h>
+
+register void *__thread_self asm ("$tp");
+#define READ_THREAD_POINTER() ({ __thread_self; })
+
+/* Get system call information.  */
+#include <sysdep.h>
+
+/* The TP points to the start of the thread blocks.  */
+#define TLS_DTV_AT_TP 1
+#define TLS_TCB_AT_TP 0
+
+/* Get the thread descriptor definition.  */
+#include <nptl/descr.h>
+
+typedef struct
+{
+  dtv_t *dtv;
+  void *private;
+} tcbhead_t;
+
+/* This is the size of the initial TCB.  Because our TCB is before the thread
+   pointer, we don't need this.  */
+#define TLS_INIT_TCB_SIZE 0
+
+/* Alignment requirements for the initial TCB.  */
+#define TLS_INIT_TCB_ALIGN __alignof__(struct pthread)
+
+/* This is the size of the TCB.  Because our TCB is before the thread
+   pointer, we don't need this.  */
+#define TLS_TCB_SIZE 0
+
+/* Alignment requirements for the TCB.  */
+#define TLS_TCB_ALIGN __alignof__(struct pthread)
+
+/* This is the size we need before TCB - actually, it includes the TCB.  */
+#define TLS_PRE_TCB_SIZE \
+  (sizeof (struct pthread) \
+   + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
+
+/* The thread pointer tp points to the end of the TCB.
+   The pthread_descr structure is immediately in front of the TCB.  */
+#define TLS_TCB_OFFSET 0
+
+/* Install the dtv pointer.  The pointer passed is to the element with
+   index -1 which contain the length.  */
+#define INSTALL_DTV(tcbp, dtvp) (((tcbhead_t *) (tcbp))[-1].dtv = (dtvp) + 1)
+
+/* Install new dtv for current thread.  */
+#define INSTALL_NEW_DTV(dtv) (THREAD_DTV () = (dtv))
+
+/* Return dtv of given thread descriptor.  */
+#define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
+
+/* Code to initially initialize the thread pointer.  */
+#define TLS_INIT_TP(tcbp) \
+  ({ \
+    __thread_self = (char *) tcbp + TLS_TCB_OFFSET; \
+    NULL; \
+  })
+
+/* Return the address of the dtv for the current thread.  */
+#define THREAD_DTV() \
+  (((tcbhead_t *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET))[-1].dtv)
+
+/* Return the thread descriptor for the current thread.  */
+#define THREAD_SELF \
+  ((struct pthread *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET \
+		       - TLS_PRE_TCB_SIZE))
+
+/* Value passed to 'clone' for initialization of the thread register.  */
+#define TLS_DEFINE_INIT_TP(tp, pd) \
+  void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
+
+/* Informs libthread_db that the thread pointer is register 2, which is used
+ * to know how to do THREAD_SELF.  */
+#define DB_THREAD_SELF \
+  REGISTER (64, 64, 2 * 8, -TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
+
+/* Access to data in the thread descriptor is easy.  */
+# include <tcb-access.h>
+
+/* l_tls_offset == 0 is perfectly valid, so we have to use some different
+   value to mean unset l_tls_offset.  */
+#define NO_TLS_OFFSET -1
+
+/* Get and set the global scope generation counter in struct pthread.  */
+#define THREAD_GSCOPE_IN_TCB 1
+#define THREAD_GSCOPE_FLAG_UNUSED 0
+#define THREAD_GSCOPE_FLAG_USED 1
+#define THREAD_GSCOPE_FLAG_WAIT 2
+#define THREAD_GSCOPE_RESET_FLAG() \
+  do \
+    { \
+      int __res = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
+				       THREAD_GSCOPE_FLAG_UNUSED); \
+      if (__res == THREAD_GSCOPE_FLAG_WAIT) \
+	lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
+    } \
+  while (0)
+#define THREAD_GSCOPE_SET_FLAG() \
+  do \
+    { \
+      THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
+      atomic_write_barrier (); \
+    } \
+  while (0)
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* tls.h */
diff --git a/sysdeps/loongarch/stackinfo.h b/sysdeps/loongarch/stackinfo.h
new file mode 100644
index 0000000000..ff8b9b7bf2
--- /dev/null
+++ b/sysdeps/loongarch/stackinfo.h
@@ -0,0 +1,33 @@
+/* Stack environment definitions for LoongArch.
+   Copyright (C) 2022 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/>.  */
+
+/* This file contains a bit of information about the stack allocation
+   of the processor.  */
+
+#ifndef _STACKINFO_H
+#define _STACKINFO_H 1
+
+#include <elf.h>
+
+/* On LoongArch the stack grows down.  */
+#define _STACK_GROWS_DOWN 1
+
+/* Default to a non-executable stack.  */
+#define DEFAULT_STACK_PERMS (PF_R | PF_W)
+
+#endif /* stackinfo.h */
-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v7 05/13] LoongArch: Generic <math.h> and soft-fp Routines
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
                   ` (3 preceding siblings ...)
  2022-07-19  1:20 ` [PATCH v7 04/13] LoongArch: Thread-Local Storage Support caiyinyu
@ 2022-07-19  1:20 ` caiyinyu
  2022-07-20 13:04   ` Adhemerval Zanella Netto
  2022-07-19  1:20 ` [PATCH v7 06/13] LoongArch: Atomic and Locking Routines caiyinyu
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

---
 sysdeps/loongarch/bits/fenv.h   |  90 ++++++++++++++++++++++++++++
 sysdeps/loongarch/e_sqrtl.c     |  39 ++++++++++++
 sysdeps/loongarch/fpu_control.h |  90 ++++++++++++++++++++++++++++
 sysdeps/loongarch/sfp-machine.h | 102 ++++++++++++++++++++++++++++++++
 sysdeps/loongarch/tininess.h    |   1 +
 5 files changed, 322 insertions(+)
 create mode 100644 sysdeps/loongarch/bits/fenv.h
 create mode 100644 sysdeps/loongarch/e_sqrtl.c
 create mode 100644 sysdeps/loongarch/fpu_control.h
 create mode 100644 sysdeps/loongarch/sfp-machine.h
 create mode 100644 sysdeps/loongarch/tininess.h

diff --git a/sysdeps/loongarch/bits/fenv.h b/sysdeps/loongarch/bits/fenv.h
new file mode 100644
index 0000000000..7e223b402b
--- /dev/null
+++ b/sysdeps/loongarch/bits/fenv.h
@@ -0,0 +1,90 @@
+/* Floating point environment.
+   Copyright (C) 2022 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 _FENV_H
+#error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
+#endif
+
+/* Define bits representing the exception.  We use the bit positions
+   of the appropriate bits in the FPU control word.  */
+enum
+{
+  FE_INEXACT =
+#define FE_INEXACT 0x010000
+    FE_INEXACT,
+  FE_UNDERFLOW =
+#define FE_UNDERFLOW 0x020000
+    FE_UNDERFLOW,
+  FE_OVERFLOW =
+#define FE_OVERFLOW 0x040000
+    FE_OVERFLOW,
+  FE_DIVBYZERO =
+#define FE_DIVBYZERO 0x080000
+    FE_DIVBYZERO,
+  FE_INVALID =
+#define FE_INVALID 0x100000
+    FE_INVALID,
+};
+
+#define FE_ALL_EXCEPT \
+  (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
+
+/* The LoongArch FPU supports all of the four defined rounding modes.  We
+   use again the bit positions in the FPU control word as the values
+   for the appropriate macros.  */
+enum
+{
+  FE_TONEAREST =
+#define FE_TONEAREST 0x000
+    FE_TONEAREST,
+  FE_TOWARDZERO =
+#define FE_TOWARDZERO 0x100
+    FE_TOWARDZERO,
+  FE_UPWARD =
+#define FE_UPWARD 0x200
+    FE_UPWARD,
+  FE_DOWNWARD =
+#define FE_DOWNWARD 0x300
+    FE_DOWNWARD
+};
+
+/* Type representing exception flags.  */
+typedef unsigned int fexcept_t;
+
+/* Type representing floating-point environment.  This function corresponds
+   to the layout of the block written by the `fstenv'.  */
+typedef struct
+{
+  unsigned int __fp_control_register;
+} fenv_t;
+
+/* If the default argument is used we use this value.  */
+#define FE_DFL_ENV ((const fenv_t *) -1)
+
+#ifdef __USE_GNU
+/* Floating-point environment where none of the exception is masked.  */
+#define FE_NOMASK_ENV ((const fenv_t *) -257)
+#endif
+
+#if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
+/* Type representing floating-point control modes.  */
+typedef unsigned int femode_t;
+
+/* Default floating-point control modes.  */
+#define FE_DFL_MODE ((const femode_t *) -1L)
+#endif
diff --git a/sysdeps/loongarch/e_sqrtl.c b/sysdeps/loongarch/e_sqrtl.c
new file mode 100644
index 0000000000..020c8911e6
--- /dev/null
+++ b/sysdeps/loongarch/e_sqrtl.c
@@ -0,0 +1,39 @@
+/* long double square root in software floating-point emulation.
+   Copyright (C) 2022 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/>.  */
+
+#include <stdlib.h>
+#include <soft-fp/soft-fp.h>
+#include <soft-fp/quad.h>
+#include <libm-alias-finite.h>
+
+long double
+__ieee754_sqrtl (const long double a)
+{
+  FP_DECL_EX;
+  FP_DECL_Q (A);
+  FP_DECL_Q (C);
+  long double c;
+
+  FP_INIT_ROUNDMODE;
+  FP_UNPACK_Q (A, a);
+  FP_SQRT_Q (C, A);
+  FP_PACK_Q (c, C);
+  FP_HANDLE_EXCEPTIONS;
+  return c;
+}
+libm_alias_finite (__ieee754_sqrtl, __sqrtl)
diff --git a/sysdeps/loongarch/fpu_control.h b/sysdeps/loongarch/fpu_control.h
new file mode 100644
index 0000000000..d34936c62b
--- /dev/null
+++ b/sysdeps/loongarch/fpu_control.h
@@ -0,0 +1,90 @@
+/* FPU control word bits.
+   Copyright (C) 2022 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 _FPU_CONTROL_H
+#define _FPU_CONTROL_H
+
+/* LoongArch FPU floating point control register bits.
+ *
+ * 31-29  -> reserved (read as 0, can not changed by software)
+ * 28     -> cause bit for invalid exception
+ * 27     -> cause bit for division by zero exception
+ * 26     -> cause bit for overflow exception
+ * 25     -> cause bit for underflow exception
+ * 24     -> cause bit for inexact exception
+ * 23-21  -> reserved (read as 0, can not changed by software)
+ * 20     -> flag invalid exception
+ * 19     -> flag division by zero exception
+ * 18     -> flag overflow exception
+ * 17     -> flag underflow exception
+ * 16     -> flag inexact exception
+ *  9-8   -> rounding control
+ *  7-5   -> reserved (read as 0, can not changed by software)
+ *  4     -> enable exception for invalid exception
+ *  3     -> enable exception for division by zero exception
+ *  2     -> enable exception for overflow exception
+ *  1     -> enable exception for underflow exception
+ *  0     -> enable exception for inexact exception
+ *
+ *
+ * Rounding Control:
+ * 00 - rounding ties to even (RNE)
+ * 01 - rounding toward zero (RZ)
+ * 10 - rounding (up) toward plus infinity (RP)
+ * 11 - rounding (down) toward minus infinity (RM)
+ */
+
+#include <features.h>
+
+/* Masks for interrupts.  */
+#define _FPU_MASK_V 0x10 /* Invalid operation */
+#define _FPU_MASK_Z 0x08 /* Division by zero  */
+#define _FPU_MASK_O 0x04 /* Overflow */
+#define _FPU_MASK_U 0x02 /* Underflow */
+#define _FPU_MASK_I 0x01 /* Inexact operation */
+
+/* Flush denormalized numbers to zero.  */
+#define _FPU_FLUSH_TZ 0x1000000
+
+/* Rounding control.  */
+#define _FPU_RC_NEAREST 0x000 /* RECOMMENDED */
+#define _FPU_RC_ZERO 0x100
+#define _FPU_RC_UP 0x200
+#define _FPU_RC_DOWN 0x300
+/* Mask for rounding control.  */
+#define _FPU_RC_MASK 0x300
+
+#define _FPU_RESERVED 0x0
+
+#define _FPU_DEFAULT 0x0
+#define _FPU_IEEE 0x1F
+
+/* Type of the control word.  */
+typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__SI__)));
+
+/* Macros for accessing the hardware control word.  */
+extern fpu_control_t __loongarch_fpu_getcw (void) __THROW;
+extern void __loongarch_fpu_setcw (fpu_control_t) __THROW;
+#define _FPU_GETCW(cw) __asm__ volatile ("movfcsr2gr %0,$r0" : "=r"(cw))
+#define _FPU_SETCW(cw) __asm__ volatile ("movgr2fcsr $r0,%0" : : "r"(cw))
+
+/* Default control word set at startup.  */
+extern fpu_control_t __fpu_control;
+
+#endif /* fpu_control.h */
+
diff --git a/sysdeps/loongarch/sfp-machine.h b/sysdeps/loongarch/sfp-machine.h
new file mode 100644
index 0000000000..5b92ac4ba2
--- /dev/null
+++ b/sysdeps/loongarch/sfp-machine.h
@@ -0,0 +1,102 @@
+/* LoongArch softfloat definitions
+   Copyright (C) 2022 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/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+#define _FP_W_TYPE_SIZE 64
+#define _FP_W_TYPE unsigned long long
+#define _FP_WS_TYPE signed long long
+#define _FP_I_TYPE long long
+
+#define _FP_MUL_MEAT_S(R, X, Y) _FP_MUL_MEAT_1_imm (_FP_WFRACBITS_S, R, X, Y)
+#define _FP_MUL_MEAT_D(R, X, Y) \
+  _FP_MUL_MEAT_1_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
+#define _FP_MUL_MEAT_Q(R, X, Y) \
+  _FP_MUL_MEAT_2_wide_3mul (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
+
+#define _FP_MUL_MEAT_DW_S(R, X, Y) \
+  _FP_MUL_MEAT_DW_1_imm (_FP_WFRACBITS_S, R, X, Y)
+#define _FP_MUL_MEAT_DW_D(R, X, Y) \
+  _FP_MUL_MEAT_DW_1_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
+#define _FP_MUL_MEAT_DW_Q(R, X, Y) \
+  _FP_MUL_MEAT_DW_2_wide_3mul (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
+
+#define _FP_DIV_MEAT_S(R, X, Y) \
+  _FP_DIV_MEAT_1_imm (S, R, X, Y, _FP_DIV_HELP_imm)
+#define _FP_DIV_MEAT_D(R, X, Y) _FP_DIV_MEAT_1_udiv_norm (D, R, X, Y)
+#define _FP_DIV_MEAT_Q(R, X, Y) _FP_DIV_MEAT_2_udiv (Q, R, X, Y)
+
+#define _FP_NANFRAC_S _FP_QNANBIT_S
+#define _FP_NANFRAC_D _FP_QNANBIT_D
+#define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0
+
+#define _FP_NANSIGN_S 0
+#define _FP_NANSIGN_D 0
+#define _FP_NANSIGN_Q 0
+
+#define _FP_KEEPNANFRACP 1
+#define _FP_QNANNEGATEDP 0
+
+/* NaN payloads should be preserved for NAN2008.  */
+#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
+  do \
+    { \
+      R##_s = X##_s; \
+      _FP_FRAC_COPY_##wc (R, X); \
+      R##_c = FP_CLS_NAN; \
+    } \
+  while (0)
+
+#define _FP_DECL_EX fpu_control_t _fcw
+
+#define FP_ROUNDMODE (_fcw & 0x300)
+
+#define FP_RND_NEAREST FE_TONEAREST
+#define FP_RND_ZERO FE_TOWARDZERO
+#define FP_RND_PINF FE_UPWARD
+#define FP_RND_MINF FE_DOWNWARD
+
+#define FP_EX_INVALID FE_INVALID
+#define FP_EX_OVERFLOW FE_OVERFLOW
+#define FP_EX_UNDERFLOW FE_UNDERFLOW
+#define FP_EX_DIVZERO FE_DIVBYZERO
+#define FP_EX_INEXACT FE_INEXACT
+
+#define _FP_TININESS_AFTER_ROUNDING 1
+
+#ifdef __loongarch_hard_float
+#define FP_INIT_ROUNDMODE \
+  do \
+    { \
+      _FPU_GETCW (_fcw); \
+    } \
+  while (0)
+
+#define FP_HANDLE_EXCEPTIONS \
+  do \
+    { \
+      if (__glibc_unlikely (_fex)) \
+	_FPU_SETCW (_fcw | _fex | (_fex << 8)); \
+    } \
+  while (0)
+#define FP_TRAPPING_EXCEPTIONS ((_fcw << 16) & 0x1f0000)
+#else
+#define FP_INIT_ROUNDMODE _fcw = FP_RND_NEAREST
+#endif
diff --git a/sysdeps/loongarch/tininess.h b/sysdeps/loongarch/tininess.h
new file mode 100644
index 0000000000..90956c35f7
--- /dev/null
+++ b/sysdeps/loongarch/tininess.h
@@ -0,0 +1 @@
+#define TININESS_AFTER_ROUNDING 1
-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v7 06/13] LoongArch: Atomic and Locking Routines
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
                   ` (4 preceding siblings ...)
  2022-07-19  1:20 ` [PATCH v7 05/13] LoongArch: Generic <math.h> and soft-fp Routines caiyinyu
@ 2022-07-19  1:20 ` caiyinyu
  2022-07-20 14:32   ` Adhemerval Zanella Netto
  2022-07-19  1:20 ` [PATCH v7 07/13] LoongArch: Linux Syscall Interface caiyinyu
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

---
 .../sysv/linux/loongarch/atomic-machine.h     | 147 ++++++++++++++++++
 1 file changed, 147 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/atomic-machine.h

diff --git a/sysdeps/unix/sysv/linux/loongarch/atomic-machine.h b/sysdeps/unix/sysv/linux/loongarch/atomic-machine.h
new file mode 100644
index 0000000000..d1b8f1c11b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/atomic-machine.h
@@ -0,0 +1,147 @@
+/* Atomic operations.
+   Copyright (C) 2022 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 _LINUX_LOONGARCH_BITS_ATOMIC_H
+#define _LINUX_LOONGARCH_BITS_ATOMIC_H 1
+
+#define atomic_full_barrier() __sync_synchronize ()
+
+#define __HAVE_64B_ATOMICS (__loongarch_grlen >= 64)
+#define USE_ATOMIC_COMPILER_BUILTINS 1
+#define ATOMIC_EXCHANGE_USES_CAS 0
+
+/* Compare and exchange.
+   For all "bool" routines, we return FALSE if exchange succesful.  */
+
+#define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
+  ({ \
+    typeof (*mem) __oldval = (oldval); \
+    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
+				  __ATOMIC_RELAXED); \
+  })
+
+#define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
+  ({ \
+    typeof (*mem) __oldval = (oldval); \
+    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
+				  __ATOMIC_RELAXED); \
+  })
+
+#define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
+  ({ \
+    typeof (*mem) __oldval = (oldval); \
+    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
+				  __ATOMIC_RELAXED); \
+  })
+
+#define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
+  ({ \
+    typeof (*mem) __oldval = (oldval); \
+    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
+				  __ATOMIC_RELAXED); \
+  })
+
+#define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
+  ({ \
+    typeof (*mem) __oldval = (oldval); \
+    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
+				 __ATOMIC_RELAXED); \
+    __oldval; \
+  })
+
+#define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
+  ({ \
+    typeof (*mem) __oldval = (oldval); \
+    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
+				 __ATOMIC_RELAXED); \
+    __oldval; \
+  })
+
+#define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
+  ({ \
+    typeof (*mem) __oldval = (oldval); \
+    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
+				 __ATOMIC_RELAXED); \
+    __oldval; \
+  })
+
+#define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
+  ({ \
+    typeof (*mem) __oldval = (oldval); \
+    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
+				 __ATOMIC_RELAXED); \
+    __oldval; \
+  })
+
+/* Atomic compare and exchange.  */
+
+#define atomic_compare_and_exchange_bool_acq(mem, new, old) \
+  __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, mem, new, old, \
+			__ATOMIC_ACQUIRE)
+
+#define atomic_compare_and_exchange_val_acq(mem, new, old) \
+  __atomic_val_bysize (__arch_compare_and_exchange_val, int, mem, new, old, \
+		       __ATOMIC_ACQUIRE)
+
+#define atomic_compare_and_exchange_val_rel(mem, new, old) \
+  __atomic_val_bysize (__arch_compare_and_exchange_val, int, mem, new, old, \
+		       __ATOMIC_RELEASE)
+
+/* Atomic exchange (without compare).  */
+
+#define __arch_exchange_8_int(mem, newval, model) \
+  __atomic_exchange_n (mem, newval, model)
+
+#define __arch_exchange_16_int(mem, newval, model) \
+  __atomic_exchange_n (mem, newval, model)
+
+#define __arch_exchange_32_int(mem, newval, model) \
+  __atomic_exchange_n (mem, newval, model)
+
+#define __arch_exchange_64_int(mem, newval, model) \
+  __atomic_exchange_n (mem, newval, model)
+
+#define atomic_exchange_acq(mem, value) \
+  __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
+
+#define atomic_exchange_rel(mem, value) \
+  __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
+
+/* Atomically add value and return the previous (unincremented) value.  */
+
+#define __arch_exchange_and_add_8_int(mem, value, model) \
+  __atomic_fetch_add (mem, value, model)
+
+#define __arch_exchange_and_add_16_int(mem, value, model) \
+  __atomic_fetch_add (mem, value, model)
+
+#define __arch_exchange_and_add_32_int(mem, value, model) \
+  __atomic_fetch_add (mem, value, model)
+
+#define __arch_exchange_and_add_64_int(mem, value, model) \
+  __atomic_fetch_add (mem, value, model)
+
+#define atomic_exchange_and_add_acq(mem, value) \
+  __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
+		       __ATOMIC_ACQUIRE)
+
+#define atomic_exchange_and_add_rel(mem, value) \
+  __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
+		       __ATOMIC_RELEASE)
+
+#endif /* bits/atomic.h */
-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v7 07/13] LoongArch: Linux Syscall Interface
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
                   ` (5 preceding siblings ...)
  2022-07-19  1:20 ` [PATCH v7 06/13] LoongArch: Atomic and Locking Routines caiyinyu
@ 2022-07-19  1:20 ` caiyinyu
  2022-07-20 14:35   ` Adhemerval Zanella Netto
  2022-07-27  5:27   ` WANG Xuerui
  2022-07-19  1:20 ` [PATCH v7 08/13] LoongArch: Linux ABI caiyinyu
                   ` (2 subsequent siblings)
  9 siblings, 2 replies; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

---
 sysdeps/loongarch/abort-instr.h               |   2 +
 sysdeps/loongarch/hp-timing.h                 |  42 +++
 .../unix/sysv/linux/loongarch/arch-syscall.h  | 301 ++++++++++++++++
 sysdeps/unix/sysv/linux/loongarch/clone.S     |  96 ++++++
 sysdeps/unix/sysv/linux/loongarch/clone3.S    |  83 +++++
 sysdeps/unix/sysv/linux/loongarch/sysdep.S    |  53 +++
 sysdeps/unix/sysv/linux/loongarch/sysdep.h    | 320 ++++++++++++++++++
 sysdeps/unix/sysv/linux/loongarch/vfork.S     |  50 +++
 8 files changed, 947 insertions(+)
 create mode 100644 sysdeps/loongarch/abort-instr.h
 create mode 100644 sysdeps/loongarch/hp-timing.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone3.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sysdep.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/vfork.S

diff --git a/sysdeps/loongarch/abort-instr.h b/sysdeps/loongarch/abort-instr.h
new file mode 100644
index 0000000000..46d3ad0871
--- /dev/null
+++ b/sysdeps/loongarch/abort-instr.h
@@ -0,0 +1,2 @@
+/* An instruction which should crash any program is a breakpoint.  */
+#define ABORT_INSTRUCTION asm ("break 0")
diff --git a/sysdeps/loongarch/hp-timing.h b/sysdeps/loongarch/hp-timing.h
new file mode 100644
index 0000000000..af1da81024
--- /dev/null
+++ b/sysdeps/loongarch/hp-timing.h
@@ -0,0 +1,42 @@
+/* High precision, low overhead timing functions.
+   Copyright (C) 2022 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 _HP_TIMING_H
+#define _HP_TIMING_H 1
+
+/* We always assume having the timestamp register.  */
+#define HP_TIMING_AVAIL (1)
+#define HP_SMALL_TIMING_AVAIL (1)
+
+/* We indeed have inlined functions.  */
+#define HP_TIMING_INLINE (1)
+
+/* We use 64bit values for the times.  */
+typedef unsigned long long int hp_timing_t;
+
+/* Read the stable counter.  */
+#define HP_TIMING_NOW(Var) \
+  ({ \
+    unsigned long long int _count; \
+    asm volatile ("rdtime.d\t%0,$r0" : "=r" (_count)); \
+    (Var) = _count; \
+  })
+
+#include <hp-timing-common.h>
+
+#endif /* hp-timing.h */
diff --git a/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h b/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
new file mode 100644
index 0000000000..6bb3c8adbc
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
@@ -0,0 +1,301 @@
+/* AUTOGENERATED by update-syscall-lists.py.  */
+#define __NR_accept 202
+#define __NR_accept4 242
+#define __NR_acct 89
+#define __NR_add_key 217
+#define __NR_adjtimex 171
+#define __NR_bind 200
+#define __NR_bpf 280
+#define __NR_brk 214
+#define __NR_capget 90
+#define __NR_capset 91
+#define __NR_chdir 49
+#define __NR_chroot 51
+#define __NR_clock_adjtime 266
+#define __NR_clock_getres 114
+#define __NR_clock_gettime 113
+#define __NR_clock_nanosleep 115
+#define __NR_clock_settime 112
+#define __NR_clone 220
+#define __NR_clone3 435
+#define __NR_close 57
+#define __NR_close_range 436
+#define __NR_connect 203
+#define __NR_copy_file_range 285
+#define __NR_delete_module 106
+#define __NR_dup 23
+#define __NR_dup3 24
+#define __NR_epoll_create1 20
+#define __NR_epoll_ctl 21
+#define __NR_epoll_pwait 22
+#define __NR_epoll_pwait2 441
+#define __NR_eventfd2 19
+#define __NR_execve 221
+#define __NR_execveat 281
+#define __NR_exit 93
+#define __NR_exit_group 94
+#define __NR_faccessat 48
+#define __NR_faccessat2 439
+#define __NR_fadvise64 223
+#define __NR_fallocate 47
+#define __NR_fanotify_init 262
+#define __NR_fanotify_mark 263
+#define __NR_fchdir 50
+#define __NR_fchmod 52
+#define __NR_fchmodat 53
+#define __NR_fchown 55
+#define __NR_fchownat 54
+#define __NR_fcntl 25
+#define __NR_fdatasync 83
+#define __NR_fgetxattr 10
+#define __NR_finit_module 273
+#define __NR_flistxattr 13
+#define __NR_flock 32
+#define __NR_fremovexattr 16
+#define __NR_fsconfig 431
+#define __NR_fsetxattr 7
+#define __NR_fsmount 432
+#define __NR_fsopen 430
+#define __NR_fspick 433
+#define __NR_fstatfs 44
+#define __NR_fsync 82
+#define __NR_ftruncate 46
+#define __NR_futex 98
+#define __NR_futex_waitv 449
+#define __NR_get_mempolicy 236
+#define __NR_get_robust_list 100
+#define __NR_getcpu 168
+#define __NR_getcwd 17
+#define __NR_getdents64 61
+#define __NR_getegid 177
+#define __NR_geteuid 175
+#define __NR_getgid 176
+#define __NR_getgroups 158
+#define __NR_getitimer 102
+#define __NR_getpeername 205
+#define __NR_getpgid 155
+#define __NR_getpid 172
+#define __NR_getppid 173
+#define __NR_getpriority 141
+#define __NR_getrandom 278
+#define __NR_getresgid 150
+#define __NR_getresuid 148
+#define __NR_getrusage 165
+#define __NR_getsid 156
+#define __NR_getsockname 204
+#define __NR_getsockopt 209
+#define __NR_gettid 178
+#define __NR_gettimeofday 169
+#define __NR_getuid 174
+#define __NR_getxattr 8
+#define __NR_init_module 105
+#define __NR_inotify_add_watch 27
+#define __NR_inotify_init1 26
+#define __NR_inotify_rm_watch 28
+#define __NR_io_cancel 3
+#define __NR_io_destroy 1
+#define __NR_io_getevents 4
+#define __NR_io_pgetevents 292
+#define __NR_io_setup 0
+#define __NR_io_submit 2
+#define __NR_io_uring_enter 426
+#define __NR_io_uring_register 427
+#define __NR_io_uring_setup 425
+#define __NR_ioctl 29
+#define __NR_ioprio_get 31
+#define __NR_ioprio_set 30
+#define __NR_kcmp 272
+#define __NR_kexec_file_load 294
+#define __NR_kexec_load 104
+#define __NR_keyctl 219
+#define __NR_kill 129
+#define __NR_landlock_add_rule 445
+#define __NR_landlock_create_ruleset 444
+#define __NR_landlock_restrict_self 446
+#define __NR_lgetxattr 9
+#define __NR_linkat 37
+#define __NR_listen 201
+#define __NR_listxattr 11
+#define __NR_llistxattr 12
+#define __NR_lookup_dcookie 18
+#define __NR_lremovexattr 15
+#define __NR_lseek 62
+#define __NR_lsetxattr 6
+#define __NR_madvise 233
+#define __NR_mbind 235
+#define __NR_membarrier 283
+#define __NR_memfd_create 279
+#define __NR_migrate_pages 238
+#define __NR_mincore 232
+#define __NR_mkdirat 34
+#define __NR_mknodat 33
+#define __NR_mlock 228
+#define __NR_mlock2 284
+#define __NR_mlockall 230
+#define __NR_mmap 222
+#define __NR_mount 40
+#define __NR_mount_setattr 442
+#define __NR_move_mount 429
+#define __NR_move_pages 239
+#define __NR_mprotect 226
+#define __NR_mq_getsetattr 185
+#define __NR_mq_notify 184
+#define __NR_mq_open 180
+#define __NR_mq_timedreceive 183
+#define __NR_mq_timedsend 182
+#define __NR_mq_unlink 181
+#define __NR_mremap 216
+#define __NR_msgctl 187
+#define __NR_msgget 186
+#define __NR_msgrcv 188
+#define __NR_msgsnd 189
+#define __NR_msync 227
+#define __NR_munlock 229
+#define __NR_munlockall 231
+#define __NR_munmap 215
+#define __NR_name_to_handle_at 264
+#define __NR_nanosleep 101
+#define __NR_nfsservctl 42
+#define __NR_open_by_handle_at 265
+#define __NR_open_tree 428
+#define __NR_openat 56
+#define __NR_openat2 437
+#define __NR_perf_event_open 241
+#define __NR_personality 92
+#define __NR_pidfd_getfd 438
+#define __NR_pidfd_open 434
+#define __NR_pidfd_send_signal 424
+#define __NR_pipe2 59
+#define __NR_pivot_root 41
+#define __NR_pkey_alloc 289
+#define __NR_pkey_free 290
+#define __NR_pkey_mprotect 288
+#define __NR_ppoll 73
+#define __NR_prctl 167
+#define __NR_pread64 67
+#define __NR_preadv 69
+#define __NR_preadv2 286
+#define __NR_prlimit64 261
+#define __NR_process_madvise 440
+#define __NR_process_mrelease 448
+#define __NR_process_vm_readv 270
+#define __NR_process_vm_writev 271
+#define __NR_pselect6 72
+#define __NR_ptrace 117
+#define __NR_pwrite64 68
+#define __NR_pwritev 70
+#define __NR_pwritev2 287
+#define __NR_quotactl 60
+#define __NR_quotactl_fd 443
+#define __NR_read 63
+#define __NR_readahead 213
+#define __NR_readlinkat 78
+#define __NR_readv 65
+#define __NR_reboot 142
+#define __NR_recvfrom 207
+#define __NR_recvmmsg 243
+#define __NR_recvmsg 212
+#define __NR_remap_file_pages 234
+#define __NR_removexattr 14
+#define __NR_renameat2 276
+#define __NR_request_key 218
+#define __NR_restart_syscall 128
+#define __NR_rseq 293
+#define __NR_rt_sigaction 134
+#define __NR_rt_sigpending 136
+#define __NR_rt_sigprocmask 135
+#define __NR_rt_sigqueueinfo 138
+#define __NR_rt_sigreturn 139
+#define __NR_rt_sigsuspend 133
+#define __NR_rt_sigtimedwait 137
+#define __NR_rt_tgsigqueueinfo 240
+#define __NR_sched_get_priority_max 125
+#define __NR_sched_get_priority_min 126
+#define __NR_sched_getaffinity 123
+#define __NR_sched_getattr 275
+#define __NR_sched_getparam 121
+#define __NR_sched_getscheduler 120
+#define __NR_sched_rr_get_interval 127
+#define __NR_sched_setaffinity 122
+#define __NR_sched_setattr 274
+#define __NR_sched_setparam 118
+#define __NR_sched_setscheduler 119
+#define __NR_sched_yield 124
+#define __NR_seccomp 277
+#define __NR_semctl 191
+#define __NR_semget 190
+#define __NR_semop 193
+#define __NR_semtimedop 192
+#define __NR_sendfile 71
+#define __NR_sendmmsg 269
+#define __NR_sendmsg 211
+#define __NR_sendto 206
+#define __NR_set_mempolicy 237
+#define __NR_set_mempolicy_home_node 450
+#define __NR_set_robust_list 99
+#define __NR_set_tid_address 96
+#define __NR_setdomainname 162
+#define __NR_setfsgid 152
+#define __NR_setfsuid 151
+#define __NR_setgid 144
+#define __NR_setgroups 159
+#define __NR_sethostname 161
+#define __NR_setitimer 103
+#define __NR_setns 268
+#define __NR_setpgid 154
+#define __NR_setpriority 140
+#define __NR_setregid 143
+#define __NR_setresgid 149
+#define __NR_setresuid 147
+#define __NR_setreuid 145
+#define __NR_setsid 157
+#define __NR_setsockopt 208
+#define __NR_settimeofday 170
+#define __NR_setuid 146
+#define __NR_setxattr 5
+#define __NR_shmat 196
+#define __NR_shmctl 195
+#define __NR_shmdt 197
+#define __NR_shmget 194
+#define __NR_shutdown 210
+#define __NR_sigaltstack 132
+#define __NR_signalfd4 74
+#define __NR_socket 198
+#define __NR_socketpair 199
+#define __NR_splice 76
+#define __NR_statfs 43
+#define __NR_statx 291
+#define __NR_swapoff 225
+#define __NR_swapon 224
+#define __NR_symlinkat 36
+#define __NR_sync 81
+#define __NR_sync_file_range 84
+#define __NR_syncfs 267
+#define __NR_sysinfo 179
+#define __NR_syslog 116
+#define __NR_tee 77
+#define __NR_tgkill 131
+#define __NR_timer_create 107
+#define __NR_timer_delete 111
+#define __NR_timer_getoverrun 109
+#define __NR_timer_gettime 108
+#define __NR_timer_settime 110
+#define __NR_timerfd_create 85
+#define __NR_timerfd_gettime 87
+#define __NR_timerfd_settime 86
+#define __NR_times 153
+#define __NR_tkill 130
+#define __NR_truncate 45
+#define __NR_umask 166
+#define __NR_umount2 39
+#define __NR_uname 160
+#define __NR_unlinkat 35
+#define __NR_unshare 97
+#define __NR_userfaultfd 282
+#define __NR_utimensat 88
+#define __NR_vhangup 58
+#define __NR_vmsplice 75
+#define __NR_wait4 260
+#define __NR_waitid 95
+#define __NR_write 64
+#define __NR_writev 66
diff --git a/sysdeps/unix/sysv/linux/loongarch/clone.S b/sysdeps/unix/sysv/linux/loongarch/clone.S
new file mode 100644
index 0000000000..c73245be82
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/clone.S
@@ -0,0 +1,96 @@
+/* The clone syscall wrapper.
+   Copyright (C) 2022 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/>.  */
+
+/* clone() is even more special than fork() as it mucks with stacks
+   and invokes a function in the right context after its all over.  */
+
+#include <sys/asm.h>
+#include <sysdep.h>
+#define _ERRNO_H  1
+#include <bits/errno.h>
+#include <tls.h>
+#include "tcb-offsets.h"
+
+/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+   void *parent_tidptr, void *tls, void *child_tidptr) */
+
+ENTRY (__clone)
+
+	/* Align stack to 16.  */
+	BSTRINS		a1, zero, 3, 0
+
+	/* Sanity check arguments.  */
+	beqz		a0, L (invalid) /* No NULL function pointers.  */
+	beqz		a1, L (invalid) /* No NULL stack pointers.  */
+
+	ADDI 		a1, a1, -16 /* Reserve argument save space.  */
+	REG_S		a0, a1, 0   /* Save function pointer.  */
+	REG_S		a3, a1, SZREG   /* Save argument pointer.  */
+
+	/* The syscall expects the args to be in different slots.  */
+	or		a0, a2, zero
+	or		a2, a4, zero
+	or		a3, a6, zero
+	or		a4, a5, zero
+
+	/* Do the system call.  */
+	LI		a7,__NR_clone
+	syscall		0
+
+	blt		a0, zero ,L (error)
+	beqz		a0,L (thread_start)
+
+	/* Successful return from the parent.  */
+	ret
+
+L (invalid):
+	LI		a0, -EINVAL
+
+	/* Something bad happened -- no child created.  */
+L (error):
+	b		__syscall_error
+
+END (__clone)
+
+/* Load up the arguments to the function.  Put this block of code in
+   its own function so that we can terminate the stack trace with our
+   debug info.  */
+ENTRY (__thread_start)
+L (thread_start):
+
+/* Terminate call stack by noting ra is undefined.  Use a dummy
+   .cfi_label to force starting the FDE.  */
+	.cfi_label .Ldummy
+	cfi_undefined (1)
+
+	/* Restore the arg for user's function.  */
+	REG_L		a1, sp, 0   /* Function pointer.  */
+	REG_L		a0, sp, SZREG   /* Argument pointer.  */
+
+	/* Call the user's function.  */
+	jirl		ra, a1, 0
+
+	/* Call exit with the function's return value.  */
+	LI		a7, __NR_exit
+	syscall		0
+
+	END (__thread_start)
+
+libc_hidden_def (__clone)
+weak_alias (__clone, clone)
diff --git a/sysdeps/unix/sysv/linux/loongarch/clone3.S b/sysdeps/unix/sysv/linux/loongarch/clone3.S
new file mode 100644
index 0000000000..38be4c809b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/clone3.S
@@ -0,0 +1,83 @@
+/* The clone3 syscall wrapper.
+   Copyright (C) 2022 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/>.  */
+
+/* clone3() is even more special than fork() as it mucks with stacks
+   and invokes a function in the right context after its all over.  */
+
+#include <sys/asm.h>
+#include <sysdep.h>
+#define _ERRNO_H  1
+#include <bits/errno.h>
+#include <tls.h>
+#include "tcb-offsets.h"
+
+/* int clone3(struct clone_args *cl_args, size_t size,
+   int (*func)(void *arg), void *arg); */
+
+ENTRY (__clone3)
+
+	/* Sanity check arguments.  */
+	beqz		a0, L (invalid)	/* No NULL cl_args pointer.  */
+	beqz		a2, L (invalid)	/* No NULL function pointer.  */
+
+	/* Do the system call.  */
+	LI		a7, __NR_clone3
+	syscall		0
+
+	blt		a0, zero ,L (error)
+	beqz		a0, L (thread_start3)
+
+	/* Successful return from the parent.  */
+	ret
+
+L (invalid):
+	LI		a0, -EINVAL
+
+	/* Something bad happened -- no child created.  */
+L (error):
+	b		__syscall_error
+
+END (__clone3)
+
+/* Load up the arguments to the function.  Put this block of code in
+   its own function so that we can terminate the stack trace with our
+   debug info.  */
+ENTRY (__thread_start3)
+L (thread_start3):
+
+/* Terminate call stack by noting ra is undefined.  Use a dummy
+   .cfi_label to force starting the FDE.  */
+	.cfi_label .Ldummy
+	cfi_undefined (1)
+
+	/* Align stack to 16.  */
+	BSTRINS		sp, zero, 3, 0
+
+	/* Set up arguments for the function call.  */
+	move		a0, a3		/* Argument.  */
+	jirl		ra, a2, 0	/* Call function.  */
+
+	/* Call exit with the function's return value.  */
+	LI		a7, __NR_exit
+	syscall		0
+
+	END (__thread_start3)
+
+libc_hidden_def (__clone3)
+weak_alias (__clone3, clone3)
diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.S b/sysdeps/unix/sysv/linux/loongarch/sysdep.S
new file mode 100644
index 0000000000..a4db2a97b5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.S
@@ -0,0 +1,53 @@
+/* syscall error handlers
+   Copyright (C) 2022 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/>.  */
+
+#include <sysdep.h>
+
+#if IS_IN (libc)
+# define errno __libc_errno
+#endif
+
+ENTRY (__syscall_error)
+/* Fall through to __syscall_set_errno */
+END (__syscall_error)
+
+/* Non-standard calling convention: argument in a0, return address in t0,
+   and clobber only t1.
+ */
+ENTRY (__syscall_set_errno)
+
+/* We got here because a0 < 0, but only codes in the range [-4095, -1]
+   represent errors.  Otherwise, just return the result normally.
+ */
+	li.d		t1, -4096
+	bgeu		t1, a0, L (out)
+	sub.w		a0, zero, a0
+#if RTLD_PRIVATE_ERRNO
+	la		t1, rtld_errno
+#elif defined(__PIC__)
+	la.tls.ie	t1, errno
+	add.d		t1, tp, t1
+#else
+	la.tls.le	t1, errno
+	add.d		t1, tp, t1
+#endif
+	st.w		a0, t1, 0
+	li.d		a0, -1
+L (out):
+	ret
+END (__syscall_set_errno)
diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
new file mode 100644
index 0000000000..c586df819c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
@@ -0,0 +1,320 @@
+/* Assembly macros for LoongArch.
+   Copyright (C) 2022 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 _LINUX_LOONGARCH_SYSDEP_H
+#define _LINUX_LOONGARCH_SYSDEP_H 1
+
+#include <sysdeps/unix/sysv/linux/generic/sysdep.h>
+#include <tls.h>
+
+#ifdef __ASSEMBLER__
+
+#include <sys/asm.h>
+#define ret jirl zero, ra, 0
+#define L(label) .L##label
+
+/* Performs a system call, handling errors by setting errno.  Linux indicates
+   errors by setting a0 to a value between -1 and -4095.  */
+#undef PSEUDO
+#define PSEUDO(name, syscall_name, args) \
+  ENTRY (name); \
+  li.d a7, SYS_ify (syscall_name); \
+  syscall 0; \
+  li.d a7, -4096; \
+  bltu a7, a0, .Lsyscall_error##name;
+
+#undef PSEUDO_END
+#define PSEUDO_END(sym) \
+  SYSCALL_ERROR_HANDLER (sym); \
+  ret; \
+  END (sym);
+
+#if !IS_IN(libc)
+#if RTLD_PRIVATE_ERRNO
+
+#define SYSCALL_ERROR_HANDLER(name) \
+  .Lsyscall_error##name : la t0, rtld_errno; \
+  sub.w a0, zero, a0; \
+  st.w a0, t0, 0; \
+  li.d a0, -1;
+
+#else
+
+#define SYSCALL_ERROR_HANDLER(name) \
+  .Lsyscall_error##name : la.tls.ie t0, errno; \
+  add.d t0, tp, t0; \
+  sub.w a0, zero, a0; \
+  st.w a0, t0, 0; \
+  li.d a0, -1;
+
+#endif
+#else
+
+#define SYSCALL_ERROR_HANDLER(name) .Lsyscall_error##name : b __syscall_error;
+
+#endif
+
+/* Performs a system call, not setting errno.  */
+#undef PSEUDO_NEORRNO
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+  ENTRY (name); \
+  li.d a7, SYS_ify (syscall_name); \
+  syscall 0;
+
+#undef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(name) END (name);
+
+#undef ret_NOERRNO
+#define ret_NOERRNO ret
+
+/* Perfroms a system call, returning the error code.  */
+#undef PSEUDO_ERRVAL
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+  PSEUDO_NOERRNO (name, syscall_name, args); \
+  slli.d a0, a0, 32; \
+  srai.d a0, a0, 32; /* sign_ext */ \
+  sub.d a0, zero, a0;
+
+#undef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(name) END (name);
+
+#undef ret_ERRVAL
+#define ret_ERRVAL ret
+
+#endif /* __ASSEMBLER__ */
+
+/* In order to get __set_errno() definition in INLINE_SYSCALL.  */
+#ifndef __ASSEMBLER__
+#include <errno.h>
+#endif
+
+#include <sysdeps/unix/sysdep.h>
+
+#undef SYS_ify
+#define SYS_ify(syscall_name) __NR_##syscall_name
+
+#ifndef __ASSEMBLER__
+
+#define VDSO_NAME "LINUX_2.6"
+#define VDSO_HASH 61765110
+
+/* List of system calls which are supported as vsyscalls.  */
+#define HAVE_CLOCK_GETRES64_VSYSCALL "__vdso_clock_getres"
+#define HAVE_CLOCK_GETTIME64_VSYSCALL "__vdso_clock_gettime"
+#define HAVE_GETCPU_VSYSCALL "__vdso_getcpu"
+
+#define HAVE_CLONE3_WRAPPER 1
+
+#define INTERNAL_SYSCALL(name, nr, args...) \
+  internal_syscall##nr (SYS_ify (name), args)
+
+#define INTERNAL_SYSCALL_NCS(number, nr, args...) \
+  internal_syscall##nr (number, args)
+
+#define internal_syscall0(number, dummy...) \
+  ({ \
+    long int _sys_result; \
+\
+    { \
+      register long int __a7 asm ("$a7") = number; \
+      register long int __a0 asm ("$a0"); \
+      __asm__ volatile ("syscall 0\n\t" \
+		       : "=r"(__a0) \
+		       : "r"(__a7) \
+		       : __SYSCALL_CLOBBERS); \
+      _sys_result = __a0; \
+    } \
+    _sys_result; \
+  })
+
+#define internal_syscall1(number, arg0) \
+  ({ \
+    long int _sys_result; \
+\
+    { \
+      long int _arg0 = (long int) (arg0); \
+      register long int __a7 asm ("$a7") = number; \
+      register long int __a0 asm ("$a0") = _arg0; \
+      __asm__ volatile ("syscall 0\n\t" \
+		       : "+r"(__a0) \
+		       : "r"(__a7) \
+		       : __SYSCALL_CLOBBERS); \
+      _sys_result = __a0; \
+    } \
+    _sys_result; \
+  })
+
+#define internal_syscall2(number, arg0, arg1) \
+  ({ \
+    long int _sys_result; \
+\
+    { \
+      long int _arg0 = (long int) (arg0); \
+      long int _arg1 = (long int) (arg1); \
+      register long int __a7 asm ("$a7") = number; \
+      register long int __a0 asm ("$a0") = _arg0; \
+      register long int __a1 asm ("$a1") = _arg1; \
+      __asm__ volatile ("syscall 0\n\t" \
+		       : "+r"(__a0) \
+		       : "r"(__a7), "r"(__a1) \
+		       : __SYSCALL_CLOBBERS); \
+      _sys_result = __a0; \
+    } \
+    _sys_result; \
+  })
+
+#define internal_syscall3(number, arg0, arg1, arg2) \
+  ({ \
+    long int _sys_result; \
+\
+    { \
+      long int _arg0 = (long int) (arg0); \
+      long int _arg1 = (long int) (arg1); \
+      long int _arg2 = (long int) (arg2); \
+      register long int __a7 asm ("$a7") = number; \
+      register long int __a0 asm ("$a0") = _arg0; \
+      register long int __a1 asm ("$a1") = _arg1; \
+      register long int __a2 asm ("$a2") = _arg2; \
+      __asm__ volatile ("syscall 0\n\t" \
+		       : "+r"(__a0) \
+		       : "r"(__a7), "r"(__a1), "r"(__a2) \
+		       : __SYSCALL_CLOBBERS); \
+      _sys_result = __a0; \
+    } \
+    _sys_result; \
+  })
+
+#define internal_syscall4(number, arg0, arg1, arg2, arg3) \
+  ({ \
+    long int _sys_result; \
+\
+    { \
+      long int _arg0 = (long int) (arg0); \
+      long int _arg1 = (long int) (arg1); \
+      long int _arg2 = (long int) (arg2); \
+      long int _arg3 = (long int) (arg3); \
+      register long int __a7 asm ("$a7") = number; \
+      register long int __a0 asm ("$a0") = _arg0; \
+      register long int __a1 asm ("$a1") = _arg1; \
+      register long int __a2 asm ("$a2") = _arg2; \
+      register long int __a3 asm ("$a3") = _arg3; \
+      __asm__ volatile ("syscall 0\n\t" \
+		       : "+r"(__a0) \
+		       : "r"(__a7), "r"(__a1), "r"(__a2), "r"(__a3) \
+		       : __SYSCALL_CLOBBERS); \
+      _sys_result = __a0; \
+    } \
+    _sys_result; \
+  })
+
+#define internal_syscall5(number, arg0, arg1, arg2, arg3, arg4) \
+  ({ \
+    long int _sys_result; \
+\
+    { \
+      long int _arg0 = (long int) (arg0); \
+      long int _arg1 = (long int) (arg1); \
+      long int _arg2 = (long int) (arg2); \
+      long int _arg3 = (long int) (arg3); \
+      long int _arg4 = (long int) (arg4); \
+      register long int __a7 asm ("$a7") = number; \
+      register long int __a0 asm ("$a0") = _arg0; \
+      register long int __a1 asm ("$a1") = _arg1; \
+      register long int __a2 asm ("$a2") = _arg2; \
+      register long int __a3 asm ("$a3") = _arg3; \
+      register long int __a4 asm ("$a4") = _arg4; \
+      __asm__ volatile ("syscall 0\n\t" \
+		       : "+r"(__a0) \
+		       : "r"(__a7), "r"(__a1), "r"(__a2), \
+			 "r"(__a3), "r"(__a4) \
+		       : __SYSCALL_CLOBBERS); \
+      _sys_result = __a0; \
+    } \
+    _sys_result; \
+  })
+
+#define internal_syscall6(number, arg0, arg1, arg2, arg3, arg4, arg5) \
+  ({ \
+    long int _sys_result; \
+\
+    { \
+      long int _arg0 = (long int) (arg0); \
+      long int _arg1 = (long int) (arg1); \
+      long int _arg2 = (long int) (arg2); \
+      long int _arg3 = (long int) (arg3); \
+      long int _arg4 = (long int) (arg4); \
+      long int _arg5 = (long int) (arg5); \
+      register long int __a7 asm ("$a7") = number; \
+      register long int __a0 asm ("$a0") = _arg0; \
+      register long int __a1 asm ("$a1") = _arg1; \
+      register long int __a2 asm ("$a2") = _arg2; \
+      register long int __a3 asm ("$a3") = _arg3; \
+      register long int __a4 asm ("$a4") = _arg4; \
+      register long int __a5 asm ("$a5") = _arg5; \
+      __asm__ volatile ("syscall 0\n\t" \
+		       : "+r"(__a0) \
+		       : "r"(__a7), "r"(__a1), "r"(__a2), "r"(__a3), \
+			 "r"(__a4), "r"(__a5) \
+		       : __SYSCALL_CLOBBERS); \
+      _sys_result = __a0; \
+    } \
+    _sys_result; \
+  })
+
+#define internal_syscall7(number, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \
+  ({ \
+    long int _sys_result; \
+\
+    { \
+      long int _arg0 = (long int) (arg0); \
+      long int _arg1 = (long int) (arg1); \
+      long int _arg2 = (long int) (arg2); \
+      long int _arg3 = (long int) (arg3); \
+      long int _arg4 = (long int) (arg4); \
+      long int _arg5 = (long int) (arg5); \
+      long int _arg6 = (long int) (arg6); \
+      register long int __a7 asm ("$a7") = number; \
+      register long int __a0 asm ("$a0") = _arg0; \
+      register long int __a1 asm ("$a1") = _arg1; \
+      register long int __a2 asm ("$a2") = _arg2; \
+      register long int __a3 asm ("$a3") = _arg3; \
+      register long int __a4 asm ("$a4") = _arg4; \
+      register long int __a5 asm ("$a5") = _arg5; \
+      register long int __a6 asm ("$a6") = _arg6; \
+      __asm__ volatile ("syscall 0\n\t" \
+		       : "+r"(__a0) \
+		       : "r"(__a7), "r"(__a1), "r"(__a2), "r"(__a3), \
+			 "r"(__a4), "r"(__a5), "r"(__a6) \
+		       : __SYSCALL_CLOBBERS); \
+      _sys_result = __a0; \
+    } \
+    _sys_result; \
+  })
+
+#define __SYSCALL_CLOBBERS \
+  "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8", "memory"
+
+extern long int __syscall_error (long int neg_errno);
+
+#endif /* ! __ASSEMBLER__ */
+
+/* Pointer mangling is not supported.  */
+#define PTR_MANGLE(var) (void) (var)
+#define PTR_DEMANGLE(var) (void) (var)
+
+#endif /* linux/loongarch/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/loongarch/vfork.S b/sysdeps/unix/sysv/linux/loongarch/vfork.S
new file mode 100644
index 0000000000..fcc84e3549
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/vfork.S
@@ -0,0 +1,50 @@
+/* vfork for Linux.
+   Copyright (C) 2022 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/>.  */
+
+#include <sysdep.h>
+#define _ERRNO_H  1
+#include <bits/errno.h>
+
+/* Clone the calling process, but without copying the whole address space.
+   The calling process is suspended until the new process exits or is
+   replaced by a call to `execve'.  Return -1 for errors, 0 to the new process,
+   and the process ID of the new process to the old process.  */
+
+ENTRY (__vfork)
+
+	li.d	a0, 0x4111 /* CLONE_VM | CLONE_VFORK | SIGCHLD */
+	add.d   a1, zero, sp
+
+	/* Do the system call.  */
+	li.d	a7, __NR_clone
+	syscall	0
+
+	blt	a0, zero ,L (error)
+
+	ret
+
+L (error):
+	b	__syscall_error
+
+END (__vfork)
+
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
+strong_alias (__vfork, __libc_vfork)
-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v7 08/13] LoongArch: Linux ABI
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
                   ` (6 preceding siblings ...)
  2022-07-19  1:20 ` [PATCH v7 07/13] LoongArch: Linux Syscall Interface caiyinyu
@ 2022-07-19  1:20 ` caiyinyu
  2022-07-20 16:37   ` Adhemerval Zanella Netto
  2022-07-20 17:19 ` [PATCH v7 00/13] GLIBC LoongArch PATCHES Adhemerval Zanella Netto
  2022-07-24  9:49 ` WANG Xuerui
  9 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-19  1:20 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail; +Cc: caiyinyu

---
 sysdeps/loongarch/dl-irel.h                   |  54 ++++++++++
 sysdeps/loongarch/nptl/pthreaddef.h           |  32 ++++++
 sysdeps/loongarch/sys/ifunc.h                 |  30 ++++++
 .../unix/sysv/linux/loongarch/bits/fcntl.h    |  61 +++++++++++
 .../unix/sysv/linux/loongarch/bits/procfs.h   |  52 +++++++++
 .../linux/loongarch/bits/pthread_stack_min.h  |  20 ++++
 .../unix/sysv/linux/loongarch/bits/sigstack.h |  32 ++++++
 .../unix/sysv/linux/loongarch/getcontext.S    |  59 +++++++++++
 .../unix/sysv/linux/loongarch/localplt.data   |  12 +++
 .../unix/sysv/linux/loongarch/makecontext.c   |  81 ++++++++++++++
 .../unix/sysv/linux/loongarch/setcontext.S    | 100 ++++++++++++++++++
 .../sysv/linux/loongarch/sigcontextinfo.h     |  32 ++++++
 .../unix/sysv/linux/loongarch/swapcontext.S   |  95 +++++++++++++++++
 .../unix/sysv/linux/loongarch/sys/ucontext.h  |  61 +++++++++++
 sysdeps/unix/sysv/linux/loongarch/sys/user.h  |  42 ++++++++
 .../sysv/linux/loongarch/ucontext-macros.h    |  32 ++++++
 .../unix/sysv/linux/loongarch/ucontext_i.sym  |  31 ++++++
 17 files changed, 826 insertions(+)
 create mode 100644 sysdeps/loongarch/dl-irel.h
 create mode 100644 sysdeps/loongarch/nptl/pthreaddef.h
 create mode 100644 sysdeps/loongarch/sys/ifunc.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/procfs.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/getcontext.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/localplt.data
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/makecontext.c
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/setcontext.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/swapcontext.S
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/sys/user.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym

diff --git a/sysdeps/loongarch/dl-irel.h b/sysdeps/loongarch/dl-irel.h
new file mode 100644
index 0000000000..4440453f06
--- /dev/null
+++ b/sysdeps/loongarch/dl-irel.h
@@ -0,0 +1,54 @@
+/* Machine-dependent ELF indirect relocation inline functions.
+   Copyright (C) 2022 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 _DL_IREL_H
+#define _DL_IREL_H
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/ifunc.h>
+
+#define ELF_MACHINE_IRELA 1
+
+static inline ElfW (Addr) __attribute ((always_inline))
+elf_ifunc_invoke (ElfW (Addr) addr)
+{
+  __ifunc_arg_t arg =
+  {
+    ._size = sizeof (__ifunc_arg_t),
+    ._hwcap = GLRO(dl_hwcap),
+  };
+  return ((ElfW(Addr) (*) (const __ifunc_arg_t *)) (addr)) (&arg);
+}
+
+static inline void __attribute ((always_inline))
+elf_irela (const ElfW (Rela) *reloc)
+{
+  ElfW (Addr) *const reloc_addr = (void *) reloc->r_offset;
+  const unsigned long int r_type = ELFW (R_TYPE) (reloc->r_info);
+
+  if (__glibc_likely (r_type == R_LARCH_IRELATIVE))
+    {
+      ElfW (Addr) value = elf_ifunc_invoke (reloc->r_addend);
+      *reloc_addr = value;
+    }
+  else
+    __libc_fatal ("Unexpected reloc type in static binary.\n");
+}
+
+#endif /* dl-irel.h */
diff --git a/sysdeps/loongarch/nptl/pthreaddef.h b/sysdeps/loongarch/nptl/pthreaddef.h
new file mode 100644
index 0000000000..955566cddc
--- /dev/null
+++ b/sysdeps/loongarch/nptl/pthreaddef.h
@@ -0,0 +1,32 @@
+/* pthread machine parameter definitions.
+   Copyright (C) 2022 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/>.  */
+
+/* Default stack size.  */
+#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024)
+
+/* Minimum guard size.  */
+#define ARCH_MIN_GUARD_SIZE 0
+
+/* Required stack pointer alignment at beginning.  */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size.  */
+#define MINIMAL_REST_STACK 2048
+
+/* Location of current stack frame.  */
+#define CURRENT_STACK_FRAME __builtin_frame_address (0)
diff --git a/sysdeps/loongarch/sys/ifunc.h b/sysdeps/loongarch/sys/ifunc.h
new file mode 100644
index 0000000000..461df20c96
--- /dev/null
+++ b/sysdeps/loongarch/sys/ifunc.h
@@ -0,0 +1,30 @@
+/* Definitions used by LoongArch indirect function resolvers.
+   Copyright (C) 2022 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_IFUNC_H
+#define _SYS_IFUNC_H
+
+struct __ifunc_arg_t
+{
+  unsigned long _size; /* Size of the struct, so it can grow.  */
+  unsigned long _hwcap;
+};
+
+typedef struct __ifunc_arg_t __ifunc_arg_t;
+
+#endif
diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h b/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
new file mode 100644
index 0000000000..bf1e254234
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
@@ -0,0 +1,61 @@
+/* O_*, F_*, FD_* bit values for the generic Linux/LoongArch ABI.
+   Copyright (C) 2022 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 _FCNTL_H
+#error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+/* In 64-bit ISA files are always with 64bit off_t and F_*LK64 are the same as
+   non-64-bit versions.  It will need to be revised for 128-bit.  */
+#if __WORDSIZE == 64
+#define __O_LARGEFILE 0
+
+#define F_GETLK64 5  /* Get record locking info.  */
+#define F_SETLK64 6  /* Set record locking info (non-blocking).  */
+#define F_SETLKW64 7 /* Set record locking info (blocking).  */
+#endif
+
+struct flock
+{
+  short int l_type;   /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
+  short int l_whence; /* Where `l_start' is relative to (like `lseek').  */
+#ifndef __USE_FILE_OFFSET64
+  __off_t l_start; /* Offset where the lock begins.  */
+  __off_t l_len;   /* Size of the locked area; zero means until EOF.  */
+#else
+  __off64_t l_start; /* Offset where the lock begins.  */
+  __off64_t l_len;   /* Size of the locked area; zero means until EOF.  */
+#endif
+  __pid_t l_pid; /* Process holding the lock.  */
+};
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+{
+  short int l_type;   /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
+  short int l_whence; /* Where `l_start' is relative to (like `lseek').  */
+  __off64_t l_start;  /* Offset where the lock begins.  */
+  __off64_t l_len;    /* Size of the locked area; zero means until EOF.  */
+  __pid_t l_pid;      /* Process holding the lock.  */
+};
+#endif
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/procfs.h b/sysdeps/unix/sysv/linux/loongarch/bits/procfs.h
new file mode 100644
index 0000000000..2db777b38c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/bits/procfs.h
@@ -0,0 +1,52 @@
+/* Types for registers for sys/procfs.h.
+   Copyright (C) 2022 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_PROCFS_H
+# error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
+#endif
+
+/* Type for a general-purpose register.  */
+typedef __uint64_t elf_greg_t;
+
+/* And the whole bunch of them.  We could have used `struct
+   pt_regs' directly in the typedef, but tradition says that
+   the register set is an array, which does have some peculiar
+   semantics, so leave it that way.  */
+#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof (elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+#define ELF_NFPREG 34 /* 32 FPRs + 8-byte byte-vec for fcc + 4-byte FCR */
+typedef union
+{
+  double d;
+  float f;
+} elf_fpreg_t;
+typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+
+typedef union
+{
+  double d[2];
+  float f[4];
+} __attribute__ ((__aligned__ (16))) elf_lsxregset_t[32];
+
+typedef union
+{
+  double d[4];
+  float f[8];
+} __attribute__ ((__aligned__ (32))) elf_lasxregset_t[32];
diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h b/sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h
new file mode 100644
index 0000000000..072c2ade42
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h
@@ -0,0 +1,20 @@
+/* Definition of PTHREAD_STACK_MIN.  LoongArch Linux version.
+   Copyright (C) 2022 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/>.  */
+
+/* Minimum size for a thread.  At least two pages with 64k pages.  */
+#define PTHREAD_STACK_MIN	131072
diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h b/sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h
new file mode 100644
index 0000000000..238c1a98e6
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h
@@ -0,0 +1,32 @@
+/* sigstack, sigaltstack definitions.
+   Copyright (C) 2022 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 _BITS_SIGSTACK_H
+#define _BITS_SIGSTACK_H 1
+
+#if !defined _SIGNAL_H && !defined _SYS_UCONTEXT_H
+# error "Never include this file directly.  Use <signal.h> instead"
+#endif
+
+/* Minimum stack size for a signal handler.  */
+#define MINSIGSTKSZ	4096
+
+/* System default stack size.  */
+#define SIGSTKSZ	16384
+
+#endif /* bits/sigstack.h */
diff --git a/sysdeps/unix/sysv/linux/loongarch/getcontext.S b/sysdeps/unix/sysv/linux/loongarch/getcontext.S
new file mode 100644
index 0000000000..43b95e9715
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/getcontext.S
@@ -0,0 +1,59 @@
+/* Save current context.
+   Copyright (C) 2022 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/>.  */
+
+#include "ucontext-macros.h"
+
+/* int getcontext (ucontext_t *ucp) */
+
+	.text
+LEAF (__getcontext)
+	SAVE_INT_REG (ra,   1, a0)
+	SAVE_INT_REG (sp,   3, a0)
+	SAVE_INT_REG (zero, 4, a0) /* return 0 by overwriting a0.  */
+	SAVE_INT_REG (x,   21, a0)
+	SAVE_INT_REG (fp,  22, a0)
+	SAVE_INT_REG (s0,  23, a0)
+	SAVE_INT_REG (s1,  24, a0)
+	SAVE_INT_REG (s2,  25, a0)
+	SAVE_INT_REG (s3,  26, a0)
+	SAVE_INT_REG (s4,  27, a0)
+	SAVE_INT_REG (s5,  28, a0)
+	SAVE_INT_REG (s6,  29, a0)
+	SAVE_INT_REG (s7,  30, a0)
+	SAVE_INT_REG (s8,  31, a0)
+	st.d		ra, a0, MCONTEXT_PC
+
+/* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
+	li.d		a3, _NSIG8
+	li.d		a2, UCONTEXT_SIGMASK
+	add.d		a2, a2, a0
+	ori		a1, zero,0
+	li.d		a0, SIG_BLOCK
+
+	li.d		a7, SYS_ify (rt_sigprocmask)
+	syscall		0
+	blt		a0, zero, 99f
+
+	jirl		$r0, $r1, 0
+
+99:
+	b		__syscall_error
+
+PSEUDO_END (__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/sysdeps/unix/sysv/linux/loongarch/localplt.data b/sysdeps/unix/sysv/linux/loongarch/localplt.data
new file mode 100644
index 0000000000..817ab2659a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/localplt.data
@@ -0,0 +1,12 @@
+# See scripts/check-localplt.awk for how this file is processed.
+# PLT use is required for the malloc family and for matherr because
+# users can define their own functions and have library internals call them.
+libc.so: calloc
+libc.so: free
+libc.so: malloc
+libc.so: realloc
+# The TLS-enabled version of these functions is interposed from libc.so.
+ld.so: _dl_signal_error
+ld.so: _dl_catch_error
+ld.so: _dl_signal_exception
+ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/loongarch/makecontext.c b/sysdeps/unix/sysv/linux/loongarch/makecontext.c
new file mode 100644
index 0000000000..94a45bf4ad
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/makecontext.c
@@ -0,0 +1,81 @@
+/* Create new context.
+   Copyright (C) 2022 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/>.  */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+#include <sys/ucontext.h>
+#include <stdarg.h>
+#include <assert.h>
+
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, long int a0,
+	       long int a1, long int a2, long int a3, long int a4, ...)
+{
+  extern void __start_context (void) attribute_hidden;
+  unsigned long int *sp;
+
+  _Static_assert(LARCH_REG_NARGS == 8,
+		 "__makecontext assumes 8 argument registers");
+
+  /* Set up the stack.  */
+  sp = (unsigned long int *)
+       (((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ALMASK);
+
+  /* Set up the register context.
+     ra = s0 = 0, terminating the stack for backtracing purposes.
+     s1 = the function we must call.
+     s2 = the subsequent context to run.  */
+  ucp->uc_mcontext.__gregs[LARCH_REG_RA] = (uintptr_t) 0;
+  ucp->uc_mcontext.__gregs[LARCH_REG_S0] = (uintptr_t) 0;
+  ucp->uc_mcontext.__gregs[LARCH_REG_S1] = (uintptr_t) func;
+  ucp->uc_mcontext.__gregs[LARCH_REG_S2] = (uintptr_t) ucp->uc_link;
+  ucp->uc_mcontext.__gregs[LARCH_REG_SP] = (uintptr_t) sp;
+  ucp->uc_mcontext.__pc = (uintptr_t) &__start_context;
+
+  /* Put args in a0-a7, then put any remaining args on the stack.  */
+  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 0] = (uintptr_t) a0;
+  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 1] = (uintptr_t) a1;
+  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 2] = (uintptr_t) a2;
+  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 3] = (uintptr_t) a3;
+  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 4] = (uintptr_t) a4;
+
+  if (__glibc_unlikely (argc > 5))
+    {
+      va_list vl;
+      va_start (vl, a4);
+
+      long int reg_args = argc < LARCH_REG_NARGS ? argc : LARCH_REG_NARGS;
+      for (long int i = 5; i < reg_args; i++)
+	ucp->uc_mcontext.__gregs[LARCH_REG_A0 + i] = va_arg (vl, unsigned long int);
+
+      long int stack_args = argc - reg_args;
+      if (stack_args > 0)
+	{
+	  sp = (unsigned long int *)
+	       (((uintptr_t) sp - stack_args * sizeof (long int)) & ALMASK);
+	  ucp->uc_mcontext.__gregs[LARCH_REG_SP] = (uintptr_t) sp;
+	  for (long int i = 0; i < stack_args; i++)
+	    sp[i] = va_arg (vl, unsigned long int);
+	}
+
+      va_end (vl);
+    }
+}
+
+weak_alias (__makecontext, makecontext)
diff --git a/sysdeps/unix/sysv/linux/loongarch/setcontext.S b/sysdeps/unix/sysv/linux/loongarch/setcontext.S
new file mode 100644
index 0000000000..7295900149
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/setcontext.S
@@ -0,0 +1,100 @@
+/* Set current context.
+   Copyright (C) 2022 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/>.  */
+#include "sys/regdef.h"
+#include "ucontext-macros.h"
+
+/*  int __setcontext (const ucontext_t *ucp)
+
+  Restores the machine context in UCP and thereby resumes execution
+  in that context.
+
+  This implementation is intended to be used for *synchronous* context
+  switches only.  Therefore, it does not have to restore anything
+  other than the PRESERVED state.  */
+
+	.text
+LEAF (__setcontext)
+
+	addi.d		sp, sp, -16
+	st.d		a0, sp, 0	/* Save ucp to stack */
+
+/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
+	li.d		a3, _NSIG8
+	li.d		a2, 0
+	li.d		a1, UCONTEXT_SIGMASK
+	add.d		a1, a1, a0
+	li.d		a0, SIG_SETMASK
+
+	li.d		a7, SYS_ify (rt_sigprocmask)
+	syscall		0
+
+	blt		a0, $r0, 99f
+
+	ld.d		t0, sp, 0	/* Load ucp to t0 */
+	cfi_def_cfa (12, 0)
+
+/* Note the contents of argument registers will be random
+   unless makecontext() has been called.  */
+	RESTORE_INT_REG(ra,   1, t0)
+	RESTORE_INT_REG(sp,   3, t0)
+	RESTORE_INT_REG(a0,   4, t0)
+	RESTORE_INT_REG(a1,   5, t0)
+	RESTORE_INT_REG(a2,   6, t0)
+	RESTORE_INT_REG(a3,   7, t0)
+	RESTORE_INT_REG(a4,   8, t0)
+	RESTORE_INT_REG(a5,   9, t0)
+	RESTORE_INT_REG(a6,  10, t0)
+	RESTORE_INT_REG(a7,  11, t0)
+	RESTORE_INT_REG(x,   21, t0)
+	RESTORE_INT_REG(fp,  22, t0)
+	RESTORE_INT_REG(s0,  23, t0)
+	RESTORE_INT_REG(s1,  24, t0)
+	RESTORE_INT_REG(s2,  25, t0)
+	RESTORE_INT_REG(s3,  26, t0)
+	RESTORE_INT_REG(s4,  27, t0)
+	RESTORE_INT_REG(s5,  28, t0)
+	RESTORE_INT_REG(s6,  29, t0)
+	RESTORE_INT_REG(s7,  30, t0)
+	RESTORE_INT_REG(s8,  31, t0)
+
+	ld.d		t1, t0, MCONTEXT_PC
+	jirl		$r0,t1,0
+
+99:
+	addi.d		sp, sp, 16
+	b		__syscall_error
+
+PSEUDO_END (__setcontext)
+weak_alias (__setcontext, setcontext)
+
+LEAF (__start_context)
+
+	/* Terminate call stack by noting ra == 0.  Happily, s0 == 0 here.  */
+	cfi_register (1, 23)
+
+	/* Call the function passed to makecontext.  */
+	jirl		$r1,s1,0
+
+	/* Invoke subsequent context if present, else exit(0).  */
+	ori		a0, s2, 0
+	beqz		s2, 1f
+	bl		__setcontext
+1:
+	b		HIDDEN_JUMPTARGET(exit)
+
+PSEUDO_END (__start_context)
diff --git a/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h b/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h
new file mode 100644
index 0000000000..5e202bc0b4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h
@@ -0,0 +1,32 @@
+/* LoongArch definitions for signal handling calling conventions.
+   Copyright (C) 2022 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 _SIGCONTEXTINFO_H
+#define _SIGCONTEXTINFO_H
+
+#include <stdint.h>
+#include <sys/ucontext.h>
+
+static inline uintptr_t
+sigcontext_get_pc (const ucontext_t *ctx)
+{
+  return ctx->uc_mcontext.__pc;
+}
+
+#endif
diff --git a/sysdeps/unix/sysv/linux/loongarch/swapcontext.S b/sysdeps/unix/sysv/linux/loongarch/swapcontext.S
new file mode 100644
index 0000000000..bb22cd2f00
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/swapcontext.S
@@ -0,0 +1,95 @@
+/* Save and set current context.
+   Copyright (C) 2022 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/>.  */
+
+#include "ucontext-macros.h"
+
+/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
+
+LEAF (__swapcontext)
+	ori		a2, sp, 0		/* Save sp to a2 */
+	addi.d		sp, sp, -16
+	st.d		a1, sp, 0
+	ori		t0, a1, 0
+
+	SAVE_INT_REG (ra,   1, a0)
+	SAVE_INT_REG (a2,   3, a0)		/* Store sp */
+	SAVE_INT_REG (zero, 4, a0)		/* return 0 by overwriting a0 */
+	SAVE_INT_REG (x,   21, a0)
+	SAVE_INT_REG (fp,  22, a0)
+	SAVE_INT_REG (s0,  23, a0)
+	SAVE_INT_REG (s1,  24, a0)
+	SAVE_INT_REG (s2,  25, a0)
+	SAVE_INT_REG (s3,  26, a0)
+	SAVE_INT_REG (s4,  27, a0)
+	SAVE_INT_REG (s5,  28, a0)
+	SAVE_INT_REG (s6,  29, a0)
+	SAVE_INT_REG (s7,  30, a0)
+	SAVE_INT_REG (s8,  31, a0)
+
+	st.d		ra, a0, MCONTEXT_PC
+
+/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8) */
+	li.d		a3, _NSIG8
+	li.d		a2, UCONTEXT_SIGMASK
+	add.d		a2, a2, a0
+	li.d		a1, UCONTEXT_SIGMASK
+	add.d		a1, a1, t0
+	li.d		a0, SIG_SETMASK
+
+	li.d		a7, SYS_ify (rt_sigprocmask)
+	syscall		0
+
+	blt		a0, zero, 99f
+
+	ld.d		t0, sp, 0		/* Load a1 to t0 */
+
+/* Note the contents of argument registers will be random
+   unless makecontext() has been called.  */
+	RESTORE_INT_REG (ra,   1, t0)
+	RESTORE_INT_REG (sp,   3, t0)
+	RESTORE_INT_REG (a0,   4, t0)
+	RESTORE_INT_REG (a1,   5, t0)
+	RESTORE_INT_REG (a2,   6, t0)
+	RESTORE_INT_REG (a3,   7, t0)
+	RESTORE_INT_REG (a4,   8, t0)
+	RESTORE_INT_REG (a5,   9, t0)
+	RESTORE_INT_REG (a6,  10, t0)
+	RESTORE_INT_REG (a7,  11, t0)
+	RESTORE_INT_REG (x,   21, t0)
+	RESTORE_INT_REG (fp,  22, t0)
+	RESTORE_INT_REG (s0,  23, t0)
+	RESTORE_INT_REG (s1,  24, t0)
+	RESTORE_INT_REG (s2,  25, t0)
+	RESTORE_INT_REG (s3,  26, t0)
+	RESTORE_INT_REG (s4,  27, t0)
+	RESTORE_INT_REG (s5,  28, t0)
+	RESTORE_INT_REG (s6,  29, t0)
+	RESTORE_INT_REG (s7,  30, t0)
+	RESTORE_INT_REG (s8,  31, t0)
+
+	ld.d		t1, t0, MCONTEXT_PC
+	jirl		$r0, t1, 0
+
+
+99:
+	addi.d		sp, sp, 16
+	b		__syscall_error
+
+PSEUDO_END (__swapcontext)
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h b/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
new file mode 100644
index 0000000000..e334a45a44
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
@@ -0,0 +1,61 @@
+/* struct ucontext definition.
+   Copyright (C) 2022 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/>.  */
+
+/* Don't rely on this, the interface is currently messed up and may need to
+   be broken to be fixed.  */
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+
+#include <bits/types/sigset_t.h>
+#include <bits/types/stack_t.h>
+
+#ifdef __USE_MISC
+#define LARCH_NGREG 32
+
+#define LARCH_REG_RA 1
+#define LARCH_REG_SP 3
+#define LARCH_REG_S0 23
+#define LARCH_REG_S1 24
+#define LARCH_REG_A0 4
+#define LARCH_REG_S2 25
+#define LARCH_REG_NARGS 8
+
+#endif
+
+typedef struct mcontext_t
+{
+  unsigned long long __pc;
+  unsigned long long __gregs[32];
+  unsigned int __flags;
+  unsigned long long __extcontext[0] __attribute__((__aligned__(16)));
+} mcontext_t;
+
+/* Userlevel context.  */
+typedef struct ucontext_t
+{
+  unsigned long int __uc_flags;
+  struct ucontext_t *uc_link;
+  stack_t uc_stack;
+  sigset_t uc_sigmask;
+  mcontext_t uc_mcontext;
+} ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/loongarch/sys/user.h b/sysdeps/unix/sysv/linux/loongarch/sys/user.h
new file mode 100644
index 0000000000..55181de816
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/sys/user.h
@@ -0,0 +1,42 @@
+/* struct user_regs_struct definition for LoongArch.
+   Copyright (C) 2022 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_USER_H
+#define _SYS_USER_H 1
+
+#include <stdint.h>
+
+struct user_regs_struct
+{
+  /* Saved main processor registers. */
+  uint64_t regs[32];
+
+  /* Saved special registers. */
+  uint64_t orig_a0;
+  uint64_t csr_era;
+  uint64_t csr_badv;
+  uint64_t reserved[10];
+};
+
+struct user_fp_struct {
+  uint64_t    fpr[32];
+  uint64_t    fcc;
+  uint32_t    fcsr;
+};
+
+#endif /* _SYS_USER_H */
diff --git a/sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h b/sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h
new file mode 100644
index 0000000000..859eba464b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h
@@ -0,0 +1,32 @@
+/* Macros for ucontext routines.
+   Copyright (C) 2022 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 _LINUX_LOONGARCH_UCONTEXT_MACROS_H
+#define _LINUX_LOONGARCH_UCONTEXT_MACROS_H
+
+#include <sysdep.h>
+#include <sys/asm.h>
+#include "ucontext_i.h"
+
+#define SAVE_INT_REG(name, num, base) \
+  REG_S name, base, ((num) *SZREG + MCONTEXT_GREGS)
+
+#define RESTORE_INT_REG(name, num, base) \
+  REG_L name, base, ((num) *SZREG + MCONTEXT_GREGS)
+
+#endif /* _LINUX_LOONGARCH_UCONTEXT_MACROS_H */
diff --git a/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym b/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym
new file mode 100644
index 0000000000..f27afad56f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym
@@ -0,0 +1,31 @@
+#include <inttypes.h>
+#include <signal.h>
+#include <stddef.h>
+#include <sys/ucontext.h>
+
+-- Constants used by the rt_sigprocmask call.
+
+SIG_BLOCK
+SIG_SETMASK
+
+_NSIG8				(_NSIG / 8)
+
+-- Offsets of the fields in the ucontext_t structure.
+#define ucontext(member)	offsetof (ucontext_t, member)
+#define stack(member)		ucontext (uc_stack.member)
+#define mcontext(member)	ucontext (uc_mcontext.member)
+
+UCONTEXT_FLAGS			ucontext (__uc_flags)
+UCONTEXT_LINK			ucontext (uc_link)
+UCONTEXT_STACK			ucontext (uc_stack)
+UCONTEXT_MCONTEXT		ucontext (uc_mcontext)
+UCONTEXT_SIGMASK		ucontext (uc_sigmask)
+
+STACK_SP			stack (ss_sp)
+STACK_SIZE			stack (ss_size)
+STACK_FLAGS			stack (ss_flags)
+
+MCONTEXT_PC			mcontext (__pc)
+MCONTEXT_GREGS			mcontext (__gregs)
+
+UCONTEXT_SIZE			sizeof (ucontext_t)
-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 03/13] LoongArch: ABI Implementation
  2022-07-19  1:20 ` [PATCH v7 03/13] LoongArch: ABI Implementation caiyinyu
@ 2022-07-20 12:29   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-20 12:29 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

On 18/07/22 22:20, caiyinyu wrote:
> ---
>  sysdeps/loongarch/__longjmp.S       |  50 +++++
>  sysdeps/loongarch/bits/endianness.h |  11 ++
>  sysdeps/loongarch/bits/link.h       |  58 ++++++
>  sysdeps/loongarch/bits/setjmp.h     |  39 ++++
>  sysdeps/loongarch/bsd-_setjmp.c     |   1 +
>  sysdeps/loongarch/bsd-setjmp.c      |   1 +
>  sysdeps/loongarch/dl-machine.h      | 288 ++++++++++++++++++++++++++++
>  sysdeps/loongarch/dl-trampoline.S   |  83 ++++++++
>  sysdeps/loongarch/jmpbuf-offsets.h  |  22 +++
>  sysdeps/loongarch/jmpbuf-unwind.h   |  45 +++++
>  sysdeps/loongarch/ldsodefs.h        |  41 ++++
>  sysdeps/loongarch/linkmap.h         |  22 +++
>  sysdeps/loongarch/machine-gmon.h    |  37 ++++
>  sysdeps/loongarch/setjmp.S          |  64 +++++++
>  sysdeps/loongarch/sotruss-lib.c     |  50 +++++
>  sysdeps/loongarch/start.S           |  66 +++++++
>  sysdeps/loongarch/sys/asm.h         |  59 ++++++
>  sysdeps/loongarch/tst-audit.h       |  23 +++
>  18 files changed, 960 insertions(+)
>  create mode 100644 sysdeps/loongarch/__longjmp.S
>  create mode 100644 sysdeps/loongarch/bits/endianness.h
>  create mode 100644 sysdeps/loongarch/bits/link.h
>  create mode 100644 sysdeps/loongarch/bits/setjmp.h
>  create mode 100644 sysdeps/loongarch/bsd-_setjmp.c
>  create mode 100644 sysdeps/loongarch/bsd-setjmp.c
>  create mode 100644 sysdeps/loongarch/dl-machine.h
>  create mode 100644 sysdeps/loongarch/dl-trampoline.S
>  create mode 100644 sysdeps/loongarch/jmpbuf-offsets.h
>  create mode 100644 sysdeps/loongarch/jmpbuf-unwind.h
>  create mode 100644 sysdeps/loongarch/ldsodefs.h
>  create mode 100644 sysdeps/loongarch/linkmap.h
>  create mode 100644 sysdeps/loongarch/machine-gmon.h
>  create mode 100644 sysdeps/loongarch/setjmp.S
>  create mode 100644 sysdeps/loongarch/sotruss-lib.c
>  create mode 100644 sysdeps/loongarch/start.S
>  create mode 100644 sysdeps/loongarch/sys/asm.h
>  create mode 100644 sysdeps/loongarch/tst-audit.h
> 
> diff --git a/sysdeps/loongarch/__longjmp.S b/sysdeps/loongarch/__longjmp.S
> new file mode 100644
> index 0000000000..37e7384413
> --- /dev/null
> +++ b/sysdeps/loongarch/__longjmp.S
> @@ -0,0 +1,50 @@
> +/* longjmp.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <sysdep.h>
> +#include <sys/asm.h>
> +
> +ENTRY (__longjmp)
> +	REG_L ra, a0, 0*SZREG
> +	REG_L sp, a0, 1*SZREG
> +	REG_L x,  a0, 2*SZREG
> +	REG_L fp, a0, 3*SZREG
> +	REG_L s0, a0, 4*SZREG
> +	REG_L s1, a0, 5*SZREG
> +	REG_L s2, a0, 6*SZREG
> +	REG_L s3, a0, 7*SZREG
> +	REG_L s4, a0, 8*SZREG
> +	REG_L s5, a0, 9*SZREG
> +	REG_L s6, a0, 10*SZREG
> +	REG_L s7, a0, 11*SZREG
> +	REG_L s8, a0, 12*SZREG
> +
> +	FREG_L $f24, a0, 13*SZREG + 0*SZFREG
> +	FREG_L $f25, a0, 13*SZREG + 1*SZFREG
> +	FREG_L $f26, a0, 13*SZREG + 2*SZFREG
> +	FREG_L $f27, a0, 13*SZREG + 3*SZFREG
> +	FREG_L $f28, a0, 13*SZREG + 4*SZFREG
> +	FREG_L $f29, a0, 13*SZREG + 5*SZFREG
> +	FREG_L $f30, a0, 13*SZREG + 6*SZFREG
> +	FREG_L $f31, a0, 13*SZREG + 7*SZFREG
> +
> +	sltui	a0,a1,1
> +	ADD	a0, a0, a1	 # a0 = (a1 == 0) ? 1 : a1
> +	jirl	zero,ra,0
> +
> +END (__longjmp)
> diff --git a/sysdeps/loongarch/bits/endianness.h b/sysdeps/loongarch/bits/endianness.h
> new file mode 100644
> index 0000000000..7290be7b18
> --- /dev/null
> +++ b/sysdeps/loongarch/bits/endianness.h
> @@ -0,0 +1,11 @@
> +#ifndef _BITS_ENDIANNESS_H
> +#define _BITS_ENDIANNESS_H 1
> +
> +#ifndef _BITS_ENDIAN_H
> +#error "Never use <bits/endianness.h> directly; include <endian.h> instead."
> +#endif
> +
> +/* LoongArch is little-endian.  */
> +#define __BYTE_ORDER __LITTLE_ENDIAN
> +
> +#endif /* bits/endianness.h */
> diff --git a/sysdeps/loongarch/bits/link.h b/sysdeps/loongarch/bits/link.h
> new file mode 100644
> index 0000000000..05c91575e9
> --- /dev/null
> +++ b/sysdeps/loongarch/bits/link.h
> @@ -0,0 +1,58 @@
> +/* Machine-specific declarations for dynamic linker interface.
> +   Copyright (C) 2022 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 _LINK_H
> +#error "Never include <bits/link.h> directly; use <link.h> instead."
> +#endif
> +
> +typedef struct La_loongarch_regs
> +{
> +  unsigned long int lr_reg[8]; /* a0 - a7 */
> +  double lr_fpreg[8];	       /* fa0 - fa7 */
> +  unsigned long int lr_ra;
> +  unsigned long int lr_sp;
> +} La_loongarch_regs;
> +
> +/* Return values for calls from PLT on LoongArch.  */
> +typedef struct La_loongarch_retval
> +{
> +  unsigned long int lrv_a0;
> +  unsigned long int lrv_a1;
> +  double lrv_fa0;
> +  double lrv_fa1;
> +} La_loongarch_retval;
> +
> +__BEGIN_DECLS
> +
> +extern ElfW (Addr) la_loongarch_gnu_pltenter (ElfW (Sym) *__sym,
> +					      unsigned int __ndx,
> +					      uintptr_t *__refcook,
> +					      uintptr_t *__defcook,
> +					      La_loongarch_regs *__regs,
> +					      unsigned int *__flags,
> +					      const char *__symname,
> +					      long int *__framesizep);
> +extern unsigned int la_loongarch_gnu_pltexit (ElfW (Sym) *__sym,
> +					      unsigned int __ndx,
> +					      uintptr_t *__refcook,
> +					      uintptr_t *__defcook,
> +					      const La_loongarch_regs *__inregs,
> +					      La_loongarch_retval *__outregs,
> +					      const char *__symname);
> +
> +__END_DECLS
> diff --git a/sysdeps/loongarch/bits/setjmp.h b/sysdeps/loongarch/bits/setjmp.h
> new file mode 100644
> index 0000000000..42f8fa7657
> --- /dev/null
> +++ b/sysdeps/loongarch/bits/setjmp.h
> @@ -0,0 +1,39 @@
> +/* Define the machine-dependent type `jmp_buf'.
> +   Copyright (C) 2022 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 _LOONGARCH_BITS_SETJMP_H
> +#define _LOONGARCH_BITS_SETJMP_H
> +
> +typedef struct __jmp_buf_internal_tag
> +{
> +  /* Program counter.  */
> +  long int __pc;
> +  /* Stack pointer.  */
> +  long int __sp;
> +  /* Reserved */
> +  long int __x;
> +  /* Frame pointer.  */
> +  long int __fp;
> +  /* Callee-saved registers.  */
> +  long int __regs[9];
> +  /* Callee-saved floating point registers.  */
> +  double __fpregs[8];
> +
> +} __jmp_buf[1];
> +
> +#endif /* _LOONGARCH_BITS_SETJMP_H */
> diff --git a/sysdeps/loongarch/bsd-_setjmp.c b/sysdeps/loongarch/bsd-_setjmp.c
> new file mode 100644
> index 0000000000..32f49441c3
> --- /dev/null
> +++ b/sysdeps/loongarch/bsd-_setjmp.c
> @@ -0,0 +1 @@
> +/* _setjmp is implemented in setjmp.S.  */
> diff --git a/sysdeps/loongarch/bsd-setjmp.c b/sysdeps/loongarch/bsd-setjmp.c
> new file mode 100644
> index 0000000000..45fd802aac
> --- /dev/null
> +++ b/sysdeps/loongarch/bsd-setjmp.c
> @@ -0,0 +1 @@
> +/* setjmp is implemented in setjmp.S.  */
> diff --git a/sysdeps/loongarch/dl-machine.h b/sysdeps/loongarch/dl-machine.h
> new file mode 100644
> index 0000000000..c69c72d0ff
> --- /dev/null
> +++ b/sysdeps/loongarch/dl-machine.h
> @@ -0,0 +1,288 @@
> +/* Machine-dependent ELF dynamic relocation inline functions.
> +   Copyright (C) 2022 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 dl_machine_h
> +#define dl_machine_h
> +
> +#define ELF_MACHINE_NAME "LoongArch"
> +
> +#include <entry.h>
> +#include <elf/elf.h>
> +#include <sys/asm.h>
> +#include <dl-tls.h>
> +#include <dl-static-tls.h>
> +#include <dl-machine-rel.h>
> +
> +#ifndef _RTLD_PROLOGUE
> +# define _RTLD_PROLOGUE(entry)					\
> +	".globl\t" __STRING (entry) "\n\t"			\
> +	".type\t" __STRING (entry) ", @function\n\t"		\
> +	CFI_STARTPROC "\n"					\
> +	__STRING (entry) ":\n"
> +#endif
> +
> +#ifndef _RTLD_EPILOGUE
> +# define _RTLD_EPILOGUE(entry)					\
> +	CFI_ENDPROC "\n\t"					\
> +	".size\t" __STRING (entry) ", . - " __STRING (entry) "\n"
> +#endif
> +
> +#define ELF_MACHINE_JMP_SLOT R_LARCH_JUMP_SLOT
> +#define ELF_MACHINE_IRELATIVE R_LARCH_IRELATIVE
> +
> +#define elf_machine_type_class(type)				\
> +  ((ELF_RTYPE_CLASS_PLT *((type) == ELF_MACHINE_JMP_SLOT))	\
> +   | (ELF_RTYPE_CLASS_COPY *((type) == R_LARCH_COPY)))
> +
> +#define ELF_MACHINE_NO_REL 1
> +#define ELF_MACHINE_NO_RELA 0
> +
> +/* Return nonzero iff ELF header is compatible with the running host.  */
> +static inline int
> +elf_machine_matches_host (const ElfW (Ehdr) *ehdr)
> +{
> +  /* We can only run LoongArch binaries.  */
> +  if (ehdr->e_machine != EM_LOONGARCH)
> +    return 0;
> +
> +  return 1;
> +}
> +
> +/* Return the run-time load address of the shared object.  */
> +static inline ElfW (Addr) elf_machine_load_address (void)
> +{
> +  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
> +  return (ElfW(Addr)) &__ehdr_start;
> +}
> +
> +/* Return the link-time address of _DYNAMIC.  */
> +static inline ElfW (Addr) elf_machine_dynamic (void)
> +{
> +  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
> +  return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
> +}
> +
> +/* Initial entry point code for the dynamic linker.
> +   The C function `_dl_start' is the real entry point;
> +   its return value is the user program's entry point.  */
> +
> +#define RTLD_START asm (\
> +	".text\n\
> +	" _RTLD_PROLOGUE (ENTRY_POINT) "\
> +	.cfi_label .Ldummy   \n\
> +	" CFI_UNDEFINED (1) "   \n\
> +	or	$a0, $sp, $zero   \n\
> +	bl	_dl_start   \n\
> +	# Stash user entry point in s0.   \n\
> +	or	$s0, $v0, $zero   \n\
> +	# Load the original argument count.   \n\
> +	ld.d	$a1, $sp, 0   \n\
> +	# Call _dl_init (struct link_map *main_map, int argc, \
> +			 char **argv, char **env)    \n\
> +	la	$a0, _rtld_local   \n\
> +	ld.d	$a0, $a0, 0   \n\
> +	addi.d	$a2, $sp, 8   \n\
> +	slli.d	$a3, $a1, 3   \n\
> +	add.d	$a3, $a3, $a2   \n\
> +	addi.d	$a3, $a3, 8   \n\
> +	# Stash the stack pointer in s1.\n\
> +	or	$s1, $sp, $zero	\n\
> +	# Adjust $sp for 16-aligned   \n\
> +	bstrins.d	$sp, $zero, 3, 0  \n\
> +	# Call the function to run the initializers.   \n\
> +	bl	_dl_init   \n\
> +	# Restore the stack pointer for _start.\n\
> +	or	$sp, $s1, $zero	 \n\
> +	# Pass our finalizer function to _start.   \n\
> +	la	$a0, _dl_fini   \n\
> +	# Jump to the user entry point.   \n\
> +	jirl	$zero, $s0, 0   \n\
> +	" _RTLD_EPILOGUE (ENTRY_POINT) "\
> +	.previous");
> +
> +/* Names of the architecture-specific auditing callback functions.  */
> +#define ARCH_LA_PLTENTER loongarch_gnu_pltenter
> +#define ARCH_LA_PLTEXIT loongarch_gnu_pltexit
> +
> +/* Bias .got.plt entry by the offset requested by the PLT header.  */
> +#define elf_machine_plt_value(map, reloc, value) (value)
> +
> +static inline ElfW (Addr)
> +elf_machine_fixup_plt (struct link_map *map, lookup_t t,
> +			 const ElfW (Sym) *refsym, const ElfW (Sym) *sym,
> +			 const ElfW (Rela) *reloc, ElfW (Addr) *reloc_addr,
> +			 ElfW (Addr) value)
> +{
> +  return *reloc_addr = value;
> +}
> +
> +#endif /* !dl_machine_h */
> +
> +#ifdef RESOLVE_MAP
> +
> +/* Perform a relocation described by R_INFO at the location pointed to
> +   by RELOC_ADDR.  SYM is the relocation symbol specified by R_INFO and
> +   MAP is the object containing the reloc.  */
> +
> +static inline void __attribute__ ((always_inline))
> +elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
> +		  const ElfW (Rela) *reloc,
> +		  const ElfW (Sym) *sym,
> +		  const struct r_found_version *version,
> +		  void *const reloc_addr, int skip_ifunc)
> +{
> +  ElfW (Addr) r_info = reloc->r_info;
> +  const unsigned long int r_type = ELFW (R_TYPE) (r_info);
> +  ElfW (Addr) *addr_field = (ElfW (Addr) *) reloc_addr;
> +  const ElfW (Sym) *const __attribute__ ((unused)) refsym = sym;
> +  struct link_map *sym_map = RESOLVE_MAP (map, scope, &sym, version, r_type);
> +  ElfW (Addr) value = 0;
> +  if (sym_map != NULL)
> +    value = SYMBOL_ADDRESS (sym_map, sym, true) + reloc->r_addend;
> +
> +  if (sym != NULL
> +      && __glibc_unlikely (ELFW (ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)
> +      && __glibc_likely (sym->st_shndx != SHN_UNDEF)
> +      && __glibc_likely (!skip_ifunc))
> +    value = ((ElfW (Addr) (*) (int)) value) (GLRO (dl_hwcap));
> +
> +  switch (r_type)
> +    {
> +
> +    case R_LARCH_JUMP_SLOT:
> +    case __WORDSIZE == 64 ? R_LARCH_64:
> +    R_LARCH_32:
> +      *addr_field = value;
> +      break;
> +
> +    case R_LARCH_NONE:
> +      break;
> +
> +#ifndef RTLD_BOOTSTRAP
> +    case __WORDSIZE == 64 ? R_LARCH_TLS_DTPMOD64:
> +    R_LARCH_TLS_DTPMOD32:
> +      *addr_field = sym_map->l_tls_modid;
> +      break;
> +
> +    case __WORDSIZE == 64 ? R_LARCH_TLS_DTPREL64:
> +    R_LARCH_TLS_DTPREL32:
> +      *addr_field = TLS_DTPREL_VALUE (sym) + reloc->r_addend;
> +      break;
> +
> +    case __WORDSIZE == 64 ? R_LARCH_TLS_TPREL64:
> +    R_LARCH_TLS_TPREL32:
> +      CHECK_STATIC_TLS (map, sym_map);
> +      *addr_field = TLS_TPREL_VALUE (sym_map, sym) + reloc->r_addend;
> +      break;
> +
> +    case R_LARCH_COPY:
> +      {
> +	  if (sym == NULL)
> +	    /* This can happen in trace mode if an object could not be
> +	       found.  */
> +	    break;
> +	  if (__glibc_unlikely (sym->st_size > refsym->st_size)
> +	      || (__glibc_unlikely (sym->st_size < refsym->st_size)
> +		&& GLRO(dl_verbose)))
> +	  {
> +	    const char *strtab;
> +
> +	    strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
> +	    _dl_error_printf ("\
> +%s: Symbol `%s' has different size in shared object, consider re-linking\n",
> +	    rtld_progname ?: "<program name unknown>",
> +	    strtab + refsym->st_name);
> +	  }
> +	  memcpy (reloc_addr, (void *) value,
> +		  MIN (sym->st_size, refsym->st_size));
> +	    break;
> +      }
> +
> +    case R_LARCH_RELATIVE:
> +      *addr_field = map->l_addr + reloc->r_addend;
> +      break;
> +
> +    case R_LARCH_IRELATIVE:
> +      value = map->l_addr + reloc->r_addend;
> +      if (__glibc_likely (!skip_ifunc))
> +	value = ((ElfW (Addr) (*) (void)) value) ();
> +      *addr_field = value;
> +      break;
> +
> +#endif
> +
> +    default:
> +      _dl_reloc_bad_type (map, r_type, 0);
> +      break;
> +    }
> +}
> +
> +static inline void __attribute__ ((always_inline))
> +elf_machine_rela_relative (ElfW (Addr) l_addr, const ElfW (Rela) *reloc,
> +			   void *const reloc_addr)
> +{
> +  *(ElfW (Addr) *) reloc_addr = l_addr + reloc->r_addend;
> +}
> +
> +static inline void __attribute__ ((always_inline))
> +elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
> +		      ElfW (Addr) l_addr,
> +		      const ElfW (Rela) *reloc, int skip_ifunc)
> +{
> +  ElfW (Addr) *const reloc_addr = (void *) (l_addr + reloc->r_offset);
> +  const unsigned int r_type = ELFW (R_TYPE) (reloc->r_info);
> +
> +  /* Check for unexpected PLT reloc type.  */
> +  if (__glibc_likely (r_type == R_LARCH_JUMP_SLOT))
> +    {
> +      if (__glibc_unlikely (map->l_mach.plt == 0))
> +	{
> +	  if (l_addr)
> +	    *reloc_addr += l_addr;
> +	}
> +      else
> +	*reloc_addr = map->l_mach.plt;
> +    }
> +  else
> +    _dl_reloc_bad_type (map, r_type, 1);
> +}
> +
> +/* Set up the loaded object described by L so its stub function
> +   will jump to the on-demand fixup code __dl_runtime_resolve.  */
> +
> +static inline int __attribute__ ((always_inline))
> +elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
> +			   int lazy, int profile)
> +{
> +#ifndef RTLD_BOOTSTRAP
> +  /* If using PLTs, fill in the first two entries of .got.plt.  */
> +  if (l->l_info[DT_JMPREL])
> +    {
> +      extern void _dl_runtime_resolve (void)
> +	__attribute__ ((visibility ("hidden")));
> +      ElfW (Addr) *gotplt = (ElfW (Addr) *) D_PTR (l, l_info[DT_PLTGOT]);
> +      gotplt[0] = (ElfW (Addr)) & _dl_runtime_resolve;
> +      gotplt[1] = (ElfW (Addr)) l;
> +    }
> +#endif
> +
> +  return lazy;
> +}
> +
> +#endif /* RESOLVE_MAP */
> diff --git a/sysdeps/loongarch/dl-trampoline.S b/sysdeps/loongarch/dl-trampoline.S
> new file mode 100644
> index 0000000000..ad8ab0fda7
> --- /dev/null
> +++ b/sysdeps/loongarch/dl-trampoline.S
> @@ -0,0 +1,83 @@
> +/* PLT trampolines.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <sysdep.h>
> +#include <sys/asm.h>
> +
> +/* Assembler veneer called from the PLT header code for lazy loading.
> +   The PLT header passes its own args in t0-t2.  */
> +
> +# define FRAME_SIZE (-((-10 * SZREG - 8 * SZFREG) & ALMASK))
> +
> +ENTRY (_dl_runtime_resolve)
> +
> +	/* Save arguments to stack. */
> +	ADDI	sp, sp, -FRAME_SIZE
> +
> +	REG_S	ra, sp, 9*SZREG
> +	REG_S	a0, sp, 1*SZREG
> +	REG_S	a1, sp, 2*SZREG
> +	REG_S	a2, sp, 3*SZREG
> +	REG_S	a3, sp, 4*SZREG
> +	REG_S	a4, sp, 5*SZREG
> +	REG_S	a5, sp, 6*SZREG
> +	REG_S	a6, sp, 7*SZREG
> +	REG_S	a7, sp, 8*SZREG
> +
> +	FREG_S	fa0, sp, 10*SZREG + 0*SZFREG
> +	FREG_S	fa1, sp, 10*SZREG + 1*SZFREG
> +	FREG_S	fa2, sp, 10*SZREG + 2*SZFREG
> +	FREG_S	fa3, sp, 10*SZREG + 3*SZFREG
> +	FREG_S	fa4, sp, 10*SZREG + 4*SZFREG
> +	FREG_S	fa5, sp, 10*SZREG + 5*SZFREG
> +	FREG_S	fa6, sp, 10*SZREG + 6*SZFREG
> +	FREG_S	fa7, sp, 10*SZREG + 7*SZFREG
> +
> +	/* Update .got.plt and obtain runtime address of callee */
> +	SLLI	a1, t1, 1
> +	or	a0, t0, zero
> +	ADD	a1, a1, t1
> +	la	a2, _dl_fixup
> +	jirl	ra, a2, 0
> +	or	t1, v0, zero
> +
> +	/* Restore arguments from stack. */
> +	REG_L	ra, sp, 9*SZREG
> +	REG_L	a0, sp, 1*SZREG
> +	REG_L	a1, sp, 2*SZREG
> +	REG_L	a2, sp, 3*SZREG
> +	REG_L	a3, sp, 4*SZREG
> +	REG_L	a4, sp, 5*SZREG
> +	REG_L	a5, sp, 6*SZREG
> +	REG_L	a6, sp, 7*SZREG
> +	REG_L	a7, sp, 8*SZREG
> +
> +	FREG_L	fa0, sp, 10*SZREG + 0*SZFREG
> +	FREG_L	fa1, sp, 10*SZREG + 1*SZFREG
> +	FREG_L	fa2, sp, 10*SZREG + 2*SZFREG
> +	FREG_L	fa3, sp, 10*SZREG + 3*SZFREG
> +	FREG_L	fa4, sp, 10*SZREG + 4*SZFREG
> +	FREG_L	fa5, sp, 10*SZREG + 5*SZFREG
> +	FREG_L	fa6, sp, 10*SZREG + 6*SZFREG
> +	FREG_L	fa7, sp, 10*SZREG + 7*SZFREG
> +
> +	ADDI	sp, sp, FRAME_SIZE
> +
> +	/* Invoke the callee. */
> +	jirl		zero, t1, 0
> +END (_dl_runtime_resolve)
> diff --git a/sysdeps/loongarch/jmpbuf-offsets.h b/sysdeps/loongarch/jmpbuf-offsets.h
> new file mode 100644
> index 0000000000..a4b8ea690e
> --- /dev/null
> +++ b/sysdeps/loongarch/jmpbuf-offsets.h
> @@ -0,0 +1,22 @@
> +/* Private macros for accessing __jmp_buf contents.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <jmpbuf-unwind.h>
> +
> +/* Helper for generic ____longjmp_chk().  */
> +#define JB_FRAME_ADDRESS(buf) ((void *) _jmpbuf_sp (buf))
> diff --git a/sysdeps/loongarch/jmpbuf-unwind.h b/sysdeps/loongarch/jmpbuf-unwind.h
> new file mode 100644
> index 0000000000..6fa509151d
> --- /dev/null
> +++ b/sysdeps/loongarch/jmpbuf-unwind.h
> @@ -0,0 +1,45 @@
> +/* Examine __jmp_buf for unwinding frames.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <setjmp.h>
> +#include <stdint.h>
> +#include <unwind.h>
> +#include <sysdep.h>
> +
> +/* Test if longjmp to JMPBUF would unwind the frame
> +   containing a local variable at ADDRESS.  */
> +#define _JMPBUF_UNWINDS(jmpbuf, address, demangle) \
> +  ((void *) (address) < (void *) demangle ((jmpbuf)[0].__sp))
> +
> +#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
> +  _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
> +
> +static inline uintptr_t __attribute__ ((unused)) _jmpbuf_sp (__jmp_buf regs)
> +{
> +  uintptr_t sp = regs[0].__sp;
> +#ifdef PTR_DEMANGLE
> +  PTR_DEMANGLE (sp);
> +#endif
> +  return sp;
> +}
> +
> +#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
> +  ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
> +
> +/* We use the normal longjmp for unwinding.  */
> +#define __libc_unwind_longjmp(buf, val) __libc_longjmp (buf, val)
> diff --git a/sysdeps/loongarch/ldsodefs.h b/sysdeps/loongarch/ldsodefs.h
> new file mode 100644
> index 0000000000..36b1b25b9f
> --- /dev/null
> +++ b/sysdeps/loongarch/ldsodefs.h
> @@ -0,0 +1,41 @@
> +/* Run-time dynamic linker data structures for loaded ELF shared objects.
> +   Copyright (C) 2022 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 _LOONGARCH_LDSODEFS_H
> +#define _LOONGARCH_LDSODEFS_H 1
> +
> +#include <elf.h>
> +
> +struct La_loongarch_regs;
> +struct La_loongarch_retval;
> +
> +#define ARCH_PLTENTER_MEMBERS \
> +  ElfW (Addr) (*loongarch_gnu_pltenter) (ElfW (Sym) *, unsigned int, \
> +					 uintptr_t *, uintptr_t *, \
> +					 const struct La_loongarch_regs *, \
> +					 unsigned int *, const char *name, \
> +					 long int *framesizep);
> +
> +#define ARCH_PLTEXIT_MEMBERS \
> +  unsigned int (*loongarch_gnu_pltexit) (ElfW (Sym) *, unsigned int, \
> +		uintptr_t *, uintptr_t *, const struct La_loongarch_regs *, \
> +		struct La_loongarch_retval *, const char *);
> +
> +#include_next <ldsodefs.h>
> +
> +#endif
> diff --git a/sysdeps/loongarch/linkmap.h b/sysdeps/loongarch/linkmap.h
> new file mode 100644
> index 0000000000..bbba73ed70
> --- /dev/null
> +++ b/sysdeps/loongarch/linkmap.h
> @@ -0,0 +1,22 @@
> +/* Definition of link_map_machine.
> +   Copyright (C) 2022 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/>.  */
> +
> +struct link_map_machine
> +{
> +  ElfW (Addr) plt; /* Address of .plt.  */
> +};
> diff --git a/sysdeps/loongarch/machine-gmon.h b/sysdeps/loongarch/machine-gmon.h
> new file mode 100644
> index 0000000000..4a3cdd964e
> --- /dev/null
> +++ b/sysdeps/loongarch/machine-gmon.h
> @@ -0,0 +1,37 @@
> +/* LoongArch definitions for profiling support.
> +   Copyright (C) 2022 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/>.  */
> +
> +/* Accept 'frompc' address as argument from the function that calls
> +   _mcount for profiling.  Use  __builtin_return_address (0)
> +   for the 'selfpc' address.  */
> +
> +#include <sysdep.h>
> +
> +static void mcount_internal (unsigned long int frompc,
> +			     unsigned long int selfpc);
> +
> +#define _MCOUNT_DECL(frompc, selfpc) \
> +  static inline void mcount_internal (unsigned long int frompc, \
> +				      unsigned long int selfpc)
> +
> +#define MCOUNT \
> +  void _mcount (void *frompc) \
> +  { \
> +    mcount_internal ((unsigned long int) frompc, \
> +		     (unsigned long int) RETURN_ADDRESS (0)); \
> +  }
> diff --git a/sysdeps/loongarch/setjmp.S b/sysdeps/loongarch/setjmp.S
> new file mode 100644
> index 0000000000..3afb9f3948
> --- /dev/null
> +++ b/sysdeps/loongarch/setjmp.S
> @@ -0,0 +1,64 @@
> +/* setjmp for LoongArch.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <sysdep.h>
> +#include <sys/asm.h>
> +
> +ENTRY (_setjmp)
> +	li.w		a1,0
> +	b		HIDDEN_JUMPTARGET (__sigsetjmp)
> +END (_setjmp)
> +
> +ENTRY (setjmp)
> +	li.w		a1,1
> +END (setjmp)
> +
> +ENTRY (__sigsetjmp)
> +	REG_S ra, a0, 0*SZREG
> +	REG_S sp, a0, 1*SZREG
> +	REG_S x,  a0, 2*SZREG
> +	REG_S fp, a0, 3*SZREG
> +	REG_S s0, a0, 4*SZREG
> +	REG_S s1, a0, 5*SZREG
> +	REG_S s2, a0, 6*SZREG
> +	REG_S s3, a0, 7*SZREG
> +	REG_S s4, a0, 8*SZREG
> +	REG_S s5, a0, 9*SZREG
> +	REG_S s6, a0, 10*SZREG
> +	REG_S s7, a0, 11*SZREG
> +	REG_S s8, a0, 12*SZREG
> +
> +	FREG_S $f24, a0, 13*SZREG + 0*SZFREG
> +	FREG_S $f25, a0, 13*SZREG + 1*SZFREG
> +	FREG_S $f26, a0, 13*SZREG + 2*SZFREG
> +	FREG_S $f27, a0, 13*SZREG + 3*SZFREG
> +	FREG_S $f28, a0, 13*SZREG + 4*SZFREG
> +	FREG_S $f29, a0, 13*SZREG + 5*SZFREG
> +	FREG_S $f30, a0, 13*SZREG + 6*SZFREG
> +	FREG_S $f31, a0, 13*SZREG + 7*SZFREG
> +
> +#if !IS_IN (libc) && IS_IN(rtld)
> +	li.w		v0, 0
> +	jirl		zero,ra,0
> +#else
> +	b		__sigjmp_save
> +#endif
> +END (__sigsetjmp)
> +
> +hidden_def (__sigsetjmp)
> +weak_alias (_setjmp, __GI__setjmp)
> diff --git a/sysdeps/loongarch/sotruss-lib.c b/sysdeps/loongarch/sotruss-lib.c
> new file mode 100644
> index 0000000000..ce752785f6
> --- /dev/null
> +++ b/sysdeps/loongarch/sotruss-lib.c
> @@ -0,0 +1,50 @@
> +/* Override generic sotruss-lib.c to define actual functions for LoongArch.
> +   Copyright (C) 2022 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/>.  */
> +
> +#define HAVE_ARCH_PLTENTER
> +#define HAVE_ARCH_PLTEXIT
> +
> +#include <elf/sotruss-lib.c>
> +
> +ElfW (Addr)
> +la_loongarch_gnu_pltenter (ElfW (Sym) *sym __attribute__ ((unused)),
> +			   unsigned int ndx __attribute__ ((unused)),
> +			   uintptr_t *refcook, uintptr_t *defcook,
> +			   La_loongarch_regs *regs, unsigned int *flags,
> +			   const char *symname, long int *framesizep)
> +{
> +  print_enter (refcook, defcook, symname, regs->lr_reg[0], regs->lr_reg[1],
> +		   regs->lr_reg[2], *flags);
> +
> +  /* No need to copy anything, we will not need the parameters in any case.  */
> +  *framesizep = 0;
> +
> +  return sym->st_value;
> +}
> +
> +unsigned int
> +la_loongarch_gnu_pltexit (ElfW (Sym) *sym, unsigned int ndx,
> +			  uintptr_t *refcook, uintptr_t *defcook,
> +			  const struct La_loongarch_regs *inregs,
> +			  struct La_loongarch_retval *outregs,
> +			  const char *symname)
> +{
> +  print_exit (refcook, defcook, symname, outregs->lrv_a0);
> +
> +  return 0;
> +}
> diff --git a/sysdeps/loongarch/start.S b/sysdeps/loongarch/start.S
> new file mode 100644
> index 0000000000..280b5fab8c
> --- /dev/null
> +++ b/sysdeps/loongarch/start.S
> @@ -0,0 +1,66 @@
> +/* Startup code compliant to the ELF LoongArch ABI.
> +   Copyright (C) 2022 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/>.  */
> +
> +#define __ASSEMBLY__ 1
> +#include <entry.h>
> +#include <sys/asm.h>
> +
> +/* The entry point's job is to call __libc_start_main.  Per the ABI,
> +   a0 contains the address of a function to be passed to atexit.
> +   __libc_start_main wants this in a5.  */
> +
> +/*
> +int
> +__libc_start_main (int (*main) (int, char **, char **),
> +		   int argc,
> +		   char **argv,
> +		   __typeof (main) init,
> +		   void (*fini) (void),
> +		   void (*rtld_fini) (void),
> +		   void *stack_end);
> + */
> +
> +ENTRY (ENTRY_POINT)
> +
> +/* Terminate call stack by noting ra is undefined.  Use a dummy
> +   .cfi_label to force starting the FDE.  */
> +	.cfi_label .Ldummy
> +	cfi_undefined (1)
> +	or		a5, a0, zero /* rtld_fini */
> +
> +/* We must get symbol main through GOT table, since main may not be local.
> +   For instance: googletest defines main in dynamic library.  */
> +	la.got		a0, t0, main
> +	REG_L		a1, sp, 0
> +	ADDI		a2, sp, SZREG
> +
> +	/* Adjust $sp for 16-aligned */
> +	BSTRINS		sp, zero, 3, 0
> +
> +	move		a3, zero /* used to be init */
> +	move		a4, zero /* used to be fini */
> +	or		a6, sp, zero /* stack_end */
> +
> +	la.got		ra, t0, __libc_start_main
> +	jirl		ra, ra, 0
> +
> +	la.got		ra, t0, abort
> +	jirl		ra, ra, 0
> +END (ENTRY_POINT)
> +
> diff --git a/sysdeps/loongarch/sys/asm.h b/sysdeps/loongarch/sys/asm.h
> new file mode 100644
> index 0000000000..b41ee59694
> --- /dev/null
> +++ b/sysdeps/loongarch/sys/asm.h
> @@ -0,0 +1,59 @@
> +/* Miscellaneous macros.
> +   Copyright (C) 2022 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_ASM_H
> +#define _SYS_ASM_H
> +
> +#include <sys/regdef.h>
> +#include <sysdeps/generic/sysdep.h>
> +
> +/* Macros to handle different pointer/register sizes for 32/64-bit code.  */
> +#define SZREG 8
> +#define SZFREG 8
> +#define REG_L ld.d
> +#define REG_S st.d
> +#define SRLI srli.d
> +#define SLLI slli.d
> +#define ADDI addi.d
> +#define ADD  add.d
> +#define BSTRINS  bstrins.d
> +#define LI  li.d
> +#define FREG_L fld.d
> +#define FREG_S fst.d
> +
> +/* Declare leaf routine.  */
> +#define LEAF(symbol) \
> +  .text; \
> +  .globl symbol; \
> +  .align 3; \
> +  cfi_startproc; \
> +  .type symbol, @function; \
> +  symbol:
> +
> +#define ENTRY(symbol) LEAF (symbol)
> +
> +/* Mark end of function.  */
> +#undef END
> +#define END(function) \
> +  cfi_endproc; \
> +  .size function, .- function;
> +
> +/* Stack alignment.  */
> +#define ALMASK ~15
> +
> +#endif /* sys/asm.h */
> diff --git a/sysdeps/loongarch/tst-audit.h b/sysdeps/loongarch/tst-audit.h
> new file mode 100644
> index 0000000000..e71948c86e
> --- /dev/null
> +++ b/sysdeps/loongarch/tst-audit.h
> @@ -0,0 +1,23 @@
> +/* Definitions for testing PLT entry/exit auditing.
> +   Copyright (C) 2022 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/>.  */
> +
> +#define pltenter la_loongarch_gnu_pltenter
> +#define pltexit la_loongarch_gnu_pltexit
> +#define La_regs La_loongarch_regs
> +#define La_retval La_loongarch_retval
> +#define int_retval lrv_a0

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 05/13] LoongArch: Generic <math.h> and soft-fp Routines
  2022-07-19  1:20 ` [PATCH v7 05/13] LoongArch: Generic <math.h> and soft-fp Routines caiyinyu
@ 2022-07-20 13:04   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-20 13:04 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

On 18/07/22 22:20, caiyinyu wrote:
> ---
>  sysdeps/loongarch/bits/fenv.h   |  90 ++++++++++++++++++++++++++++
>  sysdeps/loongarch/e_sqrtl.c     |  39 ++++++++++++
>  sysdeps/loongarch/fpu_control.h |  90 ++++++++++++++++++++++++++++
>  sysdeps/loongarch/sfp-machine.h | 102 ++++++++++++++++++++++++++++++++
>  sysdeps/loongarch/tininess.h    |   1 +
>  5 files changed, 322 insertions(+)
>  create mode 100644 sysdeps/loongarch/bits/fenv.h
>  create mode 100644 sysdeps/loongarch/e_sqrtl.c
>  create mode 100644 sysdeps/loongarch/fpu_control.h
>  create mode 100644 sysdeps/loongarch/sfp-machine.h
>  create mode 100644 sysdeps/loongarch/tininess.h
> 
> diff --git a/sysdeps/loongarch/bits/fenv.h b/sysdeps/loongarch/bits/fenv.h
> new file mode 100644
> index 0000000000..7e223b402b
> --- /dev/null
> +++ b/sysdeps/loongarch/bits/fenv.h
> @@ -0,0 +1,90 @@
> +/* Floating point environment.
> +   Copyright (C) 2022 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 _FENV_H
> +#error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
> +#endif
> +
> +/* Define bits representing the exception.  We use the bit positions
> +   of the appropriate bits in the FPU control word.  */
> +enum
> +{
> +  FE_INEXACT =
> +#define FE_INEXACT 0x010000
> +    FE_INEXACT,
> +  FE_UNDERFLOW =
> +#define FE_UNDERFLOW 0x020000
> +    FE_UNDERFLOW,
> +  FE_OVERFLOW =
> +#define FE_OVERFLOW 0x040000
> +    FE_OVERFLOW,
> +  FE_DIVBYZERO =
> +#define FE_DIVBYZERO 0x080000
> +    FE_DIVBYZERO,
> +  FE_INVALID =
> +#define FE_INVALID 0x100000
> +    FE_INVALID,
> +};
> +
> +#define FE_ALL_EXCEPT \
> +  (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
> +
> +/* The LoongArch FPU supports all of the four defined rounding modes.  We
> +   use again the bit positions in the FPU control word as the values
> +   for the appropriate macros.  */
> +enum
> +{
> +  FE_TONEAREST =
> +#define FE_TONEAREST 0x000
> +    FE_TONEAREST,
> +  FE_TOWARDZERO =
> +#define FE_TOWARDZERO 0x100
> +    FE_TOWARDZERO,
> +  FE_UPWARD =
> +#define FE_UPWARD 0x200
> +    FE_UPWARD,
> +  FE_DOWNWARD =
> +#define FE_DOWNWARD 0x300
> +    FE_DOWNWARD
> +};
> +
> +/* Type representing exception flags.  */
> +typedef unsigned int fexcept_t;
> +
> +/* Type representing floating-point environment.  This function corresponds
> +   to the layout of the block written by the `fstenv'.  */
> +typedef struct
> +{
> +  unsigned int __fp_control_register;
> +} fenv_t;
> +
> +/* If the default argument is used we use this value.  */
> +#define FE_DFL_ENV ((const fenv_t *) -1)
> +
> +#ifdef __USE_GNU
> +/* Floating-point environment where none of the exception is masked.  */
> +#define FE_NOMASK_ENV ((const fenv_t *) -257)
> +#endif
> +
> +#if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
> +/* Type representing floating-point control modes.  */
> +typedef unsigned int femode_t;
> +
> +/* Default floating-point control modes.  */
> +#define FE_DFL_MODE ((const femode_t *) -1L)
> +#endif

Ok.

> diff --git a/sysdeps/loongarch/e_sqrtl.c b/sysdeps/loongarch/e_sqrtl.c
> new file mode 100644
> index 0000000000..020c8911e6
> --- /dev/null
> +++ b/sysdeps/loongarch/e_sqrtl.c
> @@ -0,0 +1,39 @@
> +/* long double square root in software floating-point emulation.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <stdlib.h>
> +#include <soft-fp/soft-fp.h>
> +#include <soft-fp/quad.h>
> +#include <libm-alias-finite.h>
> +
> +long double
> +__ieee754_sqrtl (const long double a)
> +{
> +  FP_DECL_EX;
> +  FP_DECL_Q (A);
> +  FP_DECL_Q (C);
> +  long double c;
> +
> +  FP_INIT_ROUNDMODE;
> +  FP_UNPACK_Q (A, a);
> +  FP_SQRT_Q (C, A);
> +  FP_PACK_Q (c, C);
> +  FP_HANDLE_EXCEPTIONS;
> +  return c;
> +}
> +libm_alias_finite (__ieee754_sqrtl, __sqrtl)

Ok.

> diff --git a/sysdeps/loongarch/fpu_control.h b/sysdeps/loongarch/fpu_control.h
> new file mode 100644
> index 0000000000..d34936c62b
> --- /dev/null
> +++ b/sysdeps/loongarch/fpu_control.h
> @@ -0,0 +1,90 @@
> +/* FPU control word bits.
> +   Copyright (C) 2022 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 _FPU_CONTROL_H
> +#define _FPU_CONTROL_H
> +
> +/* LoongArch FPU floating point control register bits.
> + *
> + * 31-29  -> reserved (read as 0, can not changed by software)
> + * 28     -> cause bit for invalid exception
> + * 27     -> cause bit for division by zero exception
> + * 26     -> cause bit for overflow exception
> + * 25     -> cause bit for underflow exception
> + * 24     -> cause bit for inexact exception
> + * 23-21  -> reserved (read as 0, can not changed by software)
> + * 20     -> flag invalid exception
> + * 19     -> flag division by zero exception
> + * 18     -> flag overflow exception
> + * 17     -> flag underflow exception
> + * 16     -> flag inexact exception
> + *  9-8   -> rounding control
> + *  7-5   -> reserved (read as 0, can not changed by software)
> + *  4     -> enable exception for invalid exception
> + *  3     -> enable exception for division by zero exception
> + *  2     -> enable exception for overflow exception
> + *  1     -> enable exception for underflow exception
> + *  0     -> enable exception for inexact exception
> + *
> + *
> + * Rounding Control:
> + * 00 - rounding ties to even (RNE)
> + * 01 - rounding toward zero (RZ)
> + * 10 - rounding (up) toward plus infinity (RP)
> + * 11 - rounding (down) toward minus infinity (RM)
> + */
> +
> +#include <features.h>
> +
> +/* Masks for interrupts.  */
> +#define _FPU_MASK_V 0x10 /* Invalid operation */
> +#define _FPU_MASK_Z 0x08 /* Division by zero  */
> +#define _FPU_MASK_O 0x04 /* Overflow */
> +#define _FPU_MASK_U 0x02 /* Underflow */
> +#define _FPU_MASK_I 0x01 /* Inexact operation */
> +
> +/* Flush denormalized numbers to zero.  */
> +#define _FPU_FLUSH_TZ 0x1000000
> +
> +/* Rounding control.  */
> +#define _FPU_RC_NEAREST 0x000 /* RECOMMENDED */
> +#define _FPU_RC_ZERO 0x100
> +#define _FPU_RC_UP 0x200
> +#define _FPU_RC_DOWN 0x300
> +/* Mask for rounding control.  */
> +#define _FPU_RC_MASK 0x300
> +
> +#define _FPU_RESERVED 0x0
> +
> +#define _FPU_DEFAULT 0x0
> +#define _FPU_IEEE 0x1F
> +
> +/* Type of the control word.  */
> +typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__SI__)));
> +
> +/* Macros for accessing the hardware control word.  */
> +extern fpu_control_t __loongarch_fpu_getcw (void) __THROW;
> +extern void __loongarch_fpu_setcw (fpu_control_t) __THROW;
> +#define _FPU_GETCW(cw) __asm__ volatile ("movfcsr2gr %0,$r0" : "=r"(cw))
> +#define _FPU_SETCW(cw) __asm__ volatile ("movgr2fcsr $r0,%0" : : "r"(cw))
> +
> +/* Default control word set at startup.  */
> +extern fpu_control_t __fpu_control;
> +
> +#endif /* fpu_control.h */
> +

Ok.

> diff --git a/sysdeps/loongarch/sfp-machine.h b/sysdeps/loongarch/sfp-machine.h
> new file mode 100644
> index 0000000000..5b92ac4ba2
> --- /dev/null
> +++ b/sysdeps/loongarch/sfp-machine.h
> @@ -0,0 +1,102 @@
> +/* LoongArch softfloat definitions
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <fenv.h>
> +#include <fpu_control.h>
> +
> +#define _FP_W_TYPE_SIZE 64
> +#define _FP_W_TYPE unsigned long long
> +#define _FP_WS_TYPE signed long long
> +#define _FP_I_TYPE long long
> +
> +#define _FP_MUL_MEAT_S(R, X, Y) _FP_MUL_MEAT_1_imm (_FP_WFRACBITS_S, R, X, Y)
> +#define _FP_MUL_MEAT_D(R, X, Y) \
> +  _FP_MUL_MEAT_1_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
> +#define _FP_MUL_MEAT_Q(R, X, Y) \
> +  _FP_MUL_MEAT_2_wide_3mul (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
> +
> +#define _FP_MUL_MEAT_DW_S(R, X, Y) \
> +  _FP_MUL_MEAT_DW_1_imm (_FP_WFRACBITS_S, R, X, Y)
> +#define _FP_MUL_MEAT_DW_D(R, X, Y) \
> +  _FP_MUL_MEAT_DW_1_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
> +#define _FP_MUL_MEAT_DW_Q(R, X, Y) \
> +  _FP_MUL_MEAT_DW_2_wide_3mul (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
> +
> +#define _FP_DIV_MEAT_S(R, X, Y) \
> +  _FP_DIV_MEAT_1_imm (S, R, X, Y, _FP_DIV_HELP_imm)
> +#define _FP_DIV_MEAT_D(R, X, Y) _FP_DIV_MEAT_1_udiv_norm (D, R, X, Y)
> +#define _FP_DIV_MEAT_Q(R, X, Y) _FP_DIV_MEAT_2_udiv (Q, R, X, Y)
> +
> +#define _FP_NANFRAC_S _FP_QNANBIT_S
> +#define _FP_NANFRAC_D _FP_QNANBIT_D
> +#define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0
> +
> +#define _FP_NANSIGN_S 0
> +#define _FP_NANSIGN_D 0
> +#define _FP_NANSIGN_Q 0
> +
> +#define _FP_KEEPNANFRACP 1
> +#define _FP_QNANNEGATEDP 0
> +
> +/* NaN payloads should be preserved for NAN2008.  */
> +#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
> +  do \
> +    { \
> +      R##_s = X##_s; \
> +      _FP_FRAC_COPY_##wc (R, X); \
> +      R##_c = FP_CLS_NAN; \
> +    } \
> +  while (0)
> +
> +#define _FP_DECL_EX fpu_control_t _fcw
> +
> +#define FP_ROUNDMODE (_fcw & 0x300)
> +
> +#define FP_RND_NEAREST FE_TONEAREST
> +#define FP_RND_ZERO FE_TOWARDZERO
> +#define FP_RND_PINF FE_UPWARD
> +#define FP_RND_MINF FE_DOWNWARD
> +
> +#define FP_EX_INVALID FE_INVALID
> +#define FP_EX_OVERFLOW FE_OVERFLOW
> +#define FP_EX_UNDERFLOW FE_UNDERFLOW
> +#define FP_EX_DIVZERO FE_DIVBYZERO
> +#define FP_EX_INEXACT FE_INEXACT
> +
> +#define _FP_TININESS_AFTER_ROUNDING 1
> +
> +#ifdef __loongarch_hard_float
> +#define FP_INIT_ROUNDMODE \
> +  do \
> +    { \
> +      _FPU_GETCW (_fcw); \
> +    } \
> +  while (0)
> +
> +#define FP_HANDLE_EXCEPTIONS \
> +  do \
> +    { \
> +      if (__glibc_unlikely (_fex)) \
> +	_FPU_SETCW (_fcw | _fex | (_fex << 8)); \
> +    } \
> +  while (0)
> +#define FP_TRAPPING_EXCEPTIONS ((_fcw << 16) & 0x1f0000)
> +#else
> +#define FP_INIT_ROUNDMODE _fcw = FP_RND_NEAREST
> +#endif
> diff --git a/sysdeps/loongarch/tininess.h b/sysdeps/loongarch/tininess.h
> new file mode 100644
> index 0000000000..90956c35f7
> --- /dev/null
> +++ b/sysdeps/loongarch/tininess.h
> @@ -0,0 +1 @@
> +#define TININESS_AFTER_ROUNDING 1

Ok.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 06/13] LoongArch: Atomic and Locking Routines
  2022-07-19  1:20 ` [PATCH v7 06/13] LoongArch: Atomic and Locking Routines caiyinyu
@ 2022-07-20 14:32   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-20 14:32 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail

LGTM.  We really need to remove this old atomic wrappers / implementations...

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

On 18/07/22 22:20, caiyinyu wrote:
> ---
>  .../sysv/linux/loongarch/atomic-machine.h     | 147 ++++++++++++++++++
>  1 file changed, 147 insertions(+)
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/atomic-machine.h
> 
> diff --git a/sysdeps/unix/sysv/linux/loongarch/atomic-machine.h b/sysdeps/unix/sysv/linux/loongarch/atomic-machine.h
> new file mode 100644
> index 0000000000..d1b8f1c11b
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/atomic-machine.h
> @@ -0,0 +1,147 @@
> +/* Atomic operations.
> +   Copyright (C) 2022 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 _LINUX_LOONGARCH_BITS_ATOMIC_H
> +#define _LINUX_LOONGARCH_BITS_ATOMIC_H 1
> +
> +#define atomic_full_barrier() __sync_synchronize ()
> +
> +#define __HAVE_64B_ATOMICS (__loongarch_grlen >= 64)
> +#define USE_ATOMIC_COMPILER_BUILTINS 1
> +#define ATOMIC_EXCHANGE_USES_CAS 0
> +
> +/* Compare and exchange.
> +   For all "bool" routines, we return FALSE if exchange succesful.  */
> +
> +#define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
> +  ({ \
> +    typeof (*mem) __oldval = (oldval); \
> +    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
> +				  __ATOMIC_RELAXED); \
> +  })
> +
> +#define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
> +  ({ \
> +    typeof (*mem) __oldval = (oldval); \
> +    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
> +				  __ATOMIC_RELAXED); \
> +  })
> +
> +#define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
> +  ({ \
> +    typeof (*mem) __oldval = (oldval); \
> +    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
> +				  __ATOMIC_RELAXED); \
> +  })
> +
> +#define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
> +  ({ \
> +    typeof (*mem) __oldval = (oldval); \
> +    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
> +				  __ATOMIC_RELAXED); \
> +  })
> +
> +#define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
> +  ({ \
> +    typeof (*mem) __oldval = (oldval); \
> +    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
> +				 __ATOMIC_RELAXED); \
> +    __oldval; \
> +  })
> +
> +#define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
> +  ({ \
> +    typeof (*mem) __oldval = (oldval); \
> +    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
> +				 __ATOMIC_RELAXED); \
> +    __oldval; \
> +  })
> +
> +#define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
> +  ({ \
> +    typeof (*mem) __oldval = (oldval); \
> +    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
> +				 __ATOMIC_RELAXED); \
> +    __oldval; \
> +  })
> +
> +#define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
> +  ({ \
> +    typeof (*mem) __oldval = (oldval); \
> +    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, model, \
> +				 __ATOMIC_RELAXED); \
> +    __oldval; \
> +  })
> +
> +/* Atomic compare and exchange.  */
> +
> +#define atomic_compare_and_exchange_bool_acq(mem, new, old) \
> +  __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, mem, new, old, \
> +			__ATOMIC_ACQUIRE)
> +
> +#define atomic_compare_and_exchange_val_acq(mem, new, old) \
> +  __atomic_val_bysize (__arch_compare_and_exchange_val, int, mem, new, old, \
> +		       __ATOMIC_ACQUIRE)
> +
> +#define atomic_compare_and_exchange_val_rel(mem, new, old) \
> +  __atomic_val_bysize (__arch_compare_and_exchange_val, int, mem, new, old, \
> +		       __ATOMIC_RELEASE)
> +
> +/* Atomic exchange (without compare).  */
> +
> +#define __arch_exchange_8_int(mem, newval, model) \
> +  __atomic_exchange_n (mem, newval, model)
> +
> +#define __arch_exchange_16_int(mem, newval, model) \
> +  __atomic_exchange_n (mem, newval, model)
> +
> +#define __arch_exchange_32_int(mem, newval, model) \
> +  __atomic_exchange_n (mem, newval, model)
> +
> +#define __arch_exchange_64_int(mem, newval, model) \
> +  __atomic_exchange_n (mem, newval, model)
> +
> +#define atomic_exchange_acq(mem, value) \
> +  __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
> +
> +#define atomic_exchange_rel(mem, value) \
> +  __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
> +
> +/* Atomically add value and return the previous (unincremented) value.  */
> +
> +#define __arch_exchange_and_add_8_int(mem, value, model) \
> +  __atomic_fetch_add (mem, value, model)
> +
> +#define __arch_exchange_and_add_16_int(mem, value, model) \
> +  __atomic_fetch_add (mem, value, model)
> +
> +#define __arch_exchange_and_add_32_int(mem, value, model) \
> +  __atomic_fetch_add (mem, value, model)
> +
> +#define __arch_exchange_and_add_64_int(mem, value, model) \
> +  __atomic_fetch_add (mem, value, model)
> +
> +#define atomic_exchange_and_add_acq(mem, value) \
> +  __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
> +		       __ATOMIC_ACQUIRE)
> +
> +#define atomic_exchange_and_add_rel(mem, value) \
> +  __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
> +		       __ATOMIC_RELEASE)
> +
> +#endif /* bits/atomic.h */

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 04/13] LoongArch: Thread-Local Storage Support
  2022-07-19  1:20 ` [PATCH v7 04/13] LoongArch: Thread-Local Storage Support caiyinyu
@ 2022-07-20 14:34   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-20 14:34 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

On 18/07/22 22:20, caiyinyu wrote:
> ---
>  sysdeps/loongarch/dl-tls.h    |  46 ++++++++++++
>  sysdeps/loongarch/libc-tls.c  |  32 ++++++++
>  sysdeps/loongarch/nptl/tls.h  | 138 ++++++++++++++++++++++++++++++++++
>  sysdeps/loongarch/stackinfo.h |  33 ++++++++
>  4 files changed, 249 insertions(+)
>  create mode 100644 sysdeps/loongarch/dl-tls.h
>  create mode 100644 sysdeps/loongarch/libc-tls.c
>  create mode 100644 sysdeps/loongarch/nptl/tls.h
>  create mode 100644 sysdeps/loongarch/stackinfo.h
> 
> diff --git a/sysdeps/loongarch/dl-tls.h b/sysdeps/loongarch/dl-tls.h
> new file mode 100644
> index 0000000000..f82edcae76
> --- /dev/null
> +++ b/sysdeps/loongarch/dl-tls.h
> @@ -0,0 +1,46 @@
> +/* Thread-local storage handling in the ELF dynamic linker.
> +   Copyright (C) 2022 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/>.  */
> +
> +/* Type used for the representation of TLS information in the GOT.  */
> +typedef struct
> +{
> +  unsigned long int ti_module;
> +  unsigned long int ti_offset;
> +} tls_index;
> +
> +/* The thread pointer points to the first static TLS block.  */
> +#define TLS_TP_OFFSET 0
> +
> +/* Dynamic thread vector pointers point to the start of each
> +   TLS block.  */
> +#define TLS_DTV_OFFSET 0
> +
> +/* Compute the value for a GOTTPREL reloc.  */
> +#define TLS_TPREL_VALUE(sym_map, sym) \
> +  ((sym_map)->l_tls_offset + (sym)->st_value - TLS_TP_OFFSET)
> +
> +/* Compute the value for a DTPREL reloc.  */
> +#define TLS_DTPREL_VALUE(sym) ((sym)->st_value - TLS_DTV_OFFSET)
> +
> +extern void *__tls_get_addr (tls_index *ti);
> +
> +#define GET_ADDR_OFFSET (ti->ti_offset + TLS_DTV_OFFSET)
> +#define __TLS_GET_ADDR(__ti) (__tls_get_addr (__ti) - TLS_DTV_OFFSET)
> +
> +/* Value used for dtv entries for which the allocation is delayed.  */
> +#define TLS_DTV_UNALLOCATED ((void *) -1l)

Ok.

> diff --git a/sysdeps/loongarch/libc-tls.c b/sysdeps/loongarch/libc-tls.c
> new file mode 100644
> index 0000000000..9285d11a7b
> --- /dev/null
> +++ b/sysdeps/loongarch/libc-tls.c
> @@ -0,0 +1,32 @@
> +/* Thread-local storage handling in the ELF dynamic linker.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <csu/libc-tls.c>
> +#include <dl-tls.h>
> +
> +/* On LoongArch, linker optimizations are not required, so __tls_get_addr
> +   can be called even in statically linked binaries.  In this case module
> +   must be always 1 and PT_TLS segment exist in the binary, otherwise it
> +   would not link.  */
> +
> +void *
> +__tls_get_addr (tls_index *ti)
> +{
> +  dtv_t *dtv = THREAD_DTV ();
> +  return (char *) dtv[1].pointer.val + GET_ADDR_OFFSET;
> +}

Ok.

> diff --git a/sysdeps/loongarch/nptl/tls.h b/sysdeps/loongarch/nptl/tls.h
> new file mode 100644
> index 0000000000..3b271c4b60
> --- /dev/null
> +++ b/sysdeps/loongarch/nptl/tls.h
> @@ -0,0 +1,138 @@
> +/* Definition for thread-local data handling.
> +   Copyright (C) 2022 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 _LOONGARCH_TLS_H
> +#define _LOONGARCH_TLS_H 1
> +
> +#include <dl-sysdep.h>
> +
> +#ifndef __ASSEMBLER__
> +#include <stdbool.h>
> +#include <stddef.h>
> +#include <stdint.h>
> +#include <dl-dtv.h>
> +
> +register void *__thread_self asm ("$tp");
> +#define READ_THREAD_POINTER() ({ __thread_self; })
> +
> +/* Get system call information.  */
> +#include <sysdep.h>
> +
> +/* The TP points to the start of the thread blocks.  */
> +#define TLS_DTV_AT_TP 1
> +#define TLS_TCB_AT_TP 0
> +
> +/* Get the thread descriptor definition.  */
> +#include <nptl/descr.h>
> +
> +typedef struct
> +{
> +  dtv_t *dtv;
> +  void *private;
> +} tcbhead_t;
> +
> +/* This is the size of the initial TCB.  Because our TCB is before the thread
> +   pointer, we don't need this.  */
> +#define TLS_INIT_TCB_SIZE 0
> +
> +/* Alignment requirements for the initial TCB.  */
> +#define TLS_INIT_TCB_ALIGN __alignof__(struct pthread)
> +
> +/* This is the size of the TCB.  Because our TCB is before the thread
> +   pointer, we don't need this.  */
> +#define TLS_TCB_SIZE 0
> +
> +/* Alignment requirements for the TCB.  */
> +#define TLS_TCB_ALIGN __alignof__(struct pthread)
> +
> +/* This is the size we need before TCB - actually, it includes the TCB.  */
> +#define TLS_PRE_TCB_SIZE \
> +  (sizeof (struct pthread) \
> +   + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
> +
> +/* The thread pointer tp points to the end of the TCB.
> +   The pthread_descr structure is immediately in front of the TCB.  */
> +#define TLS_TCB_OFFSET 0
> +
> +/* Install the dtv pointer.  The pointer passed is to the element with
> +   index -1 which contain the length.  */
> +#define INSTALL_DTV(tcbp, dtvp) (((tcbhead_t *) (tcbp))[-1].dtv = (dtvp) + 1)
> +
> +/* Install new dtv for current thread.  */
> +#define INSTALL_NEW_DTV(dtv) (THREAD_DTV () = (dtv))
> +
> +/* Return dtv of given thread descriptor.  */
> +#define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
> +
> +/* Code to initially initialize the thread pointer.  */
> +#define TLS_INIT_TP(tcbp) \
> +  ({ \
> +    __thread_self = (char *) tcbp + TLS_TCB_OFFSET; \
> +    NULL; \
> +  })
> +
> +/* Return the address of the dtv for the current thread.  */
> +#define THREAD_DTV() \
> +  (((tcbhead_t *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET))[-1].dtv)
> +
> +/* Return the thread descriptor for the current thread.  */
> +#define THREAD_SELF \
> +  ((struct pthread *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET \
> +		       - TLS_PRE_TCB_SIZE))
> +
> +/* Value passed to 'clone' for initialization of the thread register.  */
> +#define TLS_DEFINE_INIT_TP(tp, pd) \
> +  void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
> +
> +/* Informs libthread_db that the thread pointer is register 2, which is used
> + * to know how to do THREAD_SELF.  */
> +#define DB_THREAD_SELF \
> +  REGISTER (64, 64, 2 * 8, -TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
> +
> +/* Access to data in the thread descriptor is easy.  */
> +# include <tcb-access.h>
> +
> +/* l_tls_offset == 0 is perfectly valid, so we have to use some different
> +   value to mean unset l_tls_offset.  */
> +#define NO_TLS_OFFSET -1
> +
> +/* Get and set the global scope generation counter in struct pthread.  */
> +#define THREAD_GSCOPE_IN_TCB 1
> +#define THREAD_GSCOPE_FLAG_UNUSED 0
> +#define THREAD_GSCOPE_FLAG_USED 1
> +#define THREAD_GSCOPE_FLAG_WAIT 2
> +#define THREAD_GSCOPE_RESET_FLAG() \
> +  do \
> +    { \
> +      int __res = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
> +				       THREAD_GSCOPE_FLAG_UNUSED); \
> +      if (__res == THREAD_GSCOPE_FLAG_WAIT) \
> +	lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
> +    } \
> +  while (0)
> +#define THREAD_GSCOPE_SET_FLAG() \
> +  do \
> +    { \
> +      THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
> +      atomic_write_barrier (); \
> +    } \
> +  while (0)
> +
> +#endif /* __ASSEMBLER__ */
> +
> +#endif /* tls.h */

Ok.

> diff --git a/sysdeps/loongarch/stackinfo.h b/sysdeps/loongarch/stackinfo.h
> new file mode 100644
> index 0000000000..ff8b9b7bf2
> --- /dev/null
> +++ b/sysdeps/loongarch/stackinfo.h
> @@ -0,0 +1,33 @@
> +/* Stack environment definitions for LoongArch.
> +   Copyright (C) 2022 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/>.  */
> +
> +/* This file contains a bit of information about the stack allocation
> +   of the processor.  */
> +
> +#ifndef _STACKINFO_H
> +#define _STACKINFO_H 1
> +
> +#include <elf.h>
> +
> +/* On LoongArch the stack grows down.  */
> +#define _STACK_GROWS_DOWN 1
> +
> +/* Default to a non-executable stack.  */
> +#define DEFAULT_STACK_PERMS (PF_R | PF_W)
> +
> +#endif /* stackinfo.h */

Ok.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 07/13] LoongArch: Linux Syscall Interface
  2022-07-19  1:20 ` [PATCH v7 07/13] LoongArch: Linux Syscall Interface caiyinyu
@ 2022-07-20 14:35   ` Adhemerval Zanella Netto
  2022-07-27  5:27   ` WANG Xuerui
  1 sibling, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-20 14:35 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

On 18/07/22 22:20, caiyinyu wrote:
> ---
>  sysdeps/loongarch/abort-instr.h               |   2 +
>  sysdeps/loongarch/hp-timing.h                 |  42 +++
>  .../unix/sysv/linux/loongarch/arch-syscall.h  | 301 ++++++++++++++++
>  sysdeps/unix/sysv/linux/loongarch/clone.S     |  96 ++++++
>  sysdeps/unix/sysv/linux/loongarch/clone3.S    |  83 +++++
>  sysdeps/unix/sysv/linux/loongarch/sysdep.S    |  53 +++
>  sysdeps/unix/sysv/linux/loongarch/sysdep.h    | 320 ++++++++++++++++++
>  sysdeps/unix/sysv/linux/loongarch/vfork.S     |  50 +++
>  8 files changed, 947 insertions(+)
>  create mode 100644 sysdeps/loongarch/abort-instr.h
>  create mode 100644 sysdeps/loongarch/hp-timing.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone.S
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/sysdep.S
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/sysdep.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/vfork.S
> 
> diff --git a/sysdeps/loongarch/abort-instr.h b/sysdeps/loongarch/abort-instr.h
> new file mode 100644
> index 0000000000..46d3ad0871
> --- /dev/null
> +++ b/sysdeps/loongarch/abort-instr.h
> @@ -0,0 +1,2 @@
> +/* An instruction which should crash any program is a breakpoint.  */
> +#define ABORT_INSTRUCTION asm ("break 0")
> diff --git a/sysdeps/loongarch/hp-timing.h b/sysdeps/loongarch/hp-timing.h
> new file mode 100644
> index 0000000000..af1da81024
> --- /dev/null
> +++ b/sysdeps/loongarch/hp-timing.h
> @@ -0,0 +1,42 @@
> +/* High precision, low overhead timing functions.
> +   Copyright (C) 2022 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 _HP_TIMING_H
> +#define _HP_TIMING_H 1
> +
> +/* We always assume having the timestamp register.  */
> +#define HP_TIMING_AVAIL (1)
> +#define HP_SMALL_TIMING_AVAIL (1)
> +
> +/* We indeed have inlined functions.  */
> +#define HP_TIMING_INLINE (1)
> +
> +/* We use 64bit values for the times.  */
> +typedef unsigned long long int hp_timing_t;
> +
> +/* Read the stable counter.  */
> +#define HP_TIMING_NOW(Var) \
> +  ({ \
> +    unsigned long long int _count; \
> +    asm volatile ("rdtime.d\t%0,$r0" : "=r" (_count)); \
> +    (Var) = _count; \
> +  })
> +
> +#include <hp-timing-common.h>
> +
> +#endif /* hp-timing.h */
> diff --git a/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h b/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
> new file mode 100644
> index 0000000000..6bb3c8adbc
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
> @@ -0,0 +1,301 @@
> +/* AUTOGENERATED by update-syscall-lists.py.  */
> +#define __NR_accept 202
> +#define __NR_accept4 242
> +#define __NR_acct 89
> +#define __NR_add_key 217
> +#define __NR_adjtimex 171
> +#define __NR_bind 200
> +#define __NR_bpf 280
> +#define __NR_brk 214
> +#define __NR_capget 90
> +#define __NR_capset 91
> +#define __NR_chdir 49
> +#define __NR_chroot 51
> +#define __NR_clock_adjtime 266
> +#define __NR_clock_getres 114
> +#define __NR_clock_gettime 113
> +#define __NR_clock_nanosleep 115
> +#define __NR_clock_settime 112
> +#define __NR_clone 220
> +#define __NR_clone3 435
> +#define __NR_close 57
> +#define __NR_close_range 436
> +#define __NR_connect 203
> +#define __NR_copy_file_range 285
> +#define __NR_delete_module 106
> +#define __NR_dup 23
> +#define __NR_dup3 24
> +#define __NR_epoll_create1 20
> +#define __NR_epoll_ctl 21
> +#define __NR_epoll_pwait 22
> +#define __NR_epoll_pwait2 441
> +#define __NR_eventfd2 19
> +#define __NR_execve 221
> +#define __NR_execveat 281
> +#define __NR_exit 93
> +#define __NR_exit_group 94
> +#define __NR_faccessat 48
> +#define __NR_faccessat2 439
> +#define __NR_fadvise64 223
> +#define __NR_fallocate 47
> +#define __NR_fanotify_init 262
> +#define __NR_fanotify_mark 263
> +#define __NR_fchdir 50
> +#define __NR_fchmod 52
> +#define __NR_fchmodat 53
> +#define __NR_fchown 55
> +#define __NR_fchownat 54
> +#define __NR_fcntl 25
> +#define __NR_fdatasync 83
> +#define __NR_fgetxattr 10
> +#define __NR_finit_module 273
> +#define __NR_flistxattr 13
> +#define __NR_flock 32
> +#define __NR_fremovexattr 16
> +#define __NR_fsconfig 431
> +#define __NR_fsetxattr 7
> +#define __NR_fsmount 432
> +#define __NR_fsopen 430
> +#define __NR_fspick 433
> +#define __NR_fstatfs 44
> +#define __NR_fsync 82
> +#define __NR_ftruncate 46
> +#define __NR_futex 98
> +#define __NR_futex_waitv 449
> +#define __NR_get_mempolicy 236
> +#define __NR_get_robust_list 100
> +#define __NR_getcpu 168
> +#define __NR_getcwd 17
> +#define __NR_getdents64 61
> +#define __NR_getegid 177
> +#define __NR_geteuid 175
> +#define __NR_getgid 176
> +#define __NR_getgroups 158
> +#define __NR_getitimer 102
> +#define __NR_getpeername 205
> +#define __NR_getpgid 155
> +#define __NR_getpid 172
> +#define __NR_getppid 173
> +#define __NR_getpriority 141
> +#define __NR_getrandom 278
> +#define __NR_getresgid 150
> +#define __NR_getresuid 148
> +#define __NR_getrusage 165
> +#define __NR_getsid 156
> +#define __NR_getsockname 204
> +#define __NR_getsockopt 209
> +#define __NR_gettid 178
> +#define __NR_gettimeofday 169
> +#define __NR_getuid 174
> +#define __NR_getxattr 8
> +#define __NR_init_module 105
> +#define __NR_inotify_add_watch 27
> +#define __NR_inotify_init1 26
> +#define __NR_inotify_rm_watch 28
> +#define __NR_io_cancel 3
> +#define __NR_io_destroy 1
> +#define __NR_io_getevents 4
> +#define __NR_io_pgetevents 292
> +#define __NR_io_setup 0
> +#define __NR_io_submit 2
> +#define __NR_io_uring_enter 426
> +#define __NR_io_uring_register 427
> +#define __NR_io_uring_setup 425
> +#define __NR_ioctl 29
> +#define __NR_ioprio_get 31
> +#define __NR_ioprio_set 30
> +#define __NR_kcmp 272
> +#define __NR_kexec_file_load 294
> +#define __NR_kexec_load 104
> +#define __NR_keyctl 219
> +#define __NR_kill 129
> +#define __NR_landlock_add_rule 445
> +#define __NR_landlock_create_ruleset 444
> +#define __NR_landlock_restrict_self 446
> +#define __NR_lgetxattr 9
> +#define __NR_linkat 37
> +#define __NR_listen 201
> +#define __NR_listxattr 11
> +#define __NR_llistxattr 12
> +#define __NR_lookup_dcookie 18
> +#define __NR_lremovexattr 15
> +#define __NR_lseek 62
> +#define __NR_lsetxattr 6
> +#define __NR_madvise 233
> +#define __NR_mbind 235
> +#define __NR_membarrier 283
> +#define __NR_memfd_create 279
> +#define __NR_migrate_pages 238
> +#define __NR_mincore 232
> +#define __NR_mkdirat 34
> +#define __NR_mknodat 33
> +#define __NR_mlock 228
> +#define __NR_mlock2 284
> +#define __NR_mlockall 230
> +#define __NR_mmap 222
> +#define __NR_mount 40
> +#define __NR_mount_setattr 442
> +#define __NR_move_mount 429
> +#define __NR_move_pages 239
> +#define __NR_mprotect 226
> +#define __NR_mq_getsetattr 185
> +#define __NR_mq_notify 184
> +#define __NR_mq_open 180
> +#define __NR_mq_timedreceive 183
> +#define __NR_mq_timedsend 182
> +#define __NR_mq_unlink 181
> +#define __NR_mremap 216
> +#define __NR_msgctl 187
> +#define __NR_msgget 186
> +#define __NR_msgrcv 188
> +#define __NR_msgsnd 189
> +#define __NR_msync 227
> +#define __NR_munlock 229
> +#define __NR_munlockall 231
> +#define __NR_munmap 215
> +#define __NR_name_to_handle_at 264
> +#define __NR_nanosleep 101
> +#define __NR_nfsservctl 42
> +#define __NR_open_by_handle_at 265
> +#define __NR_open_tree 428
> +#define __NR_openat 56
> +#define __NR_openat2 437
> +#define __NR_perf_event_open 241
> +#define __NR_personality 92
> +#define __NR_pidfd_getfd 438
> +#define __NR_pidfd_open 434
> +#define __NR_pidfd_send_signal 424
> +#define __NR_pipe2 59
> +#define __NR_pivot_root 41
> +#define __NR_pkey_alloc 289
> +#define __NR_pkey_free 290
> +#define __NR_pkey_mprotect 288
> +#define __NR_ppoll 73
> +#define __NR_prctl 167
> +#define __NR_pread64 67
> +#define __NR_preadv 69
> +#define __NR_preadv2 286
> +#define __NR_prlimit64 261
> +#define __NR_process_madvise 440
> +#define __NR_process_mrelease 448
> +#define __NR_process_vm_readv 270
> +#define __NR_process_vm_writev 271
> +#define __NR_pselect6 72
> +#define __NR_ptrace 117
> +#define __NR_pwrite64 68
> +#define __NR_pwritev 70
> +#define __NR_pwritev2 287
> +#define __NR_quotactl 60
> +#define __NR_quotactl_fd 443
> +#define __NR_read 63
> +#define __NR_readahead 213
> +#define __NR_readlinkat 78
> +#define __NR_readv 65
> +#define __NR_reboot 142
> +#define __NR_recvfrom 207
> +#define __NR_recvmmsg 243
> +#define __NR_recvmsg 212
> +#define __NR_remap_file_pages 234
> +#define __NR_removexattr 14
> +#define __NR_renameat2 276
> +#define __NR_request_key 218
> +#define __NR_restart_syscall 128
> +#define __NR_rseq 293
> +#define __NR_rt_sigaction 134
> +#define __NR_rt_sigpending 136
> +#define __NR_rt_sigprocmask 135
> +#define __NR_rt_sigqueueinfo 138
> +#define __NR_rt_sigreturn 139
> +#define __NR_rt_sigsuspend 133
> +#define __NR_rt_sigtimedwait 137
> +#define __NR_rt_tgsigqueueinfo 240
> +#define __NR_sched_get_priority_max 125
> +#define __NR_sched_get_priority_min 126
> +#define __NR_sched_getaffinity 123
> +#define __NR_sched_getattr 275
> +#define __NR_sched_getparam 121
> +#define __NR_sched_getscheduler 120
> +#define __NR_sched_rr_get_interval 127
> +#define __NR_sched_setaffinity 122
> +#define __NR_sched_setattr 274
> +#define __NR_sched_setparam 118
> +#define __NR_sched_setscheduler 119
> +#define __NR_sched_yield 124
> +#define __NR_seccomp 277
> +#define __NR_semctl 191
> +#define __NR_semget 190
> +#define __NR_semop 193
> +#define __NR_semtimedop 192
> +#define __NR_sendfile 71
> +#define __NR_sendmmsg 269
> +#define __NR_sendmsg 211
> +#define __NR_sendto 206
> +#define __NR_set_mempolicy 237
> +#define __NR_set_mempolicy_home_node 450
> +#define __NR_set_robust_list 99
> +#define __NR_set_tid_address 96
> +#define __NR_setdomainname 162
> +#define __NR_setfsgid 152
> +#define __NR_setfsuid 151
> +#define __NR_setgid 144
> +#define __NR_setgroups 159
> +#define __NR_sethostname 161
> +#define __NR_setitimer 103
> +#define __NR_setns 268
> +#define __NR_setpgid 154
> +#define __NR_setpriority 140
> +#define __NR_setregid 143
> +#define __NR_setresgid 149
> +#define __NR_setresuid 147
> +#define __NR_setreuid 145
> +#define __NR_setsid 157
> +#define __NR_setsockopt 208
> +#define __NR_settimeofday 170
> +#define __NR_setuid 146
> +#define __NR_setxattr 5
> +#define __NR_shmat 196
> +#define __NR_shmctl 195
> +#define __NR_shmdt 197
> +#define __NR_shmget 194
> +#define __NR_shutdown 210
> +#define __NR_sigaltstack 132
> +#define __NR_signalfd4 74
> +#define __NR_socket 198
> +#define __NR_socketpair 199
> +#define __NR_splice 76
> +#define __NR_statfs 43
> +#define __NR_statx 291
> +#define __NR_swapoff 225
> +#define __NR_swapon 224
> +#define __NR_symlinkat 36
> +#define __NR_sync 81
> +#define __NR_sync_file_range 84
> +#define __NR_syncfs 267
> +#define __NR_sysinfo 179
> +#define __NR_syslog 116
> +#define __NR_tee 77
> +#define __NR_tgkill 131
> +#define __NR_timer_create 107
> +#define __NR_timer_delete 111
> +#define __NR_timer_getoverrun 109
> +#define __NR_timer_gettime 108
> +#define __NR_timer_settime 110
> +#define __NR_timerfd_create 85
> +#define __NR_timerfd_gettime 87
> +#define __NR_timerfd_settime 86
> +#define __NR_times 153
> +#define __NR_tkill 130
> +#define __NR_truncate 45
> +#define __NR_umask 166
> +#define __NR_umount2 39
> +#define __NR_uname 160
> +#define __NR_unlinkat 35
> +#define __NR_unshare 97
> +#define __NR_userfaultfd 282
> +#define __NR_utimensat 88
> +#define __NR_vhangup 58
> +#define __NR_vmsplice 75
> +#define __NR_wait4 260
> +#define __NR_waitid 95
> +#define __NR_write 64
> +#define __NR_writev 66
> diff --git a/sysdeps/unix/sysv/linux/loongarch/clone.S b/sysdeps/unix/sysv/linux/loongarch/clone.S
> new file mode 100644
> index 0000000000..c73245be82
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/clone.S
> @@ -0,0 +1,96 @@
> +/* The clone syscall wrapper.
> +   Copyright (C) 2022 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/>.  */
> +
> +/* clone() is even more special than fork() as it mucks with stacks
> +   and invokes a function in the right context after its all over.  */
> +
> +#include <sys/asm.h>
> +#include <sysdep.h>
> +#define _ERRNO_H  1
> +#include <bits/errno.h>
> +#include <tls.h>
> +#include "tcb-offsets.h"
> +
> +/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
> +   void *parent_tidptr, void *tls, void *child_tidptr) */
> +
> +ENTRY (__clone)
> +
> +	/* Align stack to 16.  */
> +	BSTRINS		a1, zero, 3, 0
> +
> +	/* Sanity check arguments.  */
> +	beqz		a0, L (invalid) /* No NULL function pointers.  */
> +	beqz		a1, L (invalid) /* No NULL stack pointers.  */
> +
> +	ADDI 		a1, a1, -16 /* Reserve argument save space.  */
> +	REG_S		a0, a1, 0   /* Save function pointer.  */
> +	REG_S		a3, a1, SZREG   /* Save argument pointer.  */
> +
> +	/* The syscall expects the args to be in different slots.  */
> +	or		a0, a2, zero
> +	or		a2, a4, zero
> +	or		a3, a6, zero
> +	or		a4, a5, zero
> +
> +	/* Do the system call.  */
> +	LI		a7,__NR_clone
> +	syscall		0
> +
> +	blt		a0, zero ,L (error)
> +	beqz		a0,L (thread_start)
> +
> +	/* Successful return from the parent.  */
> +	ret
> +
> +L (invalid):
> +	LI		a0, -EINVAL
> +
> +	/* Something bad happened -- no child created.  */
> +L (error):
> +	b		__syscall_error
> +
> +END (__clone)
> +
> +/* Load up the arguments to the function.  Put this block of code in
> +   its own function so that we can terminate the stack trace with our
> +   debug info.  */
> +ENTRY (__thread_start)
> +L (thread_start):
> +
> +/* Terminate call stack by noting ra is undefined.  Use a dummy
> +   .cfi_label to force starting the FDE.  */
> +	.cfi_label .Ldummy
> +	cfi_undefined (1)
> +
> +	/* Restore the arg for user's function.  */
> +	REG_L		a1, sp, 0   /* Function pointer.  */
> +	REG_L		a0, sp, SZREG   /* Argument pointer.  */
> +
> +	/* Call the user's function.  */
> +	jirl		ra, a1, 0
> +
> +	/* Call exit with the function's return value.  */
> +	LI		a7, __NR_exit
> +	syscall		0
> +
> +	END (__thread_start)
> +
> +libc_hidden_def (__clone)
> +weak_alias (__clone, clone)
> diff --git a/sysdeps/unix/sysv/linux/loongarch/clone3.S b/sysdeps/unix/sysv/linux/loongarch/clone3.S
> new file mode 100644
> index 0000000000..38be4c809b
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/clone3.S
> @@ -0,0 +1,83 @@
> +/* The clone3 syscall wrapper.
> +   Copyright (C) 2022 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/>.  */
> +
> +/* clone3() is even more special than fork() as it mucks with stacks
> +   and invokes a function in the right context after its all over.  */
> +
> +#include <sys/asm.h>
> +#include <sysdep.h>
> +#define _ERRNO_H  1
> +#include <bits/errno.h>
> +#include <tls.h>
> +#include "tcb-offsets.h"
> +
> +/* int clone3(struct clone_args *cl_args, size_t size,
> +   int (*func)(void *arg), void *arg); */
> +
> +ENTRY (__clone3)
> +
> +	/* Sanity check arguments.  */
> +	beqz		a0, L (invalid)	/* No NULL cl_args pointer.  */
> +	beqz		a2, L (invalid)	/* No NULL function pointer.  */
> +
> +	/* Do the system call.  */
> +	LI		a7, __NR_clone3
> +	syscall		0
> +
> +	blt		a0, zero ,L (error)
> +	beqz		a0, L (thread_start3)
> +
> +	/* Successful return from the parent.  */
> +	ret
> +
> +L (invalid):
> +	LI		a0, -EINVAL
> +
> +	/* Something bad happened -- no child created.  */
> +L (error):
> +	b		__syscall_error
> +
> +END (__clone3)
> +
> +/* Load up the arguments to the function.  Put this block of code in
> +   its own function so that we can terminate the stack trace with our
> +   debug info.  */
> +ENTRY (__thread_start3)
> +L (thread_start3):
> +
> +/* Terminate call stack by noting ra is undefined.  Use a dummy
> +   .cfi_label to force starting the FDE.  */
> +	.cfi_label .Ldummy
> +	cfi_undefined (1)
> +
> +	/* Align stack to 16.  */
> +	BSTRINS		sp, zero, 3, 0
> +
> +	/* Set up arguments for the function call.  */
> +	move		a0, a3		/* Argument.  */
> +	jirl		ra, a2, 0	/* Call function.  */
> +
> +	/* Call exit with the function's return value.  */
> +	LI		a7, __NR_exit
> +	syscall		0
> +
> +	END (__thread_start3)
> +
> +libc_hidden_def (__clone3)
> +weak_alias (__clone3, clone3)
> diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.S b/sysdeps/unix/sysv/linux/loongarch/sysdep.S
> new file mode 100644
> index 0000000000..a4db2a97b5
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.S
> @@ -0,0 +1,53 @@
> +/* syscall error handlers
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <sysdep.h>
> +
> +#if IS_IN (libc)
> +# define errno __libc_errno
> +#endif
> +
> +ENTRY (__syscall_error)
> +/* Fall through to __syscall_set_errno */
> +END (__syscall_error)
> +
> +/* Non-standard calling convention: argument in a0, return address in t0,
> +   and clobber only t1.
> + */
> +ENTRY (__syscall_set_errno)
> +
> +/* We got here because a0 < 0, but only codes in the range [-4095, -1]
> +   represent errors.  Otherwise, just return the result normally.
> + */
> +	li.d		t1, -4096
> +	bgeu		t1, a0, L (out)
> +	sub.w		a0, zero, a0
> +#if RTLD_PRIVATE_ERRNO
> +	la		t1, rtld_errno
> +#elif defined(__PIC__)
> +	la.tls.ie	t1, errno
> +	add.d		t1, tp, t1
> +#else
> +	la.tls.le	t1, errno
> +	add.d		t1, tp, t1
> +#endif
> +	st.w		a0, t1, 0
> +	li.d		a0, -1
> +L (out):
> +	ret
> +END (__syscall_set_errno)
> diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> new file mode 100644
> index 0000000000..c586df819c
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> @@ -0,0 +1,320 @@
> +/* Assembly macros for LoongArch.
> +   Copyright (C) 2022 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 _LINUX_LOONGARCH_SYSDEP_H
> +#define _LINUX_LOONGARCH_SYSDEP_H 1
> +
> +#include <sysdeps/unix/sysv/linux/generic/sysdep.h>
> +#include <tls.h>
> +
> +#ifdef __ASSEMBLER__
> +
> +#include <sys/asm.h>
> +#define ret jirl zero, ra, 0
> +#define L(label) .L##label
> +
> +/* Performs a system call, handling errors by setting errno.  Linux indicates
> +   errors by setting a0 to a value between -1 and -4095.  */
> +#undef PSEUDO
> +#define PSEUDO(name, syscall_name, args) \
> +  ENTRY (name); \
> +  li.d a7, SYS_ify (syscall_name); \
> +  syscall 0; \
> +  li.d a7, -4096; \
> +  bltu a7, a0, .Lsyscall_error##name;
> +
> +#undef PSEUDO_END
> +#define PSEUDO_END(sym) \
> +  SYSCALL_ERROR_HANDLER (sym); \
> +  ret; \
> +  END (sym);
> +
> +#if !IS_IN(libc)
> +#if RTLD_PRIVATE_ERRNO
> +
> +#define SYSCALL_ERROR_HANDLER(name) \
> +  .Lsyscall_error##name : la t0, rtld_errno; \
> +  sub.w a0, zero, a0; \
> +  st.w a0, t0, 0; \
> +  li.d a0, -1;
> +
> +#else
> +
> +#define SYSCALL_ERROR_HANDLER(name) \
> +  .Lsyscall_error##name : la.tls.ie t0, errno; \
> +  add.d t0, tp, t0; \
> +  sub.w a0, zero, a0; \
> +  st.w a0, t0, 0; \
> +  li.d a0, -1;
> +
> +#endif
> +#else
> +
> +#define SYSCALL_ERROR_HANDLER(name) .Lsyscall_error##name : b __syscall_error;
> +
> +#endif
> +
> +/* Performs a system call, not setting errno.  */
> +#undef PSEUDO_NEORRNO
> +#define PSEUDO_NOERRNO(name, syscall_name, args) \
> +  ENTRY (name); \
> +  li.d a7, SYS_ify (syscall_name); \
> +  syscall 0;
> +
> +#undef PSEUDO_END_NOERRNO
> +#define PSEUDO_END_NOERRNO(name) END (name);
> +
> +#undef ret_NOERRNO
> +#define ret_NOERRNO ret
> +
> +/* Perfroms a system call, returning the error code.  */
> +#undef PSEUDO_ERRVAL
> +#define PSEUDO_ERRVAL(name, syscall_name, args) \
> +  PSEUDO_NOERRNO (name, syscall_name, args); \
> +  slli.d a0, a0, 32; \
> +  srai.d a0, a0, 32; /* sign_ext */ \
> +  sub.d a0, zero, a0;
> +
> +#undef PSEUDO_END_ERRVAL
> +#define PSEUDO_END_ERRVAL(name) END (name);
> +
> +#undef ret_ERRVAL
> +#define ret_ERRVAL ret
> +
> +#endif /* __ASSEMBLER__ */
> +
> +/* In order to get __set_errno() definition in INLINE_SYSCALL.  */
> +#ifndef __ASSEMBLER__
> +#include <errno.h>
> +#endif
> +
> +#include <sysdeps/unix/sysdep.h>
> +
> +#undef SYS_ify
> +#define SYS_ify(syscall_name) __NR_##syscall_name
> +
> +#ifndef __ASSEMBLER__
> +
> +#define VDSO_NAME "LINUX_2.6"
> +#define VDSO_HASH 61765110
> +
> +/* List of system calls which are supported as vsyscalls.  */
> +#define HAVE_CLOCK_GETRES64_VSYSCALL "__vdso_clock_getres"
> +#define HAVE_CLOCK_GETTIME64_VSYSCALL "__vdso_clock_gettime"
> +#define HAVE_GETCPU_VSYSCALL "__vdso_getcpu"
> +
> +#define HAVE_CLONE3_WRAPPER 1
> +
> +#define INTERNAL_SYSCALL(name, nr, args...) \
> +  internal_syscall##nr (SYS_ify (name), args)
> +
> +#define INTERNAL_SYSCALL_NCS(number, nr, args...) \
> +  internal_syscall##nr (number, args)
> +
> +#define internal_syscall0(number, dummy...) \
> +  ({ \
> +    long int _sys_result; \
> +\
> +    { \
> +      register long int __a7 asm ("$a7") = number; \
> +      register long int __a0 asm ("$a0"); \
> +      __asm__ volatile ("syscall 0\n\t" \
> +		       : "=r"(__a0) \
> +		       : "r"(__a7) \
> +		       : __SYSCALL_CLOBBERS); \
> +      _sys_result = __a0; \
> +    } \
> +    _sys_result; \
> +  })
> +
> +#define internal_syscall1(number, arg0) \
> +  ({ \
> +    long int _sys_result; \
> +\
> +    { \
> +      long int _arg0 = (long int) (arg0); \
> +      register long int __a7 asm ("$a7") = number; \
> +      register long int __a0 asm ("$a0") = _arg0; \
> +      __asm__ volatile ("syscall 0\n\t" \
> +		       : "+r"(__a0) \
> +		       : "r"(__a7) \
> +		       : __SYSCALL_CLOBBERS); \
> +      _sys_result = __a0; \
> +    } \
> +    _sys_result; \
> +  })
> +
> +#define internal_syscall2(number, arg0, arg1) \
> +  ({ \
> +    long int _sys_result; \
> +\
> +    { \
> +      long int _arg0 = (long int) (arg0); \
> +      long int _arg1 = (long int) (arg1); \
> +      register long int __a7 asm ("$a7") = number; \
> +      register long int __a0 asm ("$a0") = _arg0; \
> +      register long int __a1 asm ("$a1") = _arg1; \
> +      __asm__ volatile ("syscall 0\n\t" \
> +		       : "+r"(__a0) \
> +		       : "r"(__a7), "r"(__a1) \
> +		       : __SYSCALL_CLOBBERS); \
> +      _sys_result = __a0; \
> +    } \
> +    _sys_result; \
> +  })
> +
> +#define internal_syscall3(number, arg0, arg1, arg2) \
> +  ({ \
> +    long int _sys_result; \
> +\
> +    { \
> +      long int _arg0 = (long int) (arg0); \
> +      long int _arg1 = (long int) (arg1); \
> +      long int _arg2 = (long int) (arg2); \
> +      register long int __a7 asm ("$a7") = number; \
> +      register long int __a0 asm ("$a0") = _arg0; \
> +      register long int __a1 asm ("$a1") = _arg1; \
> +      register long int __a2 asm ("$a2") = _arg2; \
> +      __asm__ volatile ("syscall 0\n\t" \
> +		       : "+r"(__a0) \
> +		       : "r"(__a7), "r"(__a1), "r"(__a2) \
> +		       : __SYSCALL_CLOBBERS); \
> +      _sys_result = __a0; \
> +    } \
> +    _sys_result; \
> +  })
> +
> +#define internal_syscall4(number, arg0, arg1, arg2, arg3) \
> +  ({ \
> +    long int _sys_result; \
> +\
> +    { \
> +      long int _arg0 = (long int) (arg0); \
> +      long int _arg1 = (long int) (arg1); \
> +      long int _arg2 = (long int) (arg2); \
> +      long int _arg3 = (long int) (arg3); \
> +      register long int __a7 asm ("$a7") = number; \
> +      register long int __a0 asm ("$a0") = _arg0; \
> +      register long int __a1 asm ("$a1") = _arg1; \
> +      register long int __a2 asm ("$a2") = _arg2; \
> +      register long int __a3 asm ("$a3") = _arg3; \
> +      __asm__ volatile ("syscall 0\n\t" \
> +		       : "+r"(__a0) \
> +		       : "r"(__a7), "r"(__a1), "r"(__a2), "r"(__a3) \
> +		       : __SYSCALL_CLOBBERS); \
> +      _sys_result = __a0; \
> +    } \
> +    _sys_result; \
> +  })
> +
> +#define internal_syscall5(number, arg0, arg1, arg2, arg3, arg4) \
> +  ({ \
> +    long int _sys_result; \
> +\
> +    { \
> +      long int _arg0 = (long int) (arg0); \
> +      long int _arg1 = (long int) (arg1); \
> +      long int _arg2 = (long int) (arg2); \
> +      long int _arg3 = (long int) (arg3); \
> +      long int _arg4 = (long int) (arg4); \
> +      register long int __a7 asm ("$a7") = number; \
> +      register long int __a0 asm ("$a0") = _arg0; \
> +      register long int __a1 asm ("$a1") = _arg1; \
> +      register long int __a2 asm ("$a2") = _arg2; \
> +      register long int __a3 asm ("$a3") = _arg3; \
> +      register long int __a4 asm ("$a4") = _arg4; \
> +      __asm__ volatile ("syscall 0\n\t" \
> +		       : "+r"(__a0) \
> +		       : "r"(__a7), "r"(__a1), "r"(__a2), \
> +			 "r"(__a3), "r"(__a4) \
> +		       : __SYSCALL_CLOBBERS); \
> +      _sys_result = __a0; \
> +    } \
> +    _sys_result; \
> +  })
> +
> +#define internal_syscall6(number, arg0, arg1, arg2, arg3, arg4, arg5) \
> +  ({ \
> +    long int _sys_result; \
> +\
> +    { \
> +      long int _arg0 = (long int) (arg0); \
> +      long int _arg1 = (long int) (arg1); \
> +      long int _arg2 = (long int) (arg2); \
> +      long int _arg3 = (long int) (arg3); \
> +      long int _arg4 = (long int) (arg4); \
> +      long int _arg5 = (long int) (arg5); \
> +      register long int __a7 asm ("$a7") = number; \
> +      register long int __a0 asm ("$a0") = _arg0; \
> +      register long int __a1 asm ("$a1") = _arg1; \
> +      register long int __a2 asm ("$a2") = _arg2; \
> +      register long int __a3 asm ("$a3") = _arg3; \
> +      register long int __a4 asm ("$a4") = _arg4; \
> +      register long int __a5 asm ("$a5") = _arg5; \
> +      __asm__ volatile ("syscall 0\n\t" \
> +		       : "+r"(__a0) \
> +		       : "r"(__a7), "r"(__a1), "r"(__a2), "r"(__a3), \
> +			 "r"(__a4), "r"(__a5) \
> +		       : __SYSCALL_CLOBBERS); \
> +      _sys_result = __a0; \
> +    } \
> +    _sys_result; \
> +  })
> +
> +#define internal_syscall7(number, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \
> +  ({ \
> +    long int _sys_result; \
> +\
> +    { \
> +      long int _arg0 = (long int) (arg0); \
> +      long int _arg1 = (long int) (arg1); \
> +      long int _arg2 = (long int) (arg2); \
> +      long int _arg3 = (long int) (arg3); \
> +      long int _arg4 = (long int) (arg4); \
> +      long int _arg5 = (long int) (arg5); \
> +      long int _arg6 = (long int) (arg6); \
> +      register long int __a7 asm ("$a7") = number; \
> +      register long int __a0 asm ("$a0") = _arg0; \
> +      register long int __a1 asm ("$a1") = _arg1; \
> +      register long int __a2 asm ("$a2") = _arg2; \
> +      register long int __a3 asm ("$a3") = _arg3; \
> +      register long int __a4 asm ("$a4") = _arg4; \
> +      register long int __a5 asm ("$a5") = _arg5; \
> +      register long int __a6 asm ("$a6") = _arg6; \
> +      __asm__ volatile ("syscall 0\n\t" \
> +		       : "+r"(__a0) \
> +		       : "r"(__a7), "r"(__a1), "r"(__a2), "r"(__a3), \
> +			 "r"(__a4), "r"(__a5), "r"(__a6) \
> +		       : __SYSCALL_CLOBBERS); \
> +      _sys_result = __a0; \
> +    } \
> +    _sys_result; \
> +  })
> +
> +#define __SYSCALL_CLOBBERS \
> +  "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8", "memory"
> +
> +extern long int __syscall_error (long int neg_errno);
> +
> +#endif /* ! __ASSEMBLER__ */
> +
> +/* Pointer mangling is not supported.  */
> +#define PTR_MANGLE(var) (void) (var)
> +#define PTR_DEMANGLE(var) (void) (var)
> +
> +#endif /* linux/loongarch/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/loongarch/vfork.S b/sysdeps/unix/sysv/linux/loongarch/vfork.S
> new file mode 100644
> index 0000000000..fcc84e3549
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/vfork.S
> @@ -0,0 +1,50 @@
> +/* vfork for Linux.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <sysdep.h>
> +#define _ERRNO_H  1
> +#include <bits/errno.h>
> +
> +/* Clone the calling process, but without copying the whole address space.
> +   The calling process is suspended until the new process exits or is
> +   replaced by a call to `execve'.  Return -1 for errors, 0 to the new process,
> +   and the process ID of the new process to the old process.  */
> +
> +ENTRY (__vfork)
> +
> +	li.d	a0, 0x4111 /* CLONE_VM | CLONE_VFORK | SIGCHLD */
> +	add.d   a1, zero, sp
> +
> +	/* Do the system call.  */
> +	li.d	a7, __NR_clone
> +	syscall	0
> +
> +	blt	a0, zero ,L (error)
> +
> +	ret
> +
> +L (error):
> +	b	__syscall_error
> +
> +END (__vfork)
> +
> +libc_hidden_def (__vfork)
> +
> +weak_alias (__vfork, vfork)
> +strong_alias (__vfork, __libc_vfork)

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 08/13] LoongArch: Linux ABI
  2022-07-19  1:20 ` [PATCH v7 08/13] LoongArch: Linux ABI caiyinyu
@ 2022-07-20 16:37   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-20 16:37 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

On 18/07/22 22:20, caiyinyu wrote:
> ---
>  sysdeps/loongarch/dl-irel.h                   |  54 ++++++++++
>  sysdeps/loongarch/nptl/pthreaddef.h           |  32 ++++++
>  sysdeps/loongarch/sys/ifunc.h                 |  30 ++++++
>  .../unix/sysv/linux/loongarch/bits/fcntl.h    |  61 +++++++++++
>  .../unix/sysv/linux/loongarch/bits/procfs.h   |  52 +++++++++
>  .../linux/loongarch/bits/pthread_stack_min.h  |  20 ++++
>  .../unix/sysv/linux/loongarch/bits/sigstack.h |  32 ++++++
>  .../unix/sysv/linux/loongarch/getcontext.S    |  59 +++++++++++
>  .../unix/sysv/linux/loongarch/localplt.data   |  12 +++
>  .../unix/sysv/linux/loongarch/makecontext.c   |  81 ++++++++++++++
>  .../unix/sysv/linux/loongarch/setcontext.S    | 100 ++++++++++++++++++
>  .../sysv/linux/loongarch/sigcontextinfo.h     |  32 ++++++
>  .../unix/sysv/linux/loongarch/swapcontext.S   |  95 +++++++++++++++++
>  .../unix/sysv/linux/loongarch/sys/ucontext.h  |  61 +++++++++++
>  sysdeps/unix/sysv/linux/loongarch/sys/user.h  |  42 ++++++++
>  .../sysv/linux/loongarch/ucontext-macros.h    |  32 ++++++
>  .../unix/sysv/linux/loongarch/ucontext_i.sym  |  31 ++++++
>  17 files changed, 826 insertions(+)
>  create mode 100644 sysdeps/loongarch/dl-irel.h
>  create mode 100644 sysdeps/loongarch/nptl/pthreaddef.h
>  create mode 100644 sysdeps/loongarch/sys/ifunc.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/procfs.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/getcontext.S
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/localplt.data
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/makecontext.c
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/setcontext.S
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/swapcontext.S
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/sys/user.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym
> 
> diff --git a/sysdeps/loongarch/dl-irel.h b/sysdeps/loongarch/dl-irel.h
> new file mode 100644
> index 0000000000..4440453f06
> --- /dev/null
> +++ b/sysdeps/loongarch/dl-irel.h
> @@ -0,0 +1,54 @@
> +/* Machine-dependent ELF indirect relocation inline functions.
> +   Copyright (C) 2022 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 _DL_IREL_H
> +#define _DL_IREL_H
> +
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <sys/ifunc.h>
> +
> +#define ELF_MACHINE_IRELA 1
> +
> +static inline ElfW (Addr) __attribute ((always_inline))
> +elf_ifunc_invoke (ElfW (Addr) addr)
> +{
> +  __ifunc_arg_t arg =
> +  {
> +    ._size = sizeof (__ifunc_arg_t),
> +    ._hwcap = GLRO(dl_hwcap),
> +  };
> +  return ((ElfW(Addr) (*) (const __ifunc_arg_t *)) (addr)) (&arg);
> +}
> +
> +static inline void __attribute ((always_inline))
> +elf_irela (const ElfW (Rela) *reloc)
> +{
> +  ElfW (Addr) *const reloc_addr = (void *) reloc->r_offset;
> +  const unsigned long int r_type = ELFW (R_TYPE) (reloc->r_info);
> +
> +  if (__glibc_likely (r_type == R_LARCH_IRELATIVE))
> +    {
> +      ElfW (Addr) value = elf_ifunc_invoke (reloc->r_addend);
> +      *reloc_addr = value;
> +    }
> +  else
> +    __libc_fatal ("Unexpected reloc type in static binary.\n");
> +}
> +
> +#endif /* dl-irel.h */

Ok.

> diff --git a/sysdeps/loongarch/nptl/pthreaddef.h b/sysdeps/loongarch/nptl/pthreaddef.h
> new file mode 100644
> index 0000000000..955566cddc
> --- /dev/null
> +++ b/sysdeps/loongarch/nptl/pthreaddef.h
> @@ -0,0 +1,32 @@
> +/* pthread machine parameter definitions.
> +   Copyright (C) 2022 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/>.  */
> +
> +/* Default stack size.  */
> +#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024)
> +
> +/* Minimum guard size.  */
> +#define ARCH_MIN_GUARD_SIZE 0
> +
> +/* Required stack pointer alignment at beginning.  */
> +#define STACK_ALIGN 16
> +
> +/* Minimal stack size after allocating thread descriptor and guard size.  */
> +#define MINIMAL_REST_STACK 2048
> +
> +/* Location of current stack frame.  */
> +#define CURRENT_STACK_FRAME __builtin_frame_address (0)

Ok.

> diff --git a/sysdeps/loongarch/sys/ifunc.h b/sysdeps/loongarch/sys/ifunc.h
> new file mode 100644
> index 0000000000..461df20c96
> --- /dev/null
> +++ b/sysdeps/loongarch/sys/ifunc.h
> @@ -0,0 +1,30 @@
> +/* Definitions used by LoongArch indirect function resolvers.
> +   Copyright (C) 2022 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_IFUNC_H
> +#define _SYS_IFUNC_H
> +
> +struct __ifunc_arg_t
> +{
> +  unsigned long _size; /* Size of the struct, so it can grow.  */
> +  unsigned long _hwcap;
> +};
> +
> +typedef struct __ifunc_arg_t __ifunc_arg_t;
> +
> +#endif

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h b/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
> new file mode 100644
> index 0000000000..bf1e254234
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
> @@ -0,0 +1,61 @@
> +/* O_*, F_*, FD_* bit values for the generic Linux/LoongArch ABI.
> +   Copyright (C) 2022 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 _FCNTL_H
> +#error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
> +#endif
> +
> +#include <bits/wordsize.h>
> +
> +/* In 64-bit ISA files are always with 64bit off_t and F_*LK64 are the same as
> +   non-64-bit versions.  It will need to be revised for 128-bit.  */
> +#if __WORDSIZE == 64
> +#define __O_LARGEFILE 0
> +
> +#define F_GETLK64 5  /* Get record locking info.  */
> +#define F_SETLK64 6  /* Set record locking info (non-blocking).  */
> +#define F_SETLKW64 7 /* Set record locking info (blocking).  */
> +#endif
> +
> +struct flock
> +{
> +  short int l_type;   /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
> +  short int l_whence; /* Where `l_start' is relative to (like `lseek').  */
> +#ifndef __USE_FILE_OFFSET64
> +  __off_t l_start; /* Offset where the lock begins.  */
> +  __off_t l_len;   /* Size of the locked area; zero means until EOF.  */
> +#else
> +  __off64_t l_start; /* Offset where the lock begins.  */
> +  __off64_t l_len;   /* Size of the locked area; zero means until EOF.  */
> +#endif
> +  __pid_t l_pid; /* Process holding the lock.  */
> +};
> +
> +#ifdef __USE_LARGEFILE64
> +struct flock64
> +{
> +  short int l_type;   /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
> +  short int l_whence; /* Where `l_start' is relative to (like `lseek').  */
> +  __off64_t l_start;  /* Offset where the lock begins.  */
> +  __off64_t l_len;    /* Size of the locked area; zero means until EOF.  */
> +  __pid_t l_pid;      /* Process holding the lock.  */
> +};
> +#endif
> +
> +/* Include generic Linux declarations.  */
> +#include <bits/fcntl-linux.h>

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/procfs.h b/sysdeps/unix/sysv/linux/loongarch/bits/procfs.h
> new file mode 100644
> index 0000000000..2db777b38c
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/bits/procfs.h
> @@ -0,0 +1,52 @@
> +/* Types for registers for sys/procfs.h.
> +   Copyright (C) 2022 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_PROCFS_H
> +# error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
> +#endif
> +
> +/* Type for a general-purpose register.  */
> +typedef __uint64_t elf_greg_t;
> +
> +/* And the whole bunch of them.  We could have used `struct
> +   pt_regs' directly in the typedef, but tradition says that
> +   the register set is an array, which does have some peculiar
> +   semantics, so leave it that way.  */
> +#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof (elf_greg_t))
> +typedef elf_greg_t elf_gregset_t[ELF_NGREG];
> +
> +#define ELF_NFPREG 34 /* 32 FPRs + 8-byte byte-vec for fcc + 4-byte FCR */
> +typedef union
> +{
> +  double d;
> +  float f;
> +} elf_fpreg_t;
> +typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
> +
> +typedef union
> +{
> +  double d[2];
> +  float f[4];
> +} __attribute__ ((__aligned__ (16))) elf_lsxregset_t[32];
> +
> +typedef union
> +{
> +  double d[4];
> +  float f[8];
> +} __attribute__ ((__aligned__ (32))) elf_lasxregset_t[32];

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h b/sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h
> new file mode 100644
> index 0000000000..072c2ade42
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/bits/pthread_stack_min.h
> @@ -0,0 +1,20 @@
> +/* Definition of PTHREAD_STACK_MIN.  LoongArch Linux version.
> +   Copyright (C) 2022 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/>.  */
> +
> +/* Minimum size for a thread.  At least two pages with 64k pages.  */
> +#define PTHREAD_STACK_MIN	131072

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h b/sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h
> new file mode 100644
> index 0000000000..238c1a98e6
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/bits/sigstack.h
> @@ -0,0 +1,32 @@
> +/* sigstack, sigaltstack definitions.
> +   Copyright (C) 2022 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 _BITS_SIGSTACK_H
> +#define _BITS_SIGSTACK_H 1
> +
> +#if !defined _SIGNAL_H && !defined _SYS_UCONTEXT_H
> +# error "Never include this file directly.  Use <signal.h> instead"
> +#endif
> +
> +/* Minimum stack size for a signal handler.  */
> +#define MINSIGSTKSZ	4096
> +
> +/* System default stack size.  */
> +#define SIGSTKSZ	16384
> +
> +#endif /* bits/sigstack.h */
> diff --git a/sysdeps/unix/sysv/linux/l

Ok.

oongarch/getcontext.S b/sysdeps/unix/sysv/linux/loongarch/getcontext.S
> new file mode 100644
> index 0000000000..43b95e9715
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/getcontext.S
> @@ -0,0 +1,59 @@
> +/* Save current context.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include "ucontext-macros.h"
> +
> +/* int getcontext (ucontext_t *ucp) */
> +
> +	.text
> +LEAF (__getcontext)
> +	SAVE_INT_REG (ra,   1, a0)
> +	SAVE_INT_REG (sp,   3, a0)
> +	SAVE_INT_REG (zero, 4, a0) /* return 0 by overwriting a0.  */
> +	SAVE_INT_REG (x,   21, a0)
> +	SAVE_INT_REG (fp,  22, a0)
> +	SAVE_INT_REG (s0,  23, a0)
> +	SAVE_INT_REG (s1,  24, a0)
> +	SAVE_INT_REG (s2,  25, a0)
> +	SAVE_INT_REG (s3,  26, a0)
> +	SAVE_INT_REG (s4,  27, a0)
> +	SAVE_INT_REG (s5,  28, a0)
> +	SAVE_INT_REG (s6,  29, a0)
> +	SAVE_INT_REG (s7,  30, a0)
> +	SAVE_INT_REG (s8,  31, a0)
> +	st.d		ra, a0, MCONTEXT_PC
> +
> +/* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
> +	li.d		a3, _NSIG8
> +	li.d		a2, UCONTEXT_SIGMASK
> +	add.d		a2, a2, a0
> +	ori		a1, zero,0
> +	li.d		a0, SIG_BLOCK
> +
> +	li.d		a7, SYS_ify (rt_sigprocmask)
> +	syscall		0
> +	blt		a0, zero, 99f
> +
> +	jirl		$r0, $r1, 0
> +
> +99:
> +	b		__syscall_error
> +
> +PSEUDO_END (__getcontext)
> +
> +weak_alias (__getcontext, getcontext)

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/localplt.data b/sysdeps/unix/sysv/linux/loongarch/localplt.data
> new file mode 100644
> index 0000000000..817ab2659a
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/localplt.data
> @@ -0,0 +1,12 @@
> +# See scripts/check-localplt.awk for how this file is processed.
> +# PLT use is required for the malloc family and for matherr because
> +# users can define their own functions and have library internals call them.
> +libc.so: calloc
> +libc.so: free
> +libc.so: malloc
> +libc.so: realloc
> +# The TLS-enabled version of these functions is interposed from libc.so.
> +ld.so: _dl_signal_error
> +ld.so: _dl_catch_error
> +ld.so: _dl_signal_exception
> +ld.so: _dl_catch_exception

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/makecontext.c b/sysdeps/unix/sysv/linux/loongarch/makecontext.c
> new file mode 100644
> index 0000000000..94a45bf4ad
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/makecontext.c
> @@ -0,0 +1,81 @@
> +/* Create new context.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include <sysdep.h>
> +#include <sys/asm.h>
> +#include <sys/ucontext.h>
> +#include <stdarg.h>
> +#include <assert.h>
> +
> +void
> +__makecontext (ucontext_t *ucp, void (*func) (void), int argc, long int a0,
> +	       long int a1, long int a2, long int a3, long int a4, ...)
> +{
> +  extern void __start_context (void) attribute_hidden;
> +  unsigned long int *sp;
> +
> +  _Static_assert(LARCH_REG_NARGS == 8,
> +		 "__makecontext assumes 8 argument registers");
> +
> +  /* Set up the stack.  */
> +  sp = (unsigned long int *)
> +       (((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ALMASK);
> +
> +  /* Set up the register context.
> +     ra = s0 = 0, terminating the stack for backtracing purposes.
> +     s1 = the function we must call.
> +     s2 = the subsequent context to run.  */
> +  ucp->uc_mcontext.__gregs[LARCH_REG_RA] = (uintptr_t) 0;
> +  ucp->uc_mcontext.__gregs[LARCH_REG_S0] = (uintptr_t) 0;
> +  ucp->uc_mcontext.__gregs[LARCH_REG_S1] = (uintptr_t) func;
> +  ucp->uc_mcontext.__gregs[LARCH_REG_S2] = (uintptr_t) ucp->uc_link;
> +  ucp->uc_mcontext.__gregs[LARCH_REG_SP] = (uintptr_t) sp;
> +  ucp->uc_mcontext.__pc = (uintptr_t) &__start_context;
> +
> +  /* Put args in a0-a7, then put any remaining args on the stack.  */
> +  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 0] = (uintptr_t) a0;
> +  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 1] = (uintptr_t) a1;
> +  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 2] = (uintptr_t) a2;
> +  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 3] = (uintptr_t) a3;
> +  ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 4] = (uintptr_t) a4;
> +
> +  if (__glibc_unlikely (argc > 5))
> +    {
> +      va_list vl;
> +      va_start (vl, a4);
> +
> +      long int reg_args = argc < LARCH_REG_NARGS ? argc : LARCH_REG_NARGS;
> +      for (long int i = 5; i < reg_args; i++)
> +	ucp->uc_mcontext.__gregs[LARCH_REG_A0 + i] = va_arg (vl, unsigned long int);
> +
> +      long int stack_args = argc - reg_args;
> +      if (stack_args > 0)
> +	{
> +	  sp = (unsigned long int *)
> +	       (((uintptr_t) sp - stack_args * sizeof (long int)) & ALMASK);
> +	  ucp->uc_mcontext.__gregs[LARCH_REG_SP] = (uintptr_t) sp;
> +	  for (long int i = 0; i < stack_args; i++)
> +	    sp[i] = va_arg (vl, unsigned long int);
> +	}
> +
> +      va_end (vl);
> +    }
> +}
> +
> +weak_alias (__makecontext, makecontext)

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/setcontext.S b/sysdeps/unix/sysv/linux/loongarch/setcontext.S
> new file mode 100644
> index 0000000000..7295900149
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/setcontext.S
> @@ -0,0 +1,100 @@
> +/* Set current context.
> +   Copyright (C) 2022 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/>.  */
> +#include "sys/regdef.h"
> +#include "ucontext-macros.h"
> +
> +/*  int __setcontext (const ucontext_t *ucp)
> +
> +  Restores the machine context in UCP and thereby resumes execution
> +  in that context.
> +
> +  This implementation is intended to be used for *synchronous* context
> +  switches only.  Therefore, it does not have to restore anything
> +  other than the PRESERVED state.  */
> +
> +	.text
> +LEAF (__setcontext)
> +
> +	addi.d		sp, sp, -16
> +	st.d		a0, sp, 0	/* Save ucp to stack */
> +
> +/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
> +	li.d		a3, _NSIG8
> +	li.d		a2, 0
> +	li.d		a1, UCONTEXT_SIGMASK
> +	add.d		a1, a1, a0
> +	li.d		a0, SIG_SETMASK
> +
> +	li.d		a7, SYS_ify (rt_sigprocmask)
> +	syscall		0
> +
> +	blt		a0, $r0, 99f
> +
> +	ld.d		t0, sp, 0	/* Load ucp to t0 */
> +	cfi_def_cfa (12, 0)
> +
> +/* Note the contents of argument registers will be random
> +   unless makecontext() has been called.  */
> +	RESTORE_INT_REG(ra,   1, t0)
> +	RESTORE_INT_REG(sp,   3, t0)
> +	RESTORE_INT_REG(a0,   4, t0)
> +	RESTORE_INT_REG(a1,   5, t0)
> +	RESTORE_INT_REG(a2,   6, t0)
> +	RESTORE_INT_REG(a3,   7, t0)
> +	RESTORE_INT_REG(a4,   8, t0)
> +	RESTORE_INT_REG(a5,   9, t0)
> +	RESTORE_INT_REG(a6,  10, t0)
> +	RESTORE_INT_REG(a7,  11, t0)
> +	RESTORE_INT_REG(x,   21, t0)
> +	RESTORE_INT_REG(fp,  22, t0)
> +	RESTORE_INT_REG(s0,  23, t0)
> +	RESTORE_INT_REG(s1,  24, t0)
> +	RESTORE_INT_REG(s2,  25, t0)
> +	RESTORE_INT_REG(s3,  26, t0)
> +	RESTORE_INT_REG(s4,  27, t0)
> +	RESTORE_INT_REG(s5,  28, t0)
> +	RESTORE_INT_REG(s6,  29, t0)
> +	RESTORE_INT_REG(s7,  30, t0)
> +	RESTORE_INT_REG(s8,  31, t0)
> +
> +	ld.d		t1, t0, MCONTEXT_PC
> +	jirl		$r0,t1,0
> +
> +99:
> +	addi.d		sp, sp, 16
> +	b		__syscall_error
> +
> +PSEUDO_END (__setcontext)
> +weak_alias (__setcontext, setcontext)
> +
> +LEAF (__start_context)
> +
> +	/* Terminate call stack by noting ra == 0.  Happily, s0 == 0 here.  */
> +	cfi_register (1, 23)
> +
> +	/* Call the function passed to makecontext.  */
> +	jirl		$r1,s1,0
> +
> +	/* Invoke subsequent context if present, else exit(0).  */
> +	ori		a0, s2, 0
> +	beqz		s2, 1f
> +	bl		__setcontext
> +1:
> +	b		HIDDEN_JUMPTARGET(exit)
> +
> +PSEUDO_END (__start_context)

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h b/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h
> new file mode 100644
> index 0000000000..5e202bc0b4
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h
> @@ -0,0 +1,32 @@
> +/* LoongArch definitions for signal handling calling conventions.
> +   Copyright (C) 2022 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 _SIGCONTEXTINFO_H
> +#define _SIGCONTEXTINFO_H
> +
> +#include <stdint.h>
> +#include <sys/ucontext.h>
> +
> +static inline uintptr_t
> +sigcontext_get_pc (const ucontext_t *ctx)
> +{
> +  return ctx->uc_mcontext.__pc;
> +}
> +
> +#endif

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/swapcontext.S b/sysdeps/unix/sysv/linux/loongarch/swapcontext.S
> new file mode 100644
> index 0000000000..bb22cd2f00
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/swapcontext.S
> @@ -0,0 +1,95 @@
> +/* Save and set current context.
> +   Copyright (C) 2022 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/>.  */
> +
> +#include "ucontext-macros.h"
> +
> +/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
> +
> +LEAF (__swapcontext)
> +	ori		a2, sp, 0		/* Save sp to a2 */
> +	addi.d		sp, sp, -16
> +	st.d		a1, sp, 0
> +	ori		t0, a1, 0
> +
> +	SAVE_INT_REG (ra,   1, a0)
> +	SAVE_INT_REG (a2,   3, a0)		/* Store sp */
> +	SAVE_INT_REG (zero, 4, a0)		/* return 0 by overwriting a0 */
> +	SAVE_INT_REG (x,   21, a0)
> +	SAVE_INT_REG (fp,  22, a0)
> +	SAVE_INT_REG (s0,  23, a0)
> +	SAVE_INT_REG (s1,  24, a0)
> +	SAVE_INT_REG (s2,  25, a0)
> +	SAVE_INT_REG (s3,  26, a0)
> +	SAVE_INT_REG (s4,  27, a0)
> +	SAVE_INT_REG (s5,  28, a0)
> +	SAVE_INT_REG (s6,  29, a0)
> +	SAVE_INT_REG (s7,  30, a0)
> +	SAVE_INT_REG (s8,  31, a0)
> +
> +	st.d		ra, a0, MCONTEXT_PC
> +
> +/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8) */
> +	li.d		a3, _NSIG8
> +	li.d		a2, UCONTEXT_SIGMASK
> +	add.d		a2, a2, a0
> +	li.d		a1, UCONTEXT_SIGMASK
> +	add.d		a1, a1, t0
> +	li.d		a0, SIG_SETMASK
> +
> +	li.d		a7, SYS_ify (rt_sigprocmask)
> +	syscall		0
> +
> +	blt		a0, zero, 99f
> +
> +	ld.d		t0, sp, 0		/* Load a1 to t0 */
> +
> +/* Note the contents of argument registers will be random
> +   unless makecontext() has been called.  */
> +	RESTORE_INT_REG (ra,   1, t0)
> +	RESTORE_INT_REG (sp,   3, t0)
> +	RESTORE_INT_REG (a0,   4, t0)
> +	RESTORE_INT_REG (a1,   5, t0)
> +	RESTORE_INT_REG (a2,   6, t0)
> +	RESTORE_INT_REG (a3,   7, t0)
> +	RESTORE_INT_REG (a4,   8, t0)
> +	RESTORE_INT_REG (a5,   9, t0)
> +	RESTORE_INT_REG (a6,  10, t0)
> +	RESTORE_INT_REG (a7,  11, t0)
> +	RESTORE_INT_REG (x,   21, t0)
> +	RESTORE_INT_REG (fp,  22, t0)
> +	RESTORE_INT_REG (s0,  23, t0)
> +	RESTORE_INT_REG (s1,  24, t0)
> +	RESTORE_INT_REG (s2,  25, t0)
> +	RESTORE_INT_REG (s3,  26, t0)
> +	RESTORE_INT_REG (s4,  27, t0)
> +	RESTORE_INT_REG (s5,  28, t0)
> +	RESTORE_INT_REG (s6,  29, t0)
> +	RESTORE_INT_REG (s7,  30, t0)
> +	RESTORE_INT_REG (s8,  31, t0)
> +
> +	ld.d		t1, t0, MCONTEXT_PC
> +	jirl		$r0, t1, 0
> +
> +
> +99:
> +	addi.d		sp, sp, 16
> +	b		__syscall_error
> +
> +PSEUDO_END (__swapcontext)
> +
> +weak_alias (__swapcontext, swapcontext)

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h b/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
> new file mode 100644
> index 0000000000..e334a45a44
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
> @@ -0,0 +1,61 @@
> +/* struct ucontext definition.
> +   Copyright (C) 2022 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/>.  */
> +
> +/* Don't rely on this, the interface is currently messed up and may need to
> +   be broken to be fixed.  */
> +#ifndef _SYS_UCONTEXT_H
> +#define _SYS_UCONTEXT_H 1
> +
> +#include <features.h>
> +
> +#include <bits/types/sigset_t.h>
> +#include <bits/types/stack_t.h>
> +
> +#ifdef __USE_MISC
> +#define LARCH_NGREG 32
> +
> +#define LARCH_REG_RA 1
> +#define LARCH_REG_SP 3
> +#define LARCH_REG_S0 23
> +#define LARCH_REG_S1 24
> +#define LARCH_REG_A0 4
> +#define LARCH_REG_S2 25
> +#define LARCH_REG_NARGS 8
> +
> +#endif
> +
> +typedef struct mcontext_t
> +{
> +  unsigned long long __pc;
> +  unsigned long long __gregs[32];
> +  unsigned int __flags;
> +  unsigned long long __extcontext[0] __attribute__((__aligned__(16)));
> +} mcontext_t;
> +
> +/* Userlevel context.  */
> +typedef struct ucontext_t
> +{
> +  unsigned long int __uc_flags;
> +  struct ucontext_t *uc_link;
> +  stack_t uc_stack;
> +  sigset_t uc_sigmask;
> +  mcontext_t uc_mcontext;
> +} ucontext_t;
> +
> +#endif /* sys/ucontext.h */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/sys/user.h b/sysdeps/unix/sysv/linux/loongarch/sys/user.h
> new file mode 100644
> index 0000000000..55181de816
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/sys/user.h
> @@ -0,0 +1,42 @@
> +/* struct user_regs_struct definition for LoongArch.
> +   Copyright (C) 2022 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_USER_H
> +#define _SYS_USER_H 1
> +
> +#include <stdint.h>
> +
> +struct user_regs_struct
> +{
> +  /* Saved main processor registers. */
> +  uint64_t regs[32];
> +
> +  /* Saved special registers. */
> +  uint64_t orig_a0;
> +  uint64_t csr_era;
> +  uint64_t csr_badv;
> +  uint64_t reserved[10];
> +};
> +
> +struct user_fp_struct {
> +  uint64_t    fpr[32];
> +  uint64_t    fcc;
> +  uint32_t    fcsr;
> +};
> +
> +#endif /* _SYS_USER_H */

I think it should be ok to use stdint.h types here, although it is not usual
for other ports. AFAIK it is only mainly for GDB.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h b/sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h
> new file mode 100644
> index 0000000000..859eba464b
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/ucontext-macros.h
> @@ -0,0 +1,32 @@
> +/* Macros for ucontext routines.
> +   Copyright (C) 2022 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 _LINUX_LOONGARCH_UCONTEXT_MACROS_H
> +#define _LINUX_LOONGARCH_UCONTEXT_MACROS_H
> +
> +#include <sysdep.h>
> +#include <sys/asm.h>
> +#include "ucontext_i.h"
> +
> +#define SAVE_INT_REG(name, num, base) \
> +  REG_S name, base, ((num) *SZREG + MCONTEXT_GREGS)
> +
> +#define RESTORE_INT_REG(name, num, base) \
> +  REG_L name, base, ((num) *SZREG + MCONTEXT_GREGS)
> +
> +#endif /* _LINUX_LOONGARCH_UCONTEXT_MACROS_H */

OK.

> diff --git a/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym b/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym
> new file mode 100644
> index 0000000000..f27afad56f
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym
> @@ -0,0 +1,31 @@
> +#include <inttypes.h>
> +#include <signal.h>
> +#include <stddef.h>
> +#include <sys/ucontext.h>
> +
> +-- Constants used by the rt_sigprocmask call.
> +
> +SIG_BLOCK
> +SIG_SETMASK
> +
> +_NSIG8				(_NSIG / 8)
> +
> +-- Offsets of the fields in the ucontext_t structure.
> +#define ucontext(member)	offsetof (ucontext_t, member)
> +#define stack(member)		ucontext (uc_stack.member)
> +#define mcontext(member)	ucontext (uc_mcontext.member)
> +
> +UCONTEXT_FLAGS			ucontext (__uc_flags)
> +UCONTEXT_LINK			ucontext (uc_link)
> +UCONTEXT_STACK			ucontext (uc_stack)
> +UCONTEXT_MCONTEXT		ucontext (uc_mcontext)
> +UCONTEXT_SIGMASK		ucontext (uc_sigmask)
> +
> +STACK_SP			stack (ss_sp)
> +STACK_SIZE			stack (ss_size)
> +STACK_FLAGS			stack (ss_flags)
> +
> +MCONTEXT_PC			mcontext (__pc)
> +MCONTEXT_GREGS			mcontext (__gregs)
> +
> +UCONTEXT_SIZE			sizeof (ucontext_t)

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
                   ` (7 preceding siblings ...)
  2022-07-19  1:20 ` [PATCH v7 08/13] LoongArch: Linux ABI caiyinyu
@ 2022-07-20 17:19 ` Adhemerval Zanella Netto
  2022-07-21  2:44   ` caiyinyu
  2022-07-24  9:49 ` WANG Xuerui
  9 siblings, 1 reply; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-20 17:19 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail



On 18/07/22 22:20, caiyinyu wrote:
> Hello, these are LoongArch patches v7, and we really need your futher suggestions:
> 
> There are 6 parts in total.
> 
> 1. HISTORY:
> LoongArch patches v1: https://sourceware.org/pipermail/libc-alpha/2021-August/130262.html
> LoongArch patches v2: https://sourceware.org/pipermail/libc-alpha/2021-December/134811.html
> LoongArch patches v3: https://sourceware.org/pipermail/libc-alpha/2022-April/137888.html
> LoongArch patches v4: https://sourceware.org/pipermail/libc-alpha/2022-May/subject.html
> LoongArch patches v5: https://sourceware.org/pipermail/libc-alpha/2022-June/139262.html
> LoongArch patches v6: https://sourceware.org/pipermail/libc-alpha/2022-July/140446.html
> 
> 2. LoongArch-Doc:  https://github.com/loongson/LoongArch-Documentation
> 
> We add new section: procedure calling convention.
> https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_procedure_calling_convention
> 
> 
> 3. Linux kernel, GCC and Binutils Loongarch parts have been into GNU Open Source community.
> 
> 
> 4. From Adhemerval Zanella Netto:
>> I finished my review for the port and it looks ok in general, however there
>> some pieces that would require a v7:
>>
>>   1. Add R_LARCH_NONE handling on bootstrap, binutils 2.38 does generated it
>>      and from previous discussion it should be considered a missed
>>      optimizations instead of a linker error.
> 
>     R_LARCH_NONE handling has been added on bootstrap.
>>
>>   2. Remove the __loongarch_soft_float parts, since there is no support for
>>      soft floating-point.
> 
>     All __loongarch_soft_float removed.
>>
>>   3. Remove sysdeps/unix/sysv/linux/loongarch/ldconfig.h, this file is not
>>      required.
> 
>     This file has been removed.
>>
>>   4. Some minor style issues.
> 
>     See previous emails.
>     https://sourceware.org/pipermail/libc-alpha/2022-July/thread.html
>>
>>   5. Either remove HAVE_GETTIMEOFDAY_VSYSCALL or add a gettimeofday ifunc
>>      optimization.
> 
>     Removed now.
>>
>> The only part really prevent port inclusion is 1.  I am also assuming ifunc
>> is support (at least you have added support on the Linux ABI part) with
>> binutils 2.38.  If not, you will need to remove support until you fix it on
>> binutils.
>>
>> And also, you need to check and report the test results using the expected
>> defined release branches, using out-of-tree branches are not acceptable for
>> inclusion.
> 
> 5. There are some new changes:

This version looks good to me, everything I have pointed out in previous release
was addressed, build-many-glibcs.py and make check does not trigger any issue,
and some qemu tests show that the generated loader and binaries are corrected
generated.

If you want, I can push it upstream.  Carlos is ok to install it?

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-20 17:19 ` [PATCH v7 00/13] GLIBC LoongArch PATCHES Adhemerval Zanella Netto
@ 2022-07-21  2:44   ` caiyinyu
  0 siblings, 0 replies; 36+ messages in thread
From: caiyinyu @ 2022-07-21  2:44 UTC (permalink / raw)
  To: Adhemerval Zanella Netto, libc-alpha, joseph_myers, carlos, i.swmail


This version looks good to me, everything I have pointed out in previous 
release
was addressed, build-many-glibcs.py and make check does not trigger any 
issue,
and some qemu tests show that the generated loader and binaries are 
corrected
generated.

If you want, I can push it upstream.  Carlos is ok to install it?

-------------------------------------

Very glad to know that you agreed to install Loongarch ports and I have

submitted application for write access to the Loongarch parts of glibc.

Waiting for Carlos' advice.

Thank everyone for their efforts.



在 2022/7/21 上午1:19, Adhemerval Zanella Netto 写道:
>
> On 18/07/22 22:20, caiyinyu wrote:
>> Hello, these are LoongArch patches v7, and we really need your futher suggestions:
>>
>> There are 6 parts in total.
>>
>> 1. HISTORY:
>> LoongArch patches v1: https://sourceware.org/pipermail/libc-alpha/2021-August/130262.html
>> LoongArch patches v2: https://sourceware.org/pipermail/libc-alpha/2021-December/134811.html
>> LoongArch patches v3: https://sourceware.org/pipermail/libc-alpha/2022-April/137888.html
>> LoongArch patches v4: https://sourceware.org/pipermail/libc-alpha/2022-May/subject.html
>> LoongArch patches v5: https://sourceware.org/pipermail/libc-alpha/2022-June/139262.html
>> LoongArch patches v6: https://sourceware.org/pipermail/libc-alpha/2022-July/140446.html
>>
>> 2. LoongArch-Doc:  https://github.com/loongson/LoongArch-Documentation
>>
>> We add new section: procedure calling convention.
>> https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_procedure_calling_convention
>>
>>
>> 3. Linux kernel, GCC and Binutils Loongarch parts have been into GNU Open Source community.
>>
>>
>> 4. From Adhemerval Zanella Netto:
>>> I finished my review for the port and it looks ok in general, however there
>>> some pieces that would require a v7:
>>>
>>>    1. Add R_LARCH_NONE handling on bootstrap, binutils 2.38 does generated it
>>>       and from previous discussion it should be considered a missed
>>>       optimizations instead of a linker error.
>>      R_LARCH_NONE handling has been added on bootstrap.
>>>    2. Remove the __loongarch_soft_float parts, since there is no support for
>>>       soft floating-point.
>>      All __loongarch_soft_float removed.
>>>    3. Remove sysdeps/unix/sysv/linux/loongarch/ldconfig.h, this file is not
>>>       required.
>>      This file has been removed.
>>>    4. Some minor style issues.
>>      See previous emails.
>>      https://sourceware.org/pipermail/libc-alpha/2022-July/thread.html
>>>    5. Either remove HAVE_GETTIMEOFDAY_VSYSCALL or add a gettimeofday ifunc
>>>       optimization.
>>      Removed now.
>>> The only part really prevent port inclusion is 1.  I am also assuming ifunc
>>> is support (at least you have added support on the Linux ABI part) with
>>> binutils 2.38.  If not, you will need to remove support until you fix it on
>>> binutils.
>>>
>>> And also, you need to check and report the test results using the expected
>>> defined release branches, using out-of-tree branches are not acceptable for
>>> inclusion.
>> 5. There are some new changes:
> This version looks good to me, everything I have pointed out in previous release
> was addressed, build-many-glibcs.py and make check does not trigger any issue,
> and some qemu tests show that the generated loader and binaries are corrected
> generated.
>
> If you want, I can push it upstream.  Carlos is ok to install it?


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 01/13] LoongArch: Add LoongArch entries to config.h.in
  2022-07-19  1:20 ` [PATCH v7 01/13] LoongArch: Add LoongArch entries to config.h.in caiyinyu
@ 2022-07-21 21:02   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-21 21:02 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail

LGTM, as for v6.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

On 18/07/22 22:20, caiyinyu wrote:
> ---
>  config.h.in | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/config.h.in b/config.h.in
> index bf316439a0..43d32518ab 100644
> --- a/config.h.in
> +++ b/config.h.in
> @@ -132,6 +132,12 @@
>  /* RISC-V floating-point ABI for ld.so.  */
>  #undef RISCV_ABI_FLEN
>  
> +/* LOONGARCH integer ABI for ld.so.  */
> +#undef LOONGARCH_ABI_GRLEN
> +
> +/* LOONGARCH floating-point ABI for ld.so.  */
> +#undef LOONGARCH_ABI_FRLEN
> +
>  /* Linux specific: minimum supported kernel version.  */
>  #undef	__LINUX_KERNEL_VERSION
>  

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 02/13] LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py
  2022-07-19  1:20 ` [PATCH v7 02/13] LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py caiyinyu
@ 2022-07-21 21:02   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-21 21:02 UTC (permalink / raw)
  To: caiyinyu, libc-alpha, joseph_myers, carlos, i.swmail

LGTM, as for v6.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>


On 18/07/22 22:20, caiyinyu wrote:
> ---
>  elf/elf.h           | 68 ++++++++++++++++++++++++++++++++++++++++++++-
>  scripts/glibcelf.py |  3 +-
>  2 files changed, 69 insertions(+), 2 deletions(-)
> 
> diff --git a/elf/elf.h b/elf/elf.h
> index 2b5c2c5fb6..02a1b3f52f 100644
> --- a/elf/elf.h
> +++ b/elf/elf.h
> @@ -358,8 +358,9 @@ typedef struct
>  
>  #define EM_BPF		247	/* Linux BPF -- in-kernel virtual machine */
>  #define EM_CSKY		252     /* C-SKY */
> +#define EM_LOONGARCH	258	/* LoongArch */
>  
> -#define EM_NUM		253
> +#define EM_NUM		259
>  
>  /* Old spellings/synonyms.  */
>  
> @@ -4083,6 +4084,71 @@ enum
>  #define R_NDS32_TLS_TPOFF	102
>  #define R_NDS32_TLS_DESC	119
>  
> +/* LoongArch ELF Flags */
> +#define EF_LARCH_ABI    	0x07
> +#define EF_LARCH_ABI_LP64D	0x03
> +
> +/* LoongArch specific dynamic relocations */
> +#define R_LARCH_NONE		0
> +#define R_LARCH_32		1
> +#define R_LARCH_64		2
> +#define R_LARCH_RELATIVE	3
> +#define R_LARCH_COPY		4
> +#define R_LARCH_JUMP_SLOT	5
> +#define R_LARCH_TLS_DTPMOD32	6
> +#define R_LARCH_TLS_DTPMOD64	7
> +#define R_LARCH_TLS_DTPREL32	8
> +#define R_LARCH_TLS_DTPREL64	9
> +#define R_LARCH_TLS_TPREL32	10
> +#define R_LARCH_TLS_TPREL64	11
> +#define R_LARCH_IRELATIVE	12
> +
> +/* Reserved for future relocs that the dynamic linker must understand.  */
> +
> +/* used by the static linker for relocating .text.  */
> +#define R_LARCH_MARK_LA  20
> +#define R_LARCH_MARK_PCREL  21
> +#define R_LARCH_SOP_PUSH_PCREL  22
> +#define R_LARCH_SOP_PUSH_ABSOLUTE  23
> +#define R_LARCH_SOP_PUSH_DUP  24
> +#define R_LARCH_SOP_PUSH_GPREL  25
> +#define R_LARCH_SOP_PUSH_TLS_TPREL  26
> +#define R_LARCH_SOP_PUSH_TLS_GOT  27
> +#define R_LARCH_SOP_PUSH_TLS_GD  28
> +#define R_LARCH_SOP_PUSH_PLT_PCREL  29
> +#define R_LARCH_SOP_ASSERT  30
> +#define R_LARCH_SOP_NOT  31
> +#define R_LARCH_SOP_SUB  32
> +#define R_LARCH_SOP_SL  33
> +#define R_LARCH_SOP_SR  34
> +#define R_LARCH_SOP_ADD  35
> +#define R_LARCH_SOP_AND  36
> +#define R_LARCH_SOP_IF_ELSE  37
> +#define R_LARCH_SOP_POP_32_S_10_5  38
> +#define R_LARCH_SOP_POP_32_U_10_12  39
> +#define R_LARCH_SOP_POP_32_S_10_12  40
> +#define R_LARCH_SOP_POP_32_S_10_16  41
> +#define R_LARCH_SOP_POP_32_S_10_16_S2  42
> +#define R_LARCH_SOP_POP_32_S_5_20  43
> +#define R_LARCH_SOP_POP_32_S_0_5_10_16_S2  44
> +#define R_LARCH_SOP_POP_32_S_0_10_10_16_S2  45
> +#define R_LARCH_SOP_POP_32_U  46
> +
> +/* used by the static linker for relocating non .text.  */
> +#define R_LARCH_ADD8  47
> +#define R_LARCH_ADD16  48
> +#define R_LARCH_ADD24  49
> +#define R_LARCH_ADD32  50
> +#define R_LARCH_ADD64  51
> +#define R_LARCH_SUB8  52
> +#define R_LARCH_SUB16  53
> +#define R_LARCH_SUB24  54
> +#define R_LARCH_SUB32  55
> +#define R_LARCH_SUB64  56
> +#define R_LARCH_GNU_VTINHERIT  57
> +#define R_LARCH_GNU_VTENTRY  58
> +
> +
>  /* ARCompact/ARCv2 specific relocs.  */
>  #define R_ARC_NONE		0x0
>  #define R_ARC_8			0x1
> diff --git a/scripts/glibcelf.py b/scripts/glibcelf.py
> index 47f95d07ba..de0509130e 100644
> --- a/scripts/glibcelf.py
> +++ b/scripts/glibcelf.py
> @@ -252,7 +252,8 @@ class Machine(_OpenIntEnum):
>      EM_RISCV = 243
>      EM_BPF = 247
>      EM_CSKY = 252
> -    EM_NUM = 253
> +    EM_LOONGARCH = 258
> +    EM_NUM = 259
>      EM_ALPHA = 0x9026
>  
>  class Et(_OpenIntEnum):

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
                   ` (8 preceding siblings ...)
  2022-07-20 17:19 ` [PATCH v7 00/13] GLIBC LoongArch PATCHES Adhemerval Zanella Netto
@ 2022-07-24  9:49 ` WANG Xuerui
  2022-07-24 11:51   ` Xi Ruoyao
  2022-07-25 13:27   ` Adhemerval Zanella Netto
  9 siblings, 2 replies; 36+ messages in thread
From: WANG Xuerui @ 2022-07-24  9:49 UTC (permalink / raw)
  To: caiyinyu, adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail

Hi,

On 7/19/22 09:20, caiyinyu wrote:
> <snip>
> 6. Test result: all passed (ifunc disable).
>
> Test with:
>    Linux-5.19-rc4, Binutils-2.38, and GCC-12.1.
>    glibc: https://github.com/loongson/glibc/tree/loongarch_2_36_upstream_v7
>
> Result (ifunc disable):
> XPASS: conform/UNIX98/ndbm.h/linknamespace
> XPASS: conform/XOPEN2K/ndbm.h/linknamespace
> XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
> XPASS: conform/XPG42/ndbm.h/linknamespace
> UNSUPPORTED: crypt/cert
> UNSUPPORTED: elf/tst-env-setuid
> UNSUPPORTED: elf/tst-env-setuid-tunables
> XPASS: elf/tst-protected1a
> XPASS: elf/tst-protected1b
> UNSUPPORTED: elf/tst-valgrind-smoke
> UNSUPPORTED: misc/tst-adjtimex
> UNSUPPORTED: misc/tst-clock_adjtime
> UNSUPPORTED: misc/tst-ntp_adjtime
> UNSUPPORTED: misc/tst-pkey
> UNSUPPORTED: misc/tst-rseq
> UNSUPPORTED: misc/tst-rseq-disable
> UNSUPPORTED: nptl/test-cond-printers
> UNSUPPORTED: nptl/test-condattr-printers
> UNSUPPORTED: nptl/test-mutex-printers
> UNSUPPORTED: nptl/test-mutexattr-printers
> UNSUPPORTED: nptl/test-rwlock-printers
> UNSUPPORTED: nptl/test-rwlockattr-printers
> UNSUPPORTED: nptl/tst-pthread-gdb-attach
> UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
> UNSUPPORTED: nptl/tst-rseq-nptl
> UNSUPPORTED: stdlib/tst-secure-getenv
> UNSUPPORTED: time/tst-clock_settime
> UNSUPPORTED: time/tst-settimeofday
> Summary of test results:
>     4535 PASS
>       22 UNSUPPORTED
>       12 XFAIL
>        6 XPASS

Thanks for your effort these days. I ran the test on Gentoo and this is 
what I have found out:

UNSUPPORTED: crypt/cert
FAIL: elf/check-abi-libc
FAIL: elf/ifuncmain1
FAIL: elf/ifuncmain1pic
FAIL: elf/ifuncmain1pie
FAIL: elf/ifuncmain1staticpic
FAIL: elf/ifuncmain1staticpie
FAIL: elf/ifuncmain1vis
FAIL: elf/ifuncmain1vispic
FAIL: elf/ifuncmain1vispie
FAIL: elf/ifuncmain2
FAIL: elf/ifuncmain2pic
FAIL: elf/ifuncmain3
FAIL: elf/ifuncmain4
FAIL: elf/ifuncmain5staticpic
FAIL: elf/ifuncmain6pie
FAIL: elf/ifuncmain7
FAIL: elf/ifuncmain7pic
FAIL: elf/ifuncmain7pie
FAIL: elf/ifuncmain9
FAIL: elf/ifuncmain9pic
FAIL: elf/ifuncmain9pie
UNSUPPORTED: elf/tst-env-setuid
UNSUPPORTED: elf/tst-env-setuid-tunables
FAIL: elf/tst-glibc-hwcaps-prepend-cache
FAIL: elf/tst-ifunc-textrel
FAIL: elf/tst-ldconfig-ld_so_conf-update
XPASS: elf/tst-protected1a
XPASS: elf/tst-protected1b
UNSUPPORTED: elf/tst-valgrind-smoke
FAIL: malloc/tst-free-errno-malloc-hugetlb1
UNSUPPORTED: misc/tst-adjtimex
UNSUPPORTED: misc/tst-clock_adjtime
UNSUPPORTED: misc/tst-ntp_adjtime
UNSUPPORTED: misc/tst-pkey
UNSUPPORTED: misc/tst-rseq
UNSUPPORTED: misc/tst-rseq-disable
FAIL: nptl/tst-pthread-gdb-attach
FAIL: nptl/tst-pthread-gdb-attach-static
UNSUPPORTED: nptl/tst-rseq-nptl
FAIL: nss/tst-nss-files-hosts-long
UNSUPPORTED: resolv/tst-resolv-ai_idn
UNSUPPORTED: resolv/tst-resolv-ai_idn-latin1
UNSUPPORTED: stdlib/tst-secure-getenv
UNSUPPORTED: time/tst-clock_settime
UNSUPPORTED: time/tst-settimeofday

Of these, the ifunc failures are "expected" by you, the 
elf/check-abi-libc diff is trivial (maybe you just didn't rebase as 
frequently):

--- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 2022-07-23 
14:45:57.490029442 +0800
+++ /home/xenon/src/glibc/build/libc.symlist    2022-07-24 
13:44:10.416642655 +0800
@@ -496 +496 @@ GLIBC_2.36 _mcount F
-GLIBC_2.36 _nl_default_dirname D 0x12
+GLIBC_2.36 _nl_default_dirname D 0x17
@@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
+GLIBC_2.36 arc4random F
+GLIBC_2.36 arc4random_buf F
+GLIBC_2.36 arc4random_uniform F

The others may need some love. Of course they're possibly because of my 
particular environment (Gentoo is a little bit different than "ordinary" 
distros like Debian/Fedora, and I already have to symlink the 
libgcc_s.so and libstdc++.so to pass the nptl tests at all).

Coming to code quality, there are obviously warts present, like the 
lingering uses of the name "x" for $r21 and apparent lack of assembly 
pseudo-insn sugar usages (e.g. no "move a, b" but always "or a, b, 
zero"; the code must be directly descended from an extremely early time 
when the assembler didn't have such support), but at this point these 
cosmetic concerns are better fixed after 2.36 to minimize churn prior to 
release. At a quick glance the ABI is looking good. (There is a certain 
"__x" in bits/setjmp.h meant to refer to r21, but __jmp_buf is not 
public API so I think we're safe here.)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-24  9:49 ` WANG Xuerui
@ 2022-07-24 11:51   ` Xi Ruoyao
  2022-07-24 12:02     ` WANG Xuerui
  2022-07-25  1:58     ` 刘振松
  2022-07-25 13:27   ` Adhemerval Zanella Netto
  1 sibling, 2 replies; 36+ messages in thread
From: Xi Ruoyao @ 2022-07-24 11:51 UTC (permalink / raw)
  To: WANG Xuerui, caiyinyu, adhemerval.zanella, libc-alpha,
	joseph_myers, carlos
  Cc: liuzhensong

[-- Attachment #1: Type: text/plain, Size: 3553 bytes --]

On Sun, 2022-07-24 at 17:49 +0800, WANG Xuerui wrote:

> Of these, the ifunc failures are "expected" by you, the 
> elf/check-abi-libc diff is trivial (maybe you just didn't rebase as 
> frequently):
> 
> --- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 2022-07-23 
> 14:45:57.490029442 +0800
> +++ /home/xenon/src/glibc/build/libc.symlist    2022-07-24 
> 13:44:10.416642655 +0800
> @@ -496 +496 @@ GLIBC_2.36 _mcount F
> -GLIBC_2.36 _nl_default_dirname D 0x12
> +GLIBC_2.36 _nl_default_dirname D 0x17
> @@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
> +GLIBC_2.36 arc4random F
> +GLIBC_2.36 arc4random_buf F
> +GLIBC_2.36 arc4random_uniform F

arc4random is just merged two days ago.

> The others may need some love. Of course they're possibly because of my 
> particular environment (Gentoo is a little bit different than "ordinary" 
> distros like Debian/Fedora, and I already have to symlink the 
> libgcc_s.so and libstdc++.so to pass the nptl tests at all)

I can tell tst-nss-files-hosts-long is most likely PR24816.  For the
others I'm not sure.

By "symlink libgcc_s.so and libstdc++.so" I guess you are running tests
in a temporary system ("Gentoo stage 1" IIRC).  In LFS we also get some
additional test failures in the temporary system [1] so it's better to
rerun the tests in a full system.

(In earlier LFS releases we also needed to symlink libgcc_s.so and
libstdc++.so for glibc tests, but it's no longer needed now thanks to a
major refactoring [2].)

[1]: https://www.linuxfromscratch.org/lfs/view/systemd/chapter08/glibc.html
[2]: https://lists.linuxfromscratch.org/sympa/arc/lfs-dev/2020-05/msg00000.html

My test result on LFS (fully built) with a patched ld seems clean.  The
patch is originally published at
https://sourceware.org/pipermail/binutils/2022-July/121852.html, but
it's in a large series introducing new relocation types.  I managed to
rebased and adjusted the patch so it can be applied individually for
binutils-gdb master branch.  The patch is attached in this mail.

+Zhensong: is there any possibility to merge this patch for binutils
master and 2.39 release branch (including 2.38 release branch would be
even better) so at least glibc ifunc tests will be happy?

XPASS: conform/UNIX98/ndbm.h/linknamespace
XPASS: conform/XOPEN2K/ndbm.h/linknamespace
XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
XPASS: conform/XPG42/ndbm.h/linknamespace
UNSUPPORTED: crypt/cert
FAIL: elf/check-abi-libc
UNSUPPORTED: elf/tst-env-setuid
UNSUPPORTED: elf/tst-env-setuid-tunables
XPASS: elf/tst-protected1a
XPASS: elf/tst-protected1b
UNSUPPORTED: elf/tst-valgrind-smoke
UNSUPPORTED: misc/tst-adjtimex
UNSUPPORTED: misc/tst-clock_adjtime
UNSUPPORTED: misc/tst-ntp_adjtime
UNSUPPORTED: misc/tst-pkey
UNSUPPORTED: misc/tst-rseq
UNSUPPORTED: misc/tst-rseq-disable
UNSUPPORTED: nptl/test-cond-printers
UNSUPPORTED: nptl/test-condattr-printers
UNSUPPORTED: nptl/test-mutex-printers
UNSUPPORTED: nptl/test-mutexattr-printers
UNSUPPORTED: nptl/test-rwlock-printers
UNSUPPORTED: nptl/test-rwlockattr-printers
UNSUPPORTED: nptl/tst-pthread-gdb-attach
UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
UNSUPPORTED: nptl/tst-rseq-nptl
UNSUPPORTED: stdlib/tst-secure-getenv
UNSUPPORTED: time/tst-clock_settime
UNSUPPORTED: time/tst-settimeofday
Summary of test results:
      1 FAIL
   4576 PASS
     22 UNSUPPORTED
     12 XFAIL
      6 XPASS


-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

[-- Attachment #2: binutils-loongarch-ifunc.patch --]
[-- Type: text/x-patch, Size: 14154 bytes --]

From 2928edd4da284bff42c770cb29dbf94f83e7f69c Mon Sep 17 00:00:00 2001
From: liuzhensong <liuzhensong@loongson.cn>
Date: Fri, 15 Jul 2022 16:07:48 +0800
Subject: [PATCH] LoongArch: Move ifunc info to rela.dyn from rela.plt

Delete R_LARCH_IRELATIVE from dynamic loader (glibc ld.so) when
loading lazy function (rela.plt section).

In dynamic programs, move ifunc dynamic relocate info to section
srelgot from srelplt.
---
 bfd/elfnn-loongarch.c | 338 ++++++++++++++++++++++++++++++++++++++----
 1 file changed, 311 insertions(+), 27 deletions(-)

diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 5b44901b9e0..7c0b88f22de 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -1196,6 +1196,259 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   return true;
 }
 
+/* Based function _bfd_elf_allocate_ifunc_dyn_relocs.
+   For local def and ref ifunc,
+   dynamic relocations are stored in
+   1.  rel[a].irelifunc section in PIC object.
+   2.  rel[a].srelgot section in dynamic executable.
+   3.  rel[a].irelplt section in static executable.
+   Change ifunc dynamic info from srelplt to srelgot.
+   In loader, remove R_LARCH_IRELACTIVE from rela lazy in ld.so.  */
+
+static bool
+local_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
+				    struct elf_link_hash_entry *h,
+				    struct elf_dyn_relocs **head,
+				    unsigned int plt_entry_size,
+				    unsigned int plt_header_size,
+				    unsigned int got_entry_size,
+				    bool avoid_plt)
+{
+  asection *plt, *gotplt, *relplt;
+  struct elf_dyn_relocs *p;
+  unsigned int sizeof_reloc;
+  const struct elf_backend_data *bed;
+  struct elf_link_hash_table *htab;
+  /* If AVOID_PLT is TRUE, don't use PLT if possible.  */
+  bool use_plt = !avoid_plt || h->plt.refcount > 0;
+  bool need_dynreloc = !use_plt || bfd_link_pic (info);
+
+  /* When a PIC object references a STT_GNU_IFUNC symbol defined
+     in executable or it isn't referenced via PLT, the address of
+     the resolved function may be used.  But in non-PIC executable,
+     the address of its plt slot may be used.  Pointer equality may
+     not work correctly.  PIE or non-PLT reference should be used if
+     pointer equality is required here.
+
+     If STT_GNU_IFUNC symbol is defined in position-dependent executable,
+     backend should change it to the normal function and set its address
+     to its PLT entry which should be resolved by R_*_IRELATIVE at
+     run-time.  All external references should be resolved to its PLT in
+     executable.  */
+  if (!need_dynreloc
+      && !(bfd_link_pde (info) && h->def_regular)
+      && (h->dynindx != -1
+	  || info->export_dynamic)
+      && h->pointer_equality_needed)
+    {
+      info->callbacks->einfo
+	/* xgettext:c-format.  */
+	(_("%F%P: dynamic STT_GNU_IFUNC symbol `%s' with pointer "
+	   "equality in `%pB' can not be used when making an "
+	   "executable; recompile with -fPIE and relink with -pie\n"),
+	 h->root.root.string,
+	 h->root.u.def.section->owner);
+      bfd_set_error (bfd_error_bad_value);
+      return false;
+    }
+
+  htab = elf_hash_table (info);
+
+  /* When the symbol is marked with regular reference, if PLT isn't used
+     or we are building a PIC object, we must keep dynamic relocation
+     if there is non-GOT reference and use PLT if there is PC-relative
+     reference.  */
+  if (need_dynreloc && h->ref_regular)
+    {
+      bool keep = false;
+      for (p = *head; p != NULL; p = p->next)
+	if (p->count)
+	  {
+	    h->non_got_ref = 1;
+	    /* Need dynamic relocations for non-GOT reference.  */
+	    keep = true;
+	    if (p->pc_count)
+	      {
+		/* Must use PLT for PC-relative reference.  */
+		use_plt = true;
+		need_dynreloc = bfd_link_pic (info);
+		break;
+	      }
+	  }
+      if (keep)
+	goto keep;
+    }
+
+  /* Support garbage collection against STT_GNU_IFUNC symbols.  */
+  if (h->plt.refcount <= 0 && h->got.refcount <= 0)
+    {
+      h->got = htab->init_got_offset;
+      h->plt = htab->init_plt_offset;
+      *head = NULL;
+      return true;
+    }
+
+  /* Return and discard space for dynamic relocations against it if
+     it is never referenced.  */
+  if (!h->ref_regular)
+    {
+      if (h->plt.refcount > 0
+	  || h->got.refcount > 0)
+	abort ();
+      h->got = htab->init_got_offset;
+      h->plt = htab->init_plt_offset;
+      *head = NULL;
+      return true;
+    }
+
+ keep:
+  bed = get_elf_backend_data (info->output_bfd);
+  if (bed->rela_plts_and_copies_p)
+    sizeof_reloc = bed->s->sizeof_rela;
+  else
+    sizeof_reloc = bed->s->sizeof_rel;
+
+  /* When building a static executable, use iplt, igot.plt and
+     rel[a].iplt sections for STT_GNU_IFUNC symbols.  */
+  if (htab->splt != NULL)
+    {
+      plt = htab->splt;
+      gotplt = htab->sgotplt;
+      /* Change dynamic info of ifunc gotplt from srelplt to srelgot.  */
+      relplt = htab->srelgot;
+
+      /* If this is the first plt entry and PLT is used, make room for
+	 the special first entry.  */
+      if (plt->size == 0 && use_plt)
+	plt->size += plt_header_size;
+    }
+  else
+    {
+      plt = htab->iplt;
+      gotplt = htab->igotplt;
+      relplt = htab->irelplt;
+    }
+
+  if (use_plt)
+    {
+      /* Don't update value of STT_GNU_IFUNC symbol to PLT.  We need
+	 the original value for R_*_IRELATIVE.  */
+      h->plt.offset = plt->size;
+
+      /* Make room for this entry in the plt/iplt section.  */
+      plt->size += plt_entry_size;
+
+      /* We also need to make an entry in the got.plt/got.iplt section,
+	 which will be placed in the got section by the linker script.  */
+      gotplt->size += got_entry_size;
+    }
+
+  /* We also need to make an entry in the rel[a].plt/.rel[a].iplt
+     section for GOTPLT relocation if PLT is used.  */
+  if (use_plt)
+    {
+      relplt->size += sizeof_reloc;
+      relplt->reloc_count++;
+    }
+
+  /* We need dynamic relocation for STT_GNU_IFUNC symbol only when
+     there is a non-GOT reference in a PIC object or PLT isn't used.  */
+  if (!need_dynreloc || !h->non_got_ref)
+    *head = NULL;
+
+  /* Finally, allocate space.  */
+  p = *head;
+  if (p != NULL)
+    {
+      bfd_size_type count = 0;
+      do
+	{
+	  count += p->count;
+	  p = p->next;
+	}
+      while (p != NULL);
+
+      htab->ifunc_resolvers = count != 0;
+
+      /* Dynamic relocations are stored in
+	 1.  rel[a].srelgot section in PIC object.
+	 2.  rel[a].srelgot section in dynamic executable.
+	 3.  rel[a].irelplt section in static executable.  */
+      if (htab->splt != NULL)
+	htab->srelgot->size += count * sizeof_reloc;
+      else
+	{
+	  relplt->size += count * sizeof_reloc;
+	  relplt->reloc_count += count;
+	}
+    }
+
+  /* For STT_GNU_IFUNC symbol, got.plt has the real function address
+     and got has the PLT entry adddress.  We will load the GOT entry
+     with the PLT entry in finish_dynamic_symbol if it is used.  For
+     branch, it uses got.plt.  For symbol value, if PLT is used,
+     1.  Use got.plt in a PIC object if it is forced local or not
+     dynamic.
+     2.  Use got.plt in a non-PIC object if pointer equality isn't
+     needed.
+     3.  Use got.plt in PIE.
+     4.  Use got.plt if got isn't used.
+     5.  Otherwise use got so that it can be shared among different
+     objects at run-time.
+     If PLT isn't used, always use got for symbol value.
+     We only need to relocate got entry in PIC object or in dynamic
+     executable without PLT.  */
+  if (use_plt
+      && (h->got.refcount <= 0
+	  || (bfd_link_pic (info)
+	      && (h->dynindx == -1
+		  || h->forced_local))
+	  || (
+	      !h->pointer_equality_needed)
+	  || htab->sgot == NULL))
+    {
+      /* Use got.plt.  */
+      h->got.offset = (bfd_vma) -1;
+    }
+  else
+    {
+      if (!use_plt)
+	{
+	  /* PLT isn't used.  */
+	  h->plt.offset = (bfd_vma) -1;
+	}
+      if (h->got.refcount <= 0)
+	{
+	  /* GOT isn't need when there are only relocations for static
+	     pointers.  */
+	  h->got.offset = (bfd_vma) -1;
+	}
+      else
+	{
+	  h->got.offset = htab->sgot->size;
+	  htab->sgot->size += got_entry_size;
+	  /* Need to relocate the GOT entry in a PIC object or PLT isn't
+	     used.  Otherwise, the GOT entry will be filled with the PLT
+	     entry and dynamic GOT relocation isn't needed.  */
+	  if (need_dynreloc)
+	    {
+	      /* For non-static executable, dynamic GOT relocation is in
+		 rel[a].got section, but for static executable, it is
+		 in rel[a].iplt section.  */
+	      if (htab->splt != NULL)
+		htab->srelgot->size += sizeof_reloc;
+	      else
+		{
+		  relplt->size += sizeof_reloc;
+		  relplt->reloc_count++;
+		}
+	    }
+	}
+    }
+
+  return true;
+}
+
 /* Allocate space in .plt, .got and associated reloc sections for
    ifunc dynamic relocs.  */
 
@@ -1223,14 +1476,25 @@ elfNN_loongarch_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
 
   /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
      here if it is defined and referenced in a non-shared object.  */
-  if (h->type == STT_GNU_IFUNC
-      && h->def_regular)
-    return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
+  if (h->type == STT_GNU_IFUNC && h->def_regular)
+    {
+      if (SYMBOL_REFERENCES_LOCAL (info, h))
+	return local_allocate_ifunc_dyn_relocs (info, h,
 					       &h->dyn_relocs,
 					       PLT_ENTRY_SIZE,
 					       PLT_HEADER_SIZE,
 					       GOT_ENTRY_SIZE,
 					       false);
+      else
+	return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
+					       &h->dyn_relocs,
+					       PLT_ENTRY_SIZE,
+					       PLT_HEADER_SIZE,
+					       GOT_ENTRY_SIZE,
+					       false);
+
+    }
+
   return true;
 }
 
@@ -2150,13 +2414,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
 				     + h->root.u.def.section->output_section->vma
 				     + h->root.u.def.section->output_offset);
 
-		  /* Dynamic relocations are stored in
-		     1. .rela.ifunc section in PIC object.
-		     2. .rela.got section in dynamic executable.
-		     3. .rela.iplt section in static executable.  */
-		  if (bfd_link_pic (info))
-		    sreloc = htab->elf.irelifunc;
-		  else if (htab->elf.splt != NULL)
+		  if (htab->elf.splt != NULL)
 		    sreloc = htab->elf.srelgot;
 		  else
 		    sreloc = htab->elf.irelplt;
@@ -2427,7 +2685,9 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
 
 	  if (h != NULL)
 	    {
-	      off = h->got.offset;
+	      bfd_vma alt_off = h->got.offset;
+	      struct bfd_section *alt_got = got;
+	      off = alt_off;
 
 	      if (off == MINUS_ONE
 		  && h->type != STT_GNU_IFUNC)
@@ -2450,20 +2710,19 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
 		    }
 
 		  bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE;
-		  off = plt_index * GOT_ENTRY_SIZE;
+		  alt_off = plt_index * GOT_ENTRY_SIZE;
 
 		  if (htab->elf.splt != NULL)
 		    {
 		      /* Section .plt header is 2 times of plt entry.  */
-		      off = sec_addr(htab->elf.sgotplt) + off
-			- sec_addr(htab->elf.sgot);
+		      alt_got = htab->elf.sgotplt;
 		    }
 		  else
 		    {
 		      /* Section iplt not has plt header.  */
-		      off = sec_addr(htab->elf.igotplt) + off
-			- sec_addr(htab->elf.sgot);
+		      alt_got = htab->elf.igotplt;
 		    }
+		  off = sec_addr(alt_got) + alt_off - sec_addr(htab->elf.sgot);
 		}
 
 	      if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (is_dyn, is_pic, h)
@@ -2525,7 +2784,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
 			  outrel.r_addend = relocation; /* Link-time addr.  */
 			  loongarch_elf_append_rela (output_bfd, s, &outrel);
 			}
-		      bfd_put_NN (output_bfd, relocation, got->contents + off);
+		      bfd_put_NN (output_bfd, relocation, alt_got->contents + alt_off);
 		      h->got.offset |= 1;
 		    }
 		}
@@ -2860,7 +3119,10 @@ loongarch_elf_finish_dynamic_symbol (bfd *output_bfd,
 
 	  plt = htab->elf.splt;
 	  gotplt = htab->elf.sgotplt;
-	  relplt = htab->elf.srelplt;
+	  if (h->type == STT_GNU_IFUNC && SYMBOL_REFERENCES_LOCAL (info, h))
+	    relplt = htab->elf.srelgot;
+	  else
+	    relplt = htab->elf.srelplt;
 	  plt_idx = (h->plt.offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
 	  got_address =
 	    sec_addr (gotplt) + GOTPLT_HEADER_SIZE + plt_idx * GOT_ENTRY_SIZE;
@@ -2896,23 +3158,45 @@ loongarch_elf_finish_dynamic_symbol (bfd *output_bfd,
       rela.r_offset = got_address;
 
       /* TRUE if this is a PLT reference to a local IFUNC.  */
-      if (PLT_LOCAL_IFUNC_P(info, h))
+      if (PLT_LOCAL_IFUNC_P (info, h)
+	  && (relplt == htab->elf.srelgot
+	      || relplt == htab->elf.irelplt))
 	{
-	  rela.r_info = ELFNN_R_INFO (0, R_LARCH_IRELATIVE);
-	  rela.r_addend = (h->root.u.def.value
-			   + h->root.u.def.section->output_section->vma
-			   + h->root.u.def.section->output_offset);
+	    {
+	      rela.r_info = ELFNN_R_INFO (0, R_LARCH_IRELATIVE);
+	      rela.r_addend = (h->root.u.def.value
+			       + h->root.u.def.section->output_section->vma
+			       + h->root.u.def.section->output_offset);
+	    }
+
+	    /* Find the space after dyn sort.  */
+	    {
+	      Elf_Internal_Rela *dyn = (Elf_Internal_Rela *)relplt->contents;
+	      bool fill = false;
+	      for (;dyn < dyn + relplt->size / sizeof (*dyn); dyn++)
+		{
+		  if (0 == dyn->r_offset)
+		    {
+		      bed->s->swap_reloca_out (output_bfd, &rela,
+					       (bfd_byte *)dyn);
+		      relplt->reloc_count++;
+		      fill = true;
+		      break;
+		    }
+		}
+	      BFD_ASSERT (fill);
+	    }
+
 	}
       else
 	{
-	  /* Fill in the entry in the .rela.plt section.  */
+	  /* Fill in the entry in the rela.plt section.  */
 	  rela.r_info = ELFNN_R_INFO (h->dynindx, R_LARCH_JUMP_SLOT);
 	  rela.r_addend = 0;
+	  loc = relplt->contents + plt_idx * sizeof (ElfNN_External_Rela);
+	  bed->s->swap_reloca_out (output_bfd, &rela, loc);
 	}
 
-      loc = relplt->contents + plt_idx * sizeof (ElfNN_External_Rela);
-      bed->s->swap_reloca_out (output_bfd, &rela, loc);
-
       if (!h->def_regular)
 	{
 	  /* Mark the symbol as undefined, rather than as defined in
-- 
2.37.0


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-24 11:51   ` Xi Ruoyao
@ 2022-07-24 12:02     ` WANG Xuerui
  2022-07-25  8:21       ` caiyinyu
  2022-07-25  1:58     ` 刘振松
  1 sibling, 1 reply; 36+ messages in thread
From: WANG Xuerui @ 2022-07-24 12:02 UTC (permalink / raw)
  To: Xi Ruoyao, WANG Xuerui, caiyinyu, adhemerval.zanella, libc-alpha,
	joseph_myers, carlos
  Cc: liuzhensong

On 7/24/22 19:51, Xi Ruoyao wrote:
> On Sun, 2022-07-24 at 17:49 +0800, WANG Xuerui wrote:
>
>> Of these, the ifunc failures are "expected" by you, the
>> elf/check-abi-libc diff is trivial (maybe you just didn't rebase as
>> frequently):
>>
>> --- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 2022-07-23
>> 14:45:57.490029442 +0800
>> +++ /home/xenon/src/glibc/build/libc.symlist    2022-07-24
>> 13:44:10.416642655 +0800
>> @@ -496 +496 @@ GLIBC_2.36 _mcount F
>> -GLIBC_2.36 _nl_default_dirname D 0x12
>> +GLIBC_2.36 _nl_default_dirname D 0x17
>> @@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
>> +GLIBC_2.36 arc4random F
>> +GLIBC_2.36 arc4random_buf F
>> +GLIBC_2.36 arc4random_uniform F
> arc4random is just merged two days ago.
Yeah; I meant to alert the relevant people (patch author or committer) 
to not forget adjusting this.
>
>> The others may need some love. Of course they're possibly because of my
>> particular environment (Gentoo is a little bit different than "ordinary"
>> distros like Debian/Fedora, and I already have to symlink the
>> libgcc_s.so and libstdc++.so to pass the nptl tests at all)
> I can tell tst-nss-files-hosts-long is most likely PR24816.  For the
> others I'm not sure.
>
> By "symlink libgcc_s.so and libstdc++.so" I guess you are running tests
> in a temporary system ("Gentoo stage 1" IIRC).  In LFS we also get some
> additional test failures in the temporary system [1] so it's better to
> rerun the tests in a full system.
>
> (In earlier LFS releases we also needed to symlink libgcc_s.so and
> libstdc++.so for glibc tests, but it's no longer needed now thanks to a
> major refactoring [2].)

Of course my Gentoo devbox is fully bootstrapped and working :-)

I'm referring to the Gentoo-specific behavior of slotted gcc 
installation, where gcc-provided libraries (including the two mentioned 
here) are NOT present in the usual place, but rather in 
/usr/lib/gcc/<PACKAGE VERSION>. Additional magic is present for the 
"active" gcc to be switchable via the gcc-config tool. Binutils is 
similar; there is a binutils-config too.

But anyway, the nptl tests mostly passed, with the only 2 failures 
related to the botched gdb on LoongArch (I compiled from the upstream 
HEAD and still it doesn't work). The others are worth looking into too 
but don't seem to cause any problem so far.

>
> [1]: https://www.linuxfromscratch.org/lfs/view/systemd/chapter08/glibc.html
> [2]: https://lists.linuxfromscratch.org/sympa/arc/lfs-dev/2020-05/msg00000.html
>
> My test result on LFS (fully built) with a patched ld seems clean.  The
> patch is originally published at
> https://sourceware.org/pipermail/binutils/2022-July/121852.html, but
> it's in a large series introducing new relocation types.  I managed to
> rebased and adjusted the patch so it can be applied individually for
> binutils-gdb master branch.  The patch is attached in this mail.
>
> +Zhensong: is there any possibility to merge this patch for binutils
> master and 2.39 release branch (including 2.38 release branch would be
> even better) so at least glibc ifunc tests will be happy?
>
> XPASS: conform/UNIX98/ndbm.h/linknamespace
> XPASS: conform/XOPEN2K/ndbm.h/linknamespace
> XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
> XPASS: conform/XPG42/ndbm.h/linknamespace
> UNSUPPORTED: crypt/cert
> FAIL: elf/check-abi-libc
> UNSUPPORTED: elf/tst-env-setuid
> UNSUPPORTED: elf/tst-env-setuid-tunables
> XPASS: elf/tst-protected1a
> XPASS: elf/tst-protected1b
> UNSUPPORTED: elf/tst-valgrind-smoke
> UNSUPPORTED: misc/tst-adjtimex
> UNSUPPORTED: misc/tst-clock_adjtime
> UNSUPPORTED: misc/tst-ntp_adjtime
> UNSUPPORTED: misc/tst-pkey
> UNSUPPORTED: misc/tst-rseq
> UNSUPPORTED: misc/tst-rseq-disable
> UNSUPPORTED: nptl/test-cond-printers
> UNSUPPORTED: nptl/test-condattr-printers
> UNSUPPORTED: nptl/test-mutex-printers
> UNSUPPORTED: nptl/test-mutexattr-printers
> UNSUPPORTED: nptl/test-rwlock-printers
> UNSUPPORTED: nptl/test-rwlockattr-printers
> UNSUPPORTED: nptl/tst-pthread-gdb-attach
> UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
> UNSUPPORTED: nptl/tst-rseq-nptl
> UNSUPPORTED: stdlib/tst-secure-getenv
> UNSUPPORTED: time/tst-clock_settime
> UNSUPPORTED: time/tst-settimeofday
> Summary of test results:
>        1 FAIL
>     4576 PASS
>       22 UNSUPPORTED
>       12 XFAIL
>        6 XPASS
Overall this is looking good. Thanks for your testing.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-24 11:51   ` Xi Ruoyao
  2022-07-24 12:02     ` WANG Xuerui
@ 2022-07-25  1:58     ` 刘振松
  2022-07-25  8:01       ` Xi Ruoyao
  1 sibling, 1 reply; 36+ messages in thread
From: 刘振松 @ 2022-07-25  1:58 UTC (permalink / raw)
  To: Xi Ruoyao
  Cc: WANG Xuerui, caiyinyu, adhemerval.zanella, libc-alpha,
	joseph_myers, carlos




&gt; -----原始邮件-----
&gt; 发件人: "Xi Ruoyao" <xry111@xry111.site>
&gt; 发送时间: 2022-07-24 19:51:51 (星期日)
&gt; 收件人: "WANG Xuerui" <i.swmail@xen0n.name>, caiyinyu <caiyinyu@loongson.cn>, adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, joseph_myers@mentor.com, carlos@redhat.com
&gt; 抄送: liuzhensong@loongson.cn
&gt; 主题: Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
&gt; 
&gt; On Sun, 2022-07-24 at 17:49 +0800, WANG Xuerui wrote:
&gt; 
&gt; &gt; Of these, the ifunc failures are "expected" by you, the 
&gt; &gt; elf/check-abi-libc diff is trivial (maybe you just didn't rebase as 
&gt; &gt; frequently):
&gt; &gt; 
&gt; &gt; --- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 2022-07-23 
&gt; &gt; 14:45:57.490029442 +0800
&gt; &gt; +++ /home/xenon/src/glibc/build/libc.symlist&nbsp;&nbsp;&nbsp; 2022-07-24 
&gt; &gt; 13:44:10.416642655 +0800
&gt; &gt; @@ -496 +496 @@ GLIBC_2.36 _mcount F
&gt; &gt; -GLIBC_2.36 _nl_default_dirname D 0x12
&gt; &gt; +GLIBC_2.36 _nl_default_dirname D 0x17
&gt; &gt; @@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
&gt; &gt; +GLIBC_2.36 arc4random F
&gt; &gt; +GLIBC_2.36 arc4random_buf F
&gt; &gt; +GLIBC_2.36 arc4random_uniform F
&gt; 
&gt; arc4random is just merged two days ago.
&gt; 
&gt; &gt; The others may need some love. Of course they're possibly because of my 
&gt; &gt; particular environment (Gentoo is a little bit different than "ordinary" 
&gt; &gt; distros like Debian/Fedora, and I already have to symlink the 
&gt; &gt; libgcc_s.so and libstdc++.so to pass the nptl tests at all)
&gt; 
&gt; I can tell tst-nss-files-hosts-long is most likely PR24816.  For the
&gt; others I'm not sure.
&gt; 
&gt; By "symlink libgcc_s.so and libstdc++.so" I guess you are running tests
&gt; in a temporary system ("Gentoo stage 1" IIRC).  In LFS we also get some
&gt; additional test failures in the temporary system [1] so it's better to
&gt; rerun the tests in a full system.
&gt; 
&gt; (In earlier LFS releases we also needed to symlink libgcc_s.so and
&gt; libstdc++.so for glibc tests, but it's no longer needed now thanks to a
&gt; major refactoring [2].)
&gt; 
&gt; [1]: https://www.linuxfromscratch.org/lfs/view/systemd/chapter08/glibc.html
&gt; [2]: https://lists.linuxfromscratch.org/sympa/arc/lfs-dev/2020-05/msg00000.html
&gt; 
&gt; My test result on LFS (fully built) with a patched ld seems clean.  The
&gt; patch is originally published at
&gt; https://sourceware.org/pipermail/binutils/2022-July/121852.html, but
&gt; it's in a large series introducing new relocation types.  I managed to
&gt; rebased and adjusted the patch so it can be applied individually for
&gt; binutils-gdb master branch.  The patch is attached in this mail.
&gt; 
&gt; +Zhensong: is there any possibility to merge this patch for binutils
&gt; master and 2.39 release branch (including 2.38 release branch would be
&gt; even better) so at least glibc ifunc tests will be happy?

This patch alone has not been fully tested, some ifunc implementations rely on new modifications.
If there is no problem with the tests, it can be merged into other branchs.

&gt; 
&gt; XPASS: conform/UNIX98/ndbm.h/linknamespace
&gt; XPASS: conform/XOPEN2K/ndbm.h/linknamespace
&gt; XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
&gt; XPASS: conform/XPG42/ndbm.h/linknamespace
&gt; UNSUPPORTED: crypt/cert
&gt; FAIL: elf/check-abi-libc
&gt; UNSUPPORTED: elf/tst-env-setuid
&gt; UNSUPPORTED: elf/tst-env-setuid-tunables
&gt; XPASS: elf/tst-protected1a
&gt; XPASS: elf/tst-protected1b
&gt; UNSUPPORTED: elf/tst-valgrind-smoke
&gt; UNSUPPORTED: misc/tst-adjtimex
&gt; UNSUPPORTED: misc/tst-clock_adjtime
&gt; UNSUPPORTED: misc/tst-ntp_adjtime
&gt; UNSUPPORTED: misc/tst-pkey
&gt; UNSUPPORTED: misc/tst-rseq
&gt; UNSUPPORTED: misc/tst-rseq-disable
&gt; UNSUPPORTED: nptl/test-cond-printers
&gt; UNSUPPORTED: nptl/test-condattr-printers
&gt; UNSUPPORTED: nptl/test-mutex-printers
&gt; UNSUPPORTED: nptl/test-mutexattr-printers
&gt; UNSUPPORTED: nptl/test-rwlock-printers
&gt; UNSUPPORTED: nptl/test-rwlockattr-printers
&gt; UNSUPPORTED: nptl/tst-pthread-gdb-attach
&gt; UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
&gt; UNSUPPORTED: nptl/tst-rseq-nptl
&gt; UNSUPPORTED: stdlib/tst-secure-getenv
&gt; UNSUPPORTED: time/tst-clock_settime
&gt; UNSUPPORTED: time/tst-settimeofday
&gt; Summary of test results:
&gt;       1 FAIL
&gt;    4576 PASS
&gt;      22 UNSUPPORTED
&gt;      12 XFAIL
&gt;       6 XPASS
&gt; 
&gt; 
&gt; -- 
&gt; Xi Ruoyao <xry111@xry111.site>
&gt; School of Aerospace Science and Technology, Xidian University
</xry111@xry111.site></caiyinyu@loongson.cn></i.swmail@xen0n.name></xry111@xry111.site>

本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。 
This email and its attachments contain confidential information from Loongson Technology , which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this email in error, please notify the sender by phone or email immediately and delete it. 

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-25  1:58     ` 刘振松
@ 2022-07-25  8:01       ` Xi Ruoyao
  0 siblings, 0 replies; 36+ messages in thread
From: Xi Ruoyao @ 2022-07-25  8:01 UTC (permalink / raw)
  To: 刘振松
  Cc: WANG Xuerui, caiyinyu, adhemerval.zanella, libc-alpha,
	joseph_myers, carlos

On Mon, 2022-07-25 at 09:58 +0800, 刘振松 wrote:
> > +Zhensong: is there any possibility to merge this patch for binutils
> > master and 2.39 release branch (including 2.38 release branch would be
> > even better) so at least glibc ifunc tests will be happy?
> 
> This patch alone has not been fully tested, some ifunc implementations rely on new modifications.
> If there is no problem with the tests, it can be merged into other branchs.

Binutils tests OK with the change.

I had to introduce "alt_got" and "alt_off" (not in your original patch)
when I extracted the patch out of the series, with changes like:

-		      bfd_put_NN (output_bfd, relocation, got->contents + off);
+		      bfd_put_NN (output_bfd, relocation, alt_got->contents + alt_off);

It's because if something is not in .got section, referring it with
got->contents + off will cause a heap buffer overflow even if off is
correct.  If the full series of your patch is applied, this seems not
happening.  But with only this patch, we need to prevent it.
-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-24 12:02     ` WANG Xuerui
@ 2022-07-25  8:21       ` caiyinyu
  2022-07-25  8:28         ` Xi Ruoyao
  0 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-25  8:21 UTC (permalink / raw)
  To: WANG Xuerui, Xi Ruoyao, adhemerval.zanella, libc-alpha,
	joseph_myers, carlos
  Cc: liuzhensong

Summary of test results:
        1 FAIL
     4576 PASS
       22 UNSUPPORTED
       12 XFAIL
        6 XPASS
Overall this is looking good. Thanks for your testing.


So, is it necessary to release another version of v8??


在 2022/7/24 下午8:02, WANG Xuerui 写道:
> On 7/24/22 19:51, Xi Ruoyao wrote:
>> On Sun, 2022-07-24 at 17:49 +0800, WANG Xuerui wrote:
>>
>>> Of these, the ifunc failures are "expected" by you, the
>>> elf/check-abi-libc diff is trivial (maybe you just didn't rebase as
>>> frequently):
>>>
>>> --- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 2022-07-23
>>> 14:45:57.490029442 +0800
>>> +++ /home/xenon/src/glibc/build/libc.symlist    2022-07-24
>>> 13:44:10.416642655 +0800
>>> @@ -496 +496 @@ GLIBC_2.36 _mcount F
>>> -GLIBC_2.36 _nl_default_dirname D 0x12
>>> +GLIBC_2.36 _nl_default_dirname D 0x17
>>> @@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
>>> +GLIBC_2.36 arc4random F
>>> +GLIBC_2.36 arc4random_buf F
>>> +GLIBC_2.36 arc4random_uniform F
>> arc4random is just merged two days ago.
> Yeah; I meant to alert the relevant people (patch author or committer) 
> to not forget adjusting this.
>>
>>> The others may need some love. Of course they're possibly because of my
>>> particular environment (Gentoo is a little bit different than 
>>> "ordinary"
>>> distros like Debian/Fedora, and I already have to symlink the
>>> libgcc_s.so and libstdc++.so to pass the nptl tests at all)
>> I can tell tst-nss-files-hosts-long is most likely PR24816.  For the
>> others I'm not sure.
>>
>> By "symlink libgcc_s.so and libstdc++.so" I guess you are running tests
>> in a temporary system ("Gentoo stage 1" IIRC).  In LFS we also get some
>> additional test failures in the temporary system [1] so it's better to
>> rerun the tests in a full system.
>>
>> (In earlier LFS releases we also needed to symlink libgcc_s.so and
>> libstdc++.so for glibc tests, but it's no longer needed now thanks to a
>> major refactoring [2].)
>
> Of course my Gentoo devbox is fully bootstrapped and working :-)
>
> I'm referring to the Gentoo-specific behavior of slotted gcc 
> installation, where gcc-provided libraries (including the two 
> mentioned here) are NOT present in the usual place, but rather in 
> /usr/lib/gcc/<PACKAGE VERSION>. Additional magic is present for the 
> "active" gcc to be switchable via the gcc-config tool. Binutils is 
> similar; there is a binutils-config too.
>
> But anyway, the nptl tests mostly passed, with the only 2 failures 
> related to the botched gdb on LoongArch (I compiled from the upstream 
> HEAD and still it doesn't work). The others are worth looking into too 
> but don't seem to cause any problem so far.
>
>>
>> [1]: 
>> https://www.linuxfromscratch.org/lfs/view/systemd/chapter08/glibc.html
>> [2]: 
>> https://lists.linuxfromscratch.org/sympa/arc/lfs-dev/2020-05/msg00000.html
>>
>> My test result on LFS (fully built) with a patched ld seems clean.  The
>> patch is originally published at
>> https://sourceware.org/pipermail/binutils/2022-July/121852.html, but
>> it's in a large series introducing new relocation types.  I managed to
>> rebased and adjusted the patch so it can be applied individually for
>> binutils-gdb master branch.  The patch is attached in this mail.
>>
>> +Zhensong: is there any possibility to merge this patch for binutils
>> master and 2.39 release branch (including 2.38 release branch would be
>> even better) so at least glibc ifunc tests will be happy?
>>
>> XPASS: conform/UNIX98/ndbm.h/linknamespace
>> XPASS: conform/XOPEN2K/ndbm.h/linknamespace
>> XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
>> XPASS: conform/XPG42/ndbm.h/linknamespace
>> UNSUPPORTED: crypt/cert
>> FAIL: elf/check-abi-libc
>> UNSUPPORTED: elf/tst-env-setuid
>> UNSUPPORTED: elf/tst-env-setuid-tunables
>> XPASS: elf/tst-protected1a
>> XPASS: elf/tst-protected1b
>> UNSUPPORTED: elf/tst-valgrind-smoke
>> UNSUPPORTED: misc/tst-adjtimex
>> UNSUPPORTED: misc/tst-clock_adjtime
>> UNSUPPORTED: misc/tst-ntp_adjtime
>> UNSUPPORTED: misc/tst-pkey
>> UNSUPPORTED: misc/tst-rseq
>> UNSUPPORTED: misc/tst-rseq-disable
>> UNSUPPORTED: nptl/test-cond-printers
>> UNSUPPORTED: nptl/test-condattr-printers
>> UNSUPPORTED: nptl/test-mutex-printers
>> UNSUPPORTED: nptl/test-mutexattr-printers
>> UNSUPPORTED: nptl/test-rwlock-printers
>> UNSUPPORTED: nptl/test-rwlockattr-printers
>> UNSUPPORTED: nptl/tst-pthread-gdb-attach
>> UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
>> UNSUPPORTED: nptl/tst-rseq-nptl
>> UNSUPPORTED: stdlib/tst-secure-getenv
>> UNSUPPORTED: time/tst-clock_settime
>> UNSUPPORTED: time/tst-settimeofday
>> Summary of test results:
>>        1 FAIL
>>     4576 PASS
>>       22 UNSUPPORTED
>>       12 XFAIL
>>        6 XPASS
> Overall this is looking good. Thanks for your testing.


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-25  8:21       ` caiyinyu
@ 2022-07-25  8:28         ` Xi Ruoyao
  0 siblings, 0 replies; 36+ messages in thread
From: Xi Ruoyao @ 2022-07-25  8:28 UTC (permalink / raw)
  To: caiyinyu, WANG Xuerui, adhemerval.zanella, libc-alpha,
	joseph_myers, carlos
  Cc: liuzhensong

On Mon, 2022-07-25 at 16:21 +0800, caiyinyu wrote:
> Summary of test results:
>         1 FAIL
>      4576 PASS
>        22 UNSUPPORTED
>        12 XFAIL
>         6 XPASS
> Overall this is looking good. Thanks for your testing.
> 
> 
> So, is it necessary to release another version of v8??

I guess a v8 is better because the 17th patch (NEWS) needs a rebase
anyway.  But let's wait for Adhemerval's suggestion...

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-24  9:49 ` WANG Xuerui
  2022-07-24 11:51   ` Xi Ruoyao
@ 2022-07-25 13:27   ` Adhemerval Zanella Netto
  2022-07-25 14:14     ` caiyinyu
  1 sibling, 1 reply; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-25 13:27 UTC (permalink / raw)
  To: WANG Xuerui, caiyinyu, libc-alpha, joseph_myers, carlos



On 24/07/22 06:49, WANG Xuerui wrote:
> Hi,
> 
> On 7/19/22 09:20, caiyinyu wrote:
>> <snip>
>> 6. Test result: all passed (ifunc disable).
>>
>> Test with:
>>    Linux-5.19-rc4, Binutils-2.38, and GCC-12.1.
>>    glibc: https://github.com/loongson/glibc/tree/loongarch_2_36_upstream_v7
>>
>> Result (ifunc disable):
>> XPASS: conform/UNIX98/ndbm.h/linknamespace
>> XPASS: conform/XOPEN2K/ndbm.h/linknamespace
>> XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
>> XPASS: conform/XPG42/ndbm.h/linknamespace
>> UNSUPPORTED: crypt/cert
>> UNSUPPORTED: elf/tst-env-setuid
>> UNSUPPORTED: elf/tst-env-setuid-tunables
>> XPASS: elf/tst-protected1a
>> XPASS: elf/tst-protected1b
>> UNSUPPORTED: elf/tst-valgrind-smoke
>> UNSUPPORTED: misc/tst-adjtimex
>> UNSUPPORTED: misc/tst-clock_adjtime
>> UNSUPPORTED: misc/tst-ntp_adjtime
>> UNSUPPORTED: misc/tst-pkey
>> UNSUPPORTED: misc/tst-rseq
>> UNSUPPORTED: misc/tst-rseq-disable
>> UNSUPPORTED: nptl/test-cond-printers
>> UNSUPPORTED: nptl/test-condattr-printers
>> UNSUPPORTED: nptl/test-mutex-printers
>> UNSUPPORTED: nptl/test-mutexattr-printers
>> UNSUPPORTED: nptl/test-rwlock-printers
>> UNSUPPORTED: nptl/test-rwlockattr-printers
>> UNSUPPORTED: nptl/tst-pthread-gdb-attach
>> UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
>> UNSUPPORTED: nptl/tst-rseq-nptl
>> UNSUPPORTED: stdlib/tst-secure-getenv
>> UNSUPPORTED: time/tst-clock_settime
>> UNSUPPORTED: time/tst-settimeofday
>> Summary of test results:
>>     4535 PASS
>>       22 UNSUPPORTED
>>       12 XFAIL
>>        6 XPASS
> 
> Thanks for your effort these days. I ran the test on Gentoo and this is what I have found out:
> 
> UNSUPPORTED: crypt/cert
> FAIL: elf/check-abi-libc
> FAIL: elf/ifuncmain1
> FAIL: elf/ifuncmain1pic
> FAIL: elf/ifuncmain1pie
> FAIL: elf/ifuncmain1staticpic
> FAIL: elf/ifuncmain1staticpie
> FAIL: elf/ifuncmain1vis
> FAIL: elf/ifuncmain1vispic
> FAIL: elf/ifuncmain1vispie
> FAIL: elf/ifuncmain2
> FAIL: elf/ifuncmain2pic
> FAIL: elf/ifuncmain3
> FAIL: elf/ifuncmain4
> FAIL: elf/ifuncmain5staticpic
> FAIL: elf/ifuncmain6pie
> FAIL: elf/ifuncmain7
> FAIL: elf/ifuncmain7pic
> FAIL: elf/ifuncmain7pie
> FAIL: elf/ifuncmain9
> FAIL: elf/ifuncmain9pic
> FAIL: elf/ifuncmain9pie
> UNSUPPORTED: elf/tst-env-setuid
> UNSUPPORTED: elf/tst-env-setuid-tunables
> FAIL: elf/tst-glibc-hwcaps-prepend-cache
> FAIL: elf/tst-ifunc-textrel
> FAIL: elf/tst-ldconfig-ld_so_conf-update
> XPASS: elf/tst-protected1a
> XPASS: elf/tst-protected1b
> UNSUPPORTED: elf/tst-valgrind-smoke
> FAIL: malloc/tst-free-errno-malloc-hugetlb1
> UNSUPPORTED: misc/tst-adjtimex
> UNSUPPORTED: misc/tst-clock_adjtime
> UNSUPPORTED: misc/tst-ntp_adjtime
> UNSUPPORTED: misc/tst-pkey
> UNSUPPORTED: misc/tst-rseq
> UNSUPPORTED: misc/tst-rseq-disable
> FAIL: nptl/tst-pthread-gdb-attach
> FAIL: nptl/tst-pthread-gdb-attach-static
> UNSUPPORTED: nptl/tst-rseq-nptl
> FAIL: nss/tst-nss-files-hosts-long
> UNSUPPORTED: resolv/tst-resolv-ai_idn
> UNSUPPORTED: resolv/tst-resolv-ai_idn-latin1
> UNSUPPORTED: stdlib/tst-secure-getenv
> UNSUPPORTED: time/tst-clock_settime
> UNSUPPORTED: time/tst-settimeofday
> 
> Of these, the ifunc failures are "expected" by you, the elf/check-abi-libc diff is trivial (maybe you just didn't rebase as frequently):
> 
> --- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 2022-07-23 14:45:57.490029442 +0800
> +++ /home/xenon/src/glibc/build/libc.symlist    2022-07-24 13:44:10.416642655 +0800
> @@ -496 +496 @@ GLIBC_2.36 _mcount F
> -GLIBC_2.36 _nl_default_dirname D 0x12
> +GLIBC_2.36 _nl_default_dirname D 0x17
> @@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
> +GLIBC_2.36 arc4random F
> +GLIBC_2.36 arc4random_buf F
> +GLIBC_2.36 arc4random_uniform F
> 
> The others may need some love. Of course they're possibly because of my particular environment (Gentoo is a little bit different than "ordinary" distros like Debian/Fedora, and I already have to symlink the libgcc_s.so and libstdc++.so to pass the nptl tests at all).

The 'elf/tst-glibc-hwcaps-prepend-cache' and 'elf/tst-ldconfig-ld_so_conf-update',
might worth to take a look, although they are not arch-specific and I think it is
more related to the test environment.

Also, once you add the loongarch entry on release wiki [2], please the configure
options use to state ifunc needs to be explicit disabled.

> 
> Coming to code quality, there are obviously warts present, like the lingering uses of the name "x" for $r21 and apparent lack of assembly pseudo-insn sugar usages (e.g. no "move a, b" but always "or a, b, zero"; the code must be directly descended from an extremely early time when the assembler didn't have such support), but at this point these cosmetic concerns are better fixed after 2.36 to minimize churn prior to release. At a quick glance the ABI is looking good. (There is a certain "__x" in bits/setjmp.h meant to refer to r21, but __jmp_buf is not public API so I think we're safe here.)
> 
I agree that cosmetic issues should not interfere with loongarch64 addition, we
can backport if required (although for such changes I also do not see much
point).

I have create a branch which I think it is suitable for inclusion [1], I 
have fixed the ABI issue due arc4random addition and some style issues 
(trailing lines) that were triggering our pre-commit hooks..

> 
> I guess a v8 is better because the 17th patch (NEWS) needs a rebase
> anyway.  But let's wait for Adhemerval's suggestion...

It is up to your, if you are ok with my fixed branch I can install otherwise
you send a v8.

[1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/loongarch64
[2] https://sourceware.org/glibc/wiki/Release/2.36

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-25 13:27   ` Adhemerval Zanella Netto
@ 2022-07-25 14:14     ` caiyinyu
  2022-07-26 12:35       ` caiyinyu
  0 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-25 14:14 UTC (permalink / raw)
  To: Adhemerval Zanella Netto, WANG Xuerui, libc-alpha, joseph_myers, carlos

> I guess a v8 is better because the 17th patch (NEWS) needs a rebase
> anyway.  But let's wait for Adhemerval's suggestion...

It is up to your, if you are ok with my fixed branch I can install otherwise
you send a v8.

--------------------

I checked and I'm ok with the fixed branch.

Waiting for other suggestions.

Thanks.



在 2022/7/25 下午9:27, Adhemerval Zanella Netto 写道:
>
> On 24/07/22 06:49, WANG Xuerui wrote:
>> Hi,
>>
>> On 7/19/22 09:20, caiyinyu wrote:
>>> <snip>
>>> 6. Test result: all passed (ifunc disable).
>>>
>>> Test with:
>>>     Linux-5.19-rc4, Binutils-2.38, and GCC-12.1.
>>>     glibc: https://github.com/loongson/glibc/tree/loongarch_2_36_upstream_v7
>>>
>>> Result (ifunc disable):
>>> XPASS: conform/UNIX98/ndbm.h/linknamespace
>>> XPASS: conform/XOPEN2K/ndbm.h/linknamespace
>>> XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
>>> XPASS: conform/XPG42/ndbm.h/linknamespace
>>> UNSUPPORTED: crypt/cert
>>> UNSUPPORTED: elf/tst-env-setuid
>>> UNSUPPORTED: elf/tst-env-setuid-tunables
>>> XPASS: elf/tst-protected1a
>>> XPASS: elf/tst-protected1b
>>> UNSUPPORTED: elf/tst-valgrind-smoke
>>> UNSUPPORTED: misc/tst-adjtimex
>>> UNSUPPORTED: misc/tst-clock_adjtime
>>> UNSUPPORTED: misc/tst-ntp_adjtime
>>> UNSUPPORTED: misc/tst-pkey
>>> UNSUPPORTED: misc/tst-rseq
>>> UNSUPPORTED: misc/tst-rseq-disable
>>> UNSUPPORTED: nptl/test-cond-printers
>>> UNSUPPORTED: nptl/test-condattr-printers
>>> UNSUPPORTED: nptl/test-mutex-printers
>>> UNSUPPORTED: nptl/test-mutexattr-printers
>>> UNSUPPORTED: nptl/test-rwlock-printers
>>> UNSUPPORTED: nptl/test-rwlockattr-printers
>>> UNSUPPORTED: nptl/tst-pthread-gdb-attach
>>> UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
>>> UNSUPPORTED: nptl/tst-rseq-nptl
>>> UNSUPPORTED: stdlib/tst-secure-getenv
>>> UNSUPPORTED: time/tst-clock_settime
>>> UNSUPPORTED: time/tst-settimeofday
>>> Summary of test results:
>>>      4535 PASS
>>>        22 UNSUPPORTED
>>>        12 XFAIL
>>>         6 XPASS
>> Thanks for your effort these days. I ran the test on Gentoo and this is what I have found out:
>>
>> UNSUPPORTED: crypt/cert
>> FAIL: elf/check-abi-libc
>> FAIL: elf/ifuncmain1
>> FAIL: elf/ifuncmain1pic
>> FAIL: elf/ifuncmain1pie
>> FAIL: elf/ifuncmain1staticpic
>> FAIL: elf/ifuncmain1staticpie
>> FAIL: elf/ifuncmain1vis
>> FAIL: elf/ifuncmain1vispic
>> FAIL: elf/ifuncmain1vispie
>> FAIL: elf/ifuncmain2
>> FAIL: elf/ifuncmain2pic
>> FAIL: elf/ifuncmain3
>> FAIL: elf/ifuncmain4
>> FAIL: elf/ifuncmain5staticpic
>> FAIL: elf/ifuncmain6pie
>> FAIL: elf/ifuncmain7
>> FAIL: elf/ifuncmain7pic
>> FAIL: elf/ifuncmain7pie
>> FAIL: elf/ifuncmain9
>> FAIL: elf/ifuncmain9pic
>> FAIL: elf/ifuncmain9pie
>> UNSUPPORTED: elf/tst-env-setuid
>> UNSUPPORTED: elf/tst-env-setuid-tunables
>> FAIL: elf/tst-glibc-hwcaps-prepend-cache
>> FAIL: elf/tst-ifunc-textrel
>> FAIL: elf/tst-ldconfig-ld_so_conf-update
>> XPASS: elf/tst-protected1a
>> XPASS: elf/tst-protected1b
>> UNSUPPORTED: elf/tst-valgrind-smoke
>> FAIL: malloc/tst-free-errno-malloc-hugetlb1
>> UNSUPPORTED: misc/tst-adjtimex
>> UNSUPPORTED: misc/tst-clock_adjtime
>> UNSUPPORTED: misc/tst-ntp_adjtime
>> UNSUPPORTED: misc/tst-pkey
>> UNSUPPORTED: misc/tst-rseq
>> UNSUPPORTED: misc/tst-rseq-disable
>> FAIL: nptl/tst-pthread-gdb-attach
>> FAIL: nptl/tst-pthread-gdb-attach-static
>> UNSUPPORTED: nptl/tst-rseq-nptl
>> FAIL: nss/tst-nss-files-hosts-long
>> UNSUPPORTED: resolv/tst-resolv-ai_idn
>> UNSUPPORTED: resolv/tst-resolv-ai_idn-latin1
>> UNSUPPORTED: stdlib/tst-secure-getenv
>> UNSUPPORTED: time/tst-clock_settime
>> UNSUPPORTED: time/tst-settimeofday
>>
>> Of these, the ifunc failures are "expected" by you, the elf/check-abi-libc diff is trivial (maybe you just didn't rebase as frequently):
>>
>> --- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 2022-07-23 14:45:57.490029442 +0800
>> +++ /home/xenon/src/glibc/build/libc.symlist    2022-07-24 13:44:10.416642655 +0800
>> @@ -496 +496 @@ GLIBC_2.36 _mcount F
>> -GLIBC_2.36 _nl_default_dirname D 0x12
>> +GLIBC_2.36 _nl_default_dirname D 0x17
>> @@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
>> +GLIBC_2.36 arc4random F
>> +GLIBC_2.36 arc4random_buf F
>> +GLIBC_2.36 arc4random_uniform F
>>
>> The others may need some love. Of course they're possibly because of my particular environment (Gentoo is a little bit different than "ordinary" distros like Debian/Fedora, and I already have to symlink the libgcc_s.so and libstdc++.so to pass the nptl tests at all).
> The 'elf/tst-glibc-hwcaps-prepend-cache' and 'elf/tst-ldconfig-ld_so_conf-update',
> might worth to take a look, although they are not arch-specific and I think it is
> more related to the test environment.
>
> Also, once you add the loongarch entry on release wiki [2], please the configure
> options use to state ifunc needs to be explicit disabled.
>
>> Coming to code quality, there are obviously warts present, like the lingering uses of the name "x" for $r21 and apparent lack of assembly pseudo-insn sugar usages (e.g. no "move a, b" but always "or a, b, zero"; the code must be directly descended from an extremely early time when the assembler didn't have such support), but at this point these cosmetic concerns are better fixed after 2.36 to minimize churn prior to release. At a quick glance the ABI is looking good. (There is a certain "__x" in bits/setjmp.h meant to refer to r21, but __jmp_buf is not public API so I think we're safe here.)
>>
> I agree that cosmetic issues should not interfere with loongarch64 addition, we
> can backport if required (although for such changes I also do not see much
> point).
>
> I have create a branch which I think it is suitable for inclusion [1], I
> have fixed the ABI issue due arc4random addition and some style issues
> (trailing lines) that were triggering our pre-commit hooks..
>
>> I guess a v8 is better because the 17th patch (NEWS) needs a rebase
>> anyway.  But let's wait for Adhemerval's suggestion...
> It is up to your, if you are ok with my fixed branch I can install otherwise
> you send a v8.
>
> [1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/loongarch64
> [2] https://sourceware.org/glibc/wiki/Release/2.36


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-25 14:14     ` caiyinyu
@ 2022-07-26 12:35       ` caiyinyu
  2022-07-26 12:42         ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 36+ messages in thread
From: caiyinyu @ 2022-07-26 12:35 UTC (permalink / raw)
  To: Adhemerval Zanella Netto, WANG Xuerui, libc-alpha, joseph_myers, carlos


Also, once you add the loongarch entry on release wiki [2], please the 
configure
options use to state ifunc needs to be explicit disabled.

---------

I have created an account (caiyinyu@loongson.cn) on glibc wiki and we 
need to participate in the wiki to edit loongarch parts.


在 2022/7/25 下午10:14, caiyinyu 写道:
>> I guess a v8 is better because the 17th patch (NEWS) needs a rebase
>> anyway.  But let's wait for Adhemerval's suggestion...
>
> It is up to your, if you are ok with my fixed branch I can install 
> otherwise
> you send a v8.
>
> --------------------
>
> I checked and I'm ok with the fixed branch.
>
> Waiting for other suggestions.
>
> Thanks.
>
>
>
> 在 2022/7/25 下午9:27, Adhemerval Zanella Netto 写道:
>>
>> On 24/07/22 06:49, WANG Xuerui wrote:
>>> Hi,
>>>
>>> On 7/19/22 09:20, caiyinyu wrote:
>>>> <snip>
>>>> 6. Test result: all passed (ifunc disable).
>>>>
>>>> Test with:
>>>>     Linux-5.19-rc4, Binutils-2.38, and GCC-12.1.
>>>>     glibc: 
>>>> https://github.com/loongson/glibc/tree/loongarch_2_36_upstream_v7
>>>>
>>>> Result (ifunc disable):
>>>> XPASS: conform/UNIX98/ndbm.h/linknamespace
>>>> XPASS: conform/XOPEN2K/ndbm.h/linknamespace
>>>> XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
>>>> XPASS: conform/XPG42/ndbm.h/linknamespace
>>>> UNSUPPORTED: crypt/cert
>>>> UNSUPPORTED: elf/tst-env-setuid
>>>> UNSUPPORTED: elf/tst-env-setuid-tunables
>>>> XPASS: elf/tst-protected1a
>>>> XPASS: elf/tst-protected1b
>>>> UNSUPPORTED: elf/tst-valgrind-smoke
>>>> UNSUPPORTED: misc/tst-adjtimex
>>>> UNSUPPORTED: misc/tst-clock_adjtime
>>>> UNSUPPORTED: misc/tst-ntp_adjtime
>>>> UNSUPPORTED: misc/tst-pkey
>>>> UNSUPPORTED: misc/tst-rseq
>>>> UNSUPPORTED: misc/tst-rseq-disable
>>>> UNSUPPORTED: nptl/test-cond-printers
>>>> UNSUPPORTED: nptl/test-condattr-printers
>>>> UNSUPPORTED: nptl/test-mutex-printers
>>>> UNSUPPORTED: nptl/test-mutexattr-printers
>>>> UNSUPPORTED: nptl/test-rwlock-printers
>>>> UNSUPPORTED: nptl/test-rwlockattr-printers
>>>> UNSUPPORTED: nptl/tst-pthread-gdb-attach
>>>> UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
>>>> UNSUPPORTED: nptl/tst-rseq-nptl
>>>> UNSUPPORTED: stdlib/tst-secure-getenv
>>>> UNSUPPORTED: time/tst-clock_settime
>>>> UNSUPPORTED: time/tst-settimeofday
>>>> Summary of test results:
>>>>      4535 PASS
>>>>        22 UNSUPPORTED
>>>>        12 XFAIL
>>>>         6 XPASS
>>> Thanks for your effort these days. I ran the test on Gentoo and this 
>>> is what I have found out:
>>>
>>> UNSUPPORTED: crypt/cert
>>> FAIL: elf/check-abi-libc
>>> FAIL: elf/ifuncmain1
>>> FAIL: elf/ifuncmain1pic
>>> FAIL: elf/ifuncmain1pie
>>> FAIL: elf/ifuncmain1staticpic
>>> FAIL: elf/ifuncmain1staticpie
>>> FAIL: elf/ifuncmain1vis
>>> FAIL: elf/ifuncmain1vispic
>>> FAIL: elf/ifuncmain1vispie
>>> FAIL: elf/ifuncmain2
>>> FAIL: elf/ifuncmain2pic
>>> FAIL: elf/ifuncmain3
>>> FAIL: elf/ifuncmain4
>>> FAIL: elf/ifuncmain5staticpic
>>> FAIL: elf/ifuncmain6pie
>>> FAIL: elf/ifuncmain7
>>> FAIL: elf/ifuncmain7pic
>>> FAIL: elf/ifuncmain7pie
>>> FAIL: elf/ifuncmain9
>>> FAIL: elf/ifuncmain9pic
>>> FAIL: elf/ifuncmain9pie
>>> UNSUPPORTED: elf/tst-env-setuid
>>> UNSUPPORTED: elf/tst-env-setuid-tunables
>>> FAIL: elf/tst-glibc-hwcaps-prepend-cache
>>> FAIL: elf/tst-ifunc-textrel
>>> FAIL: elf/tst-ldconfig-ld_so_conf-update
>>> XPASS: elf/tst-protected1a
>>> XPASS: elf/tst-protected1b
>>> UNSUPPORTED: elf/tst-valgrind-smoke
>>> FAIL: malloc/tst-free-errno-malloc-hugetlb1
>>> UNSUPPORTED: misc/tst-adjtimex
>>> UNSUPPORTED: misc/tst-clock_adjtime
>>> UNSUPPORTED: misc/tst-ntp_adjtime
>>> UNSUPPORTED: misc/tst-pkey
>>> UNSUPPORTED: misc/tst-rseq
>>> UNSUPPORTED: misc/tst-rseq-disable
>>> FAIL: nptl/tst-pthread-gdb-attach
>>> FAIL: nptl/tst-pthread-gdb-attach-static
>>> UNSUPPORTED: nptl/tst-rseq-nptl
>>> FAIL: nss/tst-nss-files-hosts-long
>>> UNSUPPORTED: resolv/tst-resolv-ai_idn
>>> UNSUPPORTED: resolv/tst-resolv-ai_idn-latin1
>>> UNSUPPORTED: stdlib/tst-secure-getenv
>>> UNSUPPORTED: time/tst-clock_settime
>>> UNSUPPORTED: time/tst-settimeofday
>>>
>>> Of these, the ifunc failures are "expected" by you, the 
>>> elf/check-abi-libc diff is trivial (maybe you just didn't rebase as 
>>> frequently):
>>>
>>> --- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 
>>> 2022-07-23 14:45:57.490029442 +0800
>>> +++ /home/xenon/src/glibc/build/libc.symlist    2022-07-24 
>>> 13:44:10.416642655 +0800
>>> @@ -496 +496 @@ GLIBC_2.36 _mcount F
>>> -GLIBC_2.36 _nl_default_dirname D 0x12
>>> +GLIBC_2.36 _nl_default_dirname D 0x17
>>> @@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
>>> +GLIBC_2.36 arc4random F
>>> +GLIBC_2.36 arc4random_buf F
>>> +GLIBC_2.36 arc4random_uniform F
>>>
>>> The others may need some love. Of course they're possibly because of 
>>> my particular environment (Gentoo is a little bit different than 
>>> "ordinary" distros like Debian/Fedora, and I already have to symlink 
>>> the libgcc_s.so and libstdc++.so to pass the nptl tests at all).
>> The 'elf/tst-glibc-hwcaps-prepend-cache' and 
>> 'elf/tst-ldconfig-ld_so_conf-update',
>> might worth to take a look, although they are not arch-specific and I 
>> think it is
>> more related to the test environment.
>>
>> Also, once you add the loongarch entry on release wiki [2], please 
>> the configure
>> options use to state ifunc needs to be explicit disabled.
>>
>>> Coming to code quality, there are obviously warts present, like the 
>>> lingering uses of the name "x" for $r21 and apparent lack of 
>>> assembly pseudo-insn sugar usages (e.g. no "move a, b" but always 
>>> "or a, b, zero"; the code must be directly descended from an 
>>> extremely early time when the assembler didn't have such support), 
>>> but at this point these cosmetic concerns are better fixed after 
>>> 2.36 to minimize churn prior to release. At a quick glance the ABI 
>>> is looking good. (There is a certain "__x" in bits/setjmp.h meant to 
>>> refer to r21, but __jmp_buf is not public API so I think we're safe 
>>> here.)
>>>
>> I agree that cosmetic issues should not interfere with loongarch64 
>> addition, we
>> can backport if required (although for such changes I also do not see 
>> much
>> point).
>>
>> I have create a branch which I think it is suitable for inclusion [1], I
>> have fixed the ABI issue due arc4random addition and some style issues
>> (trailing lines) that were triggering our pre-commit hooks..
>>
>>> I guess a v8 is better because the 17th patch (NEWS) needs a rebase
>>> anyway.  But let's wait for Adhemerval's suggestion...
>> It is up to your, if you are ok with my fixed branch I can install 
>> otherwise
>> you send a v8.
>>
>> [1] 
>> https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/loongarch64
>> [2] https://sourceware.org/glibc/wiki/Release/2.36


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-26 12:35       ` caiyinyu
@ 2022-07-26 12:42         ` Adhemerval Zanella Netto
  2022-07-26 14:00           ` Mark Wielaard
  0 siblings, 1 reply; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-26 12:42 UTC (permalink / raw)
  To: caiyinyu, WANG Xuerui, libc-alpha, joseph_myers, carlos

Thanks, I will check with Carlos on how to give you write access.

I plan to install loongarch support today.

On 26/07/22 09:35, caiyinyu wrote:
> 
> Also, once you add the loongarch entry on release wiki [2], please the configure
> options use to state ifunc needs to be explicit disabled.
> 
> ---------
> 
> I have created an account (caiyinyu@loongson.cn) on glibc wiki and we need to participate in the wiki to edit loongarch parts.
> 
> 
> 在 2022/7/25 下午10:14, caiyinyu 写道:
>>> I guess a v8 is better because the 17th patch (NEWS) needs a rebase
>>> anyway.  But let's wait for Adhemerval's suggestion...
>>
>> It is up to your, if you are ok with my fixed branch I can install otherwise
>> you send a v8.
>>
>> --------------------
>>
>> I checked and I'm ok with the fixed branch.
>>
>> Waiting for other suggestions.
>>
>> Thanks.
>>
>>
>>
>> 在 2022/7/25 下午9:27, Adhemerval Zanella Netto 写道:
>>>
>>> On 24/07/22 06:49, WANG Xuerui wrote:
>>>> Hi,
>>>>
>>>> On 7/19/22 09:20, caiyinyu wrote:
>>>>> <snip>
>>>>> 6. Test result: all passed (ifunc disable).
>>>>>
>>>>> Test with:
>>>>>     Linux-5.19-rc4, Binutils-2.38, and GCC-12.1.
>>>>>     glibc: https://github.com/loongson/glibc/tree/loongarch_2_36_upstream_v7
>>>>>
>>>>> Result (ifunc disable):
>>>>> XPASS: conform/UNIX98/ndbm.h/linknamespace
>>>>> XPASS: conform/XOPEN2K/ndbm.h/linknamespace
>>>>> XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
>>>>> XPASS: conform/XPG42/ndbm.h/linknamespace
>>>>> UNSUPPORTED: crypt/cert
>>>>> UNSUPPORTED: elf/tst-env-setuid
>>>>> UNSUPPORTED: elf/tst-env-setuid-tunables
>>>>> XPASS: elf/tst-protected1a
>>>>> XPASS: elf/tst-protected1b
>>>>> UNSUPPORTED: elf/tst-valgrind-smoke
>>>>> UNSUPPORTED: misc/tst-adjtimex
>>>>> UNSUPPORTED: misc/tst-clock_adjtime
>>>>> UNSUPPORTED: misc/tst-ntp_adjtime
>>>>> UNSUPPORTED: misc/tst-pkey
>>>>> UNSUPPORTED: misc/tst-rseq
>>>>> UNSUPPORTED: misc/tst-rseq-disable
>>>>> UNSUPPORTED: nptl/test-cond-printers
>>>>> UNSUPPORTED: nptl/test-condattr-printers
>>>>> UNSUPPORTED: nptl/test-mutex-printers
>>>>> UNSUPPORTED: nptl/test-mutexattr-printers
>>>>> UNSUPPORTED: nptl/test-rwlock-printers
>>>>> UNSUPPORTED: nptl/test-rwlockattr-printers
>>>>> UNSUPPORTED: nptl/tst-pthread-gdb-attach
>>>>> UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
>>>>> UNSUPPORTED: nptl/tst-rseq-nptl
>>>>> UNSUPPORTED: stdlib/tst-secure-getenv
>>>>> UNSUPPORTED: time/tst-clock_settime
>>>>> UNSUPPORTED: time/tst-settimeofday
>>>>> Summary of test results:
>>>>>      4535 PASS
>>>>>        22 UNSUPPORTED
>>>>>        12 XFAIL
>>>>>         6 XPASS
>>>> Thanks for your effort these days. I ran the test on Gentoo and this is what I have found out:
>>>>
>>>> UNSUPPORTED: crypt/cert
>>>> FAIL: elf/check-abi-libc
>>>> FAIL: elf/ifuncmain1
>>>> FAIL: elf/ifuncmain1pic
>>>> FAIL: elf/ifuncmain1pie
>>>> FAIL: elf/ifuncmain1staticpic
>>>> FAIL: elf/ifuncmain1staticpie
>>>> FAIL: elf/ifuncmain1vis
>>>> FAIL: elf/ifuncmain1vispic
>>>> FAIL: elf/ifuncmain1vispie
>>>> FAIL: elf/ifuncmain2
>>>> FAIL: elf/ifuncmain2pic
>>>> FAIL: elf/ifuncmain3
>>>> FAIL: elf/ifuncmain4
>>>> FAIL: elf/ifuncmain5staticpic
>>>> FAIL: elf/ifuncmain6pie
>>>> FAIL: elf/ifuncmain7
>>>> FAIL: elf/ifuncmain7pic
>>>> FAIL: elf/ifuncmain7pie
>>>> FAIL: elf/ifuncmain9
>>>> FAIL: elf/ifuncmain9pic
>>>> FAIL: elf/ifuncmain9pie
>>>> UNSUPPORTED: elf/tst-env-setuid
>>>> UNSUPPORTED: elf/tst-env-setuid-tunables
>>>> FAIL: elf/tst-glibc-hwcaps-prepend-cache
>>>> FAIL: elf/tst-ifunc-textrel
>>>> FAIL: elf/tst-ldconfig-ld_so_conf-update
>>>> XPASS: elf/tst-protected1a
>>>> XPASS: elf/tst-protected1b
>>>> UNSUPPORTED: elf/tst-valgrind-smoke
>>>> FAIL: malloc/tst-free-errno-malloc-hugetlb1
>>>> UNSUPPORTED: misc/tst-adjtimex
>>>> UNSUPPORTED: misc/tst-clock_adjtime
>>>> UNSUPPORTED: misc/tst-ntp_adjtime
>>>> UNSUPPORTED: misc/tst-pkey
>>>> UNSUPPORTED: misc/tst-rseq
>>>> UNSUPPORTED: misc/tst-rseq-disable
>>>> FAIL: nptl/tst-pthread-gdb-attach
>>>> FAIL: nptl/tst-pthread-gdb-attach-static
>>>> UNSUPPORTED: nptl/tst-rseq-nptl
>>>> FAIL: nss/tst-nss-files-hosts-long
>>>> UNSUPPORTED: resolv/tst-resolv-ai_idn
>>>> UNSUPPORTED: resolv/tst-resolv-ai_idn-latin1
>>>> UNSUPPORTED: stdlib/tst-secure-getenv
>>>> UNSUPPORTED: time/tst-clock_settime
>>>> UNSUPPORTED: time/tst-settimeofday
>>>>
>>>> Of these, the ifunc failures are "expected" by you, the elf/check-abi-libc diff is trivial (maybe you just didn't rebase as frequently):
>>>>
>>>> --- ../sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist 2022-07-23 14:45:57.490029442 +0800
>>>> +++ /home/xenon/src/glibc/build/libc.symlist    2022-07-24 13:44:10.416642655 +0800
>>>> @@ -496 +496 @@ GLIBC_2.36 _mcount F
>>>> -GLIBC_2.36 _nl_default_dirname D 0x12
>>>> +GLIBC_2.36 _nl_default_dirname D 0x17
>>>> @@ -541,0 +542,3 @@ GLIBC_2.36 alphasort64 F
>>>> +GLIBC_2.36 arc4random F
>>>> +GLIBC_2.36 arc4random_buf F
>>>> +GLIBC_2.36 arc4random_uniform F
>>>>
>>>> The others may need some love. Of course they're possibly because of my particular environment (Gentoo is a little bit different than "ordinary" distros like Debian/Fedora, and I already have to symlink the libgcc_s.so and libstdc++.so to pass the nptl tests at all).
>>> The 'elf/tst-glibc-hwcaps-prepend-cache' and 'elf/tst-ldconfig-ld_so_conf-update',
>>> might worth to take a look, although they are not arch-specific and I think it is
>>> more related to the test environment.
>>>
>>> Also, once you add the loongarch entry on release wiki [2], please the configure
>>> options use to state ifunc needs to be explicit disabled.
>>>
>>>> Coming to code quality, there are obviously warts present, like the lingering uses of the name "x" for $r21 and apparent lack of assembly pseudo-insn sugar usages (e.g. no "move a, b" but always "or a, b, zero"; the code must be directly descended from an extremely early time when the assembler didn't have such support), but at this point these cosmetic concerns are better fixed after 2.36 to minimize churn prior to release. At a quick glance the ABI is looking good. (There is a certain "__x" in bits/setjmp.h meant to refer to r21, but __jmp_buf is not public API so I think we're safe here.)
>>>>
>>> I agree that cosmetic issues should not interfere with loongarch64 addition, we
>>> can backport if required (although for such changes I also do not see much
>>> point).
>>>
>>> I have create a branch which I think it is suitable for inclusion [1], I
>>> have fixed the ABI issue due arc4random addition and some style issues
>>> (trailing lines) that were triggering our pre-commit hooks..
>>>
>>>> I guess a v8 is better because the 17th patch (NEWS) needs a rebase
>>>> anyway.  But let's wait for Adhemerval's suggestion...
>>> It is up to your, if you are ok with my fixed branch I can install otherwise
>>> you send a v8.
>>>
>>> [1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/loongarch64
>>> [2] https://sourceware.org/glibc/wiki/Release/2.36
> 

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 00/13] GLIBC LoongArch PATCHES
  2022-07-26 12:42         ` Adhemerval Zanella Netto
@ 2022-07-26 14:00           ` Mark Wielaard
  0 siblings, 0 replies; 36+ messages in thread
From: Mark Wielaard @ 2022-07-26 14:00 UTC (permalink / raw)
  To: Adhemerval Zanella Netto
  Cc: caiyinyu, WANG Xuerui, libc-alpha, joseph_myers, carlos

On Tue, Jul 26, 2022 at 09:42:27AM -0300, Adhemerval Zanella Netto via Libc-alpha wrote:
> On 26/07/22 09:35, caiyinyu wrote:
> > I have created an account (caiyinyu@loongson.cn) on glibc wiki and
> > we need to participate in the wiki to edit loongarch parts.
> > 
> Thanks, I will check with Carlos on how to give you write access.

Someone with EditorGroup permissions needs to add the account to
https://sourceware.org/glibc/wiki/EditorGroup

Cheers,

Mark

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 07/13] LoongArch: Linux Syscall Interface
  2022-07-19  1:20 ` [PATCH v7 07/13] LoongArch: Linux Syscall Interface caiyinyu
  2022-07-20 14:35   ` Adhemerval Zanella Netto
@ 2022-07-27  5:27   ` WANG Xuerui
  2022-07-27  5:32     ` WANG Xuerui
  1 sibling, 1 reply; 36+ messages in thread
From: WANG Xuerui @ 2022-07-27  5:27 UTC (permalink / raw)
  To: caiyinyu, adhemerval.zanella, libc-alpha, joseph_myers, carlos, i.swmail

Wait. I almost missed this, glad I took an extra look before starting 
afternoon's $DAY_JOB work...

On 2022/7/19 09:20, caiyinyu wrote:
> |+#define VDSO_NAME "LINUX_2.6" +#define VDSO_HASH 61765110|

|According to Linux sources [1], this should be "LINUX_5.10" instead, 
and the hash should be 182947696. The current value is for the old world 
and will lead to the vDSO being essentially wasted.
|

|To the Release Manager: do this need a proper patch, or if this can be 
fixed up in the branch pending inclusion? I can prepare one in short 
order if that's the proper way.
|

|[1]: 
https://github.com/torvalds/linux/blob/v5.19-rc8/arch/loongarch/vdso/vdso.lds.S#L59
|



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 07/13] LoongArch: Linux Syscall Interface
  2022-07-27  5:27   ` WANG Xuerui
@ 2022-07-27  5:32     ` WANG Xuerui
  2022-07-27 11:16       ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 36+ messages in thread
From: WANG Xuerui @ 2022-07-27  5:32 UTC (permalink / raw)
  To: WANG Xuerui, caiyinyu, adhemerval.zanella, libc-alpha,
	joseph_myers, carlos

On 2022/7/27 13:27, WANG Xuerui wrote:
> Wait. I almost missed this, glad I took an extra look before starting 
> afternoon's $DAY_JOB work...
>
> On 2022/7/19 09:20, caiyinyu wrote:
>> |+#define VDSO_NAME "LINUX_2.6" +#define VDSO_HASH 61765110|
>
> |According to Linux sources [1], this should be "LINUX_5.10" instead, 
> and the hash should be 182947696. The current value is for the old 
> world and will lead to the vDSO being essentially wasted.
> |
>
> |To the Release Manager: do this need a proper patch, or if this can 
> be fixed up in the branch pending inclusion? I can prepare one in 
> short order if that's the proper way.
> |
>
> |[1]: 
> https://github.com/torvalds/linux/blob/v5.19-rc8/arch/loongarch/vdso/vdso.lds.S#L59
> |
>
>
Ah. I just saw the branch merged in master.

But a quick vdsotest shows the libc version's performance on par with 
correct vDSO calls:

clock-gettime-monotonic: syscall: 183 nsec/call
clock-gettime-monotonic:    libc: 44 nsec/call
clock-gettime-monotonic:    vdso: 34 nsec/call
clock-getres-monotonic: syscall: 152 nsec/call
clock-getres-monotonic:    libc: 19 nsec/call
clock-getres-monotonic:    vdso: 14 nsec/call
clock-gettime-monotonic-coarse: syscall: 172 nsec/call
clock-gettime-monotonic-coarse:    libc: 39 nsec/call
clock-gettime-monotonic-coarse:    vdso: 29 nsec/call
clock-getres-monotonic-coarse: syscall: 154 nsec/call
clock-getres-monotonic-coarse:    libc: 18 nsec/call
clock-getres-monotonic-coarse:    vdso: 14 nsec/call
clock-gettime-monotonic-raw: syscall: 181 nsec/call
clock-gettime-monotonic-raw:    libc: 45 nsec/call
clock-gettime-monotonic-raw:    vdso: 36 nsec/call
clock-getres-monotonic-raw: syscall: 151 nsec/call
clock-getres-monotonic-raw:    libc: 19 nsec/call
clock-getres-monotonic-raw:    vdso: 14 nsec/call
clock-gettime-tai: syscall: 187 nsec/call
clock-gettime-tai:    libc: 44 nsec/call
clock-gettime-tai:    vdso: 34 nsec/call
clock-getres-tai: syscall: 151 nsec/call
clock-getres-tai:    libc: 19 nsec/call
clock-getres-tai:    vdso: 14 nsec/call
clock-gettime-boottime: syscall: 184 nsec/call
clock-gettime-boottime:    libc: 44 nsec/call
clock-gettime-boottime:    vdso: 34 nsec/call
clock-getres-boottime: syscall: 151 nsec/call
clock-getres-boottime:    libc: 19 nsec/call
clock-getres-boottime:    vdso: 14 nsec/call
clock-gettime-realtime: syscall: 181 nsec/call
clock-gettime-realtime:    libc: 44 nsec/call
clock-gettime-realtime:    vdso: 34 nsec/call
clock-getres-realtime: syscall: 151 nsec/call
clock-getres-realtime:    libc: 19 nsec/call
clock-getres-realtime:    vdso: 14 nsec/call
clock-gettime-realtime-coarse: syscall: 179 nsec/call
clock-gettime-realtime-coarse:    libc: 40 nsec/call
clock-gettime-realtime-coarse:    vdso: 29 nsec/call
clock-getres-realtime-coarse: syscall: 154 nsec/call
clock-getres-realtime-coarse:    libc: 18 nsec/call
clock-getres-realtime-coarse:    vdso: 14 nsec/call
getcpu: syscall: 134 nsec/call
getcpu:    libc: 20 nsec/call
getcpu:    vdso: 13 nsec/call
gettimeofday: syscall: 171 nsec/call
gettimeofday:    libc: 47 nsec/call
gettimeofday:    vdso: 33 nsec/call

Which is getting interesting. (This may explain why nobody noticed 
before the merge.) I think we should still "fix" it, but at this point 
I'm starting to doubt whether it's a problem in the first place...


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 07/13] LoongArch: Linux Syscall Interface
  2022-07-27  5:32     ` WANG Xuerui
@ 2022-07-27 11:16       ` Adhemerval Zanella Netto
  2022-07-27 13:01         ` WANG Xuerui
  0 siblings, 1 reply; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-27 11:16 UTC (permalink / raw)
  To: WANG Xuerui, caiyinyu, libc-alpha, joseph_myers, carlos



On 27/07/22 02:32, WANG Xuerui wrote:
> On 2022/7/27 13:27, WANG Xuerui wrote:
>> Wait. I almost missed this, glad I took an extra look before starting afternoon's $DAY_JOB work...
>>
>> On 2022/7/19 09:20, caiyinyu wrote:
>>> |+#define VDSO_NAME "LINUX_2.6" +#define VDSO_HASH 61765110|
>>
>> |According to Linux sources [1], this should be "LINUX_5.10" instead, and the hash should be 182947696. The current value is for the old world and will lead to the vDSO being essentially wasted.
>> |
>>
>> |To the Release Manager: do this need a proper patch, or if this can be fixed up in the branch pending inclusion? I can prepare one in short order if that's the proper way.
>> |
>>
>> |[1]: https://github.com/torvalds/linux/blob/v5.19-rc8/arch/loongarch/vdso/vdso.lds.S#L59
>> |
>>
>>
> Ah. I just saw the branch merged in master.
> 
> But a quick vdsotest shows the libc version's performance on par with correct vDSO calls:
> 
> clock-gettime-monotonic: syscall: 183 nsec/call
> clock-gettime-monotonic:    libc: 44 nsec/call
> clock-gettime-monotonic:    vdso: 34 nsec/call
> clock-getres-monotonic: syscall: 152 nsec/call
> clock-getres-monotonic:    libc: 19 nsec/call
> clock-getres-monotonic:    vdso: 14 nsec/call
> clock-gettime-monotonic-coarse: syscall: 172 nsec/call
> clock-gettime-monotonic-coarse:    libc: 39 nsec/call
> clock-gettime-monotonic-coarse:    vdso: 29 nsec/call
> clock-getres-monotonic-coarse: syscall: 154 nsec/call
> clock-getres-monotonic-coarse:    libc: 18 nsec/call
> clock-getres-monotonic-coarse:    vdso: 14 nsec/call
> clock-gettime-monotonic-raw: syscall: 181 nsec/call
> clock-gettime-monotonic-raw:    libc: 45 nsec/call
> clock-gettime-monotonic-raw:    vdso: 36 nsec/call
> clock-getres-monotonic-raw: syscall: 151 nsec/call
> clock-getres-monotonic-raw:    libc: 19 nsec/call
> clock-getres-monotonic-raw:    vdso: 14 nsec/call
> clock-gettime-tai: syscall: 187 nsec/call
> clock-gettime-tai:    libc: 44 nsec/call
> clock-gettime-tai:    vdso: 34 nsec/call
> clock-getres-tai: syscall: 151 nsec/call
> clock-getres-tai:    libc: 19 nsec/call
> clock-getres-tai:    vdso: 14 nsec/call
> clock-gettime-boottime: syscall: 184 nsec/call
> clock-gettime-boottime:    libc: 44 nsec/call
> clock-gettime-boottime:    vdso: 34 nsec/call
> clock-getres-boottime: syscall: 151 nsec/call
> clock-getres-boottime:    libc: 19 nsec/call
> clock-getres-boottime:    vdso: 14 nsec/call
> clock-gettime-realtime: syscall: 181 nsec/call
> clock-gettime-realtime:    libc: 44 nsec/call
> clock-gettime-realtime:    vdso: 34 nsec/call
> clock-getres-realtime: syscall: 151 nsec/call
> clock-getres-realtime:    libc: 19 nsec/call
> clock-getres-realtime:    vdso: 14 nsec/call
> clock-gettime-realtime-coarse: syscall: 179 nsec/call
> clock-gettime-realtime-coarse:    libc: 40 nsec/call
> clock-gettime-realtime-coarse:    vdso: 29 nsec/call
> clock-getres-realtime-coarse: syscall: 154 nsec/call
> clock-getres-realtime-coarse:    libc: 18 nsec/call
> clock-getres-realtime-coarse:    vdso: 14 nsec/call
> getcpu: syscall: 134 nsec/call
> getcpu:    libc: 20 nsec/call
> getcpu:    vdso: 13 nsec/call
> gettimeofday: syscall: 171 nsec/call
> gettimeofday:    libc: 47 nsec/call
> gettimeofday:    vdso: 33 nsec/call
> 
> Which is getting interesting. (This may explain why nobody noticed before the merge.) I think we should still "fix" it, but at this point I'm starting to doubt whether it's a problem in the first place...
> 

So does it this need to be fixed in the end? The numbers indicates that vDSO is indeed
being used.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 07/13] LoongArch: Linux Syscall Interface
  2022-07-27 11:16       ` Adhemerval Zanella Netto
@ 2022-07-27 13:01         ` WANG Xuerui
  2022-07-27 19:22           ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 36+ messages in thread
From: WANG Xuerui @ 2022-07-27 13:01 UTC (permalink / raw)
  To: Adhemerval Zanella Netto, WANG Xuerui, caiyinyu, libc-alpha,
	joseph_myers, carlos


On 2022/7/27 19:16, Adhemerval Zanella Netto wrote:
>
> On 27/07/22 02:32, WANG Xuerui wrote:
>> On 2022/7/27 13:27, WANG Xuerui wrote:
>>> Wait. I almost missed this, glad I took an extra look before starting afternoon's $DAY_JOB work...
>>>
>>> On 2022/7/19 09:20, caiyinyu wrote:
>>>> |+#define VDSO_NAME "LINUX_2.6" +#define VDSO_HASH 61765110|
>>> |According to Linux sources [1], this should be "LINUX_5.10" instead, and the hash should be 182947696. The current value is for the old world and will lead to the vDSO being essentially wasted.
>>> |
>>>
>>> |To the Release Manager: do this need a proper patch, or if this can be fixed up in the branch pending inclusion? I can prepare one in short order if that's the proper way.
>>> |
>>>
>>> |[1]: https://github.com/torvalds/linux/blob/v5.19-rc8/arch/loongarch/vdso/vdso.lds.S#L59
>>> |
>>>
>>>
>> Ah. I just saw the branch merged in master.
>>
>> But a quick vdsotest shows the libc version's performance on par with correct vDSO calls:
>>
>> clock-gettime-monotonic: syscall: 183 nsec/call
>> clock-gettime-monotonic:    libc: 44 nsec/call
>> clock-gettime-monotonic:    vdso: 34 nsec/call
>> clock-getres-monotonic: syscall: 152 nsec/call
>> clock-getres-monotonic:    libc: 19 nsec/call
>> clock-getres-monotonic:    vdso: 14 nsec/call
>> clock-gettime-monotonic-coarse: syscall: 172 nsec/call
>> clock-gettime-monotonic-coarse:    libc: 39 nsec/call
>> clock-gettime-monotonic-coarse:    vdso: 29 nsec/call
>> clock-getres-monotonic-coarse: syscall: 154 nsec/call
>> clock-getres-monotonic-coarse:    libc: 18 nsec/call
>> clock-getres-monotonic-coarse:    vdso: 14 nsec/call
>> clock-gettime-monotonic-raw: syscall: 181 nsec/call
>> clock-gettime-monotonic-raw:    libc: 45 nsec/call
>> clock-gettime-monotonic-raw:    vdso: 36 nsec/call
>> clock-getres-monotonic-raw: syscall: 151 nsec/call
>> clock-getres-monotonic-raw:    libc: 19 nsec/call
>> clock-getres-monotonic-raw:    vdso: 14 nsec/call
>> clock-gettime-tai: syscall: 187 nsec/call
>> clock-gettime-tai:    libc: 44 nsec/call
>> clock-gettime-tai:    vdso: 34 nsec/call
>> clock-getres-tai: syscall: 151 nsec/call
>> clock-getres-tai:    libc: 19 nsec/call
>> clock-getres-tai:    vdso: 14 nsec/call
>> clock-gettime-boottime: syscall: 184 nsec/call
>> clock-gettime-boottime:    libc: 44 nsec/call
>> clock-gettime-boottime:    vdso: 34 nsec/call
>> clock-getres-boottime: syscall: 151 nsec/call
>> clock-getres-boottime:    libc: 19 nsec/call
>> clock-getres-boottime:    vdso: 14 nsec/call
>> clock-gettime-realtime: syscall: 181 nsec/call
>> clock-gettime-realtime:    libc: 44 nsec/call
>> clock-gettime-realtime:    vdso: 34 nsec/call
>> clock-getres-realtime: syscall: 151 nsec/call
>> clock-getres-realtime:    libc: 19 nsec/call
>> clock-getres-realtime:    vdso: 14 nsec/call
>> clock-gettime-realtime-coarse: syscall: 179 nsec/call
>> clock-gettime-realtime-coarse:    libc: 40 nsec/call
>> clock-gettime-realtime-coarse:    vdso: 29 nsec/call
>> clock-getres-realtime-coarse: syscall: 154 nsec/call
>> clock-getres-realtime-coarse:    libc: 18 nsec/call
>> clock-getres-realtime-coarse:    vdso: 14 nsec/call
>> getcpu: syscall: 134 nsec/call
>> getcpu:    libc: 20 nsec/call
>> getcpu:    vdso: 13 nsec/call
>> gettimeofday: syscall: 171 nsec/call
>> gettimeofday:    libc: 47 nsec/call
>> gettimeofday:    vdso: 33 nsec/call
>>
>> Which is getting interesting. (This may explain why nobody noticed before the merge.) I think we should still "fix" it, but at this point I'm starting to doubt whether it's a problem in the first place...
>>
> So does it this need to be fixed in the end? The numbers indicates that vDSO is indeed
> being used.

If striving for purity, the bug should definitely get fixed, but again I 
saw in sysdeps/unix/sysv/linux/dl-vdso.h that the dl_vdso_vsym makes use 
of dl_lookup_symbol_x, which states in its docstring:

 > Search loaded objects' symbol tables for a definition of the symbol 
UNDEF_NAME, perhaps with a requested version for the symbol.

I dug a little deeper but can't really verify the "perhaps" part, but 
judging from the doc alone the current behavior may well be expected. 
Maybe you or someone else more familiar with the details could enlighten 
me on this, but indeed vDSO must actually be effective for the 
order-of-magnitude improvement in numbers, hence the inconsistency 
should not be adversely affecting normal operation besides being a minor 
nuisance. We can fix it after 2.36 gets released then.


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v7 07/13] LoongArch: Linux Syscall Interface
  2022-07-27 13:01         ` WANG Xuerui
@ 2022-07-27 19:22           ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 36+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-27 19:22 UTC (permalink / raw)
  To: WANG Xuerui, caiyinyu, libc-alpha, joseph_myers, carlos



On 27/07/22 10:01, WANG Xuerui wrote:
> 
> On 2022/7/27 19:16, Adhemerval Zanella Netto wrote:
>>
>> On 27/07/22 02:32, WANG Xuerui wrote:
>>> On 2022/7/27 13:27, WANG Xuerui wrote:
>>>> Wait. I almost missed this, glad I took an extra look before starting afternoon's $DAY_JOB work...
>>>>
>>>> On 2022/7/19 09:20, caiyinyu wrote:
>>>>> |+#define VDSO_NAME "LINUX_2.6" +#define VDSO_HASH 61765110|
>>>> |According to Linux sources [1], this should be "LINUX_5.10" instead, and the hash should be 182947696. The current value is for the old world and will lead to the vDSO being essentially wasted.
>>>> |
>>>>
>>>> |To the Release Manager: do this need a proper patch, or if this can be fixed up in the branch pending inclusion? I can prepare one in short order if that's the proper way.
>>>> |
>>>>
>>>> |[1]: https://github.com/torvalds/linux/blob/v5.19-rc8/arch/loongarch/vdso/vdso.lds.S#L59
>>>> |
>>>>
>>>>
>>> Ah. I just saw the branch merged in master.
>>>
>>> But a quick vdsotest shows the libc version's performance on par with correct vDSO calls:
>>>
>>> clock-gettime-monotonic: syscall: 183 nsec/call
>>> clock-gettime-monotonic:    libc: 44 nsec/call
>>> clock-gettime-monotonic:    vdso: 34 nsec/call
>>> clock-getres-monotonic: syscall: 152 nsec/call
>>> clock-getres-monotonic:    libc: 19 nsec/call
>>> clock-getres-monotonic:    vdso: 14 nsec/call
>>> clock-gettime-monotonic-coarse: syscall: 172 nsec/call
>>> clock-gettime-monotonic-coarse:    libc: 39 nsec/call
>>> clock-gettime-monotonic-coarse:    vdso: 29 nsec/call
>>> clock-getres-monotonic-coarse: syscall: 154 nsec/call
>>> clock-getres-monotonic-coarse:    libc: 18 nsec/call
>>> clock-getres-monotonic-coarse:    vdso: 14 nsec/call
>>> clock-gettime-monotonic-raw: syscall: 181 nsec/call
>>> clock-gettime-monotonic-raw:    libc: 45 nsec/call
>>> clock-gettime-monotonic-raw:    vdso: 36 nsec/call
>>> clock-getres-monotonic-raw: syscall: 151 nsec/call
>>> clock-getres-monotonic-raw:    libc: 19 nsec/call
>>> clock-getres-monotonic-raw:    vdso: 14 nsec/call
>>> clock-gettime-tai: syscall: 187 nsec/call
>>> clock-gettime-tai:    libc: 44 nsec/call
>>> clock-gettime-tai:    vdso: 34 nsec/call
>>> clock-getres-tai: syscall: 151 nsec/call
>>> clock-getres-tai:    libc: 19 nsec/call
>>> clock-getres-tai:    vdso: 14 nsec/call
>>> clock-gettime-boottime: syscall: 184 nsec/call
>>> clock-gettime-boottime:    libc: 44 nsec/call
>>> clock-gettime-boottime:    vdso: 34 nsec/call
>>> clock-getres-boottime: syscall: 151 nsec/call
>>> clock-getres-boottime:    libc: 19 nsec/call
>>> clock-getres-boottime:    vdso: 14 nsec/call
>>> clock-gettime-realtime: syscall: 181 nsec/call
>>> clock-gettime-realtime:    libc: 44 nsec/call
>>> clock-gettime-realtime:    vdso: 34 nsec/call
>>> clock-getres-realtime: syscall: 151 nsec/call
>>> clock-getres-realtime:    libc: 19 nsec/call
>>> clock-getres-realtime:    vdso: 14 nsec/call
>>> clock-gettime-realtime-coarse: syscall: 179 nsec/call
>>> clock-gettime-realtime-coarse:    libc: 40 nsec/call
>>> clock-gettime-realtime-coarse:    vdso: 29 nsec/call
>>> clock-getres-realtime-coarse: syscall: 154 nsec/call
>>> clock-getres-realtime-coarse:    libc: 18 nsec/call
>>> clock-getres-realtime-coarse:    vdso: 14 nsec/call
>>> getcpu: syscall: 134 nsec/call
>>> getcpu:    libc: 20 nsec/call
>>> getcpu:    vdso: 13 nsec/call
>>> gettimeofday: syscall: 171 nsec/call
>>> gettimeofday:    libc: 47 nsec/call
>>> gettimeofday:    vdso: 33 nsec/call
>>>
>>> Which is getting interesting. (This may explain why nobody noticed before the merge.) I think we should still "fix" it, but at this point I'm starting to doubt whether it's a problem in the first place...
>>>
>> So does it this need to be fixed in the end? The numbers indicates that vDSO is indeed
>> being used.
> 
> If striving for purity, the bug should definitely get fixed, but again I saw in sysdeps/unix/sysv/linux/dl-vdso.h that the dl_vdso_vsym makes use of dl_lookup_symbol_x, which states in its docstring:
> 
>> Search loaded objects' symbol tables for a definition of the symbol UNDEF_NAME, perhaps with a requested version for the symbol.
> 
> I dug a little deeper but can't really verify the "perhaps" part, but judging from the doc alone the current behavior may well be expected. Maybe you or someone else more familiar with the details could enlighten me on this, but indeed vDSO must actually be effective for the order-of-magnitude improvement in numbers, hence the inconsistency should not be adversely affecting normal operation besides being a minor nuisance. We can fix it after 2.36 gets released then.
> 

Alright, if you do think this is required for 2.36 I think it should be ok
since is a localized change for loongarch.

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2022-07-27 19:23 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19  1:20 [PATCH v7 00/13] GLIBC LoongArch PATCHES caiyinyu
2022-07-19  1:20 ` [PATCH v7 01/13] LoongArch: Add LoongArch entries to config.h.in caiyinyu
2022-07-21 21:02   ` Adhemerval Zanella Netto
2022-07-19  1:20 ` [PATCH v7 02/13] LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py caiyinyu
2022-07-21 21:02   ` Adhemerval Zanella Netto
2022-07-19  1:20 ` [PATCH v7 03/13] LoongArch: ABI Implementation caiyinyu
2022-07-20 12:29   ` Adhemerval Zanella Netto
2022-07-19  1:20 ` [PATCH v7 04/13] LoongArch: Thread-Local Storage Support caiyinyu
2022-07-20 14:34   ` Adhemerval Zanella Netto
2022-07-19  1:20 ` [PATCH v7 05/13] LoongArch: Generic <math.h> and soft-fp Routines caiyinyu
2022-07-20 13:04   ` Adhemerval Zanella Netto
2022-07-19  1:20 ` [PATCH v7 06/13] LoongArch: Atomic and Locking Routines caiyinyu
2022-07-20 14:32   ` Adhemerval Zanella Netto
2022-07-19  1:20 ` [PATCH v7 07/13] LoongArch: Linux Syscall Interface caiyinyu
2022-07-20 14:35   ` Adhemerval Zanella Netto
2022-07-27  5:27   ` WANG Xuerui
2022-07-27  5:32     ` WANG Xuerui
2022-07-27 11:16       ` Adhemerval Zanella Netto
2022-07-27 13:01         ` WANG Xuerui
2022-07-27 19:22           ` Adhemerval Zanella Netto
2022-07-19  1:20 ` [PATCH v7 08/13] LoongArch: Linux ABI caiyinyu
2022-07-20 16:37   ` Adhemerval Zanella Netto
2022-07-20 17:19 ` [PATCH v7 00/13] GLIBC LoongArch PATCHES Adhemerval Zanella Netto
2022-07-21  2:44   ` caiyinyu
2022-07-24  9:49 ` WANG Xuerui
2022-07-24 11:51   ` Xi Ruoyao
2022-07-24 12:02     ` WANG Xuerui
2022-07-25  8:21       ` caiyinyu
2022-07-25  8:28         ` Xi Ruoyao
2022-07-25  1:58     ` 刘振松
2022-07-25  8:01       ` Xi Ruoyao
2022-07-25 13:27   ` Adhemerval Zanella Netto
2022-07-25 14:14     ` caiyinyu
2022-07-26 12:35       ` caiyinyu
2022-07-26 12:42         ` Adhemerval Zanella Netto
2022-07-26 14:00           ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).