]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
7 months agoRevert "elf: Always call destructors in reverse constructor order (bug 30785)"
Florian Weimer [Wed, 18 Oct 2023 09:30:38 +0000 (11:30 +0200)] 
Revert "elf: Always call destructors in reverse constructor order (bug 30785)"

This reverts commit 6985865bc3ad5b23147ee73466583dd7fdf65892.

Reason for revert:

The commit changes the order of ELF destructor calls too much relative
to what applications expect or can handle.  In particular, during
process exit and _dl_fini, after the revert commit, we no longer call
the destructors of the main program first; that only happens after
some dlopen'ed objects have been destructed.  This robs applications
of an opportunity to influence destructor order by calling dlclose
explicitly from the main program's ELF destructors.  A couple of
different approaches involving reverse constructor order were tried,
and none of them worked really well.  It seems we need to keep the
dependency sorting in _dl_fini.

There is also an ambiguity regarding nested dlopen calls from ELF
constructors: Should those destructors run before or after the object
that called dlopen?  Commit 6985865bc3ad5b2314 used reverse order
of the start of ELF constructor calls for destructors, but arguably
using completion of constructors is more correct.  However, that alone
is not sufficient to address application compatibility issues (it
does not change _dl_fini ordering at all).

7 months agoRevert "elf: Fix compile error with -DNDEBUG [BZ #18755]"
Florian Weimer [Wed, 18 Oct 2023 09:30:38 +0000 (11:30 +0200)] 
Revert "elf: Fix compile error with -DNDEBUG [BZ #18755]"

This reverts commit 964d15a007d7fb1258f2ad7c8cf4afcfb9a65719.

Reason for revert: Conflicts with revert of commit 6985865bc3ad5b23147.

7 months agoAdd strlcat/wcslcat testcase.
Sunil K Pandey [Thu, 27 Jul 2023 23:20:49 +0000 (16:20 -0700)] 
Add strlcat/wcslcat testcase.

This patch implements comprehensive tests for strlcat/wcslcat
functions.  Tests are mostly derived from strncat test suites
and modified to incorporate strlcat/wcslcat specifications.

Reviewed-by: DJ Delorie <dj@redhat.com>
7 months agoAdd strlcpy/wcslcpy testcase
Sunil K Pandey [Thu, 27 Jul 2023 23:20:37 +0000 (16:20 -0700)] 
Add strlcpy/wcslcpy testcase

This patch implements comprehensive tests for strlcpy/wcslcpy
functions.  Tests are mostly derived from strncpy test suites
and modified to incorporate strlcpy/wcslcpy specifications.

Reviewed-by: DJ Delorie <dj@redhat.com>
7 months agoAdd LE DSCP code point from RFC-8622.
Bruno Victal [Tue, 17 Oct 2023 17:00:27 +0000 (19:00 +0200)] 
Add LE DSCP code point from RFC-8622.

Signed-off-by: Bruno Victal <mirai@makinata.eu>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
7 months agoAdd HWCAP2_MOPS from Linux 6.5 to AArch64 bits/hwcap.h
Joseph Myers [Tue, 17 Oct 2023 13:13:27 +0000 (13:13 +0000)] 
Add HWCAP2_MOPS from Linux 6.5 to AArch64 bits/hwcap.h

Linux 6.5 adds a new AArch64 HWCAP2 value, HWCAP2_MOPS.  Add it to
glibc's bits/hwcap.h.

Tested with build-many-glibcs.py for aarch64-linux-gnu.

7 months agoAdd SCM_SECURITY, SCM_PIDFD to bits/socket.h
Joseph Myers [Mon, 16 Oct 2023 13:19:26 +0000 (13:19 +0000)] 
Add SCM_SECURITY, SCM_PIDFD to bits/socket.h

Linux 6.5 adds a constant SCM_PIDFD (recall that the non-uapi
linux/socket.h, where this constant is added, is in fact a header
providing many constants that are part of the kernel/userspace
interface).  This shows up that SCM_SECURITY, from the same set of
definitions and added in Linux 2.6.17, is also missing from glibc,
although glibc has the first two constants from this set, SCM_RIGHTS
and SCM_CREDENTIALS; add both missing constants to glibc.

Tested for x86_64.

7 months agoAdd AT_HANDLE_FID from Linux 6.5 to bits/fcntl-linux.h
Joseph Myers [Mon, 16 Oct 2023 13:18:51 +0000 (13:18 +0000)] 
Add AT_HANDLE_FID from Linux 6.5 to bits/fcntl-linux.h

Linux 6.5 adds a constant AT_HANDLE_FID; add it to glibc.  Because
this is a flag for the function name_to_handle_at declared in
bits/fcntl-linux.h, put the flag there rather than alongside other
AT_* flags in (OS-independent) fcntl.h.

Tested for x86_64.

7 months agoAvoid maybe-uninitialized warning in __kernel_rem_pio2
Andreas Schwab [Sun, 8 Oct 2023 16:23:30 +0000 (18:23 +0200)] 
Avoid maybe-uninitialized warning in __kernel_rem_pio2

With GCC 14 on 32-bit x86 the compiler emits a maybe-uninitialized
warning:

../sysdeps/ieee754/dbl-64/k_rem_pio2.c: In function '__kernel_rem_pio2':
../sysdeps/ieee754/dbl-64/k_rem_pio2.c:364:20: error: 'fq' may be used uninitialized [-Werror=maybe-uninitialized]
  364 |           y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
      |                  ~~^~~

This is similar to the warning that is suppressed in the other branch of
the switch.  Help the compiler knowing that the variable is always
initialized, which also makes the suppression obsolete.

7 months agoFix WAIT_FOR_DEBUGGER for container tests.
Stefan Liebler [Thu, 28 Sep 2023 10:50:40 +0000 (12:50 +0200)] 
Fix WAIT_FOR_DEBUGGER for container tests.

For container tests, gdb needs to set the sysroot to the corresponding
testroot.root directory.  The assumption was that PIDs < 3 means that
we are running within a container.

Starting with commit 2fe64148a81f0d78050c302f34a6853d21f7cae4
"Allow for unpriviledged nested containers", the default is to use
the PID namespace of the parent.  Thus support_test_main.c does not
recognize our container anymore.

This patch now assumes that we are running inside a container if
test-container.c has set PID_OUTSIDE_CONTAINER and always uses this
PID independent of having a new PID namespace or not.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
7 months agostdlib: fix grouping verification with multi-byte thousands separator (bug 30964)
Andreas Schwab [Wed, 11 Oct 2023 14:22:16 +0000 (16:22 +0200)] 
stdlib: fix grouping verification with multi-byte thousands separator (bug 30964)

The grouping verification only worked for a single-byte thousands
separator.  With a multi-byte separator it returned as if no separators
were present.  The actual parsing in str_to_mpn will then go wrong when
there are multiple adjacent multi-byte separators in the number.

8 months agobuild-many-glibcs: Check for required system tools
DJ Delorie [Thu, 21 Sep 2023 21:24:05 +0000 (17:24 -0400)] 
build-many-glibcs: Check for required system tools

Notes for future devs:

* Add tools as you find they're needed, with version 0,0
* Bump version when you find an old tool that doesn't work
* Don't add a version just because you know it works

Co-authored-by: Lukasz Majewski <lukma@denx.de>
Co-authored-by: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
8 months agox86: Prepare `strrchr-evex` and `strrchr-evex512` for AVX10
Noah Goldstein [Thu, 21 Sep 2023 14:38:37 +0000 (09:38 -0500)] 
x86: Prepare `strrchr-evex` and `strrchr-evex512` for AVX10

This commit refactors `strrchr-evex` and `strrchr-evex512` to use a
common implementation: `strrchr-evex-base.S`.

The motivation is `strrchr-evex` needed to be refactored to not use
64-bit masked registers in preperation for AVX10.

Once vec-width masked register combining was removed, the EVEX and
EVEX512 implementations can easily be implemented in the same file
without any major overhead.

The net result is performance improvements (measured on TGL) for both
`strrchr-evex` and `strrchr-evex512`. Although, note there are some
regressions in the test suite and it may be many of the cases that
make the total-geomean of improvement/regression across bench-strrchr
are cold. The point of the performance measurement is to show there
are no major regressions, but the primary motivation is preperation
for AVX10.

Benchmarks where taken on TGL:
https://www.intel.com/content/www/us/en/products/sku/213799/intel-core-i711850h-processor-24m-cache-up-to-4-80-ghz/specifications.html

EVEX geometric_mean(N=5) of all benchmarks New / Original   : 0.74
EVEX512 geometric_mean(N=5) of all benchmarks New / Original: 0.87

Full check passes on x86.

8 months agoaarch64: Optimise vecmath logs
Joe Ramsay [Wed, 4 Oct 2023 09:38:57 +0000 (10:38 +0100)] 
aarch64: Optimise vecmath logs

* Transpose table layout for improved memory access
* Use half-vector special comparisons for AdvSIMD
* Improve register use near special-case branches
  - Due to the presence of a function call, return value would get
    mov-d out of x0 in order to facilitate PCS. By moving the final
    computation after the branch this can be avoided

Also change SVE routines to use overloaded intrinsics for readability.

8 months agoaarch64: Cosmetic change in SVE exp routines
Joe Ramsay [Wed, 4 Oct 2023 09:40:04 +0000 (10:40 +0100)] 
aarch64: Cosmetic change in SVE exp routines

Use overloaded intrinsics for readability. Codegen does not
change, however while we're bringing the routines up-to-date with
recent improvements to other routines in AOR it is worth copying
this change over as well.

8 months agoaarch64: Optimize SVE cos & cosf
Joe Ramsay [Wed, 4 Oct 2023 09:37:50 +0000 (10:37 +0100)] 
aarch64: Optimize SVE cos & cosf

Saves a mov by ensuring return value does not need to be moved out of
the way before special-case branch. Also change to use overloaded
intrinsics.

8 months agoaarch64: Improve vecmath sin routines
Joe Ramsay [Thu, 5 Oct 2023 09:31:38 +0000 (10:31 +0100)] 
aarch64: Improve vecmath sin routines

* Update ULP comment reflecting a new observed max in [-pi/2, pi/2]
* Use the same polynomial in AdvSIMD and SVE, rather than FTRIG instructions
* Improve register use near special-case branch

Also use overloaded intrinsics for SVE.

8 months agonss: Get rid of alloca usage in makedb's write_output.
Joe Simmons-Talbott [Wed, 4 Oct 2023 18:18:02 +0000 (18:18 +0000)] 
nss: Get rid of alloca usage in makedb's write_output.

Replace alloca usage with a scratch_buffer.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
8 months agodebug: Add regression tests for BZ 30932
Adhemerval Zanella [Tue, 3 Oct 2023 18:09:36 +0000 (15:09 -0300)] 
debug: Add regression tests for BZ 30932

Checked on x86_64-linux-gnu.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 months agoFix FORTIFY_SOURCE false positive
Volker Weißmann [Tue, 3 Oct 2023 17:18:44 +0000 (19:18 +0200)] 
Fix FORTIFY_SOURCE false positive

When -D_FORTIFY_SOURCE=2 was given during compilation,
sprintf and similar functions will check if their
first argument is in read-only memory and exit with
*** %n in writable segment detected ***
otherwise. To check if the memory is read-only, glibc
reads frpm the file "/proc/self/maps". If opening this
file fails due to too many open files (EMFILE), glibc
will now ignore this error.

Fixes [BZ #30932]

Signed-off-by: Volker Weißmann <volker.weissmann@gmx.de>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 months agonss: Rearrange and sort Makefile variables
Arjun Shankar [Mon, 2 Oct 2023 12:55:14 +0000 (14:55 +0200)] 
nss: Rearrange and sort Makefile variables

Rearrange lists of routines, tests, etc. into one-per-line in
nss/Makefile and sort them using scripts/sort-makefile-lines.py.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 months agoinet: Rearrange and sort Makefile variables
Arjun Shankar [Mon, 2 Oct 2023 12:55:13 +0000 (14:55 +0200)] 
inet: Rearrange and sort Makefile variables

Rearrange lists of routines, tests, etc. into one-per-line in
inet/Makefile and sort them using scripts/sort-makefile-lines.py.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 months agoFix off-by-one OOB write in iconv/tst-iconv-mt
Szabolcs Nagy [Mon, 26 Sep 2022 14:38:19 +0000 (15:38 +0100)] 
Fix off-by-one OOB write in iconv/tst-iconv-mt

The iconv buffer sizes must not include the \0 string terminator.
And the output termination with *outbufpos = '\0' was OOB.

Consistently use non-null-terminated buffer sizes.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8 months agotunables: Terminate if end of input is reached (CVE-2023-4911)
Siddhesh Poyarekar [Tue, 19 Sep 2023 22:39:32 +0000 (18:39 -0400)] 
tunables: Terminate if end of input is reached (CVE-2023-4911)

The string parsing routine may end up writing beyond bounds of tunestr
if the input tunable string is malformed, of the form name=name=val.
This gets processed twice, first as name=name=val and next as name=val,
resulting in tunestr being name=name=val:name=val, thus overflowing
tunestr.

Terminate the parsing loop at the first instance itself so that tunestr
does not overflow.

This also fixes up tst-env-setuid-tunables to actually handle failures
correct and add new tests to validate the fix for this CVE.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
8 months agoPropagate GLIBC_TUNABLES in setxid binaries
Siddhesh Poyarekar [Tue, 19 Sep 2023 17:25:40 +0000 (13:25 -0400)] 
Propagate GLIBC_TUNABLES in setxid binaries

GLIBC_TUNABLES scrubbing happens earlier than envvar scrubbing and some
tunables are required to propagate past setxid boundary, like their
env_alias.  Rely on tunable scrubbing to clean out GLIBC_TUNABLES like
before, restoring behaviour in glibc 2.37 and earlier.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
8 months agoLinux: add ST_NOSYMFOLLOW
Kir Kolyshkin [Wed, 27 Sep 2023 22:37:12 +0000 (15:37 -0700)] 
Linux: add ST_NOSYMFOLLOW

Linux v5.10 added a mount option MS_NOSYMFOLLOW, which was added to
glibc in commit 0ca21427d950755b.

Add the corresponding statfs/statvfs flag bit, ST_NOSYMFOLLOW.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8 months agoresolve: Remove __res_context_query alloca usage
Adhemerval Zanella [Wed, 20 Sep 2023 10:16:07 +0000 (10:16 +0000)] 
resolve: Remove __res_context_query alloca usage

The bufsize on current Linux build is:

   size_t bufsize = (type == 439963904 ? 2 : 1) * (12 + 4 + 255 + 1);

So with upper bound as 544 (2 * (12 + 4 + 255 + 1)).  However, it might
increase to 2 * PACKETSIZE later with malloc.  The default scratch_buffer
should fullfill the most usual allocation requirement.

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Joe Simmons-Talbott <josimmon@redhat.com>
8 months agomips: dl-machine-reject-phdr: Get rid of alloca.
Joe Simmons-Talbott [Mon, 2 Oct 2023 12:55:27 +0000 (12:55 +0000)] 
mips: dl-machine-reject-phdr: Get rid of alloca.

Read directly into the mips_abiflags struct rather than reading the
entire segment and using alloca when the passed buffer is not big enough.

Checked with build-many-glibcs.py on mips-linux-gnu

Tested-by: Ying Huang <ying.huang@oss.cipunited.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8 months agox86: Add support for AVX10 preset and vec size in cpu-features
Noah Goldstein [Wed, 20 Sep 2023 20:44:50 +0000 (15:44 -0500)] 
x86: Add support for AVX10 preset and vec size in cpu-features

This commit add support for the new AVX10 cpu features:
https://cdrdv2-public.intel.com/784267/355989-intel-avx10-spec.pdf

We add checks for:
    - `AVX10`: Check if AVX10 is present.
    - `AVX10_{X,Y,Z}MM`: Check if a given vec class has AVX10 support.

`make check` passes and cpuid output was checked against GNR/DMR on an
emulator.

8 months agoresolv: Fix a comment typo in __resolv_conf_load
Arjun Shankar [Fri, 29 Sep 2023 09:35:03 +0000 (11:35 +0200)] 
resolv: Fix a comment typo in __resolv_conf_load

The file being referred to is host.conf, not hosts.conf.

8 months agoRemove unused -DRESOLVER getaddrinfo build flag
Arjun Shankar [Fri, 29 Sep 2023 09:13:19 +0000 (11:13 +0200)] 
Remove unused -DRESOLVER getaddrinfo build flag

getaddrinfo doesn't look for any RESOLVER defines for conditional
compilation.  Therefore, remove the unnecessary -DRESOLVER build flag in
getaddrinfo's CFLAGS.

Checked on x86_64 for code generation changes; none found.

8 months agoC2x scanf %wN, %wfN support
Joseph Myers [Thu, 28 Sep 2023 17:27:58 +0000 (17:27 +0000)] 
C2x scanf %wN, %wfN support

ISO C2x defines scanf length modifiers wN (for intN_t / int_leastN_t /
uintN_t / uint_leastN_t) and wfN (for int_fastN_t / uint_fastN_t).
Add support for those length modifiers, similar to the printf support
previously added.

Tested for x86_64 and x86.

8 months agotest-container: Use nftw instead of rm -rf
Adhemerval Zanella [Wed, 27 Sep 2023 19:20:13 +0000 (16:20 -0300)] 
test-container: Use nftw instead of rm -rf

If the binary to run is 'env', test-containers skips it and adds
any required environment variable on the process envs variables.
This simplifies the required code to spawn new process (no need
to build an env-like program).

However, this is an issue for recursive_remove if there is any
LD_PRELOAD, since test-container will not prepend the loader command
along with required paths.  If the required preloaded library can
not be loaded by the system glibc, the 'post-clean rsync' will
eventually fail.

One example is if system glibc does not support DT_RELR and the
built glibc does, the nss/tst-nss-gai-hv2-canonname test fails
with:

../scripts/evaluate-test.sh nss/tst-nss-gai-hv2-canonname $? false false
86_64-linux-gnu/nss/tst-nss-gai-hv2-canonname.test-result
rm: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_ABI_DT_RELR' not
found (required by x86_64-linux-gnu/malloc/libc_malloc_debug.so)

Instead trying to figure out the required loader arguments on how
to spawn the 'rm -rf', replace the command with a nftw call.

Checked on x86_64-linux-gnu.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
8 months agohurd: Drop REG_GSFS and REG_ESDS from x86_64's ucontext
Samuel Thibault [Wed, 27 Sep 2023 22:07:18 +0000 (00:07 +0200)] 
hurd: Drop REG_GSFS and REG_ESDS from x86_64's ucontext

These are useless on x86_64, and __NGREG was actually wrong with them.

8 months agoelf: Fix compile error with -DNDEBUG [BZ #18755]
Qingqing Li [Thu, 21 Sep 2023 12:11:36 +0000 (20:11 +0800)] 
elf: Fix compile error with -DNDEBUG [BZ #18755]

Compilation fails when building with -DNDEBUG after commit a3189f66a5f2fe86568286fa025fa153be04c6c0.
Here is the error:

dl-close.c: In function ‘_dl_close_worker’:
dl-close.c:140:22: error: unused variable ‘nloaded’ [-Werror=unused-variable]
  140 |   const unsigned int nloaded = ns->_ns_nloaded;

Add __attribute_maybe_unused__ for‘nloaded’to fix it.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8 months agoMIPS: Add relocation types
Ying Huang [Thu, 31 Aug 2023 03:22:48 +0000 (23:22 -0400)] 
MIPS: Add relocation types

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8 months agoMIPS: Add new section type SHT_MIPS_ABIFLAGS
Ying Huang [Thu, 31 Aug 2023 03:22:47 +0000 (23:22 -0400)] 
MIPS: Add new section type SHT_MIPS_ABIFLAGS

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8 months agoMIPS: Add ELF file header flags
Ying Huang [Thu, 31 Aug 2023 03:22:46 +0000 (23:22 -0400)] 
MIPS: Add ELF file header flags

Now binutils use some E_MIPS_* macros and EF_MIPS_* macros, it is
difficult to decide which style macro we should use when we want
to add new ELF file header flags.
IRIX used to use EF_MIPS_* macros and in elf/elf.h there also has
comments "The following are unofficial names and should not be used".
So we should use EF_MIPS_* to keep same style with the beginning.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8 months agofegetenv_and_set_rn now uses the builtins provided by GCC.
Manjunath Matti [Sat, 23 Sep 2023 15:49:51 +0000 (10:49 -0500)] 
fegetenv_and_set_rn now uses the builtins provided by GCC.

On powerpc, SET_RESTORE_ROUND uses inline assembly to optimize the
prologue get/save/set rounding mode operations for POWER9 and
later by using 'mffscrn' where possible, this was introduced by
commit f1c56cdff09f650ad721fae026eb6a3651631f3d.

GCC version 14 onwards supports builtins as __builtin_set_fpscr_rn
which now returns the FPSCR fields in a double. This feature is
available on Power9 when the __SET_FPSCR_RN_RETURNS_FPSCR__ macro
is defined.
GCC commit ef3bbc69d15707e4db6e2f198c621effb636cc26 adds
this feature.

Changes are done to use __builtin_set_fpscr_rn instead of mffscrn
or mffscrni in __fe_mffscrn(rn).

Suggested-by: Carl Love <cel@us.ibm.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8 months agoio: Do not implement fstat with fstatat
Adhemerval Zanella [Mon, 11 Sep 2023 13:25:48 +0000 (10:25 -0300)] 
io: Do not implement fstat with fstatat

AT_EMPTY_PATH is a requirement to implement fstat over fstatat,
however it does not prevent the kernel to read the path argument.
It is not an issue, but on x86-64 with SMAP-capable CPUs the kernel is
forced to perform expensive user memory access.  After that regular
lookup is performed which adds even more overhead.

Instead, issue the fstat syscall directly on LFS fstat implementation
(32 bit architectures will still continue to use statx, which is
required to have 64 bit time_t support).  it should be even a
small performance gain on non x86_64, since there is no need
to handle the path argument.

Checked on x86_64-linux-gnu.

8 months agolibio: Add nonnull attribute for most FILE * arguments in stdio.h
Xi Ruoyao [Mon, 25 Sep 2023 11:53:26 +0000 (19:53 +0800)] 
libio: Add nonnull attribute for most FILE * arguments in stdio.h

During the review of a GCC analyzer test case, we found most stdio
functions accepting a FILE * argument expect it to be nonnull and just
segfault when the argument is NULL.  Add nonnull attribute for them.

fflush and fflush_unlocked are well defined when __stream is NULL so
they are not touched.

For fputs, fgets, fread, fwrite, fprintf, vfprintf, and their unlocked
version, if __stream is empty but there is nothing to read or write,
they did not segfault.  But the standard disallow __stream to be empty
here, so nonnull attribute is also added for them.  Note that this may
blow up some old code already subtly broken.

Also add __nonnull for _chk variants and __fortify_function versions for
them.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 months agoAArch64: Remove -0.0 check from vector sin
Wilco Dijkstra [Tue, 19 Sep 2023 13:03:48 +0000 (14:03 +0100)] 
AArch64: Remove -0.0 check from vector sin

Remove the unnecessary extra checks for sin (-0.0) from vector sin/sinf,
improving performance.  Passes regress.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
8 months agoDocument CVE-2023-4806 and CVE-2023-5156 in NEWS
Siddhesh Poyarekar [Tue, 26 Sep 2023 11:38:07 +0000 (07:38 -0400)] 
Document CVE-2023-4806 and CVE-2023-5156 in NEWS

These are tracked in BZ #30884 and BZ #30843.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 months agoelf: Add dummy declaration of _dl_audit_objclose for !SHARED
Florian Weimer [Tue, 26 Sep 2023 09:40:12 +0000 (11:40 +0200)] 
elf: Add dummy declaration of _dl_audit_objclose for !SHARED

This allows us to avoid some #ifdef SHARED conditionals.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
8 months agoFix leak in getaddrinfo introduced by the fix for CVE-2023-4806 [BZ #30843]
Romain Geissler [Mon, 25 Sep 2023 00:21:51 +0000 (01:21 +0100)] 
Fix leak in getaddrinfo introduced by the fix for CVE-2023-4806 [BZ #30843]

This patch fixes a very recently added leak in getaddrinfo.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 months agoelf: dl-lookup: Remove unused alloca.h include
Joe Simmons-Talbott [Thu, 21 Sep 2023 14:08:20 +0000 (14:08 +0000)] 
elf: dl-lookup: Remove unused alloca.h include

8 months agoRemove unused localedata/th_TH.in
Mike FABIAN [Tue, 25 Jul 2023 14:00:28 +0000 (16:00 +0200)] 
Remove unused localedata/th_TH.in

8 months agoAdapt collation in th_TH locale to use the iso14651_t1_common file and sync the colla...
Mike FABIAN [Thu, 1 Jun 2023 15:02:44 +0000 (17:02 +0200)] 
Adapt collation in th_TH locale to use the iso14651_t1_common file and sync the collation with CLDR

I made it to agree as much as possible with the rules from CLDR (see:
https://github.com/unicode-org/cldr/blob/main/common/collation/th.xml).

It seems to be impossible to follow the CLDR rules

  &[before 1]๚<ฯ # should be "variable"

and

  &๛<ๆ # should be "variable"

exactly though. These ask for a primary difference in punctuation
characters whose primary weight should be "IGNORE". But using a
secondary differnence instead still sorts the test data correctly and
the previously used collation in th_TH used tertiary differences for
these characters.

There was old localedata/th_TH.in test data in TIS-620 encoding which
was not used (it was not in the localedata/Makefile). I converted this
to UTF-8 and moved it to localedata/th_TH.UTF-8.in and added it to
localedata/Makefile.

Using the existing collation rules in the th_TH locale did not sort that
test file completely correct, I think my new collation rules based on
iso14651_t1 are better.

8 months agoRevert "LoongArch: Add glibc.cpu.hwcap support."
caiyinyu [Thu, 21 Sep 2023 01:10:11 +0000 (09:10 +0800)] 
Revert "LoongArch: Add glibc.cpu.hwcap support."

This reverts commit a53451559dc9cce765ea5bcbb92c4007e058e92b.

8 months agoUpdate kernel version to 6.5 in header constant tests
Joseph Myers [Wed, 20 Sep 2023 13:36:46 +0000 (13:36 +0000)] 
Update kernel version to 6.5 in header constant tests

This patch updates the kernel version in the tests tst-mman-consts.py
and tst-pidfd-consts.py to 6.5.  (There are no new constants covered
by these tests in 6.5 that need any other header changes;
tst-mount-consts.py was updated separately along with a header
constant addition.)

Tested with build-many-glibcs.py.

8 months agoLoongArch: Add glibc.cpu.hwcap support.
caiyinyu [Fri, 15 Sep 2023 09:35:19 +0000 (17:35 +0800)] 
LoongArch: Add glibc.cpu.hwcap support.

Key Points:
1. On lasx & lsx platforms, We must use _dl_runtime_{profile, resolve}_{lsx, lasx}
   to save vector registers.
2. Via "tunables", users can choose str/mem_{lasx,lsx,unaligned} functions with
   `export GLIBC_TUNABLES=glibc.cpu.hwcaps=LASX,...`.
   Note: glibc.cpu.hwcaps doesn't affect _dl_runtime_{profile, resolve}_{lsx, lasx}
   selection.

Usage Notes:
1. Only valid inputs: LASX, LSX, UAL. Case-sensitive, comma-separated, no spaces.
2. Example: `export GLIBC_TUNABLES=glibc.cpu.hwcaps=LASX,UAL` turns on LASX & UAL.
   Unmentioned features turn off. With default ifunc: lasx > lsx > unaligned >
   aligned > generic, effect is: lasx > unaligned > aligned > generic; lsx off.
3. Incorrect GLIBC_TUNABLES settings will show error messages.
   For example: On lsx platforms, you cannot enable lasx features. If you do
   that, you will get error messages.
4. Valid input examples:
   - GLIBC_TUNABLES=glibc.cpu.hwcaps=LASX: lasx > aligned > generic.
   - GLIBC_TUNABLES=glibc.cpu.hwcaps=LSX,UAL: lsx > unaligned > aligned > generic.
   - GLIBC_TUNABLES=glibc.cpu.hwcaps=LASX,UAL,LASX,UAL,LSX,LASX,UAL: Repetitions
     allowed but not recommended. Results in: lasx > lsx > unaligned > aligned >
     generic.

8 months agomath: Add a no-mathvec flag for sin (-0.0)
Wilco Dijkstra [Tue, 15 Aug 2023 17:01:53 +0000 (18:01 +0100)] 
math: Add a no-mathvec flag for sin (-0.0)

Add support for a no-mathvec flag to gen-auto-libm-tests.c.
Update input test sin (-0.0) to be skipped in vector math libraries and
regenerate testcases.

Reviewed-By: Paul Zimmermann <Paul.Zimmermann@inria.fr>
8 months agoUpdate to Unicode 15.1.0 [BZ #30854]
Mike FABIAN [Thu, 14 Sep 2023 16:01:40 +0000 (18:01 +0200)] 
Update to Unicode 15.1.0 [BZ #30854]

Unicode 15.1.0 Support: Character encoding, character type info, and
transliteration tables are all updated to Unicode 15.1.0, using
the generator scripts contributed by Mike FABIAN (Red Hat).

    Total removed characters in newly generated CHARMAP: 0
    Total changed characters in newly generated CHARMAP: 0
    Total added characters in newly generated CHARMAP: 627
    Total removed characters in newly generated WIDTH: 0
    Total changed characters in newly generated WIDTH: 0
    Total added characters in newly generated WIDTH: 627

    alpha: Added 622 characters in new ctype which were not in old ctype
    graph: Added 627 characters in new ctype which were not in old ctype
    print: Added 627 characters in new ctype which were not in old ctype
    punct: Added 5 characters in new ctype which were not in old ctype
        The five characters added to punct are:
        2FFC;IDEOGRAPHIC DESCRIPTION CHARACTER SURROUND FROM RIGHT;So;0;ON;;;;;N;;;;;
        2FFD;IDEOGRAPHIC DESCRIPTION CHARACTER SURROUND FROM LOWER RIGHT;So;0;ON;;;;;N;;;;;
        2FFE;IDEOGRAPHIC DESCRIPTION CHARACTER HORIZONTAL REFLECTION;So;0;ON;;;;;N;;;;;
        2FFF;IDEOGRAPHIC DESCRIPTION CHARACTER ROTATION;So;0;ON;;;;;N;;;;;
        31EF;IDEOGRAPHIC DESCRIPTION CHARACTER SUBTRACTION;So;0;ON;;;;;N;;;;;

    The Unicode announcement blog entry says "[...] adds 627
    characters, [...] additions include 622 CJK unified ideographs in
    a new block, [...]", so that looks OK. The Unicode
    blog mentions "six completely new emoji" but they don't appear here as
    they are all sequences and not single code points.

Resolves: BZ #30854

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
8 months agolocaledata/unicode-gen/utf8_gen.py: adapt regexp to get relevant lines from EastAsian...
Mike FABIAN [Thu, 14 Sep 2023 17:18:00 +0000 (19:18 +0200)] 
localedata/unicode-gen/utf8_gen.py: adapt regexp to get relevant lines from EastAsianWidth.txt

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
8 months agoFix regexp syntax warnings in localedata/unicode-gen/ctype_compatibility.py
Mike FABIAN [Thu, 14 Sep 2023 16:20:57 +0000 (18:20 +0200)] 
Fix regexp syntax warnings in localedata/unicode-gen/ctype_compatibility.py

Fix these:

$ python -m py_compile ./ctype_compatibility.py
./ctype_compatibility.py:146: SyntaxWarning: invalid escape sequence '\)'

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
8 months agogetaddrinfo: Fix use after free in getcanonname (CVE-2023-4806)
Siddhesh Poyarekar [Fri, 15 Sep 2023 17:51:12 +0000 (13:51 -0400)] 
getaddrinfo: Fix use after free in getcanonname (CVE-2023-4806)

When an NSS plugin only implements the _gethostbyname2_r and
_getcanonname_r callbacks, getaddrinfo could use memory that was freed
during tmpbuf resizing, through h_name in a previous query response.

The backing store for res->at->name when doing a query with
gethostbyname3_r or gethostbyname2_r is tmpbuf, which is reallocated in
gethosts during the query.  For AF_INET6 lookup with AI_ALL |
AI_V4MAPPED, gethosts gets called twice, once for a v6 lookup and second
for a v4 lookup.  In this case, if the first call reallocates tmpbuf
enough number of times, resulting in a malloc, th->h_name (that
res->at->name refers to) ends up on a heap allocated storage in tmpbuf.
Now if the second call to gethosts also causes the plugin callback to
return NSS_STATUS_TRYAGAIN, tmpbuf will get freed, resulting in a UAF
reference in res->at->name.  This then gets dereferenced in the
getcanonname_r plugin call, resulting in the use after free.

Fix this by copying h_name over and freeing it at the end.  This
resolves BZ #30843, which is assigned CVE-2023-4806.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 months agoLoongArch: Change to put magic number to .rodata section
dengjianbo [Wed, 13 Sep 2023 07:35:01 +0000 (15:35 +0800)] 
LoongArch: Change to put magic number to .rodata section

Change to put magic number to .rodata section in memmove-lsx, and use
pcalau12i and %pc_lo12 with vld to get the data.

8 months agoLoongArch: Add ifunc support for strrchr{aligned, lsx, lasx}
dengjianbo [Wed, 13 Sep 2023 07:35:00 +0000 (15:35 +0800)] 
LoongArch: Add ifunc support for strrchr{aligned, lsx, lasx}

According to glibc strrchr microbenchmark test results, this implementation
could reduce the runtime time as following:

Name                Percent of rutime reduced
strrchr-lasx        10%-50%
strrchr-lsx         0%-50%
strrchr-aligned     5%-50%

Generic strrchr is implemented by function strlen + memrchr, the lasx version
will compare with generic strrchr implemented by strlen-lasx + memrchr-lasx,
the lsx version will compare with generic strrchr implemented by strlen-lsx +
memrchr-lsx, the aligned version will compare with generic strrchr implemented
by strlen-aligned + memrchr-generic.

8 months agoLoongArch: Add ifunc support for strcpy, stpcpy{aligned, unaligned, lsx, lasx}
dengjianbo [Wed, 13 Sep 2023 07:34:59 +0000 (15:34 +0800)] 
LoongArch: Add ifunc support for strcpy, stpcpy{aligned, unaligned, lsx, lasx}

According to glibc strcpy and stpcpy microbenchmark test results(changed
to use generic_strcpy and generic_stpcpy instead of strlen + memcpy),
comparing with the generic version, this implementation could reduce the
runtime as following:

Name              Percent of rutime reduced
strcpy-aligned    8%-45%
strcpy-unaligned  8%-48%, comparing with the aligned version, unaligned
                  version takes less instructions to copy the tail of data
  which length is less than 8. it also has better performance
  in case src and dest cannot be both aligned with 8bytes
strcpy-lsx        20%-80%
strcpy-lasx       15%-86%
stpcpy-aligned    6%-43%
stpcpy-unaligned  8%-48%
stpcpy-lsx        10%-80%
stpcpy-lasx       10%-87%

8 months agoLoongArch: Replace deprecated $v0 with $a0 to eliminate 'as' Warnings.
caiyinyu [Thu, 14 Sep 2023 11:48:24 +0000 (19:48 +0800)] 
LoongArch: Replace deprecated $v0 with $a0 to eliminate 'as' Warnings.

8 months agoLoongArch: Add lasx/lsx support for _dl_runtime_profile.
caiyinyu [Fri, 8 Sep 2023 06:10:55 +0000 (14:10 +0800)] 
LoongArch: Add lasx/lsx support for _dl_runtime_profile.

8 months agoAdd MOVE_MOUNT_BENEATH from Linux 6.5 to sys/mount.h
Joseph Myers [Thu, 14 Sep 2023 14:58:15 +0000 (14:58 +0000)] 
Add MOVE_MOUNT_BENEATH from Linux 6.5 to sys/mount.h

This patch adds the MOVE_MOUNT_BENEATH constant from Linux 6.5 to
glibc's sys/mount.h and updates tst-mount-consts.py to reflect these
constants being up to date with that Linux kernel version.

Tested with build-many-glibcs.py.

8 months agoCVE-2023-4527: Stack read overflow with large TCP responses in no-aaaa mode
Florian Weimer [Wed, 13 Sep 2023 12:10:56 +0000 (14:10 +0200)] 
CVE-2023-4527: Stack read overflow with large TCP responses in no-aaaa mode

Without passing alt_dns_packet_buffer, __res_context_search can only
store 2048 bytes (what fits into dns_packet_buffer).  However,
the function returns the total packet size, and the subsequent
DNS parsing code in _nss_dns_gethostbyname4_r reads beyond the end
of the stack-allocated buffer.

Fixes commit f282cdbe7f436c75864e5640a4 ("resolv: Implement no-aaaa
stub resolver option") and bug 30842.

8 months agoresolv: Fix some unaligned accesses in resolver [BZ #30750]
John David Anglin [Wed, 13 Sep 2023 11:04:41 +0000 (11:04 +0000)] 
resolv: Fix some unaligned accesses in resolver [BZ #30750]

Signed-off-by: John David Anglin <dave.anglin@bell.net>
8 months agoUpdate syscall lists for Linux 6.5
Joseph Myers [Tue, 12 Sep 2023 14:08:53 +0000 (14:08 +0000)] 
Update syscall lists for Linux 6.5

Linux 6.5 has one new syscall, cachestat, and also enables the
cacheflush syscall for hppa.  Update syscall-names.list and regenerate
the arch-syscall.h headers with build-many-glibcs.py update-syscalls.

Tested with build-many-glibcs.py.

8 months agoia64: Work around miscompilation and fix build on ia64's gcc-10 and later
Sergei Trofimovich [Sat, 11 Jul 2020 17:06:51 +0000 (20:06 +0300)] 
ia64: Work around miscompilation and fix build on ia64's gcc-10 and later

Needed since gcc-10 enabled -fno-common by default.

[In use in Gentoo since gcc-10, no problems observed.
Also discussed with and reviewed by Jessica Clarke from
Debian. Andreas]

Bug: https://bugs.gentoo.org/723268
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
8 months agostdio: Remove __libc_message alloca usage
Joe Simmons-Talbott [Mon, 11 Sep 2023 16:16:49 +0000 (16:16 +0000)] 
stdio: Remove __libc_message alloca usage

Use a fixed size array instead.  The maximum number of arguments
is set by macro tricks.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
9 months agohtl: avoid exposing the vm_region symbol
Samuel Thibault [Sat, 9 Sep 2023 08:06:59 +0000 (10:06 +0200)] 
htl: avoid exposing the vm_region symbol

9 months agolibio: Fix oversized __io_vtables
Adam Jackson [Fri, 8 Sep 2023 19:55:19 +0000 (15:55 -0400)] 
libio: Fix oversized __io_vtables

IO_VTABLES_LEN is the size of the struct array in bytes, not the number
of __IO_jump_t's in the array. Drops just under 384kb from .rodata on
LP64 machines.

Fixes: 3020f72618e ("libio: Remove the usage of __libc_IO_vtables")
Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Tested-by: Florian Weimer <fweimer@redhat.com>
9 months agoUse Linux 6.5 in build-many-glibcs.py
Joseph Myers [Fri, 8 Sep 2023 20:04:42 +0000 (20:04 +0000)] 
Use Linux 6.5 in build-many-glibcs.py

This patch makes build-many-glibcs.py use Linux 6.5.

Tested with build-many-glibcs.py (host-libraries, compilers and glibcs
builds).

9 months agoelf: Remove unused l_text_end field from struct link_map
Florian Weimer [Fri, 8 Sep 2023 11:02:06 +0000 (13:02 +0200)] 
elf: Remove unused l_text_end field from struct link_map

It is a left-over from commit 52a01100ad011293197637e42b5be1a479a2
("elf: Remove ad-hoc restrictions on dlopen callers [BZ #22787]").

When backporting commmit 6985865bc3ad5b23147ee73466583dd7fdf65892
("elf: Always call destructors in reverse constructor order
(bug 30785)"), we can move the l_init_called_next field to this
place, so that the internal GLIBC_PRIVATE ABI does not change.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
9 months agoelf: Always call destructors in reverse constructor order (bug 30785)
Florian Weimer [Fri, 8 Sep 2023 10:32:14 +0000 (12:32 +0200)] 
elf: Always call destructors in reverse constructor order (bug 30785)

The current implementation of dlclose (and process exit) re-sorts the
link maps before calling ELF destructors.  Destructor order is not the
reverse of the constructor order as a result: The second sort takes
relocation dependencies into account, and other differences can result
from ambiguous inputs, such as cycles.  (The force_first handling in
_dl_sort_maps is not effective for dlclose.)  After the changes in
this commit, there is still a required difference due to
dlopen/dlclose ordering by the application, but the previous
discrepancies went beyond that.

A new global (namespace-spanning) list of link maps,
_dl_init_called_list, is updated right before ELF constructors are
called from _dl_init.

In dl_close_worker, the maps variable, an on-stack variable length
array, is eliminated.  (VLAs are problematic, and dlclose should not
call malloc because it cannot readily deal with malloc failure.)
Marking still-used objects uses the namespace list directly, with
next and next_idx replacing the done_index variable.

After marking, _dl_init_called_list is used to call the destructors
of now-unused maps in reverse destructor order.  These destructors
can call dlopen.  Previously, new objects do not have l_map_used set.
This had to change: There is no copy of the link map list anymore,
so processing would cover newly opened (and unmarked) mappings,
unloading them.  Now, _dl_init (indirectly) sets l_map_used, too.
(dlclose is handled by the existing reentrancy guard.)

After _dl_init_called_list traversal, two more loops follow.  The
processing order changes to the original link map order in the
namespace.  Previously, dependency order was used.  The difference
should not matter because relocation dependencies could already
reorder link maps in the old code.

The changes to _dl_fini remove the sorting step and replace it with
a traversal of _dl_init_called_list.  The l_direct_opencount
decrement outside the loader lock is removed because it appears
incorrect: the counter manipulation could race with other dynamic
loader operations.

tst-audit23 needs adjustments to the changes in LA_ACT_DELETE
notifications.  The new approach for checking la_activity should
make it clearer that la_activty calls come in pairs around namespace
updates.

The dependency sorting test cases need updates because the destructor
order is always the opposite order of constructor order, even with
relocation dependencies or cycles present.

There is a future cleanup opportunity to remove the now-constant
force_first and for_fini arguments from the _dl_sort_maps function.

Fixes commit 1df71d32fe5f5905ffd5d100e5e9ca8ad62 ("elf: Implement
force_first handling in _dl_sort_maps_dfs (bug 28937)").

Reviewed-by: DJ Delorie <dj@redhat.com>
9 months agoio: Fix record locking contants for powerpc64 with __USE_FILE_OFFSET64
Aurelien Jarno [Mon, 28 Aug 2023 21:30:37 +0000 (23:30 +0200)] 
io: Fix record locking contants for powerpc64 with __USE_FILE_OFFSET64

Commit 5f828ff824e3b7cd1 ("io: Fix F_GETLK, F_SETLK, and F_SETLKW for
powerpc64") fixed an issue with the value of the lock constants on
powerpc64 when not using __USE_FILE_OFFSET64, but it ended-up also
changing the value when using __USE_FILE_OFFSET64 causing an API change.

Fix that by also checking that define, restoring the pre
4d0fe291aed3a476a commit values:

Default values:
- F_GETLK: 5
- F_SETLK: 6
- F_SETLKW: 7

With -D_FILE_OFFSET_BITS=64:
- F_GETLK: 12
- F_SETLK: 13
- F_SETLKW: 14

At the same time, it has been noticed that there was no test for io lock
with __USE_FILE_OFFSET64, so just add one.

Tested on x86_64-linux-gnu, i686-linux-gnu and
powerpc64le-unknown-linux-gnu.

Resolves: BZ #30804.
Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
9 months agomanual: Fix ld.so diagnostics menu/section structure
Florian Weimer [Wed, 6 Sep 2023 16:37:21 +0000 (18:37 +0200)] 
manual: Fix ld.so diagnostics menu/section structure

And shorten the section/node names a bit, so that the menu
entries become easier to read.

Texinfo 6.5 fails to process the previous structure:

./dynlink.texi:56: warning: node `Dynamic Linker Introspection' is
  next for `Dynamic Linker Diagnostics' in sectioning but not in menu
./dynlink.texi:56: warning: node up `Dynamic Linker Diagnostics'
  in menu `Dynamic Linker Invocation' and
  in sectioning `Dynamic Linker' differ
./dynlink.texi:1: node `Dynamic Linker' lacks menu item for
  `Dynamic Linker Diagnostics' despite being its Up target
./dynlink.texi:226: warning: node prev `Dynamic Linker Introspection' in menu `Dynamic Linker Invocation'
  and in sectioning `Dynamic Linker Diagnostics' differ

Texinfo 7.0.2 does not report an error.

This fixes commit f21962ddfc8bb23e92597da1f98e313dbde11cc1
("manual: Document ld.so --list-diagnostics output").

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
9 months agogetaddrinfo: Get rid of alloca
Joe Simmons-Talbott [Wed, 6 Sep 2023 13:32:46 +0000 (13:32 +0000)] 
getaddrinfo: Get rid of alloca

Use a scratch_buffer rather than alloca to avoid potential stack
overflow.

9 months agoriscv: Add support for XTheadBb in string-fz[a,i].h
Christoph Müllner [Wed, 23 Aug 2023 05:46:28 +0000 (07:46 +0200)] 
riscv: Add support for XTheadBb in string-fz[a,i].h

XTheadBb has similar instructions like Zbb, which allow optimized
string processing:
* th.ff0: find-first zero is a CLZ instruction.
* th.tstnbz: Similar like orc.b, but with a bit-inverted result.

The instructions are documented here:
  https://github.com/T-head-Semi/thead-extension-spec/tree/master/xtheadbb

These instructions can be found in the T-Head C906 and the C910.

Tested with the string tests.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
9 months agogetcanonname: Fix a typo
Siddhesh Poyarekar [Tue, 5 Sep 2023 21:04:05 +0000 (17:04 -0400)] 
getcanonname: Fix a typo

This code is generally unused in practice since there don't seem to be
any NSS modules that only implement _nss_MOD_gethostbyname2_r and not
_nss_MOD_gethostbyname3_r.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
9 months agolinux: Add pidfd_getpid
Adhemerval Zanella Netto [Thu, 24 Aug 2023 16:42:19 +0000 (13:42 -0300)] 
linux: Add pidfd_getpid

This interface allows to obtain the associated process ID from the
process file descriptor.  It is done by parsing the procps fdinfo
information.  Its prototype is:

   pid_t pidfd_getpid (int fd)

It returns the associated pid or -1 in case of an error and sets the
errno accordingly.  The possible errno values are those from open, read,
and close (used on procps parsing), along with:

   - EBADF if the FD is negative, does not have a PID associated, or if
     the fdinfo fields contain a value larger than pid_t.

   - EREMOTE if the PID is in a separate namespace.

   - ESRCH if the process is already terminated.

Checked on x86_64-linux-gnu on Linux 4.15 (no CLONE_PIDFD or waitid
support), Linux 5.4 (full support), and Linux 6.2.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
9 months agoposix: Add pidfd_spawn and pidfd_spawnp (BZ 30349)
Adhemerval Zanella Netto [Thu, 24 Aug 2023 16:42:18 +0000 (13:42 -0300)] 
posix: Add pidfd_spawn and pidfd_spawnp (BZ 30349)

Returning a pidfd allows a process to keep a race-free handle for a
child process, otherwise, the caller will need to either use pidfd_open
(which still might be subject to TOCTOU) or keep the old racy interface
base on pid_t.

To correct use pifd_spawn, the kernel must support not only returning
the pidfd with clone/clone3 but also waitid (P_PIDFD) (added on Linux
5.4).  If kernel does not support the waitid, pidfd return ENOSYS.
It avoids the need to racy workarounds, such as reading the procfs
fdinfo to get the pid to use along with other wait interfaces.

These interfaces are similar to the posix_spawn and posix_spawnp, with
the only difference being it returns a process file descriptor (int)
instead of a process ID (pid_t).  Their prototypes are:

  int pidfd_spawn (int *restrict pidfd,
                   const char *restrict file,
                   const posix_spawn_file_actions_t *restrict facts,
                   const posix_spawnattr_t *restrict attrp,
                   char *const argv[restrict],
                   char *const envp[restrict])

  int pidfd_spawnp (int *restrict pidfd,
                    const char *restrict path,
                    const posix_spawn_file_actions_t *restrict facts,
                    const posix_spawnattr_t *restrict attrp,
                    char *const argv[restrict_arr],
                    char *const envp[restrict_arr]);

A new symbol is used instead of a posix_spawn extension to avoid
possible issues with language bindings that might track the return
argument lifetime.  Although on Linux pid_t and int are interchangeable,
POSIX only states that pid_t should be a signed integer.

Both symbols reuse the posix_spawn posix_spawn_file_actions_t and
posix_spawnattr_t, to void rehash posix_spawn API or add a new one. It
also means that both interfaces support the same attribute and file
actions, and a new flag or file action on posix_spawn is also added
automatically for pidfd_spawn.

Also, using posix_spawn plumbing allows the reusing of most of the
current testing with some changes:

  - waitid is used instead of waitpid since it is a more generic
    interface.

  - tst-posix_spawn-setsid.c is adapted to take into consideration that
    the caller can check for session id directly.  The test now spawns
itself and writes the session id as a file instead.

  - tst-spawn3.c need to know where pidfd_spawn is used so it keeps an
    extra file description unused.

Checked on x86_64-linux-gnu on Linux 4.15 (no CLONE_PIDFD or waitid
support), Linux 5.4 (full support), and Linux 6.2.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
9 months agolinux: Add posix_spawnattr_{get, set}cgroup_np (BZ 26371)
Adhemerval Zanella Netto [Thu, 24 Aug 2023 16:42:17 +0000 (13:42 -0300)] 
linux: Add posix_spawnattr_{get, set}cgroup_np (BZ 26371)

These functions allow to posix_spawn and posix_spawnp to use
CLONE_INTO_CGROUP with clone3, allowing the child process to
be created in a different cgroup version 2.  These are GNU
extensions that are available only for Linux, and also only
for the architectures that implement clone3 wrapper
(HAVE_CLONE3_WRAPPER).

To create a process on a different cgroupv2, one can use the:

  posix_spawnattr_t attr;
  posix_spawnattr_init (&attr);
  posix_spawnattr_setflags (&attr, POSIX_SPAWN_SETCGROUP);
  posix_spawnattr_setcgroup_np (&attr, cgroup);
  posix_spawn (...)

Similar to other posix_spawn flags, POSIX_SPAWN_SETCGROUP control
whether the cgroup file descriptor will be used or not with
clone3.

There is no fallback if either clone3 does not support the flag
or if the architecture does not provide the clone3 wrapper, in
this case posix_spawn returns EOPNOTSUPP.

Checked on x86_64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
9 months agolinux: Define __ASSUME_CLONE3 to 0 for alpha, ia64, nios2, sh, and sparc
Adhemerval Zanella Netto [Thu, 24 Aug 2023 16:42:16 +0000 (13:42 -0300)] 
linux: Define __ASSUME_CLONE3 to 0 for alpha, ia64, nios2, sh, and sparc

Not all architectures added clone3 syscall.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
9 months agomips: Add the clone3 wrapper
Adhemerval Zanella Netto [Thu, 24 Aug 2023 16:42:15 +0000 (13:42 -0300)] 
mips: Add the clone3 wrapper

It follows the internal signature:

extern int clone3 (struct clone_args *__cl_args, size_t __size,
                   int (*__func) (void *__arg), void *__arg);

Checked on mips64el-linux-gnueabihf, mips64el-n32-linux-gnu, and
mipsel-linux-gnu.

9 months agoarm: Add the clone3 wrapper
Adhemerval Zanella Netto [Thu, 24 Aug 2023 16:42:14 +0000 (13:42 -0300)] 
arm: Add the clone3 wrapper

It follows the internal signature:

  extern int clone3 (struct clone_args *__cl_args, size_t __size,
    int (*__func) (void *__arg), void *__arg);

Checked on arm-linux-gnueabihf.

9 months agohurd: Avoid including thread_state.h in installed header
Samuel Thibault [Tue, 5 Sep 2023 09:58:26 +0000 (11:58 +0200)] 
hurd: Avoid including thread_state.h in installed header

thread_state.h is not actually installed. It was only needed for
struct machine_thread_all_state, which we can just declare, actually.

9 months ago__call_tls_dtors: Use call_function_static_weak
Samuel Thibault [Mon, 4 Sep 2023 18:03:37 +0000 (20:03 +0200)] 
__call_tls_dtors: Use call_function_static_weak

9 months agointl: Treat C.UTF-8 locale like C locale (BZ# 16621)
Bruno Haible [Mon, 4 Sep 2023 13:31:36 +0000 (15:31 +0200)] 
intl: Treat C.UTF-8 locale like C locale (BZ# 16621)

The wiki page https://sourceware.org/glibc/wiki/Proposals/C.UTF-8
says that "Setting LC_ALL=C.UTF-8 will ignore LANGUAGE just like it
does with LC_ALL=C." This patch implements it.

* intl/dcigettext.c (guess_category_value): Treat C.<encoding> locale
like the C locale.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
9 months agohtl: Fix stack information for main thread
Samuel Thibault [Sun, 3 Sep 2023 19:11:09 +0000 (21:11 +0200)] 
htl: Fix stack information for main thread

We can easily directly ask the kernel with vm_region rather than
assuming a one-page stack.

9 months agohtl: thread_local destructors support
Samuel Thibault [Sun, 3 Sep 2023 13:23:56 +0000 (15:23 +0200)] 
htl: thread_local destructors support

9 months agoelf: Fix slow tls access after dlopen [BZ #19924]
Szabolcs Nagy [Tue, 16 Feb 2021 12:55:13 +0000 (12:55 +0000)] 
elf: Fix slow tls access after dlopen [BZ #19924]

In short: __tls_get_addr checks the global generation counter and if
the current dtv is older then _dl_update_slotinfo updates dtv up to the
generation of the accessed module. So if the global generation is newer
than generation of the module then __tls_get_addr keeps hitting the
slow dtv update path. The dtv update path includes a number of checks
to see if any update is needed and this already causes measurable tls
access slow down after dlopen.

It may be possible to detect up-to-date dtv faster.  But if there are
many modules loaded (> TLS_SLOTINFO_SURPLUS) then this requires at
least walking the slotinfo list.

This patch tries to update the dtv to the global generation instead, so
after a dlopen the tls access slow path is only hit once.  The modules
with larger generation than the accessed one were not necessarily
synchronized before, so additional synchronization is needed.

This patch uses acquire/release synchronization when accessing the
generation counter.

Note: in the x86_64 version of dl-tls.c the generation is only loaded
once, since relaxed mo is not faster than acquire mo load.

I have not benchmarked this. Tested by Adhemerval Zanella on aarch64,
powerpc, sparc, x86 who reported that it fixes the performance issue
of bug 19924.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
9 months agox86: Check the lower byte of EAX of CPUID leaf 2 [BZ #30643]
H.J. Lu [Mon, 28 Aug 2023 19:08:14 +0000 (12:08 -0700)] 
x86: Check the lower byte of EAX of CPUID leaf 2 [BZ #30643]

The old Intel software developer manual specified that the low byte of
EAX of CPUID leaf 2 returned 1 which indicated the number of rounds of
CPUDID leaf 2 was needed to retrieve the complete cache information. The
newer Intel manual has been changed to that it should always return 1
and be ignored.  If the lower byte isn't 1, CPUID leaf 2 can't be used.
In this case, we ignore CPUID leaf 2 and use CPUID leaf 4 instead.  If
CPUID leaf 4 doesn't contain the cache information, cache information
isn't available at all.  This addresses BZ #30643.

9 months agoadd GB18030-2022 charmap and test the entire GB18030 charmap [BZ #30243]
lijianglin [Tue, 27 Jun 2023 12:15:49 +0000 (20:15 +0800)] 
add GB18030-2022 charmap and test the entire GB18030 charmap [BZ #30243]

support GB18030-2022 after add and change some transcoding relationship
of GB18030-2022.Details are as follows:
add 25 transcoding relationship
  UE81E 0x82359037
  UE826 0x82359038
  UE82B 0x82359039
  UE82C 0x82359130
  UE832 0x82359131
  UE843 0x82359132
  UE854 0x82359133
  UE864 0x82359134
  UE78D 0x84318236
  UE78F 0x84318237
  UE78E 0x84318238
  UE790 0x84318239
  UE791 0x84318330
  UE792 0x84318331
  UE793 0x84318332
  UE794 0x84318333
  UE795 0x84318334
  UE796 0x84318335
  UE816 0xfe51
  UE817 0xfe52
  UE818 0xfe53
  UE831 0xfe6c
  UE83B 0xfe76
  UE855 0xfe91
change 6 transcoding relationship
  U20087 0x95329031
  U20089 0x95329033
  U200CC 0x95329730
  U215D7 0x9536b937
  U2298F 0x9630ba35
  U241FE 0x9635b630
Test the entire GB18030 charmap, not only the Unicode BMP part.

Co-authored-by: yangyanchao <yangyanchao6@huawei.com>
Co-authored-by: liqingqing <liqingqing3@huawei.com>
Co-authored-by: Bruno Haible <bruno@clisp.org>
Reviewed-by: Andreas Schwab <schwab@suse.de>
Reviewed-by: Mike FABIAN <mfabian@redhat.com>
9 months agoUse GMP 6.3.0, MPFR 4.2.1 in build-many-glibcs.py
Joseph Myers [Tue, 29 Aug 2023 14:11:35 +0000 (14:11 +0000)] 
Use GMP 6.3.0, MPFR 4.2.1 in build-many-glibcs.py

This patch makes build-many-glibcs.py use the new GMP 6.3.0 and MPFR
4.2.1 releases.

Tested with build-many-glibcs.py (host-libraries, compilers and glibcs
builds).

9 months agolocaledata: Translit common emojis to smileys [BZ #30649]
Colin Leroy-Mira [Tue, 29 Aug 2023 06:02:50 +0000 (08:02 +0200)] 
localedata: Translit common emojis to smileys [BZ #30649]

Add common emojis to the translit-able characters (mostly
faces and hearts), and translit them to old-fashioned
smileys.

Signed-off-by: Colin Leroy-Mira <colin@colino.net>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
9 months agonscd: Skip unusable entries in first pass in prune_cache (bug 30800)
Florian Weimer [Tue, 29 Aug 2023 06:28:31 +0000 (08:28 +0200)] 
nscd: Skip unusable entries in first pass in prune_cache (bug 30800)

Previously, if an entry was marked unusable for any reason, but had
not timed out yet, the assert would trigger.

One way to get into such state is if a data change is detected during
re-validation of an entry.  This causes the entry to be marked as not
usable.  If exits nscd soon after that, then the clock jumps
backwards, and nscd restarted, the cache re-validation run after
startup triggers the removed assert.

The change is more complicated than just the removal of the assert
because entries marked as not usable should be garbage-collected in
the second pass.  To make this happen, it is necessary to update some
book-keeping data.

Reviewed-by: DJ Delorie <dj@redhat.com>
9 months agoLoongArch: Change loongarch to LoongArch in comments
dengjianbo [Mon, 28 Aug 2023 02:08:40 +0000 (10:08 +0800)] 
LoongArch: Change loongarch to LoongArch in comments

9 months agoLoongArch: Add ifunc support for memcmp{aligned, lsx, lasx}
dengjianbo [Mon, 28 Aug 2023 02:08:39 +0000 (10:08 +0800)] 
LoongArch: Add ifunc support for memcmp{aligned, lsx, lasx}

According to glibc memcmp microbenchmark test results(Add generic
memcmp), this implementation have performance improvement
except the length is less than 3, details as below:

Name             Percent of time reduced
memcmp-lasx      16%-74%
memcmp-lsx       20%-50%
memcmp-aligned   5%-20%

9 months agoLoongArch: Add ifunc support for memset{aligned, unaligned, lsx, lasx}
dengjianbo [Mon, 28 Aug 2023 02:08:38 +0000 (10:08 +0800)] 
LoongArch: Add ifunc support for memset{aligned, unaligned, lsx, lasx}

According to glibc memset microbenchmark test results, for LSX and LASX
versions, A few cases with length less than 8 experience performace
degradation, overall, the LASX version could reduce the runtime about
15% - 75%, LSX version could reduce the runtime about 15%-50%.

The unaligned version uses unaligned memmory access to set data which
length is less than 64 and make address aligned with 8. For this part,
the performace is better than aligned version. Comparing with the generic
version, the performance is close when the length is larger than 128. When
the length is 8-128, the unaligned version could reduce the runtime about
30%-70%, the aligned version could reduce the runtime about 20%-50%.

9 months agoLoongArch: Add ifunc support for memrchr{lsx, lasx}
dengjianbo [Mon, 28 Aug 2023 02:08:37 +0000 (10:08 +0800)] 
LoongArch: Add ifunc support for memrchr{lsx, lasx}

According to glibc memrchr microbenchmark, this implementation could reduce
the runtime as following:

Name            Percent of rutime reduced
memrchr-lasx    20%-83%
memrchr-lsx     20%-64%

9 months agoLoongArch: Add ifunc support for memchr{aligned, lsx, lasx}
dengjianbo [Mon, 28 Aug 2023 02:08:36 +0000 (10:08 +0800)] 
LoongArch: Add ifunc support for memchr{aligned, lsx, lasx}

According to glibc memchr microbenchmark, this implementation could reduce
the runtime as following:

Name               Percent of runtime reduced
memchr-lasx        37%-83%
memchr-lsx         30%-66%
memchr-aligned     0%-15%

9 months agoLoongArch: Add ifunc support for rawmemchr{aligned, lsx, lasx}
dengjianbo [Mon, 28 Aug 2023 02:08:35 +0000 (10:08 +0800)] 
LoongArch: Add ifunc support for rawmemchr{aligned, lsx, lasx}

According to glibc rawmemchr microbenchmark, A few cases tested with
char '\0' experience performance degradation due to the lasx and lsx
versions don't handle the '\0' separately. Overall, rawmemchr-lasx
implementation could reduce the runtime about 40%-80%, rawmemchr-lsx
implementation could reduce the runtime about 40%-66%, rawmemchr-aligned
implementation could reduce the runtime about 20%-40%.