diff -Nru glibc-2.35/debian/changelog glibc-2.35/debian/changelog --- glibc-2.35/debian/changelog 2022-07-06 23:23:23.000000000 +0000 +++ glibc-2.35/debian/changelog 2023-07-26 08:27:54.000000000 +0000 @@ -1,3 +1,23 @@ +glibc (2.35-0ubuntu3.3) jammy; urgency=medium + + * Drop SVE patches due to kernal-related performance regression + * Fix the armhf stripping exception for ld.so (LP: #1927192) + + -- Simon Chopin Wed, 26 Jul 2023 10:27:54 +0200 + +glibc (2.35-0ubuntu3.2) jammy; urgency=medium + + * d/rules.d/debhelper.mk: fix permissions of libc.so (LP: #1989082) + * Cherry-picks from upstream: + - d/p/lp1999551/*: arm64 memcpy optimization (LP: #1999551) + - d/p/lp1995362*.patch: Fix ldd segfault with missing libs (LP: #1995362) + - d/p/lp2007796*: Fix missing cancellation point in pthread (LP: #2007796) + - d/p/lp2007599*: add new tunables for s390x (LP: #2007599) + - d/p/lp2011421/*: Fix crash on TDX-enabled platforms (LP: #2011421) + - d/p/lp1992159*: Fix socket.h headers for non-GNU compilers (LP: #1992159) + + -- Simon Chopin Wed, 31 May 2023 17:17:00 +0200 + glibc (2.35-0ubuntu3.1) jammy; urgency=medium * debian/maint: add a script to manage backports of patches from upstream diff -Nru glibc-2.35/debian/patches/lp1992159-socket-Fix-mistyped-define-statement-in-socket-sys-s.patch glibc-2.35/debian/patches/lp1992159-socket-Fix-mistyped-define-statement-in-socket-sys-s.patch --- glibc-2.35/debian/patches/lp1992159-socket-Fix-mistyped-define-statement-in-socket-sys-s.patch 1970-01-01 00:00:00.000000000 +0000 +++ glibc-2.35/debian/patches/lp1992159-socket-Fix-mistyped-define-statement-in-socket-sys-s.patch 2023-07-26 08:23:48.000000000 +0000 @@ -0,0 +1,30 @@ +From fe9ca732ace94cb49e4d4846a4492db40cde34e4 Mon Sep 17 00:00:00 2001 +From: Dmitriy Fedchenko +Date: Mon, 6 Jun 2022 12:46:14 -0300 +Subject: [PATCH] socket: Fix mistyped define statement in socket/sys/socket.h + (BZ #29225) + +(cherry picked from commit 999835533bc60fbd0b0b65d2412a6742e5a54b9d) + +Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/jammy/+source/glibc/+bug/1992159 +Origin: upstream, https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=999835533bc60fbd0b0b65d2412a6742e5a54b9d +--- + socket/sys/socket.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/socket/sys/socket.h b/socket/sys/socket.h +index 7d5b21a2c4..0abfb5dd03 100644 +--- a/socket/sys/socket.h ++++ b/socket/sys/socket.h +@@ -181,7 +181,7 @@ extern ssize_t __REDIRECT (sendmsg, (int __fd, const struct msghdr *__message, + # else + extern ssize_t __sendmsg64 (int __fd, const struct msghdr *__message, + int __flags); +-# defien sendmsg __sendmsg64 ++# define sendmsg __sendmsg64 + # endif + #endif + +-- +2.39.2 + diff -Nru glibc-2.35/debian/patches/lp1995362-elf-Fix-DFS-sorting-algorithm-for-LD_TRACE_LOADED_OB.patch glibc-2.35/debian/patches/lp1995362-elf-Fix-DFS-sorting-algorithm-for-LD_TRACE_LOADED_OB.patch --- glibc-2.35/debian/patches/lp1995362-elf-Fix-DFS-sorting-algorithm-for-LD_TRACE_LOADED_OB.patch 1970-01-01 00:00:00.000000000 +0000 +++ glibc-2.35/debian/patches/lp1995362-elf-Fix-DFS-sorting-algorithm-for-LD_TRACE_LOADED_OB.patch 2023-07-26 08:23:48.000000000 +0000 @@ -0,0 +1,384 @@ +From 10fe3cd309b32c003a6b98e08928e7d6007caecf Mon Sep 17 00:00:00 2001 +From: Adhemerval Zanella +Date: Tue, 8 Feb 2022 15:22:49 -0300 +Subject: [PATCH] elf: Fix DFS sorting algorithm for LD_TRACE_LOADED_OBJECTS + with missing libraries (BZ #28868) + +On _dl_map_object the underlying file is not opened in trace mode +(in other cases where the underlying file can't be opened, +_dl_map_object quits with an error). If there any missing libraries +being processed, they will not be considered on final nlist size +passed on _dl_sort_maps later in the function. And it is then used by +_dl_sort_maps_dfs on the stack allocated working maps: + +222 /* Array to hold RPO sorting results, before we copy back to maps[]. */ +223 struct link_map *rpo[nmaps]; +224 +225 /* The 'head' position during each DFS iteration. Note that we start at +226 one past the last element due to first-decrement-then-store (see the +227 bottom of above dfs_traversal() routine). */ +228 struct link_map **rpo_head = &rpo[nmaps]; + +However while transversing the 'l_initfini' on dfs_traversal it will +still consider the l_faked maps and thus update rpo more times than the +allocated working 'rpo', overflowing the stack object. + +As suggested in bugzilla, one option would be to avoid sorting the maps +for trace mode. However I think ignoring l_faked object does make +sense (there is one less constraint to call the sorting function), it +allows a slight less stack usage for trace, and it is slight simpler +solution. + +The tests does trigger the stack overflow, however I tried to make +it more generic to check different scenarios or missing objects. + +Checked on x86_64-linux-gnu. + +Reviewed-by: Siddhesh Poyarekar +(cherry picked from commit 3a0588ae48fb35384a6bd33f9b66403badfa1262) + +Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/jammy/+source/glibc/+bug/1995362 +Origin: upstream, https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=10fe3cd309b32c003a6b98e08928e7d6007caecf + +--- + elf/Makefile | 54 ++++++++++++++++++++ + elf/dl-deps.c | 2 + + elf/dl-sort-maps.c | 4 +- + elf/libtracemod1-1.c | 1 + + elf/libtracemod2-1.c | 1 + + elf/libtracemod3-1.c | 1 + + elf/libtracemod4-1.c | 1 + + elf/libtracemod5-1.c | 1 + + elf/tst-trace1.exp | 4 ++ + elf/tst-trace2.exp | 6 +++ + elf/tst-trace3.exp | 6 +++ + elf/tst-trace4.exp | 6 +++ + elf/tst-trace5.exp | 6 +++ + scripts/tst-ld-trace.py | 108 ++++++++++++++++++++++++++++++++++++++++ + 15 files changed, 202 insertions(+), 1 deletion(-) + create mode 100644 elf/libtracemod1-1.c + create mode 100644 elf/libtracemod2-1.c + create mode 100644 elf/libtracemod3-1.c + create mode 100644 elf/libtracemod4-1.c + create mode 100644 elf/libtracemod5-1.c + create mode 100644 elf/tst-trace1.exp + create mode 100644 elf/tst-trace2.exp + create mode 100644 elf/tst-trace3.exp + create mode 100644 elf/tst-trace4.exp + create mode 100644 elf/tst-trace5.exp + create mode 100755 scripts/tst-ld-trace.py + +diff --git a/elf/Makefile b/elf/Makefile +index 4bca0424a3..fa1ea28b25 100644 +--- a/elf/Makefile ++++ b/elf/Makefile +@@ -652,6 +652,11 @@ modules-names = \ + libmarkermod5-3 \ + libmarkermod5-4 \ + libmarkermod5-5 \ ++ libtracemod1-1 \ ++ libtracemod2-1 \ ++ libtracemod3-1 \ ++ libtracemod4-1 \ ++ libtracemod5-1 \ + ltglobmod1 \ + ltglobmod2 \ + neededobj1 \ +@@ -1112,6 +1117,11 @@ tests-special += \ + $(objpfx)tst-initorder2-cmp.out \ + $(objpfx)tst-unused-dep-cmp.out \ + $(objpfx)tst-unused-dep.out \ ++ $(objpfx)tst-trace1.out \ ++ $(objpfx)tst-trace2.out \ ++ $(objpfx)tst-trace3.out \ ++ $(objpfx)tst-trace4.out \ ++ $(objpfx)tst-trace5.out \ + # tests-special + endif + +@@ -2787,3 +2797,47 @@ $(objpfx)tst-p_align3: $(objpfx)tst-p_alignmod3.so + $(objpfx)tst-p_align3.out: tst-p_align3.sh $(objpfx)tst-p_align3 + $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ + $(evaluate-test) ++ ++LDFLAGS-libtracemod1-1.so += -Wl,-soname,libtracemod1.so ++LDFLAGS-libtracemod2-1.so += -Wl,-soname,libtracemod2.so ++LDFLAGS-libtracemod3-1.so += -Wl,-soname,libtracemod3.so ++LDFLAGS-libtracemod4-1.so += -Wl,-soname,libtracemod4.so ++LDFLAGS-libtracemod5-1.so += -Wl,-soname,libtracemod5.so ++ ++$(objpfx)libtracemod1-1.so: $(objpfx)libtracemod2-1.so \ ++ $(objpfx)libtracemod3-1.so ++$(objpfx)libtracemod2-1.so: $(objpfx)libtracemod4-1.so \ ++ $(objpfx)libtracemod5-1.so ++ ++define libtracemod-x ++$(objpfx)libtracemod$(1)/libtracemod$(1).so: $(objpfx)libtracemod$(1)-1.so ++ $$(make-target-directory) ++ cp $$< $$@ ++endef ++libtracemod-suffixes = 1 2 3 4 5 ++$(foreach i,$(libtracemod-suffixes), $(eval $(call libtracemod-x,$(i)))) ++ ++define tst-trace-skeleton ++$(objpfx)tst-trace$(1).out: $(objpfx)libtracemod1/libtracemod1.so \ ++ $(objpfx)libtracemod2/libtracemod2.so \ ++ $(objpfx)libtracemod3/libtracemod3.so \ ++ $(objpfx)libtracemod4/libtracemod4.so \ ++ $(objpfx)libtracemod5/libtracemod5.so \ ++ $(..)scripts/tst-ld-trace.py \ ++ tst-trace$(1).exp ++ ${ $(PYTHON) $(..)scripts/tst-ld-trace.py \ ++ "$(test-wrapper-env) $(elf-objpfx)$(rtld-installed-name) \ ++ --library-path $(common-objpfx):$(strip $(2)) \ ++ $(objpfx)libtracemod1/libtracemod1.so" tst-trace$(1).exp \ ++ } > $$@; $$(evaluate-test) ++endef ++ ++$(eval $(call tst-trace-skeleton,1,)) ++$(eval $(call tst-trace-skeleton,2,\ ++ $(objpfx)libtracemod2)) ++$(eval $(call tst-trace-skeleton,3,\ ++ $(objpfx)libtracemod2:$(objpfx)libtracemod3)) ++$(eval $(call tst-trace-skeleton,4,\ ++ $(objpfx)libtracemod2:$(objpfx)libtracemod3:$(objpfx)libtracemod4)) ++$(eval $(call tst-trace-skeleton,5,\ ++ $(objpfx)libtracemod2:$(objpfx)libtracemod3:$(objpfx)libtracemod4:$(objpfx)libtracemod5)) +diff --git a/elf/dl-deps.c b/elf/dl-deps.c +index c8bab5cad5..cfe7f0743a 100644 +--- a/elf/dl-deps.c ++++ b/elf/dl-deps.c +@@ -489,6 +489,8 @@ _dl_map_object_deps (struct link_map *map, + + for (nlist = 0, runp = known; runp; runp = runp->next) + { ++ /* _dl_sort_maps ignores l_faked object, so it is safe to not consider ++ them for nlist. */ + if (__builtin_expect (trace_mode, 0) && runp->map->l_faked) + /* This can happen when we trace the loading. */ + --map->l_searchlist.r_nlist; +diff --git a/elf/dl-sort-maps.c b/elf/dl-sort-maps.c +index 9e9d53ec47..96638d7ed1 100644 +--- a/elf/dl-sort-maps.c ++++ b/elf/dl-sort-maps.c +@@ -140,7 +140,9 @@ static void + dfs_traversal (struct link_map ***rpo, struct link_map *map, + bool *do_reldeps) + { +- if (map->l_visited) ++ /* _dl_map_object_deps ignores l_faked objects when calculating the ++ number of maps before calling _dl_sort_maps, ignore them as well. */ ++ if (map->l_visited || map->l_faked) + return; + + map->l_visited = 1; +diff --git a/elf/libtracemod1-1.c b/elf/libtracemod1-1.c +new file mode 100644 +index 0000000000..7c89c9a5a4 +--- /dev/null ++++ b/elf/libtracemod1-1.c +@@ -0,0 +1 @@ ++/* Empty */ +diff --git a/elf/libtracemod2-1.c b/elf/libtracemod2-1.c +new file mode 100644 +index 0000000000..7c89c9a5a4 +--- /dev/null ++++ b/elf/libtracemod2-1.c +@@ -0,0 +1 @@ ++/* Empty */ +diff --git a/elf/libtracemod3-1.c b/elf/libtracemod3-1.c +new file mode 100644 +index 0000000000..7c89c9a5a4 +--- /dev/null ++++ b/elf/libtracemod3-1.c +@@ -0,0 +1 @@ ++/* Empty */ +diff --git a/elf/libtracemod4-1.c b/elf/libtracemod4-1.c +new file mode 100644 +index 0000000000..7c89c9a5a4 +--- /dev/null ++++ b/elf/libtracemod4-1.c +@@ -0,0 +1 @@ ++/* Empty */ +diff --git a/elf/libtracemod5-1.c b/elf/libtracemod5-1.c +new file mode 100644 +index 0000000000..7c89c9a5a4 +--- /dev/null ++++ b/elf/libtracemod5-1.c +@@ -0,0 +1 @@ ++/* Empty */ +diff --git a/elf/tst-trace1.exp b/elf/tst-trace1.exp +new file mode 100644 +index 0000000000..4a6f5211a6 +--- /dev/null ++++ b/elf/tst-trace1.exp +@@ -0,0 +1,4 @@ ++ld 1 ++libc 1 ++libtracemod2.so 0 ++libtracemod3.so 0 +diff --git a/elf/tst-trace2.exp b/elf/tst-trace2.exp +new file mode 100644 +index 0000000000..e13506e2eb +--- /dev/null ++++ b/elf/tst-trace2.exp +@@ -0,0 +1,6 @@ ++ld 1 ++libc 1 ++libtracemod2.so 1 ++libtracemod3.so 0 ++libtracemod4.so 0 ++libtracemod5.so 0 +diff --git a/elf/tst-trace3.exp b/elf/tst-trace3.exp +new file mode 100644 +index 0000000000..e574549d12 +--- /dev/null ++++ b/elf/tst-trace3.exp +@@ -0,0 +1,6 @@ ++ld 1 ++libc 1 ++libtracemod2.so 1 ++libtracemod3.so 1 ++libtracemod4.so 0 ++libtracemod5.so 0 +diff --git a/elf/tst-trace4.exp b/elf/tst-trace4.exp +new file mode 100644 +index 0000000000..31ca97b35b +--- /dev/null ++++ b/elf/tst-trace4.exp +@@ -0,0 +1,6 @@ ++ld 1 ++libc 1 ++libtracemod2.so 1 ++libtracemod3.so 1 ++libtracemod4.so 1 ++libtracemod5.so 0 +diff --git a/elf/tst-trace5.exp b/elf/tst-trace5.exp +new file mode 100644 +index 0000000000..5d7d953726 +--- /dev/null ++++ b/elf/tst-trace5.exp +@@ -0,0 +1,6 @@ ++ld 1 ++libc 1 ++libtracemod2.so 1 ++libtracemod3.so 1 ++libtracemod4.so 1 ++libtracemod5.so 1 +diff --git a/scripts/tst-ld-trace.py b/scripts/tst-ld-trace.py +new file mode 100755 +index 0000000000..f5a4028003 +--- /dev/null ++++ b/scripts/tst-ld-trace.py +@@ -0,0 +1,108 @@ ++#!/usr/bin/python3 ++# Dump the output of LD_TRACE_LOADED_OBJECTS in architecture neutral format. ++# Copyright (C) 2022 Free Software Foundation, Inc. ++# Copyright The GNU Toolchain Authors. ++# 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 ++# . ++ ++import argparse ++import os ++import subprocess ++import sys ++ ++try: ++ subprocess.run ++except: ++ class _CompletedProcess: ++ def __init__(self, args, returncode, stdout=None, stderr=None): ++ self.args = args ++ self.returncode = returncode ++ self.stdout = stdout ++ self.stderr = stderr ++ ++ def _run(*popenargs, input=None, timeout=None, check=False, **kwargs): ++ assert(timeout is None) ++ with subprocess.Popen(*popenargs, **kwargs) as process: ++ try: ++ stdout, stderr = process.communicate(input) ++ except: ++ process.kill() ++ process.wait() ++ raise ++ returncode = process.poll() ++ if check and returncode: ++ raise subprocess.CalledProcessError(returncode, popenargs) ++ return _CompletedProcess(popenargs, returncode, stdout, stderr) ++ ++ subprocess.run = _run ++ ++def is_vdso(lib): ++ return lib.startswith('linux-gate') or lib.startswith('linux-vdso') ++ ++ ++def parse_trace(cmd, fref): ++ new_env = os.environ.copy() ++ new_env['LD_TRACE_LOADED_OBJECTS'] = '1' ++ trace_out = subprocess.run(cmd, stdout=subprocess.PIPE, check=True, ++ universal_newlines=True, env=new_env).stdout ++ trace = [] ++ for line in trace_out.splitlines(): ++ line = line.strip() ++ if is_vdso(line): ++ continue ++ fields = line.split('=>' if '=>' in line else ' ') ++ lib = os.path.basename(fields[0].strip()) ++ if lib.startswith('ld'): ++ lib = 'ld' ++ elif lib.startswith('libc'): ++ lib = 'libc' ++ found = 1 if fields[1].strip() != 'not found' else 0 ++ trace += ['{} {}'.format(lib, found)] ++ trace = sorted(trace) ++ ++ reference = sorted(line.replace('\n','') for line in fref.readlines()) ++ ++ ret = 0 if trace == reference else 1 ++ if ret != 0: ++ for i in reference: ++ if i not in trace: ++ print("Only in {}: {}".format(fref.name, i)) ++ for i in trace: ++ if i not in reference: ++ print("Only in trace: {}".format(i)) ++ ++ sys.exit(ret) ++ ++ ++def get_parser(): ++ parser = argparse.ArgumentParser(description=__doc__) ++ parser.add_argument('command', ++ help='comand to run') ++ parser.add_argument('reference', ++ help='reference file to compare') ++ return parser ++ ++ ++def main(argv): ++ parser = get_parser() ++ opts = parser.parse_args(argv) ++ with open(opts.reference, 'r') as fref: ++ # Remove the initial 'env' command. ++ parse_trace(opts.command.split()[1:], fref) ++ ++ ++if __name__ == '__main__': ++ main(sys.argv[1:]) +-- +2.39.2 + diff -Nru glibc-2.35/debian/patches/lp2007599-S390-Influence-hwcaps-stfle-via-GLIBC_TUNABLES.patch glibc-2.35/debian/patches/lp2007599-S390-Influence-hwcaps-stfle-via-GLIBC_TUNABLES.patch --- glibc-2.35/debian/patches/lp2007599-S390-Influence-hwcaps-stfle-via-GLIBC_TUNABLES.patch 1970-01-01 00:00:00.000000000 +0000 +++ glibc-2.35/debian/patches/lp2007599-S390-Influence-hwcaps-stfle-via-GLIBC_TUNABLES.patch 2023-07-26 08:23:48.000000000 +0000 @@ -0,0 +1,669 @@ +From 41f67ccbe92b4fd09e1062b383e55e407ae5bfa1 Mon Sep 17 00:00:00 2001 +From: Stefan Liebler +Date: Thu, 2 Feb 2023 14:57:50 +0100 +Subject: [PATCH] S390: Influence hwcaps/stfle via GLIBC_TUNABLES. + +This patch enables the option to influence hwcaps and stfle bits used +by the s390 specific ifunc-resolvers. The currently x86-specific +tunable glibc.cpu.hwcaps is also used on s390x to achieve the task. In +addition the user can also set a CPU arch-level like z13 instead of +single HWCAP and STFLE features. + +Note that the tunable only handles the features which are really used +in the IFUNC-resolvers. All others are ignored as the values are only +used inside glibc. Thus we can influence: +- HWCAP_S390_VXRS (z13) +- HWCAP_S390_VXRS_EXT (z14) +- HWCAP_S390_VXRS_EXT2 (z15) +- STFLE_MIE3 (z15) + +The influenced hwcap/stfle-bits are stored in the s390-specific +cpu_features struct which also contains reserved fields for future +usage. + +The ifunc-resolvers and users of stfle bits are adjusted to use the +information from cpu_features struct. + +On 31bit, the ELF_MACHINE_IRELATIVE macro is now also defined. +Otherwise the new ifunc-resolvers segfaults as they depend on +the not yet processed_rtld_global_ro@GLIBC_PRIVATE relocation. +--- + manual/tunables.texi | 6 +- + sysdeps/s390/cpu-features.c | 239 +++++++++++++++++++++++ + sysdeps/s390/cpu-features.h | 46 +++++ + sysdeps/s390/dl-procinfo.c | 37 ++++ + sysdeps/s390/dl-tunables.list | 25 +++ + sysdeps/s390/ldsodefs.h | 1 + + sysdeps/s390/libc-start.c | 33 ++++ + sysdeps/s390/multiarch/ifunc-impl-list.c | 13 +- + sysdeps/s390/multiarch/ifunc-resolve.h | 41 +--- + sysdeps/s390/s390-32/dl-machine.h | 9 + + sysdeps/s390/s390-64/dl-machine.h | 8 + + sysdeps/unix/sysv/linux/s390/sysconf.c | 29 +-- + 12 files changed, 423 insertions(+), 64 deletions(-) + create mode 100644 sysdeps/s390/cpu-features.c + create mode 100644 sysdeps/s390/cpu-features.h + create mode 100644 sysdeps/s390/dl-tunables.list + create mode 100644 sysdeps/s390/libc-start.c + +diff --git a/manual/tunables.texi b/manual/tunables.texi +index ffd50a3fe2..c2630b83ab 100644 +--- a/manual/tunables.texi ++++ b/manual/tunables.texi +@@ -486,7 +486,11 @@ enable CPU/ARCH feature @code{yyy}, disable CPU/ARCH feature @code{xxx} + and @code{zzz} where the feature name is case-sensitive and has to match + the ones in @code{sysdeps/x86/cpu-features.h}. + +-This tunable is specific to i386 and x86-64. ++On s390x, the supported HWCAP and STFLE features can be found in ++@code{sysdeps/s390/cpu-features.c}. In addition the user can also set ++a CPU arch-level like @code{z13} instead of single HWCAP and STFLE features. ++ ++This tunable is specific to i386, x86-64 and s390x. + @end deftp + + @deftp Tunable glibc.cpu.cached_memopt +diff --git a/sysdeps/s390/cpu-features.c b/sysdeps/s390/cpu-features.c +new file mode 100644 +index 0000000000..afeb9b5638 +--- /dev/null ++++ b/sysdeps/s390/cpu-features.c +@@ -0,0 +1,239 @@ ++/* Initialize cpu feature data. s390x version. ++ Copyright (C) 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 ++ ++#if HAVE_TUNABLES ++# include ++# include ++# include ++extern __typeof (memcmp) MEMCMP_DEFAULT; ++#endif ++ ++#if HAVE_TUNABLES ++# define S390_COPY_CPU_FEATURES(SRC_PTR, DEST_PTR) \ ++ (DEST_PTR)->hwcap = (SRC_PTR)->hwcap; \ ++ (DEST_PTR)->stfle_bits[0] = (SRC_PTR)->stfle_bits[0]; ++ ++static void ++TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp) ++{ ++ /* The current IFUNC selection is always using the most recent ++ features which are available via AT_HWCAP or STFLE-bits. But in ++ some scenarios it is useful to adjust this selection. ++ ++ The environment variable: ++ ++ GLIBC_TUNABLES=glibc.cpu.hwcaps=-xxx,yyy,zzz,.... ++ ++ can be used to enable HWCAP/STFLE feature yyy, disable HWCAP/STFLE feature ++ xxx, where the feature name is case-sensitive and has to match the ones ++ used below. Furthermore, the ARCH-level zzz can be used to set various ++ HWCAP/STFLE features at once. */ ++ ++ /* Copy the features from dl_s390_cpu_features, which contains the features ++ provided by AT_HWCAP and stfle-instruction. */ ++ struct cpu_features *cpu_features = &GLRO(dl_s390_cpu_features); ++ struct cpu_features cpu_features_orig; ++ S390_COPY_CPU_FEATURES (cpu_features, &cpu_features_orig); ++ struct cpu_features cpu_features_curr; ++ S390_COPY_CPU_FEATURES (cpu_features, &cpu_features_curr); ++ ++ const char *token = valp->strval; ++ do ++ { ++ const char *token_end, *feature; ++ bool disable; ++ size_t token_len; ++ size_t feature_len; ++ ++ /* Find token separator or end of string. */ ++ for (token_end = token; *token_end != ','; token_end++) ++ if (*token_end == '\0') ++ break; ++ ++ /* Determine feature. */ ++ token_len = token_end - token; ++ if (*token == '-') ++ { ++ disable = true; ++ feature = token + 1; ++ feature_len = token_len - 1; ++ } ++ else ++ { ++ disable = false; ++ feature = token; ++ feature_len = token_len; ++ } ++ ++ /* Handle only the features here which are really used in the ++ IFUNC-resolvers. All others are ignored as the values are only used ++ inside glibc. */ ++ bool reset_features = false; ++ unsigned long int hwcap_mask = 0UL; ++ unsigned long long stfle_bits0_mask = 0ULL; ++ ++ if ((*feature == 'z' || *feature == 'a')) ++ { ++ if ((feature_len == 5 && *feature == 'z' ++ && MEMCMP_DEFAULT (feature, "zEC12", 5) == 0) ++ || (feature_len == 6 && *feature == 'a' ++ && MEMCMP_DEFAULT (feature, "arch10", 6) == 0)) ++ { ++ reset_features = true; ++ disable = true; ++ hwcap_mask = HWCAP_S390_VXRS | HWCAP_S390_VXRS_EXT ++ | HWCAP_S390_VXRS_EXT2; ++ stfle_bits0_mask = S390_STFLE_MASK_ARCH13_MIE3; ++ } ++ else if ((feature_len == 3 && *feature == 'z' ++ && MEMCMP_DEFAULT (feature, "z13", 3) == 0) ++ || (feature_len == 6 && *feature == 'a' ++ && MEMCMP_DEFAULT (feature, "arch11", 6) == 0)) ++ { ++ reset_features = true; ++ disable = true; ++ hwcap_mask = HWCAP_S390_VXRS_EXT | HWCAP_S390_VXRS_EXT2; ++ stfle_bits0_mask = S390_STFLE_MASK_ARCH13_MIE3; ++ } ++ else if ((feature_len == 3 && *feature == 'z' ++ && MEMCMP_DEFAULT (feature, "z14", 3) == 0) ++ || (feature_len == 6 && *feature == 'a' ++ && MEMCMP_DEFAULT (feature, "arch12", 6) == 0)) ++ { ++ reset_features = true; ++ disable = true; ++ hwcap_mask = HWCAP_S390_VXRS_EXT2; ++ stfle_bits0_mask = S390_STFLE_MASK_ARCH13_MIE3; ++ } ++ else if ((feature_len == 3 && *feature == 'z' ++ && (MEMCMP_DEFAULT (feature, "z15", 3) == 0 ++ || MEMCMP_DEFAULT (feature, "z16", 3) == 0)) ++ || (feature_len == 6 ++ && (MEMCMP_DEFAULT (feature, "arch13", 6) == 0 ++ || MEMCMP_DEFAULT (feature, "arch14", 6) == 0))) ++ { ++ /* For z15 or newer we don't have to disable something, ++ but we have to reset to the original values. */ ++ reset_features = true; ++ } ++ } ++ else if (*feature == 'H') ++ { ++ if (feature_len == 15 ++ && MEMCMP_DEFAULT (feature, "HWCAP_S390_VXRS", 15) == 0) ++ { ++ hwcap_mask = HWCAP_S390_VXRS; ++ if (disable) ++ hwcap_mask |= HWCAP_S390_VXRS_EXT | HWCAP_S390_VXRS_EXT2; ++ } ++ else if (feature_len == 19 ++ && MEMCMP_DEFAULT (feature, "HWCAP_S390_VXRS_EXT", 19) == 0) ++ { ++ hwcap_mask = HWCAP_S390_VXRS_EXT; ++ if (disable) ++ hwcap_mask |= HWCAP_S390_VXRS_EXT2; ++ else ++ hwcap_mask |= HWCAP_S390_VXRS; ++ } ++ else if (feature_len == 20 ++ && MEMCMP_DEFAULT (feature, "HWCAP_S390_VXRS_EXT2", 20) == 0) ++ { ++ hwcap_mask = HWCAP_S390_VXRS_EXT2; ++ if (!disable) ++ hwcap_mask |= HWCAP_S390_VXRS | HWCAP_S390_VXRS_EXT; ++ } ++ } ++ else if (*feature == 'S') ++ { ++ if (feature_len == 10 ++ && MEMCMP_DEFAULT (feature, "STFLE_MIE3", 10) == 0) ++ { ++ stfle_bits0_mask = S390_STFLE_MASK_ARCH13_MIE3; ++ } ++ } ++ ++ /* Perform the actions determined above. */ ++ if (reset_features) ++ { ++ S390_COPY_CPU_FEATURES (&cpu_features_orig, &cpu_features_curr); ++ } ++ ++ if (hwcap_mask != 0UL) ++ { ++ if (disable) ++ cpu_features_curr.hwcap &= ~hwcap_mask; ++ else ++ cpu_features_curr.hwcap |= hwcap_mask; ++ } ++ ++ if (stfle_bits0_mask != 0ULL) ++ { ++ if (disable) ++ cpu_features_curr.stfle_bits[0] &= ~stfle_bits0_mask; ++ else ++ cpu_features_curr.stfle_bits[0] |= stfle_bits0_mask; ++ } ++ ++ /* Jump over current token ... */ ++ token += token_len; ++ ++ /* ... and skip token separator for next round. */ ++ if (*token == ',') token++; ++ } ++ while (*token != '\0'); ++ ++ /* Copy back the features after checking that no unsupported features were ++ enabled by user. */ ++ cpu_features->hwcap = cpu_features_curr.hwcap & cpu_features_orig.hwcap; ++ cpu_features->stfle_bits[0] = cpu_features_curr.stfle_bits[0] ++ & cpu_features_orig.stfle_bits[0]; ++} ++#endif ++ ++static inline void ++init_cpu_features (struct cpu_features *cpu_features) ++{ ++ /* Fill cpu_features as passed by kernel and machine. */ ++ cpu_features->hwcap = GLRO(dl_hwcap); ++ ++ /* We want just 1 double word to be returned. */ ++ if (__glibc_likely ((cpu_features->hwcap & HWCAP_S390_STFLE) ++ && (cpu_features->hwcap & HWCAP_S390_ZARCH) ++ && (cpu_features->hwcap & HWCAP_S390_HIGH_GPRS))) ++ { ++ register unsigned long reg0 __asm__("0") = 0; ++ __asm__ __volatile__(".machine push" "\n\t" ++ ".machine \"z9-109\"" "\n\t" ++ ".machinemode \"zarch_nohighgprs\"\n\t" ++ "stfle %0" "\n\t" ++ ".machine pop" "\n" ++ : "=QS" (cpu_features->stfle_bits[0]), ++ "+d" (reg0) ++ : : "cc"); ++ } ++ else ++ { ++ cpu_features->stfle_bits[0] = 0ULL; ++ } ++ ++#if HAVE_TUNABLES ++ TUNABLE_GET (glibc, cpu, hwcaps, tunable_val_t *, TUNABLE_CALLBACK (set_hwcaps)); ++#endif ++} +diff --git a/sysdeps/s390/cpu-features.h b/sysdeps/s390/cpu-features.h +new file mode 100644 +index 0000000000..5e6b58f7c5 +--- /dev/null ++++ b/sysdeps/s390/cpu-features.h +@@ -0,0 +1,46 @@ ++/* Initialize cpu feature data. s390x version. ++ Copyright (C) 2023 Free Software Foundation, Inc. ++ ++ 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 __CPU_FEATURES_S390X_H ++# define __CPU_FEATURES_S390X_H ++ ++#define S390_STFLE_BITS_Z10 34 /* General instructions extension */ ++#define S390_STFLE_BITS_Z196 45 /* Distinct operands, pop ... */ ++#define S390_STFLE_BITS_ARCH13_MIE3 61 /* Miscellaneous-Instruction-Extensions ++ Facility 3, e.g. mvcrl. */ ++ ++#define S390_STFLE_MASK_ARCH13_MIE3 (1ULL << (63 - S390_STFLE_BITS_ARCH13_MIE3)) ++ ++ ++#define S390_IS_ARCH13_MIE3(STFLE_BITS_ARRAY) \ ++ (((STFLE_BITS_ARRAY)[0] & S390_STFLE_MASK_ARCH13_MIE3) != 0) ++ ++#define S390_IS_Z196(STFLE_BITS_ARRAY) \ ++ (((STFLE_BITS_ARRAY)[0] & (1ULL << (63 - S390_STFLE_BITS_Z196))) != 0) ++ ++#define S390_IS_Z10(STFLE_BITS_ARRAY) \ ++ (((STFLE_BITS_ARRAY)[0] & (1ULL << (63 - S390_STFLE_BITS_Z10))) != 0) ++ ++struct cpu_features ++{ ++ unsigned long int hwcap; ++ unsigned long int __reserved_hwcap2; ++ unsigned long long stfle_bits[3]; ++ unsigned long long __reserved[11]; ++}; ++ ++#endif /* __CPU_FEATURES_S390X_H */ +diff --git a/sysdeps/s390/dl-procinfo.c b/sysdeps/s390/dl-procinfo.c +index 52fb6ac488..a6b61e8523 100644 +--- a/sysdeps/s390/dl-procinfo.c ++++ b/sysdeps/s390/dl-procinfo.c +@@ -77,5 +77,21 @@ + , + #endif + ++#if !IS_IN (ldconfig) ++# if !defined PROCINFO_DECL && defined SHARED ++ ._dl_s390_cpu_features ++# else ++PROCINFO_CLASS struct cpu_features _dl_s390_cpu_features ++# endif ++# ifndef PROCINFO_DECL ++= { } ++# endif ++# if !defined SHARED || defined PROCINFO_DECL ++; ++# else ++, ++# endif ++#endif ++ + #undef PROCINFO_DECL + #undef PROCINFO_CLASS +diff --git a/sysdeps/s390/dl-tunables.list b/sysdeps/s390/dl-tunables.list +new file mode 100644 +index 0000000000..7a09828c48 +--- /dev/null ++++ b/sysdeps/s390/dl-tunables.list +@@ -0,0 +1,25 @@ ++# s390 specific tunables. ++# Copyright (C) 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 ++# . ++ ++glibc { ++ cpu { ++ hwcaps { ++ type: STRING ++ } ++ } ++} +diff --git a/sysdeps/s390/ldsodefs.h b/sysdeps/s390/ldsodefs.h +index 67f02c8f34..0f63d7cc0d 100644 +--- a/sysdeps/s390/ldsodefs.h ++++ b/sysdeps/s390/ldsodefs.h +@@ -20,6 +20,7 @@ + #define _S390_LDSODEFS_H 1 + + #include ++#include + + struct La_s390_32_regs; + struct La_s390_32_retval; +diff --git a/sysdeps/s390/libc-start.c b/sysdeps/s390/libc-start.c +new file mode 100644 +index 0000000000..eb35d6679f +--- /dev/null ++++ b/sysdeps/s390/libc-start.c +@@ -0,0 +1,33 @@ ++/* Override csu/libc-start.c on s390x. ++ Copyright (C) 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 SHARED ++ ++/* Mark symbols hidden in static PIE for early self relocation to work. */ ++# if BUILD_PIE_DEFAULT ++# pragma GCC visibility push(hidden) ++# endif ++# include ++# include ++ ++extern struct cpu_features _dl_s390_cpu_features; ++ ++# define ARCH_INIT_CPU_FEATURES() init_cpu_features (&_dl_s390_cpu_features) ++ ++#endif ++#include +diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c +index fd6b596bdf..1532258af2 100644 +--- a/sysdeps/s390/multiarch/ifunc-impl-list.c ++++ b/sysdeps/s390/multiarch/ifunc-impl-list.c +@@ -19,6 +19,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -78,14 +79,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, + size_t i = 0; + + /* Get hardware information. */ +- unsigned long int dl_hwcap = GLRO (dl_hwcap); +- unsigned long long stfle_bits = 0ULL; +- if ((dl_hwcap & HWCAP_S390_STFLE) +- && (dl_hwcap & HWCAP_S390_ZARCH) +- && (dl_hwcap & HWCAP_S390_HIGH_GPRS)) +- { +- S390_STORE_STFLE (stfle_bits); +- } ++ const struct cpu_features *features = &GLRO(dl_s390_cpu_features); ++ unsigned long int dl_hwcap = features->hwcap; ++ const unsigned long long * __attribute__((unused)) stfle_bits ++ = features->stfle_bits; + + #if HAVE_MEMSET_IFUNC + IFUNC_IMPL (i, name, memset, +diff --git a/sysdeps/s390/multiarch/ifunc-resolve.h b/sysdeps/s390/multiarch/ifunc-resolve.h +index 4e1445d717..12b55da679 100644 +--- a/sysdeps/s390/multiarch/ifunc-resolve.h ++++ b/sysdeps/s390/multiarch/ifunc-resolve.h +@@ -19,42 +19,17 @@ + + #include + #include ++#include + +-#define S390_STFLE_BITS_Z10 34 /* General instructions extension */ +-#define S390_STFLE_BITS_Z196 45 /* Distinct operands, pop ... */ +-#define S390_STFLE_BITS_ARCH13_MIE3 61 /* Miscellaneous-Instruction-Extensions +- Facility 3, e.g. mvcrl. */ +- +-#define S390_IS_ARCH13_MIE3(STFLE_BITS) \ +- ((STFLE_BITS & (1ULL << (63 - S390_STFLE_BITS_ARCH13_MIE3))) != 0) +- +-#define S390_IS_Z196(STFLE_BITS) \ +- ((STFLE_BITS & (1ULL << (63 - S390_STFLE_BITS_Z196))) != 0) +- +-#define S390_IS_Z10(STFLE_BITS) \ +- ((STFLE_BITS & (1ULL << (63 - S390_STFLE_BITS_Z10))) != 0) +- +-#define S390_STORE_STFLE(STFLE_BITS) \ +- /* We want just 1 double word to be returned. */ \ +- register unsigned long reg0 __asm__("0") = 0; \ +- \ +- __asm__ __volatile__(".machine push" "\n\t" \ +- ".machine \"z9-109\"" "\n\t" \ +- ".machinemode \"zarch_nohighgprs\"\n\t" \ +- "stfle %0" "\n\t" \ +- ".machine pop" "\n" \ +- : "=QS" (STFLE_BITS), "+d" (reg0) \ +- : : "cc"); + #define s390_libc_ifunc_expr_stfle_init() \ +- unsigned long long stfle_bits = 0ULL; \ +- if (__glibc_likely ((hwcap & HWCAP_S390_STFLE) \ +- && (hwcap & HWCAP_S390_ZARCH) \ +- && (hwcap & HWCAP_S390_HIGH_GPRS))) \ +- { \ +- S390_STORE_STFLE (stfle_bits); \ +- } ++ const unsigned long long *stfle_bits = features->stfle_bits; ++ ++#define s390_libc_ifunc_expr_init() \ ++ const struct cpu_features *features = &GLRO(dl_s390_cpu_features); \ ++ /* The hwcap from kernel is passed as argument, but we \ ++ explicitly use the hwcaps from cpu-features struct. */ \ ++ hwcap = features->hwcap; + +-#define s390_libc_ifunc_expr_init() + #define s390_libc_ifunc_expr(TYPE_FUNC, FUNC, EXPR) \ + __ifunc (TYPE_FUNC, FUNC, EXPR, unsigned long int hwcap, \ + s390_libc_ifunc_expr_init); +diff --git a/sysdeps/s390/s390-32/dl-machine.h b/sysdeps/s390/s390-32/dl-machine.h +index d09ab68ab1..100a3e05f6 100644 +--- a/sysdeps/s390/s390-32/dl-machine.h ++++ b/sysdeps/s390/s390-32/dl-machine.h +@@ -28,6 +28,9 @@ + #include + #include + #include ++#include ++ ++#define ELF_MACHINE_IRELATIVE R_390_IRELATIVE + + /* This is an older, now obsolete value. */ + #define EM_S390_OLD 0xA390 +@@ -242,6 +245,12 @@ dl_platform_init (void) + if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0') + /* Avoid an empty string which would disturb us. */ + GLRO(dl_platform) = NULL; ++ ++#ifdef SHARED ++ /* init_cpu_features has been called early from __libc_start_main in ++ static executable. */ ++ init_cpu_features (&GLRO(dl_s390_cpu_features)); ++#endif + } + + static inline Elf32_Addr +diff --git a/sysdeps/s390/s390-64/dl-machine.h b/sysdeps/s390/s390-64/dl-machine.h +index 10b1f00052..9fabb09750 100644 +--- a/sysdeps/s390/s390-64/dl-machine.h ++++ b/sysdeps/s390/s390-64/dl-machine.h +@@ -29,6 +29,7 @@ + #include + #include + #include ++#include + + #define ELF_MACHINE_IRELATIVE R_390_IRELATIVE + +@@ -220,6 +221,13 @@ dl_platform_init (void) + if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0') + /* Avoid an empty string which would disturb us. */ + GLRO(dl_platform) = NULL; ++ ++#ifdef SHARED ++ /* init_cpu_features has been called early from __libc_start_main in ++ static executable. */ ++ init_cpu_features (&GLRO(dl_s390_cpu_features)); ++#endif ++ + } + + static inline Elf64_Addr +diff --git a/sysdeps/unix/sysv/linux/s390/sysconf.c b/sysdeps/unix/sysv/linux/s390/sysconf.c +index 69969f78e4..45bd8bf4a1 100644 +--- a/sysdeps/unix/sysv/linux/s390/sysconf.c ++++ b/sysdeps/unix/sysv/linux/s390/sysconf.c +@@ -18,6 +18,7 @@ + + #include + #include ++#include + + static long int linux_sysconf (int name); + +@@ -44,12 +45,14 @@ get_cache_info (int level, int attr, int type) + || type < CACHE_TYPE_DATA || type > CACHE_TYPE_INSTRUCTION) + return 0L; + ++ const struct cpu_features *features = &GLRO(dl_s390_cpu_features); ++ + /* Check if ecag-instruction is available. + ecag - extract CPU attribute (only in zarch; arch >= z10; in as 2.24) */ +- if (!(GLRO (dl_hwcap) & HWCAP_S390_STFLE) ++ if (!(features->hwcap & HWCAP_S390_STFLE) + #if !defined __s390x__ +- || !(GLRO (dl_hwcap) & HWCAP_S390_ZARCH) +- || !(GLRO (dl_hwcap) & HWCAP_S390_HIGH_GPRS) ++ || !(features->hwcap & HWCAP_S390_ZARCH) ++ || !(features->hwcap & HWCAP_S390_HIGH_GPRS) + #endif /* !__s390x__ */ + ) + { +@@ -62,25 +65,7 @@ get_cache_info (int level, int attr, int type) + return 0L; + } + +- /* Store facility list and check for z10. +- (see ifunc-resolver for details) */ +- register unsigned long reg0 __asm__("0") = 0; +-#ifdef __s390x__ +- unsigned long stfle_bits; +-# define STFLE_Z10_MASK (1UL << (63 - 34)) +-#else +- unsigned long long stfle_bits; +-# define STFLE_Z10_MASK (1ULL << (63 - 34)) +-#endif /* !__s390x__ */ +- __asm__ __volatile__(".machine push" "\n\t" +- ".machinemode \"zarch_nohighgprs\"\n\t" +- ".machine \"z9-109\"" "\n\t" +- "stfle %0" "\n\t" +- ".machine pop" "\n" +- : "=QS" (stfle_bits), "+d" (reg0) +- : : "cc"); +- +- if (!(stfle_bits & STFLE_Z10_MASK)) ++ if (!S390_IS_Z10 (features->stfle_bits)) + { + /* We are at least on a z9 machine. + Return 256byte for LINESIZE for L1 d/i-cache, +-- +2.39.2 + diff -Nru glibc-2.35/debian/patches/lp2007796-debug-make-__read_chk-a-cancellation-point-bug-29274.patch glibc-2.35/debian/patches/lp2007796-debug-make-__read_chk-a-cancellation-point-bug-29274.patch --- glibc-2.35/debian/patches/lp2007796-debug-make-__read_chk-a-cancellation-point-bug-29274.patch 1970-01-01 00:00:00.000000000 +0000 +++ glibc-2.35/debian/patches/lp2007796-debug-make-__read_chk-a-cancellation-point-bug-29274.patch 2023-07-26 08:23:48.000000000 +0000 @@ -0,0 +1,133 @@ +From dc30acf20bd635d71cd4c84100e842fdf0429e48 Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Wed, 22 Jun 2022 13:16:30 +0200 +Subject: [PATCH] debug: make __read_chk a cancellation point (bug 29274) + +The __read_chk function, as the implementation behind the fortified read +function, must be a cancellation point, thus it cannot use INLINE_SYSCALL. + +Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/jammy/+source/glibc/+bug/2007796 +Origin: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=dc30acf20bd635d71cd4c84100e842fdf0429e48 + +--- + debug/Makefile | 7 ++++++ + debug/read_chk.c | 10 -------- + debug/tst-read-chk-cancel.c | 50 +++++++++++++++++++++++++++++++++++++ + 3 files changed, 57 insertions(+), 10 deletions(-) + create mode 100644 debug/tst-read-chk-cancel.c + +diff --git a/debug/Makefile b/debug/Makefile +index 96029f32ee..456b349c4d 100644 +--- a/debug/Makefile ++++ b/debug/Makefile +@@ -110,6 +110,7 @@ CPPFLAGS-tst-longjmp_chk2.c += -D_FORTIFY_SOURCE=1 + CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables + CPPFLAGS-tst-longjmp_chk3.c += -D_FORTIFY_SOURCE=1 + CPPFLAGS-tst-realpath-chk.c += -D_FORTIFY_SOURCE=2 ++CPPFLAGS-tst-read-chk-cancel.c += -D_FORTIFY_SOURCE=2 + + # _FORTIFY_SOURCE tests. + # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and +@@ -204,6 +205,10 @@ ifeq ($(have-ssp),yes) + tests += tst-ssp-1 + endif + ++ifeq ($(have-thread-library), yes) ++tests += tst-read-chk-cancel ++endif ++ + ifeq (,$(CXX)) + tests-unsupported = $(tests-cc-chk) + endif +@@ -242,3 +247,5 @@ $(objpfx)xtrace: xtrace.sh + -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \ + -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \ + && rm -f $@ && mv $@.new $@ && chmod +x $@ ++ ++$(objpfx)tst-read-chk-cancel: $(shared-thread-library) +diff --git a/debug/read_chk.c b/debug/read_chk.c +index 0cd58db8cb..274b4f93e9 100644 +--- a/debug/read_chk.c ++++ b/debug/read_chk.c +@@ -16,12 +16,6 @@ + . */ + + #include +-#include +-#ifdef HAVE_INLINED_SYSCALLS +-# include +-# include +-#endif +- + + ssize_t + __read_chk (int fd, void *buf, size_t nbytes, size_t buflen) +@@ -29,9 +23,5 @@ __read_chk (int fd, void *buf, size_t nbytes, size_t buflen) + if (nbytes > buflen) + __chk_fail (); + +-#ifdef HAVE_INLINED_SYSCALLS +- return INLINE_SYSCALL (read, 3, fd, buf, nbytes); +-#else + return __read (fd, buf, nbytes); +-#endif + } +diff --git a/debug/tst-read-chk-cancel.c b/debug/tst-read-chk-cancel.c +new file mode 100644 +index 0000000000..7e06afb596 +--- /dev/null ++++ b/debug/tst-read-chk-cancel.c +@@ -0,0 +1,50 @@ ++/* Test that __read_chk is a cancellation point (BZ #29274) ++ Copyright (C) 2022 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#include ++#include ++#include ++ ++static int pipe_fds[2]; ++static pthread_barrier_t barrier; ++ ++static void * ++read_thread (void *n) ++{ ++ xpthread_barrier_wait (&barrier); ++ char c; ++ /* This call should be forwarded to __read_chk because the buffer size ++ is known, but the read length is non-constant. */ ++ if (read (pipe_fds[0], &c, (uintptr_t) n) != 1) ++ return (void *) -1L; ++ return 0; ++} ++ ++static int ++do_test (void) ++{ ++ xpthread_barrier_init (&barrier, 0, 2); ++ xpipe (pipe_fds); ++ pthread_t thr = xpthread_create (0, read_thread, (void *) 1L); ++ xpthread_barrier_wait (&barrier); ++ xpthread_cancel (thr); ++ xpthread_join (thr); ++ return 0; ++} ++ ++#include +-- +2.39.2 + diff -Nru glibc-2.35/debian/patches/lp2011421/0001-x86-Add-bounds-x86_non_temporal_threshold.patch glibc-2.35/debian/patches/lp2011421/0001-x86-Add-bounds-x86_non_temporal_threshold.patch --- glibc-2.35/debian/patches/lp2011421/0001-x86-Add-bounds-x86_non_temporal_threshold.patch 1970-01-01 00:00:00.000000000 +0000 +++ glibc-2.35/debian/patches/lp2011421/0001-x86-Add-bounds-x86_non_temporal_threshold.patch 2023-07-26 08:23:48.000000000 +0000 @@ -0,0 +1,61 @@ +From b446822b6ae4e8149902a78cdd4a886634ad6321 Mon Sep 17 00:00:00 2001 +From: Noah Goldstein +Date: Wed, 15 Jun 2022 10:41:29 -0700 +Subject: [PATCH] x86: Add bounds `x86_non_temporal_threshold` + +The lower-bound (16448) and upper-bound (SIZE_MAX / 16) are assumed +by memmove-vec-unaligned-erms. + +The lower-bound is needed because memmove-vec-unaligned-erms unrolls +the loop aggressively in the L(large_memset_4x) case. + +The upper-bound is needed because memmove-vec-unaligned-erms +right-shifts the value of `x86_non_temporal_threshold` by +LOG_4X_MEMCPY_THRESH (4) which without a bound may overflow. + +The lack of lower-bound can be a correctness issue. The lack of +upper-bound cannot. + +Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/jammy/+source/glibc/+bug/2011421 +Origin: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b446822b6ae4e8149902a78cdd4a886634ad6321 +--- + manual/tunables.texi | 2 +- + sysdeps/x86/dl-cacheinfo.h | 8 +++++++- + 2 files changed, 8 insertions(+), 2 deletions(-) + +diff --git a/manual/tunables.texi b/manual/tunables.texi +index 1482412078..2c076019ae 100644 +--- a/manual/tunables.texi ++++ b/manual/tunables.texi +@@ -47,7 +47,7 @@ glibc.malloc.mxfast: 0x0 (min: 0x0, max: 0xffffffffffffffff) + glibc.elision.skip_lock_busy: 3 (min: -2147483648, max: 2147483647) + glibc.malloc.top_pad: 0x0 (min: 0x0, max: 0xffffffffffffffff) + glibc.cpu.x86_rep_stosb_threshold: 0x800 (min: 0x1, max: 0xffffffffffffffff) +-glibc.cpu.x86_non_temporal_threshold: 0xc0000 (min: 0x0, max: 0xffffffffffffffff) ++glibc.cpu.x86_non_temporal_threshold: 0xc0000 (min: 0x4040, max: 0x0fffffffffffffff) + glibc.cpu.x86_shstk: + glibc.cpu.hwcap_mask: 0x6 (min: 0x0, max: 0xffffffffffffffff) + glibc.malloc.mmap_max: 0 (min: -2147483648, max: 2147483647) +diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h +index cc3b840f9c..e9f3382108 100644 +--- a/sysdeps/x86/dl-cacheinfo.h ++++ b/sysdeps/x86/dl-cacheinfo.h +@@ -931,8 +931,14 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) + + TUNABLE_SET_WITH_BOUNDS (x86_data_cache_size, data, 0, SIZE_MAX); + TUNABLE_SET_WITH_BOUNDS (x86_shared_cache_size, shared, 0, SIZE_MAX); ++ /* SIZE_MAX >> 4 because memmove-vec-unaligned-erms right-shifts the value of ++ 'x86_non_temporal_threshold' by `LOG_4X_MEMCPY_THRESH` (4) and it is best ++ if that operation cannot overflow. Minimum of 0x4040 (16448) because the ++ L(large_memset_4x) loops need 64-byte to cache align and enough space for ++ at least 1 iteration of 4x PAGE_SIZE unrolled loop. Both values are ++ reflected in the manual. */ + TUNABLE_SET_WITH_BOUNDS (x86_non_temporal_threshold, non_temporal_threshold, +- 0, SIZE_MAX); ++ 0x4040, SIZE_MAX >> 4); + TUNABLE_SET_WITH_BOUNDS (x86_rep_movsb_threshold, rep_movsb_threshold, + minimum_rep_movsb_threshold, SIZE_MAX); + TUNABLE_SET_WITH_BOUNDS (x86_rep_stosb_threshold, rep_stosb_threshold, 1, +-- +2.34.1 + diff -Nru glibc-2.35/debian/patches/lp2011421/0002-x86-Check-minimum-maximum-of-non_temporal_threshold-.patch glibc-2.35/debian/patches/lp2011421/0002-x86-Check-minimum-maximum-of-non_temporal_threshold-.patch --- glibc-2.35/debian/patches/lp2011421/0002-x86-Check-minimum-maximum-of-non_temporal_threshold-.patch 1970-01-01 00:00:00.000000000 +0000 +++ glibc-2.35/debian/patches/lp2011421/0002-x86-Check-minimum-maximum-of-non_temporal_threshold-.patch 2023-07-26 08:23:48.000000000 +0000 @@ -0,0 +1,73 @@ +From 48b74865c63840b288bd85b4d8743533b73b339b Mon Sep 17 00:00:00 2001 +From: "H.J. Lu" +Date: Tue, 3 Jan 2023 13:06:48 -0800 +Subject: [PATCH] x86: Check minimum/maximum of non_temporal_threshold [BZ + #29953] + +The minimum non_temporal_threshold is 0x4040. non_temporal_threshold may +be set to less than the minimum value when the shared cache size isn't +available (e.g., in an emulator) or by the tunable. Add checks for +minimum and maximum of non_temporal_threshold. + +This fixes BZ #29953. + +Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/jammy/+source/glibc/+bug/2011421 +Origin: upstream, https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=48b74865c63840b288bd85b4d8743533b73b339b +--- + sysdeps/x86/dl-cacheinfo.h | 25 ++++++++++++++++--------- + 1 file changed, 16 insertions(+), 9 deletions(-) + +diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h +index e9f3382108..637b5a022d 100644 +--- a/sysdeps/x86/dl-cacheinfo.h ++++ b/sysdeps/x86/dl-cacheinfo.h +@@ -861,6 +861,18 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) + share of the cache, it has a substantial risk of negatively + impacting the performance of other threads running on the chip. */ + unsigned long int non_temporal_threshold = shared * 3 / 4; ++ /* SIZE_MAX >> 4 because memmove-vec-unaligned-erms right-shifts the value of ++ 'x86_non_temporal_threshold' by `LOG_4X_MEMCPY_THRESH` (4) and it is best ++ if that operation cannot overflow. Minimum of 0x4040 (16448) because the ++ L(large_memset_4x) loops need 64-byte to cache align and enough space for ++ at least 1 iteration of 4x PAGE_SIZE unrolled loop. Both values are ++ reflected in the manual. */ ++ unsigned long int maximum_non_temporal_threshold = SIZE_MAX >> 4; ++ unsigned long int minimum_non_temporal_threshold = 0x4040; ++ if (non_temporal_threshold < minimum_non_temporal_threshold) ++ non_temporal_threshold = minimum_non_temporal_threshold; ++ else if (non_temporal_threshold > maximum_non_temporal_threshold) ++ non_temporal_threshold = maximum_non_temporal_threshold; + + #if HAVE_TUNABLES + /* NB: The REP MOVSB threshold must be greater than VEC_SIZE * 8. */ +@@ -915,8 +927,8 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) + shared = tunable_size; + + tunable_size = TUNABLE_GET (x86_non_temporal_threshold, long int, NULL); +- /* NB: Ignore the default value 0. */ +- if (tunable_size != 0) ++ if (tunable_size > minimum_non_temporal_threshold ++ && tunable_size <= maximum_non_temporal_threshold) + non_temporal_threshold = tunable_size; + + tunable_size = TUNABLE_GET (x86_rep_movsb_threshold, long int, NULL); +@@ -931,14 +943,9 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) + + TUNABLE_SET_WITH_BOUNDS (x86_data_cache_size, data, 0, SIZE_MAX); + TUNABLE_SET_WITH_BOUNDS (x86_shared_cache_size, shared, 0, SIZE_MAX); +- /* SIZE_MAX >> 4 because memmove-vec-unaligned-erms right-shifts the value of +- 'x86_non_temporal_threshold' by `LOG_4X_MEMCPY_THRESH` (4) and it is best +- if that operation cannot overflow. Minimum of 0x4040 (16448) because the +- L(large_memset_4x) loops need 64-byte to cache align and enough space for +- at least 1 iteration of 4x PAGE_SIZE unrolled loop. Both values are +- reflected in the manual. */ + TUNABLE_SET_WITH_BOUNDS (x86_non_temporal_threshold, non_temporal_threshold, +- 0x4040, SIZE_MAX >> 4); ++ minimum_non_temporal_threshold, ++ maximum_non_temporal_threshold); + TUNABLE_SET_WITH_BOUNDS (x86_rep_movsb_threshold, rep_movsb_threshold, + minimum_rep_movsb_threshold, SIZE_MAX); + TUNABLE_SET_WITH_BOUNDS (x86_rep_stosb_threshold, rep_stosb_threshold, 1, +-- +2.34.1 + diff -Nru glibc-2.35/debian/patches/series glibc-2.35/debian/patches/series --- glibc-2.35/debian/patches/series 2022-07-06 23:21:29.000000000 +0000 +++ glibc-2.35/debian/patches/series 2023-07-26 08:23:48.000000000 +0000 @@ -179,3 +179,14 @@ ubuntu/local-fallback-to-monotonic.diff ubuntu/submitted-broadcast-to-prevent-deadlock.diff ubuntu/sdt-headers.patch + +lp1995362-elf-Fix-DFS-sorting-algorithm-for-LD_TRACE_LOADED_OB.patch + +lp2007796-debug-make-__read_chk-a-cancellation-point-bug-29274.patch + +lp2007599-S390-Influence-hwcaps-stfle-via-GLIBC_TUNABLES.patch + +lp2011421/0001-x86-Add-bounds-x86_non_temporal_threshold.patch +lp2011421/0002-x86-Check-minimum-maximum-of-non_temporal_threshold-.patch + +lp1992159-socket-Fix-mistyped-define-statement-in-socket-sys-s.patch diff -Nru glibc-2.35/debian/rules.d/debhelper.mk glibc-2.35/debian/rules.d/debhelper.mk --- glibc-2.35/debian/rules.d/debhelper.mk 2022-07-04 22:58:49.000000000 +0000 +++ glibc-2.35/debian/rules.d/debhelper.mk 2023-07-26 08:24:52.000000000 +0000 @@ -52,7 +52,7 @@ if test "$(NOSTRIP_$(curpass))" != 1; then \ if test "$(DEBUG_$(curpass))" = 1; then \ if test "$(DEB_HOST_ARCH)" = "armhf"; then \ - dh_strip -p$(curpass) -Xlibpthread -Xld-$(GLIBC_VERSION).so $(DH_STRIP_DEBUG_PACKAGE); \ + dh_strip -p$(curpass) -Xlibpthread -Xld-linux-$(DEB_HOST_ARCH).so $(DH_STRIP_DEBUG_PACKAGE); \ else \ dh_strip -p$(curpass) -Xlibpthread $(DH_STRIP_DEBUG_PACKAGE); \ fi ; \ @@ -66,7 +66,7 @@ done ; \ else \ if test "$(DEB_HOST_ARCH)" = "armhf"; then \ - dh_strip -p$(curpass) -Xlibpthread -Xld-$(GLIBC_VERSION).so ; \ + dh_strip -p$(curpass) -Xlibpthread -Xld-linux-$(DEB_HOST_ARCH).so ; \ else \ dh_strip -p$(curpass) -Xlibpthread ; \ fi ; \ @@ -100,6 +100,7 @@ -regex '.*/libpthread-.*so' \ -o -regex '.*/libc-.*so' \) \ -exec chmod a+x '{}' ';' + find debian/$(curpass) -type f -name libc.so.* -exec chmod a+x '{}' ';' dh_makeshlibs -Xgconv/ -p$(curpass) -V "$(call xx,shlib_dep)" # Add relevant udeb: lines in shlibs files sh ./debian/shlibs-add-udebs $(curpass)