From 04530399d520ab559ea7a0d44de4605ffa9821f7 Mon Sep 17 00:00:00 2001 From: Chang Yang Date: Wed, 13 Mar 2024 10:28:27 +0800 Subject: [PATCH] feat: init package --- README.md | 1 - debian/changelog | 30 +- debian/compat | 1 - debian/control | 37 +- debian/copyright | 22 - debian/install | 2 + ...0001-add-old-world-abi-compatibility.patch | 454 ++++++++++ .../patches/glibc/0002-add-sigset-ops.patch | 354 ++++++++ .../glibc/0003-add-signal-functions.patch | 235 ++++++ .../0004-add-sigaction-ucontext-compat.patch | 786 ++++++++++++++++++ ...dd-stubs-for-signal-related-io-funcs.patch | 83 ++ ...006-add-syscall-fallback-for-stat-at.patch | 350 ++++++++ .../glibc/0007-add-more-pthread-symbols.patch | 467 +++++++++++ ...ove-clone3-for-compatibility-with-qq.patch | 27 + .../glibc/0009-prepend-trusted-dirs.patch | 95 +++ .../glibc/0010-Add-___brk_addr-symbol.patch | 28 + debian/patches/glibc/local-ld-multiarch.diff | 51 ++ debian/patches/glibc/local-remove-manual.diff | 218 +++++ debian/patches/glibc/series | 12 + .../patchelf/0001-add-remap-symvers.patch | 483 +++++++++++ debian/patches/patchelf/series | 1 + debian/rules | 252 +++++- 22 files changed, 3947 insertions(+), 42 deletions(-) delete mode 100644 README.md delete mode 100644 debian/compat delete mode 100644 debian/copyright create mode 100644 debian/install create mode 100644 debian/patches/glibc/0001-add-old-world-abi-compatibility.patch create mode 100644 debian/patches/glibc/0002-add-sigset-ops.patch create mode 100644 debian/patches/glibc/0003-add-signal-functions.patch create mode 100644 debian/patches/glibc/0004-add-sigaction-ucontext-compat.patch create mode 100644 debian/patches/glibc/0005-add-stubs-for-signal-related-io-funcs.patch create mode 100644 debian/patches/glibc/0006-add-syscall-fallback-for-stat-at.patch create mode 100644 debian/patches/glibc/0007-add-more-pthread-symbols.patch create mode 100644 debian/patches/glibc/0008-remove-clone3-for-compatibility-with-qq.patch create mode 100644 debian/patches/glibc/0009-prepend-trusted-dirs.patch create mode 100644 debian/patches/glibc/0010-Add-___brk_addr-symbol.patch create mode 100644 debian/patches/glibc/local-ld-multiarch.diff create mode 100644 debian/patches/glibc/local-remove-manual.diff create mode 100644 debian/patches/glibc/series create mode 100644 debian/patches/patchelf/0001-add-remap-symvers.patch create mode 100644 debian/patches/patchelf/series diff --git a/README.md b/README.md deleted file mode 100644 index 9ebb84009..000000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# template-repository \ No newline at end of file diff --git a/debian/changelog b/debian/changelog index bad88e262..5680fec50 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,29 @@ -template-repository (1.0-1) unstable; urgency=medium +liblol (0.1.4-1) unstable; urgency=medium - * Initial release + * Release 0.1.4-1 - -- Tsic404 Sat, 28 Jan 2023 13:46:49 +0800 + -- Miao Wang Fri, 01 Mar 2024 23:31:00 +0800 + +liblol (0.1.4~pre4-1) unstable; urgency=medium + + * glibc: also add syscall fallback for fstatat + + -- Miao Wang Tue, 20 Feb 2024 15:22:00 +0800 + +liblol (0.1.4~pre3-1) unstable; urgency=medium + + * make libc.so.6 executable + + -- Miao Wang Thu, 08 Feb 2024 16:09:00 +0800 + +liblol (0.1.4~pre2-1) unstable; urgency=medium + + * new upstream version + + -- Miao Wang Sun, 28 Jan 2024 08:07:00 +0800 + +liblol (0.1.3-1) unstable; urgency=medium + + * Initial upload + + -- Miao Wang Sat, 27 Jan 2024 18:09:00 +0800 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index b4de39476..000000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -11 diff --git a/debian/control b/debian/control index cb7c4a069..9664a66af 100644 --- a/debian/control +++ b/debian/control @@ -1,15 +1,26 @@ -Source: template-repository -Section: unknown +Source: liblol +Section: otherosfs Priority: optional -Maintainer: Tsic404 -Build-Depends: debhelper (>= 11) -Standards-Version: 4.1.3 -Homepage: https://github.com/deepin-community/template-repository -#Vcs-Browser: https://salsa.debian.org/debian/deepin-community-template-repository -#Vcs-Git: https://salsa.debian.org/debian/deepin-community-template-repository.git +Maintainer: Miao Wang +Build-Depends: debhelper-compat (= 13), + libstdc++6, + quilt, + bison, + gawk, + python3, +Standards-Version: 4.6.2 +Homepage: https://github.com/AOSC-Dev/liblol -Package: template-repository -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: - +Package: liblol +Architecture: loong64 +Multi-Arch: foreign +Depends: ${misc:Depends}, + ${shlibs:Depends}, + libstdc++6, + libc6 (>= 2.36), + libc6 (<< ${glibcVer}.1~), +Conflicts: glibc, +Recommends: liblol-dkms, +Description: Compatibility layer for old world applications + This package contains a Compatibility layer for old world + applications on new world loongarch64 platform. diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index f5c805eec..000000000 --- a/debian/copyright +++ /dev/null @@ -1,22 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: template-repository -Source: https://github.com/deepin-community/template-repository - -Files: * -Copyright: 2023 Tsic404 -License: GPL-2+ - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - . - This package 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 General Public License for more details. - . - You should have received a copy of the GNU General Public License - along with this program. If not, see - . - On Debian systems, the complete text of the GNU General - Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". diff --git a/debian/install b/debian/install new file mode 100644 index 000000000..3cf73aaa5 --- /dev/null +++ b/debian/install @@ -0,0 +1,2 @@ +/lib64/ +/usr/lib/loongarch64-debian-linux-gnuow diff --git a/debian/patches/glibc/0001-add-old-world-abi-compatibility.patch b/debian/patches/glibc/0001-add-old-world-abi-compatibility.patch new file mode 100644 index 000000000..b42ab22f8 --- /dev/null +++ b/debian/patches/glibc/0001-add-old-world-abi-compatibility.patch @@ -0,0 +1,454 @@ +From d55a93c9639ea23d9b62a1d01cadedefeefb67ae Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sat, 13 Jan 2024 03:23:48 +0800 +Subject: [PATCH 01/10] add old world abi compatibility + +--- + login/Makefile | 8 +- + nptl/Versions | 261 ++++++++++++++++++ + scripts/firstversions.awk | 9 +- + scripts/versions.awk | 2 +- + sunrpc/Makefile | 4 +- + sysdeps/nptl/Makeconfig | 1 + + sysdeps/unix/sysv/linux/loongarch/Versions | 36 +++ + .../unix/sysv/linux/loongarch/shlib-versions | 11 +- + sysdeps/unix/sysv/linux/loongarch/statx_cp.c | 4 + + 9 files changed, 319 insertions(+), 17 deletions(-) + create mode 100644 sysdeps/unix/sysv/linux/loongarch/Versions + create mode 100644 sysdeps/unix/sysv/linux/loongarch/statx_cp.c + +diff --git a/login/Makefile b/login/Makefile +index 74216cbc..5f5f2427 100644 +--- a/login/Makefile ++++ b/login/Makefile +@@ -49,7 +49,7 @@ tests := tst-utmp tst-utmpx tst-grantpt tst-ptsname tst-getlogin tst-updwtmpx \ + # Empty compatibility library for old binaries. + extra-libs := libutil + extra-libs-others := $(extra-libs) +-ifeq ($(have-GLIBC_2.33),yes) ++#ifeq ($(have-GLIBC_2.33),yes) + libutil-routines := libutil-compat + libutil-shared-only-routines := libutil-compat + +@@ -57,9 +57,9 @@ libutil-shared-only-routines := libutil-compat + # link is not installed. + install-lib-ldscripts = libutil.so + $(inst_libdir)/libutil.so: +-else # not $(have-GLIBC_2.33) +-libutil-inhibit-o = $(filter-out .o,$(object-suffixes)) +-endif # $(have-GLIBC_2.33) ++#else # not $(have-GLIBC_2.33) ++#libutil-inhibit-o = $(filter-out .o,$(object-suffixes)) ++#endif # $(have-GLIBC_2.33) + + include ../Rules + +diff --git a/nptl/Versions b/nptl/Versions +index 3221de89..a0df5497 100644 +--- a/nptl/Versions ++++ b/nptl/Versions +@@ -533,3 +533,264 @@ ld { + __nptl_set_robust_list_avail; + } + } ++ ++libpthread_in_libc { ++ GLIBC_2.0 { ++ pthread_create; pthread_join; ++ pthread_exit; pthread_detach; ++ ++ pthread_mutex_init; pthread_mutex_destroy; ++ pthread_mutex_lock; pthread_mutex_trylock; pthread_mutex_unlock; ++ ++ pthread_mutexattr_init; pthread_mutexattr_destroy; ++ ++ pthread_cond_wait; pthread_cond_timedwait; ++ pthread_cond_signal; pthread_cond_broadcast; ++ ++ pthread_cancel; pthread_testcancel; ++ pthread_setcancelstate; pthread_setcanceltype; ++ ++ pthread_sigmask; pthread_kill; ++ ++ pthread_key_create; pthread_key_delete; ++ pthread_getspecific; pthread_setspecific; ++ ++ pthread_once; ++ ++ pthread_atfork; ++ ++ flockfile; funlockfile; ftrylockfile; ++ ++ # Non-standard POSIX1.x functions. ++ pthread_mutexattr_getkind_np; pthread_mutexattr_setkind_np; ++ ++ # Protected names for functions used in other shared objects. ++ __pthread_mutex_init; __pthread_mutex_destroy; ++ __pthread_mutex_lock; __pthread_mutex_trylock; __pthread_mutex_unlock; ++ __pthread_mutexattr_init; __pthread_mutexattr_destroy; ++ __pthread_mutexattr_settype; ++ __pthread_key_create; __pthread_getspecific; __pthread_setspecific; ++ __pthread_once; __pthread_atfork; ++ _IO_flockfile; _IO_ftrylockfile; _IO_funlockfile; ++ ++ # Semaphores. ++ sem_destroy; sem_getvalue; sem_init; sem_post; sem_trywait; sem_wait; ++ ++ # Special fork handling. ++ fork; __fork; ++ ++ # Cancellation points. ++ close; __close; fcntl; __fcntl; read; __read; write; __write; accept; ++ connect; __connect; recv; recvfrom; recvmsg; send; __send; sendmsg; sendto; ++ fsync; lseek; __lseek; msync; open; __open; pause; tcdrain; ++ system; ++ nanosleep; wait; __wait; waitpid; ++ ++ # Hidden entry point (through macros). ++ _pthread_cleanup_push; _pthread_cleanup_pop; ++ _pthread_cleanup_push_defer; _pthread_cleanup_pop_restore; ++ ++ pthread_kill_other_threads_np; ++ ++ # The error functions. ++ __errno_location; __h_errno_location; ++ ++ # Functions which previously have been overwritten. ++ sigwait; sigaction; __sigaction; _exit; _Exit; longjmp; siglongjmp; ++ raise; ++ ++ #Additional ++ pthread_attr_destroy; pthread_attr_getdetachstate; ++ pthread_attr_getinheritsched; pthread_attr_getschedparam; ++ pthread_attr_getschedpolicy; pthread_attr_getscope; pthread_attr_init; ++ pthread_attr_setdetachstate; pthread_attr_setinheritsched; ++ pthread_attr_setschedparam; pthread_attr_setschedpolicy; ++ pthread_attr_setscope; pthread_cond_destroy; pthread_cond_init; ++ pthread_condattr_destroy; ++ pthread_condattr_init; pthread_equal; pthread_getschedparam; pthread_self; ++ pthread_setschedparam; ++ } ++ ++ GLIBC_2.1 { ++ pthread_create; ++ ++ pthread_attr_getguardsize; pthread_attr_setguardsize; ++ pthread_attr_getstackaddr; pthread_attr_setstackaddr; ++ pthread_attr_getstacksize; pthread_attr_setstacksize; ++ ++ pthread_mutexattr_gettype; pthread_mutexattr_settype; ++ ++ pthread_rwlock_init; pthread_rwlock_destroy; ++ pthread_rwlock_rdlock; pthread_rwlock_wrlock; pthread_rwlock_unlock; ++ pthread_rwlock_tryrdlock; pthread_rwlock_trywrlock; ++ ++ pthread_rwlockattr_init; pthread_rwlockattr_destroy; ++ pthread_rwlockattr_getpshared; pthread_rwlockattr_setpshared; ++ pthread_rwlockattr_getkind_np; pthread_rwlockattr_setkind_np; ++ ++ pthread_getconcurrency; pthread_setconcurrency; ++ ++ # Semaphores. ++ sem_destroy; sem_getvalue; sem_init; sem_post; sem_trywait; sem_wait; ++ ++ __libc_current_sigrtmin; __libc_current_sigrtmax; ++ __libc_allocate_rtsig; ++ } ++ ++ GLIBC_2.1.1 { ++ sem_close; sem_open; sem_unlink; ++ } ++ ++ GLIBC_2.1.2 { ++ __libpthread_version_placeholder; ++ } ++ ++ GLIBC_2.2 { ++ pthread_mutexattr_getpshared; pthread_mutexattr_setpshared; ++ ++ pthread_condattr_getpshared; pthread_condattr_setpshared; ++ ++ # New functions from IEEE Std. 1003.1-2001. ++ pthread_mutex_timedlock; ++ ++ pthread_rwlock_timedrdlock; pthread_rwlock_timedwrlock; ++ ++ pthread_attr_getstack; pthread_attr_setstack; ++ ++ pthread_spin_destroy; pthread_spin_init; pthread_spin_lock; ++ pthread_spin_trylock; pthread_spin_unlock; ++ ++ pthread_barrier_init; pthread_barrier_destroy; pthread_barrier_wait; ++ pthread_barrierattr_destroy; pthread_barrierattr_init; ++ pthread_barrierattr_setpshared; ++ ++ sem_timedwait; ++ ++ pthread_yield; ++ ++ pthread_getcpuclockid; ++ ++ # Cancellation points. ++ lseek64; open64; __open64; pread; pread64; __pread64; pwrite; pwrite64; ++ __pwrite64; ++ ++ # Names used internally. ++ __pthread_rwlock_init; __pthread_rwlock_destroy; ++ __pthread_rwlock_rdlock; __pthread_rwlock_tryrdlock; ++ __pthread_rwlock_wrlock; __pthread_rwlock_trywrlock; ++ __pthread_rwlock_unlock; ++ ++ __res_state; ++ ++ # Additional ++ pthread_attr_init; ++ } ++ ++ GLIBC_2.2.3 { ++ __libpthread_version_placeholder; ++ ++ # Additional ++ pthread_getattr_np; ++ } ++ ++ GLIBC_2.2.6 { ++ __libpthread_version_placeholder; ++ ++ # Additional ++ __nanosleep; ++ } ++ ++ GLIBC_2.3.2 { ++ # Changed pthread_cond_t. ++ pthread_cond_init; ++ pthread_cond_wait; pthread_cond_timedwait; ++ pthread_cond_signal; pthread_cond_broadcast; ++ ++ # Additional ++ pthread_cond_destroy; ++ } ++ ++ GLIBC_2.3.3 { ++ # 1003.1-2001 function accidentally left out in 2.2. ++ pthread_barrierattr_getpshared; ++ ++ # Unix CS option. ++ pthread_condattr_getclock; pthread_condattr_setclock; ++ ++ # Proposed API extensions. ++ pthread_tryjoin_np; pthread_timedjoin_np; ++ ++ # New cancellation cleanup handling. ++ __pthread_register_cancel; __pthread_unregister_cancel; ++ __pthread_register_cancel_defer; __pthread_unregister_cancel_restore; ++ __pthread_unwind_next; ++ __pthread_cleanup_routine; ++ ++ # affinity interfaces without size parameter ++ pthread_setaffinity_np; ++ pthread_attr_getaffinity_np; ++ ++ # Additional ++ pthread_attr_setaffinity_np; pthread_attr_setstack; ++ pthread_attr_setstacksize; pthread_getaffinity_np; ++ } ++ ++ GLIBC_2.3.4 { ++ # New affinity interfaces. ++ pthread_getaffinity_np; pthread_setaffinity_np; ++ pthread_attr_getaffinity_np; ++ ++ pthread_setschedprio; ++ ++ # Additional ++ pthread_attr_setaffinity_np; ++ } ++ ++ GLIBC_2.4 { ++ pthread_mutexattr_getrobust_np; pthread_mutexattr_setrobust_np; ++ pthread_mutex_consistent_np; ++ pthread_mutexattr_getprotocol; pthread_mutexattr_setprotocol; ++ pthread_mutexattr_getprioceiling; pthread_mutexattr_setprioceiling; ++ pthread_mutex_getprioceiling; pthread_mutex_setprioceiling; ++ }; ++ ++ GLIBC_2.11 { ++ pthread_sigqueue; ++ }; ++ ++ GLIBC_2.12 { ++ pthread_mutex_consistent; pthread_mutexattr_getrobust; ++ pthread_mutexattr_setrobust; ++ ++ pthread_setname_np; pthread_getname_np; ++ }; ++ ++ GLIBC_2.18 { ++ pthread_getattr_default_np; ++ pthread_setattr_default_np; ++ } ++ ++ GLIBC_2.20 { ++ } ++ ++ GLIBC_2.22 { ++ } ++ ++ # C11 thread symbols. ++ GLIBC_2.28 { ++ thrd_create; thrd_detach; thrd_exit; thrd_join; ++ mtx_init; mtx_lock; mtx_timedlock; mtx_trylock; mtx_unlock; mtx_destroy; ++ call_once; cnd_broadcast; cnd_destroy; cnd_init; cnd_signal; ++ cnd_timedwait; cnd_wait; tss_create; tss_delete; tss_get; tss_set; ++ } ++ ++ GLIBC_2.30 { ++ sem_clockwait; pthread_cond_clockwait; ++ pthread_rwlock_clockrdlock; pthread_rwlock_clockwrlock; ++ pthread_mutex_clocklock; ++ } ++ ++ GLIBC_2.31 { ++ pthread_clockjoin_np; ++ } ++} +diff --git a/scripts/firstversions.awk b/scripts/firstversions.awk +index ccde4b59..16008b08 100644 +--- a/scripts/firstversions.awk ++++ b/scripts/firstversions.awk +@@ -27,9 +27,16 @@ function vers_compare (v1, v2) + } + + NF > 2 && $2 == ":" { +- for (i = 0; i <= NF - 3; ++i) ++ for (i = 0; i <= NF - 3; ++i){ + firstversion[$1, i] = $(3 + i); ++ if ( $1 == "libpthread" ) { ++ firstversion["libpthread_in_libc", i] = $(3 + i); ++ } ++ } + idx[$1] = 0; ++ if ( $1 == "libpthread" ) { ++ idx["libpthread_in_libc"] = 0; ++ } + next; + } + +diff --git a/scripts/versions.awk b/scripts/versions.awk +index eeb7a106..6b30e745 100644 +--- a/scripts/versions.awk ++++ b/scripts/versions.awk +@@ -89,7 +89,7 @@ function ord(c) { + sortver=actver + # Ensure GLIBC_ versions come always first + sub(/^GLIBC_/," GLIBC_",sortver) +- printf("%s %s %s\n", actlib, sortver, $0) | sort; ++ printf("%s %s %s\n", actlib == "libpthread_in_libc" ? "libc" : actlib, sortver, $0) | sort; + } + + # Some targets do not set the ABI baseline for libdl. As a result, +diff --git a/sunrpc/Makefile b/sunrpc/Makefile +index ec2ea04c..015be5be 100644 +--- a/sunrpc/Makefile ++++ b/sunrpc/Makefile +@@ -22,7 +22,7 @@ subdir := sunrpc + + include ../Makeconfig + +-ifdef have-GLIBC_2.31 ++#ifdef have-GLIBC_2.31 + + # The code in this subdirectory is taken from Sun's RPCSRC-4.0 + # distribution with some additional changes from the TI-RPC package +@@ -62,7 +62,7 @@ routines := auth_none authuxprot clnt_raw clnt_simp \ + rpc_gethostbyname + # We only add the RPC for compatibility to libc.so. + shared-only-routines = $(routines) +-endif ++#endif + + tests = tst-xdrmem tst-xdrmem2 test-rpcent tst-udp-error tst-udp-timeout \ + tst-udp-nonblocking tst-bug22542 tst-bug28768 +diff --git a/sysdeps/nptl/Makeconfig b/sysdeps/nptl/Makeconfig +index 77aedd1e..963ad5d5 100644 +--- a/sysdeps/nptl/Makeconfig ++++ b/sysdeps/nptl/Makeconfig +@@ -20,6 +20,7 @@ + + have-thread-library = yes + have-anl-library = $(have-GLIBC_2.34) ++have-anl-library = yes + + # The thread library is integrated. + shared-thread-library = +diff --git a/sysdeps/unix/sysv/linux/loongarch/Versions b/sysdeps/unix/sysv/linux/loongarch/Versions +new file mode 100644 +index 00000000..6b3dd0d1 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/Versions +@@ -0,0 +1,36 @@ ++libc { ++ GLIBC_2.36 { ++ __ppoll_chk; ++ signalfd; ++ epoll_pwait2; ++ epoll_pwait; ++ pselect; ++ ppoll; ++ posix_spawnattr_getsigmask; ++ posix_spawnattr_getsigdefault; ++ posix_spawnattr_setsigmask; ++ posix_spawnattr_setsigdefault; ++ sigwaitinfo; ++ sigorset; ++ sigandset; ++ sigisemptyset; ++ sigismember; ++ sigaddset; ++ sigfillset; ++ sigemptyset; ++ sigdelset; ++ sigwait; ++ sigtimedwait; ++ __sigsuspend; ++ sigsuspend; ++ sigpending; ++ pthread_sigmask; ++ sigprocmask; ++ sigaction; ++ __sigaction; ++ swapcontext; ++ setcontext; ++ makecontext; ++ getcontext; ++ } ++} +diff --git a/sysdeps/unix/sysv/linux/loongarch/shlib-versions b/sysdeps/unix/sysv/linux/loongarch/shlib-versions +index 5f40e7f5..4f126b54 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/shlib-versions ++++ b/sysdeps/unix/sysv/linux/loongarch/shlib-versions +@@ -1,9 +1,2 @@ +-DEFAULT GLIBC_2.36 +- +-%if LOONGARCH_ABI_GRLEN == 64 && LOONGARCH_ABI_FRLEN == 64 +-ld=ld-linux-loongarch-lp64d.so.1 +-%elif LOONGARCH_ABI_GRLEN == 64 && LOONGARCH_ABI_FRLEN == 0 +-ld=ld-linux-loongarch-lp64s.so.1 +-%else +-%error cannot determine ABI +-%endif ++DEFAULT GLIBC_2.27 GLIBC_2.28 GLIBC_2.36 ++libpthread=0 GLIBC_2.0 GLIBC_2.2 GLIBC_2.2.1 GLIBC_2.2.2 GLIBC_2.2.3 GLIBC_2.2.4 GLIBC_2.2.6 GLIBC_2.3 GLIBC_2.3.2 GLIBC_2.3.3 GLIBC_2.3.4 GLIBC_2.4 GLIBC_2.5 GLIBC_2.6 GLIBC_2.7 GLIBC_2.8 GLIBC_2.9 GLIBC_2.10 GLIBC_2.11 GLIBC_2.12 GLIBC_2.13 GLIBC_2.14 GLIBC_2.15 GLIBC_2.16 GLIBC_2.17 GLIBC_2.18 GLIBC_2.19 GLIBC_2.20 GLIBC_2.21 GLIBC_2.22 GLIBC_2.23 GLIBC_2.24 GLIBC_2.25 GLIBC_2.26 GLIBC_2.27 GLIBC_2.28 GLIBC_2.36 +diff --git a/sysdeps/unix/sysv/linux/loongarch/statx_cp.c b/sysdeps/unix/sysv/linux/loongarch/statx_cp.c +new file mode 100644 +index 00000000..3b57a461 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/statx_cp.c +@@ -0,0 +1,4 @@ ++// We neet statx_cp for oldworld compaitibility. ++// So include it back and override the oerride in wordsize-64 ++ ++#include +-- +2.43.0 + diff --git a/debian/patches/glibc/0002-add-sigset-ops.patch b/debian/patches/glibc/0002-add-sigset-ops.patch new file mode 100644 index 000000000..a0890cde6 --- /dev/null +++ b/debian/patches/glibc/0002-add-sigset-ops.patch @@ -0,0 +1,354 @@ +From dc917c1307c621f28528e8e797c6eb35f6bc48ac Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sat, 13 Jan 2024 05:07:19 +0800 +Subject: [PATCH 02/10] add sigset ops + +--- + sysdeps/unix/sysv/linux/loongarch/Makefile | 13 +++++++++++++ + .../unix/sysv/linux/loongarch/bits/signum-arch.h | 6 ++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigaddset.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigandset.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigdelset.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigempty.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigfillset.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigisempty.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigismem.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigop.h | 8 ++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigorset.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/sigaddset.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/sigandset.c | 7 +++++++ + sysdeps/unix/sysv/linux/loongarch/sigdelset.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/sigempty.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/sigfillset.c | 11 +++++++++++ + sysdeps/unix/sysv/linux/loongarch/sigisempty.c | 7 +++++++ + sysdeps/unix/sysv/linux/loongarch/sigismem.c | 7 +++++++ + sysdeps/unix/sysv/linux/loongarch/sigorset.c | 7 +++++++ + 19 files changed, 187 insertions(+) + create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/signum-arch.h + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigaddset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigandset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigdelset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigempty.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigfillset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigisempty.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigismem.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigop.h + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_sigorset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigaddset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigandset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigdelset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigempty.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigfillset.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigisempty.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigismem.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigorset.c + +diff --git a/sysdeps/unix/sysv/linux/loongarch/Makefile b/sysdeps/unix/sysv/linux/loongarch/Makefile +index c84a1762..70cac2d3 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/Makefile ++++ b/sysdeps/unix/sysv/linux/loongarch/Makefile +@@ -2,6 +2,19 @@ ifeq ($(subdir),stdlib) + gen-as-const-headers += ucontext_i.sym + endif + ++ifeq ($(subdir),signal) ++sysdep_routines += \ ++ ow_sigisempty \ ++ ow_sigismem \ ++ ow_sigaddset \ ++ ow_sigfillset \ ++ ow_sigempty \ ++ ow_sigdelset \ ++ ow_sigandset \ ++ ow_sigorset \ ++ # sysdep_routines ++endif ++ + abi-variants := lp64s lp64d + + ifeq (,$(filter $(default-abi),$(abi-variants))) +diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/signum-arch.h b/sysdeps/unix/sysv/linux/loongarch/bits/signum-arch.h +new file mode 100644 +index 00000000..522f0846 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/bits/signum-arch.h +@@ -0,0 +1,6 @@ ++#include ++ ++#ifdef LA_OW_COMPACT ++#undef __SIGRTMAX ++#define __SIGRTMAX 128 ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigaddset.c b/sysdeps/unix/sysv/linux/loongarch/ow_sigaddset.c +new file mode 100644 +index 00000000..0bc18cda +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigaddset.c +@@ -0,0 +1,11 @@ ++#define LA_OW_COMPACT ++ ++#include ++ ++#define sigaddset __ow_sigaddset ++#include ++ ++#undef sigaddset ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol(libc, __ow_sigaddset, sigaddset, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigandset.c b/sysdeps/unix/sysv/linux/loongarch/ow_sigandset.c +new file mode 100644 +index 00000000..b28cfc23 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigandset.c +@@ -0,0 +1,11 @@ ++#define LA_OW_COMPACT ++ ++#include ++ ++#define sigandset __ow_sigandset ++#include ++ ++#undef sigandset ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol(libc, __ow_sigandset, sigandset, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigdelset.c b/sysdeps/unix/sysv/linux/loongarch/ow_sigdelset.c +new file mode 100644 +index 00000000..d29dc885 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigdelset.c +@@ -0,0 +1,11 @@ ++#define LA_OW_COMPACT ++ ++#include ++ ++#define sigdelset __ow_sigdelset ++#include ++ ++#undef sigdelset ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol(libc, __ow_sigdelset, sigdelset, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigempty.c b/sysdeps/unix/sysv/linux/loongarch/ow_sigempty.c +new file mode 100644 +index 00000000..67d3176e +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigempty.c +@@ -0,0 +1,11 @@ ++#define LA_OW_COMPACT ++ ++#include ++ ++#define sigemptyset __ow_sigemptyset ++#include ++ ++#undef sigemptyset ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol(libc, __ow_sigemptyset, sigemptyset, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigfillset.c b/sysdeps/unix/sysv/linux/loongarch/ow_sigfillset.c +new file mode 100644 +index 00000000..3d41cbf5 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigfillset.c +@@ -0,0 +1,11 @@ ++#define LA_OW_COMPACT ++ ++#include ++ ++#define sigfillset __ow_sigfillset ++#include ++ ++#undef sigfillset ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol(libc, __ow_sigfillset, sigfillset, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigisempty.c b/sysdeps/unix/sysv/linux/loongarch/ow_sigisempty.c +new file mode 100644 +index 00000000..b30cb1a2 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigisempty.c +@@ -0,0 +1,11 @@ ++#define LA_OW_COMPACT ++ ++#include ++ ++#define sigisemptyset __ow_sigisemptyset ++#include ++ ++#undef sigisemptyset ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol(libc, __ow_sigisemptyset, sigisemptyset, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigismem.c b/sysdeps/unix/sysv/linux/loongarch/ow_sigismem.c +new file mode 100644 +index 00000000..21432e42 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigismem.c +@@ -0,0 +1,11 @@ ++#define LA_OW_COMPACT ++ ++#include ++ ++#define sigismember __ow_sigismember ++#include ++ ++#undef sigismember ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol(libc, __ow_sigismember, sigismember, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigop.h b/sysdeps/unix/sysv/linux/loongarch/ow_sigop.h +new file mode 100644 +index 00000000..f06836b8 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigop.h +@@ -0,0 +1,8 @@ ++#include ++ ++extern int __ow_sigaddset(sigset_t *, int); ++extern int __ow_sigdelset(sigset_t *, int); ++extern int __ow_sigemptyset(sigset_t *); ++extern int __ow_sigfillset(sigset_t *); ++extern int __ow_sigandset (sigset_t *__set, const sigset_t *__left, const sigset_t *__right); ++extern int __ow_sigorset (sigset_t *__set, const sigset_t *__left, const sigset_t *__right); +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigorset.c b/sysdeps/unix/sysv/linux/loongarch/ow_sigorset.c +new file mode 100644 +index 00000000..8e73662b +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigorset.c +@@ -0,0 +1,11 @@ ++#define LA_OW_COMPACT ++ ++#include ++ ++#define sigorset __ow_sigorset ++#include ++ ++#undef sigorset ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol(libc, __ow_sigorset, sigorset, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigaddset.c b/sysdeps/unix/sysv/linux/loongarch/sigaddset.c +new file mode 100644 +index 00000000..d86362d1 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigaddset.c +@@ -0,0 +1,11 @@ ++#include ++#include ++ ++#define sigaddset __nw_sigaddset ++#undef libc_hidden_def ++#define libc_hidden_def(name) ++#include ++ ++#undef sigaddset ++versioned_symbol(libc, __nw_sigaddset, sigaddset, GLIBC_2_36); ++libc_hidden_ver(__nw_sigaddset, sigaddset) +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigandset.c b/sysdeps/unix/sysv/linux/loongarch/sigandset.c +new file mode 100644 +index 00000000..e3345db8 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigandset.c +@@ -0,0 +1,7 @@ ++#include ++ ++#define sigandset __nw_sigandset ++#include ++ ++#undef sigandset ++versioned_symbol(libc, __nw_sigandset, sigandset, GLIBC_2_36); +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigdelset.c b/sysdeps/unix/sysv/linux/loongarch/sigdelset.c +new file mode 100644 +index 00000000..13e9c950 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigdelset.c +@@ -0,0 +1,11 @@ ++#include ++#include ++ ++#define sigdelset __nw_sigdelset ++#undef libc_hidden_def ++#define libc_hidden_def(name) ++#include ++ ++#undef sigdelset ++versioned_symbol(libc, __nw_sigdelset, sigdelset, GLIBC_2_36); ++libc_hidden_ver(__nw_sigdelset, sigdelset) +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigempty.c b/sysdeps/unix/sysv/linux/loongarch/sigempty.c +new file mode 100644 +index 00000000..476756e6 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigempty.c +@@ -0,0 +1,11 @@ ++#include ++#include ++ ++#define sigemptyset __nw_sigemptyset ++#undef libc_hidden_def ++#define libc_hidden_def(name) ++#include ++ ++#undef sigemptyset ++versioned_symbol(libc, __nw_sigemptyset, sigemptyset, GLIBC_2_36); ++libc_hidden_ver(__nw_sigemptyset, sigemptyset) +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigfillset.c b/sysdeps/unix/sysv/linux/loongarch/sigfillset.c +new file mode 100644 +index 00000000..2f55b866 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigfillset.c +@@ -0,0 +1,11 @@ ++#include ++#include ++ ++#define sigfillset __nw_sigfillset ++#undef libc_hidden_def ++#define libc_hidden_def(name) ++#include ++ ++#undef sigfillset ++versioned_symbol(libc, __nw_sigfillset, sigfillset, GLIBC_2_36); ++libc_hidden_ver(__nw_sigfillset, sigfillset) +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigisempty.c b/sysdeps/unix/sysv/linux/loongarch/sigisempty.c +new file mode 100644 +index 00000000..b6ea8b84 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigisempty.c +@@ -0,0 +1,7 @@ ++#include ++ ++#define sigisemptyset __nw_sigisemptyset ++#include ++ ++#undef sigisemptyset ++versioned_symbol(libc, __nw_sigisemptyset, sigisemptyset, GLIBC_2_36); +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigismem.c b/sysdeps/unix/sysv/linux/loongarch/sigismem.c +new file mode 100644 +index 00000000..ae7d9b62 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigismem.c +@@ -0,0 +1,7 @@ ++#include ++ ++#define sigismember __nw_sigismember ++#include ++ ++#undef sigismember ++versioned_symbol(libc, __nw_sigismember, sigismember, GLIBC_2_36); +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigorset.c b/sysdeps/unix/sysv/linux/loongarch/sigorset.c +new file mode 100644 +index 00000000..a49e3f4e +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigorset.c +@@ -0,0 +1,7 @@ ++#include ++ ++#define sigorset __nw_sigorset ++#include ++ ++#undef sigorset ++versioned_symbol(libc, __nw_sigorset, sigorset, GLIBC_2_36); +-- +2.43.0 + diff --git a/debian/patches/glibc/0003-add-signal-functions.patch b/debian/patches/glibc/0003-add-signal-functions.patch new file mode 100644 index 000000000..aec7fac62 --- /dev/null +++ b/debian/patches/glibc/0003-add-signal-functions.patch @@ -0,0 +1,235 @@ +From cf322ba313a0a4ec8581470d1fb7a0f8d05249b1 Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sat, 13 Jan 2024 06:35:35 +0800 +Subject: [PATCH 03/10] add signal functions + +--- + sysdeps/loongarch/nptl/pthread_sigmask.c | 73 +++++++++++++++++++ + sysdeps/unix/sysv/linux/loongarch/ow_sigop.h | 8 ++ + .../unix/sysv/linux/loongarch/sigpending.c | 22 ++++++ + .../unix/sysv/linux/loongarch/sigprocmask.c | 20 +++++ + .../unix/sysv/linux/loongarch/sigsuspend.c | 1 + + .../unix/sysv/linux/loongarch/sigtimedwait.c | 1 + + sysdeps/unix/sysv/linux/loongarch/sigwait.c | 10 +++ + .../unix/sysv/linux/loongarch/sigwaitinfo.c | 1 + + .../linux/loongarch/spawnattr_setdefault.c | 1 + + .../linux/loongarch/spawnattr_setsigmask.c | 1 + + 10 files changed, 138 insertions(+) + create mode 100644 sysdeps/loongarch/nptl/pthread_sigmask.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigpending.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigprocmask.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigsuspend.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigtimedwait.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigwait.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigwaitinfo.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/spawnattr_setdefault.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/spawnattr_setsigmask.c + +diff --git a/sysdeps/loongarch/nptl/pthread_sigmask.c b/sysdeps/loongarch/nptl/pthread_sigmask.c +new file mode 100644 +index 00000000..d6947000 +--- /dev/null ++++ b/sysdeps/loongarch/nptl/pthread_sigmask.c +@@ -0,0 +1,73 @@ ++/* Copyright (C) 2002-2023 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#include ++#include ++#include ++#include ++ ++int ++__pthread_sigmask (int how, const sigset_t *newmask, sigset_t *oldmask) ++{ ++ sigset_t local_newmask; ++ ++ /* The only thing we have to make sure here is that SIGCANCEL and ++ SIGSETXID is not blocked. */ ++ if (newmask != NULL ++ && (__glibc_unlikely (__sigismember (newmask, SIGCANCEL)) ++ || __glibc_unlikely (__sigismember (newmask, SIGSETXID)))) ++ { ++ local_newmask = *newmask; ++ clear_internal_signals (&local_newmask); ++ newmask = &local_newmask; ++ } ++ ++ /* We know that realtime signals are available if NPTL is used. */ ++ int result = INTERNAL_SYSCALL_CALL (rt_sigprocmask, how, newmask, ++ oldmask, __NSIG_BYTES); ++ ++ return (INTERNAL_SYSCALL_ERROR_P (result) ++ ? INTERNAL_SYSCALL_ERRNO (result) ++ : 0); ++} ++libc_hidden_def (__pthread_sigmask) ++ ++versioned_symbol (libc, __pthread_sigmask, pthread_sigmask, GLIBC_2_36); ++ ++#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_36) ++ ++#include ++ ++int ++__ow___pthread_sigmask (int how, const sigset_t *newmask, sigset_t *oldmask) ++{ ++ int rc = __pthread_sigmask (how, newmask, oldmask); ++ if (rc >= 0 && oldmask != NULL){ ++ __ow_clear_unused_bits(oldmask); ++ } ++ return rc; ++} ++#if SHLIB_COMPAT (libc, GLIBC_2_32, GLIBC_2_36) ++compat_symbol (libc, __ow___pthread_sigmask, pthread_sigmask, GLIBC_2_32); ++#endif ++ ++#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_32) ++strong_alias (__ow___pthread_sigmask, __ow___pthread_sigmask_2); ++compat_symbol (libc, __ow___pthread_sigmask_2, pthread_sigmask, GLIBC_2_0); ++#endif ++ ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_sigop.h b/sysdeps/unix/sysv/linux/loongarch/ow_sigop.h +index f06836b8..a74c2240 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/ow_sigop.h ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_sigop.h +@@ -1,4 +1,5 @@ + #include ++#include + + extern int __ow_sigaddset(sigset_t *, int); + extern int __ow_sigdelset(sigset_t *, int); +@@ -6,3 +7,10 @@ extern int __ow_sigemptyset(sigset_t *); + extern int __ow_sigfillset(sigset_t *); + extern int __ow_sigandset (sigset_t *__set, const sigset_t *__left, const sigset_t *__right); + extern int __ow_sigorset (sigset_t *__set, const sigset_t *__left, const sigset_t *__right); ++ ++#define __OW_NSIG 128 ++ ++static inline void __ow_clear_unused_bits(sigset_t *set) ++{ ++ memset ((void *)set + (NSIG / 8), 0, (__OW_NSIG - NSIG) / 8); ++} +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigpending.c b/sysdeps/unix/sysv/linux/loongarch/sigpending.c +new file mode 100644 +index 00000000..238c27ad +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigpending.c +@@ -0,0 +1,22 @@ ++#include ++ ++#include ++ ++#define sigpending __sigpending ++#include ++#undef sigpending ++ ++versioned_symbol (libc, __sigpending, sigpending, GLIBC_2_36); ++ ++#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_36) ++#include "ow_sigop.h" ++int __ow_sigpending (sigset_t *set) ++{ ++ int rc = __sigpending (set); ++ if (rc >= 0){ ++ __ow_clear_unused_bits(set); ++ } ++ return rc; ++} ++compat_symbol (libc, __ow_sigpending, sigpending, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigprocmask.c b/sysdeps/unix/sysv/linux/loongarch/sigprocmask.c +new file mode 100644 +index 00000000..17aa8572 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigprocmask.c +@@ -0,0 +1,20 @@ ++#include ++ ++#undef weak_alias ++#define weak_alias(name, aliasname) ++#include ++ ++versioned_symbol (libc, __sigprocmask, sigprocmask, GLIBC_2_36); ++ ++#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_36) ++#include "ow_sigop.h" ++int __ow_sigprocmask (int how, const sigset_t *set, sigset_t *oldset) ++{ ++ int rc = __sigprocmask (how, set, oldset); ++ if (rc >= 0 && oldset != NULL){ ++ __ow_clear_unused_bits(oldset); ++ } ++ return rc; ++} ++compat_symbol (libc, __ow_sigprocmask, sigprocmask, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigsuspend.c b/sysdeps/unix/sysv/linux/loongarch/sigsuspend.c +new file mode 100644 +index 00000000..9351c54b +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigsuspend.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigtimedwait.c b/sysdeps/unix/sysv/linux/loongarch/sigtimedwait.c +new file mode 100644 +index 00000000..65636bb6 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigtimedwait.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigwait.c b/sysdeps/unix/sysv/linux/loongarch/sigwait.c +new file mode 100644 +index 00000000..e11d42f2 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigwait.c +@@ -0,0 +1,10 @@ ++#include ++ ++#undef weak_alias ++#define weak_alias(name, aliasname) ++#include ++ ++versioned_symbol (libc, __sigwait, sigwait, GLIBC_2_0); ++#if OTHER_SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_34) ++compat_symbol (libpthread, __sigwait, sigwait, GLIBC_2_0); ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigwaitinfo.c b/sysdeps/unix/sysv/linux/loongarch/sigwaitinfo.c +new file mode 100644 +index 00000000..36edb293 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigwaitinfo.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/spawnattr_setdefault.c b/sysdeps/unix/sysv/linux/loongarch/spawnattr_setdefault.c +new file mode 100644 +index 00000000..f75f1f16 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/spawnattr_setdefault.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/spawnattr_setsigmask.c b/sysdeps/unix/sysv/linux/loongarch/spawnattr_setsigmask.c +new file mode 100644 +index 00000000..a95cf5da +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/spawnattr_setsigmask.c +@@ -0,0 +1 @@ ++#include +-- +2.43.0 + diff --git a/debian/patches/glibc/0004-add-sigaction-ucontext-compat.patch b/debian/patches/glibc/0004-add-sigaction-ucontext-compat.patch new file mode 100644 index 000000000..98dd8605b --- /dev/null +++ b/debian/patches/glibc/0004-add-sigaction-ucontext-compat.patch @@ -0,0 +1,786 @@ +From 6cdd1507ce24af347189225ccb4badae1da08add Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sun, 14 Jan 2024 05:15:07 +0800 +Subject: [PATCH 04/10] add sigaction & ucontext compat + +--- + sysdeps/unix/sysv/linux/loongarch/Makefile | 8 +- + .../unix/sysv/linux/loongarch/getcontext.S | 3 +- + .../unix/sysv/linux/loongarch/makecontext.c | 3 +- + .../unix/sysv/linux/loongarch/ow_getcontext.S | 13 + + .../sysv/linux/loongarch/ow_makecontext.c | 17 + + .../unix/sysv/linux/loongarch/ow_setcontext.S | 14 + + .../sysv/linux/loongarch/ow_swapcontext.S | 13 + + .../sysv/linux/loongarch/ow_ucontext-macros.h | 35 ++ + .../unix/sysv/linux/loongarch/ow_ucontext.h | 105 +++++ + .../sysv/linux/loongarch/ow_ucontext_i.sym | 32 ++ + .../unix/sysv/linux/loongarch/setcontext.S | 4 +- + sysdeps/unix/sysv/linux/loongarch/sigaction.c | 384 ++++++++++++++++++ + .../unix/sysv/linux/loongarch/swapcontext.S | 3 +- + 13 files changed, 629 insertions(+), 5 deletions(-) + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_getcontext.S + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_makecontext.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_setcontext.S + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_swapcontext.S + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_ucontext-macros.h + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_ucontext.h + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_ucontext_i.sym + create mode 100644 sysdeps/unix/sysv/linux/loongarch/sigaction.c + +diff --git a/sysdeps/unix/sysv/linux/loongarch/Makefile b/sysdeps/unix/sysv/linux/loongarch/Makefile +index 70cac2d3..1d447ea4 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/Makefile ++++ b/sysdeps/unix/sysv/linux/loongarch/Makefile +@@ -1,5 +1,11 @@ + ifeq ($(subdir),stdlib) +-gen-as-const-headers += ucontext_i.sym ++gen-as-const-headers += ucontext_i.sym ow_ucontext_i.sym ++sysdep_routines += \ ++ ow_swapcontext \ ++ ow_makecontext \ ++ ow_getcontext \ ++ ow_setcontext \ ++ # sysdep_routines + endif + + ifeq ($(subdir),signal) +diff --git a/sysdeps/unix/sysv/linux/loongarch/getcontext.S b/sysdeps/unix/sysv/linux/loongarch/getcontext.S +index d04e33c0..88f4aa92 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/getcontext.S ++++ b/sysdeps/unix/sysv/linux/loongarch/getcontext.S +@@ -16,6 +16,7 @@ + License along with the GNU C Library. If not, see + . */ + ++#include + #include "ucontext-macros.h" + + /* int getcontext (ucontext_t *ucp) */ +@@ -56,4 +57,4 @@ LEAF (__getcontext) + + PSEUDO_END (__getcontext) + +-weak_alias (__getcontext, getcontext) ++versioned_symbol (libc, __getcontext, getcontext, GLIBC_2_36); +diff --git a/sysdeps/unix/sysv/linux/loongarch/makecontext.c b/sysdeps/unix/sysv/linux/loongarch/makecontext.c +index a17f6ccc..b17fdc5d 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/makecontext.c ++++ b/sysdeps/unix/sysv/linux/loongarch/makecontext.c +@@ -17,6 +17,7 @@ + License along with the GNU C Library. If not, see + . */ + ++#include + #include + #include + #include +@@ -78,4 +79,4 @@ __makecontext (ucontext_t *ucp, void (*func) (void), int argc, long int a0, + } + } + +-weak_alias (__makecontext, makecontext) ++versioned_symbol (libc, __makecontext, makecontext, GLIBC_2_36); +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_getcontext.S b/sysdeps/unix/sysv/linux/loongarch/ow_getcontext.S +new file mode 100644 +index 00000000..24ae4244 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_getcontext.S +@@ -0,0 +1,13 @@ ++#include ++#include "ow_ucontext-macros.h" ++ ++#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_36) ++#undef versioned_symbol ++#define versioned_symbol(a, b, c, d) ++#define __getcontext __ow___getcontext ++#include "getcontext.S" ++ ++#undef __getcontext ++compat_symbol (libc, __ow___getcontext, getcontext, GLIBC_2_1); ++ ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_makecontext.c b/sysdeps/unix/sysv/linux/loongarch/ow_makecontext.c +new file mode 100644 +index 00000000..d2effdc9 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_makecontext.c +@@ -0,0 +1,17 @@ ++#include ++ ++#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_36) ++#include ++#include "ow_ucontext.h" ++ ++#undef versioned_symbol ++#define versioned_symbol(a, b, c, d) ++#define ucontext_t __ow_ucontext_t ++#define __makecontext __ow___makecontext ++#define __start_context __ow___start_context ++#include "makecontext.c" ++ ++#undef __makecontext ++compat_symbol (libc, __ow___makecontext, makecontext, GLIBC_2_1); ++ ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_setcontext.S b/sysdeps/unix/sysv/linux/loongarch/ow_setcontext.S +new file mode 100644 +index 00000000..906e28fb +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_setcontext.S +@@ -0,0 +1,14 @@ ++#include ++#include "ow_ucontext-macros.h" ++ ++#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_36) ++#undef versioned_symbol ++#define versioned_symbol(a, b, c, d) ++#define __setcontext __ow___setcontext ++#define __start_context __ow___start_context ++#include "setcontext.S" ++ ++#undef __setcontext ++compat_symbol (libc, __ow___setcontext, setcontext, GLIBC_2_0); ++ ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_swapcontext.S b/sysdeps/unix/sysv/linux/loongarch/ow_swapcontext.S +new file mode 100644 +index 00000000..c0a0b6a4 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_swapcontext.S +@@ -0,0 +1,13 @@ ++#include ++#include "ow_ucontext-macros.h" ++ ++#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_36) ++#undef versioned_symbol ++#define versioned_symbol(a, b, c, d) ++#define __swapcontext __ow___swapcontext ++#include "swapcontext.S" ++ ++#undef __swapcontext ++compat_symbol (libc, __ow___swapcontext, swapcontext, GLIBC_2_1); ++ ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_ucontext-macros.h b/sysdeps/unix/sysv/linux/loongarch/ow_ucontext-macros.h +new file mode 100644 +index 00000000..984c9069 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_ucontext-macros.h +@@ -0,0 +1,35 @@ ++/* Macros for ucontext routines. ++ Copyright (C) 2022-2023 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library. If not, see ++ . */ ++ ++#ifndef _LINUX_LOONGARCH_OW_UCONTEXT_MACROS_H ++#define _LINUX_LOONGARCH_OW_UCONTEXT_MACROS_H ++ ++// We also define this to prevent new world headers from being included. ++#define _LINUX_LOONGARCH_UCONTEXT_MACROS_H ++ ++#include ++#include ++#include "ow_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_OW_UCONTEXT_MACROS_H */ +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_ucontext.h b/sysdeps/unix/sysv/linux/loongarch/ow_ucontext.h +new file mode 100644 +index 00000000..33cd554f +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_ucontext.h +@@ -0,0 +1,105 @@ ++#ifndef _OW_UCONTEXT_H ++#define _OW_UCONTEXT_H 1 ++#include ++#include ++#include ++#include ++#include "ow_sigop.h" ++ ++union __ow_loongarch_mc_fp_state { ++ unsigned int __val32[256 / 32]; ++ unsigned long long __val64[256 / 64]; ++}; ++ ++typedef struct __ow_mcontext_t { ++ unsigned long long __pc; ++ unsigned long long __gregs[32]; ++ unsigned int __flags; ++ ++ unsigned int __fcsr; ++ unsigned int __vcsr; ++ unsigned long long __fcc; ++ union __ow_loongarch_mc_fp_state __fpregs[32] __attribute__((__aligned__ (32))); ++ ++ unsigned int __reserved; ++} __ow_mcontext_t; ++ ++/* Userlevel context. */ ++typedef struct __ow_ucontext_t ++ { ++ unsigned long int __uc_flags; ++ struct __ow_ucontext_t *uc_link; ++ stack_t uc_stack; ++ __ow_mcontext_t uc_mcontext; ++ sigset_t uc_sigmask; ++ } __ow_ucontext_t; ++ ++struct __nw_sctx_info ++ { ++ unsigned int magic; ++ unsigned int size; ++ unsigned long long padding; /* padding to 16 bytes */ ++ }; ++ ++/* FPU context */ ++#define FPU_CTX_MAGIC 0x46505501 ++#define FPU_CTX_ALIGN 8 ++struct __nw_fpu_context ++ { ++ unsigned long long regs[32]; ++ unsigned long long fcc; ++ unsigned int fcsr; ++ }; ++/* LSX context */ ++#define LSX_CTX_MAGIC 0x53580001 ++#define LSX_CTX_ALIGN 16 ++struct __nw_lsx_context ++ { ++ unsigned long long regs[32][2]; ++ unsigned long long fcc; ++ unsigned long long fcsr; ++ }; ++/* LASX context */ ++#define LASX_CTX_MAGIC 0x41535801 ++#define LASX_CTX_ALIGN 32 ++struct __nw_lasx_context ++ { ++ unsigned long long regs[32][4]; ++ unsigned long long fcc; ++ unsigned long long fcsr; ++ }; ++ ++static inline void __copy_nw_ow (__ow_ucontext_t *ow_ctx, const ucontext_t *nw_ctx){ ++ ow_ctx->__uc_flags = nw_ctx->__uc_flags; ++ ow_ctx->uc_link = NULL; ++ ow_ctx->uc_stack = nw_ctx->uc_stack; ++ ow_ctx->uc_sigmask = nw_ctx->uc_sigmask; ++ __ow_clear_unused_bits (&ow_ctx->uc_sigmask); ++ ++ ow_ctx->uc_mcontext.__pc = nw_ctx->uc_mcontext.__pc; ++ static_assert (sizeof (ow_ctx->uc_mcontext.__gregs) == ++ sizeof (nw_ctx->uc_mcontext.__gregs), ++ "gregs size mismatch"); ++ memcpy (&ow_ctx->uc_mcontext.__gregs, &nw_ctx->uc_mcontext.__gregs, ++ sizeof (ow_ctx->uc_mcontext.__gregs)); ++ ow_ctx->uc_mcontext.__flags = nw_ctx->uc_mcontext.__flags; ++ ow_ctx->uc_mcontext.__fcsr = 0; ++ ow_ctx->uc_mcontext.__vcsr = 0; ++ ow_ctx->uc_mcontext.__fcc = 0; ++ memset (&ow_ctx->uc_mcontext.__fpregs, 0, ++ sizeof (ow_ctx->uc_mcontext.__fpregs)); ++ ow_ctx->uc_mcontext.__reserved = 0; ++} ++ ++static inline void __copy_ow_nw (ucontext_t *nw_ctx, const __ow_ucontext_t *ow_ctx){ ++ nw_ctx->uc_mcontext.__flags = ow_ctx->uc_mcontext.__flags; ++ memcpy (&nw_ctx->uc_mcontext.__gregs, &ow_ctx->uc_mcontext.__gregs, ++ sizeof (nw_ctx->uc_mcontext.__gregs)); ++ nw_ctx->uc_mcontext.__pc = ow_ctx->uc_mcontext.__pc; ++ nw_ctx->uc_sigmask = ow_ctx->uc_sigmask; ++ __ow_clear_unused_bits (&nw_ctx->uc_sigmask); ++ nw_ctx->uc_stack = ow_ctx->uc_stack; ++ nw_ctx->__uc_flags = ow_ctx->__uc_flags; ++} ++ ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_ucontext_i.sym b/sysdeps/unix/sysv/linux/loongarch/ow_ucontext_i.sym +new file mode 100644 +index 00000000..5af4dd4d +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_ucontext_i.sym +@@ -0,0 +1,32 @@ ++#include ++#include ++#include ++#include ++#include "ow_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 (__ow_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 (__ow_ucontext_t) +diff --git a/sysdeps/unix/sysv/linux/loongarch/setcontext.S b/sysdeps/unix/sysv/linux/loongarch/setcontext.S +index d01409af..5ca9467b 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/setcontext.S ++++ b/sysdeps/unix/sysv/linux/loongarch/setcontext.S +@@ -15,6 +15,8 @@ + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ ++ ++#include + #include "sys/regdef.h" + #include "ucontext-macros.h" + +@@ -80,7 +82,7 @@ LEAF (__setcontext) + b __syscall_error + + PSEUDO_END (__setcontext) +-weak_alias (__setcontext, setcontext) ++versioned_symbol (libc, __setcontext, setcontext, GLIBC_2_36); + + LEAF (__start_context) + +diff --git a/sysdeps/unix/sysv/linux/loongarch/sigaction.c b/sysdeps/unix/sysv/linux/loongarch/sigaction.c +new file mode 100644 +index 00000000..6e370c33 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/sigaction.c +@@ -0,0 +1,384 @@ ++#include ++#include ++#include ++ ++#undef weak_alias ++#define weak_alias(name, aliasname) ++#undef libc_hidden_def ++#define libc_hidden_def(name) ++#define __sigaction __nw_sigaction ++ ++#include ++ ++#undef __sigaction ++ ++versioned_symbol (libc, __nw_sigaction, sigaction, GLIBC_2_36); ++versioned_symbol (libc, __nw_sigaction, __sigaction, GLIBC_2_36); ++libc_hidden_ver (__nw_sigaction, __sigaction); ++ ++#if IS_IN(libc) && (SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_36) || OTHER_SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_34)) ++#include ++#include ++#if !IS_IN(rtld) ++#include ++#endif ++#include "ow_ucontext.h" ++ ++typedef void (*__linx_sighandler_t) (int, siginfo_t *, void *); ++ ++static void ++custom_handler (int sig, siginfo_t *info, void *ucontext, ++ __linx_sighandler_t real_handler) ++{ ++ struct __ow_ucontext_t ow_ctx; ++ ++ struct ucontext_t *nw_ctx = ucontext; ++ ++ __copy_nw_ow(&ow_ctx, nw_ctx); ++ int have_fpu = 0, have_lsx = 0, have_lasx = 0; ++ void *fp_ctx_p = NULL; ++ struct __nw_sctx_info *extinfo = (void *)&nw_ctx->uc_mcontext.__extcontext; ++ while (extinfo->magic) ++ { ++ switch (extinfo->magic) ++ { ++ case FPU_CTX_MAGIC: ++ { ++ struct __nw_fpu_context *fp_ctx = (void *)(extinfo + 1); ++ have_fpu = 1; ++ fp_ctx_p = fp_ctx; ++ ow_ctx.uc_mcontext.__fcsr = fp_ctx->fcsr; ++ ow_ctx.uc_mcontext.__fcc = fp_ctx->fcc; ++ for (int i = 0; i < 32; i++) ++ { ++ ow_ctx.uc_mcontext.__fpregs[i].__val64[0] = fp_ctx->regs[i]; ++ } ++ break; ++ } ++ case LSX_CTX_MAGIC: ++ { ++ struct __nw_lsx_context *fp_ctx = (void *)(extinfo + 1); ++ have_lsx = 1; ++ fp_ctx_p = fp_ctx; ++ ow_ctx.uc_mcontext.__fcsr = fp_ctx->fcsr; ++ ow_ctx.uc_mcontext.__fcc = fp_ctx->fcc; ++ for (int i = 0; i < 32; i++) ++ { ++ ow_ctx.uc_mcontext.__fpregs[i].__val64[0] = fp_ctx->regs[i][0]; ++ ow_ctx.uc_mcontext.__fpregs[i].__val64[1] = fp_ctx->regs[i][1]; ++ } ++ break; ++ } ++ case LASX_CTX_MAGIC: ++ { ++ struct __nw_lasx_context *fp_ctx = (void *)(extinfo + 1); ++ have_lasx = 1; ++ fp_ctx_p = fp_ctx; ++ ow_ctx.uc_mcontext.__fcsr = fp_ctx->fcsr; ++ ow_ctx.uc_mcontext.__fcc = fp_ctx->fcc; ++ for (int i = 0; i < 32; i++) ++ { ++ ow_ctx.uc_mcontext.__fpregs[i].__val64[0] = fp_ctx->regs[i][0]; ++ ow_ctx.uc_mcontext.__fpregs[i].__val64[1] = fp_ctx->regs[i][1]; ++ ow_ctx.uc_mcontext.__fpregs[i].__val64[2] = fp_ctx->regs[i][2]; ++ ow_ctx.uc_mcontext.__fpregs[i].__val64[3] = fp_ctx->regs[i][3]; ++ } ++ break; ++ } ++ } ++ if (have_fpu || have_lsx || have_lasx) ++ { ++ break; ++ } ++ extinfo = (struct __nw_sctx_info *)((void *)extinfo + extinfo->size); ++ } ++ ++ real_handler (sig, info, &ow_ctx); ++ ++ if (have_lasx) ++ { ++ struct __nw_lasx_context *fp_ctx = fp_ctx_p; ++ for (int i = 0; i < 32; i++) ++ { ++ fp_ctx->regs[i][0] = ow_ctx.uc_mcontext.__fpregs[i].__val64[0]; ++ fp_ctx->regs[i][1] = ow_ctx.uc_mcontext.__fpregs[i].__val64[1]; ++ fp_ctx->regs[i][2] = ow_ctx.uc_mcontext.__fpregs[i].__val64[2]; ++ fp_ctx->regs[i][3] = ow_ctx.uc_mcontext.__fpregs[i].__val64[3]; ++ } ++ fp_ctx->fcc = ow_ctx.uc_mcontext.__fcc; ++ fp_ctx->fcsr = ow_ctx.uc_mcontext.__fcsr; ++ } ++ else if (have_lsx) ++ { ++ struct __nw_lsx_context *fp_ctx = fp_ctx_p; ++ for (int i = 0; i < 32; i++) ++ { ++ fp_ctx->regs[i][0] = ow_ctx.uc_mcontext.__fpregs[i].__val64[0]; ++ fp_ctx->regs[i][1] = ow_ctx.uc_mcontext.__fpregs[i].__val64[1]; ++ } ++ fp_ctx->fcc = ow_ctx.uc_mcontext.__fcc; ++ fp_ctx->fcsr = ow_ctx.uc_mcontext.__fcsr; ++ } ++ else if (have_fpu) ++ { ++ struct __nw_fpu_context *fp_ctx = fp_ctx_p; ++ for (int i = 0; i < 32; i++) ++ { ++ fp_ctx->regs[i] = ow_ctx.uc_mcontext.__fpregs[i].__val64[0]; ++ } ++ fp_ctx->fcc = ow_ctx.uc_mcontext.__fcc; ++ fp_ctx->fcsr = ow_ctx.uc_mcontext.__fcsr; ++ } ++ __copy_ow_nw (nw_ctx, &ow_ctx); ++} ++ ++static inline int ++is_fake_handler (__linx_sighandler_t handler) ++{ ++ return handler == (__linx_sighandler_t)SIG_ERR ++ || handler == (__linx_sighandler_t)SIG_DFL ++ || handler == (__linx_sighandler_t)SIG_IGN ++#ifdef SIG_HOLD ++ || handler == (__linx_sighandler_t)SIG_HOLD ++#endif ++ ; ++} ++ ++ ++#define LA_INS_PCADDI 0x18000000u ++#define LA_INS_LD_D 0x28C00000u ++#define LA_INS_JIRL 0x4C000000u ++#define LA_REG_ZERO 0 ++#define LA_REG_T0 12 ++#define LA_REG_RA 1 ++#define LA_REG_A0 4 ++#define LA_REG_A1 5 ++#define LA_REG_A2 6 ++#define LA_REG_A3 7 ++#define LA_REG_A4 8 ++#define LA_REG_A5 9 ++ ++#define SIGHANDLER_PROG_NR_INS 4 ++struct __attribute__ ((__packed__, aligned (8))) sighandler_prog ++{ ++ unsigned int magic[2]; ++ unsigned int prog[SIGHANDLER_PROG_NR_INS]; ++ ++ struct sighandler_prog_data ++ { ++ unsigned long our_handler_addr; ++ unsigned long orig_handler_addr; ++ } data; ++} static const prog_tmpl = { ++ .magic = {U"开刀"}, ++ .prog = { ++ /* pcaddi $t0, SIGHANDLER_PROG_NR_INS */ ++ LA_INS_PCADDI | LA_REG_T0 | (SIGHANDLER_PROG_NR_INS << 5), ++ /* ld.d $a3, $t0, orig_handler_addr */ ++ LA_INS_LD_D | LA_REG_A3 | (LA_REG_T0 << 5) | (offsetof (struct sighandler_prog_data, orig_handler_addr) << 10), ++ /* ld.d $t0, $t0, our_handler_addr */ ++ LA_INS_LD_D | LA_REG_T0 | (LA_REG_T0 << 5) | (offsetof (struct sighandler_prog_data, our_handler_addr) << 10), ++ /* jirl $zero, $t0, 0 */ ++ LA_INS_JIRL | LA_REG_ZERO | (LA_REG_T0 << 5) | (0 << 10), ++ }, ++ .data = { ++ .our_handler_addr = (unsigned long)custom_handler, ++ } ++}; ++ ++ ++#define PROG_POOL_SIZE 2 ++#define LA_PAGE_SIZE (16 * 1024) ++ ++static_assert (sizeof (struct sighandler_prog) <= LA_PAGE_SIZE, ++ "sighandler_prog too large"); ++static_assert (SIGHANDLER_PROG_NR_INS < (1u << 19), "prog too long"); ++static_assert (offsetof (struct sighandler_prog, data.our_handler_addr) ++ == offsetof (struct sighandler_prog, prog) ++ + sizeof (unsigned int) * SIGHANDLER_PROG_NR_INS, ++ "data offset wrong"); ++static_assert (offsetof (struct sighandler_prog, data.our_handler_addr) ++ % sizeof (unsigned long) ++ == 0, ++ "data offset not aligned"); ++static_assert (offsetof (struct sighandler_prog_data, orig_handler_addr) ++ < (1u << 11), ++ "data too long"); ++static_assert (offsetof (struct sighandler_prog_data, our_handler_addr) ++ < (1u << 11), ++ "data too long"); ++ ++ ++struct sighandler_prog_pool ++{ ++ struct sighandler_prog *prog[PROG_POOL_SIZE]; ++ size_t pos; ++#if !IS_IN(rtld) ++ __libc_lock_define (, lock); ++#endif ++}; ++ ++static void ++destroy_handler (struct sighandler_prog *prog) ++{ ++ __munmap (prog, LA_PAGE_SIZE); ++} ++ ++ ++static struct sighandler_prog * ++alloc_handler (__linx_sighandler_t handler) ++{ ++ struct sighandler_prog *prog ++ = __mmap (NULL, LA_PAGE_SIZE, PROT_READ | PROT_WRITE, ++ MAP_ANON | MAP_PRIVATE, -1, 0); ++ if (__glibc_unlikely (prog == MAP_FAILED)) ++ { ++ return NULL; ++ } ++ memcpy (prog, &prog_tmpl, sizeof (struct sighandler_prog)); ++ prog->data.orig_handler_addr = (unsigned long)handler; ++ ++ int rc = __mprotect (prog, LA_PAGE_SIZE, PROT_READ | PROT_EXEC); ++ if (rc < 0) ++ { ++ destroy_handler (prog); ++ prog = NULL; ++ } ++ return prog; ++} ++ ++ ++static void ++store_handler (struct sighandler_prog_pool *pool, struct sighandler_prog *prog) ++{ ++ struct sighandler_prog *orig_prog; ++ orig_prog = pool->prog[pool->pos]; ++ pool->prog[pool->pos] = prog; ++ pool->pos = (pool->pos + 1) % PROG_POOL_SIZE; ++ if (orig_prog) ++ { ++ destroy_handler (orig_prog); ++ } ++} ++ ++int __ow___sigaction (int sig, const struct sigaction *act, struct sigaction *oact) ++{ ++ static struct sighandler_prog_pool prog_pool[NSIG] ++ = { [0 ... NSIG - 1] = { ++ .prog = { NULL }, ++ .pos = 0, ++#if !IS_IN(rtld) ++ .lock = _LIBC_LOCK_INITIALIZER, ++#endif ++ } }; ++ ++ sigset_t saveset, allset; ++ struct sighandler_prog *old_prog = NULL; ++ struct sighandler_prog *new_prog = NULL; ++ int result = 0, result2 = 0; ++ struct sigaction iact, ioact; ++ ++ if (sig <= 0 || sig >= __OW_NSIG || is_internal_signal (sig)) ++ { ++ __set_errno (EINVAL); ++ return -1; ++ } ++ ++ if (sig >= NSIG) ++ { ++ if (oact) ++ { ++ memset (oact, 0, sizeof (struct sigaction)); ++ oact->sa_handler = SIG_IGN; ++ } ++ return 0; ++ } ++ ++ if (act) ++ { ++ if (!is_fake_handler (act->sa_sigaction)) ++ { ++ new_prog = alloc_handler (act->sa_sigaction); ++ if (!new_prog) ++ { ++ return -1; ++ } ++ iact.sa_sigaction = (__linx_sighandler_t)new_prog; ++ } ++ else ++ { ++ iact.sa_sigaction = act->sa_sigaction; ++ } ++ memcpy (&iact.sa_mask, &act->sa_mask, sizeof (sigset_t)); ++ iact.sa_flags = act->sa_flags; ++ } ++ if (new_prog) ++ { ++ __sigfillset (&allset); ++ result = INLINE_SYSCALL_CALL (rt_sigprocmask, SIG_BLOCK, &allset, ++ &saveset, NSIG / 8); ++ if (result < 0) ++ { ++ destroy_handler (new_prog); ++ return result; ++ } ++ ++#if !IS_IN(rtld) ++ __libc_lock_lock (prog_pool[sig].lock); ++#endif ++ } ++ result = __libc_sigaction (sig, act ? &iact : NULL, oact ? &ioact : NULL); ++ if (result < 0) ++ { ++ if (new_prog) ++ { ++ destroy_handler (new_prog); ++ } ++ goto out_unlock; ++ } ++ if (oact) ++ { ++ oact->sa_sigaction = ioact.sa_sigaction; ++ if (!is_fake_handler (ioact.sa_sigaction)) ++ { ++ old_prog = (struct sighandler_prog *)ioact.sa_sigaction; ++ if (memcmp (old_prog->magic, prog_tmpl.magic, ++ sizeof (prog_tmpl.magic)) ++ == 0) ++ { ++ oact->sa_sigaction ++ = (__linx_sighandler_t)old_prog->data.orig_handler_addr; ++ } ++ } ++ memcpy (&oact->sa_mask, &ioact.sa_mask, NSIG / 8); ++ __ow_clear_unused_bits (&oact->sa_mask); ++ oact->sa_flags = ioact.sa_flags; ++ } ++ if (new_prog) ++ store_handler (&prog_pool[sig], new_prog); ++ ++out_unlock: ++ if (new_prog) ++ { ++#if !IS_IN(rtld) ++ __libc_lock_unlock (prog_pool[sig].lock); ++#endif ++ ++ result2 = INLINE_SYSCALL_CALL (rt_sigprocmask, SIG_SETMASK, &saveset, ++ NULL, NSIG / 8); ++ if (result2 < 0) ++ result = result2; ++ } ++ return result; ++} ++ ++#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_36) ++compat_symbol (libc, __ow___sigaction, sigaction, GLIBC_2_0); ++compat_symbol (libc, __ow___sigaction, __sigaction, GLIBC_2_0); ++#endif ++ ++#if OTHER_SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_34) ++compat_symbol (libpthread, __ow___sigaction, sigaction, GLIBC_2_0); ++compat_symbol (libpthread, __ow___sigaction, __sigaction, GLIBC_2_0); ++#endif ++#endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/swapcontext.S b/sysdeps/unix/sysv/linux/loongarch/swapcontext.S +index e58d5c0c..d69540ef 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/swapcontext.S ++++ b/sysdeps/unix/sysv/linux/loongarch/swapcontext.S +@@ -16,6 +16,7 @@ + License along with the GNU C Library. If not, see + . */ + ++#include + #include "ucontext-macros.h" + + /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */ +@@ -92,4 +93,4 @@ LEAF (__swapcontext) + + PSEUDO_END (__swapcontext) + +-weak_alias (__swapcontext, swapcontext) ++versioned_symbol (libc, __swapcontext, swapcontext, GLIBC_2_36); +-- +2.43.0 + diff --git a/debian/patches/glibc/0005-add-stubs-for-signal-related-io-funcs.patch b/debian/patches/glibc/0005-add-stubs-for-signal-related-io-funcs.patch new file mode 100644 index 000000000..09bcc7ec9 --- /dev/null +++ b/debian/patches/glibc/0005-add-stubs-for-signal-related-io-funcs.patch @@ -0,0 +1,83 @@ +From fc4952061e3fc675a3293eecf5880916ddafbf8f Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sat, 13 Jan 2024 07:38:04 +0800 +Subject: [PATCH 05/10] add stubs for signal related io funcs + +--- + sysdeps/unix/sysv/linux/loongarch/epoll_pwait.c | 1 + + sysdeps/unix/sysv/linux/loongarch/epoll_pwait2.c | 1 + + sysdeps/unix/sysv/linux/loongarch/ppoll.c | 1 + + sysdeps/unix/sysv/linux/loongarch/ppoll_chk.c | 1 + + sysdeps/unix/sysv/linux/loongarch/pselect.c | 1 + + sysdeps/unix/sysv/linux/loongarch/signalfd.c | 1 + + sysdeps/unix/sysv/linux/loongarch/spawnattr_getdefault.c | 1 + + sysdeps/unix/sysv/linux/loongarch/spawnattr_getsigmask.c | 1 + + 8 files changed, 8 insertions(+) + create mode 100644 sysdeps/unix/sysv/linux/loongarch/epoll_pwait.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/epoll_pwait2.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ppoll.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ppoll_chk.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/pselect.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/signalfd.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/spawnattr_getdefault.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/spawnattr_getsigmask.c + +diff --git a/sysdeps/unix/sysv/linux/loongarch/epoll_pwait.c b/sysdeps/unix/sysv/linux/loongarch/epoll_pwait.c +new file mode 100644 +index 00000000..5810355b +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/epoll_pwait.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/epoll_pwait2.c b/sysdeps/unix/sysv/linux/loongarch/epoll_pwait2.c +new file mode 100644 +index 00000000..1c7586a4 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/epoll_pwait2.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/ppoll.c b/sysdeps/unix/sysv/linux/loongarch/ppoll.c +new file mode 100644 +index 00000000..65b7258b +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ppoll.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/ppoll_chk.c b/sysdeps/unix/sysv/linux/loongarch/ppoll_chk.c +new file mode 100644 +index 00000000..638bd42c +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ppoll_chk.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/pselect.c b/sysdeps/unix/sysv/linux/loongarch/pselect.c +new file mode 100644 +index 00000000..224a88aa +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/pselect.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/signalfd.c b/sysdeps/unix/sysv/linux/loongarch/signalfd.c +new file mode 100644 +index 00000000..dc0ab6db +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/signalfd.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/spawnattr_getdefault.c b/sysdeps/unix/sysv/linux/loongarch/spawnattr_getdefault.c +new file mode 100644 +index 00000000..0d6e3feb +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/spawnattr_getdefault.c +@@ -0,0 +1 @@ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/spawnattr_getsigmask.c b/sysdeps/unix/sysv/linux/loongarch/spawnattr_getsigmask.c +new file mode 100644 +index 00000000..192980c6 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/spawnattr_getsigmask.c +@@ -0,0 +1 @@ ++#include +-- +2.43.0 + diff --git a/debian/patches/glibc/0006-add-syscall-fallback-for-stat-at.patch b/debian/patches/glibc/0006-add-syscall-fallback-for-stat-at.patch new file mode 100644 index 000000000..7ceb21376 --- /dev/null +++ b/debian/patches/glibc/0006-add-syscall-fallback-for-stat-at.patch @@ -0,0 +1,350 @@ +From 58396f14b1732fd25cb4ad965a9353f48e1b97f7 Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sun, 14 Jan 2024 15:51:49 +0800 +Subject: [PATCH 06/10] add syscall fallback for *stat(at)? + +--- + sysdeps/unix/sysv/linux/loongarch/fstatat64.c | 13 ++++ + sysdeps/unix/sysv/linux/loongarch/fxstat64.c | 67 ++++++++++++++++ + .../unix/sysv/linux/loongarch/fxstatat64.c | 61 +++++++++++++++ + sysdeps/unix/sysv/linux/loongarch/lxstat64.c | 77 +++++++++++++++++++ + .../unix/sysv/linux/loongarch/ow_syscall_nr.h | 2 + + sysdeps/unix/sysv/linux/loongarch/xstat64.c | 71 +++++++++++++++++ + 6 files changed, 291 insertions(+) + create mode 100644 sysdeps/unix/sysv/linux/loongarch/fstatat64.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/fxstat64.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/fxstatat64.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/lxstat64.c + create mode 100644 sysdeps/unix/sysv/linux/loongarch/ow_syscall_nr.h + create mode 100644 sysdeps/unix/sysv/linux/loongarch/xstat64.c + +diff --git a/sysdeps/unix/sysv/linux/loongarch/fstatat64.c b/sysdeps/unix/sysv/linux/loongarch/fstatat64.c +new file mode 100644 +index 00000000..a437eeaa +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/fstatat64.c +@@ -0,0 +1,13 @@ ++#include ++ ++#if LIB_COMPAT(libc, GLIBC_2_27, GLIBC_2_36) ++# include ++# ifdef __ASSUME_STATX ++# undef __ASSUME_STATX ++# endif ++// Hack: force use statx for fstatat64 even __NR_newfstatat is available ++# define STAT_HAS_TIME32 ++# include "ow_syscall_nr.h" ++#endif ++ ++#include +diff --git a/sysdeps/unix/sysv/linux/loongarch/fxstat64.c b/sysdeps/unix/sysv/linux/loongarch/fxstat64.c +new file mode 100644 +index 00000000..f7174ea8 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/fxstat64.c +@@ -0,0 +1,67 @@ ++/* fxstat64 using Linux fstat64/statx system call. ++ Copyright (C) 1997-2023 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#define __fxstat __redirect___fxstat ++#include ++#undef __fxstat ++#include ++#include ++#include ++#include ++#include ++#include ++#include "ow_syscall_nr.h" ++ ++#if LIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_33) ++ ++/* Get information about the file FD in BUF. */ ++ ++int ++___fxstat64 (int vers, int fd, struct stat64 *buf) ++{ ++ /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ ++ struct statx tmp; ++ int r = INLINE_SYSCALL_CALL (statx, fd, "", AT_EMPTY_PATH, ++ STATX_BASIC_STATS, &tmp); ++ if (r == 0) { ++ __cp_stat64_statx (buf, &tmp); ++ return r; ++ } else if (errno != ENOSYS) { ++ return r; ++ } ++#if defined __NR_fstat ++ if (vers == _STAT_VER_KERNEL || vers == _STAT_VER_LINUX) ++ return INLINE_SYSCALL_CALL (fstat, fd, buf); ++ return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); ++#endif ++ return r; ++} ++ ++#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) ++versioned_symbol (libc, ___fxstat64, __fxstat64, GLIBC_2_2); ++strong_alias (___fxstat64, __old__fxstat64) ++compat_symbol (libc, __old__fxstat64, __fxstat64, GLIBC_2_1); ++#else ++strong_alias (___fxstat64, __fxstat64) ++#endif ++ ++#if XSTAT_IS_XSTAT64 ++strong_alias (___fxstat64, __fxstat) ++#endif ++ ++#endif /* LIB_COMPAT */ +diff --git a/sysdeps/unix/sysv/linux/loongarch/fxstatat64.c b/sysdeps/unix/sysv/linux/loongarch/fxstatat64.c +new file mode 100644 +index 00000000..720f12a0 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/fxstatat64.c +@@ -0,0 +1,61 @@ ++/* fxstatat64 used on fstatat64, Linux implementation. ++ Copyright (C) 2005-2023 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#define __fxstatat __redirect___fxstatat ++#include ++#undef __fxstatat ++#include ++#include ++#include ++#include ++#include ++#include ++#include "ow_syscall_nr.h" ++ ++#if LIB_COMPAT(libc, GLIBC_2_4, GLIBC_2_33) ++ ++/* Get information about the file FD in BUF. */ ++ ++int ++__fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag) ++{ ++ /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ ++ if (vers == _STAT_VER_KERNEL) ++ { ++ struct statx tmp; ++ int r = INLINE_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag, ++ STATX_BASIC_STATS, &tmp); ++ if (r == 0) { ++ __cp_stat64_statx (st, &tmp); ++ return r; ++ }else if (errno != ENOSYS){ ++ return r; ++ } ++#if defined __NR_newfstatat ++ return INLINE_SYSCALL_CALL (newfstatat, fd, file, st, flag); ++#endif ++ return r; ++ } ++ return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); ++} ++ ++#if XSTAT_IS_XSTAT64 ++strong_alias (__fxstatat64, __fxstatat) ++#endif ++ ++#endif /* LIB_COMPAT(libc, GLIBC_2_4, GLIBC_2_33) */ +diff --git a/sysdeps/unix/sysv/linux/loongarch/lxstat64.c b/sysdeps/unix/sysv/linux/loongarch/lxstat64.c +new file mode 100644 +index 00000000..ab561ce0 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/lxstat64.c +@@ -0,0 +1,77 @@ ++/* lxstat64 using Linux lstat64 system call. ++ Copyright (C) 1991-2023 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#define __lxstat __redirect___lxstat ++#include ++#undef __lxstat ++#include ++#include ++#include ++#include ++#include ++#include ++#include "ow_syscall_nr.h" ++ ++#if LIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_33) ++ ++/* Get information about the file NAME in BUF. */ ++ ++int ++___lxstat64 (int vers, const char *name, struct stat64 *buf) ++{ ++ /* New kABIs which uses generic 64-bit Linux ABI, e.g. aarch64, riscv64. */ ++ if (vers == _STAT_VER_KERNEL) ++ return INLINE_SYSCALL_CALL (newfstatat, AT_FDCWD, name, buf, ++ AT_SYMLINK_NOFOLLOW); ++ ++ /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ ++ if (vers == _STAT_VER_KERNEL) ++ { ++ struct statx tmp; ++ int r = INLINE_SYSCALL_CALL (statx, AT_FDCWD, name, ++ AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW, ++ STATX_BASIC_STATS, &tmp); ++ if (r == 0) { ++ __cp_stat64_statx (buf, &tmp); ++ return r; ++ }else if(errno != ENOSYS){ ++ return r; ++ } ++#if defined __NR_newfstatat ++ return INLINE_SYSCALL_CALL (newfstatat, AT_FDCWD, name, buf, ++ AT_SYMLINK_NOFOLLOW); ++#endif ++ return r; ++ } ++ ++ return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); ++} ++ ++#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) ++versioned_symbol (libc, ___lxstat64, __lxstat64, GLIBC_2_2); ++strong_alias (___lxstat64, __old__lxstat64) ++compat_symbol (libc, __old__lxstat64, __lxstat64, GLIBC_2_1); ++#else ++strong_alias (___lxstat64, __lxstat64); ++#endif ++ ++#if XSTAT_IS_XSTAT64 ++strong_alias (___lxstat64,__lxstat) ++#endif ++ ++#endif /* LIB_COMPAT */ +diff --git a/sysdeps/unix/sysv/linux/loongarch/ow_syscall_nr.h b/sysdeps/unix/sysv/linux/loongarch/ow_syscall_nr.h +new file mode 100644 +index 00000000..61886aeb +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/ow_syscall_nr.h +@@ -0,0 +1,2 @@ ++#define __NR_newfstatat 79 ++#define __NR_fstat 80 +diff --git a/sysdeps/unix/sysv/linux/loongarch/xstat64.c b/sysdeps/unix/sysv/linux/loongarch/xstat64.c +new file mode 100644 +index 00000000..c30f52e9 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/xstat64.c +@@ -0,0 +1,71 @@ ++/* xstat64 using Linux stat64 system call. ++ Copyright (C) 1991-2023 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#define __xstat __redirect___xstat ++#include ++#undef __xstat ++#include ++#include ++#include ++#include ++#include ++#include ++#include "ow_syscall_nr.h" ++ ++#if LIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_33) ++ ++/* Get information about the file NAME in BUF. */ ++ ++int ++___xstat64 (int vers, const char *name, struct stat64 *buf) ++{ ++ /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ ++ if (vers == _STAT_VER_KERNEL) ++ { ++ struct statx tmp; ++ int r = INLINE_SYSCALL_CALL (statx, AT_FDCWD, name, AT_NO_AUTOMOUNT, ++ STATX_BASIC_STATS, &tmp); ++ if (r == 0) { ++ __cp_stat64_statx (buf, &tmp); ++ return r; ++ }else if(errno != ENOSYS){ ++ return r; ++ } ++#if defined __NR_newfstatat ++ return INLINE_SYSCALL_CALL (newfstatat, AT_FDCWD, name, buf, 0); ++#endif ++ return r; ++ } ++ ++ return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); ++} ++ ++#if XSTAT_IS_XSTAT64 ++strong_alias (___xstat64, __xstat) ++#endif ++ ++#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) ++versioned_symbol (libc, ___xstat64, __xstat64, GLIBC_2_2); ++strong_alias (___xstat64, __old__xstat64) ++compat_symbol (libc, __old__xstat64, __xstat64, GLIBC_2_1); ++#else ++strong_alias (___xstat64, __xstat64) ++#endif ++ ++ ++#endif /* LIB_COMPAT */ +-- +2.43.0 + diff --git a/debian/patches/glibc/0007-add-more-pthread-symbols.patch b/debian/patches/glibc/0007-add-more-pthread-symbols.patch new file mode 100644 index 000000000..52b0f0af9 --- /dev/null +++ b/debian/patches/glibc/0007-add-more-pthread-symbols.patch @@ -0,0 +1,467 @@ +From 6b633be48edaedf1337da787a8da18eec0f0b151 Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sun, 14 Jan 2024 08:41:15 +0800 +Subject: [PATCH 07/10] add more pthread symbols + +--- + nptl/old_pthread_cond_destroy.c | 4 ++-- + nptl/old_pthread_cond_init.c | 4 ++-- + nptl/pthread_attr_init.c | 6 +++--- + nptl/pthread_attr_setaffinity.c | 10 +++++----- + nptl/pthread_attr_setstack.c | 4 ++-- + nptl/pthread_attr_setstacksize.c | 2 +- + nptl/pthread_cond_broadcast.c | 2 +- + nptl/pthread_cond_destroy.c | 2 +- + nptl/pthread_cond_init.c | 2 +- + nptl/pthread_cond_wait.c | 4 ++-- + nptl/pthread_detach.c | 2 +- + nptl/pthread_getaffinity.c | 10 +++++----- + nptl/pthread_getattr_np.c | 6 +++--- + nptl/pthread_join.c | 4 ++-- + nptl/pthread_kill.c | 4 ++-- + nptl/pthread_mutex_destroy.c | 2 +- + nptl/pthread_mutexattr_destroy.c | 6 +++--- + nptl/pthread_setattr_default_np.c | 4 ++-- + nptl/pthread_sigmask.c | 6 +++--- + nptl/pthread_testcancel.c | 4 ++-- + nptl/pthread_tryjoin.c | 4 ++-- + sysdeps/loongarch/nptl/pthread_sigmask.c | 10 +++++----- + sysdeps/unix/sysv/linux/loongarch/Makefile | 4 ++++ + 23 files changed, 55 insertions(+), 51 deletions(-) + +diff --git a/nptl/old_pthread_cond_destroy.c b/nptl/old_pthread_cond_destroy.c +index b7cf4286..f6340f36 100644 +--- a/nptl/old_pthread_cond_destroy.c ++++ b/nptl/old_pthread_cond_destroy.c +@@ -20,7 +20,7 @@ + #include + + +-#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_3_2) + int + __pthread_cond_destroy_2_0 (pthread_cond_2_0_t *cond) + { +@@ -29,6 +29,6 @@ __pthread_cond_destroy_2_0 (pthread_cond_2_0_t *cond) + + return 0; + } +-compat_symbol (libc, __pthread_cond_destroy_2_0, pthread_cond_destroy, ++compat_symbol (libpthread, __pthread_cond_destroy_2_0, pthread_cond_destroy, + GLIBC_2_0); + #endif +diff --git a/nptl/old_pthread_cond_init.c b/nptl/old_pthread_cond_init.c +index 01efd333..2cd57d9a 100644 +--- a/nptl/old_pthread_cond_init.c ++++ b/nptl/old_pthread_cond_init.c +@@ -20,7 +20,7 @@ + #include + + +-#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_3_2) + int + __pthread_cond_init_2_0 (pthread_cond_2_0_t *cond, + const pthread_condattr_t *cond_attr) +@@ -39,6 +39,6 @@ __pthread_cond_init_2_0 (pthread_cond_2_0_t *cond, + + return 0; + } +-compat_symbol (libc, __pthread_cond_init_2_0, pthread_cond_init, ++compat_symbol (libpthread, __pthread_cond_init_2_0, pthread_cond_init, + GLIBC_2_0); + #endif +diff --git a/nptl/pthread_attr_init.c b/nptl/pthread_attr_init.c +index d55dfa20..88c7563a 100644 +--- a/nptl/pthread_attr_init.c ++++ b/nptl/pthread_attr_init.c +@@ -48,10 +48,10 @@ __pthread_attr_init (pthread_attr_t *attr) + return 0; + } + libc_hidden_def (__pthread_attr_init) +-versioned_symbol (libc, __pthread_attr_init, pthread_attr_init, GLIBC_2_1); ++versioned_symbol (libpthread, __pthread_attr_init, pthread_attr_init, GLIBC_2_1); + + +-#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_1) ++#if OTHER_SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1) + int + __pthread_attr_init_2_0 (pthread_attr_t *attr) + { +@@ -80,5 +80,5 @@ __pthread_attr_init_2_0 (pthread_attr_t *attr) + old attribute structure. */ + return 0; + } +-compat_symbol (libc, __pthread_attr_init_2_0, pthread_attr_init, GLIBC_2_0); ++compat_symbol (libpthread, __pthread_attr_init_2_0, pthread_attr_init, GLIBC_2_0); + #endif +diff --git a/nptl/pthread_attr_setaffinity.c b/nptl/pthread_attr_setaffinity.c +index 96a060c0..670e58c9 100644 +--- a/nptl/pthread_attr_setaffinity.c ++++ b/nptl/pthread_attr_setaffinity.c +@@ -62,24 +62,24 @@ __pthread_attr_setaffinity_np (pthread_attr_t *attr, size_t cpusetsize, + return 0; + } + libc_hidden_def (__pthread_attr_setaffinity_np) +-versioned_symbol (libc, __pthread_attr_setaffinity_np, ++versioned_symbol (libpthread, __pthread_attr_setaffinity_np, + pthread_attr_setaffinity_np, GLIBC_2_32); + + +-#if SHLIB_COMPAT (libc, GLIBC_2_3_4, GLIBC_2_32) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_4, GLIBC_2_32) + /* Compat symbol with the old libc version. */ + strong_alias (__pthread_attr_setaffinity_np, __pthread_attr_setaffinity_alias) +-compat_symbol (libc, __pthread_attr_setaffinity_alias, ++compat_symbol (libpthread, __pthread_attr_setaffinity_alias, + pthread_attr_setaffinity_np, GLIBC_2_3_4); + #endif + +-#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4) + int + __pthread_attr_setaffinity_old (pthread_attr_t *attr, cpu_set_t *cpuset) + { + /* The old interface by default assumed a 1024 processor bitmap. */ + return __pthread_attr_setaffinity_np (attr, 128, cpuset); + } +-compat_symbol (libc, __pthread_attr_setaffinity_old, ++compat_symbol (libpthread, __pthread_attr_setaffinity_old, + pthread_attr_setaffinity_np, GLIBC_2_3_3); + #endif +diff --git a/nptl/pthread_attr_setstack.c b/nptl/pthread_attr_setstack.c +index 6eff8bc9..95de1d1f 100644 +--- a/nptl/pthread_attr_setstack.c ++++ b/nptl/pthread_attr_setstack.c +@@ -53,10 +53,10 @@ __pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, + + return 0; + } +-versioned_symbol (libc, __pthread_attr_setstack, pthread_attr_setstack, ++versioned_symbol (libpthread, __pthread_attr_setstack, pthread_attr_setstack, + GLIBC_2_34); + +-#if PTHREAD_STACK_MIN == 16384 ++#if PTHREAD_STACK_MIN == 16384 && !defined(COMP_CHANGED_PTHREAD_STACK_MIN) + # if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_2, GLIBC_2_34) + compat_symbol (libpthread, __pthread_attr_setstack, pthread_attr_setstack, + GLIBC_2_2); +diff --git a/nptl/pthread_attr_setstacksize.c b/nptl/pthread_attr_setstacksize.c +index 75eb3a87..91f89fe2 100644 +--- a/nptl/pthread_attr_setstacksize.c ++++ b/nptl/pthread_attr_setstacksize.c +@@ -45,7 +45,7 @@ versioned_symbol (libc, __pthread_attr_setstacksize, + pthread_attr_setstacksize, GLIBC_2_34); + + +-#if PTHREAD_STACK_MIN == 16384 ++#if PTHREAD_STACK_MIN == 16384 && !defined(COMP_CHANGED_PTHREAD_STACK_MIN) + # if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_1, GLIBC_2_34) + compat_symbol (libpthread, __pthread_attr_setstacksize, + pthread_attr_setstacksize, GLIBC_2_1); +diff --git a/nptl/pthread_cond_broadcast.c b/nptl/pthread_cond_broadcast.c +index 74099583..008eeadb 100644 +--- a/nptl/pthread_cond_broadcast.c ++++ b/nptl/pthread_cond_broadcast.c +@@ -86,7 +86,7 @@ ___pthread_cond_broadcast (pthread_cond_t *cond) + + return 0; + } +-versioned_symbol (libc, ___pthread_cond_broadcast, ++versioned_symbol (libpthread, ___pthread_cond_broadcast, + pthread_cond_broadcast, GLIBC_2_3_2); + libc_hidden_ver (___pthread_cond_broadcast, __pthread_cond_broadcast) + #ifndef SHARED +diff --git a/nptl/pthread_cond_destroy.c b/nptl/pthread_cond_destroy.c +index 98c12c83..b014acc3 100644 +--- a/nptl/pthread_cond_destroy.c ++++ b/nptl/pthread_cond_destroy.c +@@ -58,5 +58,5 @@ __pthread_cond_destroy (pthread_cond_t *cond) + return 0; + } + libc_hidden_def (__pthread_cond_destroy) +-versioned_symbol (libc, __pthread_cond_destroy, ++versioned_symbol (libpthread, __pthread_cond_destroy, + pthread_cond_destroy, GLIBC_2_3_2); +diff --git a/nptl/pthread_cond_init.c b/nptl/pthread_cond_init.c +index 28829957..f73d0ea6 100644 +--- a/nptl/pthread_cond_init.c ++++ b/nptl/pthread_cond_init.c +@@ -49,5 +49,5 @@ __pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *cond_attr) + return 0; + } + libc_hidden_def (__pthread_cond_init) +-versioned_symbol (libc, __pthread_cond_init, ++versioned_symbol (libpthread, __pthread_cond_init, + pthread_cond_init, GLIBC_2_3_2); +diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c +index 806c432d..cff09c85 100644 +--- a/nptl/pthread_cond_wait.c ++++ b/nptl/pthread_cond_wait.c +@@ -618,7 +618,7 @@ ___pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) + return __pthread_cond_wait_common (cond, mutex, 0, NULL); + } + +-versioned_symbol (libc, ___pthread_cond_wait, pthread_cond_wait, ++versioned_symbol (libpthread, ___pthread_cond_wait, pthread_cond_wait, + GLIBC_2_3_2); + libc_hidden_ver (___pthread_cond_wait, __pthread_cond_wait) + #ifndef SHARED +@@ -658,7 +658,7 @@ ___pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, + return __pthread_cond_timedwait64 (cond, mutex, &ts64); + } + #endif /* __TIMESIZE == 64 */ +-versioned_symbol (libc, ___pthread_cond_timedwait, ++versioned_symbol (libpthread, ___pthread_cond_timedwait, + pthread_cond_timedwait, GLIBC_2_3_2); + libc_hidden_ver (___pthread_cond_timedwait, __pthread_cond_timedwait) + #ifndef SHARED +diff --git a/nptl/pthread_detach.c b/nptl/pthread_detach.c +index 741c3c58..f911be77 100644 +--- a/nptl/pthread_detach.c ++++ b/nptl/pthread_detach.c +@@ -59,5 +59,5 @@ strong_alias (___pthread_detach, __pthread_detach) + #endif + + #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_34) +-compat_symbol (libc, ___pthread_detach, pthread_detach, GLIBC_2_0); ++compat_symbol (libpthread, ___pthread_detach, pthread_detach, GLIBC_2_0); + #endif +diff --git a/nptl/pthread_getaffinity.c b/nptl/pthread_getaffinity.c +index b9483537..e2027183 100644 +--- a/nptl/pthread_getaffinity.c ++++ b/nptl/pthread_getaffinity.c +@@ -41,22 +41,22 @@ __pthread_getaffinity_np (pthread_t th, size_t cpusetsize, cpu_set_t *cpuset) + return 0; + } + libc_hidden_def (__pthread_getaffinity_np) +-versioned_symbol (libc, __pthread_getaffinity_np, pthread_getaffinity_np, ++versioned_symbol (libpthread, __pthread_getaffinity_np, pthread_getaffinity_np, + GLIBC_2_32); + +-#if SHLIB_COMPAT (libc, GLIBC_2_3_4, GLIBC_2_32) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_4, GLIBC_2_32) + strong_alias (__pthread_getaffinity_np, __pthread_getaffinity_alias) +-compat_symbol (libc, __pthread_getaffinity_alias, pthread_getaffinity_np, ++compat_symbol (libpthread, __pthread_getaffinity_alias, pthread_getaffinity_np, + GLIBC_2_3_4); + #endif + +-#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4) + int + __pthread_getaffinity_old (pthread_t th, cpu_set_t *cpuset) + { + /* The old interface by default assumed a 1024 processor bitmap. */ + return __pthread_getaffinity_np (th, 128, cpuset); + } +-compat_symbol (libc, __pthread_getaffinity_old, pthread_getaffinity_np, ++compat_symbol (libpthread, __pthread_getaffinity_old, pthread_getaffinity_np, + GLIBC_2_3_3); + #endif +diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c +index 65647bda..a740355c 100644 +--- a/nptl/pthread_getattr_np.c ++++ b/nptl/pthread_getattr_np.c +@@ -205,10 +205,10 @@ __pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr) + + return ret; + } +-versioned_symbol (libc, __pthread_getattr_np, pthread_getattr_np, GLIBC_2_32); ++versioned_symbol (libpthread, __pthread_getattr_np, pthread_getattr_np, GLIBC_2_32); + +-#if SHLIB_COMPAT (libc, GLIBC_2_2_3, GLIBC_2_32) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_2_3, GLIBC_2_32) + strong_alias (__pthread_getattr_np, __pthread_getattr_np_alias) +-compat_symbol (libc, __pthread_getattr_np_alias, ++compat_symbol (libpthread, __pthread_getattr_np_alias, + pthread_getattr_np, GLIBC_2_2_3); + #endif +diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c +index 2f661039..37f16405 100644 +--- a/nptl/pthread_join.c ++++ b/nptl/pthread_join.c +@@ -24,12 +24,12 @@ ___pthread_join (pthread_t threadid, void **thread_return) + return __pthread_clockjoin_ex (threadid, thread_return, 0 /* Ignored */, + NULL, true); + } +-versioned_symbol (libc, ___pthread_join, pthread_join, GLIBC_2_34); ++versioned_symbol (libpthread, ___pthread_join, pthread_join, GLIBC_2_34); + libc_hidden_ver (___pthread_join, __pthread_join) + #ifndef SHARED + strong_alias (___pthread_join, __pthread_join) + #endif + + #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_34) +-compat_symbol (libc, ___pthread_join, pthread_join, GLIBC_2_0); ++compat_symbol (libpthread, ___pthread_join, pthread_join, GLIBC_2_0); + #endif +diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c +index 44e45a4e..c5d2354f 100644 +--- a/nptl/pthread_kill.c ++++ b/nptl/pthread_kill.c +@@ -93,7 +93,7 @@ __pthread_kill (pthread_t threadid, int signo) + avoid the symbol version if it ends up being used on ld.so. */ + #if !IS_IN(rtld) + libc_hidden_def (__pthread_kill) +-versioned_symbol (libc, __pthread_kill, pthread_kill, GLIBC_2_34); ++versioned_symbol (libpthread, __pthread_kill, pthread_kill, GLIBC_2_34); + + # if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_34) + /* Variant which returns ESRCH in the no-TID case, for backwards +@@ -107,6 +107,6 @@ __pthread_kill_esrch (pthread_t threadid, int signo) + + return __pthread_kill_implementation (threadid, signo, ESRCH); + } +-compat_symbol (libc, __pthread_kill_esrch, pthread_kill, GLIBC_2_0); ++compat_symbol (libpthread, __pthread_kill_esrch, pthread_kill, GLIBC_2_0); + # endif + #endif +diff --git a/nptl/pthread_mutex_destroy.c b/nptl/pthread_mutex_destroy.c +index dbb63600..ae79c36d 100644 +--- a/nptl/pthread_mutex_destroy.c ++++ b/nptl/pthread_mutex_destroy.c +@@ -40,7 +40,7 @@ ___pthread_mutex_destroy (pthread_mutex_t *mutex) + + return 0; + } +-versioned_symbol (libc, ___pthread_mutex_destroy, pthread_mutex_destroy, ++versioned_symbol (libpthread, ___pthread_mutex_destroy, pthread_mutex_destroy, + GLIBC_2_0); + libc_hidden_ver (___pthread_mutex_destroy, __pthread_mutex_destroy) + #ifndef SHARED +diff --git a/nptl/pthread_mutexattr_destroy.c b/nptl/pthread_mutexattr_destroy.c +index 89ce6cad..c5890edd 100644 +--- a/nptl/pthread_mutexattr_destroy.c ++++ b/nptl/pthread_mutexattr_destroy.c +@@ -23,11 +23,11 @@ ___pthread_mutexattr_destroy (pthread_mutexattr_t *attr) + { + return 0; + } +-versioned_symbol (libc, ___pthread_mutexattr_destroy, ++versioned_symbol (libpthread, ___pthread_mutexattr_destroy, + pthread_mutexattr_destroy, GLIBC_2_34); + #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_34) +-compat_symbol (libc, ___pthread_mutexattr_destroy, ++compat_symbol (libpthread, ___pthread_mutexattr_destroy, + pthread_mutexattr_destroy, GLIBC_2_0); +-compat_symbol (libc, ___pthread_mutexattr_destroy, ++compat_symbol (libpthread, ___pthread_mutexattr_destroy, + __pthread_mutexattr_destroy, GLIBC_2_0); + #endif +diff --git a/nptl/pthread_setattr_default_np.c b/nptl/pthread_setattr_default_np.c +index 27b87b57..02122b5b 100644 +--- a/nptl/pthread_setattr_default_np.c ++++ b/nptl/pthread_setattr_default_np.c +@@ -81,10 +81,10 @@ __pthread_setattr_default_np (const pthread_attr_t *in) + lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE); + return ret; + } +-versioned_symbol (libc, __pthread_setattr_default_np, ++versioned_symbol (libpthread, __pthread_setattr_default_np, + pthread_setattr_default_np, GLIBC_2_34); + #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_18, GLIBC_2_34) +-compat_symbol (libc, __pthread_setattr_default_np, ++compat_symbol (libpthread, __pthread_setattr_default_np, + pthread_setattr_default_np, GLIBC_2_18); + #endif + +diff --git a/nptl/pthread_sigmask.c b/nptl/pthread_sigmask.c +index 409f4467..15bad2e9 100644 +--- a/nptl/pthread_sigmask.c ++++ b/nptl/pthread_sigmask.c +@@ -46,8 +46,8 @@ __pthread_sigmask (int how, const sigset_t *newmask, sigset_t *oldmask) + } + libc_hidden_def (__pthread_sigmask) + +-versioned_symbol (libc, __pthread_sigmask, pthread_sigmask, GLIBC_2_32); +-#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_32) ++versioned_symbol (libpthread, __pthread_sigmask, pthread_sigmask, GLIBC_2_32); ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_32) + strong_alias (__pthread_sigmask, __pthread_sigmask_2); +-compat_symbol (libc, __pthread_sigmask_2, pthread_sigmask, GLIBC_2_0); ++compat_symbol (libpthread, __pthread_sigmask_2, pthread_sigmask, GLIBC_2_0); + #endif +diff --git a/nptl/pthread_testcancel.c b/nptl/pthread_testcancel.c +index 38b5a2d4..0246b732 100644 +--- a/nptl/pthread_testcancel.c ++++ b/nptl/pthread_testcancel.c +@@ -30,12 +30,12 @@ ___pthread_testcancel (void) + __do_cancel (); + } + } +-versioned_symbol (libc, ___pthread_testcancel, pthread_testcancel, GLIBC_2_34); ++versioned_symbol (libpthread, ___pthread_testcancel, pthread_testcancel, GLIBC_2_34); + libc_hidden_ver (___pthread_testcancel, __pthread_testcancel) + #ifndef SHARED + strong_alias (___pthread_testcancel, __pthread_testcancel) + #endif + + #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_34) +-compat_symbol (libc, ___pthread_testcancel, pthread_testcancel, GLIBC_2_0); ++compat_symbol (libpthread, ___pthread_testcancel, pthread_testcancel, GLIBC_2_0); + #endif +diff --git a/nptl/pthread_tryjoin.c b/nptl/pthread_tryjoin.c +index 97137c07..dde45f55 100644 +--- a/nptl/pthread_tryjoin.c ++++ b/nptl/pthread_tryjoin.c +@@ -31,8 +31,8 @@ __pthread_tryjoin_np (pthread_t threadid, void **thread_return) + return __pthread_clockjoin_ex (threadid, thread_return, 0 /* Ignored */, + NULL, false); + } +-versioned_symbol (libc, __pthread_tryjoin_np, pthread_tryjoin_np, GLIBC_2_34); ++versioned_symbol (libpthread, __pthread_tryjoin_np, pthread_tryjoin_np, GLIBC_2_34); + + #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_34) +-compat_symbol (libc, __pthread_tryjoin_np, pthread_tryjoin_np, GLIBC_2_3_3); ++compat_symbol (libpthread, __pthread_tryjoin_np, pthread_tryjoin_np, GLIBC_2_3_3); + #endif +diff --git a/sysdeps/loongarch/nptl/pthread_sigmask.c b/sysdeps/loongarch/nptl/pthread_sigmask.c +index d6947000..707787a6 100644 +--- a/sysdeps/loongarch/nptl/pthread_sigmask.c ++++ b/sysdeps/loongarch/nptl/pthread_sigmask.c +@@ -48,7 +48,7 @@ libc_hidden_def (__pthread_sigmask) + + versioned_symbol (libc, __pthread_sigmask, pthread_sigmask, GLIBC_2_36); + +-#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_36) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_36) + + #include + +@@ -61,13 +61,13 @@ __ow___pthread_sigmask (int how, const sigset_t *newmask, sigset_t *oldmask) + } + return rc; + } +-#if SHLIB_COMPAT (libc, GLIBC_2_32, GLIBC_2_36) +-compat_symbol (libc, __ow___pthread_sigmask, pthread_sigmask, GLIBC_2_32); ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_32, GLIBC_2_36) ++compat_symbol (libpthread, __ow___pthread_sigmask, pthread_sigmask, GLIBC_2_32); + #endif + +-#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_32) ++#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_32) + strong_alias (__ow___pthread_sigmask, __ow___pthread_sigmask_2); +-compat_symbol (libc, __ow___pthread_sigmask_2, pthread_sigmask, GLIBC_2_0); ++compat_symbol (libpthread, __ow___pthread_sigmask_2, pthread_sigmask, GLIBC_2_0); + #endif + + #endif +diff --git a/sysdeps/unix/sysv/linux/loongarch/Makefile b/sysdeps/unix/sysv/linux/loongarch/Makefile +index 1d447ea4..4d1d5d0e 100644 +--- a/sysdeps/unix/sysv/linux/loongarch/Makefile ++++ b/sysdeps/unix/sysv/linux/loongarch/Makefile +@@ -21,6 +21,10 @@ sysdep_routines += \ + # sysdep_routines + endif + ++ifeq ($(subdir),nptl) ++sysdep-CFLAGS += -DCOMP_CHANGED_PTHREAD_STACK_MIN ++endif ++ + abi-variants := lp64s lp64d + + ifeq (,$(filter $(default-abi),$(abi-variants))) +-- +2.43.0 + diff --git a/debian/patches/glibc/0008-remove-clone3-for-compatibility-with-qq.patch b/debian/patches/glibc/0008-remove-clone3-for-compatibility-with-qq.patch new file mode 100644 index 000000000..ccd17d58d --- /dev/null +++ b/debian/patches/glibc/0008-remove-clone3-for-compatibility-with-qq.patch @@ -0,0 +1,27 @@ +From fdc90d7c81ac8801f9fe678adc6c0c5af83530b5 Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sun, 14 Jan 2024 16:51:44 +0800 +Subject: [PATCH 08/10] remove clone3 for compatibility with qq + +--- + sysdeps/unix/sysv/linux/loongarch/clone-internal.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone-internal.c + +diff --git a/sysdeps/unix/sysv/linux/loongarch/clone-internal.c b/sysdeps/unix/sysv/linux/loongarch/clone-internal.c +new file mode 100644 +index 00000000..e01ce980 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/clone-internal.c +@@ -0,0 +1,8 @@ ++#include ++ ++#if LIB_COMPAT(libc, GLIBC_2_27, GLIBC_2_36) ++#include ++#undef HAVE_CLONE3_WRAPPER ++#endif ++ ++#include +-- +2.43.0 + diff --git a/debian/patches/glibc/0009-prepend-trusted-dirs.patch b/debian/patches/glibc/0009-prepend-trusted-dirs.patch new file mode 100644 index 000000000..146b8935f --- /dev/null +++ b/debian/patches/glibc/0009-prepend-trusted-dirs.patch @@ -0,0 +1,95 @@ +From 8cbd2273506313f5eb287f97b657205fccb808cd Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Sun, 14 Jan 2024 13:28:41 +0800 +Subject: [PATCH 09/10] prepend trusted-dirs + +and search prepended trusted-dirs before other pathes +--- + elf/Makefile | 3 ++- + elf/dl-load.c | 26 ++++++++++++++++++++++++-- + 2 files changed, 26 insertions(+), 3 deletions(-) + +diff --git a/elf/Makefile b/elf/Makefile +index c00e2ccf..ed1f709c 100644 +--- a/elf/Makefile ++++ b/elf/Makefile +@@ -1355,9 +1355,10 @@ endif + $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @: + $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig + $(make-target-directory) +- echo "$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \ ++ echo "$(subst :, ,$(user-defined-trusted-dirs-pre) $(default-rpath) $(user-defined-trusted-dirs))" \ + | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T}; + echo '#define DL_DST_LIB "$(notdir $(slibdir))"' >> ${@:st=T} ++ echo '#define SYSTEM_DIRS_PRE_COUNT $(words $(subst :, ,$(user-defined-trusted-dirs-pre)))' >> ${@:st=T} + $(move-if-change) ${@:st=T} ${@:st=h} + touch $@ + CPPFLAGS-dl-load.c += -I$(objpfx). -I$(csu-objpfx). +diff --git a/elf/dl-load.c b/elf/dl-load.c +index 9a87fda9..d11309f2 100644 +--- a/elf/dl-load.c ++++ b/elf/dl-load.c +@@ -123,6 +123,9 @@ static const size_t system_dirs_len[] = + SYSTEM_DIRS_LEN + }; + #define nsystem_dirs_len array_length (system_dirs_len) ++#define normal_system_dirs_len (nsystem_dirs_len - SYSTEM_DIRS_PRE_COUNT) ++ ++static_assert (SYSTEM_DIRS_PRE_COUNT < nsystem_dirs_len, "should have at least one system dir"); + + static bool + is_trusted_path_normalize (const char *path, size_t len) +@@ -723,7 +726,7 @@ _dl_init_paths (const char *llp, const char *source, + + /* First set up the rest of the default search directory entries. */ + aelem = __rtld_search_dirs.dirs = (struct r_search_path_elem **) +- malloc ((nsystem_dirs_len + 1) * sizeof (struct r_search_path_elem *)); ++ malloc ((nsystem_dirs_len + 2) * sizeof (struct r_search_path_elem *)); + if (__rtld_search_dirs.dirs == NULL) + { + errstring = N_("cannot create search path array"); +@@ -748,11 +751,17 @@ _dl_init_paths (const char *llp, const char *source, + pelem = GL(dl_all_dirs) = __rtld_search_dirs.dirs[0]; + strp = system_dirs; + idx = 0; ++ aelem = &__rtld_search_dirs.dirs[normal_system_dirs_len + 1]; + + do + { + size_t cnt; + ++ if (aelem == &__rtld_search_dirs.dirs[nsystem_dirs_len + 1]){ ++ *aelem = NULL; ++ aelem = &__rtld_search_dirs.dirs[0]; ++ } ++ + *aelem++ = pelem; + + pelem->what = "system search path"; +@@ -2022,9 +2031,22 @@ _dl_map_object (struct link_map *loader, const char *name, + + fd = -1; + ++ if (SYSTEM_DIRS_PRE_COUNT > 0 ++ && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL ++ || __glibc_likely (!(l->l_flags_1 & DF_1_NODEFLIB))) ++ && __rtld_search_dirs.dirs != (void *) -1) ++ { ++ struct r_search_path_struct pre_sp = { ++ .dirs = &__rtld_search_dirs.dirs[normal_system_dirs_len + 1], ++ .malloced = 0, ++ }; ++ fd = open_path (name, namelen, mode, &pre_sp, ++ &realname, &fb, l, LA_SER_DEFAULT, &found_other_class); ++ } ++ + /* When the object has the RUNPATH information we don't use any + RPATHs. */ +- if (loader == NULL || loader->l_info[DT_RUNPATH] == NULL) ++ if (fd == -1 && (loader == NULL || loader->l_info[DT_RUNPATH] == NULL)) + { + /* This is the executable's map (if there is one). Make sure that + we do not look at it twice. */ +-- +2.43.0 + diff --git a/debian/patches/glibc/0010-Add-___brk_addr-symbol.patch b/debian/patches/glibc/0010-Add-___brk_addr-symbol.patch new file mode 100644 index 000000000..aae3ee949 --- /dev/null +++ b/debian/patches/glibc/0010-Add-___brk_addr-symbol.patch @@ -0,0 +1,28 @@ +From e520fa5aa05742d27d6e45b3187f179475e43b5f Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Mon, 15 Jan 2024 04:16:47 +0800 +Subject: [PATCH 10/10] Add ___brk_addr symbol + +--- + sysdeps/unix/sysv/linux/loongarch/brk.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + create mode 100644 sysdeps/unix/sysv/linux/loongarch/brk.c + +diff --git a/sysdeps/unix/sysv/linux/loongarch/brk.c b/sysdeps/unix/sysv/linux/loongarch/brk.c +new file mode 100644 +index 00000000..82c285f4 +--- /dev/null ++++ b/sysdeps/unix/sysv/linux/loongarch/brk.c +@@ -0,0 +1,9 @@ ++#include ++ ++#if LIB_COMPAT(libc, GLIBC_2_27, GLIBC_2_36) ++#include ++#undef HAVE_INTERNAL_BRK_ADDR_SYMBOL ++#define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1 ++#endif ++ ++#include +-- +2.43.0 + diff --git a/debian/patches/glibc/local-ld-multiarch.diff b/debian/patches/glibc/local-ld-multiarch.diff new file mode 100644 index 000000000..0bf5db61e --- /dev/null +++ b/debian/patches/glibc/local-ld-multiarch.diff @@ -0,0 +1,51 @@ +2012-05-01 Aurelien Jarno + + * elf/Makefile(trusted-dirs.st): Fix DL_DST_LIB computation with + two level slibdir directories. + +2009-09-08 Aurelien Jarno + + * Makeconfig: add support for multiarch compat directories. + +--- + Makeconfig | 9 +++++++++ + elf/Makefile | 2 +- + 2 files changed, 10 insertions(+), 1 deletion(-) + +--- a/Makeconfig ++++ b/Makeconfig +@@ -136,6 +136,11 @@ + endif + inst_libdir = $(install_root)$(libdir) + ++# Compat places to look for libraries ++ifndef extra_libdir ++extra_libdir = /lib:$(exec_prefix)/lib ++endif ++ + # Where to install the shared library. + ifndef slibdir + slibdir = $(exec_prefix)/lib +@@ -589,6 +594,10 @@ + default-rpath = $(libdir) + endif + ++ifdef extra_libdir ++default-rpath += :$(extra_libdir) ++endif ++ + ifndef link-extra-libs + link-extra-libs = $(LDLIBS-$(@F)) + link-extra-libs-static = $(link-extra-libs) +--- a/elf/Makefile ++++ b/elf/Makefile +@@ -507,7 +507,7 @@ + $(make-target-directory) + echo "$(subst :, ,$(user-defined-trusted-dirs-pre) $(default-rpath) $(user-defined-trusted-dirs))" \ + | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T}; +- echo '#define DL_DST_LIB "$(notdir $(slibdir))"' >> ${@:st=T} ++ echo '#define DL_DST_LIB "$(shell echo $(slibdir) | sed 's,/,,')"' >> ${@:st=T} + echo '#define SYSTEM_DIRS_PRE_COUNT $(words $(subst :, ,$(user-defined-trusted-dirs-pre)))' >> ${@:st=T} + $(move-if-change) ${@:st=T} ${@:st=h} + touch $@ + CPPFLAGS-dl-load.c += -I$(objpfx). -I$(csu-objpfx). diff --git a/debian/patches/glibc/local-remove-manual.diff b/debian/patches/glibc/local-remove-manual.diff new file mode 100644 index 000000000..e9ac85d40 --- /dev/null +++ b/debian/patches/glibc/local-remove-manual.diff @@ -0,0 +1,218 @@ +The GNU Libc Reference manual has to be removed for licensing reasons. +But some files have a dependency on manual/errno.texi; the easiest +solution is to drop those dependencies and make sure that MAKEINFO=: +so that no target depends on manual/*.texi files. + +--- + manual/Makefile | 182 +++++++++++++++++++++++++++++++++++++++++++++ + stdio-common/Makefile | 2 + sysdeps/mach/hurd/Makefile | 2 + 3 files changed, 184 insertions(+), 2 deletions(-) + +--- /dev/null ++++ b/manual/Makefile +@@ -0,0 +1,182 @@ ++# Copyright (C) 1992-2012 ++# 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 ++# . ++ ++# Makefile for the GNU C Library manual. ++ ++subdir := manual ++ ++# Allow override ++INSTALL_INFO = install-info ++ ++.PHONY: dvi pdf info html ++ ++# Get glibc's configuration info. ++include ../Makeconfig ++ ++dvi: $(objpfx)libc.dvi ++pdf: $(objpfx)libc.pdf ++ ++TEXI2DVI = texi2dvi ++TEXI2PDF = texi2dvi --pdf ++ ++ifneq ($(strip $(MAKEINFO)),:) ++info: $(objpfx)libc.info ++endif ++ ++chapters = $(addsuffix .texi, \ ++ intro errno memory ctype string charset locale \ ++ message search pattern io stdio llio filesys \ ++ pipe socket terminal syslog math arith time \ ++ resource setjmp signal startup process job nss \ ++ users sysinfo conf crypt debug) ++add-chapters = $(wildcard $(foreach d, $(add-ons), ../$d/$d.texi)) ++appendices = lang.texi header.texi install.texi maint.texi platform.texi \ ++ contrib.texi ++licenses = freemanuals.texi lgpl-2.1.texi fdl-1.3.texi ++ ++-include $(objpfx)texis ++$(objpfx)texis: texis.awk $(chapters) $(add-chapters) $(appendices) $(licenses) ++ $(make-target-directory) ++ $(AWK) -f $^ > $@.T ++ mv -f $@.T $@ ++ ++nonexamples = $(filter-out $(add-chapters) %.c.texi, $(texis)) ++examples = $(filter-out $(foreach d, $(add-ons), ../$d/%.c.texi), \ ++ $(filter %.c.texi, $(texis))) ++ ++# Generated files directly included from libc.texinfo. ++libc-texi-generated = chapters.texi top-menu.texi dir-add.texi \ ++ libm-err.texi version.texi ++ ++# Add path to build dir for generated files ++texis-path := $(filter-out $(libc-texi-generated) summary.texi $(examples), \ ++ $(texis)) \ ++ $(addprefix $(objpfx),$(filter $(libc-texi-generated) summary.texi \ ++ $(examples), $(texis))) ++ ++# Kludge: implicit rule so Make knows the one command does it all. ++chapters.% top-menu.%: libc-texinfo.sh $(texis-path) Makefile ++ AWK=$(AWK) $(SHELL) $< $(objpfx) \ ++ '$(chapters)' \ ++ '$(add-chapters)' \ ++ '$(appendices) $(licenses)' ++ ++ ++$(objpfx)libc.dvi $(objpfx)libc.pdf $(objpfx)libc.info: \ ++ $(addprefix $(objpfx),$(libc-texi-generated)) ++$(objpfx)libc.dvi $(objpfx)libc.pdf: texinfo.tex ++ ++html: $(objpfx)libc/index.html ++$(objpfx)libc/index.html: $(addprefix $(objpfx),$(libc-texi-generated)) ++ $(MAKEINFO) -P $(objpfx) -o $(objpfx)libc --html libc.texinfo ++ ++# Generate the summary from the Texinfo source files for each chapter. ++$(objpfx)summary.texi: $(objpfx)stamp-summary ; ++$(objpfx)stamp-summary: summary.awk $(filter-out $(objpfx)summary.texi, \ ++ $(texis-path)) ++ $(AWK) -f $^ | sort -t' ' -df -k 1,1 | tr '\014' '\012' \ ++ > $(objpfx)summary-tmp ++ $(move-if-change) $(objpfx)summary-tmp $(objpfx)summary.texi ++ touch $@ ++ ++# Generate a file which can be added to the `dir' content to provide direct ++# access to the documentation of the function, variables, and other ++# definitions. ++$(objpfx)dir-add.texi: xtract-typefun.awk $(texis-path) ++ (echo "@dircategory GNU C library functions and macros"; \ ++ echo "@direntry"; \ ++ $(AWK) -f $^ | sort; \ ++ echo "@end direntry") > $@.new ++ mv -f $@.new $@ ++ ++# The table with the math errors is generated. ++$(objpfx)libm-err.texi: $(objpfx)stamp-libm-err ++$(objpfx)stamp-libm-err: libm-err-tab.pl $(wildcard $(foreach dir,$(sysdirs),\ ++ $(dir)/libm-test-ulps)) ++ pwd=`pwd`; \ ++ $(PERL) $< $$pwd/.. > $(objpfx)libm-err-tmp ++ $(move-if-change) $(objpfx)libm-err-tmp $(objpfx)libm-err.texi ++ touch $@ ++ ++# Generate a file with the version number. ++$(objpfx)version.texi: $(objpfx)stamp-version ; ++$(objpfx)stamp-version: $(common-objpfx)config.make ++ echo "@set VERSION $(version)" > $(objpfx)version-tmp ++ $(move-if-change) $(objpfx)version-tmp $(objpfx)version.texi ++ touch $@ ++ ++# Generate Texinfo files from the C source for the example programs. ++$(objpfx)%.c.texi: examples/%.c ++ sed -e '1,/^\*\/$$/d' \ ++ -e 's,[{}],@&,g' \ ++ -e 's,/\*\(@.*\)\*/,\1,g' \ ++ -e 's,/\* *,/* @r{,g' -e 's, *\*/,} */,' \ ++ -e 's/\(@[a-z][a-z]*\)@{\([^}]*\)@}/\1{\2}/g'\ ++ $< | expand > $@.new ++ mv -f $@.new $@ ++ ++$(objpfx)%.info: %.texinfo ++ LANGUAGE=C LC_ALL=C $(MAKEINFO) -P $(objpfx) --output=$@ $< ++ ++$(objpfx)%.dvi: %.texinfo ++ cd $(objpfx);$(TEXI2DVI) -I $(shell cd $(/dev/null 2>&1; then \ ++ test -f $(inst_infodir)/dir || $(INSTALL_DATA) dir $(inst_infodir);\ ++ $(INSTALL_INFO) --info-dir=$(inst_infodir) $(inst_infodir)/libc.info;\ ++ else : ; fi ++endif ++# Catchall implicit rule for other installation targets from the parent. ++install-%: ; ++ ++$(inst_infodir)/libc.info: $(objpfx)libc.info ++ $(make-target-directory) ++ for file in $<*; do \ ++ $(INSTALL_DATA) $$file $(@D)/; \ ++ done ++ ++TAGS: $(minimal-dist) ++ $(ETAGS) -o $@ $^ +--- a/stdio-common/Makefile ++++ b/stdio-common/Makefile +@@ -251,7 +251,7 @@ + # generated + endif # $(run-built-tests) + +-tests-special += $(objpfx)tst-errno-manual.out ++# tests-special += $(objpfx)tst-errno-manual.out + + include ../Rules + +--- a/sysdeps/mach/hurd/Makefile ++++ b/sysdeps/mach/hurd/Makefile +@@ -88,7 +88,7 @@ + -e 's, \.\./, $(..),g' > $@t + mv -f $@t $@ + +-$(hurd)/bits/errno.h: $(common-objpfx)stamp-errnos ; ++$(hurd)/bits/errno-disabled.h: $(common-objpfx)stamp-errnos ; + $(common-objpfx)stamp-errnos: $(hurd)/errnos.awk $(errno.texinfo) \ + $(mach-errnos-deps) $(common-objpfx)errnos.d + mkdir -p $(hurd-objpfx)bits diff --git a/debian/patches/glibc/series b/debian/patches/glibc/series new file mode 100644 index 000000000..362e7ded0 --- /dev/null +++ b/debian/patches/glibc/series @@ -0,0 +1,12 @@ +0001-add-old-world-abi-compatibility.patch +0002-add-sigset-ops.patch +0003-add-signal-functions.patch +0004-add-sigaction-ucontext-compat.patch +0005-add-stubs-for-signal-related-io-funcs.patch +0006-add-syscall-fallback-for-stat-at.patch +0007-add-more-pthread-symbols.patch +0008-remove-clone3-for-compatibility-with-qq.patch +0009-prepend-trusted-dirs.patch +0010-Add-___brk_addr-symbol.patch +local-remove-manual.diff +local-ld-multiarch.diff diff --git a/debian/patches/patchelf/0001-add-remap-symvers.patch b/debian/patches/patchelf/0001-add-remap-symvers.patch new file mode 100644 index 000000000..a2cc11311 --- /dev/null +++ b/debian/patches/patchelf/0001-add-remap-symvers.patch @@ -0,0 +1,483 @@ +From 191f6766cf0f320a785986f91a022a9c263c69cd Mon Sep 17 00:00:00 2001 +From: Miao Wang +Date: Fri, 12 Jan 2024 16:56:07 +0800 +Subject: [PATCH] add remap-symvers + +--- + src/elf.h | 2 + + src/patchelf.cc | 351 +++++++++++++++++++++++++++++++++++++++++++++++- + src/patchelf.h | 6 +- + 3 files changed, 354 insertions(+), 5 deletions(-) + +diff --git a/src/elf.h b/src/elf.h +index 920e689..669fd2d 100644 +--- a/src/elf.h ++++ b/src/elf.h +@@ -55,6 +55,8 @@ typedef uint16_t Elf64_Section; + typedef Elf32_Half Elf32_Versym; + typedef Elf64_Half Elf64_Versym; + ++#define VERSYM_HIDDEN 0x8000 ++#define VERSYM_VERSION 0x7fff + + /* The ELF file header. This appears at the start of every ELF file. */ + +diff --git a/src/patchelf.cc b/src/patchelf.cc +index 82b4b46..f0dbdb2 100644 +--- a/src/patchelf.cc ++++ b/src/patchelf.cc +@@ -1234,8 +1234,14 @@ void ElfFile::rewriteHeaders(Elf_Addr phdrAddress) + } + else if (d_tag == DT_VERNEED) + dyn->d_un.d_ptr = findSectionHeader(".gnu.version_r").sh_addr; ++ else if (d_tag == DT_VERNEEDNUM) ++ dyn->d_un.d_val = findSectionHeader(".gnu.version_r").sh_info; + else if (d_tag == DT_VERSYM) + dyn->d_un.d_ptr = findSectionHeader(".gnu.version").sh_addr; ++ else if (d_tag == DT_VERDEF) ++ dyn->d_un.d_ptr = findSectionHeader(".gnu.version_d").sh_addr; ++ else if (d_tag == DT_VERDEFNUM) ++ dyn->d_un.d_val = findSectionHeader(".gnu.version_d").sh_info; + else if (d_tag == DT_MIPS_RLD_MAP_REL) { + /* the MIPS_RLD_MAP_REL tag stores the offset to the debug + pointer, relative to the address of the tag */ +@@ -2016,7 +2022,7 @@ auto ElfFile::parseGnuHashTable(span sectionData) -> Gn + } + + template +-void ElfFile::rebuildGnuHashTable(span strTab, span dynsyms) ++void ElfFile::rebuildGnuHashTable(span strTab, span dynsyms, span versyms) + { + auto sectionData = tryGetSectionSpan(".gnu.hash"); + if (!sectionData) +@@ -2028,12 +2034,20 @@ void ElfFile::rebuildGnuHashTable(span strTab, span(newSection.data(), newSection.size()); ++ ght = parseGnuHashTable(sectionData); ++ } ++ + // The hash table includes only a subset of dynsyms + auto firstSymIdx = rdi(ght.m_hdr.symndx); + dynsyms = span(&dynsyms[firstSymIdx], dynsyms.end()); + + // Only use the range of symbol versions that will be changed +- auto versyms = tryGetSectionSpan(".gnu.version"); ++ if (!versyms) ++ versyms = tryGetSectionSpan(".gnu.version"); + if (versyms) + versyms = span(&versyms[firstSymIdx], versyms.end()); + +@@ -2148,7 +2162,7 @@ auto ElfFile::parseHashTable(span sectionData) -> HashT + } + + template +-void ElfFile::rebuildHashTable(span strTab, span dynsyms) ++void ElfFile::rebuildHashTable(span strTab, span dynsyms, int moreSyms) + { + auto sectionData = tryGetSectionSpan(".hash"); + if (!sectionData) +@@ -2156,6 +2170,15 @@ void ElfFile::rebuildHashTable(span strTab, span 0) ++ { ++ auto & newSection = replaceSection(".hash", sectionData.size() + moreSyms * sizeof(uint32_t)); ++ sectionData = span(newSection.data(), newSection.size()); ++ auto hdr = (typename HashTable::Header*)sectionData.begin(); ++ wri(hdr->nchain, rdi(hdr->nchain) + moreSyms); ++ ht = parseHashTable(sectionData); ++ } ++ + std::fill(ht.m_buckets.begin(), ht.m_buckets.end(), 0); + std::fill(ht.m_chain.begin(), ht.m_chain.end(), 0); + +@@ -2320,6 +2343,281 @@ void ElfFile::modifyExecstack(ExecstackMode op) + printf("execstack: %c\n", result); + } + ++template ++void ElfFile::remapSymvers(const std::string & mapTo, const std::vector & mapFrom, bool alsoPatchVerNeed) ++{ ++ auto shdrDynStr = findSectionHeader(".dynstr"); ++ auto shdrDynsym = findSectionHeader(".dynsym"); ++ auto shdrVersym = findSectionHeader(".gnu.version"); ++ ++ auto strTab = (char *)fileContents->data() + rdi(shdrDynStr.sh_offset); ++ auto strTabSize = rdi(shdrDynStr.sh_size); ++ auto dynsyms = (Elf_Sym *)(fileContents->data() + rdi(shdrDynsym.sh_offset)); ++ auto versyms = (Elf_Versym *)(fileContents->data() + rdi(shdrVersym.sh_offset)); ++ const size_t count = rdi(shdrDynsym.sh_size) / sizeof(Elf_Sym); ++ ++ if (count != rdi(shdrVersym.sh_size) / sizeof(Elf_Versym)) ++ error("versym size mismatch"); ++ ++ auto &shdrVerdef = findSectionHeader(".gnu.version_d"); ++ auto verdef = (char *)(fileContents->data() + rdi(shdrVerdef.sh_offset)); ++ ++ std::map verdefMap; ++ ++ debug("Parsing .gnu.version_d\n"); ++ ++ int verdef_entries = rdi(shdrVerdef.sh_info); ++ debug(".gnu.version_d: %d entries\n", verdef_entries); ++ ++ auto verdef_end = verdef + rdi(shdrVerdef.sh_size); ++ off_t curoff = 0; ++ ++ int map_to_ndx = -1; ++ int max_ndx = 0; ++ off_t last_verdef_off = 0; ++ off_t mapToStrOff = 0; ++ bool mapToAdded = false; ++ ++ for(int i = 0; i < verdef_entries; i++){ ++ Elf_Verdef *vd = (Elf_Verdef *) (verdef + curoff); ++ if ((char *)vd + sizeof(Elf_Verdef) > verdef_end) ++ error(fmt("verdef entry overflow: idx=", i)); ++ auto ndx = rdi(vd->vd_ndx); ++ if ((char *)vd + rdi(vd->vd_aux) >= verdef_end) ++ error(fmt("verdef entry aux out of bounds: idx=", i)); ++ auto aux = (Elf_Verdaux *) ((char *)vd + rdi(vd->vd_aux)); ++ if ((char *)aux + sizeof(Elf_Verdaux) > verdef_end) ++ error(fmt("verdef entry aux overflow: idx=", i)); ++ std::string_view name = &strTab[rdi(aux->vda_name)]; ++ debug("verdef entry %d: %s, ndx=%d\n", i, name.data(), ndx); ++ if (ndx > max_ndx) ++ max_ndx = ndx; ++ if (name == mapTo) { ++ map_to_ndx = ndx; ++ mapToStrOff = rdi(aux->vda_name); ++ } ++ if(ndx != 0 && ndx != 1){ ++ verdefMap[ndx] = name; ++ } ++ ++ if(rdi(vd->vd_next) == 0){ ++ if(i == verdef_entries - 1){ ++ last_verdef_off = curoff; ++ break; ++ } ++ else ++ error(fmt("verdef entry should have next entry: idx=", i)); ++ } ++ if((char *)vd + rdi(vd->vd_next) >= verdef_end) ++ error(fmt("verdef entry next out of bounds: idx=", i)); ++ curoff += rdi(vd->vd_next); ++ } ++ if (map_to_ndx == -1){ ++ debug("no version index for %s, adding\n", mapTo.c_str()); ++ auto & newDynStr = replaceSection(".dynstr", rdi(shdrDynStr.sh_size) + mapTo.size() + 1); ++ mapToStrOff = rdi(shdrDynStr.sh_size); ++ setSubstr(newDynStr, mapToStrOff, mapTo + '\0'); ++ strTab = newDynStr.data(); ++ strTabSize = newDynStr.size(); ++ } ++ debug("parsing verneed entries\n", mapTo.c_str()); ++ auto verneedhdr = tryFindSectionHeader(".gnu.version_r"); ++ std::map verneedMap; ++ if(verneedhdr){ ++ auto &shdrVerNeed = verneedhdr->get(); ++ auto verneed = (char *)(fileContents->data() + rdi(shdrVerNeed.sh_offset)); ++ ++ debug("found .gnu.version_r, parsing\n"); ++ int verneed_entries = rdi(shdrVerNeed.sh_info); ++ debug(".gnu.version_r: %d entries\n", verdef_entries); ++ ++ auto verneed_end = verneed + rdi(shdrVerNeed.sh_size); ++ off_t curoff = 0; ++ for(int i = 0; i < verneed_entries; i++){ ++ Elf_Verneed *vn = (Elf_Verneed *) (verneed + curoff); ++ if ((char *)vn + sizeof(Elf_Verneed) > verneed_end) ++ error(fmt("verneed entry overflow: idx=", i)); ++ auto aux_cnt = rdi(vn->vn_cnt); ++ debug("file: %s, %d versions\n", &strTab[rdi(vn->vn_file)], aux_cnt); ++ off_t aux_off = rdi(vn->vn_aux); ++ if ((char *)vn + aux_off >= verneed_end) ++ error(fmt("verneed entry aux out of bounds: idx=", i)); ++ for(int j = 0; j < aux_cnt; j++){ ++ auto aux = (Elf_Vernaux *) ((char *)vn + aux_off); ++ if ((char *)aux + sizeof(Elf_Vernaux) > verneed_end) ++ error(fmt("verneed entry aux overflow: idx=", i, "aux idx=", j)); ++ auto ndx = rdi(aux->vna_other) & VERSYM_VERSION; ++ debug(" %s, ndx=%d\n", &strTab[rdi(aux->vna_name)], ndx); ++ if(alsoPatchVerNeed){ ++ for (auto it : mapFrom){ ++ if (it == &strTab[rdi(aux->vna_name)]){ ++ debug(" found %s, changing to %s\n", it.c_str(), mapTo.c_str()); ++ wri(aux->vna_name, mapToStrOff); ++ wri(aux->vna_hash, sysvHash(mapTo)); ++ break; ++ } ++ } ++ } ++ if(map_to_ndx == -1 && ndx >= max_ndx + 1){ ++ verneedMap[ndx] = ndx + 1; ++ ndx = ndx + 1; ++ wri(aux->vna_other, (rdi(aux->vna_other) & ~VERSYM_VERSION) | (ndx & VERSYM_VERSION)); ++ debug(" changing ndx to %d\n", ndx); ++ } ++ if (rdi(aux->vna_next) == 0){ ++ if (j == aux_cnt - 1) ++ break; ++ else ++ error(fmt("verneed entry should have next entry: idx=", i, "aux idx=", j)); ++ } ++ if ((char *)aux + rdi(aux->vna_next) >= verneed_end) ++ error(fmt("verneed entry next out of bounds: idx=", i, "aux idx=", j)); ++ aux_off += rdi(aux->vna_next); ++ } ++ if (rdi(vn->vn_next) == 0){ ++ if (i == verneed_entries - 1) ++ break; ++ else ++ error(fmt("verneed entry should have next entry: idx=", i)); ++ } ++ if ((char *)vn + rdi(vn->vn_next) >= verneed_end) ++ error(fmt("verneed entry next out of bounds: idx=", i)); ++ curoff += rdi(vn->vn_next); ++ } ++ }else{ ++ debug("no .gnu.version_r found\n"); ++ } ++ if (map_to_ndx == -1){ ++ map_to_ndx = max_ndx + 1; ++ debug("decided to use %d for %s\n", map_to_ndx, mapTo.c_str()); ++ if(map_to_ndx > VERSYM_VERSION){ ++ error(fmt("version index %d is too large", map_to_ndx)); ++ } ++ verdefMap[map_to_ndx] = mapTo; ++ auto & newVerdef = replaceSection(".gnu.version_d", rdi(shdrVerdef.sh_size) + sizeof(Elf_Verdef) + sizeof(Elf_Verdaux)); ++ char * newVerdefData = newVerdef.data(); ++ Elf_Verdef *lastVd = (Elf_Verdef *)(newVerdefData + last_verdef_off); ++ Elf_Verdef *newVd = (Elf_Verdef *)(newVerdefData + rdi(shdrVerdef.sh_size)); ++ wri(lastVd->vd_next, (char *)newVd - (char *)lastVd); ++ wri(newVd->vd_version, 1); ++ wri(newVd->vd_flags, 0); ++ wri(newVd->vd_ndx, map_to_ndx); ++ wri(newVd->vd_cnt, 1); ++ wri(newVd->vd_hash, sysvHash(mapTo)); ++ wri(newVd->vd_aux, sizeof(Elf_Verdef)); ++ wri(newVd->vd_next, 0); ++ Elf_Verdaux *newVda = (Elf_Verdaux *)((char *)newVd + sizeof(Elf_Verdef)); ++ wri(newVda->vda_next, 0); ++ wri(((Elf_Shdr *)(&shdrVerdef))->sh_info, rdi(shdrVerdef.sh_info) + 1); ++ verdef_entries += 1; ++ ++ wri(newVda->vda_name, mapToStrOff); ++ mapToAdded = true; ++ }else{ ++ debug("verdef entry for %s found at ndx=%d\n", mapTo.c_str(), map_to_ndx); ++ } ++ std::map> symVersionMap; ++ ++ debug("Parsing .dynsym\n"); ++ for(size_t i = 0; i < count; i++){ ++ auto dynsym = &dynsyms[i]; ++ std::string name = strTab + rdi(dynsym->st_name); ++ auto verndx = rdi(versyms[i]); ++ auto verdef_ndx = verndx & VERSYM_VERSION; ++ ++ if(verneedMap.find(verdef_ndx) != verneedMap.end()){ ++ debug("verneed entry remapping for %s found at ndx=%d\n", name.c_str(), verdef_ndx); ++ verdef_ndx = verneedMap[verdef_ndx]; ++ wri(versyms[i], (verndx & ~VERSYM_VERSION) | (verdef_ndx & VERSYM_VERSION)); ++ } ++ ++ if(name.empty()) ++ continue; ++ debug("dynsym entry %d: %s ", i, name.c_str()); ++ auto shndx = rdi(dynsym->st_shndx); ++ if(shndx == SHN_UNDEF){ ++ debug("(undefined)\n"); ++ continue; ++ }else if(shndx == SHN_ABS){ ++ debug("(absolute)\n"); ++ continue; ++ }else if(shndx == SHN_COMMON){ ++ debug("(common)\n"); ++ continue; ++ } ++ if(verndx == 0){ ++ debug("(local)\n"); ++ continue; ++ }else if(verndx == 1){ ++ debug("(global)\n"); ++ continue; ++ } ++ if(verdefMap.find(verdef_ndx) == verdefMap.end()){ ++ debug("(verdef %d not found)\n", verdef_ndx); ++ continue; ++ } ++ debug("(ver: %s)\n", verdefMap[verdef_ndx].c_str()); ++ symVersionMap[verdefMap[verdef_ndx]][name] = i; ++ } ++ ++ debug("Generating new dsyms list\n"); ++ std::map newDsyms; ++ for(const auto &fromVer : mapFrom){ ++ if(symVersionMap.find(fromVer) == symVersionMap.end()){ ++ debug("No symbols with version %s found\n", fromVer.c_str()); ++ continue; ++ } ++ for(auto sym : symVersionMap[fromVer]){ ++ debug("Adding %s@%s to new dsyms list\n", sym.first.c_str(), fromVer.c_str()); ++ newDsyms[sym.first] = sym.second; ++ } ++ } ++ for(const auto &syms : symVersionMap[mapTo]){ ++ debug("removing %s@%s from new dsyms list\n", syms.first.c_str(), mapTo.c_str()); ++ newDsyms.erase(syms.first); ++ } ++ auto newDynsymSize = (newDsyms.size() + (mapToAdded ? 1 : 0)) * sizeof(Elf_Sym) + rdi(shdrDynsym.sh_size); ++ auto newVersymSize = (newDsyms.size() + (mapToAdded ? 1 : 0)) * sizeof(Elf_Versym) + rdi(shdrVersym.sh_size); ++ ++ auto& newDynsym = replaceSection(".dynsym", newDynsymSize); ++ auto& newVersym = replaceSection(".gnu.version", newVersymSize); ++ ++ auto newDynsymSpan = span((Elf_Sym *)newDynsym.data(), newDynsymSize / sizeof(Elf_Sym)); ++ auto newVersymSpan = span((Elf_Versym *)newVersym.data(), newVersymSize / sizeof(Elf_Versym)); ++ ++ { ++ int i = count; ++ for(auto it = newDsyms.cbegin(); it != newDsyms.cend(); ++it){ ++ auto sym = it->second; ++ debug("Adding %s@%s to dynsym list\n", it->first.c_str(), mapTo.c_str()); ++ newDynsymSpan[i] = dynsyms[sym]; ++ bool is_hidden = rdi(newVersymSpan[sym]) & VERSYM_HIDDEN; ++ wri(newVersymSpan[i], map_to_ndx | (is_hidden ? VERSYM_HIDDEN : 0)); ++ wri(newVersymSpan[sym], rdi(newVersymSpan[sym]) | VERSYM_HIDDEN); ++ i += 1; ++ } ++ if(mapToAdded){ ++ debug("Adding %s@%s to dynsym list\n", mapTo.c_str(), mapTo.c_str()); ++ wri(newDynsymSpan[i].st_name, mapToStrOff); ++ wri(newDynsymSpan[i].st_info, STB_GLOBAL << 4 | STT_OBJECT); ++ wri(newDynsymSpan[i].st_other, STV_DEFAULT); ++ wri(newDynsymSpan[i].st_shndx, SHN_ABS); ++ wri(newDynsymSpan[i].st_value, 0); ++ wri(newDynsymSpan[i].st_size, 0); ++ wri(newVersymSpan[i], map_to_ndx); ++ } ++ } ++ ++ debug("Rebuilding hash tables\n"); ++ ++ rebuildGnuHashTable(span(strTab, strTabSize), newDynsymSpan, newVersymSpan); ++ rebuildHashTable(span(strTab, strTabSize), newDynsymSpan, newDsyms.size() + (mapToAdded ? 1 : 0)); ++ ++ this->rewriteSections(); ++ ++ changed = true; ++} ++ + template + template + void ElfFile::forAllStringReferences(const Elf_Shdr& strTabHdr, StrIdxCallback&& fn) +@@ -2384,6 +2682,10 @@ static bool noDefaultLib = false; + static bool printExecstack = false; + static bool clearExecstack = false; + static bool setExecstack = false; ++static bool remapSymvers = false; ++static bool remapVerneed = false; ++static std::string symverMapTo; ++static std::vector symverMapFrom; + + template + static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, const std::string & fileName) +@@ -2441,6 +2743,9 @@ static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, con + if (renameDynamicSymbols) + elfFile.renameDynamicSymbols(symbolsToRename); + ++ if (remapSymvers) ++ elfFile.remapSymvers(symverMapTo, symverMapFrom, remapVerneed); ++ + if (elfFile.isChanged()){ + writeFile(fileName, elfFile.fileContents); + } else if (alwaysWrite) { +@@ -2505,6 +2810,8 @@ static void showHelp(const std::string & progName) + [--clear-execstack]\n\ + [--set-execstack]\n\ + [--rename-dynamic-symbols NAME_MAP_FILE]\tRenames dynamic symbols. The map file should contain two symbols (old_name new_name) per line\n\ ++ [--remap-symvers TO=FROM1,FROM2...]\n\ ++ [--also-remap-verneed]\n\ + [--output FILE]\n\ + [--debug]\n\ + [--version]\n\ +@@ -2661,6 +2968,44 @@ static int mainWrapped(int argc, char * * argv) + symbolsToRename[*symbolsToRenameKeys.insert(from).first] = to; + } + } ++ else if (arg == "--remap-symvers") { ++ remapSymvers = true; ++ if (++i == argc) error("missing argument"); ++ ++ const char* mapping = argv[i]; ++ for(int i = 0; mapping[i]; ++i) ++ { ++ if (mapping[i] == '=') ++ { ++ char *mapto = strndup(mapping, i); ++ symverMapTo = mapto; ++ free(mapto); ++ mapping += i + 1; ++ break; ++ } ++ } ++ if (symverMapTo.empty()) ++ error(fmt("Invalid symver mapping, must contains =: ", mapping)); ++ for(int i = 0; mapping[i]; ++i) ++ { ++ if (mapping[i] == ',') ++ { ++ char *mapfrom = strndup(mapping, i); ++ if(strlen(mapfrom) != 0) ++ symverMapFrom.push_back(mapfrom); ++ free(mapfrom); ++ mapping += i + 1; ++ i = -1; ++ } ++ } ++ if (strlen(mapping) != 0) ++ symverMapFrom.push_back(mapping); ++ if (symverMapFrom.empty()) ++ error(fmt("Invalid symver mapping, must contains at least one from: ", mapping)); ++ } ++ else if (arg == "--also-remap-verneed") { ++ remapVerneed = true; ++ } + else if (arg == "--help" || arg == "-h" ) { + showHelp(argv[0]); + return 0; +diff --git a/src/patchelf.h b/src/patchelf.h +index 4e229d6..3d2eb23 100644 +--- a/src/patchelf.h ++++ b/src/patchelf.h +@@ -175,6 +175,8 @@ public: + + void modifyExecstack(ExecstackMode op); + ++ void remapSymvers(const std::string & mapTo, const std::vector & mapFrom, bool alsoRemapVerneed); ++ + private: + struct GnuHashTable { + using BloomWord = Elf_Addr; +@@ -194,8 +196,8 @@ private: + }; + HashTable parseHashTable(span gh); + +- void rebuildGnuHashTable(span strTab, span dynsyms); +- void rebuildHashTable(span strTab, span dynsyms); ++ void rebuildGnuHashTable(span strTab, span dynsyms, span versyms = {nullptr, nullptr}); ++ void rebuildHashTable(span strTab, span dynsyms, int moreSyms = 0); + + using Elf_Rel_Info = decltype(Elf_Rel::r_info); + +-- +2.43.0 + diff --git a/debian/patches/patchelf/series b/debian/patches/patchelf/series new file mode 100644 index 000000000..a8f0673a7 --- /dev/null +++ b/debian/patches/patchelf/series @@ -0,0 +1 @@ +0001-add-remap-symvers.patch diff --git a/debian/rules b/debian/rules index 2d33f6ac8..deaa8b0a1 100755 --- a/debian/rules +++ b/debian/rules @@ -1,4 +1,252 @@ -#!/usr/bin/make -f +#! /usr/bin/make -f + + +include /usr/share/dpkg/pkg-info.mk + +glibc-ver := 2.38 +patchelf-ver := 0.18.0 + +SUBSTVARS += -VglibcVer="$(glibc-ver)" + +glibc-orig = ../liblol_$(DEB_VERSION_UPSTREAM).orig-glibc.tar.xz +patchelf-orig = ../liblol_$(DEB_VERSION_UPSTREAM).orig-patchelf.tar.gz + +DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) +DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) +DEB_HOST_MULTIARCH := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) +lol_target_gnu_type := loongarch64-debian-linux-gnuow + +build_cflags := -pipe $(shell dpkg-buildflags --get CFLAGS_FOR_BUILD) $(shell dpkg-buildflags --get CPPFLAGS_FOR_BUILD) +build_cxxflags := -pipe $(shell dpkg-buildflags --get CXXFLAGS_FOR_BUILD) $(shell dpkg-buildflags --get CPPFLAGS_FOR_BUILD) +build_ldflags := $(shell dpkg-buildflags --get LDFLAGS_FOR_BUILD) +host_cflags := -pipe $(shell dpkg-buildflags --get CFLAGS) $(shell dpkg-buildflags --get CPPFLAGS) +host_ldflags := $(shell dpkg-buildflags --get LDFLAGS) + +ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) +NJOBS := -j $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) +endif + +BASE_CC = gcc +DEB_GCC_VERSION = -13 + +CC = $(DEB_HOST_GNU_TYPE)-$(BASE_CC)$(DEB_GCC_VERSION) +BUILD_CC = $(DEB_BUILD_GNU_TYPE)-$(BASE_CC) + +prefix=/usr +bindir=$(prefix)/bin +datadir=$(prefix)/share +complocaledir=$(prefix)/lib/locale +sysconfdir=/etc +libexecdir=$(prefix)/lib +rootsbindir=/sbin +includedir=$(prefix)/include +docdir=$(prefix)/share/doc +mandir=$(prefix)/share/man +sbindir=$(prefix)/sbin +vardbdir=/var/lib/misc +rtlddir=/lib64 +slibdir=/lib/$(DEB_HOST_MULTIARCH) +libdir=/usr/lib/$(DEB_HOST_MULTIARCH) + +get-orig-source: $(glibc-orig) $(patchelf-orig) + : + +$(glibc-orig): + curl -sSfL -o $@ https://ftp.debian.org/debian/pool/main/g/glibc/glibc_$(glibc-ver).orig.tar.xz +$(patchelf-orig): + curl -sSfL -o $@ https://ftp.debian.org/debian/pool/main/p/patchelf/patchelf_$(patchelf-ver).orig.tar.gz %: - dh $@ + dh $@ --without autoreconf + +override_dh_auto_configure: patch-src config-glibc config-patchelf +override_dh_auto_build: build-glibc build-patchelf +override_dh_auto_install: install-glibc symlink-hostlibs + +patchelf_build_dir := debian/build-dir/patchelf + +config-patchelf: patch-src.patchelf + dh_autoreconf -Dpatchelf + mkdir -p $(patchelf_build_dir) + cd $(patchelf_build_dir) && \ + $(CURDIR)/patchelf/configure \ + --build=$(DEB_BUILD_GNU_TYPE) \ + --host=$(DEB_BUILD_GNU_TYPE) \ + CFLAGS='$(build_cflags)' \ + CXXFLAGS='$(build_cxxflags)' \ + LDFLAGS='$(build_ldflags)' + +glibc_build_dir := debian/build-dir/glibc +config-glibc: patch-src.glibc + mkdir -p $(glibc_build_dir) + rm -rf $(glibc_build_dir)/configparms + echo "BUILD_CC = $(BUILD_CC)" >> $(glibc_build_dir)/configparms + echo "CFLAGS = $(host_cflags)" >> $(glibc_build_dir)/configparms + echo "ASFLAGS = $(host_cflags)" >> $(glibc_build_dir)/configparms + echo "BUILD_CFLAGS = $(build_cflags)" >> $(glibc_build_dir)/configparms + echo "LDFLAGS = " >> $(glibc_build_dir)/configparms + echo "BASH := /bin/bash" >> $(glibc_build_dir)/configparms + echo "KSH := /bin/bash" >> $(glibc_build_dir)/configparms + echo "SHELL := /bin/bash" >> $(glibc_build_dir)/configparms + echo "LIBGD = no" >> $(glibc_build_dir)/configparms + echo "bindir = $(bindir)" >> $(glibc_build_dir)/configparms + echo "datadir = $(datadir)" >> $(glibc_build_dir)/configparms + echo "complocaledir = $(complocaledir)" >> $(glibc_build_dir)/configparms + echo "sysconfdir = $(sysconfdir)/liblol" >> $(glibc_build_dir)/configparms + echo "localtime-file = $(sysconfdir)/localtime" >> $(glibc_build_dir)/configparms + echo "libexecdir = $(libexecdir)" >> $(glibc_build_dir)/configparms + echo "rootsbindir = $(rootsbindir)" >> $(glibc_build_dir)/configparms + echo "includedir = $(includedir)" >> $(glibc_build_dir)/configparms + echo "docdir = $(docdir)" >> $(glibc_build_dir)/configparms + echo "mandir = $(mandir)" >> $(glibc_build_dir)/configparms + echo "sbindir = $(sbindir)" >> $(glibc_build_dir)/configparms + echo "vardbdir = $(vardbdir)" >> $(glibc_build_dir)/configparms + echo "libdir = $(libdir)" >> $(glibc_build_dir)/configparms + echo "slibdir = $(slibdir)" >> $(glibc_build_dir)/configparms + echo "rtlddir = $(rtlddir)" >> $(glibc_build_dir)/configparms + echo "user-defined-trusted-dirs-pre = /usr/local/lib/$(lol_target_gnu_type)/preload:/usr/lib/$(lol_target_gnu_type)/preload" >> $(glibc_build_dir)/configparms + echo "user-defined-trusted-dirs = /usr/local/lib/$(lol_target_gnu_type):/usr/lib/$(lol_target_gnu_type)" >> $(glibc_build_dir)/configparms + cd $(glibc_build_dir) && \ + CC=$(CC) \ + AUTOCONF=false \ + MAKEINFO=: \ + $(CURDIR)/glibc/configure \ + --host=$(lol_target_gnu_type) \ + --build=$(DEB_BUILD_GNU_TYPE) \ + --prefix=/usr \ + --without-selinux \ + --enable-crypt \ + --enable-bind-now \ + --enable-fortify-source \ + --enable-stackguard-randomization \ + --enable-stack-protector=strong \ + --with-pkgversion="LibLoL $(DEB_VERSION)" \ + --with-bugurl="https://github.com/AOSC-Dev/liblol/issues" \ + --disable-nscd \ + --disable-werror \ + --enable-multi-arch \ + --enable-obsolete-rpc + +glibc_libs = libc.so.6 \ + nptl/libpthread.so.0 \ + elf/ld.so.1 \ + math/libm.so.6 \ + resolv/libresolv.so.2 \ + malloc/libc_malloc_debug.so.0 \ + nptl_db/libthread_db.so.1 \ + dlfcn/libdl.so.2 \ + locale/libBrokenLocale.so.1 \ + rt/librt.so.1 \ + crypt/libcrypt.so.1 \ + resolv/libanl.so.1 \ + login/libutil.so.1 \ + nis/libnsl.so.1 + +glibc_libs_targets = $(addprefix build-glibc-,$(subst /,-,$(glibc_libs))) +glibc_libs_targets_after = $(addprefix build-glibc-,$(filter-out libc.so.6,$(subst /,-,$(glibc_libs)))) + +glibc_libs_install_targets = $(addprefix install-glibc-,$(subst /,-,$(glibc_libs))) + +patchelf_bin := $(patchelf_build_dir)/src/patchelf + +$(patchelf_bin): build-patchelf + : + +build-glibc: $(glibc_libs_targets) + : + +$(glibc_libs_targets_after): build-glibc-libc.so.6 + +build-glibc-libc.so.6: + $(MAKE) -C $(glibc_build_dir) "$(CURDIR)/$(glibc_build_dir)/libc.so.6" $(NJOBS) + +glibc_cur_lib = $(subst -,/,$(*)) +glibc_cur_lib_dir = $(subst /,,$(dir $(glibc_cur_lib))) +glibc_cur_lib_name = $(notdir $(glibc_cur_lib)) +build-glibc-%: + $(MAKE) -C $(CURDIR)/glibc/$(glibc_cur_lib_dir) \ + "$(CURDIR)/$(glibc_build_dir)/$(glibc_cur_lib)" \ + subdir=$(glibc_cur_lib_dir) \ + ..=../ \ + objdir="$(CURDIR)/$(glibc_build_dir)" \ + $(NJOBS) + +TMPDIR ?= debian/tmp +install_libs_dir := $(TMPDIR)/usr/lib/$(lol_target_gnu_type) +install_preload_libs_dir := $(install_libs_dir)/preload +$(install_preload_libs_dir) $(install_libs_dir): + mkdir -p $@ +install-glibc-%: $(patchelf_bin) $(install_preload_libs_dir) + if [ "$(glibc_cur_lib)" = "nptl/libpthread.so.0" ] || [ "$(glibc_cur_lib)" = "libc.so.6" ]; then \ + $(patchelf_bin) \ + --page-size "$$(( 16 * 1024 ))" \ + --remap-symvers "GLIBC_2.27=GLIBC_2.0,GLIBC_2.2,GLIBC_2.2.1,GLIBC_2.2.2,GLIBC_2.2.3,GLIBC_2.2.4,GLIBC_2.2.6,GLIBC_2.3,GLIBC_2.3.2,GLIBC_2.3.3,GLIBC_2.3.4,GLIBC_2.4,GLIBC_2.5,GLIBC_2.6,GLIBC_2.7,GLIBC_2.8,GLIBC_2.9,GLIBC_2.10,GLIBC_2.11,GLIBC_2.12,GLIBC_2.13,GLIBC_2.14,GLIBC_2.15,GLIBC_2.16,GLIBC_2.17,GLIBC_2.18,GLIBC_2.19,GLIBC_2.20,GLIBC_2.21,GLIBC_2.22,GLIBC_2.23,GLIBC_2.24,GLIBC_2.25,GLIBC_2.26,GLIBC_2.27,GLIBC_2.28" \ + --also-remap-verneed \ + $(glibc_build_dir)/$(glibc_cur_lib) \ + --output $(install_preload_libs_dir)/$(glibc_cur_lib_name); \ + else \ + install -Dvm644 $(glibc_build_dir)/$(glibc_cur_lib) \ + -t $(install_preload_libs_dir)/; \ + fi + $(patchelf_bin) \ + --page-size "$$(( 16 * 1024 ))" \ + --remap-symvers "GLIBC_2.36=GLIBC_2.27,GLIBC_2.28" \ + --also-remap-verneed \ + $(install_preload_libs_dir)/$(glibc_cur_lib_name) + +install-glibc-dummy-ldso: + $(CC) -shared \ + $(host_cflags) \ + $(host_ldflags) \ + -x c /dev/null \ + -o $(install_preload_libs_dir)/ld-linux-loongarch-lp64d.so.1 \ + -Wl,--version-script -Wl,$(glibc_build_dir)/ld.map \ + -nostdlib + +install-glibc: $(glibc_libs_install_targets) $(install_preload_libs_dir) install-glibc-dummy-ldso + chmod 0644 $(install_preload_libs_dir)/* + chmod +x $(install_preload_libs_dir)/ld.so.1 + chmod +x $(install_preload_libs_dir)/libc.so.6 + mkdir -pv $(TMPDIR)/lib64 + ln -sfvr $(install_preload_libs_dir)/ld.so.1 $(TMPDIR)/lib64/ld.so.1 + +symlink-hostlibs: $(install_libs_dir) $(install_preload_libs_dir) + ln -sfv $(libdir)/libstdc++.so.6 $(install_preload_libs_dir)/ + +build-patchelf: + $(MAKE) -C $(patchelf_build_dir) all $(NJOBS) + +patch-src: patch-src.patchelf patch-src.glibc + +patch-src.%: + cd $* && QUILT_PATCHES=../debian/patches/$* quilt push -a + +override_dh_clean: clean-patch clean-patchelf + dh_clean + rm -rf debian/build-dir + +override_dh_shlibdeps: + dh_shlibdeps -l /usr/lib/$(lol_target_gnu_type)/preload + +override_dh_gencontrol: + dh_gencontrol -- $(SUBSTVARS) + +override_dh_fixperms: + dh_fixperms -Xld.so.1 -Xlibc.so.6 + +clean-patchelf: + dh_autoreconf_clean + +clean-patch: clean-patch.patchelf clean-patch.glibc + +clean-patch.%: + if [ -s $*/.pc/applied-patches ]; then \ + cd $* && QUILT_PATCHES=../debian/patches/$* quilt pop -q -a; \ + rm -rf .pc; \ + fi + +# dwz cannot handle our patched libs +override_dh_dwz: + : + +.PHONY: get-orig-source patch-src clean-patch config-glibc config-patchelf