]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
3 months agolinux: Do not spawn a new thread for SIGEV_THREAD (BZ 30558, 27895, 29705, 32833) azanella/bz30558-posix_timer
Adhemerval Zanella [Mon, 19 Jun 2023 17:11:58 +0000 (14:11 -0300)] 
linux: Do not spawn a new thread for SIGEV_THREAD (BZ 30558, 27895, 29705, 32833)

The current timer_create SIGEV_THREAD implementation has some
downsides:

  1. There is no way to report failure at thread creation when a
     timer triggers.  It means that it might occur unreported and with
     missed events depending of the system load.

  2. The backgroup thread also kept in backgroun even when there is no
     more timers, consuming resources and also misleading memory
     profile tools (BZ 29705).

  3. There is a lot of metadata that required to be kept: a control
     variable for helper thread creation, a list of active SIGEV_THREAD
     timers, atfork handlers to cleanup the list.

  4. timer_create does not propagate all thread attributes to the new
     thread (BZ 27895).

  5. Kernel might deliver in-flight events for a timer after it was
     destroyed by timer_delete.  The timer_helper_thread mechanism to
     handle it does not cover all possible issue, which leads to
     callbacks being wrong triggered (BZ 32833).

This new implementation moves the thread creation to timer_create, so
any failure is reported to the caller.  Also, the same thread will
issues the multiple timers, thus there is no unreported missed events.
Also, avoiding parallel timer activation also avoid possible parallel
timer invocation to see the same overrun value.

To implement using SIGTIMER internally as SIGCANCEL, it requires to
mask out SIGCANCEL on thread creation.  It essentially disable async
thread cancellation, but POSIX requires that SIGEV_THREAD is always
created in detached mode and cancelling detached thread s UB (glibc
check the internal tid, but the memory referenced by pthread_t might
not always be valid as the momento of pthread_cancel call).

And to avoid the need to recreate the thread for pthread_exit call
(and having possible unreported missed due failed thread creation),
the SIGEV_THREAD install a cleanup handler that reset all internal
thread state.

It also prevents the re-use issue when a newly-allocated timer has
in-flight event being delivered by the kernel (BZ 32833).

Performance-wise it see it uses less CPU timer for multiple thread
activation, although each thread now requires a sigwaitinfo which
generate more context-switches/page-faults (check comment 7 from
BZ 30558).  I would expect that latency should improve, since it
avoid a thread creation for each timer expiration.

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

3 months agostdlib: Fix qsort memory leak if callback throws (BZ 32058)
Adhemerval Zanella [Thu, 27 Mar 2025 15:30:48 +0000 (12:30 -0300)] 
stdlib: Fix qsort memory leak if callback throws (BZ 32058)

If the input buffer exceeds the stack auxiliary buffer, qsort will
malloc a temporary one to call mergesort.  Since C++ standard does
allow the callback comparison function to throw [1], the glibc
implementation can potentially leak memory.

The fixes uses a pthread_cleanup_combined_push and
pthread_cleanup_combined_pop, so it can work with and without
exception enables.  The qsort code path that calls malloc now
requires some extra setup and a call to __pthread_cleanup_push
anmd __pthread_cleanup_pop (which should be ok since they just
setup some buffer state).

Checked on x86_64-linux-gnu.

[1] https://timsong-cpp.github.io/cppwp/n4950/alg.c.library#4

Reviewed-by: DJ Delorie <dj@redhat.com>
3 months agosysdeps: powerpc: restore -mlong-double-128 check
Sam James [Tue, 1 Apr 2025 20:56:52 +0000 (21:56 +0100)] 
sysdeps: powerpc: restore -mlong-double-128 check

We mistakenly dropped the check in 27b96e069aad17cefea9437542180bff448ac3a0;
there's some other checks which we *can* drop, but let's worry about that
later.

Fixes the build on ppc64le where GCC is configured with --with-long-double-format=ieee.

Reviewed-by: Andreas Schwab <schwab@suse.de>
3 months agostdio: Add more setvbuf tests
DJ Delorie [Fri, 14 Mar 2025 20:08:35 +0000 (16:08 -0400)] 
stdio: Add more setvbuf tests

3 months agoadd ptmx support to test-container
DJ Delorie [Fri, 14 Mar 2025 20:08:12 +0000 (16:08 -0400)] 
add ptmx support to test-container

3 months agoUpdate syscall lists for Linux 6.14
Joseph Myers [Tue, 1 Apr 2025 12:44:26 +0000 (12:44 +0000)] 
Update syscall lists for Linux 6.14

Linux 6.14 has no new syscalls.  Update the version number in
syscall-names.list to reflect that it is still current for 6.14.

Tested with build-many-glibcs.py.

4 months agox86: Link tst-gnu2-tls2-x86-noxsave{,c,xsavec} with libpthread
Florian Weimer [Mon, 31 Mar 2025 19:33:18 +0000 (21:33 +0200)] 
x86: Link tst-gnu2-tls2-x86-noxsave{,c,xsavec} with libpthread

This fixes a test build failure on Hurd.

Fixes commit 145097dff170507fe73190e8e41194f5b5f7e6bf ("x86: Use separate
variable for TLSDESC XSAVE/XSAVEC state size (bug 32810)").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agoelf: Fix tst-origin build when toolchain defaults to --as-needed (BZ 32823)
John David Anglin [Mon, 31 Mar 2025 16:48:32 +0000 (13:48 -0300)] 
elf: Fix tst-origin build when toolchain defaults to --as-needed (BZ 32823)

Checked on aarch64-linux-gnu.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoRaise the minimum GCC version to 12.1 [BZ #32539]
H.J. Lu [Wed, 12 Feb 2025 04:53:09 +0000 (12:53 +0800)] 
Raise the minimum GCC version to 12.1 [BZ #32539]

For all Linux distros with glibc 2.40 which I can find, GCC 14.2 is used
to compile glibc 2.40:

OS                    GCC      URL
AOSC                  14.2.0   https://aosc.io/
Arch Linux            14.2.0   https://archlinux.org/
ArchPOWER             14.2.0   https://archlinuxpower.org/
Artix                 14.2.0   https://artixlinux.org/
Debian                14.2.0   https://www.debian.org/
Devuan                14.2.0   https://www.devuan.org/
Exherbo               14.2.0   https://www.exherbolinux.org/
Fedora                14.2.1   https://fedoraproject.org/
Gentoo                14.2.1   https://gentoo.org/
Kali Linux            14.2.0   https://www.kali.org/
KaOS                  14.2.0   https://kaosx.us/
LiGurOS               14.2.0   https://liguros.gitlab.io/
Mageia                14.2.0   https://www.mageia.org/en/
Manjaro               14.2.0   https://manjaro.org/
NixOS                 14.2.0   https://nixos.org/
openmamba             14.2.0   https://openmamba.org/
OpenMandriva          14.2.0   https://openmandriva.org/
openSUSE              14.2.0   https://www.opensuse.org/
Parabola              14.2.0   https://www.parabola.nu/
PLD Linux             14.2.0   https://pld-linux.org/
PureOS                14.2.0   https://pureos.net/
Raspbian              14.2.0   http://raspbian.org/
Slackware             14.2.0   http://www.slackware.com/
Solus                 14.2.0   https://getsol.us/
T2 SDE                14.2.0   http://t2sde.org/
Ubuntu                14.2.0   https://www.ubuntu.com/
Wikidata              14.2.0   https://wikidata.org/

Support older versions of GCC to build glibc 2.42:

1. Need to work around bugs in older versions of GCC.
2. Can't use the new features in newer versions of GCC, which may be
required for new features, like _Float16 which requires GCC 12.1 or
above, in glibc,

The main benefit of supporting older versions of GCC is easier backport
of bug fixes to the older releases of glibc, which can be mitigated by
avoiding incompatible features in newer versions of GCC for critical bug
fixes.  Require GCC 12.1 or newer to build.  Remove GCC version check for
PowerPC and s390x.

TEST_CC and TEST_CXX can be used to test the glibc build with the older
versions of GCC.

For glibc developers who are using Linux OSes which don't come with GCC
12.1 or newer, they should build and install GCC 12.1 or newer to work
on glibc.

This fixes BZ #32539.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
4 months agoFix typo in comment
YLK [Mon, 24 Mar 2025 14:04:21 +0000 (22:04 +0800)] 
Fix typo in comment

4 months agomanual: tidy the longopt.c example
Samuel Zeter [Tue, 25 Mar 2025 08:00:33 +0000 (18:00 +1000)] 
manual: tidy the longopt.c example

- Change longopt.c's backticks to single quotes
- puts() does not use format specifiers

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agomanual: Document functions adopted by POSIX.1-2024.
Collin Funk [Thu, 27 Mar 2025 06:36:30 +0000 (23:36 -0700)] 
manual: Document functions adopted by POSIX.1-2024.

Here is a patch updating the documentation to mention GNU and BSD
extensions that were adopted by POSIX.1-2024.

* manual/llio.texi (Memory-mapped I/O): Add that MAP_ANON and
MAP_ANONYMOUS were added by POSIX.1-2024.
* manual/memory.texi (Changing Block Size): Mention that reallocarray
was added by POSIX.1-2024.
* manual/message.texi (Message Translation): Adjust wording to match
standardization.
(Translation with gettext): Mention the gettext family of functions were
added by POSIX.1-2024.
* manual/pattern.texi (Wildcard Matching): Mention that FNM_CASEFOLD was
added by POSIX.1-2024.
* manual/process.texi (Creating a Process): Mention that _Fork and
WCOREDUMP were added by POSIX.1-2024.
* manual/signal.texi (Miscellaneous Signals): Mention that SIGWINCH was
added by POSIX-1.2024.
* manual/startup.texi (Environment Access): Mention that secure_getenv
was added by POSIX.1-2024.
* manual/string.texi (Truncating Strings): Mention that strlcpy,
strlcat, wcslcpy, and wslcat were added by POSIX-1.2024.
(Search Functions): Document that memmem was added by POSIX-1.2024.
* manual/terminal.texi (Allocation): Mention that ptsname_r was added by
POSIX-1.2024.
* manual/threads.texi (Waiting with Explicit Clocks): Move node under
POSIX Threads.  Mention pthread_cond_clockwait,
pthread_rwlock_clockrdlock, and pthread_rwlock_clockwrlock were added by
POSIX-1.2024.
(Joining Threads): New node under Non-POSIX Extensions.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Collin Funk <collin.funk1@gmail.com>
4 months agoaarch64: Fix _dl_tlsdesc_dynamic unwind for pac-ret (BZ 32612)
Adhemerval Zanella [Fri, 28 Mar 2025 17:27:45 +0000 (14:27 -0300)] 
aarch64: Fix _dl_tlsdesc_dynamic unwind for pac-ret (BZ 32612)

When libgcc is built with pac-ret, it requires to autenticate the
unwinding frame based on CFI information.  The _dl_tlsdesc_dynamic
uses a custom calling convention, where it is responsible to save
and restore all registers it might use (even volatile).

The pac-ret support added by 1be3d6eb823d8b952fa54b7bbc90cbecb8981380
was added only on the slow-path, but the fast path also adds DWARF
Register Rule Instruction (cfi_adjust_cfa_offset) since it requires
to save/restore some auxiliary register.  It seems that this is not
fully supported neither by libgcc nor AArch64 ABI [1].

Instead, move paciasp/autiasp to function prologue/epilogue to be
used on both fast and slow paths.

I also corrected the _dl_tlsdesc_dynamic comment description, it was
copied from i386 implementation without any adjustment.

Checked on aarch64-linux-gnu with a toolchain built with
--enable-standard-branch-protection on a system with pac-ret
support.

[1]  https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#id1

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
4 months agox86: Use separate variable for TLSDESC XSAVE/XSAVEC state size (bug 32810)
Florian Weimer [Fri, 28 Mar 2025 08:26:59 +0000 (09:26 +0100)] 
x86: Use separate variable for TLSDESC XSAVE/XSAVEC state size (bug 32810)

Previously, the initialization code reused the xsave_state_full_size
member of struct cpu_features for the TLSDESC state size.  However,
the tunable processing code assumes that this member has the
original XSAVE (non-compact) state size, so that it can use its
value if XSAVEC is disabled via tunable.

This change uses a separate variable and not a struct member because
the value is only needed in ld.so and the static libc, but not in
libc.so.  As a result, struct cpu_features layout does not change,
helping a future backport of this change.

Fixes commit 9b7091415af47082664717210ac49d51551456ab ("x86-64:
Update _dl_tlsdesc_dynamic to preserve AMX registers").

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 months agox86: Skip XSAVE state size reset if ISA level requires XSAVE
Florian Weimer [Fri, 28 Mar 2025 08:26:06 +0000 (09:26 +0100)] 
x86: Skip XSAVE state size reset if ISA level requires XSAVE

If we have to use XSAVE or XSAVEC trampolines, do not adjust the size
information they need.  Technically, it is an operator error to try to
run with -XSAVE,-XSAVEC on such builds, but this change here disables
some unnecessary code with higher ISA levels and simplifies testing.

Related to commit befe2d3c4dec8be2cdd01a47132e47bdb7020922
("x86-64: Don't use SSE resolvers for ISA level 3 or above").

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 months agomalloc: Improve performance of __libc_malloc
Wilco Dijkstra [Thu, 20 Mar 2025 20:04:14 +0000 (20:04 +0000)] 
malloc: Improve performance of __libc_malloc

Improve performance of __libc_malloc by splitting it into 2 parts: first handle
the tcache fastpath, then do the rest in a separate tailcalled function.
This results in significant performance gains since __libc_malloc doesn't need
to setup a frame and we delay tcache initialization and setting of errno until
later.

On Neoverse V2, bench-malloc-simple improves by 6.7% overall (up to 8.5% for
ST case) and bench-malloc-thread improves by 20.3% for 1 thread and 14.4% for
32 threads.

Reviewed-by: DJ Delorie <dj@redhat.com>
4 months agostdio-common: Reject real data w/o exponent digits in scanf [BZ #12701]
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:53 +0000 (12:35 +0000)] 
stdio-common: Reject real data w/o exponent digits in scanf [BZ #12701]

Reject invalid formatted scanf real input data the exponent part of
which is comprised of an exponent introducing character, optionally
followed by a sign, and with no actual digits following.  Such data is a
prefix of, but not a matching input sequence and it is required by ISO C
to cause a matching failure.

Currently a matching success is instead incorrectly produced along with
the conversion result according to the input significand read and the
exponent of zero, with the significand and the exponent part wholly
consumed from input.

Correct an invalid `tstscanf.c' test accordingly that expects a matching
success for input data provided in the ISO C standard as an example for
a matching failure.

Enable input data that causes test failures without this fix in place.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Reject significand prefixes in scanf [BZ #12701]
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:53 +0000 (12:35 +0000)] 
stdio-common: Reject significand prefixes in scanf [BZ #12701]

Reject invalid formatted scanf real input data that is comprised of a
hexadecimal prefix, optionally preceded by a sign, and with no actual
digits following owing to the field width restriction in effect.  Such
data is a prefix of, but not a matching input sequence and it is
required by ISO C to cause a matching failure.

Currently a matching success is instead incorrectly produced along with
the conversion result of zero, with the prefix wholly consumed from
input.  Where the end of input is marked by the end-of-file condition
rather than the field width restriction in effect a matching failure is
already correctly produced.

Enable input data that causes test failures without this fix in place.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Reject integer prefixes in scanf [BZ #12701]
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:53 +0000 (12:35 +0000)] 
stdio-common: Reject integer prefixes in scanf [BZ #12701]

Reject invalid formatted scanf integer input data that is comprised of a
binary or hexadecimal prefix, optionally preceded by a sign, and with no
actual digits following.  Such data is a prefix of, but not a matching
input sequence and it is required by ISO C to cause a matching failure.

Currently a matching success is instead incorrectly produced along with
the conversion result of zero, with the prefix wholly consumed from
input.

Enable input data that causes test failures without this fix in place.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Also reject exp char w/o significand in i18n scanf [BZ #13988]
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:53 +0000 (12:35 +0000)] 
stdio-common: Also reject exp char w/o significand in i18n scanf [BZ #13988]

Fix the handling of real 'scanf' input such as "+.e" as per BZ #13988
for the i18n case as well, complementing commit 6ecec3b616ae ("Don't
accept exp char without preceding digits in scanf float parsing"), where
the 'e' character is incorrectly consumed from input.  Add a test case
matching stdio-common/bug26.c, with bits from localedata/tst-sscanf.c.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add tests for formatted vsscanf input specifiers
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:53 +0000 (12:35 +0000)] 
stdio-common: Add tests for formatted vsscanf input specifiers

Wire vsscanf into test infrastructure for formatted scanf input
specifiers.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add tests for formatted vfscanf input specifiers
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:53 +0000 (12:35 +0000)] 
stdio-common: Add tests for formatted vfscanf input specifiers

Wire vfscanf into test infrastructure for formatted scanf input
specifiers.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add tests for formatted vscanf input specifiers
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:52 +0000 (12:35 +0000)] 
stdio-common: Add tests for formatted vscanf input specifiers

Wire vscanf into test infrastructure for formatted scanf input
specifiers.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add tests for formatted sscanf input specifiers
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:52 +0000 (12:35 +0000)] 
stdio-common: Add tests for formatted sscanf input specifiers

Wire sscanf into test infrastructure for formatted scanf input
specifiers.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add tests for formatted fscanf input specifiers
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:52 +0000 (12:35 +0000)] 
stdio-common: Add tests for formatted fscanf input specifiers

Wire fscanf into test infrastructure for formatted scanf input
specifiers.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add scanf long double data for Intel/Motorola 80-bit format
Maciej W. Rozycki [Fri, 28 Mar 2025 12:35:52 +0000 (12:35 +0000)] 
stdio-common: Add scanf long double data for Intel/Motorola 80-bit format

Add Makefile infrastructure, a format-specific test skeleton providing a
data comparison implementation that ignores bits of data representation
in memory that do not participate in holding floating-point data, and
`long double' real input data for targets using the Intel/Motorola
80-bit format.

Keep input data disabled and referring to BZ #12701 for entries that are
are currently incorrectly accepted as valid data, such as '0e', '0e+',
'0x', '0x8p', '0x0p-', etc.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agoImplement C23 pown
Joseph Myers [Thu, 27 Mar 2025 10:44:44 +0000 (10:44 +0000)] 
Implement C23 pown

C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the pown functions, which are like pow but with an
integer exponent.  That exponent has type long long int in C23; it was
intmax_t in TS 18661-4, and as with other interfaces changed after
their initial appearance in the TS, I don't think we need to support
the original version of the interface.  The test inputs are based on
the subset of test inputs for pow that use integer exponents that fit
in long long.

As the first such template implementation that saves and restores the
rounding mode internally (to avoid possible issues with directed
rounding and intermediate overflows or underflows in the wrong
rounding mode), support also needed to be added for using
SET_RESTORE_ROUND* in such template function implementations.  This
required math-type-macros-float128.h to include <fenv_private.h>, so
it can tell whether SET_RESTORE_ROUNDF128 is defined.  In turn, the
include order with <fenv_private.h> included before <math_private.h>
broke loongarch builds, showing up that
sysdeps/loongarch/math_private.h is really a fenv_private.h file
(maybe implemented internally before the consistent split of those
headers in 2018?) and needed to be renamed to fenv_private.h to avoid
errors with duplicate macro definitions if <math_private.h> is
included after <fenv_private.h>.

The underlying implementation uses __ieee754_pow functions (called
more than once in some cases, where the exponent does not fit in the
floating type).  I expect a custom implementation for a given format,
that only handles integer exponents but handles larger exponents
directly, could be faster and more accurate in some cases.

I encourage searching for worst cases for ulps error for these
implementations (necessarily non-exhaustively, given the size of the
input space).

Tested for x86_64 and x86, and with build-many-glibcs.py.

4 months agosupport: Use unwinder in links-dso-program-c only with libgcc_s
Florian Weimer [Wed, 26 Mar 2025 16:46:40 +0000 (17:46 +0100)] 
support: Use unwinder in links-dso-program-c only with libgcc_s

Do not build links-dso-program-c with exception (unwinding) support
if libgcc_s is not available.  In this case, the unwinder may be
part of libgcc.a or libgcc_eh.a, depending on how GCC was built.
If the unwinder is in libgcc_eh.a only, linking links-dso-program-c
failed before this change.  After this change, the exception
handling landing pad is only generated if libgcc_s available,
avoiding an undefined _Unwind_Resume (or equivalent) symbol
reference in the non-libgcc_s case.

Fixes commit ffd36cc27407003a6f9efcb9c16370e3435c5b1d ("support: Use
unwinder in links-dso-program-c only with libgcc_s") and
commit 5dfbc3c43ecc1bcfc760a032c91bb002660051bc ("support: Link
links-dso-program-c with libgcc_s only if available").

4 months agomalloc: Use __always_inline for simple functions
Wilco Dijkstra [Thu, 20 Mar 2025 16:36:52 +0000 (16:36 +0000)] 
malloc: Use __always_inline for simple functions

Use __always_inline for small helper functions that are critical for
performance.  This ensures inlining always happens when expected.
Performance of bench-malloc-simple improves by 0.6% on average on
Neoverse V2.

Reviewed-by: DJ Delorie <dj@redhat.com>
4 months agolinux: Fix integer overflow warnings when including <sys/mount.h> [BZ #32708]
Collin Funk [Tue, 25 Mar 2025 15:17:55 +0000 (11:17 -0400)] 
linux: Fix integer overflow warnings when including <sys/mount.h> [BZ #32708]

Using gcc -Wshift-overflow=2 -Wsystem-headers to compile a file
including <sys/mount.h> will cause a warning since 1 << 31 is undefined
behavior on platforms where int is 32-bits.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
4 months agomalloc: Use _int_free_chunk for remainders
Wilco Dijkstra [Thu, 20 Mar 2025 16:23:07 +0000 (16:23 +0000)] 
malloc: Use _int_free_chunk for remainders

When splitting a chunk, release the tail part by calling int_free_chunk.
This avoids inserting random blocks into tcache that were never requested
by the user.  Fragmentation will be worse if they are never used again.
Note if the tail is fairly small, we could avoid splitting it at all.
Also remove an oddly placed initialization of tcache in _libc_realloc.

Reviewed-by: DJ Delorie <dj@redhat.com>
4 months agoUse MPFR 4.2.2 and Linux 6.14 in build-many-glibcs.py
Joseph Myers [Tue, 25 Mar 2025 18:29:01 +0000 (18:29 +0000)] 
Use MPFR 4.2.2 and Linux 6.14 in build-many-glibcs.py

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

4 months agostdio-common: Add scanf long double data for IBM 128-bit format
Maciej W. Rozycki [Tue, 25 Mar 2025 09:40:20 +0000 (09:40 +0000)] 
stdio-common: Add scanf long double data for IBM 128-bit format

Add Makefile infrastructure and IBM 128-bit 'long double' real input for
targets switching between the IEEE 754 binary128 and IBM 128-bit formats
with '-mabi=ieeelongdouble' and '-mabi=ibmlongdouble'.  Reuse IEEE 754
binary128 input data but with modified output file names so as not to
clash with the names used for IBM 128-bit format tests made with common
rules for the 'long double' data type.

Keep input data disabled and referring to BZ #12701 for entries that are
are currently incorrectly accepted as valid data, such as '0e', '0e+',
'0x', '0x8p', '0x0p-', etc.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add scanf long double data for IEEE 754 binary64 format
Maciej W. Rozycki [Tue, 25 Mar 2025 09:40:20 +0000 (09:40 +0000)] 
stdio-common: Add scanf long double data for IEEE 754 binary64 format

Add Makefile infrastructure and 64-bit `long double' real input data for
targets switching between the IEEE 754 binary64 and IEEE 754 binary128
formats with `-mlong-double-64' and `-mlong-double-128'.  Use modified
output file names for the IEEE 754 binary64 format so as not to clash
with the names used for IEEE 754 binary128 format tests made with common
rules for the 'long double' data type.

Keep input data disabled and referring to BZ #12701 for entries that are
are currently incorrectly accepted as valid data, such as '0e', '0e+',
'0x', '0x8p', '0x0p-', etc.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add scanf long double data for IEEE 754 binary128 format
Maciej W. Rozycki [Tue, 25 Mar 2025 09:40:20 +0000 (09:40 +0000)] 
stdio-common: Add scanf long double data for IEEE 754 binary128 format

Add Makefile infrastructure and `long double' real input data for
targets using the IEEE 754 binary128 format.

Keep input data disabled and referring to BZ #12701 for entries that are
are currently incorrectly accepted as valid data, such as '0e', '0e+',
'0x', '0x8p', '0x0p-', etc.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add scanf double data for IEEE 754 binary64 format
Maciej W. Rozycki [Tue, 25 Mar 2025 09:40:20 +0000 (09:40 +0000)] 
stdio-common: Add scanf double data for IEEE 754 binary64 format

Add Makefile infrastructure and `double' real input data for targets
using the IEEE 754 binary64 format.

Keep input data disabled and referring to BZ #12701 for entries that are
are currently incorrectly accepted as valid data, such as '0e', '0e+',
'0x', '0x8p', '0x0p-', etc.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add scanf float data for IEEE 754 binary32 format
Maciej W. Rozycki [Tue, 25 Mar 2025 09:40:20 +0000 (09:40 +0000)] 
stdio-common: Add scanf float data for IEEE 754 binary32 format

Add Makefile infrastructure and `float' real input data for targets
using the IEEE 754 binary32 format.

Keep input data disabled and referring to BZ #12701 for entries that are
are currently incorrectly accepted as valid data, such as '0e', '0e+',
'0x', '0x8p', '0x0p-', etc.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add scanf integer data for LP64 targets
Maciej W. Rozycki [Tue, 25 Mar 2025 09:40:20 +0000 (09:40 +0000)] 
stdio-common: Add scanf integer data for LP64 targets

Add Makefile infrastructure and `int' and `long' integer input data,
signed and unsigned, for LP64 targets.

While the size of `int' data is the same between ILP32 and LP64 targets,
resulting scanf output is different between them for out of range input
data and while ISO C and POSIX both say that the behavior is undefined
if the result of the conversion cannot be represented we want to keep
track of our output to prevent inadvertent changes.  Hence the use of
distinct `int' integer input data between ILP32 and LP64 targets.

Keep input data disabled and referring to BZ #12701 for entries that are
are currently incorrectly accepted as valid data, such as '0b' or '0x'.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add scanf integer data for ILP32 targets
Maciej W. Rozycki [Tue, 25 Mar 2025 09:40:20 +0000 (09:40 +0000)] 
stdio-common: Add scanf integer data for ILP32 targets

Add Makefile infrastructure and `int' and `long' integer input data,
signed and unsigned, for ILP32 targets.

While the size of `int' data is the same between ILP32 and LP64 targets,
resulting scanf output is different between them for out of range input
data and while ISO C and POSIX both say that the behavior is undefined
if the result of the conversion cannot be represented we want to keep
track of our output to prevent inadvertent changes.  Hence the use of
distinct `int' integer input data between ILP32 and LP64 targets.

Keep input data disabled and referring to BZ #12701 for entries that are
are currently incorrectly accepted as valid data, such as '0b' or '0x'.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agostdio-common: Add tests for formatted scanf input specifiers
Maciej W. Rozycki [Tue, 25 Mar 2025 09:40:20 +0000 (09:40 +0000)] 
stdio-common: Add tests for formatted scanf input specifiers

Add a collection of tests for formatted scanf input specifiers covering
the b, d, i, o, u, x, and X integer conversions, the a, A, e, E, f, F,
g, and G floating-point conversions, and the [, c, and s character
conversions.  Also the hh, h, l, and ll length modifiers are covered
with the integer conversions as are the l and L length modifier with the
floating-point conversions.  The tests cover assignment suppressing and
the field width as well, verifying the number of assignments made, the
number of characters consumed and the value assigned.

Add the common test code here as well as test cases for scanf, and then
base Makefile infrastructure plus target-agnostic input data, for the
character conversions and the `char', `short', and `long long' integer
ones, signed and unsigned, with remaining input data and other functions
from the scanf family deferred to subsequent additions.

Keep input data disabled and referring to BZ #12701 for entries that are
currently incorrectly accepted as valid data, such as '0b' or '0x' with
the relevant integer conversions or sequences of an insufficient number
of characters with the c conversion.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agomach: Use the host_get_time64 to replace the deprecated host_get_time for CLOCK_REALT...
Zhaoming Luo [Mon, 24 Mar 2025 05:20:42 +0000 (13:20 +0800)] 
mach: Use the host_get_time64 to replace the deprecated host_get_time for CLOCK_REALTIME when it's available

Check the availability of host_get_time64 and use it to replace
host_get_time for CLOCK_REALTIME when it's available. Fall back to
host_get_time if gnumach does not support host_get_time64 but the
gnumach headers do.

host_get_time is deprecated
See https://git.savannah.gnu.org/cgit/hurd/gnumach.git/commit/?id=569df850cd7badd1e36132ad3b44aa76a4d27c25
However, it's kept for backward compactbility.

* config.h.in: Add HAVE_HOST_GET_TIME64 config entry.
* sysdeps/mach/clock_gettime.c: Use host_get_time64 for CLOCK_REALTIME
  when it's possible, fall to host_get_time otherwise.
* sysdeps/mach/configure: Check the existence of host_get_time64 RPC.
* sysdeps/mach/configure.ac: Check the existence of host_get_time64 RPC.
Message-ID: <20250324052042.19803-1-zhmingluo@163.com>

4 months agoaio_suspend64: Fix clock discrepancy [BZ #32795]
Samuel Thibault [Sun, 9 Mar 2025 21:25:14 +0000 (22:25 +0100)] 
aio_suspend64: Fix clock discrepancy [BZ #32795]

cc5d5852c65e ("y2038: Convert aio_suspend to support 64 bit time")
switched from __clock_gettime (CLOCK_REALTIME, &now); to __clock_gettime64
(CLOCK_MONOTONIC, &ts);, but pthread_cond_timedwait is based on the
absolute realtime clock, so migrate to using pthread_cond_clockwait to
select CLOCK_MONOTONIC. Also fix AIO_MISC_WAIT into passing
CLOCK_MONOTONIC to __futex_abstimed_wait64.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agoAdd _FORTIFY_SOURCE support for inet_pton
Aaron Merey [Thu, 20 Mar 2025 17:13:33 +0000 (13:13 -0400)] 
Add _FORTIFY_SOURCE support for inet_pton

Add function __inet_pton_chk which calls __chk_fail when the size of
argument dst is too small.   inet_pton is redirected to __inet_pton_chk
or __inet_pton_warn when _FORTIFY_SOURCE is > 0.

Also add tests to debug/tst-fortify.c, update the abilist with
__inet_pton_chk and mention inet_pton fortification in maint.texi.

Co-authored-by: Frédéric Bérat <fberat@redhat.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoPrepare inet_pton to be fortified
Aaron Merey [Thu, 20 Mar 2025 15:07:05 +0000 (11:07 -0400)] 
Prepare inet_pton to be fortified

Split inet_pton internals such as __inet_pton_length from the
inet_pton entry point.

This allows the internals to be built with fortification while
leaving the inet_pton entry point unchanged.

Co-authored-by: Frédéric Bérat <fberat@redhat.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoUpdate kernel version to 6.13 in header constant tests
Joseph Myers [Mon, 24 Mar 2025 15:51:23 +0000 (15:51 +0000)] 
Update kernel version to 6.13 in header constant tests

There are no new constants covered by tst-mman-consts.py,
tst-mount-consts.py or tst-sched-consts.py in Linux 6.13 that need any
header changes, so update the kernel version in those tests.
(tst-pidfd-consts.py will need updating separately along with adding
new constants to glibc.)

Tested with build-many-glibcs.py.

4 months agosupport: Link links-dso-program-c with libgcc_s only if available
Florian Weimer [Fri, 21 Mar 2025 20:40:28 +0000 (21:40 +0100)] 
support: Link links-dso-program-c with libgcc_s only if available

Add a configure check to detect bootstrapping builds that do not
have libgcc_s.

Fixes commit 3e2be87832781a29ed67f38f87c1ce3dd4c1b866 ("support: Link
links-dso-program-c against libgcc_s").

Reviewed-by: Sam James <sam@gentoo.org>
4 months agoelf: Use +nolink-deps to add make-only dependency for tst-origin
Florian Weimer [Fri, 21 Mar 2025 20:40:28 +0000 (21:40 +0100)] 
elf: Use +nolink-deps to add make-only dependency for tst-origin

The tst-origin test must link against liborigin-mod.so.  Correct
build order depends on a makefile rule dependency on
$(objpfx)liborigin-mod.so.  Use +nolink-deps to remvoe this
dependency from the linker command line.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agoMakeconfig: Support $(+nolink-deps) in link flags
Florian Weimer [Fri, 21 Mar 2025 20:40:28 +0000 (21:40 +0100)] 
Makeconfig: Support $(+nolink-deps) in link flags

This allows adding dependencies to rules, but not linking against
them.

This is more or less a reimplementation of .EXTRA_PREREQS feature from
GNU make 4.3.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agodebug: Improve '%n' fortify detection (BZ 30932)
Adhemerval Zanella [Fri, 14 Mar 2025 19:09:57 +0000 (16:09 -0300)] 
debug: Improve '%n' fortify detection (BZ 30932)

The 7bb8045ec0 path made the '%n' fortify check ignore EMFILE errors
while trying to open /proc/self/maps, and this added a security
issue where EMFILE can be attacker-controlled thus making it
ineffective for some cases.

The EMFILE failure is reinstated but with a different error
message.  Also, to improve the false positive of the hardening for
the cases where no new files can be opened, the
_dl_readonly_area now uses  _dl_find_object to check if the
memory area is within a writable ELF segment.  The procfs method is
still used as fallback.

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Arjun Shankar <arjun@redhat.com>
4 months agoRemove eloop-threshold.h
Adhemerval Zanella [Tue, 4 Mar 2025 18:13:41 +0000 (15:13 -0300)] 
Remove eloop-threshold.h

On both Linux and Hurd the __eloop_threshold() is always a constant
(40 and 32 respectively), so there is no need to always call
__sysconf (_SC_SYMLOOP_MAX) for Linux case (!SYMLOOP_MAX).  To avoid
a name clash with gnulib, rename the new file min-eloop-threshold.h.

Checked on x86_64-linux-gnu and with a build for x86_64-gnu.
Reviewed-by: DJ Delorie <dj@redhat.com>
4 months agomalloc: missing initialization of tcache in _mid_memalign
Cupertino Miranda [Fri, 21 Mar 2025 17:50:35 +0000 (17:50 +0000)] 
malloc: missing initialization of tcache in _mid_memalign

_mid_memalign includes tcache code but does not attempt to initialize
tcaches.

Reviewed-by: DJ Delorie <dj@redhat.com>
4 months agosupport: Link links-dso-program-c against libgcc_s
Florian Weimer [Fri, 21 Mar 2025 09:33:25 +0000 (10:33 +0100)] 
support: Link links-dso-program-c against libgcc_s

If C++ support is not available, links-dso-program-c is used
instead of the C++ version.  The C version was not linked against
libgcc_s, which meant that thread cancellation and the backtrace
function did not work in containers tests in that situation.

Reviewed-by: Sam James <sam@gentoo.org>
4 months agoAdd _FORTIFY_SOURCE support for inet_ntop
Frédéric Bérat [Fri, 7 Mar 2025 17:16:30 +0000 (18:16 +0100)] 
Add _FORTIFY_SOURCE support for inet_ntop

- Create the __inet_ntop_chk routine that verifies that the builtin size
of the destination buffer is at least as big as the size given by the
user.
- Redirect calls from inet_ntop to __inet_ntop_chk or __inet_ntop_warn
- Update the abilist for this new routine
- Update the manual to mention the new fortification

Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoAdd missing guards in include/arpa/inet.h
Frédéric Bérat [Tue, 11 Mar 2025 09:40:11 +0000 (10:40 +0100)] 
Add missing guards in include/arpa/inet.h

Add the missing guards in the header, similarly to other headers at the
same level

Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoPrepare inet_ntop to be fortified
Frédéric Bérat [Fri, 7 Mar 2025 13:42:26 +0000 (14:42 +0100)] 
Prepare inet_ntop to be fortified

Rename inet_ntop to __inet_ntop and create the inet_ntop weak alias
based on it in order to prepare for disabling fortification when
available.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoadd inputs giving large errors for rsqrt
Paul Zimmermann [Wed, 12 Mar 2025 10:55:01 +0000 (11:55 +0100)] 
add inputs giving large errors for rsqrt

4 months agomalloc: Improve csize2tidx
Wilco Dijkstra [Tue, 18 Mar 2025 12:14:52 +0000 (12:14 +0000)] 
malloc: Improve csize2tidx

Remove the alignment rounding up from csize2tidx - this makes no sense
since the input should be a chunk size.  Removing it enables further
optimizations, for example chunksize_nomask can be safely used and
invalid sizes < MINSIZE are not mapped to a valid tidx.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
4 months agoelf: Fix tst-origin make rules
Adhemerval Zanella [Tue, 18 Mar 2025 19:10:05 +0000 (16:10 -0300)] 
elf: Fix tst-origin make rules

The tst-origin build can fail with:

  /usr/bin/ld: [...]libc.so: undefined reference to `__tunable_is_initialized@GLIBC_PRIVATE'

Since the custom link invocation links against system glibc instead
of the built one.

The only requirement is to avoid liborigin.so linked with a full path,
which is the default for --enable-hardcoded-path-in-tests.  There
is no need to use a custom rule.

Checked on x86_64-linux-gnu.

4 months agoAArch64: Optimize algorithm in users of SVE expf helper
Pierre Blanchard [Tue, 18 Mar 2025 17:07:31 +0000 (17:07 +0000)] 
AArch64: Optimize algorithm in users of SVE expf helper

Polynomial order was unnecessarily high, unlocking multiple
optimizations.
Max error for new SVE expf is 0.88 +0.5ULP.
Max error for new SVE coshf is 2.56 +0.5ULP.
Performance improvement on Neoverse V1: expf (30%), coshf (26%).

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
4 months agomalloc: Improve arena_for_chunk()
Wilco Dijkstra [Tue, 18 Mar 2025 12:30:10 +0000 (12:30 +0000)] 
malloc: Improve arena_for_chunk()

Change heap_max_size() to improve performance of arena_for_chunk().
Instead of a complex calculation, using a simple mask operation to get the
arena base pointer.  HEAP_MAX_SIZE should be larger than the huge page size,
otherwise heaps will use not huge pages.

On AArch64 this removes 6 instructions from arena_for_chunk(), and
bench-malloc-thread improves by 1.1% - 1.8%.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agobenchtests: Increase iterations of bench-malloc-simple
Wilco Dijkstra [Wed, 5 Mar 2025 16:22:55 +0000 (16:22 +0000)] 
benchtests: Increase iterations of bench-malloc-simple

Increase iterations so it runs for ~1 second on modern CPUs.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agoelf: Fix tst-origin make rules
Adhemerval Zanella [Mon, 17 Mar 2025 19:08:22 +0000 (19:08 +0000)] 
elf: Fix tst-origin make rules

Add tests-special before include Rules and compile liborigin.os with
MODULE_NAME set to testsuite instead of libc.

4 months agohtl: Make pthread_setcanceltype / state a cancellation point
Samuel Thibault [Sat, 15 Mar 2025 15:23:42 +0000 (15:23 +0000)] 
htl: Make pthread_setcanceltype / state a cancellation point

as expected by tst-cancel32.

4 months agotst-fopen-threaded: Only check EOF for failing read
Siddhesh Poyarekar [Fri, 14 Mar 2025 14:18:21 +0000 (10:18 -0400)] 
tst-fopen-threaded: Only check EOF for failing read

The fread race checker looks for EOF in every thread, which is incorrect
since threads calling fread successfully could lag behind and read the
EOF condition, resulting in multiple threads thinking that they
encountered an EOF.

Only look for EOF condition if fread fails to read a char.  Also drop
the clearerr() since it could mask the failure of another reader, thus
hiding a test failure.

Finally, also check for error in the stream for completeness.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoImplement C23 powr
Joseph Myers [Fri, 14 Mar 2025 15:58:11 +0000 (15:58 +0000)] 
Implement C23 powr

C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the powr functions, which are like pow, but with simpler
handling of special cases (based on exp(y*log(x)), so negative x and
0^0 are domain errors, powers of -0 are always +0 or +Inf never -0 or
-Inf, and 1^+-Inf and Inf^0 are also domain errors, while NaN^0 and
1^NaN are NaN).  The test inputs are taken from those for pow, with
appropriate adjustments (including removing all tests that would be
domain errors from those in auto-libm-test-in and adding some more
such tests in libm-test-powr.inc).

The underlying implementation uses __ieee754_pow functions after
dealing with all special cases that need to be handled differently.
It might be a little faster (avoiding a wrapper and redundant checks
for special cases) to have an underlying implementation built
separately for both pow and powr with compile-time conditionals for
special-case handling, but I expect the benefit of that would be
limited given that both functions will end up needing to use the same
logic for computing pow outside of special cases.

My understanding is that powr(negative, qNaN) should raise "invalid":
that the rule on "invalid" for an argument outside the domain of the
function takes precedence over a quiet NaN argument producing a quiet
NaN result with no exceptions raised (for rootn it's explicit that the
0th root of qNaN raises "invalid").  I've raised this on the WG14
reflector to confirm the intent.

Tested for x86_64 and x86, and with build-many-glibcs.py.

4 months agox86_64: Add atanh with FMA
Sunil K Pandey [Thu, 6 Mar 2025 00:13:38 +0000 (16:13 -0800)] 
x86_64: Add atanh with FMA

On SPR, it improves atanh bench performance by:

Before After Improvement
reciprocal-throughput 15.1715 14.8628 2%
latency 57.1941 56.1883 2%

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 months agoelf: Canonicalize $ORIGIN in an explicit ld.so invocation [BZ 25263]
Adhemerval Zanella [Tue, 18 Feb 2025 20:58:16 +0000 (15:58 -0500)] 
elf: Canonicalize $ORIGIN in an explicit ld.so invocation [BZ 25263]

When an executable is invoked directly, we calculate $ORIGIN by calling
readlink on /proc/self/exe, which the Linux kernel resolves to the
target of any symlinks.  However, if an executable is run through ld.so,
we cannot use /proc/self/exe and instead use the path given as an
argument.  This leads to a different calculation of $ORIGIN, which is
most notable in that it causes ldd to behave differently (e.g., by not
finding a library) from directly running the program.

To make the behavior consistent, take advantage of the fact that the
kernel also resolves /proc/self/fd/ symlinks to the target of any
symlinks in the same manner, so once we have opened the main executable
in order to load it, replace the user-provided path with the result of
calling readlink("/proc/self/fd/N").

(On non-Linux platforms this resolution does not happen and so no
behavior change is needed.)

The __fd_to_filename requires _fitoa_word and _itoa_word, which for
32-bits pulls a lot of definitions from _itoa.c (due _ITOA_NEEDED
being defined).  To simplify the build move the required function
to a new file, _fitoa_word.c.

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

Co-authored-by: Geoffrey Thomas <geofft@ldpreload.com>
Reviewed-by: Geoffrey Thomas <geofft@ldpreload.com>
Tested-by: Geoffrey Thomas <geofft@ldpreload.com>
4 months agox86_64: Add sinh with FMA
Sunil K Pandey [Sat, 8 Mar 2025 16:51:10 +0000 (08:51 -0800)] 
x86_64: Add sinh with FMA

On SPR, it improves sinh bench performance by:

Before After Improvement
reciprocal-throughput 14.2017 11.815 17%
latency 36.4917 35.2114 4%

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 months agobenchtests: Remove wrong snippet from 360cce0b06
Adhemerval Zanella [Thu, 13 Mar 2025 13:30:43 +0000 (10:30 -0300)] 
benchtests: Remove wrong snippet from 360cce0b06

4 months agox86_64: Add tanh with FMA
Sunil K Pandey [Mon, 10 Mar 2025 17:24:07 +0000 (10:24 -0700)] 
x86_64: Add tanh with FMA

On Skylake, it improves tanh bench performance by:

Before  After  Improvement
max 110.89 95.826 14%
min 20.966 20.157 4%
mean 30.9601 29.8431 4%

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 months agonptl: Check if thread is already terminated in sigcancel_handler (BZ 32782)
Adhemerval Zanella [Wed, 12 Mar 2025 13:59:17 +0000 (10:59 -0300)] 
nptl: Check if thread is already terminated in sigcancel_handler (BZ 32782)

The SIGCANCEL signal handler should not issue __syscall_do_cancel,
which calls __do_cancel and __pthread_unwind, if the cancellation
is already in proces (and libgcc unwind is not reentrant).  Any
cancellation signal received after is ignored.

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

Tested-by: Aurelien Jarno <aurelien@aurel32.net>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agonptl: PTHREAD_COND_INITIALIZER compatibility with pre-2.41 versions (bug 32786)
Florian Weimer [Thu, 13 Mar 2025 05:07:07 +0000 (06:07 +0100)] 
nptl: PTHREAD_COND_INITIALIZER compatibility with pre-2.41 versions (bug 32786)

The new initializer and struct layout does not initialize the
__g_signals field in the old struct layout before the change in
commit c36fc50781995e6758cae2b6927839d0157f213c ("nptl: Remove
g_refs from condition variables").  Bring back fields at the end
of struct __pthread_cond_s, so that they are again zero-initialized.

Reviewed-by: Sam James <sam@gentoo.org>
4 months agogetaddrinfo.c: support MPTCP (BZ #29609)
zhenwei pi [Tue, 11 Mar 2025 07:52:39 +0000 (15:52 +0800)] 
getaddrinfo.c: support MPTCP (BZ #29609)

There is a lack of MPTCP support from gaih_inet_typeproto array, add
MPTCP entry.

Signed-off-by: zhenwei pi <zhenwei.pi@linux.dev>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agomath: Refactor how to use libm-test-ulps
Adhemerval Zanella [Tue, 28 Jan 2025 21:22:44 +0000 (18:22 -0300)] 
math: Refactor how to use libm-test-ulps

The current approach tracks math maximum supported errors by explicitly
setting them per function and architecture. On newer implementations or
new compiler versions, the file is updated with newer values if it
shows higher results. The idea is to track the maximum known error, to
update the manual with the obtained values.

The constant libm-test-ulps shows little value, where it is usually a
mechanical change done by the maintainer, for past releases it is
usually ignored whether the ulp change resulted from a compiler
regression, and the math tests already have a maximum ulp error that
triggers a regression.

It was shown by a recent update after the new acosf [1] implementation
that is correctly rounded, where the libm-test-ulps was indeed from a
compiler issue.

This patch removes all arch-specific libm-test-ulps, adds system generic
libm-test-ulps where applicable, and changes its semantics. The generic
files now track specific implementation constraints, like if it is
expected to be correctly rounded, or if the system-specific has
different error expectations.

Now multiple libm-test-ulps can be defined, and system-specific
overrides generic implementation.  This is for the case where
arch-specific implementation might show worse precision than generic
implementation, for instance, the cbrtf on i686.

Regressions are only reported if the implementation shows larger errors
than 9 ulps (13 for IBM long double) unless it is overridden by
libm-test-ulps and the maximum error is not printed at the end of tests.
The regen-ulps rule is also removed since it does not make sense to
update the libm-test-ulps automatically.

The manual error table is also removed, Paul Zimmermann and others have
been tracking libm precision with a more comprehensive analysis for some
releases; so link to his work instead.

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=9cc9f8e11e8fb8f54f1e84d9f024917634a78201

4 months agoUpdate syscall lists for Linux 6.13
Joseph Myers [Wed, 12 Mar 2025 12:51:28 +0000 (12:51 +0000)] 
Update syscall lists for Linux 6.13

Linux 6.13 adds four new syscalls.  Update syscall-names.list and
regenerate the arch-syscall.h headers with build-many-glibcs.py
update-syscalls.

Tested with build-many-glibcs.py.

4 months agoMakefile: Clean up pthread_atfork integration
Florian Weimer [Wed, 12 Mar 2025 10:29:10 +0000 (11:29 +0100)] 
Makefile: Clean up pthread_atfork integration

Do not add the pthread_atfork routine again in nptl/Makefile,
instead rely on sysdeps/pthread/Makefile for the integration
(as this is the directory that contains the source file).

In sysdeps/pthread/Makefile, add to static-only-routines.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agonptl: Include <stdbool.h> in tst-pthread_gettid_np.c
Florian Weimer [Wed, 12 Mar 2025 10:10:14 +0000 (11:10 +0100)] 
nptl: Include <stdbool.h> in tst-pthread_gettid_np.c

The test uses the while (true) construct.

4 months agoLinux: Add new test misc/tst-sched_setattr-thread
Florian Weimer [Wed, 12 Mar 2025 09:23:47 +0000 (10:23 +0100)] 
Linux: Add new test misc/tst-sched_setattr-thread

The straightforward sched_getattr call serves as a test for
bug 32781, too.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agoLinux: Remove attribute access from sched_getattr (bug 32781)
Florian Weimer [Wed, 12 Mar 2025 09:23:47 +0000 (10:23 +0100)] 
Linux: Remove attribute access from sched_getattr (bug 32781)

The GCC attribute expects an element count, not bytes.

4 months agoLinux: Add the pthread_gettid_np function (bug 27880)
Florian Weimer [Wed, 12 Mar 2025 09:16:31 +0000 (10:16 +0100)] 
Linux: Add the pthread_gettid_np function (bug 27880)

Current Bionic has this function, with enhanced error checking
(the undefined case terminates the process).

Reviewed-by: Joseph Myers <josmyers@redhat.com>
4 months agoelf: Test dlopen (NULL, RTLD_LAZY) from an ELF constructor
Florian Weimer [Tue, 11 Mar 2025 14:30:52 +0000 (15:30 +0100)] 
elf: Test dlopen (NULL, RTLD_LAZY) from an ELF constructor

This call must not complete initialization of all shared objects
in the global scope because the ELF constructor which makes the call
likely has not finished initialization.  Calling more constructors
at this point would expose those to a partially constructed
dependency.

This completes the revert of commit 9897ced8e78db5d813166a7ccccfd5a
("elf: Run constructors on cyclic recursive dlopen (bug 31986)").

4 months agos390x: Regenerate ULPs.
Stefan Liebler [Tue, 11 Mar 2025 10:24:59 +0000 (11:24 +0100)] 
s390x: Regenerate ULPs.

Needed due to:
"Implement C23 rsqrt"
commit ID 77261698b4e938020a1b2032709a54d942ba330f

Same max ulps as used for x86_64 in the mentioned commit.

4 months agomath: Remove an extra semicolon in math function declarations
Aurelien Jarno [Thu, 6 Mar 2025 18:34:15 +0000 (19:34 +0100)] 
math: Remove an extra semicolon in math function declarations

Commit 6bc301672bfbd ("math: Remove __XXX math functions from installed
math.h [BZ #32418]") left an extra semicolon after macro expansion. For
instance the ceil declaration after expansion is:

  extern double ceil (double __x) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));;

This chokes very naive parsers like gauche c-wrapper. Fix that by
removing that extra semicolon in the macro.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agonptl: extend test coverage for sched_yield
Sergey Kolosov [Tue, 28 Jan 2025 22:56:26 +0000 (23:56 +0100)] 
nptl: extend test coverage for sched_yield

We add sched_yield() API testing to the existing thread affinity
test case because it allows us to test sched_yield() operation
in the following scenarios:

  * On a main thread.
  * On multiple threads simultaneously.
  * On every CPU the system reports simultaneously.

The ensures we exercise sched_yield() in as many scenarios as
we would exercise calls to the affinity functions.

Additionally, the test is improved by adding a semaphore to coordinate
all the threads running, so that an early starter thread won't consume
cpu resources that could be used to start the other threads.

Co-authored-by: DJ Delorie <dj@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
4 months agoposix: Move environ helper variables next to environ definition (bug 32541)
Florian Weimer [Fri, 7 Mar 2025 20:40:55 +0000 (21:40 +0100)] 
posix: Move environ helper variables next to environ definition (bug 32541)

This helps with statically interposing getenv.

Updates commit 7a61e7f557a97ab597d6fca5e2d1f13f65685c61
("stdlib: Make getenv thread-safe in more cases").

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
4 months agoImplement C23 rsqrt
Joseph Myers [Fri, 7 Mar 2025 19:15:26 +0000 (19:15 +0000)] 
Implement C23 rsqrt

C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the rsqrt functions (1/sqrt(x)).  The test inputs are
taken from those for sqrt.

Tested for x86_64 and x86, and with build-many-glibcs.py.

4 months agoUse binutils 2.44 branch and Linux 6.13 in build-many-glibcs.py
Joseph Myers [Fri, 7 Mar 2025 17:38:38 +0000 (17:38 +0000)] 
Use binutils 2.44 branch and Linux 6.13 in build-many-glibcs.py

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

4 months agoelf: Fix handling of symbol versions which hash to zero (bug 29190)
Florian Weimer [Fri, 7 Mar 2025 16:37:50 +0000 (17:37 +0100)] 
elf: Fix handling of symbol versions which hash to zero (bug 29190)

This was found through code inspection.  No application impact is
known.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agoconfigure: Fix spelling of -Wl,--no-error-execstack option
Florian Weimer [Fri, 7 Mar 2025 06:52:11 +0000 (07:52 +0100)] 
configure: Fix spelling of -Wl,--no-error-execstack option

BFD ld recognizes all -no-* options (with a single leading dash)
unconditionally.

Fixes commit a2bd5008a99032830add3e4005c25b61e3207112
("Pass -Wl,--no-error-execstack for tests where -Wl,-z,execstack
is used [PR32717]").

4 months agomanual: Mark perror as MT-unsafe and update check-safety.sh
Carlos O'Donell [Thu, 20 Feb 2025 19:26:45 +0000 (14:26 -0500)] 
manual: Mark perror as MT-unsafe and update check-safety.sh

The manual marked perror as MT-safe, but then listed a remark
indicating that it was unsafe because of a race between the function
and access to stderr.  The function is indeed MT-unsafe because
of the unlocked access to stderr internals and bug 32730 has been
filed to address this issue.

The script manual/check-safety.sh should have caught this issue,
but a missed escaping of "?" along with searching of all inputs
again via "$@" resulted in a non-functional regexp.

In order to avoid regressions we also update check-safety.sh.

The script manual/check-safety.sh is updated in the following ways:

 * The MT-unsafe remarks in MT-safe context check is fixed.
   - It now detects the perror safety note mistake.

 * Comments updated indicating that we allow MT context marks
   to count for other contexts if they are related.
   - This is why commit ad9c4c536115ba38be3e63592a632709ec8209b4
     failed and the failure is now understood as expected.

 * All checks now have verbose output.

 * Back reference based duplicate checks are removed.
   - They are too complex and don't cover all cases.

No regressions on x86_64.

4 months agoelf: Check if __attribute__ ((aligned (65536))) is supported
H.J. Lu [Fri, 7 Mar 2025 00:58:47 +0000 (08:58 +0800)] 
elf: Check if __attribute__ ((aligned (65536))) is supported

The BZ #32763 tests fail to build for MicroBlaze (which defines
MAX_OFILE_ALIGNMENT to (32768*8) in GCC, so __attribute__ ((aligned
(65536))) is unsupported).  Add a configure-time check to enable BZ #32763
tests only if __attribute__ ((aligned (65536))) is supported.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
4 months agohtl: Make __pthread_create_internal directly call __pthread_sigmask
Samuel Thibault [Wed, 5 Mar 2025 23:15:25 +0000 (00:15 +0100)] 
htl: Make __pthread_create_internal directly call __pthread_sigmask

__pthread_sigmask will already know to pass our current ss to
__sigthreadmask.

4 months agohtl: Make __pthread_sigmask directly call __sigthreadmask
Samuel Thibault [Wed, 5 Mar 2025 23:14:06 +0000 (00:14 +0100)] 
htl: Make __pthread_sigmask directly call __sigthreadmask

If no thread was created yet, __pthread_sigstate will not find our ss
because self->kernel_thread is still nul, and then change the global
sigstate instead of our sigstate! We can directly call __sigthreadmask and
skip the (bogus) lookup step.

4 months agohurd: Consolidate signal mask change
Samuel Thibault [Wed, 5 Mar 2025 23:10:40 +0000 (00:10 +0100)] 
hurd: Consolidate signal mask change

__pthread_sigstate and __sigprocmask were already the same, except for
clear_pending.

4 months agostatic-pie: Skip the empty PT_LOAD segment at offset 0 [BZ #32763]
H.J. Lu [Wed, 5 Mar 2025 02:19:59 +0000 (10:19 +0800)] 
static-pie: Skip the empty PT_LOAD segment at offset 0 [BZ #32763]

As shown in

https://sourceware.org/bugzilla/show_bug.cgi?id=25237

linker may generate an empty PT_LOAD segments at offset 0:

Elf file type is EXEC (Executable file)
Entry point 0x4000e8
There are 3 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                 0x00000000000000f0 0x00000000000000f0  R E    0x1000
  LOAD           0x0000000000000000 0x0000000000410000 0x0000000000410000
                 0x0000000000000000 0x0000000000b5dce8  RW     0x10000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10

 Section to Segment mapping:
  Segment Sections...
   00     .text
   01     .bss
   02

Skip the empty PT_LOAD segment at offset 0 to support such binaries.
This fixes BZ #32763.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
4 months agosysdeps: linux: Add BTRFS_SUPER_MAGIC to pathconf
Ronan Pigott [Thu, 6 Feb 2025 22:47:57 +0000 (15:47 -0700)] 
sysdeps: linux: Add BTRFS_SUPER_MAGIC to pathconf

btrfs has a 65535 maximum link count. Include this value in pathconf to
give the real max link count for this filesystem.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agolinux: Prefix AT_HWCAP with 0x on LD_SHOW_AUXV
Adhemerval Zanella [Wed, 26 Feb 2025 18:50:05 +0000 (15:50 -0300)] 
linux: Prefix AT_HWCAP with 0x on LD_SHOW_AUXV

Suggested-by: Stefan Liebler <stli@linux.ibm.com>
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
4 months agoRemove dl-procinfo.h
Adhemerval Zanella [Wed, 26 Feb 2025 17:11:44 +0000 (17:11 +0000)] 
Remove dl-procinfo.h

powerpc was the only architecture with arch-specific hooks for
LD_SHOW_AUXV, and with the information moved to ld diagnostics there
is no need to keep the _dl_procinfo hook.

Checked with a build for all affected ABIs.

Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
4 months agopowerpc: Remove unused dl-procinfo.h
Adhemerval Zanella [Wed, 26 Feb 2025 17:09:50 +0000 (17:09 +0000)] 
powerpc: Remove unused dl-procinfo.h

The _dl_string_platform is moved to hwcapinfo.h, since it is only used
by hwcapinfo.c and test-get_hwcap internal test.

Checked on powerpc64le-linux-gnu.

Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
4 months agopowerpc: Move cache geometry information to ld diagnostics
Adhemerval Zanella [Wed, 26 Feb 2025 16:28:41 +0000 (16:28 +0000)] 
powerpc: Move cache geometry information to ld diagnostics

From LD_SHOW_AUXV output.

Checked on powerpc64le-linux-gnu.

Reviewed-by: Peter Bergner <bergner@linux.ibm.com>