Remove the odd atomic_forced_read which is neither atomic nor forced.
Some uses are completely redundant, so simply remove them. In other cases
the intended use is to force a memory ordering, so use acquire load for those.
In yet other cases their purpose is unclear, for example __nscd_cache_search
appears to allow concurrent accesses to the cache while it is being garbage
collected by another thread! Use relaxed atomic loads here to block spills
from accidentally reloading memory that is being changed.
Passes regress on AArch64, OK for commit?
Update RSEQ access macros to use `(struct rseq_area) {}.member`
in _Static_assert and __typeof expressions, instead of
RSEQ_SELF()->member. This adopts the typeof_member style, avoiding
reliance on RSEQ_SELF for compile-time expressions.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Replace manual cast with a direct
`(struct rseq_area __seg_gs *)__rseq_offset` dereference to access
`member`. This avoids redundant `offsetof(struct rseq_area, member)`
and improves readability while preserving semantics.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Replace manual casts with a direct `(__tcbhead_t __seg_gs *)0`
dereferences for `stack_guard` and `pointer_guard`. This makes
the macros more straightforward and removes the dependency on
<stdint.h>.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Replace manual cast with a direct `(__typeof(*descr) __seg_gs *)0`
dereference to access `member`. This avoids redundant
`offsetof(struct pthread, member)` and improves readability while
preserving semantics.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
This patch addresses the actual cause of CVE-2025-5745
The vector non-volatile registers are not used anymore for
32 byte load and comparison operation
Additionally, the assembler workaround used earlier for the
instruction lxvp is replaced with actual instruction.
Signed-off-by: Sachin Monga <smonga@linux.ibm.com>
Co-authored-by: Paul Murphy <paumurph@redhat.com>
This patch addresses the actual cause of CVE-2025-5702
The vector non-volatile registers are not used anymore for
32 byte load and comparison operation
Additionally, the assembler workaround used earlier for the
instruction lxvp is replaced with actual instruction.
Signed-off-by: Sachin Monga <smonga@linux.ibm.com>
Co-authored-by: Paul Murphy <paumurph@redhat.com>
* manual/socket.texi (Out-of-Band Data): Check the atmark variable which
is set by the ioctl instead of the undefined result variable.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
The syscall() function allows to make system calls directly, however,
in the case of system calls that affect internal state of process or
thread, the caller would have to take care of extensive setup necessary
for the internals of Glibc to work correctly in the child threads. This
may make using syscall() with these syscall numbers impractical and
prone to undefined behaviour.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
It is enabled through math-use-builtins-fma.h if glibc is built
for VPFv4 (__ARM_FEATURE_FMA predefined by GCC), or through IFUNC
(testing HWCAP_ARM_VFPv4) otherwise.
Checked on arm-linux-gnueabihf.
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
With same micro-optimization done for the double variant:
* Combine the |y| zero check.
* Rework the check to adjust result and call fmod.
* Remove one check after fmod.
* Remove float-int-float roundtrip on return.
Also use math_config.h macros and indent the code. The resulting
strategy is different in many places that I think requires a
different Copyright.
I see the following performance improvements using remainder benchtests
(using reciprocal-throughput metric):
Architecture | Input | master | patch | Improvemnt
-----------------|-----------------|----------|-----------------------
x86_64 | subnormals | 20.4176 | 19.6144 | 3.93%
x86_64 | normal | 54.0939 | 52.2343 | 3.44%
x86_64 | close-exponent | 23.9120 | 22.3768 | 6.42%
aarch64 | subnormals | 9.2423 | 8.3825 | 9.30%
aarch64 | normal | 30.5393 | 29.244 | 4.24%
aarch64 | close-exponent | 15.5405 | 13.9256 | 10.39%
The aarch64 used as Neoverse-N1, gcc 15.1.1; while the x86_64 was
a AMD Ryzen 9 5900X, gcc 15.2.1.
Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
The commit 34b9f8bc17 provides an optimized fmod implementation; use
the same strategy used for remainderf and implement the double variant
on top of fmod.
I see the following performance improvements using remainder benchtests
(using reciprocal-throughput metric):
Architecture | Input | master | patch | Improvemnt
-----------------|-----------------|----------|-----------------------
x86_64 | subnormals | 76.1345 | 21.5334 | 71.72%
x86_64 | normal | 553.2670 | 426.5670 | 22.90%
x86_64 | close-exponent | 30.5111 | 22.6893 | 25.64%
aarch64 | subnormals | 26.0734 | 8.4876 | 67.45%
aarch64 | normal | 205.2590 | 200.082 | 2.52%
aarch64 | close-exponent | 13.8481 | 13.6663 | 1.31%
The aarch64 used as Neoverse-N1, gcc 15.1.1; while the x86_64 was
a AMD Ryzen 9 5900X, gcc 15.2.1.
This implementation also fixes the math/test-double-remainder issues
on alpha.
Tested on aarch64-linux-gnu and x86_64-linux-gnu.
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Refactor malloc.c to remove dead code, create macros to abstract duplicated
code, and cleanup sysmalloc_mmap_fallback to remove logic not related to the
mmap call.
Change the return type of mmap_base to uintptr_t since this allows using
operations on the return value, and avoids casting in both calls in
mremap_chunk and munmap_chunk.
Cleanup sysmalloc_mmap_fallback. Remove unused parameters nb, oldsize
and av. Remove redundant overflow check and instead use size_t for all
parameters except extra_flags to prevent overflows. Move logic not concerned
with the mmap call itself outside the function after both calls to
sysmalloc_mmap_fallback are made; this means move code for naming the VMA
and marking the arena being extended as non-contiguous to the calling code to
be handled in the case that the mmap is successful. Calculate the fallback
size from nb to avoid modifying size after it has been set for MORECORE.
Remove unused noncontiguous macro.
Remove redundant assert for checking unreachable option for global_max_fast.
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
When compiling on x86_64 with -Wshift-overflow=2 you can see the
following warning:
../sysdeps/ieee754/flt-32/math_config.h: In function ‘is_inf’:
../sysdeps/ieee754/flt-32/math_config.h:184:37: warning: result of ‘2139095040 << 1’ requires 33 bits to represent, but ‘int’ only has 32 bits [-Wshift-overflow=]
184 | return (x << 1) == (EXPONENT_MASK << 1);
| ^~
This patch adjusts the definitions to use UINT32_C. This matches the
definitions in sysdeps/ieee754/dbl-64/math_config.h which use UINT64_C
for these definitions.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
The struct shmdir_name in include/shm-directory.h has name field to
contains the full path of the POSIX IPC object (shm and sem).
The size was previously set to sizeof (SHMDIR) + 4 + NAME_MAX, where 4
bytes were reserved for the optional "sem." prefix.
This led to incorrect execution of the __shm_get_name function
in posix/shm-directory.c which is used accross in shm_[open/unlink] and
sem_[open/unlink] functions.
For shm_[open/unlink]:
This is because the name field was large enough to hold 268 characters
(255 + 4 + 9) instead of the maximum allowed 263 characters (255 + 9).
This caused the __shm_get_name to not throw ENAMETOOLONG error when the
name length exceeded NAME_MAX (255) upto 259 characters.
For sem_[open/unlink]:
Similarly, the __shm_get_name incorrectly returned success for names of
length 255 instead of 251 (255 - 4).
This was overlooked as finally these functions throw the correct
ENAMETOOLONG error; which was thrown by the openat syscall, which is
called later in the shm_* and sem_* functions.
This patch corrects the size of name field in struct shmdir_name to
sizeof (SHMDIR) + NAME_MAX. The __shm_get_name function return
ENAMETOOLONG if alloc_buffer_has_failed returns true (which only happens
when copy length > alloc_buffer_size (buffer)).
Relevant runtime monitoring were done in gdb to confirm the same.
Signed-off-by: Prasanna Paithankar <paithankarprasanna@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
C23 adds once_flag, ONCE_FLAG_INIT and call_once to stdlib.h (in C11
they were only in threads.h, in C23 they are in both headers; this
change came from N2840). Implement this change, with a
bits/types/once_flag.h header for the common type and initializer
definitions.
Note that there's an omnibus bug (bug 33001) that covers more than
just these missing definitions.
This doesn't seem a significant enough feature to be worth mentioning
in NEWS.
ISO C is not concerned with whether functions are in libc or
libpthread, but POSIX links this to what header they are declared in,
so functions declared in stdlib.h are supposed to be in libc.
However, the current edition of POSIX is based on C17; hopefully Hurd
glibc will have completed the merge of libpthread into libc (in
particular, moving call_once) well before a future edition of POSIX
based on C23 (or a later version of ISO C) is released.
Tested for x86_64 and x86.
Add the C23 memset_explicit function to glibc. Everything here is
closely based on the approach taken for explicit_bzero. This includes
the bits that relate to internal uses of explicit_bzero within glibc
(although we don't currently have any such internal uses of
memset_explicit), and also includes the nonnull attribute (when we
move to nonnull_if_nonzero for various functions following C2y, this
function should be included in that change).
The function is declared both for __USE_MISC and for __GLIBC_USE (ISOC23)
(so by default not just for compilers defaulting to C23 mode).
Tested for x86_64 and x86.
Previously this file failed to compile with the following errors:
$ gcc manual/examples/inetcli.c
manual/examples/inetcli.c: In function ‘write_to_server’:
manual/examples/inetcli.c:36:37: error: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
36 | nbytes = write (filedes, MESSAGE, strlen (MESSAGE) + 1);
| ^~~~~~
manual/examples/inetcli.c:26:1: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
25 | #include <netdb.h>
+++ |+#include <string.h>
26 |
manual/examples/inetcli.c:36:37: warning: incompatible implicit declaration of built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
36 | nbytes = write (filedes, MESSAGE, strlen (MESSAGE) + 1);
| ^~~~~~
manual/examples/inetcli.c:36:37: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Previously this file failed to compile with the following errors:
$ gcc manual/examples/inetsrv.c
manual/examples/inetsrv.c: In function ‘main’:
manual/examples/inetsrv.c:97:31: error: passing argument 3 of ‘accept’ from incompatible pointer type [-Wincompatible-pointer-types]
97 | &size);
| ^~~~~
| |
| size_t * {aka long unsigned int *}
In file included from manual/examples/inetsrv.c:23:
/usr/include/sys/socket.h:307:42: note: expected ‘socklen_t * restrict’ {aka ‘unsigned int * restrict’} but argument is of type ‘size_t *’ {aka ‘long unsigned int *’}
307 | socklen_t *__restrict __addr_len);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
manual/examples/inetsrv.c:105:26: error: implicit declaration of function ‘inet_ntoa’ [-Wimplicit-function-declaration]
105 | inet_ntoa (clientname.sin_addr),
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Previously this file failed to compile with the following errors:
$ gcc manual/examples/filesrv.c
manual/examples/filesrv.c: In function ‘main’:
manual/examples/filesrv.c:37:3: error: implicit declaration of function ‘unlink’ [-Wimplicit-function-declaration]
37 | unlink (SERVER);
| ^~~~~~
manual/examples/filesrv.c:40:10: error: implicit declaration of function ‘make_named_socket’ [-Wimplicit-function-declaration]
40 | sock = make_named_socket (SERVER);
| ^~~~~~~~~~~~~~~~~
manual/examples/filesrv.c:46:54: error: passing argument 6 of ‘recvfrom’ from incompatible pointer type [-Wincompatible-pointer-types]
46 | (struct sockaddr *) & name, &size);
| ^~~~~
| |
| size_t * {aka long unsigned int *}
In file included from manual/examples/filesrv.c:21:
/usr/include/sys/socket.h:165:48: note: expected ‘socklen_t * restrict’ {aka ‘unsigned int * restrict’} but argument is of type ‘size_t *’ {aka ‘long unsigned int *’}
165 | socklen_t *__restrict __addr_len);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
This patch fixes the missing declaration for unlink and uses
'socklen_t *' for the fourth argument of recv from. The
make_named_socket function is defined in the manual.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Without _GNU_SOURCE defined this file fails to compile with the
following error:
$ gcc manual/examples/select.c
manual/examples/select.c: In function ‘input_timeout’:
manual/examples/select.c:44:10: error: implicit declaration of function ‘TEMP_FAILURE_RETRY’ [-Wimplicit-function-declaration]
44 | return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
| ^~~~~~~~~~~~~~~~~~
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Previously this file would fail to compile with the following error:
$ gcc manual/examples/setjmp.c
manual/examples/setjmp.c: In function ‘main’:
manual/examples/setjmp.c:37:7: error: implicit declaration of function ‘do_command’ [-Wimplicit-function-declaration]
37 | do_command ();
| ^~~~~~~~~~
manual/examples/setjmp.c: At top level:
manual/examples/setjmp.c:42:1: warning: conflicting types for ‘do_command’; have ‘void(void)’
42 | do_command (void)
| ^~~~~~~~~~
manual/examples/setjmp.c:37:7: note: previous implicit declaration of ‘do_command’ with type ‘void(void)’
37 | do_command ();
| ^~~~~~~~~~
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Previously this file would fail to compile with the following error:
$ gcc manual/examples/sigh1.c
manual/examples/sigh1.c: In function ‘main’:
manual/examples/sigh1.c:46:3: error: implicit declaration of function ‘alarm’ [-Wimplicit-function-declaration]
46 | alarm (2);
| ^~~~~
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Without _GNU_SOURCE defined this file fails to compile with the
following error:
$ gcc manual/examples/strdupa.c
manual/examples/strdupa.c: In function ‘main’:
manual/examples/strdupa.c:27:19: error: implicit declaration of function ‘strdupa’; did you mean ‘strdup’? [-Wimplicit-function-declaration]
27 | char *wr_path = strdupa (path);
| ^~~~~~~
| strdup
manual/examples/strdupa.c:27:19: error: initialization of ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
GCC 15 turned -Wincompatible-pointer-types into a compiler error instead
of a warning by default. This patch prevents the following error:
$ gcc manual/examples/subopt.c
manual/examples/subopt.c: In function ‘main’:
manual/examples/subopt.c:64:40: error: passing argument 2 of ‘getsubopt’ from incompatible pointer type [-Wincompatible-pointer-types]
64 | switch (getsubopt (&subopts, mount_opts, &value))
| ^~~~~~~~~~
| |
| const char **
In file included from manual/examples/subopt.c:19:
/usr/include/stdlib.h:1100:47: note: expected ‘char * const* restrict’ but argument is of type ‘const char **’
1100 | char *const *__restrict __tokens,
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Previously this file would fail to compile with the following error:
$ gcc manual/examples/memopen.c
manual/examples/memopen.c: In function ‘main’:
manual/examples/memopen.c:28:30: error: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
28 | stream = fmemopen (buffer, strlen (buffer), "r");
| ^~~~~~
manual/examples/memopen.c:19:1: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
18 | #include <stdio.h>
+++ |+#include <string.h>
19 |
manual/examples/memopen.c:28:30: warning: incompatible implicit declaration of built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
28 | stream = fmemopen (buffer, strlen (buffer), "r");
| ^~~~~~
manual/examples/memopen.c:28:30: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Without _GNU_SOURCE defined this file fails to compile with the
following error:
$ gcc manual/examples/twalk.c
manual/examples/twalk.c: In function ‘twalk’:
manual/examples/twalk.c:55:3: error: implicit declaration of function ‘twalk_r’; did you mean ‘twalk’? [-Wimplicit-function-declaration]
55 | twalk_r (root, twalk_with_twalk_r_action, &closure);
| ^~~~~~~
| twalk
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Previously this file would fail to compile with the following error:
$ gcc manual/examples/sigusr.c
manual/examples/sigusr.c: In function ‘child_function’:
manual/examples/sigusr.c:46:3: error: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
46 | exit (0);
| ^~~~
manual/examples/sigusr.c:23:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
22 | #include <unistd.h>
+++ |+#include <stdlib.h>
23 | /*@end group*/
manual/examples/sigusr.c:46:3: warning: incompatible implicit declaration of built-in function ‘exit’ [-Wbuiltin-declaration-mismatch]
46 | exit (0);
| ^~~~
manual/examples/sigusr.c:46:3: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Previously this file would fail to compile with the following error:
$ gcc manual/examples/mbstouwcs.c
manual/examples/mbstouwcs.c: In function ‘mbstouwcs’:
manual/examples/mbstouwcs.c:34:11: error: ‘errno’ undeclared (first use in this function)
34 | errno = EILSEQ;
| ^~~~~
manual/examples/mbstouwcs.c:5:1: note: ‘errno’ is defined in header ‘<errno.h>’; this is probably fixable by adding ‘#include <errno.h>’
4 | #include <wchar.h>
+++ |+#include <errno.h>
5 |
manual/examples/mbstouwcs.c:34:11: note: each undeclared identifier is reported only once for each function it appears in
34 | errno = EILSEQ;
| ^~~~~
manual/examples/mbstouwcs.c:34:19: error: ‘EILSEQ’ undeclared (first use in this function)
34 | errno = EILSEQ;
| ^~~~~~
manual/examples/mbstouwcs.c:47:20: error: implicit declaration of function ‘towupper’ [-Wimplicit-function-declaration]
47 | *wcp++ = towupper (wc);
| ^~~~~~~~
manual/examples/mbstouwcs.c:5:1: note: include ‘<wctype.h>’ or provide a declaration of ‘towupper’
4 | #include <wchar.h>
+++ |+#include <wctype.h>
5 |
manual/examples/mbstouwcs.c:47:20: warning: incompatible implicit declaration of built-in function ‘towupper’ [-Wbuiltin-declaration-mismatch]
47 | *wcp++ = towupper (wc);
| ^~~~~~~~
manual/examples/mbstouwcs.c:47:20: note: include ‘<wctype.h>’ or provide a declaration of ‘towupper’
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Previously this file would fail to compile with the following error:
$ gcc manual/examples/db.c
db.c: In function ‘main’:
db.c:37:7: error: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
37 | printf ("Couldn't find out about user %d.\n", (int) me);
| ^~~~~~
db.c:23:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
22 | #include <stdlib.h>
+++ |+#include <stdio.h>
23 |
db.c:37:7: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
37 | printf ("Couldn't find out about user %d.\n", (int) me);
| ^~~~~~
db.c:37:7: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
db.c:42:3: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
42 | printf ("I am %s.\n", my_passwd->pw_gecos);
| ^~~~~~
db.c:42:3: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Instead of a negative return value the fixed FUSE copy_file_range will
silently truncate the size to UINT_MAX & PAGE_MASK [1]. Allow that value
to be returned as well.
[1] 1e08938c36
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Vector variants of the new C23 log10p1 routines.
Note: Benchmark inputs for log10p1(f) are identical to log1p(f)
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Vector variants of the new C23 log2p1 routines.
Note: Benchmark inputs for log2p1(f) are identical to log1p(f).
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Document the SHUT_* constants and attempt to explain the
implications for Linux TCP and UNIX domain sockets.
The Linux TCP behavior was discovered when writing the
socket/tst-shutdown test.
Suggested by Sergey Organov in
<https://inbox.sourceware.org/libc-help/qblfrh$4m4i$1@blaine.gmane.org/>.
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
fpu_control.h is an installed header so a wider range of compiler versions
(including ones older than GCC 9) are relevant with it than are relevant
for building glibc.
Fixes commit 3014dec3ad
('x86: Remove obsolete "*&" GCC asm memory operand workaround')
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
In the !defined __PIC__ case, we cannot guarantee that the delay slot
is properly filled at the final `j` instuction without reordering
active.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Testing strcmp on MIPS hardware shows that strcmp.S performs worse
than the combination of using the generic strcmp.c implementation
alongside -funroll-loops.
Suggested-by: Joseph Myers <josmyers@redhat.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
It now calls __libc_assert, which contains similar logic. The assert
call only requires memory allocation for the message translation, so
test-assert2.c is adapted to handle it.
It also removes the fxprintf from assert/assert_perror; although it
is not 100% backwards-compatible (write message only if there is a
file descriptor associated with the stderr). It now writes bytes
directly without going through the wide stream state.
Checked on aarch64-linux-gnu.
Reviewed-by: Florian Weimer <fweimer@redhat.com>