glibc.git
18 hours agobuild-many-glibcs.py: Add openrisc hard float glibc variantmaster
Stafford Horne [Sat, 8 Jan 2022 06:35:24 +0000 (8 15:35 +0900)]
build-many-glibcs.py: Add openrisc hard float glibc variant

This adds the OpenRISC hard float glibc variant to the build many
script.  We update the compiler for glibc to support hard-float
multilibs to allow us to use a single generic compiler for all glibc
variants, this requires updating the compiler name.

Tested and all builds are passing.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 hours agoor1k: Add hard float support
Stafford Horne [Sat, 27 Apr 2024 05:35:09 +0000 (27 06:35 +0100)]
or1k: Add hard float support

This patch adds hardware floating point support to OpenRISC.  Hardware
floating point toolchain builds are enabled by passing the machine
specific argument -mhard-float to gcc via CFLAGS.  With this enabled GCC
generates floating point instructions for single-precision operations
and exports __or1k_hard_float__.

There are 2 main parts to this patch.

 - Implement fenv functions to update the FPCSR flags keeping it in sync
   with sfp (software floating point).
 - Update machine context functions to store and restore the FPCSR
   state.

*On mcontext_t ABI*

This patch adds __fpcsr to mcontext_t.  This is an ABI change, but also
an ABI fix.  The Linux kernel has always defined padding in mcontext_t
that space was missing from the glibc ABI.  In Linux this unused space
has now been re-purposed for storing the FPCSR.  This patch brings
OpenRISC glibc in line with the Linux kernel and other libc
implementation (musl).

Compatibility getcontext, setcontext, etc symbols have been added to
allow for binaries expecting the old ABI to continue to work.

*Hard float ABI*

The calling conventions and types do not change with OpenRISC hard-float
so glibc hard-float builds continue to use dynamic linker
/lib/ld-linux-or1k.so.1.

*Testing*

I have tested this patch both with hard-float and soft-float builds and
the test results look fine to me.  Results are as follows:

Hard Float

    # failures
    FAIL: elf/tst-sprof-basic (Haven't figured out yet, not related to hard-float)
    FAIL: gmon/tst-gmon-pie (PIE bug in or1k toolchain)
    FAIL: gmon/tst-gmon-pie-gprof (PIE bug in or1k toolchain)
    FAIL: iconvdata/iconv-test (timeout, passed when run manually)
    FAIL: nptl/tst-cond24 (Timeout)
    FAIL: nptl/tst-mutex10 (Timeout)

    # summary
  6 FAIL
       4289 PASS
 86 UNSUPPORTED
 16 XFAIL
  2 XPASS

    # versions
    Toolchain: or1k-smhfpu-linux-gnu
    Compiler:  gcc version 14.0.1 20240324 (experimental) [master r14-9649-gbb04a11418f] (GCC)
    Binutils:  GNU assembler version 2.42.0 (or1k-smhfpu-linux-gnu) using BFD version (GNU Binutils) 2.42.0.20240324
    Linux:     Linux buildroot 6.9.0-rc1-00008-g4dc70e1aadfa #112 SMP Sat Apr 27 06:43:11 BST 2024 openrisc GNU/Linux
    Tester:    shorne
    Glibc:     2024-04-25 b62928f907 Florian Weimer   x86: In ld.so, diagnose missing APX support in APX-only builds  (origin/master, origin/HEAD)

Soft Float

    # failures
    FAIL: elf/tst-sprof-basic
    FAIL: gmon/tst-gmon-pie
    FAIL: gmon/tst-gmon-pie-gprof
    FAIL: nptl/tst-cond24
    FAIL: nptl/tst-mutex10

    # summary
  5 FAIL
       4295 PASS
 81 UNSUPPORTED
 16 XFAIL
  2 XPASS

    # versions
    Toolchain: or1k-smh-linux-gnu
    Compiler:  gcc version 14.0.1 20240324 (experimental) [master r14-9649-gbb04a11418f] (GCC)
    Binutils:  GNU assembler version 2.42.0 (or1k-smh-linux-gnu) using BFD version (GNU Binutils) 2.42.0.20240324
    Linux:     Linux buildroot 6.9.0-rc1-00008-g4dc70e1aadfa #112 SMP Sat Apr 27 06:43:11 BST 2024 openrisc GNU/Linux
    Tester:    shorne
    Glibc:     2024-04-25 b62928f907 Florian Weimer   x86: In ld.so, diagnose missing APX support in APX-only builds  (origin/master, origin/HEAD)

Documentation: https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.4-rev0.pdf
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 hours agoor1k: Add hard float libm-test-ulps
Stafford Horne [Sat, 27 Apr 2024 05:32:59 +0000 (27 06:32 +0100)]
or1k: Add hard float libm-test-ulps

This patch adds the ulps test file to prepare for the upcoming
hard float patch.  This is separated out to make the hard float patch
smaller.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
43 hours agonscd: Use time_t for return type of addgetnetgrentX
Florian Weimer [Thu, 2 May 2024 15:06:19 +0000 (2 17:06 +0200)]
nscd: Use time_t for return type of addgetnetgrentX

Using int may give false results for future dates (timeouts after the
year 2028).

Fixes commit 04a21e050d64a1193a6daab872bca2528bda44b ("CVE-2024-33601,
CVE-2024-33602: nscd: netgroup: Use two buffers in addgetnetgrentX
(bug 31680)").

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 days agoAdd a test to check for duplicate definitions in the static library
Gabi Falk [Tue, 30 Apr 2024 20:05:04 +0000 (30 20:05 +0000)]
Add a test to check for duplicate definitions in the static library

This change follows two previous fixes addressing multiple definitions
of __memcpy_chk and __mempcpy_chk functions on i586, and __memmove_chk
and __memset_chk functions on i686.  The test is intended to prevent
such issues from occurring in the future.

Signed-off-by: Gabi Falk <gabifalk@gmx.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
2 days agoi686: Fix multiple definitions of __memmove_chk and __memset_chk
Gabi Falk [Tue, 30 Apr 2024 20:05:03 +0000 (30 20:05 +0000)]
i686: Fix multiple definitions of __memmove_chk and __memset_chk

Commit c73c96a4a1af1326df7f96eec58209e1e04066d8 updated memcpy.S and
mempcpy.S, but omitted memmove.S and memset.S.  As a result, the static
library built as PIC, whether with or without multiarch support,
contains two definitions for each of the __memmove_chk and __memset_chk
symbols.

/usr/lib/gcc/i686-pc-linux-gnu/14/../../../../i686-pc-linux-gnu/bin/ld: /usr/lib/gcc/i686-pc-linux-gnu/14/../../../../lib/libc.a(memset-ia32.o): in function `__memset_chk':
/var/tmp/portage/sys-libs/glibc-2.39-r3/work/glibc-2.39/string/../sysdeps/i386/i686/memset.S:32: multiple definition of `__memset_chk'; /usr/lib/gcc/i686-pc-linux-gnu/14/../../../../lib/libc.a(memset_chk.o):/var/tmp/portage/sys-libs/glibc-2.39-r3/work/glibc-2.39/debug/../sysdeps/i386/i686/multiarch/memset_chk.c:24: first defined here

After this change, regardless of PIC options, the static library, built
for i686 with multiarch contains implementations of these functions
respectively from debug/memmove_chk.c and debug/memset_chk.c, and
without multiarch contains implementations of these functions
respectively from sysdeps/i386/memmove_chk.S and
sysdeps/i386/memset_chk.S.  This ensures that memmove and memset won't
pull in __chk_fail and the routines it calls.

Reported-by: Sam James <sam@gentoo.org>
Tested-by: Sam James <sam@gentoo.org>
Fixes: c73c96a4a1 ("i686: Fix build with --disable-multiarch")
Signed-off-by: Gabi Falk <gabifalk@gmx.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
2 days agoi586: Fix multiple definitions of __memcpy_chk and __mempcpy_chk
Gabi Falk [Tue, 30 Apr 2024 20:05:02 +0000 (30 20:05 +0000)]
i586: Fix multiple definitions of __memcpy_chk and __mempcpy_chk

/home/bmg/install/compilers/x86_64-linux-gnu/lib/gcc/x86_64-glibc-linux-gnu/13.2.1/../../../../x86_64-glibc-linux-gnu/bin/ld: /home/bmg/build/glibcs/i586-linux-gnu/glibc/libc.a(memcpy_chk.o): in function `__memcpy_chk':
/home/bmg/src/glibc/debug/../sysdeps/i386/memcpy_chk.S:29: multiple definition of `__memcpy_chk';/home/bmg/build/glibcs/i586-linux-gnu/glibc/libc.a(memcpy.o):/home/bmg/src/glibc/string/../sysdeps/i386/i586/memcpy.S:31: first defined here /home/bmg/install/compilers/x86_64-linux-gnu/lib/gcc/x86_64-glibc-linux-gnu/13.2.1/../../../../x86_64-glibc-linux-gnu/bin/ld: /home/bmg/build/glibcs/i586-linux-gnu/glibc/libc.a(mempcpy_chk.o): in function `__mempcpy_chk': /home/bmg/src/glibc/debug/../sysdeps/i386/mempcpy_chk.S:28: multiple definition of `__mempcpy_chk'; /home/bmg/build/glibcs/i586-linux-gnu/glibc/libc.a(mempcpy.o):/home/bmg/src/glibc/string/../sysdeps/i386/i586/memcpy.S:31: first defined here

After this change, the static library built for i586, regardless of PIC
options, contains implementations of these functions respectively from
sysdeps/i386/memcpy_chk.S and sysdeps/i386/mempcpy_chk.S.  This ensures
that memcpy and mempcpy won't pull in __chk_fail and the routines it
calls.

Reported-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Gabi Falk <gabifalk@gmx.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
2 days agonscd: Typo inside comment in netgroup cache
Florian Weimer [Tue, 30 Apr 2024 10:31:37 +0000 (30 12:31 +0200)]
nscd: Typo inside comment in netgroup cache

Reported-by: Jonathan Wakely <jwakely@redhat.com>
2 days agotime: Allow later version licensing.
Carlos O'Donell [Tue, 23 Apr 2024 17:30:37 +0000 (23 13:30 -0400)]
time: Allow later version licensing.

The FSF's Licensing and Compliance Lab noted a discrepancy in the
licensing of several files in the glibc package.

When timespect_get.c was impelemented the license did not include
the standard ", or (at your option) any later version." text.

Change the license in timespec_get.c and all copied files to match
the expected license.

This change was previously approved in principle by the FSF in
RT ticket #1316403. And a similar instance was fixed in
commit 46703efa02f6ddebce5ee54c92f7c32598de0de6.

3 days agohurd: Stop mapping AT_NO_AUTOMOUNT to O_NOTRANS
Sergey Bugaev [Mon, 6 Nov 2023 13:50:51 +0000 (6 16:50 +0300)]
hurd: Stop mapping AT_NO_AUTOMOUNT to O_NOTRANS

While AT_NO_AUTOMOUNT is similar in function to the Hurd's O_NOTRANS,
there are significant enough differences in semantics:

1. AT_NO_AUTOMOUNT has no effect on already established mounts,
   whereas O_NOTRANS causes the lookup to ignore both passive and active
   translators. A better approximation of the AT_NO_AUTOMOUNT behavior
   would be to honor active translators, but avoid starting passive
   ones; like what the file_name_lookup_carefully () routine from
   sutils/clookup.c in the Hurd source tree does.

2. On GNU/Hurd, translators are used much more pervasively than mounts
   on "traditional" Unix systems: among other things, translators
   underlie features like symlinks, device nodes, and sockets. And while
   on a "traditional" Unix system, the mountpoint and the root of the
   mounted tree may look similar enough for many purposes (they're both
   directories, for one thing), the Hurd allows for any combination of
   the two node types, and indeed it is common to have e.g. a device
   node "mounted" on top of a regular file node on the underlying
   filesystem. Ignoring the translator and stat'ing the underlying node
   is therefore likely to return very different results from what you'd
   get if you stat the translator's root node.

In practice, mapping AT_NO_AUTOMOUNT to O_NOTRANS was breaking GNU
Coreutils, including stat(1) and ls(1):

$ stat /dev/hd0s1
  File: /dev/hd0s1
  Size: 0       Blocks: 8          IO Block: 8192   regular empty file
Device: 0,8     Inode: 32866       Links: 1

This was also breaking GNOME's glib, where a g_local_file_stat () call
that is supposed to stat () a file through a symlink uses
AT_NO_AUTOMOUNT, which gets mapped to O_NOTRANS, which then causes the
stat () call to stat symlink itself like lstat () would, rather then the
file it points to, which is what the logic expects to happen.

This reverts most of 13710e7e6af6c8965cc9a63a0660cb4ce1966557
"hurd: Add support for AT_NO_AUTOMOUNT".

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
3 days agolibio: Sort test variables in Makefile
H.J. Lu [Tue, 30 Apr 2024 16:21:16 +0000 (30 09:21 -0700)]
libio: Sort test variables in Makefile

Sort test variables in libio/Makefile using scripts/sort-makefile-lines.py.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
3 days agoAArch64: Remove unused defines of CPU names
Wilco Dijkstra [Thu, 18 Apr 2024 15:33:32 +0000 (18 16:33 +0100)]
AArch64: Remove unused defines of CPU names

Remove unused defines of CPU names in cpu-features.h.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 days agoMake sure INSTALL is ASCII plaintext again
Mark Wielaard [Sun, 28 Apr 2024 14:59:39 +0000 (28 16:59 +0200)]
Make sure INSTALL is ASCII plaintext again

This reverts commit 84e93afc7 ("Switch to UTF-8 for INSTALL") and
reinstates commit c14f2e4aa ("Make sure INSTALL is ASCII plaintext")
and regenerates INSTALL.

It turns out that different versions of makeinfo (texinfo/texi2any),
at least versions 7.0.3 and 7.1, put unicode quote glyphs in different
places (specifically whether contractions like you'd, don't, aren't or
you'll use ’ or '). This breaks the make dist target as used for
(snapshot) releases, which have a check on the regenerated INSTALL
file. Using --disable-encoding generates the same plaintext ASCII on
all versions.

An alternative would be to regenerate INSTALL with texinfo 7.1 and
require at least that version. But that seems too soon while various
distros don't have 7.1 yet. We can try again to use UTF-8 for INSTALL
in a couple of years.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
8 days agox86: In ld.so, diagnose missing APX support in APX-only builds
Florian Weimer [Thu, 25 Apr 2024 15:20:28 +0000 (25 17:20 +0200)]
x86: In ld.so, diagnose missing APX support in APX-only builds

At this point, this is mainly a tool for testing the early ld.so
CPU compatibility diagnostics: GCC uses the new instructions in most
functions, so it's easy to spot if some of the early code is not
built correctly.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
8 days agoelf: Also compile dl-misc.os with $(rtld-early-cflags)
H.J. Lu [Thu, 25 Apr 2024 15:06:52 +0000 (25 08:06 -0700)]
elf: Also compile dl-misc.os with $(rtld-early-cflags)

Also compile dl-misc.os with $(rtld-early-cflags) to avoid

Program received signal SIGILL, Illegal instruction.
0x00007ffff7fd36ea in _dl_strtoul (nptr=nptr@entry=0x7fffffffe2c9 "2",
    endptr=endptr@entry=0x7fffffffd728) at dl-misc.c:156
156   bool positive = true;
(gdb) bt
 #0  0x00007ffff7fd36ea in _dl_strtoul (nptr=nptr@entry=0x7fffffffe2c9 "2",
    endptr=endptr@entry=0x7fffffffd728) at dl-misc.c:156
 #1  0x00007ffff7fdb1a9 in tunable_initialize (
    cur=cur@entry=0x7ffff7ffbc00 <tunable_list+2176>,
    strval=strval@entry=0x7fffffffe2c9 "2", len=len@entry=1)
    at dl-tunables.c:131
 #2  0x00007ffff7fdb3a2 in parse_tunables (valstring=<optimized out>)
    at dl-tunables.c:258
 #3  0x00007ffff7fdb5d9 in __GI___tunables_init (envp=0x7fffffffdd58)
    at dl-tunables.c:288
 #4  0x00007ffff7fe44c3 in _dl_sysdep_start (
    start_argptr=start_argptr@entry=0x7fffffffdcb0,
    dl_main=dl_main@entry=0x7ffff7fe5f80 <dl_main>)
    at ../sysdeps/unix/sysv/linux/dl-sysdep.c:110
 #5  0x00007ffff7fe5cae in _dl_start_final (arg=0x7fffffffdcb0) at rtld.c:494
 #6  _dl_start (arg=0x7fffffffdcb0) at rtld.c:581
 #7  0x00007ffff7fe4b38 in _start ()
(gdb)

when setting GLIBC_TUNABLES in glibc compiled with APX.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
8 days agoCVE-2024-33601, CVE-2024-33602: nscd: netgroup: Use two buffers in addgetnetgrentX...
Florian Weimer [Thu, 25 Apr 2024 13:01:07 +0000 (25 15:01 +0200)]
CVE-2024-33601, CVE-2024-33602: nscd: netgroup: Use two buffers in addgetnetgrentX (bug 31680)

This avoids potential memory corruption when the underlying NSS
callback function does not use the buffer space to store all strings
(e.g., for constant strings).

Instead of custom buffer management, two scratch buffers are used.
This increases stack usage somewhat.

Scratch buffer allocation failure is handled by return -1
(an invalid timeout value) instead of terminating the process.
This fixes bug 31679.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 days agoCVE-2024-33600: nscd: Avoid null pointer crashes after notfound response (bug 31678)
Florian Weimer [Thu, 25 Apr 2024 13:01:07 +0000 (25 15:01 +0200)]
CVE-2024-33600: nscd: Avoid null pointer crashes after notfound response (bug 31678)

The addgetnetgrentX call in addinnetgrX may have failed to produce
a result, so the result variable in addinnetgrX can be NULL.
Use db->negtimeout as the fallback value if there is no result data;
the timeout is also overwritten below.

Also avoid sending a second not-found response.  (The client
disconnects after receiving the first response, so the data stream did
not go out of sync even without this fix.)  It is still beneficial to
add the negative response to the mapping, so that the client can get
it from there in the future, instead of going through the socket.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 days agoCVE-2024-33600: nscd: Do not send missing not-found response in addgetnetgrentX ...
Florian Weimer [Thu, 25 Apr 2024 13:01:07 +0000 (25 15:01 +0200)]
CVE-2024-33600: nscd: Do not send missing not-found response in addgetnetgrentX (bug 31678)

If we failed to add a not-found response to the cache, the dataset
point can be null, resulting in a null pointer dereference.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
8 days agoCVE-2024-33599: nscd: Stack-based buffer overflow in netgroup cache (bug 31677)
Florian Weimer [Thu, 25 Apr 2024 13:00:45 +0000 (25 15:00 +0200)]
CVE-2024-33599: nscd: Stack-based buffer overflow in netgroup cache (bug 31677)

Using alloca matches what other caches do.  The request length is
bounded by MAXKEYLEN.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
9 days agoi386: ulp update for SSE2 --disable-multi-arch configurations
Florian Weimer [Thu, 25 Apr 2024 10:56:48 +0000 (25 12:56 +0200)]
i386: ulp update for SSE2 --disable-multi-arch configurations

9 days agoGLIBC-SA-2024-0004: add commit for 2.31 branch
Aurelien Jarno [Mon, 22 Apr 2024 22:04:08 +0000 (23 00:04 +0200)]
GLIBC-SA-2024-0004: add commit for 2.31 branch

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
9 days agobenchtests: Add difficult strstr needle for bruteforce algorithms
Wilco Dijkstra [Wed, 24 Apr 2024 17:24:45 +0000 (24 18:24 +0100)]
benchtests: Add difficult strstr needle for bruteforce algorithms

Add another difficult needle to strstr that clearly shows the quadratic
complexity of bruteforce algorithms.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
10 days agox86: Define MINIMUM_X86_ISA_LEVEL in config.h [BZ #31676]
H.J. Lu [Tue, 23 Apr 2024 20:59:50 +0000 (23 13:59 -0700)]
x86: Define MINIMUM_X86_ISA_LEVEL in config.h [BZ #31676]

Define MINIMUM_X86_ISA_LEVEL at configure time to avoid

/usr/bin/ld: …/build/elf/librtld.os: in function `init_cpu_features':
…/git/elf/../sysdeps/x86/cpu-features.c:1202: undefined reference to `_dl_runtime_resolve_fxsave'
/usr/bin/ld: …/build/elf/librtld.os: relocation R_X86_64_PC32 against undefined hidden symbol `_dl_runtime_resolve_fxsave' can not be used when making a shared object
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

when glibc is built with -march=x86-64-v3 and configured with
--with-rtld-early-cflags=-march=x86-64, which is used to allow ld.so to
print an error message on unsupported CPUs:

Fatal glibc error: CPU does not support x86-64-v3

This fixes BZ #31676.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
10 days agoLoongArch: Add glibc.cpu.hwcap support.
caiyinyu [Fri, 15 Sep 2023 09:35:19 +0000 (15 17:35 +0800)]
LoongArch: Add glibc.cpu.hwcap support.

The current IFUNC selection is always using the most recent
features which are available via AT_HWCAP.  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 feature yyy, disable HWCAP feature xxx,
where the feature name is case-sensitive and has to match the ones
used in sysdeps/loongarch/cpu-tunables.c.

Signed-off-by: caiyinyu <caiyinyu@loongson.cn>
10 days agonptl: Fix tst-cancel30 on kernels without ppoll_time64 support
Florian Weimer [Tue, 23 Apr 2024 19:16:32 +0000 (23 21:16 +0200)]
nptl: Fix tst-cancel30 on kernels without ppoll_time64 support

Fall back to ppoll if ppoll_time64 fails with ENOSYS.
Fixes commit 370da8a121c3ba9eeb2f13da15fc0f21f4136b25 ("nptl: Fix
tst-cancel30 on sparc64").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
11 days agoRevert "Allow glibc to be compiled without EXEC_PAGESIZE"
Samuel Thibault [Mon, 22 Apr 2024 21:00:18 +0000 (22 23:00 +0200)]
Revert "Allow glibc to be compiled without EXEC_PAGESIZE"

This reverts commit 49aa652db810ebdca3a662ebd5b0468bd08ec688.

This is still being discussed.

11 days agolocale: Handle loading a missing locale twice (Bug 14247)
Carlos O'Donell [Mon, 22 Apr 2024 12:16:09 +0000 (22 08:16 -0400)]
locale: Handle loading a missing locale twice (Bug 14247)

Delay setting file->decided until the data has been successfully loaded
by _nl_load_locale().  If the function fails to load the data then we
must return and error and leave decided untouched to allow the caller to
attempt to load the data again at a later time.  We should not set
decided to 1 early in the function since doing so may prevent attempting
to load it again. We want to try loading it again because that allows an
open to fail and set errno correctly.

On the other side of this problem is that if we are called again with
the same inputs we will fetch the cached version of the object and carry
out no open syscalls and that fails to set errno so we must set errno to
ENOENT in that case.  There is a second code path that has to be handled
where the name of the locale matches but the codeset doesn't match.

These changes ensure that errno is correctly set on failure in all the
return paths in _nl_find_locale().

Adds tst-locale-loadlocale to cover the bug.

No regressions on x86_64.

Co-authored-by: Jeff Law <law@redhat.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
11 days agoelf: Do not check for loader mmap on tst-decorate-maps (BZ 31553)
Adhemerval Zanella [Tue, 26 Mar 2024 13:47:42 +0000 (26 10:47 -0300)]
elf: Do not check for loader mmap on tst-decorate-maps (BZ 31553)

On some architectures and depending on the page size, the loader can
also allocate some memory during dependencies loading and it will be
marked as 'loader malloc'.  However, if the system page size is
large enough, the initial data page will be enough for all required
allocation and there will be no extra loader mmap.  To avoid false
negatives, the test does not check for such pages.

Checked on powerpc64le-linux-gnu with 64k pagesize.
Reviewed-by: Simon Chopin <simon.chopin@canonical.com>
2 weeks agoUse --enable-obsolete in build-many-glibcs.py for nios2-linux-gnu
Joseph Myers [Fri, 19 Apr 2024 17:03:56 +0000 (19 17:03 +0000)]
Use --enable-obsolete in build-many-glibcs.py for nios2-linux-gnu

Until GCC removes Nios II support (at which point we should do so as
well), this is now needed for GCC 14 / mainline to build for
nios2-linux-gnu target.

Tested with build-many-glibcs.py (GCC mainline) for nios2-linux-gnu.

2 weeks agologin: Use unsigned 32-bit types for seconds-since-epoch
Florian Weimer [Fri, 19 Apr 2024 12:38:17 +0000 (19 14:38 +0200)]
login: Use unsigned 32-bit types for seconds-since-epoch

These fields store timestamps when the system was running.  No Linux
systems existed before 1970, so these values are unused.  Switching
to unsigned types allows continued use of the existing struct layouts
beyond the year 2038.

The intent is to give distributions more time to switch to improved
interfaces that also avoid locking/data corruption issues.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 weeks agologin: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701)
Florian Weimer [Fri, 19 Apr 2024 12:38:17 +0000 (19 14:38 +0200)]
login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701)

These structs describe file formats under /var/log, and should not
depend on the definition of _TIME_BITS.  This is achieved by
defining __WORDSIZE_TIME64_COMPAT32 to 1 on 32-bit ports that
support 32-bit time_t values (where __time_t is 32 bits).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 weeks agologin: Check default sizes of structs utmp, utmpx, lastlog
Florian Weimer [Fri, 19 Apr 2024 12:38:17 +0000 (19 14:38 +0200)]
login: Check default sizes of structs utmp, utmpx, lastlog

The default <utmp-size.h> is for ports with a 64-bit time_t.
Ports with a 32-bit time_t or with __WORDSIZE_TIME64_COMPAT32=1
need to override it.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 weeks agobenchtests: Add random() benchmark
Wilco Dijkstra [Tue, 28 Nov 2023 13:33:56 +0000 (28 13:33 +0000)]
benchtests: Add random() benchmark

Add a simple benchmark to measure the overhead of internal libc locks in
the random() implementation on both single- and multi-threaded cases.
This relies on the implementation of random using internal locks to
access shared global data, and that the runtime uses multi-threaded
locking once a thread has been created (even after it finishes).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 weeks agoadvisories: Add Reported-By
Siddhesh Poyarekar [Thu, 18 Apr 2024 12:51:37 +0000 (18 08:51 -0400)]
advisories: Add Reported-By

Add a new tag to give credit to vulnerability discoverers.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 weeks agoFix 'Reported-By' to use Camel Case for commit 6a98f4640ea453f
Adhemerval Zanella [Wed, 17 Apr 2024 17:27:42 +0000 (17 14:27 -0300)]
Fix 'Reported-By' to use Camel Case for commit 6a98f4640ea453f

2 weeks agoDocument CVE-2024-2961
Adhemerval Zanella [Wed, 17 Apr 2024 17:24:26 +0000 (17 14:24 -0300)]
Document CVE-2024-2961

This commit adds "advisories" entries for the above three CVEs.

2 weeks agoiconv: ISO-2022-CN-EXT: fix out-of-bound writes when writing escape sequence (CVE...
Charles Fol [Thu, 28 Mar 2024 15:25:38 +0000 (28 12:25 -0300)]
iconv: ISO-2022-CN-EXT: fix out-of-bound writes when writing escape sequence (CVE-2024-2961)

ISO-2022-CN-EXT uses escape sequences to indicate character set changes
(as specified by RFC 1922).  While the SOdesignation has the expected
bounds checks, neither SS2designation nor SS3designation have its;
allowing a write overflow of 1, 2, or 3 bytes with fixed values:
'$+I', '$+J', '$+K', '$+L', '$+M', or '$*H'.

Checked on aarch64-linux-gnu.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2 weeks agoelf/rtld: Count skipped environment variables for enable_secure
Joe Simmons-Talbott [Tue, 16 Apr 2024 20:31:42 +0000 (16 20:31 +0000)]
elf/rtld: Count skipped environment variables for enable_secure

When using the glibc.rtld.enable_secure tunable we need to keep track of
the count of environment variables we skip due to __libc_enable_secure
being set and adjust the auxv section of the stack.  This fixes an
assertion when running ld.so directly with glibc.rtld.enable_secure set.
Add a testcase that ensures the assert is not hit.

elf/rtld.c:1324   assert (auxv == sp + 1);

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 weeks agopowerpc: Fix ld.so address determination for PCREL mode (bug 31640)
Florian Weimer [Sun, 14 Apr 2024 06:24:51 +0000 (14 08:24 +0200)]
powerpc: Fix ld.so address determination for PCREL mode (bug 31640)

This seems to have stopped working with some GCC 14 versions,
which clobber r2.  With other compilers, the kernel-provided
r2 value is still available at this point.

Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
2 weeks agoRevert "x86_64: Suppress false positive valgrind error"
Florian Weimer [Sat, 13 Apr 2024 14:17:38 +0000 (13 16:17 +0200)]
Revert "x86_64: Suppress false positive valgrind error"

This reverts commit a1735e0aa858f0c8b15e5ee9975bff4279423680.

The test failure is a real valgrind bug that needs to be fixed before
valgrind is usable with a glibc that has been built with
CC="gcc -march=x86-64-v3".  The proposed valgrind patch teaches
valgrind to replace ld.so strcmp with an unoptimized scalar
implementation, thus avoiding any AVX2-related problems.

Valgrind bug: <https://bugs.kde.org/show_bug.cgi?id=485487>

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 weeks agowcsmbs: Ensure wcstr worst-case linear execution time (BZ 23865)
Adhemerval Zanella [Tue, 19 Mar 2024 13:15:28 +0000 (19 10:15 -0300)]
wcsmbs: Ensure wcstr worst-case linear execution time (BZ 23865)

It uses the same two-way algorithm used on strstr, strcasestr, and
memmem.  Different than strstr, neither the "shift table" optimization
nor the self-adapting filtering check is used because it would result in
a too-large shift table (and it also simplifies the implementation bit).

Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Reviewed-by: DJ Delorie <dj@redhat.com>
3 weeks agowcsmbs: Add test-wcsstr
Adhemerval Zanella [Tue, 19 Mar 2024 13:15:27 +0000 (19 10:15 -0300)]
wcsmbs: Add test-wcsstr

Parametrize test-strstr.c so it can be used to check wcsstr.

Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Reviewed-by: DJ Delorie <dj@redhat.com>
3 weeks agoposix: Sync tempname with gnulib
Adhemerval Zanella [Tue, 10 Oct 2023 19:22:39 +0000 (10 16:22 -0300)]
posix: Sync tempname with gnulib

The gnulib version contains an important change (9ce573cde), which
fixes some problems with multithreading, entropy loss, and ASLR leak
nfo.  It also fixes an issue where getrandom is not being used
on some new files generation (only for __GT_NOCREATE on first try).

The 044bf893ac removed __path_search, which is now moved to another
gnulib shared files (stdio-common/tmpdir.{c,h}).  Tthis patch
also fixes direxists to use __stat64_time64 instead of __xstat64,
and move the include of pathmax.h for !_LIBC (since it is not used
by glibc).  The license is also changed from GPL 3.0 to 2.1, with
permission from the authors (Bruno Haible and Paul Eggert).

The sync also removed the clock fallback, since clock_gettime
with CLOCK_REALTIME is expected to always succeed.

It syncs with gnulib commit 323834962817af7b115187e8c9a833437f8d20ec.

Checked on x86_64-linux-gnu.

Co-authored-by: Bruno Haible <bruno@clisp.org>
Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>
Reviewed-by: Bruno Haible <bruno@clisp.org>
3 weeks agosocket: Add new test for connect
Sergey Kolosov [Wed, 10 Apr 2024 15:58:05 +0000 (10 17:58 +0200)]
socket: Add new test for connect

This commit adds a simple bind/accept/connect test for an IPv4 TCP
connection to a local process via the loopback interface.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
3 weeks agolibsupport: Add xgetpeername
Sergey Kolosov [Wed, 10 Apr 2024 15:58:04 +0000 (10 17:58 +0200)]
libsupport: Add xgetpeername

The patch adds redirections for getpeername.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
3 weeks agonptl: Add tst-pthread-key1-static for BZ #21777
H.J. Lu [Mon, 8 Apr 2024 19:33:36 +0000 (8 12:33 -0700)]
nptl: Add tst-pthread-key1-static for BZ #21777

Add a static pthread static tests to verify that BZ #21777 is fixed.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
3 weeks agoelf: Add ld.so test with non-existing program name
Florian Weimer [Mon, 8 Apr 2024 17:19:09 +0000 (8 19:19 +0200)]
elf: Add ld.so test with non-existing program name

None of the existing tests seem to cover the case where
_dl_signal_error is called without an active error handler.
The new elf/tst-rtld-does-not-exist test triggers such a
_dl_signal_error call from _dl_map_object.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 weeks agoelf: Check objname before calling fatal_error
H.J. Lu [Mon, 8 Apr 2024 16:06:09 +0000 (8 09:06 -0700)]
elf: Check objname before calling fatal_error

_dl_signal_error may be called with objname == NULL.  _dl_exception_create
checks objname == NULL.  But fatal_error doesn't.  Check objname before
calling fatal_error.  This fixes BZ #31596.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
3 weeks agoUse crtbeginT.o and crtend.o for non-PIE static executables
H.J. Lu [Fri, 5 Apr 2024 23:42:57 +0000 (5 16:42 -0700)]
Use crtbeginT.o and crtend.o for non-PIE static executables

When static PIE is enabled by default, we shouldn't use crtbeginS.o and
crtendS.o for non-PIE static executables.  Check $($(@F)-no-pie) to use
crtbeginT.o and crtend.o to create non-PIE static executables.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
3 weeks agoaarch64: Enhanced CPU diagnostics for ld.so
Florian Weimer [Mon, 8 Apr 2024 14:48:55 +0000 (8 16:48 +0200)]
aarch64: Enhanced CPU diagnostics for ld.so

This prints some information from struct cpu_features, and the midr_el1
and dczid_el0 system register contents on every CPU.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
3 weeks agox86: Add generic CPUID data dumper to ld.so --list-diagnostics
Florian Weimer [Mon, 8 Apr 2024 14:48:55 +0000 (8 16:48 +0200)]
x86: Add generic CPUID data dumper to ld.so --list-diagnostics

This is surprisingly difficult to implement if the goal is to produce
reasonably sized output.  With the current approaches to output
compression (suppressing zeros and repeated results between CPUs,
folding ranges of identical subleaves, dealing with the %ecx
reflection issue), the output is less than 600 KiB even for systems
with 256 logical CPUs.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 weeks agoelf: Add CPU iteration support for future use in ld.so diagnostics
Florian Weimer [Mon, 8 Apr 2024 14:48:55 +0000 (8 16:48 +0200)]
elf: Add CPU iteration support for future use in ld.so diagnostics

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
3 weeks agotimezone: sync to TZDB 2024a
Paul Eggert [Sun, 7 Apr 2024 06:39:53 +0000 (6 23:39 -0700)]
timezone: sync to TZDB 2024a

Sync tzselect, zdump, zic to TZDB 2024a.
This patch incorporates the following TZDB source code changes,
listed roughly in descending order of importance.

  zic now supports links to links, needed for future tzdata
  zic now defaults to '-b slim'
  zic now updates output files atomically
  zic has new options -R, -l -, -p -
  zic -r now uses -00 for unspecified timestamps
  zdump now uses [lo,hi) for both -c and -t
  Fix several integer overflow bugs
  zic now checks input bytes more carefully
  Simplify and fix new TZDIR setup
  Default time_t to 64 bits on glibc 2.34+ 32-bit
  zic now generates TZ strings that conform to POSIX when all-year DST
  zic -v now shows extreme-int tm_year transitions
  Fix zic bug in last time type of Asia/Gaza etc.
  Fix zic bug with Palestine after 2075
  Fix bug uncovered by recent change to Iran history
  Fix 'zic -b fat' bug with Port Moresby 32-bit data
  Fix zic bug with -r @X where X is deduced from TZ
  Fix bug with zic -r cutoff before 1st transition
  Fix leap second expiry and truncation
  Fix zic bug on Linux 2.6.16 and 2.6.17
  Fix bug with 'zic -d /a/b/c' if /a is unwriteable
  Don't mistruncate TZif files at leap seconds
  Fix zdump undefined behavior if !USE_LTZ
  zdump -v reports localtime+gmtime failures better
  Fix zdump diagnostic for missing timezone
  Don't assume nonempty argv
  Port better to C23
  Do not assume negative >> behavior
  I18nize zdump a bit better
  Port zdump to right_only installations
  New tzselect menu option 'now'
  tzselect can now use current time to help choose
  Improve tzselect behavior for Turkey etc.
  tzselect: do not create temporary files
  tzselect: work around mawk bug with {2,}
  tzselect: Port to POSIX awk, which prohibits -v newlines
  Do not use empty RE in tzselect
  Don't set TZ in tzselect
  Avoid sed, expr in tzselect
  tzselect: Fix problems with spaces in TZDIR
  Improve tzselect diagnostics
  Remove zic workaround for Qt bug 53071
  Remove zic support for "min" in Rule lines
  Remove zic support for zic -y, Rule TYPEs, pacificnew
  Remove tzselect workaround for Bash 1.14.7 bug

* SHARED-FILES: Update to match current sync.
* config.h.in (HAVE_STRERROR): Remove; no longer needed.
* timezone/Makefile ($(objpfx)zic.o): Depend on tzdir.h.
($(objpfx)tzdir.h): New rule to build a placeholder.
* timezone/private.h, timezone/tzfile.h, timezone/version:
* timezone/zdump.c, timezone/zic.c: Copy verbatim from TZDB 2024a.

3 weeks agoFix bsearch, qsort doc to match POSIX better
Paul Eggert [Sat, 6 Apr 2024 15:44:01 +0000 (6 08:44 -0700)]
Fix bsearch, qsort doc to match POSIX better

* manual/search.texi (Array Search Function):
Correct the statement about lfind’s mean runtime:
it is proportional to a number (not that number),
and this is true only if random elements are searched for.
Relax the constraint on bsearch’s array argument:
POSIX says it need not be sorted, only partially sorted.
Say that the first arg passed to bsearch’s comparison function
is the key, and the second arg is an array element, as
POSIX requires.  For bsearch and qsort, say that the
comparison function should not alter the array, as POSIX
requires.  For qsort, say that the comparison function
must define a total order, as POSIX requires, that
it should not depend on element addresses, that
the original array index can be used for stable sorts,
and that if qsort still works if memory allocation fails.
Be more consistent in calling the array elements
“elements” rather than “objects”.

Co-authored-by: Zack Weinberg <zack@owlfolio.org>
4 weeks agox86-64: Exclude FMA4 IFUNC functions for -mapxf
H.J. Lu [Thu, 4 Apr 2024 22:43:50 +0000 (4 15:43 -0700)]
x86-64: Exclude FMA4 IFUNC functions for -mapxf

When -mapxf is used to build glibc, the resulting glibc will never run
on FMA4 machines.  Exclude FMA4 IFUNC functions when -mapxf is used.
This requires GCC which defines __APX_F__ for -mapxf with commit:

1df56719bd8 x86: Define __APX_F__ for -mapxf

Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
4 weeks agoReinstate generic features-time64.h
Adhemerval Zanella [Fri, 5 Apr 2024 12:02:36 +0000 (5 09:02 -0300)]
Reinstate generic features-time64.h

The a4ed0471d7 removed the generic version which is included by
features.h and used by Hurd.

Checked by building i686-gnu and x86_64-gnu with build-many-glibc.py.

4 weeks agoCleanup __tls_get_addr on alpha/microblaze localplt.data
Adhemerval Zanella [Thu, 4 Apr 2024 20:04:23 +0000 (4 17:04 -0300)]
Cleanup __tls_get_addr on alpha/microblaze localplt.data

They are not required.

Checked with a make check for both ABIs.

4 weeks agoarm: Remove ld.so __tls_get_addr plt usage
Adhemerval Zanella [Thu, 4 Apr 2024 20:03:32 +0000 (4 17:03 -0300)]
arm: Remove ld.so __tls_get_addr plt usage

Use the hidden alias instead.

Checked on arm-linux-gnueabihf.

4 weeks agoaarch64: Remove ld.so __tls_get_addr plt usage
Adhemerval Zanella [Thu, 4 Apr 2024 20:02:32 +0000 (4 17:02 -0300)]
aarch64: Remove ld.so __tls_get_addr plt usage

Use the hidden alias instead.

Checked on aarch64-linux-gnu.

4 weeks agomath: x86 trunc traps when FE_INEXACT is enabled (BZ 31603)
Adhemerval Zanella [Wed, 3 Apr 2024 19:39:19 +0000 (3 16:39 -0300)]
math: x86 trunc traps when FE_INEXACT is enabled (BZ 31603)

The implementations of trunc functions using x87 floating point (i386 and
x86_64 long double only) traps when FE_INEXACT is enabled.  Although
this is a GNU extension outside the scope of the C standard, other
architectures that also support traps do not show this behavior.

The fix moves the implementation to a common one that holds any
exceptions with a 'fnclex' (libc_feholdexcept_setround_387).

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks agomath: x86 floor traps when FE_INEXACT is enabled (BZ 31601)
Adhemerval Zanella [Wed, 3 Apr 2024 19:39:18 +0000 (3 16:39 -0300)]
math: x86 floor traps when FE_INEXACT is enabled (BZ 31601)

The implementations of floor functions using x87 floating point (i386 and
86_64 long double only) traps when FE_INEXACT is enabled.  Although
this is a GNU extension outside the scope of the C standard, other
architectures that also support traps do not show this behavior.

The fix moves the implementation to a common one that holds any
exceptions with a 'fnclex' (libc_feholdexcept_setround_387).

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks agomath: x86 ceill traps when FE_INEXACT is enabled (BZ 31600)
Adhemerval Zanella [Wed, 3 Apr 2024 19:39:17 +0000 (3 16:39 -0300)]
math: x86 ceill traps when FE_INEXACT is enabled (BZ 31600)

The implementations of ceil functions using x87 floating point (i386 and
x86_64 long double only) traps when FE_INEXACT is enabled.  Although
this is a GNU extension outside the scope of the C standard, other
architectures that also support traps do not show this behavior.

The fix moves the implementation to a common one that holds any
exceptions with a 'fnclex' (libc_feholdexcept_setround_387).

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks agoaarch64/fpu: Add vector variants of erfc
Joe Ramsay [Tue, 20 Feb 2024 16:59:45 +0000 (20 16:59 +0000)]
aarch64/fpu: Add vector variants of erfc

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 weeks agoaarch64/fpu: Add vector variants of tanh
Joe Ramsay [Tue, 20 Feb 2024 16:59:44 +0000 (20 16:59 +0000)]
aarch64/fpu: Add vector variants of tanh

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 weeks agoaarch64/fpu: Add vector variants of sinh
Joe Ramsay [Wed, 3 Apr 2024 11:15:41 +0000 (3 12:15 +0100)]
aarch64/fpu: Add vector variants of sinh

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 weeks agoaarch64/fpu: Add vector variants of atanh
Joe Ramsay [Wed, 3 Apr 2024 11:13:53 +0000 (3 12:13 +0100)]
aarch64/fpu: Add vector variants of atanh

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 weeks agoaarch64/fpu: Add vector variants of asinh
Joe Ramsay [Tue, 20 Feb 2024 16:59:41 +0000 (20 16:59 +0000)]
aarch64/fpu: Add vector variants of asinh

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 weeks agoaarch64/fpu: Add vector variants of acosh
Joe Ramsay [Tue, 20 Feb 2024 16:59:40 +0000 (20 16:59 +0000)]
aarch64/fpu: Add vector variants of acosh

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 weeks agoaarch64/fpu: Add vector variants of cosh
Joe Ramsay [Tue, 20 Feb 2024 16:59:39 +0000 (20 16:59 +0000)]
aarch64/fpu: Add vector variants of cosh

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 weeks agoaarch64/fpu: Add vector variants of erf
Joe Ramsay [Tue, 20 Feb 2024 16:59:38 +0000 (20 16:59 +0000)]
aarch64/fpu: Add vector variants of erf

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 weeks agomisc: Add support for Linux uio.h RWF_NOAPPEND flag
Stafford Horne [Wed, 3 Apr 2024 05:40:37 +0000 (3 06:40 +0100)]
misc: Add support for Linux uio.h RWF_NOAPPEND flag

In Linux 6.9 a new flag is added to allow for Per-io operations to
disable append mode even if a file was opened with the flag O_APPEND.
This is done with the new RWF_NOAPPEND flag.

This caused two test failures as these tests expected the flag 0x00000020
to be unused.  Adding the flag definition now fixes these tests on Linux
6.9 (v6.9-rc1).

  FAIL: misc/tst-preadvwritev2
  FAIL: misc/tst-preadvwritev64v2

This patch adds the flag, adjusts the test and adds details to
documentation.

Link: https://lore.kernel.org/all/20200831153207.GO3265@brightrain.aerifal.cx/
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 weeks agomanual: significand() uses FLT_RADIX, not 2
Alejandro Colomar [Sun, 31 Mar 2024 20:38:52 +0000 (31 22:38 +0200)]
manual: significand() uses FLT_RADIX, not 2

It's implemented using scalb(), which uses FLT_RADIX, AFAIK.

Link: <https://lore.kernel.org/linux-man/ZeYKUOKYS7G90SaV@debian/T/#mf21ab57e16b92eb6be6c7df79dc0eb43d4454056>
Reported-by: Morten Welinder <mwelinder@gmail.com>
Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Vincent Lefevre <vincent@vinc17.net>
Cc: DJ Delorie <dj@redhat.com>
Cc: Paul Zimmermann <Paul.Zimmermann@inria.fr>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: DJ Delorie <dj@redhat.com>
4 weeks agomanual: Clarify return value of cbrt(3)
Alejandro Colomar [Sun, 31 Mar 2024 20:38:48 +0000 (31 22:38 +0200)]
manual: Clarify return value of cbrt(3)

Link: <https://lore.kernel.org/linux-man/ZeYKUOKYS7G90SaV@debian/T/#mff0ab388000c6afdb5e5162804d4a0073de481de>
Reported-by: Morten Welinder <mwelinder@gmail.com>
Cowritten-by: Morten Welinder <mwelinder@gmail.com>
Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Vincent Lefevre <vincent@vinc17.net>
Cc: DJ Delorie <dj@redhat.com>
Cc: Paul Zimmermann <Paul.Zimmermann@inria.fr>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: DJ Delorie <dj@redhat.com>
4 weeks agomanual: floor(log2(fabs(x))) has rounding errors
Alejandro Colomar [Sun, 31 Mar 2024 20:38:44 +0000 (31 22:38 +0200)]
manual: floor(log2(fabs(x))) has rounding errors

Link: <https://inbox.sourceware.org/libc-alpha/20240305150131.GD3653@qaa.vinc17.org/T/#m3ceecda630012995339bcc5448fee451cf277a8b>
Reported-by: Vincent Lefevre <vincent@vinc17.net>
Suggested-by: Vincent Lefevre <vincent@vinc17.net>
Reviewed-by: DJ Delorie <dj@redhat.com>
Cc: Morten Welinder <mwelinder@gmail.com>
Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Paul Zimmermann <Paul.Zimmermann@inria.fr>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 weeks agomanual: logb(x) is floor(log2(fabs(x)))
Alejandro Colomar [Sun, 31 Mar 2024 20:38:39 +0000 (31 22:38 +0200)]
manual: logb(x) is floor(log2(fabs(x)))

log2(3) doesn't accept negative input, but it seems logb(3) does accept
it.

Link: <https://lore.kernel.org/linux-man/ZeYKUOKYS7G90SaV@debian/T/#u>
Reported-by: Morten Welinder <mwelinder@gmail.com>
Reviewed-by: DJ Delorie <dj@redhat.com>
Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Vincent Lefevre <vincent@vinc17.net>
Cc: Paul Zimmermann <Paul.Zimmermann@inria.fr>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 weeks agopowerpc: Add missing arch flags on rounding ifunc variants
Adhemerval Zanella [Thu, 28 Dec 2023 17:20:16 +0000 (28 14:20 -0300)]
powerpc: Add missing arch flags on rounding ifunc variants

The ifunc variants now uses the powerpc implementation which in turn
uses the compiler builtin.  Without the proper -mcpu switch the builtin
does not generate the expected optimization.

Checked on powerpc-linux-gnu.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
4 weeks agomath: Reformat Makefile.
Adhemerval Zanella [Thu, 28 Dec 2023 17:20:15 +0000 (28 14:20 -0300)]
math: Reformat Makefile.

Reflow all long lines adding comment terminators.
Sort all reflowed text using scripts/sort-makefile-lines.py.

No code generation changes observed in binary artifacts.
No regressions on x86_64 and i686.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks agoAlways define __USE_TIME_BITS64 when 64 bit time_t is used
Adhemerval Zanella [Thu, 18 Jan 2024 13:18:01 +0000 (18 10:18 -0300)]
Always define __USE_TIME_BITS64 when 64 bit time_t is used

It was raised on libc-help [1] that some Linux kernel interfaces expect
the libc to define __USE_TIME_BITS64 to indicate the time_t size for the
kABI.  Different than defined by the initial y2038 design document [2],
the __USE_TIME_BITS64 is only defined for ABIs that support more than
one time_t size (by defining the _TIME_BITS for each module).

The 64 bit time_t redirects are now enabled using a different internal
define (__USE_TIME64_REDIRECTS). There is no expected change in semantic
or code generation.

Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, and
arm-linux-gnueabi

[1] https://sourceware.org/pipermail/libc-help/2024-January/006557.html
[2] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign

Reviewed-by: DJ Delorie <dj@redhat.com>
4 weeks agobenchtests: Improve benchtests for strstr
Adhemerval Zanella [Mon, 18 Mar 2024 12:27:52 +0000 (18 09:27 -0300)]
benchtests: Improve benchtests for strstr

Use same strategy as bench-strstr.c (93eebae5168e5cf2 and 80b2bfb53504)
and use json_ctx for output to help standardize format across all
benchtests.
Reviewed-by: Arjun Shankar <arjun@redhat.com>
5 weeks agox86_64: Remove avx512 strstr implementation
Adhemerval Zanella [Thu, 21 Mar 2024 17:12:00 +0000 (21 14:12 -0300)]
x86_64: Remove avx512 strstr implementation

As indicated in a recent thread, this it is a simple brute-force
algorithm that checks the whole needle at a matching character pair
(and does so 1 byte at a time after the first 64 bytes of a needle).
Also it never skips ahead and thus can match at every haystack
position after trying to match all of the needle, which generic
implementation avoids.

As indicated by Wilco, a 4x larger needle and 16x larger haystack gives
a clear 65x slowdown both basic_strstr and __strstr_avx512:

  "ifuncs": ["basic_strstr", "twoway_strstr", "__strstr_avx512",
"__strstr_sse2_unaligned", "__strstr_generic"],

    {
     "len_haystack": 65536,
     "len_needle": 1024,
     "align_haystack": 0,
     "align_needle": 0,
     "fail": 1,
     "desc": "Difficult bruteforce needle",
     "timings": [4.0948e+07, 15094.5, 3.20818e+07, 108558, 10839.2]
    },
    {
     "len_haystack": 1048576,
     "len_needle": 4096,
     "align_haystack": 0,
     "align_needle": 0,
     "fail": 1,
     "desc": "Difficult bruteforce needle",
     "timings": [2.69767e+09, 100797, 2.08535e+09, 495706, 82666.9]
    }

PS: I don't have an AVX512 capable machine to verify this issues, but
    skimming through the code it does seems to follow what Wilco has
    described.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
5 weeks agosignal: Avoid system signal disposition to interfere with tests
Adhemerval Zanella [Wed, 14 Feb 2024 17:33:41 +0000 (14 17:33 +0000)]
signal: Avoid system signal disposition to interfere with tests

Both tst-sigset2 and tst-signal1 expectes that SIGINT disposition
is set to SIG_DFL.

5 weeks agoRISC-V: Fix the static-PIE non-relocated object check
Palmer Dabbelt [Thu, 22 Feb 2024 23:24:00 +0000 (22 15:24 -0800)]
RISC-V: Fix the static-PIE non-relocated object check

The value of l_scope is only valid post relocation, so this original
check was triggering undefined behavior.  Instead just directly check to
see if the object has been relocated, at which point using l_scope is
safe.

Reported-by: Andreas Schwab <schwab@suse.de>
Closes: BZ #31317
Fixes: e0590f41fe ("RISC-V: Enable static-pie.")
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
5 weeks agohtl: Implement some support for TLS_DTV_AT_TP
Sergey Bugaev [Sat, 23 Mar 2024 17:32:59 +0000 (23 20:32 +0300)]
htl: Implement some support for TLS_DTV_AT_TP

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-19-bugaevc@gmail.com>

5 weeks agohtl: Respect GL(dl_stack_flags) when allocating stacks
Sergey Bugaev [Sat, 23 Mar 2024 17:32:47 +0000 (23 20:32 +0300)]
htl: Respect GL(dl_stack_flags) when allocating stacks

Previously, HTL would always allocate non-executable stacks.  This has
never been noticed, since GNU Mach on x86 ignores VM_PROT_EXECUTE and
makes all pages implicitly executable.  Since GNU Mach on AArch64
supports non-executable pages, HTL forgetting to pass VM_PROT_EXECUTE
immediately breaks any code that (unfortunately, still) relies on
executable stacks.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-7-bugaevc@gmail.com>

5 weeks agohurd: Use the RETURN_ADDRESS macro
Sergey Bugaev [Sat, 23 Mar 2024 17:32:46 +0000 (23 20:32 +0300)]
hurd: Use the RETURN_ADDRESS macro

This gives us PAC stripping on AArch64.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-6-bugaevc@gmail.com>

5 weeks agohurd: Disable Prefer_MAP_32BIT_EXEC on non-x86_64 for now
Sergey Bugaev [Sat, 23 Mar 2024 17:32:45 +0000 (23 20:32 +0300)]
hurd: Disable Prefer_MAP_32BIT_EXEC on non-x86_64 for now

While we could support it on any architecture, the tunable is currently
only defined on x86_64.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-5-bugaevc@gmail.com>

5 weeks agoAllow glibc to be compiled without EXEC_PAGESIZE
Sergey Bugaev [Sat, 23 Mar 2024 17:32:44 +0000 (23 20:32 +0300)]
Allow glibc to be compiled without EXEC_PAGESIZE

We would like to avoid statically defining any specific page size on
aarch64-gnu, and instead make sure that everything uses the dynamic
page size, available via vm_page_size and GLRO(dl_pagesize).

There are currently a few places in glibc that require EXEC_PAGESIZE
to be defined. Per Roland's suggestion [0], drop the static
GLRO(dl_pagesize) initializers (for now, only if EXEC_PAGESIZE is not
defined), and don't require EXEC_PAGESIZE definition for libio to
enable mmap usage.

[0]: https://mail.gnu.org/archive/html/bug-hurd/2011-10/msg00035.html

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-4-bugaevc@gmail.com>

5 weeks agohurd: Stop relying on VM_MAX_ADDRESS
Sergey Bugaev [Sat, 23 Mar 2024 17:32:43 +0000 (23 20:32 +0300)]
hurd: Stop relying on VM_MAX_ADDRESS

We'd like to avoid committing to a specific size of virtual address
space (i.e. the value of VM_AARCH64_T0SZ) on AArch64.  While the current
version of GNU Mach still exports VM_MAX_ADDRESS for compatibility, we
should try to avoid relying on it when we can.  This piece of logic in
_hurdsig_getenv () doesn't actually care about the size of user-
accessible virtual address space, it just wants to preempt faults on any
addresses starting from the value of the P pointer and above.  So, use
(unsigned long int) -1 instead of VM_MAX_ADDRESS.

While at it, change the casts to (unsigned long int) and not just
(long int), since the type of struct hurd_signal_preemptor.{first,last}
is unsigned long int.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-3-bugaevc@gmail.com>

5 weeks agohurd: Move internal functions to internal header
Sergey Bugaev [Sat, 23 Mar 2024 17:32:42 +0000 (23 20:32 +0300)]
hurd: Move internal functions to internal header

Move _hurd_self_sigstate (), _hurd_critical_section_lock (), and
_hurd_critical_section_unlock () inline implementations (that were
already guarded by #if defined _LIBC) to the internal version of the
header.  While at it, add <tls.h> to the includes, and use
__LIBC_NO_TLS () unconditionally.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-2-bugaevc@gmail.com>

6 weeks agostdlib: Fix tst-makecontext2 log when swapcontext fails
Stafford Horne [Fri, 3 Mar 2023 17:03:00 +0000 (4 02:03 +0900)]
stdlib: Fix tst-makecontext2 log when swapcontext fails

The log incorrectly prints, setcontext failed.  Update this to indicate
that actually swapcontext failed.

Signed-off-by: Stafford Horne <shorne@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
6 weeks agoor1k: Add prctl wrapper to unwrap variadic args
Stafford Horne [Tue, 19 Mar 2024 21:01:24 +0000 (19 21:01 +0000)]
or1k: Add prctl wrapper to unwrap variadic args

On OpenRISC variadic functions and regular functions have different
calling conventions so this wrapper is needed to translate.  This
wrapper is copied from x86_64/x32.  I don't know the build system enough
to find a cleaner way to share the code between x86_64/x32 and or1k
(maybe Implies?), so I went with the straight copy.

This fixes test failures:

  misc/tst-prctl
  nptl/tst-setgetname

6 weeks agoor1k: Only define fpu rouding and exceptions with hard-float
Stafford Horne [Tue, 19 Mar 2024 20:53:37 +0000 (19 20:53 +0000)]
or1k: Only define fpu rouding and exceptions with hard-float

This test failure:

  math/test-fenv

If rounding mode and exception macros are defined then the fenv tests
run and always fail.  This patch adds an ifdef using the
__or1k_hard_float__ macro provided by gcc to avoid defining these fenv
macros when they cnnot be used.  This is similar to what is done in csky.

Note, I will post the or1k hard-float support soon. So, I prefer to
leave the hard-float bits here for now.

6 weeks agoor1k: Update libm test ulps
Stafford Horne [Mon, 18 Mar 2024 15:27:56 +0000 (18 15:27 +0000)]
or1k: Update libm test ulps

To fix test failures:

    FAIL: math/test-float-hypot
    FAIL: math/test-float32-hypot

6 weeks agoAArch64: Check kernel version for SVE ifuncs
Wilco Dijkstra [Thu, 21 Mar 2024 16:48:33 +0000 (21 16:48 +0000)]
AArch64: Check kernel version for SVE ifuncs

Old Linux kernels disable SVE after every system call.  Calling the
SVE-optimized memcpy afterwards will then cause a trap to reenable SVE.
As a result, applications with a high use of syscalls may run slower with
the SVE memcpy.  This is true for kernels between 4.15.0 and before 6.2.0,
except for 5.14.0 which was patched.  Avoid this by checking the kernel
version and selecting the SVE ifunc on modern kernels.

Parse the kernel version reported by uname() into a 24-bit kernel.major.minor
value without calling any library functions.  If uname() is not supported or
if the version format is not recognized, assume the kernel is modern.

Tested-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
6 weeks agopowerpc: Placeholder and infrastructure/build support to add Power11 related changes.
Amrita H S [Wed, 20 Mar 2024 00:08:47 +0000 (19 19:08 -0500)]
powerpc: Placeholder and infrastructure/build support to add Power11 related changes.

The following three changes have been added to provide initial Power11 support.
    1. Add the directories to hold Power11 files.
    2. Add support to select Power11 libraries based on AT_PLATFORM.
    3. Let submachine=power11 be set automatically.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
6 weeks agopowerpc: Add HWCAP3/HWCAP4 data to TCB for Power Architecture.
Manjunath Matti [Tue, 19 Mar 2024 20:29:48 +0000 (19 15:29 -0500)]
powerpc: Add HWCAP3/HWCAP4 data to TCB for Power Architecture.

This patch adds a new feature for powerpc.  In order to get faster
access to the HWCAP3/HWCAP4 masks, similar to HWCAP/HWCAP2 (i.e. for
implementing __builtin_cpu_supports() in GCC) without the overhead of
reading them from the auxiliary vector, we now reserve space for them
in the TCB.

This is an ABI change for GLIBC 2.39.

Suggested-by: Peter Bergner <bergner@linux.ibm.com>
Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
6 weeks agoelf: Enable TLS descriptor tests on aarch64
Adhemerval Zanella [Tue, 12 Mar 2024 16:21:20 +0000 (12 13:21 -0300)]
elf: Enable TLS descriptor tests on aarch64

The aarch64 uses 'trad' for traditional tls and 'desc' for tls
descriptors, but unlike other targets it defaults to 'desc'.  The
gnutls2 configure check does not set aarch64 as an ABI that uses
TLS descriptors, which then disable somes stests.

Also rename the internal machinery fron gnu2 to tls descriptors.

Checked on aarch64-linux-gnu.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
6 weeks agoarm: Update _dl_tlsdesc_dynamic to preserve caller-saved registers (BZ 31372)
Adhemerval Zanella [Tue, 12 Mar 2024 16:21:19 +0000 (12 13:21 -0300)]
arm: Update _dl_tlsdesc_dynamic to preserve caller-saved registers (BZ 31372)

ARM _dl_tlsdesc_dynamic slow path has two issues:

  * The ip/r12 is defined by AAPCS as a scratch register, and gcc is
    used to save the stack pointer before on some function calls.  So it
    should also be saved/restored as well.  It fixes the tst-gnu2-tls2.

  * None of the possible VFP registers are saved/restored.  ARM has the
    additional complexity to have different VFP bank sizes (depending of
    VFP support by the chip).

The tst-gnu2-tls2 test is extended to check for VFP registers, although
only for hardfp builds.  Different than setcontext, _dl_tlsdesc_dynamic
does not have  HWCAP_ARM_IWMMXT (I don't have a way to properly test
it and it is almost a decade since newer hardware was released).

With this patch there is no need to mark tst-gnu2-tls2 as XFAIL.

Checked on arm-linux-gnueabihf.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
6 weeks agoIgnore undefined symbols for -mtls-dialect=gnu2
Adhemerval Zanella [Tue, 12 Mar 2024 16:21:18 +0000 (12 13:21 -0300)]
Ignore undefined symbols for -mtls-dialect=gnu2

So it does not fail for arm config that defaults to -mtp=soft (which
issues a call to __aeabi_read_tp).
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
6 weeks agoAdd tst-gnu2-tls2mod1 to test-internal-extras
Andreas Schwab [Tue, 19 Mar 2024 12:49:50 +0000 (19 13:49 +0100)]
Add tst-gnu2-tls2mod1 to test-internal-extras

That allows sysdeps/x86_64/tst-gnu2-tls2mod1.S to use internal headers.

Fixes: 717ebfa85c ("x86-64: Allocate state buffer space for RDI, RSI and RBX")