William Hunt [Tue, 29 Jul 2025 15:04:58 +0000 (15:04 +0000)]
malloc: Enable THP always support on hugetlb tunable
Enable support for THP always when glibc.malloc.hugetlb=1, as the tunable
currently only gives explicit support in malloc for the THP madvise mode
by aligning to a huge page size. Add a thp_mode parameter to mp_ and check
in madvise_thp whether the system is using madvise mode, otherwise the
`__madvise` call is useless. Set the thp_mode to be unsupported by default,
but if the hugetlb tunable is set this updates thp_mode. Performance of
xalancbmk improves by 4.9% on Neoverse V2 when THP always mode is set on the
system and glibc.malloc.hugetlb=1.
Paul Zimmermann [Wed, 9 Jul 2025 08:11:23 +0000 (10:11 +0200)]
replace atan2-inputs with more meaningful inputs
Commit 934d88d used inputs with exponent generated at random in the
whole binary64 exponent range, which yields essentially very large
or very small values of |y/x|. Instead, this commit generates x, y at
random in [-10,10], which should better corresponds to real applications. Reviewed-by: Florian Weimer <fweimer@redhat.com>
sframe: Add support for SFRAME_F_FDE_FUNC_START_PCREL flag
The Sframe V2 has a new errata which introduces the
SFRAME_F_FDE_FUNC_START_PCREL flag. This flag indicates the encoding
of the SFrame FDE function start address field like this:
- if set, sfde_func_start_address field contains the offset in bytes
to the start PC of the associated function from the field itself.
- if unset, sfde_func_start_address field contains the offset in bytes
to the start PC of the associated function from the start of the
SFrame section.
Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com> Reviewed-by: Sam James <sam@gentoo.org>
And add extra checks to enable for binutils 2.45 and if the architecture
explicitly enables it. When SFrame is disabled, all the related code
is also not enabled for backtrace() and _dl_find_object(), so SFrame
backtracking is not used even if the binary has the SFrame segment.
This patch also adds some other related fixes:
* Fixed an issue with AC_CHECK_PROG_VER, where the READELF_SFRAME
usage prevented specifying a different readelf through READELF
environment variable at configure time.
* Add an extra arch-specific internal definition,
libc_cv_support_sframe, to disable --enable-sframe on architectures
that have binutils but not glibc support (s390x).
* Renamed the tests without the .sframe segment and move the
tst-backtrace1 from pthread to debug.
* Use the built compiler strip to remove the .sframe segment,
instead of the system one (which might not support SFrame).
Checked on x86_64-linux-gnu and aarch64-linux-gnu.
manual: Use @Theglibc{} at sentence start in terminal documentation
Fixes commit 5dd2a19ad5218261cee064 ("termios: manual: improve the
explanation of various tty concepts") and commit c744519bad8106769760
("termios: manual: document the SPEED_MAX and BAUD_MAX constants").
debug: Link tst-sprintf-fortify-rdonly-static with -Wl,-z,relro [BZ 33183]
This test requires relro_format be placed in the PT_GNU_RELRO segment.
The ELF linker enables -z relro support by default on all Linux targets
except FRV, HPPA, IA64 and MIPS. On these targets, we need to explicitly
link with -z relro to place relro_format in the PT_GNU_RELRO segment.
Signed-off-by: John David Anglin <dave.anglin@bell.net>
Makeconfig: The hash character # confuses old make, use $(dir instead of sed
Up to Make 4.2, # is treated as the start of a comment even in
function invocations. This leads to a syntax error. Fixed in Make 4.3,
but we still support versions back to 4.0 at the moment.
Tested on Gentoo (x86-64) and Debian (loongarch64)
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org> Reviewed-by: Collin Funk <collin.funk1@gmail.com>
posix: Fix double-free after allocation failure in regcomp (bug 33185)
If a memory allocation failure occurs during bracket expression
parsing in regcomp, a double-free error may result.
Reported-by: Anastasia Belova <abelova@astralinux.ru> Co-authored-by: Paul Eggert <eggert@cs.ucla.edu> Reviewed-by: Andreas K. Huettel <dilfridge@gentoo.org>
Reason for revert: TCGETS etc. work to some extent on at least
a subset of architectures, so there is no pressing need to force
applications off them. Removal of the macros breaks building
the sanitizers, impacting both GCC and LLVM.
H. Peter Anvin [Sun, 13 Jul 2025 05:19:43 +0000 (22:19 -0700)]
termios: SPEED_MAX and BAUD_MAX constants
Add constants indicating the maximum values of speed_t and baud_t.
Hopefully if and when the baud_t interface is standardized then
BAUD_MAX will be included in the standardization from the start.
Historically, the __MAX_BAUD symbol has indicated the maximum speed_t
value on at least some platforms (including glibc). However, this
name would be problematic for future standardization, because it
confusingly implies a reference to baud_t, not speed_t, and it is
inconsistent with other limit symbols, which are all of the form *_MAX
(e.g. SIZE_MAX for size_t.)
[ v3: dropped leading underscores, leave __MAX_BAUD outside
#ifdef __USE_MISC since it is a legacy symbol, and
namespace-protected with a double underscore.
(Collin Funk, Adhermerval Zanella Netto) ]
[ v4: moved from __USE_MISC to __USE_GNU (Collin Funk) ]
Signed-off-by: "H. Peter Anvin" (Intel) <hpa@zytor.com> Reviewed-by: Collin Funk <collin.funk1@gmail.com>
H. Peter Anvin [Sun, 13 Jul 2025 05:19:42 +0000 (22:19 -0700)]
termios: move the baud_t interface from __USE_MISC to __USE_GNU
__USE_MISC refers to interfaces imported from BSD or System V, but the
baud_t interface is (at least for now) a GNU extension, so move it
from __USE_MISC to __USE_GNU.
Suggested-by: Collin Funk <collin.funk1@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Reviewed-by: Collin Funk <collin.funk1@gmail.com>
H. Peter Anvin [Sun, 13 Jul 2025 02:20:04 +0000 (19:20 -0700)]
termios: manual: improve the explanation of various tty concepts
It is a lot easier to understand the meaning of the tty interface if
it is explained from the beginning as conceptually emulating an RS232
serial port. This greatly simplifies the discussions of specific
items like the meaning of line speed.
Distinguish between "modem disconnect request" (deasserting DTR) and
"modem disconnect" (DCD deasserted). Conflating the two terms is
confusing, especially for non-RS232 devices. In particular, on most
systems, a pseudo-terminal will *not* respond to a modem disconnect
request by triggering a modem disconnect event for the purpose of the
HUPCL flag.
It is not necessarily true that the line speed has no effect on
non-serial port devices: e.g. an SPI port may interpret it as the
clock frequency to use; however, SPI does not use asynchronous framing
bits, instead synchronization is handled by the SS# wire. Similarly,
it is common but not by any means universal for interfaces that employ
various forms of fixed data to symbol rate encodings to encode the
data link layer bit rate rather than the physical symbol rate, which
may be higher (e.g. 8B10B) or lower (e.g. QAM/Trellis), without the
encoding or framing overhead.
Finally, a handful of devices use the line rate for entirely
nonstandard purposes. One example is Arduino USB interfaces, which
often interprets changing the baud rate to 1200 baud as a command to
reset the device.
[ v2: removed a bogus stray chunk from editing ]
Signed-off-by: H. Peter Anvin <hpa@zytor.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
H.J. Lu [Sat, 19 Jul 2025 00:03:04 +0000 (17:03 -0700)]
io/tst-stat.c: Use a temporary directory for symlink test
Call support_create_temp_directory to create a temporary directory for
symlink test, instead of a fixed file in the glibc source tree, to avoid
the race condition when there are more than one glibc tests running at the
same time with the same glibc source tree. This fixes BZ #33178.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Andreas K. Huettel <dilfridge@gentoo.org>
elf: Initialize GLRO (dl_read_only_area) after static dlopen (bug 33139)
The _dl_read_only_area function in the uninitialized ld.so after
static dlopen is not able to find anything. Instead, we need to
redirect to the code from the statically linked main program.
H.J. Lu [Thu, 17 Jul 2025 23:00:42 +0000 (16:00 -0700)]
x86-64: Properly compile ISA optimized modf and modff
There are 3 variants of modf and modff: SSE2, SSE4.1 and AVX. s_modf.c
and s_modff.c include the generic implementation compiled with the minimum
x86 ISA level. The IFUNC selector is used only if the minimum ISA level
is less than AVX. SSE4.1 variant is included only if the ISA level is
less than SSE4.1. AVX variant is included only the ISA level is less than
AVX.
AVX variant should be compiled with -mavx, not -msse2avx -DSSE2AVX which
are used to encode SSE assembly sources with EVEX encoding.
The routines that are shared between libc and libm should use different
rules to avoid using the same MODULE_NAME, to avoid potential issues
like BZ #33165 where __stack_chk_fail not being routed to the internal
symbol.
Tested with -march=x86-64, -march=x86-64-v2, -march=x86-64-v3 and
-march=x86-64-v4.
H.J. Lu [Thu, 17 Jul 2025 00:17:34 +0000 (17:17 -0700)]
x86-64: Compile ISA versions of modf/modff with -fno-stack-protector
Since modf and modff are compiled into both libc and libm, when glibc is
configured with --enable-stack-protector=all, ISA versions of modf and
modff should be compiled with -fno-stack-protector to avoid calling
__stack_chk_fail via PLT in libc.so.
This fixes BZ #33165.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Andreas K. Huettel <dilfridge@gentoo.org>
Enable SFrame stack track information. The --enable-sframe option
allows the glibc build to compile with SFrame stack track
information. Thus, enabling glibc's backtrace to work within glibc.
Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com> Reviewed-by: DJ Delorie <dj@redhat.com> Reviewed-by: Sam James <sam@gentoo.org>
This patch adds the necessary bits to enable stack tracing using
SFrame. In the case the new SFrame stack tracing procedure doesn't
find SFrame related info, the stack tracing falls back on default
Dwarf implementation.
The new SFrame stack tracing procedure is added to debug/backtrace.c
file, the support functions are added in sysdeps folder, namely
sframe.h, read-sframe.c and read-sfame.h.
Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com> Reviewed-by: DJ Delorie <dj@redhat.com>
elf: Add SFrame support to _dl_find_object function
The SFrame provides information to be able to do stack trace is now
well defined and implemented in Binutils 2.41. The format simply
contains enough information to be able to do stack trace given a
program counter (PC) value, the stack pointer, and the frame pointer.
The SFrame information is stored in a .sframe ELF section, which is
loaded into its own PT_GNU_SFRAME segment. We consider for this support
SFrame version 2.
This patch adds the bits to _dl_find_object to recognize and store in
struct dl_find_object the necessary info about SFrame section.
For x86_64-v1 the optimization is done through a new ifunc selector.
The avx is to follow other SSE4_1 optimization (like trunc) to avoid
the ifunc for x86_64-v3.
Checked on x86_64-linux-gnu. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Undefine TCGETS, TCGETS2, and related ioctl constants in the installed
headers. Extract the correct constants (using the kernel type
definitions) automatically from the UAPI headers. The kernel
constants are available under KERNEL_* names during the glibc build,
computed using assembler constant extraction mechanism.
Alpha may have to use TCGETS instead of TCGETS2 because TCTGETS2
became available in Linux 4.20 only. Introduce ARCH_TCGETS to make
this choice explict.
To support emulation on powerpc, glibc versions of the termios
constants are added to the emulation code in internal-ioctl.h.
Andreas Schwab [Thu, 10 Jul 2025 07:19:38 +0000 (09:19 +0200)]
Remove termios2 ioctl defintions from public headers
The use of the termios2 ioctl interface is an implementation detail which
should not bleed into public headers. Remove the PowerPC version of
<bits/ioctls.h> and define the termios2 ioctl numbers in <termios_arch.h>
instead. Also remove the include check from there which is unneeded in an
internal header.
Makeconfig: Add libgcc directory to rtld-prefix search path
* This needs to be done twice, for test runs with and without
--enable-hardcoded-path-in-tests
* Also, we need to query the used $(CC) for the library location.
* The container tests run ldd and dump the list of needed libraries, then
copy these into the container.
* Without this patch, ldd may not find libgcc_s.so, resulting in"not found"
output and no copying of the library.
* With this patch, the library is picked up independent of its location (as
long as the proper directory is provided) and copied into the testroot.
* This does not mean yet that ld.so in the testroot actually finds it.
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Stefan Liebler [Tue, 8 Jul 2025 13:06:45 +0000 (15:06 +0200)]
Mark support for lock elision as deprecated.
As discussed here:
https://sourceware.org/pipermail/libc-alpha/2025-July/168492.html
The support for TX lock elision of pthread mutexes is deprecated on
all architectures and will be removed in the next release. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Matteo Croce [Tue, 24 Jun 2025 16:40:13 +0000 (18:40 +0200)]
fstat: add test and documentation for an edge case.
The fstatat behaviour when the target is a dangling symlink is different
if flags contains AT_SYMLINK_NOFOLLOW or not.
Add a test for this and document it.
elf: Restore support for _r_debug interpositions and copy relocations
The changes in commit a93d9e03a31ec14405cb3a09aa95413b67067380
("Extend struct r_debug to support multiple namespaces [BZ #15971]")
break the dyninst dynamic instrumentation tool. It brings its
own definition of _r_debug (rather than a declaration).
Furthermore, it turns out it is rather hard to use the proposed
handshake for accessing _r_debug via DT_DEBUG. If applications want
to access _r_debug, they can do so directly if the relevant code has
been built as PIC. To protect against harm from accidental copy
relocations due to linker relaxations, this commit restores copy
relocation support by adjusting both copies if interposition or
copy relocations are in play. Therefore, it is possible to
use a hidden reference in ld.so to access _r_debug.
Only perform the copy relocation initialization if libc has been
loaded. Otherwise, the ld.so search scope can be empty, and the
lookup of the _r_debug symbol mail fail.
It replaces the ns_debug member of the namespaces. Previously,
the base namespace had an unused ns_debug member.
This change also fixes a concurrency issue: Now _dl_debug_initialize
only updates r_next of the previous namespace's r_debug after the new
r_debug is initialized, so that only the initialized version is
observed. (Client code accessing _r_debug will benefit from load
dependency tracking in CPUs even without explicit barriers.)
Collin Funk [Tue, 13 May 2025 02:07:15 +0000 (19:07 -0700)]
manual: Remove '.info' suffix in manual names passed to @ref [BZ #32962].
Texinfo 7.2 began warning about the '.info' suffix in the manual names
passed to @ref and similar commands. They eventually plan to stop
stripping the '.info' suffix internally which will lead to broken links
in the manuals without this change.
Signed-off-by: Collin Funk <collin.funk1@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
H.J. Lu [Sun, 15 Jun 2025 03:38:54 +0000 (11:38 +0800)]
elf: Add DL_ADDRESS_WITHOUT_RELOC [BZ #33088]
Add DL_ADDRESS_WITHOUT_RELOC to force an address into a general purpose
register to prevent loading it into a vector register directly before
run-time relocation. This is an updated fix for BZ #33088.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Florian Weimer <fweimer@redhat.com>
Wilco Dijkstra [Fri, 27 Jun 2025 14:10:55 +0000 (14:10 +0000)]
AArch64: Avoid memset ifunc in cpu-features.c [BZ #33112]
During early startup memcpy or memset must not be called since many targets
use ifuncs for them which won't be initialized yet. Security hardening may
use -ftrivial-auto-var-init=zero which inserts calls to memset. Redirect
memset to memset_generic by including dl-symbol-redir-ifunc.h in cpu-features.c.
This fixes BZ #33112.
William Hunt [Thu, 26 Jun 2025 15:07:14 +0000 (15:07 +0000)]
malloc: replace instances of __builtin_expect with __glibc_unlikely
Replaced all instances of __builtin_expect to __glibc_unlikely
within malloc.c and malloc-debug.c. This improves the portability
of glibc by avoiding calls to GNU C built-in functions. Since all
the expected results from calls to __builtin_expect were 0,
__glibc_likely was never used as a replacement. Multiple
calls to __builtin_expect within a single if statement have
been replaced with one call to __glibc_unlikely, which wraps
every condition.
William Hunt [Wed, 25 Jun 2025 11:35:05 +0000 (11:35 +0000)]
malloc: refactored aligned_OK and misaligned_chunk
Renamed aligned_OK to misaligned_mem as to be similar
to misaligned_chunk, and reversed any assertions using
the macro. Made misaligned_chunk call misaligned_mem after
chunk2mem rather than bitmasking with the malloc alignment
itself, since misaligned_chunk is meant to test the data
chunk itself rather than the header, and the compiler
will optimise the addition so the ternary operator is not
needed.
The generic implementation is slight more optimized than the powerpc
one, where it has a more optimized inf/nan check (by not using FP
unit checks, along with branch prediction hints), and removed one
branch by issuing trunc instead of a combination of floor/ceil (which
also generated less code).
The generic implementation is slight more optimized than the powerpc
one, where it has a more optimized inf/nan check (by not using FP
unit checks, along with branch prediction hints), and removed one
branch by issuing trunc instead of a combination of floor/ceil (which
also generated less code).
Linux: Convert '__close_nocancel_nostatus' to a standalone handler
Make '__close_nocancel_nostatus' standalone. This is a generic version
analogous to '__close_nocancel'. Platforms may choose to implement an
inline variant instead where the syscall invocation code sequence is
short enough to be beneficial over a function call.
Fix fallout from commit c181840c93d3 ("Consolidate non cancellable close
call") that caused '__close_nocancel_nostatus' to clobber 'errno' on a
close(2) failure, a 2.27 regression.
The problem came from a rewrite from 'close_not_cancel_no_status' to
'__close_nocancel_nostatus' switching from an inline implementation that
used INTERNAL_SYSCALL macro (which stays away from 'errno') to a call to
'__close_nocancel' function that uses INLINE_SYSCALL_CALL macro (which
does poke at 'errno').
Implement '__close_nocancel_nostatus' in terms of INTERNAL_SYSCALL_CALL
then, which leaves 'errno' intact.