]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
5 months agomath: Use atan2pif from CORE-MATH
Adhemerval Zanella [Fri, 20 Dec 2024 16:01:20 +0000 (13:01 -0300)] 
math: Use atan2pif from CORE-MATH

The CORE-MATH implementation is correctly rounded (for any rounding mode)
and shows better performance to the generic atan2pif.

The code was adapted to glibc style and to use the definition of
math_config.h (to handle errno, overflow, and underflow).

Benchtest on x64_64 (Ryzen 9 5900X, gcc 14.2.1), aarch64 (Neoverse-N1,
gcc 13.3.1), and powerpc (POWER10, gcc 13.2.1):

latency                 master        patched   improvement
x86_64                 79.4006        70.8726        10.74%
x86_64v2               77.5136        69.1424        10.80%
x86_64v3               71.8050        68.1637         5.07%
aarch64 (Neoverse)     27.8363        24.7700        11.02%
power8                 39.3893        17.2929        56.10%
power10                19.7200        16.8187        14.71%

reciprocal-throughput   master        patched   improvement
x86_64                 38.3457        30.9471        19.29%
x86_64v2               37.4023        30.3112        18.96%
x86_64v3               33.0713        24.4891        25.95%
aarch64 (Neoverse)     19.3683        15.3259        20.87%
power8                 19.5507        8.27165        57.69%
power10                9.05331        7.63775        15.64%

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agomath: Use asinpif from CORE-MATH
Adhemerval Zanella [Fri, 20 Dec 2024 14:10:53 +0000 (11:10 -0300)] 
math: Use asinpif from CORE-MATH

The CORE-MATH implementation is correctly rounded (for any rounding mode)
and shows better performance to the generic asinpif.

The code was adapted to glibc style and to use the definition of
math_config.h (to handle errno, overflow, and underflow).

Benchtest on x64_64 (Ryzen 9 5900X, gcc 14.2.1), aarch64 (Neoverse-N1,
gcc 13.3.1), and powerpc (POWER10, gcc 13.2.1):

latency                 master        patched   improvement
x86_64                 46.4996        41.6126        10.51%
x86_64v2               46.7551        38.8235        16.96%
x86_64v3               42.6235        33.7603        20.79%
aarch64 (Neoverse)     17.4161        14.3604        17.55%
power8                 10.7347         9.0193        15.98%
power10                10.6420         9.0362        15.09%

reciprocal-throughput   master        patched   improvement
x86_64                 24.7208        16.5544        33.03%
x86_64v2               24.2177        14.8938        38.50%
x86_64v3               20.5617        10.5452        48.71%
aarch64 (Neoverse)     13.4827        7.17613        46.78%
power8                 6.46134        3.56089        44.89%
power10                5.79007        3.49544        39.63%

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agomath: Use acospif from CORE-MATH
Adhemerval Zanella [Fri, 20 Dec 2024 13:42:35 +0000 (10:42 -0300)] 
math: Use acospif from CORE-MATH

The CORE-MATH implementation is correctly rounded (for any rounding mode)
and shows better performance to the generic acospif.

The code was adapted to glibc style and to use the definition of
math_config.h (to handle errno, overflow, and underflow).

Benchtest on x64_64 (Ryzen 9 5900X, gcc 14.2.1), aarch64 (Neoverse-N1,
gcc 13.3.1), and powerpc (POWER10, gcc 13.2.1):

latency                  master        patched   improvement
x86_64                  54.8281        42.9070        21.74%
x86_64v2                54.1717        42.7497        21.08%
x86_64v3                49.3552        34.1512        30.81%
aarch64 (Neoverse)      17.9395        14.3733        19.88%
power8                  20.3110         8.8609        56.37%
power10                 11.3113        8.84067        21.84%

reciprocal-throughput    master        patched   improvement
x86_64                  21.2301        14.4803        31.79%
x86_64v2                20.6858        13.9506        32.56%
x86_64v3                16.1944        11.3377        29.99%
aarch64 (Neoverse)      11.4474        7.13282        37.69%
power8                  10.6916        3.57547        66.56%
power10                 4.64269        3.54145        23.72%

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agobenchtests: Add tanpif
Adhemerval Zanella [Thu, 23 Jan 2025 20:57:53 +0000 (17:57 -0300)] 
benchtests: Add tanpif

Random inputs in the range of [-4,4].

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agobenchtests: Add sinpif
Adhemerval Zanella [Thu, 23 Jan 2025 20:57:11 +0000 (17:57 -0300)] 
benchtests: Add sinpif

Random inputs in the range of [-4,4].

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agobenchtests: Add cospif
Adhemerval Zanella [Thu, 23 Jan 2025 20:56:11 +0000 (17:56 -0300)] 
benchtests: Add cospif

Random inputs in the range of [-4,4].

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agobenchtests: Add atanpif
Adhemerval Zanella [Thu, 23 Jan 2025 20:51:40 +0000 (17:51 -0300)] 
benchtests: Add atanpif

Random inputs in the range of [-10,10].

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agobenchtests: Add atan2pif
Adhemerval Zanella [Thu, 23 Jan 2025 20:50:46 +0000 (17:50 -0300)] 
benchtests: Add atan2pif

Random inputs in the range of [-10,10].

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agobenchtests: Add asinpif
Adhemerval Zanella [Thu, 23 Jan 2025 20:49:38 +0000 (17:49 -0300)] 
benchtests: Add asinpif

Random inputs in the range of [-1,1].

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agobenchtests: Add acospif
Adhemerval Zanella [Thu, 23 Jan 2025 20:49:06 +0000 (17:49 -0300)] 
benchtests: Add acospif

Random inputs in the range of [-1,1].

Reviewed-by: DJ Delorie <dj@redhat.com>
5 months agohurd: Replace char foo[1024] with string_t
Samuel Thibault [Mon, 10 Feb 2025 19:06:35 +0000 (20:06 +0100)] 
hurd: Replace char foo[1024] with string_t

Like already done in various other places and advised by Roland in

https://lists.gnu.org/archive/html/bug-hurd/2012-04/msg00124.html

5 months agohurd: Drop useless buffer initialization in ttyname*
Samuel Thibault [Mon, 10 Feb 2025 19:09:20 +0000 (20:09 +0100)] 
hurd: Drop useless buffer initialization in ttyname*

The RPC stub will write a string anyway.

5 months agomig_strncpy: ensure destination string is null terminated
Flavio Cruz [Mon, 10 Feb 2025 03:37:56 +0000 (22:37 -0500)] 
mig_strncpy: ensure destination string is null terminated

Message-ID: <xaqw66fuawxm5hzgjscfg2oyp6lxflm5tnbb7u253pw3gmdy4m@5z42mw2qz2l2>

5 months agohtl: stop exporting __pthread_default_barrierattr.
gfleury [Sun, 9 Feb 2025 20:01:08 +0000 (22:01 +0200)] 
htl: stop exporting __pthread_default_barrierattr.

since all symbol that use it are now in libc
Message-ID: <20250209200108.865599-9-gfleury@disroot.org>

5 months agohtl: move pthread_barrier_wait into libc.
gfleury [Sun, 9 Feb 2025 20:01:07 +0000 (22:01 +0200)] 
htl: move pthread_barrier_wait into libc.

Message-ID: <20250209200108.865599-8-gfleury@disroot.org>

5 months agohtl: move pthread_barrier_init into libc.
gfleury [Sun, 9 Feb 2025 20:01:06 +0000 (22:01 +0200)] 
htl: move pthread_barrier_init into libc.

Message-ID: <20250209200108.865599-7-gfleury@disroot.org>

5 months agohtl: move pthread_barrier_destroy into libc.
gfleury [Sun, 9 Feb 2025 20:01:05 +0000 (22:01 +0200)] 
htl: move pthread_barrier_destroy into libc.

Message-ID: <20250209200108.865599-6-gfleury@disroot.org>

5 months agohtl: move pthread_barrierattr_getpshared, pthread_barrierattr_setpshared into libc.
gfleury [Sun, 9 Feb 2025 20:01:04 +0000 (22:01 +0200)] 
htl: move pthread_barrierattr_getpshared, pthread_barrierattr_setpshared into libc.

Message-ID: <20250209200108.865599-5-gfleury@disroot.org>

5 months agohtl: move pthread_barrierattr_init into libc.
gfleury [Sun, 9 Feb 2025 20:01:03 +0000 (22:01 +0200)] 
htl: move pthread_barrierattr_init into libc.

Message-ID: <20250209200108.865599-4-gfleury@disroot.org>

5 months agohtl: move pthread_barrierattr_destroy into libc.
gfleury [Sun, 9 Feb 2025 20:01:02 +0000 (22:01 +0200)] 
htl: move pthread_barrierattr_destroy into libc.

Message-ID: <20250209200108.865599-3-gfleury@disroot.org>

5 months agohtl: move __pthread_default_barrierattr into libc.
gfleury [Sun, 9 Feb 2025 20:01:01 +0000 (22:01 +0200)] 
htl: move __pthread_default_barrierattr into libc.

Message-ID: <20250209200108.865599-2-gfleury@disroot.org>

5 months agomanual: Update signal descriptions
DJ Delorie [Fri, 17 Jan 2025 22:34:02 +0000 (17:34 -0500)] 
manual: Update signal descriptions

Based on auditing all the signals and source trees for Hurd and
Linux...

SIGSYS - This is not used for a bad system call (ENOSYS is used
for that).  This is used by SECCOMP and some cases where an invalid
sub-function was requested.

SIGSTKFLT - Note it used to be a coprocessor stack fault but is now
obsolete and available for general user use.

SIGLOST - Hurd only now; note that its original purpose as an NFS
lock lost signal is obsolete.

SIGPWR - Note this is for power lost *and* power restored, and is
more a user-mode signal than a kernel-generated signal.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
5 months agolibio: Replace __LP64__ with __WORDSIZE
Tulio Magno Quites Machado Filho [Thu, 30 Jan 2025 18:51:01 +0000 (15:51 -0300)] 
libio: Replace __LP64__ with __WORDSIZE

__LP64__ is a GCC extension and shouldn't be used in an installed
header.

Fixes: 596a61cf6b (libio: Start to return errors when flushing fwrite's buffer [BZ #29459], 2025-01-28)
Reported-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Arjun Shankar <arjun@redhat.com>
5 months agopowerpc64le: Also avoid IFUNC for __mempcpy
Florian Weimer [Sun, 2 Feb 2025 15:21:39 +0000 (16:21 +0100)] 
powerpc64le: Also avoid IFUNC for __mempcpy

Code used during early static startup in elf/dl-tls.c uses
__mempcpy.

Fixes commit cbd9fd236981717d3d4ee942986ea912e9707c32 ("Consolidate
TLS block allocation for static binaries with ld.so").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
5 months agoelf: Build dl-tls.o with early startup symbol redirections
Florian Weimer [Sun, 2 Feb 2025 15:22:23 +0000 (16:22 +0100)] 
elf: Build dl-tls.o with early startup symbol redirections

This is required when building for powerpc64le POWER8 with GCC 8
at least.

Fixes commit cbd9fd236981717d3d4ee942986ea912e9707c32 ("Consolidate
TLS block allocation for static binaries with ld.so").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
5 months agomanual: make @manpageurl more specific to each output
DJ Delorie [Tue, 10 Dec 2024 21:57:21 +0000 (16:57 -0500)] 
manual: make @manpageurl more specific to each output

Tweak the @manpageurl macro to customize the output for
each of html, info, and pdf output.  HTML and PDF (at
least, these days) support clicking on the link title,
whereas info does not.  Add text to the intro section
explaining which man pages are normative and which
aren't.

5 months agomath: Fix tanf for some inputs (BZ 32630)
Adhemerval Zanella [Sun, 2 Feb 2025 19:57:49 +0000 (16:57 -0300)] 
math: Fix tanf for some inputs (BZ 32630)

The logic was copied wrong from CORE-MATH.

6 months agoelf: Use _dl_find_object instead of _dl_find_dso_for_object in dlopen
Florian Weimer [Sun, 2 Feb 2025 19:10:09 +0000 (20:10 +0100)] 
elf: Use _dl_find_object instead of _dl_find_dso_for_object in dlopen

The _dl_find_object function uses a binary search and is faster if
there are many objects.

6 months agoelf: Add fast path to dlopen for fully-opened maps
Florian Weimer [Sun, 2 Feb 2025 19:10:09 +0000 (20:10 +0100)] 
elf: Add fast path to dlopen for fully-opened maps

If the map is already fully open (has matching flags and its
own scope allocated), it is not necessary to unprotected memory
during dlopen.

6 months agoelf: Determine the caller link map in _dl_open
Florian Weimer [Sun, 2 Feb 2025 19:10:09 +0000 (20:10 +0100)] 
elf: Determine the caller link map in _dl_open

No functional change expected.

This is in preparation of adding a fast path to dlopen in case
no link map changes are required.

6 months agoelf: Merge __dl_libc_freemem into __rtld_libc_freeres
Florian Weimer [Sun, 2 Feb 2025 19:10:09 +0000 (20:10 +0100)] 
elf: Merge __dl_libc_freemem into __rtld_libc_freeres

The functions serve very similar purposes.  The advantage of
__rtld_libc_freeres is that it is located within ld.so, so it is
more natural to poke at link map internals there.

This slightly regresses cleanup capabilities for statically linked
binaries.  If that becomes a problem, we should start calling
__rtld_libc_freeres from __libc_freeres (perhaps after renaming it).

6 months agoelf: Add l_soname accessor function for DT_SONAME values
Florian Weimer [Sun, 2 Feb 2025 19:10:09 +0000 (20:10 +0100)] 
elf: Add l_soname accessor function for DT_SONAME values

It's not necessary to introduce temporaries because the compiler
is able to evaluate l_soname just once in constracts like:

  l_soname (l) != NULL && strcmp (l_soname (l), LIBC_SO) != 0

6 months agoelf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object
Florian Weimer [Sun, 2 Feb 2025 19:10:08 +0000 (20:10 +0100)] 
elf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object

So that they can eventually be called separately from dlopen.

6 months agohurd: Use the new __proc_reauthenticate_complete protocol
Sergey Bugaev [Sat, 1 Feb 2025 17:17:38 +0000 (18:17 +0100)] 
hurd: Use the new __proc_reauthenticate_complete protocol

6 months agoelf: Do not add a copy of _dl_find_object to libc.so
Florian Weimer [Sat, 1 Feb 2025 11:37:58 +0000 (12:37 +0100)] 
elf: Do not add a copy of _dl_find_object to libc.so

This reduces code size and dependencies on ld.so internals from
libc.so.

Fixes commit f4c142bb9fe6b02c0af8cfca8a920091e2dba44b
("arm: Use _dl_find_object on __gnu_Unwind_Find_exidx (BZ 31405)").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agohtl: move pthread_setcancelstate into libc.
gfleury [Sat, 1 Feb 2025 08:02:02 +0000 (10:02 +0200)] 
htl: move pthread_setcancelstate into libc.

sysdeps/pthread/sem_open.c: call pthread_setcancelstate directely
since forward declaration is gone on hurd too
Message-ID: <20250201080202.494671-1-gfleury@disroot.org>

6 months agomath: Fix sinhf for some inputs (BZ 32627)
Adhemerval Zanella [Fri, 31 Jan 2025 13:34:32 +0000 (10:34 -0300)] 
math: Fix sinhf for some inputs (BZ 32627)

The logic was copied wrong from CORE-MATH.

6 months agomath: Fix log10p1f internal table value (BZ 32626)
Adhemerval Zanella [Fri, 31 Jan 2025 13:27:39 +0000 (10:27 -0300)] 
math: Fix log10p1f internal table value (BZ 32626)

It was copied wrong from CORE-MATH.

6 months agomanual: Safety annotations for timespec_get and timespec_getres
Tulio Magno Quites Machado Filho [Tue, 28 Jan 2025 18:31:01 +0000 (15:31 -0300)] 
manual: Safety annotations for timespec_get and timespec_getres

Add preliminary annotations that are consistent with clock_gettime and
clock_getres.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
6 months agosh: Fix tst-guard1 build
Adhemerval Zanella [Fri, 31 Jan 2025 12:34:36 +0000 (09:34 -0300)] 
sh: Fix tst-guard1 build

The tests uses ARCH_MIN_GUARD_SIZE and the sysdep.h include is not
required.

6 months agomanual: Add links to POSIX Semaphores man-pages documentation
Arjun Shankar [Tue, 14 Jan 2025 01:52:10 +0000 (02:52 +0100)] 
manual: Add links to POSIX Semaphores man-pages documentation

The POSIX Semaphores functions are currently undocumented in our info
pages.  This commit adds links to the man-pages documentation for all
the `sem_*' functions (except `sem_clockwait') so that they refer to
some useful documentation instead of just being stubs.  `sem_clockwait'
isn't documented by man-pages but thankfully already has a small useful
blurb in our own docs.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agomanual: Consolidate POSIX Semaphores docs in Threads chapter
Arjun Shankar [Tue, 14 Jan 2025 01:52:09 +0000 (02:52 +0100)] 
manual: Consolidate POSIX Semaphores docs in Threads chapter

This commit moves the `sem_*' family of functions from the IPC chapter,
replacing them with a reference to their new location in the Threads
chapter.  `sem_clockwait' is also moved out of the Non-POSIX Extensions
subsection since it is now included in the standard since Issue 8:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_clockwait.html

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agold.so: Decorate BSS mappings
Petr Malat [Tue, 28 Jan 2025 10:08:20 +0000 (11:08 +0100)] 
ld.so: Decorate BSS mappings

Decorate BSS mappings with [anon: glibc: .bss <file>], for example
[anon: glibc: .bss /lib/libc.so.6]. The string ".bss" is already used
by bionic so use the same, but add the filename as well. If the name
would be longer than what the kernel allows, drop the directory part
of the path.

Refactor glibc.mem.decorate_maps check to a separate function and use
it to avoid assembling a name, which would not be used later.

Signed-off-by: Petr Malat <oss@malat.biz>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agonptl: Add support for setup guard pages with MADV_GUARD_INSTALL
Adhemerval Zanella [Wed, 8 Jan 2025 18:16:48 +0000 (15:16 -0300)] 
nptl: Add support for setup guard pages with MADV_GUARD_INSTALL

Linux 6.13 (662df3e5c3766) added a lightweight way to define guard areas
through madvise syscall.  Instead of PROT_NONE the guard region through
mprotect, userland can madvise the same area with a special flag, and
the kernel ensures that accessing the area will trigger a SIGSEGV (as for
PROT_NONE mapping).

The madvise way has the advantage of less kernel memory consumption for
the process page-table (one less VMA per guard area), and slightly less
contention on kernel (also due to the fewer VMA areas being tracked).

The pthread_create allocates a new thread stack in two ways: if a guard
area is set (the default) it allocates the memory range required using
PROT_NONE and then mprotect the usable stack area. Otherwise, if a
guard page is not set it allocates the region with the required flags.

For the MADV_GUARD_INSTALL support, the stack area region is allocated
with required flags and then the guard region is installed.  If the
kernel does not support it, the usual way is used instead (and
MADV_GUARD_INSTALL is disabled for future stack creations).

The stack allocation strategy is recorded on the pthread struct, and it
is used in case the guard region needs to be resized.  To avoid needing
an extra field, the 'user_stack' is repurposed and renamed to 'stack_mode'.

This patch also adds a proper test for the pthread guard.

I checked on x86_64, aarch64, powerpc64le, and hppa with kernel 6.13.0-rc7.

Reviewed-by: DJ Delorie <dj@redhat.com>
6 months agonptl: Correct stack size attribute when stack grows up [BZ #32574]
John David Anglin [Wed, 29 Jan 2025 21:51:16 +0000 (16:51 -0500)] 
nptl: Correct stack size attribute when stack grows up [BZ #32574]

Set stack size attribute to the size of the mmap'd region only
when the size of the remaining stack space is less than the size
of the mmap'd region.

This was reversed.  As a result, the initial stack size was only
135168 bytes.  On architectures where the stack grows down, the
initial stack size is approximately 8384512 bytes with the default
rlimit settings.  The small main stack size on hppa broke
applications like ruby that check for stack overflows.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
6 months agomanual: Update compatibility note on flushing of line-oriented files
Florian Weimer [Wed, 29 Jan 2025 09:28:10 +0000 (10:28 +0100)] 
manual: Update compatibility note on flushing of line-oriented files

Operation systems which represent text files in a line-oriented
fashion (and not as byte streams with a character sequence reserved
for line termination) logically cannot flush a buffer without
also creating a terminated line.

Update this portability note and move it to the Binary Streams
section.  Add another related compatibility concern, too.

6 months agohtl: move pthread_setcanceltype into libc.
gfleury [Fri, 3 Jan 2025 10:37:50 +0000 (12:37 +0200)] 
htl: move pthread_setcanceltype into libc.

Message-ID: <20250103103750.870897-7-gfleury@disroot.org>

6 months agohtl: move pthread_mutex_consistent, pthread_mutex_consistent_np into libc.
gfleury [Fri, 3 Jan 2025 10:37:49 +0000 (12:37 +0200)] 
htl: move pthread_mutex_consistent, pthread_mutex_consistent_np into libc.

Message-ID: <20250103103750.870897-6-gfleury@disroot.org>

6 months agohtl: move pthread_mutex_destroy into libc.
gfleury [Fri, 3 Jan 2025 10:37:48 +0000 (12:37 +0200)] 
htl: move pthread_mutex_destroy into libc.

Message-ID: <20250103103750.870897-5-gfleury@disroot.org>

6 months agohtl: move pthread_mutex_getprioceiling, pthread_mutex_setprioceiling into libc
gfleury [Fri, 3 Jan 2025 10:37:47 +0000 (12:37 +0200)] 
htl: move pthread_mutex_getprioceiling, pthread_mutex_setprioceiling into libc

Message-ID: <20250103103750.870897-4-gfleury@disroot.org>

6 months agohtl: move pthread_mutex_{lock, unlock, trylock, timedlock, clocklock}
gfleury [Fri, 3 Jan 2025 10:37:46 +0000 (12:37 +0200)] 
htl: move pthread_mutex_{lock, unlock, trylock, timedlock, clocklock}

I haven't exposed _pthread_mutex_lock,  _pthread_mutex_trylock and
_pthread_mutex_unlock in GLIBC_PRIVATE since there aren't used in any
code in libpthread
Message-ID: <20250103103750.870897-3-gfleury@disroot.org>

6 months agohtl: move pthread_mutex_init into libc.
gfleury [Fri, 3 Jan 2025 10:37:45 +0000 (12:37 +0200)] 
htl: move pthread_mutex_init into libc.

Message-ID: <20250103103750.870897-2-gfleury@disroot.org>

6 months agohtl: remove leftover for pthread_mutexattr_settype
gfleury [Tue, 28 Jan 2025 23:33:04 +0000 (00:33 +0100)] 
htl: remove leftover for pthread_mutexattr_settype

from b386295727d35a83aa3d4750e198cbf8040c9a23

6 months agoAdd test of input file flushing / offset issues
Joseph Myers [Tue, 28 Jan 2025 23:39:12 +0000 (23:39 +0000)] 
Add test of input file flushing / offset issues

Having fixed several bugs relating to flushing of FILE* streams (with
fflush and other operations) and their offsets (both the file position
indicator in the FILE*, and the offset in the underlying open file
description), especially after ungetc but not limited to that case,
add a test that more systematically covers different combinations of
cases for such issues, with 57220 separate scenarios tested (which
include examples of all the five separate fixed bugs), all of which
pass given the five previous bug fixes.

Tested for x86_64.

6 months agoFix fflush handling for mmap files after ungetc (bug 32535)
Joseph Myers [Tue, 28 Jan 2025 23:20:08 +0000 (23:20 +0000)] 
Fix fflush handling for mmap files after ungetc (bug 32535)

As discussed in bug 32535, fflush fails on files opened for reading
using mmap after ungetc.  Fix the logic to handle this case and still
compute the file offset correctly.

Tested for x86_64.

6 months agoFix fseek handling for mmap files after ungetc or fflush (bug 32529)
Joseph Myers [Tue, 28 Jan 2025 22:35:21 +0000 (22:35 +0000)] 
Fix fseek handling for mmap files after ungetc or fflush (bug 32529)

As discussed in bug 32529, fseek fails on files opened for reading
using mmap after ungetc.  The implementation of fseek for such files
has an offset computation that's also incorrect after fflush.  A
combined fix addresses both problems (with tests for both included as
well) and it seems reasonable to consider them a single bug.

Tested for x86_64.

6 months agoMake fflush (NULL) flush input files (bug 32369)
Joseph Myers [Tue, 28 Jan 2025 21:53:49 +0000 (21:53 +0000)] 
Make fflush (NULL) flush input files (bug 32369)

As discussed in bug 32369 and required by POSIX, the POSIX feature
fflush (NULL) should flush input files, not just output files.  The
POSIX requirement is that "fflush() shall perform this flushing action
on all streams for which the behavior is defined above", and the
definition for input files is for "a stream open for reading with an
underlying file description, if the file is not already at EOF, and
the file is one capable of seeking".

Implement this requirement in glibc.  (The underlying flushing
implementation is what deals with avoiding errors for seeking on an
unseekable file.)

Tested for x86_64.

6 months agoMake fclose seek input file to right offset (bug 12724)
Joseph Myers [Tue, 28 Jan 2025 20:22:56 +0000 (20:22 +0000)] 
Make fclose seek input file to right offset (bug 12724)

As discussed in bug 12724 and required by POSIX, before an input file
(based on an underlying seekable file descriptor) is closed, fclose is
sometimes required to seek that file descriptor to the correct offset,
so that any other file descriptors sharing the underlying open file
description are left at that offset (as a motivating example, a script
could call a sequence of commands each of which processes some data
from (seekable) stdin using stdio; fclose needs to do this so that
each successive command can read exactly the data not handled by
previous commands), but glibc fails to do this.

The precise POSIX wording has changed a few times; in the 2024 edition
it's "If the file is not already at EOF, and the file is one capable
of seeking, the file offset of the underlying open file description
shall be set to the file position of the stream if the stream is the
active handle to the underlying file description.".

Add appropriate logic to _IO_new_file_close_it to handle this case.  I
haven't made any attempt to test or change things in this area for the
"old" functions.

Note that there was a previous attempt to fix bug 12724, reverted in
commit eb6cbd249f4465b01f428057bf6ab61f5f0c07e3.  The fix version here
addresses the original test in that bug report without breaking the
one given in a subsequent comment in that bug report (which works with
glibc before the patch, but maybe was broken by the original fix that
was reverted).

The logic here tries to take care not to seek the file, even to its
newly computed current offset, if at EOF / possibly not the active
handle; even seeking to the current offset would be problematic
because of a potential race (fclose computes the current offset,
another thread or process with the active handle does its own seek,
fclose does a seek (not permitted by POSIX in this case) that loses
the effect of the seek on the active handle in another thread or
process).  There are tests included for various cases of being or not
being the active handle, though there aren't tests for the potential
race condition.

Tested for x86_64.

6 months agoFix fflush after ungetc on input file (bug 5994)
Joseph Myers [Tue, 28 Jan 2025 19:38:27 +0000 (19:38 +0000)] 
Fix fflush after ungetc on input file (bug 5994)

As discussed in bug 5994 (plus duplicates), POSIX requires fflush
after ungetc to discard pushed-back characters but preserve the file
position indicator.  For this purpose, each ungetc decrements the file
position indicator by 1; it is unspecified after ungetc at the start
of the file, and after ungetwc, so no special handling is needed for
either of those cases.

This is fixed with appropriate logic in _IO_new_file_sync.  I haven't
made any attempt to test or change things in this area for the "old"
functions; the case of files using mmap is addressed in a subsequent
patch (and there seem to be no problems in this area with files opened
with fmemopen).

Tested for x86_64.

6 months agolibio: Add a new fwrite test that evaluates partial writes
Tulio Magno Quites Machado Filho [Tue, 28 Jan 2025 18:37:44 +0000 (15:37 -0300)] 
libio: Add a new fwrite test that evaluates partial writes

Test if the file-position is correctly updated when fwrite tries to
flush its internal cache but is not able to completely write all items.

Reviewed-by: DJ Delorie <dj@redhat.com>
6 months agolibio: Start to return errors when flushing fwrite's buffer [BZ #29459]
Tulio Magno Quites Machado Filho [Tue, 28 Jan 2025 18:37:44 +0000 (15:37 -0300)] 
libio: Start to return errors when flushing fwrite's buffer [BZ #29459]

When an error happens, fwrite is expected to return a value that is less
than nmemb.  If this error happens while flushing its internal buffer,
fwrite is in a complex scenario: all the data might have been written to
the buffer, indicating a successful copy, but the buffer is expected to
be flushed and it was not.

POSIX.1-2024 states the following about errors on fwrite:

    If an error occurs, the resulting value of the file-position indicator
    for the stream is unspecified.

    The fwrite() function shall return the number of elements successfully
    written, which may be less than nitems if a write error is encountered.

With that in mind, this commit modifies _IO_new_file_write in order to
return the total number of bytes written via the file pointer.  It also
modifies fwrite in order to use the new information and return the
correct number of bytes written even when sputn returns EOF.

Add 2 tests:

1. tst-fwrite-bz29459: This test is based on the reproducer attached to
   bug 29459.  In order to work, it requires to pipe stdout to another
   process making it hard to reuse test-driver.c.  This code is more
   specific to the issue reported.
2. tst-fwrite-pipe: Recreates the issue by creating a pipe that is shared
   with a child process.  Reuses test-driver.c.  Evaluates a more generic
   scenario.

Co-authored-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: DJ Delorie <dj@redhat.com>
6 months agoAdd new tests for fopen
Martin Coufal [Thu, 23 Jan 2025 12:04:06 +0000 (13:04 +0100)] 
Add new tests for fopen

Adding some basic tests for fopen, testing different modes, stream
positioning and concurrent read/write operation on files.
Reviewed-by: DJ Delorie <dj@redhat.com>
6 months agoIncrease version to 2.41.9000, add new section to NEWS glibc-2.41.9000
Andreas K. Hüttel [Tue, 28 Jan 2025 17:42:35 +0000 (18:42 +0100)] 
Increase version to 2.41.9000, add new section to NEWS

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agoCreate ChangeLog.old/ChangeLog.30 glibc-2.41
Andreas K. Hüttel [Tue, 28 Jan 2025 17:31:33 +0000 (18:31 +0100)] 
Create ChangeLog.old/ChangeLog.30

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agoBump version to 2.41
Andreas K. Hüttel [Tue, 28 Jan 2025 17:25:13 +0000 (18:25 +0100)] 
Bump version to 2.41

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agopo: update translations (final, only timestamp and line number changes)
Andreas K. Hüttel [Tue, 28 Jan 2025 12:47:28 +0000 (13:47 +0100)] 
po: update translations (final, only timestamp and line number changes)

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agolibc.pot: regenerate (only line number changes)
Andreas K. Hüttel [Tue, 28 Jan 2025 11:36:07 +0000 (12:36 +0100)] 
libc.pot: regenerate (only line number changes)

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agoINSTALL: update last tested version numbers
Andreas K. Hüttel [Tue, 28 Jan 2025 11:31:08 +0000 (12:31 +0100)] 
INSTALL: update last tested version numbers

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agocontrib.texi: minor improvements
Andreas K. Hüttel [Mon, 27 Jan 2025 15:30:54 +0000 (16:30 +0100)] 
contrib.texi: minor improvements

Mention CORE-MATH developers by name
Fix accent

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agoNEWS: Add some more news from the 2.41 cycle
Andreas K. Hüttel [Sun, 26 Jan 2025 21:45:27 +0000 (22:45 +0100)] 
NEWS: Add some more news from the 2.41 cycle

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agocontrib.texi: Update from 2.40..2.41 commit log
Andreas K. Hüttel [Mon, 27 Jan 2025 00:06:16 +0000 (01:06 +0100)] 
contrib.texi: Update from 2.40..2.41 commit log

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agoNEWS: Add reference to (single) advisory
Andreas K. Hüttel [Sun, 26 Jan 2025 22:30:13 +0000 (23:30 +0100)] 
NEWS: Add reference to (single) advisory

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agoNEWS: Add list of bugs fixed in 2.41
Andreas K. Hüttel [Sun, 26 Jan 2025 22:26:07 +0000 (23:26 +0100)] 
NEWS: Add list of bugs fixed in 2.41

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agoNEWS: editorial changes (language, line breaks)
Andreas K. Hüttel [Sun, 26 Jan 2025 19:09:26 +0000 (20:09 +0100)] 
NEWS: editorial changes (language, line breaks)

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agotestsuite: Make stdio-common/tst-printf-format-*-mem UNSUPPORTED if the mtrace output...
Xi Ruoyao [Sat, 25 Jan 2025 16:48:27 +0000 (00:48 +0800)] 
testsuite: Make stdio-common/tst-printf-format-*-mem UNSUPPORTED if the mtrace output does not exist

When gawk was not built with MPFR, there's no mtrace output and those
tests FAIL.  But we should make them UNSUPPORTED like other
tst-printf-format-* tests in the case.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Sam James <sam@gentoo.org>
Reviewed-by: Andreas K Hüttel <dilfridge@gentoo.org>
6 months agoelf: fix 'valgrind' typo in comment
Sam James [Sat, 25 Jan 2025 05:34:20 +0000 (05:34 +0000)] 
elf: fix 'valgrind' typo in comment

6 months agomalloc: cleanup casts in tst-calloc
Sam James [Mon, 13 Jan 2025 02:27:41 +0000 (02:27 +0000)] 
malloc: cleanup casts in tst-calloc

Followup to c3d1dac96bdd10250aa37bb367d5ef8334a093a1. As pointed out by
Maciej W. Rozycki, the casts are obviously useless now.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
6 months agostdlib: Test using setenv with updated environ [BZ #32588]
H.J. Lu [Fri, 24 Jan 2025 10:53:13 +0000 (18:53 +0800)] 
stdlib: Test using setenv with updated environ [BZ #32588]

Add a test for setenv with updated environ.  Verify that BZ #32588 is
fixed.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
6 months agoLICENSES: update CORE-MATH copyright
Aurelien Jarno [Wed, 22 Jan 2025 21:11:24 +0000 (22:11 +0100)] 
LICENSES: update CORE-MATH copyright

Many more files from the CORE-MATH have been added. Also update the
authors and copyright years.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agoLICENSES: update location of getaddrinfo.c and getnameinfo.c
Aurelien Jarno [Wed, 22 Jan 2025 21:11:24 +0000 (22:11 +0100)] 
LICENSES: update location of getaddrinfo.c and getnameinfo.c

posix/getaddrinfo.c got moved into nss/getaddrinfo.c in commit
7f602256ab5b ("Move getaddrinfo from 'posix' into 'nss'")

inet/getnameinfo.c got moved into nss/getnameinfo.c in commit
2f1c 6652 d7b3 ("Move getnameinfo from 'inet' to 'nss'")

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agoLICENSES: remove Intel License Agreement
Aurelien Jarno [Wed, 22 Jan 2025 21:11:24 +0000 (22:11 +0100)] 
LICENSES: remove Intel License Agreement

The corresponding files are gone with the IA64 removal in commit
460860f457e2 ("Remove ia64-linux-gnu").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agostdlib: Re-implement free (environ) compatibility kludge for setenv
Florian Weimer [Fri, 24 Jan 2025 09:40:28 +0000 (10:40 +0100)] 
stdlib: Re-implement free (environ) compatibility kludge for setenv

For the originally failing application (userhelper from usermode),
it is not actually necessary to call realloc on the environ
pointer.  Yes, there will be a memory leak because the application
assigns a heap-allocated pointer to environ that it never frees,
but this leak was always there: the old realloc-based setenv had
a hidden internal variable, last_environ, that was used in a similar
way to __environ_array_list.  The application is not impacted by
the leak anyway because the relevant operations do not happen in
a loop.

The change here just uses a separte heap allocation and points
environ to that.  This means that if an application calls
free (environ) and restores the environ pointer to the value
at process start, and does not modify the environment further,
nothing bad happens.

This change should not invalidate any previous testing that went into
the original getenv thread safety change, commit 7a61e7f557a97ab597d6
("stdlib: Make getenv thread-safe in more cases").

The new test cases are modeled in part on the env -i use case from
bug 32588 (with !DO_MALLOC && !DO_EARLY_SETENV), and the previous
stdlib/tst-setenv-malloc test.  The DO_MALLOC && !DO_EARLY_SETENV
case in the new test should approximate what userhelper from the
usermode package does.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
6 months agoRevert "stdlib: Support malloc-managed environ arrays for compatibility"
Florian Weimer [Fri, 24 Jan 2025 07:04:23 +0000 (08:04 +0100)] 
Revert "stdlib: Support malloc-managed environ arrays for compatibility"

This reverts commit b62759db04b8ed7f829c06f1d7c3b8fb70616493.

Reason for revert: Incompatible with “env -i” and coreutils (bug 32588).

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
6 months agostdlib: Support malloc-managed environ arrays for compatibility
Florian Weimer [Wed, 22 Jan 2025 12:48:56 +0000 (13:48 +0100)] 
stdlib: Support malloc-managed environ arrays for compatibility

Some applications set environ to a heap-allocated pointer, call
setenv (expecting it to call realloc), free environ, and then
restore the original environ pointer.  This breaks after
commit 7a61e7f557a97ab597d6fca5e2d1f13f65685c61 ("stdlib: Make
getenv thread-safe in more cases") because after the setenv call,
the environ pointer does not point to the start of a heap allocation.
Instead, setenv creates a separate allocation and changes environ
to point into that.  This means that the free call in the application
results in heap corruption.

The interim approach was more compatible with other libcs because
it does not assume that the incoming environ pointer is allocated
as if by malloc (if it was written by the application).  However,
it seems to be more important to stay compatible with previous
glibc version: assume the incoming pointer is heap allocated,
and preserve this property after setenv calls.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
6 months agopo: Incorporate translations
Andreas K. Hüttel [Wed, 22 Jan 2025 21:50:23 +0000 (22:50 +0100)] 
po: Incorporate translations

be ca cs da de el eo es fi fr gl hr hu ia id it ja ka ko lt nb nl pl pt ro ru rw sk sl sr sv tr uk vi zh_CN zh_TW

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
6 months agoUpdate advisory GLIBC-SA-2025-0001 (2.40)
Siddhesh Poyarekar [Wed, 22 Jan 2025 14:40:52 +0000 (09:40 -0500)] 
Update advisory GLIBC-SA-2025-0001 (2.40)

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
6 months agoAdd advisory text for CVE-2025-0395
Siddhesh Poyarekar [Tue, 21 Jan 2025 21:48:29 +0000 (16:48 -0500)] 
Add advisory text for CVE-2025-0395

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

6 months agoFix underallocation of abort_msg_s struct (CVE-2025-0395)
Siddhesh Poyarekar [Tue, 21 Jan 2025 21:11:06 +0000 (16:11 -0500)] 
Fix underallocation of abort_msg_s struct (CVE-2025-0395)

Include the space needed to store the length of the message itself, in
addition to the message string.  This resolves BZ #32582.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

6 months agoNEWS: Add note on Guarded Control Stack support
Yury Khrustalev [Tue, 21 Jan 2025 13:44:05 +0000 (13:44 +0000)] 
NEWS: Add note on Guarded Control Stack support

Reviewed-by: Andreas K. Huettel <dilfridge@gentoo.org>
6 months agoFix typo: _POSIX_REATIME_SIGNALS -> _POSIX_REALTIME_SIGNALS [BZ# 32515]
Paul Pluzhnikov [Mon, 20 Jan 2025 21:47:38 +0000 (21:47 +0000)] 
Fix typo: _POSIX_REATIME_SIGNALS -> _POSIX_REALTIME_SIGNALS [BZ# 32515]

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agoaarch64: Add HWCAP_GCS
Yury Khrustalev [Tue, 21 Jan 2025 09:39:45 +0000 (09:39 +0000)] 
aarch64: Add HWCAP_GCS

Use upper 32 bits of HWCAP.

Reviewed-by: Andreas K. Huettel <dilfridge@gentoo.org>
6 months agonptl: Include <stdbool.h> in tst-skeleton-affinity-inheritance.c
Florian Weimer [Tue, 21 Jan 2025 09:36:58 +0000 (10:36 +0100)] 
nptl: Include <stdbool.h> in tst-skeleton-affinity-inheritance.c

The file uses the identifiers bool, false, true.

6 months agostdlib: Test for expected sequence of random numbers from rand
Florian Weimer [Mon, 20 Jan 2025 20:06:59 +0000 (21:06 +0100)] 
stdlib: Test for expected sequence of random numbers from rand

As the test comment explains, this test is not quite valid, but
preserving the exact sequences helps distributions to port to
newer glibc versions.  We can remove this test if we ever switch
to a different implementation.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
6 months agostdlib: Fix unintended change to the random_r implementation
Florian Weimer [Mon, 20 Jan 2025 20:06:43 +0000 (21:06 +0100)] 
stdlib: Fix unintended change to the random_r implementation

Commit d5bceac99d24af1131b90027dab267e437b65cd1 changed the sequence
of random numbers.  This was completely unintended.  The statistical
properties of the new sequences are unclear, so restore the old
behavior.

Fixes commit d5bceac99d24af1131b90027dab267e437b65cd1 ("stdlib:
random_r: fix unaligned access in initstate and initstate_r
[BZ #30584]").

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
6 months agoelf: Make tst-ro-dynamic-mod.map compatible with older binutils
Florian Weimer [Mon, 20 Jan 2025 19:35:10 +0000 (20:35 +0100)] 
elf: Make tst-ro-dynamic-mod.map compatible with older binutils

Older versions such as binutils 2.35.2 do not recognize
PT_GNU_PROPERTY.

Fixes commit d3f2b71ef1d146137a25dd1367d97a14fac341c6
("aarch64: Fix tests not compatible with targets supporting GCS").

6 months agoNEWS: Add the extensible rseq ABI to new features
Michael Jeanson [Tue, 14 Jan 2025 20:03:56 +0000 (15:03 -0500)] 
NEWS: Add the extensible rseq ABI to new features

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
6 months agoLinux: Do not check unused bytes after sched_getattr in tst-sched_setattr
Florian Weimer [Mon, 20 Jan 2025 08:57:09 +0000 (09:57 +0100)] 
Linux: Do not check unused bytes after sched_getattr in tst-sched_setattr

Linux 6.13 was released with a change that overwrites those bytes.
This means that the check_unused subtest fails.

Update the manual accordingly.

Tested-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
6 months agoi386: Update ulps for *pi functions
Florian Weimer [Mon, 20 Jan 2025 10:33:58 +0000 (11:33 +0100)] 
i386: Update ulps for *pi functions

As seen with GCC 11.5 on an AMD Ryzen 9 7950X CPU, with an
-fpmath=sse, --disable-multi-arch build of glibc.

6 months agoaarch64: Fix tests not compatible with targets supporting GCS
Yury Khrustalev [Tue, 26 Nov 2024 11:38:30 +0000 (11:38 +0000)] 
aarch64: Fix tests not compatible with targets supporting GCS

 - Add GCS marking to some of the tests when target supports GCS
 - Fix tst-ro-dynamic-mod.map linker script to avoid removing
   GNU properties
 - Add header with macros for GNU properties

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
6 months agoaarch64: Use __alloc_gcs in makecontext
Szabolcs Nagy [Wed, 28 Aug 2024 10:00:19 +0000 (11:00 +0100)] 
aarch64: Use __alloc_gcs in makecontext

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