1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-10-21 14:53:53 +03:00
Commit Graph

6750 Commits

Author SHA1 Message Date
Luc Michel
c284fd5eaf microblaze: fix __syscall_cancel_arch (BZ 33547)
The __syscall_cancel_arch function has an epilogue that does not match
the prologue. The stack is not used and the return address still lies in
r15 when reaching the epilogue. Fix the epilogue by simply returning
from the function.

Signed-off-by: Luc Michel <luc.michel@amd.com>
Tested-by: gopi@sankhya.com
Reviewed-by: Neal Frager <neal.frager@amd.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-20 11:33:54 -03:00
Adhemerval Zanella
a252205e1c linux: Fix function point cast on vDSO handling
There is no need to cast to avoid, both pointer already have the
expected type.

It fixes the clang -Wpointer-type-mismatch error:

../sysdeps/unix/sysv/linux/gettimeofday.c:43:6: error: pointer type mismatch ('int (*)(struct timeval *, void *)' and 'void *') [-Werror,-Wpointer-type-mismatch]
   41 | libc_ifunc (__gettimeofday,
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   42 |             GLRO(dl_vdso_gettimeofday) != NULL
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   43 |             ? VDSO_IFUNC_RET (GLRO(dl_vdso_gettimeofday))
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   44 |             : (void*) __gettimeofday_syscall)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:789:53: note: expanded from macro 'libc_ifunc'
  789 | #define libc_ifunc(name, expr) __ifunc (name, name, expr, void, INIT_ARCH)
      |                                ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:705:34: note: expanded from macro '__ifunc'
  705 |   __ifunc_args (type_name, name, expr, init, arg)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
./../include/libc-symbols.h:677:38: note: expanded from macro '__ifunc_args'
  677 |   __ifunc_resolver (type_name, name, expr, init, static, __VA_ARGS__);  \
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:667:33: note: expanded from macro '__ifunc_resolver'
  667 |     __typeof (type_name) *res = expr;                                   \
      |                                 ^~~~

Reviewed-by: Sam James <sam@gentoo.org>
2025-10-20 11:33:54 -03:00
Adhemerval Zanella
8ec0754067 aarch64: Fix gcs linker flags
clang does not work by using whitespace for defining the -z option:

$ make test t=misc/tst-gcs-disabled
[...]
clang: error: no such file or directory: 'gcs=always'

Use the usual comma separate way.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-10-20 11:33:54 -03:00
Adhemerval Zanella
917425ca6d posix: Defined _POSIX_VDISABLE as integer literal
The constant should be used with c_cc, which for all supported ABIs
is defined as unsigned char.  By using it as literar char constant,
clang triggers an error when compared with signal literal on ABIs that
define 'char' as unsigned.

On aarch64, clang shows:

  ../sysdeps/posix/fpathconf.c:118:21: error: right side of operator
  converted from negative value to unsigned: -1 to 18446744073709551615
  [-Werror]
  #if _POSIX_VDISABLE == -1
    ~~~~~~~~~~~~~~~ ^  ~~

Reviewed-by: Collin Funk <collin.funk1@gmail.com>
2025-10-20 11:33:54 -03:00
Joseph Myers
ea18d5a4c2 Implement C23 memalignment
Add the C23 memalignment function (query the alignment of a pointer)
to glibc.

Given how simple this operation is, it would make sense for compilers
to inline calls to this function, but I'm treating that as a compiler
matter (compilers should add it as a built-in function) rather than
adding an inline version to glibc headers (although such an inline
version would be reasonable as well).  I've filed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122117 for this feature
in GCC.

Tested for x86_64 and x86.
2025-10-17 16:56:59 +00:00
Yury Khrustalev
27effb3d50 aarch64: clear ZA state of SME before clone and clone3 syscalls
This change adds a call to the __arm_za_disable() function immediately
before the SVC instruction inside clone() and clone3() wrappers. It also
adds a macro for inline clone() used in fork() and adds the same call to
the vfork implementation. This sets the ZA state of SME to "off" on return
from these functions (for both the child and the parent).

The __arm_za_disable() function is described in [1] (8.1.3). Note that
the internal Glibc name for this function is __libc_arm_za_disable().

When this change was originally proposed [2,3], it generated a long
discussion where several questions and concerns were raised. Here we
will address these concerns and explain why this change is useful and,
in fact, necessary.

In a nutshell, a C library that conforms to the AAPCS64 spec [1] (pertinent
to this change, mainly, the chapters 6.2 and 6.6), should have a call to the
__arm_za_disable() function in clone() and clone3() wrappers. The following
explains in detail why this is the case.

When we consider using the __arm_za_disable() function inside the clone()
and clone3() libc wrappers, we talk about the C library subroutines clone()
and clone3() rather than the syscalls with similar names. In the current
version of Glibc, clone() is public and clone3() is private, but it being
private is not pertinent to this discussion.

We will begin with stating that this change is NOT a bug fix for something
in the kernel. The requirement to call __arm_za_disable() does NOT come from
the kernel. It also is NOT needed to satisfy a contract between the kernel
and userspace. This is why it is not for the kernel documentation to describe
this requirement. This requirement is instead needed to satisfy a pure userspace
scheme outlined in [1] and to make sure that software that uses Glibc (or any
other C library that has correct handling of SME states (see below)) conforms
to [1] without having to unnecessarily become SME-aware thus losing portability.

To recap (see [1] (6.2)), SME extension defines SME state which is part of
processor state. Part of this SME state is ZA state that is necessary to
manage ZA storage register in the context of the ZA lazy saving scheme [1]
(6.6). This scheme exists because it would be challenging to handle ZA
storage of SME in either callee-saved or caller-saved manner.

There are 3 kinds of ZA state that are defined in terms of the PSTATE.ZA
bit and the TPIDR2_EL0 register (see [1] (6.6.3)):

- "off":       PSTATE.ZA == 0
- "active":    PSTATE.ZA == 1 TPIDR2_EL0 == null
- "dormant":   PSTATE.ZA == 1 TPIDR2_EL0 != null

As [1] (6.7.2) outlines, every subroutine has exactly one SME-interface
depending on the permitted ZA-states on entry and on normal return from
a call to this subroutine. Callers of a subroutine must know and respect
the ZA-interface of the subroutines they are using. Using a subroutine
in a way that is not permitted by its ZA-interface is undefined behaviour.

In particular, clone() and clone3() (the C library functions) have the
ZA-private interface. This means that the permitted ZA-states on entry
are "off" and "dormant" and that the permitted states on return are "off"
or "dormant" (but if and only if it was "dormant" on entry).

This means that both functions in question should correctly handle both
"off" and "dormant" ZA-states on entry. The conforming states on return
are "off" and "dormant" (if inbound state was already "dormant").

This change ensures that the ZA-state on return is always "off". Note,
that, in the context of clone() and clone3(), "on return" means a point
when execution resumes at certain address after transferring from clone()
or clone3(). For the caller (we may refer to it as "parent") this is the
return address in the link register where the RET instruction jumps. For
the "child", this is the target branch address.

So, the "off" state on return is permitted and conformant. Why can't we
retain the "dormant" state? In theory, we can, but we shouldn't, here is
why.

Every subroutine with a private-ZA interface, including clone() and clone3(),
must comply with the lazy saving scheme [1] (6.7.2). This puts additional
responsibility on a subroutine if ZA-state on return is "dormant" because
this state has special meaning. The "caller" (that is the place in code
where execution is transferred to, so this include both "parent" and "child")
may check the ZA-state and use it as per the spec of the "dormant" state that
is outlined in [1] (6.6.6 and 6.6.7).

Conforming to this would require more code inside of clone() and clone3()
which hardly is desirable.

For the return to "parent" this could be achieved in theory, but given that
neither clone() nor clone3() are supposed to be used in the middle of an
SME operation, if wouldn't be useful. For the "return" to "child" this
would be particularly difficult to achieve given the complexity of these
functions and their interfaces. Most importantly, it would be illegal
and somewhat meaningless to allow a "child" to start execution in the
"dormant" ZA-state because the very essence of the "dormant" state implies
that there is a place to return and that there is some outer context that
we are allowed to interact with.

To sum up, calling __arm_za_disable() to ensure the "off" ZA-state when the
execution resumes after a call to clone() or clone3() is correct and also
the most simple way to conform to [1].

Can there be situations when we can avoid calling __arm_za_disable()?

Calling __arm_za_disable() implies certain (sufficiently small) overhead,
so one might rightly ponder avoiding making a call to this function when
we can afford not to. The most trivial cases like this (e.g. when the
calling thread doesn't have access to SME or to the TPIDR2_EL0 register)
are already handled by this function (see [1] (8.1.3 and 8.1.2)). Reasoning
about other possible use cases would require making code inside clone() and
clone3() more complicated and it would defeat the point of trying to make
an optimisation of not calling __arm_za_disable().

Why can't the kernel do this instead?

The handling of SME state by the kernel is described in [4]. In short,
kernel must not impose a specific ZA-interface onto a userspace function.
Interaction with the kernel happens (among other thing) via system calls.
In Glibc many of the system calls (notably, including SYS_clone and
SYS_clone3) are used via wrappers, and the kernel has no control of them
and, moreover, it cannot dictate how these wrappers should behave because
it is simply outside of the kernel's remit.

However, in certain cases, the kernel may ensure that a "child" doesn't
start in an incorrect state. This is what is done by the recent change
included in 6.16 kernel [5]. This is not enough to ensure that code that
uses clone() and clone3() function conforms to [1] when it runs on a
system that provides SME, hence this change.

[1]: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst
[2]: https://inbox.sourceware.org/libc-alpha/20250522114828.2291047-1-yury.khrustalev@arm.com
[3]: https://inbox.sourceware.org/libc-alpha/20250609121407.3316070-1-yury.khrustalev@arm.com
[4]: https://www.kernel.org/doc/html/v6.16/arch/arm64/sme.html
[5]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cde5c32db55740659fca6d56c09b88800d88fd29

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-14 09:42:46 +01:00
Yury Khrustalev
b4b713bd89 aarch64: define macro for calling __libc_arm_za_disable
A common sequence of instructions is used in several places
in assembly files, so define it in one place as an assembly
macro.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-14 09:42:46 +01:00
Arjun Shankar
88ce558a31 string: Add tests for unique strerror and strsignal strings
strerror, strsignal, and their variants should return unique strings for
each known (and, depending on the function, unknown) error/signal.  Add
tests to verify this for strerror, strerror_r (GNU and XSI compliant
variants), and strerror_l (for the C locale), strerrordesc_np,
strsignal, sigabbrev_np, and sigdescr_np.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2025-10-13 19:04:44 +02:00
Uros Bizjak
3a0a8eae50 x86: Fix trivial code formatting erros in my last two commits
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
2025-10-12 17:59:16 +02:00
Uros Bizjak
bb019bc68f i386: Use __seg_gs qualifiers in PTR_{MANGLE,DEMANGLE}() macros
Use __seg_gs named address space qualifiers in PTR_MANGLE() and
PTR_DEMANGLE() macros to access the pointer_guard field in the TCB.

This change allows the compiler to eliminate redundant reads of
the variable, reducing the number of reads from 105 to 94 and
decreasing the text size of the library by 280 bytes.

While at it, fix a few trivial whitespace issues as well

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2025-10-12 17:48:55 +02:00
Uros Bizjak
60e3ada68d x86_64: Use __seg_fs qualifiers in PTR_{MANGLE,DEMANGLE}() macros
Use __seg_fs named address space qualifiers in PTR_MANGLE() and
PTR_DEMANGLE() macros to access the pointer_guard field in the TCB.

This change allows the compiler to eliminate redundant reads of
the variable, reducing the number of reads from 98 to 89 and
decreasing the text size of the library by 512 bytes.

While at it, fix a few trivial whitespace issues as well.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2025-10-12 17:47:55 +02:00
Yury Khrustalev
7a47a51e8d misc: Fix several typos 2025-10-10 14:52:40 +01:00
Joseph Myers
0f201f4a81 Implement C23 memset_explicit (bug 32378)
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.
2025-10-01 15:14:09 +00:00
Collin Funk
e7eadbb29f Linux: Fix tst-copy_file_range-large test on recent kernels [BZ #33498]
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>
2025-09-27 18:18:04 -07:00
Luna Lamb
653e6c4fff AArch64: Implement AdvSIMD and SVE log10p1(f) routines
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>
2025-09-27 12:45:59 +00:00
Luna Lamb
db42732474 AArch64: Implement AdvSIMD and SVE log2p1(f) routines
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>
2025-09-27 12:44:09 +00:00
caiyinyu
cae3c9e3a1 LoongArch: Use the generic shmlab.h.
The shmlba.h file related to the LoongArch architecture was introduced
in commit 3eed5f3a1e to address the mismatch in the SHMLBA definition
between glibc and the kernel. See [1].  The SHMLBA definition was later
updated in commit d23b77953f5a. See [2].  Now, we adopt the definition
from the common layer.

[1]:
commit 3eed5f3a1e
Author: caiyinyu <caiyinyu@loongson.cn>
Date:   Thu May 25 17:01:11 2023 +0800

    LoongArch: Fix inconsistency in SHMLBA macro values between glibc and kernel

    The LoongArch glibc was using the value of the SHMLBA macro from common code,
    which is __getpagesize() (16k), but this was inconsistent with the value of
    the SHMLBA macro in the kernel, which is SZ_64K (64k). This caused several
    shmat-related tests in LTP (Linux Test Project) to fail. This commit fixes
    the issue by ensuring that the glibc's SHMLBA macro value matches the value
    used in the kernel like other architectures.

[2]:
commit d23b77953f5a4fbf94c05157b186aac2a247ae32
Author: Huacai Chen <chenhuacai@kernel.org>
Date:   Wed Jan 17 12:43:08 2024 +0800

    LoongArch: Change SHMLBA from SZ_64K to PAGE_SIZE

    LoongArch has hardware page coloring for L1 Cache, so we don't have
    cache aliases. But SFB (Store Fill Buffer) still has aliases. So we
    define SHMLBA to SZ_64K previously. But there are losts of applications
    use PAGE_SIZE rather than SHMLBA to mmap() file pages and shared pages.
    Of course we can fix them one by one, but not easy.

    On the other hand, we can simply disable SFB for 4KB page size to fix
    cache alias (there will be performance decrease, but acceptable), and
    in future we will fix SFB in hardware. So we can safely define SHMLBA to
    PAGE_SIZE (use the generic shmparam.h) to make life easier.

Signed-off-by: caiyinyu <caiyinyu@loongson.cn>
Reported-by: lixing <lixing@loongson.cn>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-12 09:42:19 +08:00
Wilco Dijkstra
9c72e0193d atomic: Switch hppa to builtin atomics
Switch hppa to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Wilco Dijkstra
6916b7faf8 atomic: Switch sh to builtin atomics
Switch sh to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Wilco Dijkstra
1c48da52bc atomic: Switch m68k to builtin atomics
Switch m68k to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Thiago Jung Bauermann
6f120faf64 Linux: Add missing si_code constants from Linux kernel
This brings the si_codes listed in siginfo-consts.h up-to-date with
Linux v6.16's include/uapi/asm-generic/siginfo.h.

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

Suggested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2025-09-08 14:12:47 -04:00
Xi Ruoyao
3b39822a82 misc: Add support for Linux uio.h RWF_DONTCACHE flag
Linux 6.14 adds the new flag for uncached buffered IO on a filesystem
supporting it.

This caused two test failures as these tests expected the flag
0x00000080 is unused.  Add the flag definition to fix these tests on
Linux >= 6.14:

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

The test failures were not detected in routine test suite runs because
normally we create the test file in /tmp, where a tmpfs is usually
mounted, and tmpfs does not support this flag.  But it can be reproduced
with TMPDIR set to some directory in an ext4 file system.

Link: https://git.kernel.org/torvalds/c/af6505e5745b
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-08 08:22:20 -03:00
Adhemerval Zanella
3795f22d42 alpha: Align stack for alpha
As done already for x86_64 [1] and aarch64 [2].  It fixes
misc/tst-misalign-clone on alpha.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=27902
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=27939
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
2025-09-08 08:21:56 -03:00
Hasaan Khan
8ced7815fb AArch64: Implement exp2m1 and exp10m1 routines
Vector variants of the new C23 exp2m1 & exp10m1 routines.

Note: Benchmark inputs for exp2m1 & exp10m1 are identical to exp2 & exp10
respectively, this also includes the floating point variations.

Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
2025-09-02 16:50:24 +00:00
Cupertino Miranda
3b2b88ccee elf: early conversion of elf p_flags to mprotect flags
This patch replaces _dl_stack_flags global variable by
_dl_stack_prot_flags.
The advantage is that any convertion from p_flags to final used mprotect
flags occurs at loading of p_flags. It avoids repeated spurious
convertions of _dl_stack_flags, for example in allocate_thread_stack.

This modification was suggested in:
  https://sourceware.org/pipermail/libc-alpha/2025-March/165537.html

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-08-27 10:45:45 -03:00
Uros Bizjak
3997c50f0b x86_64: Use __seg_fs qualifiers in NPTL accessors
Use __seg_fs named address space qualifiers to cast NPTL accessors
to %fs: prefixed addresses.  Use volatile access only where
strictly necessary.

Use existing assembly RSEQ_* accessors for x32 to
work around the GCC bug:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121613

because negative value in __rseq_offset is used
as an offset from %fs.

Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: Carlos O'Donell <carlos@redhat.com>
2025-08-22 06:36:14 -07:00
Uros Bizjak
f80dddbe29 i386: Use TESTB instead of TESTL in ____longjmp_chk()
There is no need to use TESTL when checking the least-significant bit
with a TEST instruction. Use TESTB, which is three bytes shorter:

   f6 44 24 04 01          testb  $0x1,0x4(%esp)

vs:

   f7 44 24 04 01 00 00    testl  $0x1,0x4(%esp)
   00

for the same effect.

No functional changes intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: H.J.Lu <hjl.tools@gmail.com>
Cc: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-20 11:48:17 -07:00
Uros Bizjak
dd38f49cdc x86_64: Use TESTB instead of TESTL in CHECK_INVALID_LONGJMP
There is no need to use TESTL when checking the least-significant bit
with a TEST instruction. Use TESTB, which is three bytes shorter:

   f6 44 24 f0 01      	   testb  $0x1,-0x10(%rsp)

vs:

   f7 44 24 f0 01 00 00    testl  $0x1,-0x10(%rsp)
   00

for the same effect.

No functional changes intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: H.J.Lu <hjl.tools@gmail.com>
Cc: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-20 11:47:53 -07:00
Florian Weimer
9a2aceb076 Linux: Add test case for bug 33245
The copy_file_range system call seems to be the only one that can
return an off64_t value.  Use FUSE to exercise this, without actually
creating such large files or copying any data.  Due to FUSE protocol
limitations, only sizes up to UINT_MAX can be tested, but this is
sufficient to check for the presence of bug 33245.

The FUSE protocol limitations are raised here:

  copy_file_range return value on FUSE
  <https://lore.kernel.org/all/lhuh5ynl8z5.fsf@oldenburg.str.redhat.com/>

Reviewed-by: Sam James <sam@gentoo.org>
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
2025-08-05 15:25:18 +02:00
Adhemerval Zanella
8698af6dcf aarch64: Fix aarch64_be build with --enable-sframe 2025-07-25 13:57:44 -03:00
Florian Weimer
0f93d54cde Revert "Linux: Keep termios ioctl constants strictly internal"
This reverts commit 3d3572f590.

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.

Reviewed-by: Sam James <sam@gentoo.org>
2025-07-21 15:13:08 +02:00
Claudiu Zissulescu
b231c21fc6 aarch64: Add SFrame support for aarch64 architecture
The SFrame is supported for AArch64 architecture.
    Enable SFrame stack tracer for AArch64 too.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Reviewed-by: DJ Delorie <dj@redhat.com>
2025-07-14 10:56:36 +01:00
Claudiu Zissulescu
170206b641 x86: Add SFrame support for x86 architecture
The SFrame is well supported by x86 architecture since binutils 2.41.
Enable it to be used as default frame tracer.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Reviewed-by: DJ Delorie <dj@redhat.com>
2025-07-14 10:56:36 +01:00
Florian Weimer
3d3572f590 Linux: Keep termios ioctl constants strictly internal
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.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-07-11 16:04:07 +02:00
Andreas Schwab
d6c2760ef7 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.
2025-07-10 11:39:43 +02:00
Florian Weimer
1c5f2ae4f9 Linux: Fix typo in comment in termios_internals.h 2025-07-04 13:17:31 +02:00
Wilco Dijkstra
681a24ae4d 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.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2025-06-30 13:17:38 +00:00
Maciej W. Rozycki
36bcbc6b5b 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.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-06-24 21:17:25 +01:00
Maciej W. Rozycki
3b0d495ac4 Linux: Fix '__close_nocancel_nostatus' clobbering 'errno' [BZ #33035]
Fix fallout from commit c181840c93 ("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.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-06-24 21:17:25 +01:00
Xi Ruoyao
fc6f074e04 riscv: linux: Add support for getrandom vDSO
Linux kernel >= 6.16 has getrandom() in vDSO for RISC-V.  Enable the use
of it in Glibc so it would benefit the programs using the Glibc high
quality random number functions.

Link: https://git.kernel.org/torvalds/c/ee0d03053e70
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-06-23 11:48:15 -03:00
H.J. Lu
0ef7965e5b x86: Update tst-gnu2-tls2 tests
Update tst-gnu2-tls2 tests to set XMM0...XMM7 to all 1s in malloc to
verify that XMM registers are preserved when _dl_tlsdesc_dynamic is
called by clearing vectors with zeroed XMM registers before
_dl_tlsdesc_dynamic and using these XMM registers to clear vectors
after _dl_tlsdesc_dynamic.  This improves the BZ #31372 test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
2025-06-19 05:46:31 +08:00
Andreas Schwab
0dbbc44bfd Fix termios related targets
Move Linux-specific termios headers and tests from misc to termios subdir
and install newly added bits/termios-cbaud.h.
2025-06-18 16:12:43 +02:00
Yury Khrustalev
c0f0db2d59 aarch64: simplify calls to __libc_arm_za_disable in assembly
There is no functional change in this patch.

We remove stores and loads to stack, return address signing, and redundant
CFI directives before and after call to __libc_arm_za_disable().

The __libc_arm_za_disable implementation follows special calling convention
that allows to avoid most of the operations that would be necessary for a
call to a normal function (see [1] for details).

First, we rely on __libc_arm_za_disable() not clobbering certain registers,
and we put return address into one of these registers. Now we don't need
to store it on stack, so we don't need to sign return address using PAC.

Second, as a result of the above, we don't need to update the CFI offset.

This patch provides small optimisation avoiding unnecessary store and load
on stack also simplifies assembly code and CFI directives.

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

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-06-18 09:42:33 +01:00
Yury Khrustalev
eeedfc2f74 aarch64: GCS: use internal struct in __alloc_gcs
No functional change here, just a small refactoring to simplify
using __alloc_gcs() for allocating shadow stacks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-06-18 09:37:13 +01:00
H. Peter Anvin (Intel)
964cf50bef linux/termios: regression test for termios speed functions
Test that runs through a fairly large combination of the various
termios speed functions, for the new speed_t interface, for the old
speed_t interface (if enabled), and for the new baud_t interface.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-06-17 09:57:44 -03:00
H. Peter Anvin (Intel)
be413adedf termios: unify the naming of the termios speed fields
The generic code has __ispeed and __ospeed; Linux has c_ispeed and
c_ospeed. Use an anonymous union member to allow both set of names on
all platforms.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-06-17 09:11:38 -03:00
H. Peter Anvin (Intel)
5f138519eb termios: add new baud_t interface, defined to be explicitly numeric
Add an explicitly numeric interface for baudrate setting. For glibc,
this only announces what is a fair accompli, but this is a plausible
way forward for standardization, and may be possible to infill on
non-compliant systems. The POSIX committee has stated:

[https://www.austingroupbugs.net/view.php?id=1916#c7135]

	A future version of this standard is expected to add at least
	the following symbolic constants for use as values of objects
	of type speed_t: B57600, B115200, B230400, B460800, and
	B921600.

	Implementations are encouraged to propose additional
	interfaces which will make it possible to set and query a
	wider range of speeds than just those enumerated by the
	constants beginning with B. If a set of common interfaces
	emerges between several implementations, a future version of
	this standard will likely add those interfaces.

This is exactly that interface.

The use of the term "baud" is due to the need to have a term
contrasting "speed", and it is already well established as a legacy
term -- including in the names of the legacy Bxxx
constants. Futhermore, it *is* valid from the point of view that the
termios interface fundamentally emulates an RS-232 serial port as far
as the application software is concerned.

The documentation states that for the current version of glibc,
speed_t == baud_t, but explicitly declares that this may not be the
case in the future.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-06-17 09:11:38 -03:00
H. Peter Anvin (Intel)
ad37ecd579 termios: merge the termios baud definitions
Now all platforms unconditionally use the "sane" definitions of the
termios baud constants. Unify them into a common file.

Note: I have made them explicitly unsigned to avoid problems with
compiler warnings for comparisons of unequal signedness or
similar. These constants were historically octal on most platforms,
and so unsigned by default.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-06-17 09:11:38 -03:00
H. Peter Anvin (Intel)
5cf101a85a linux: implement arbitrary and split speeds in termios
Linux has supported arbitrary speeds and split speeds in the kernel
since 2008 on all platforms except Alpha (fixed in 2020), but glibc
was never updated to match. This is further complicated by POSIX uses
of macros for the cf[gs]et[io]speed interfaces, rather than plain
numbers, as it really ought to have.

On most platforms, the glibc ABI includes the c_[io]speed fields in
struct termios, but they are incorrectly used. On MIPS and SPARC, they
are entirely missing.

For backwards compatibility, the kernel will still use the legacy
speed fields unless they are set to BOTHER, and will use the legacy
output speed as the input speed if the latter is 0 (== B0). However,
the specific encoding used is visible to user space applications,
including ones other than the one running.

- SPARC and MIPS get a new struct termios, and tc[gs]etattr() is
  versioned accordingly. However, the new struct termios is set to be
  a strict extension of the old one, which means that cf* interfaces
  other than the speed-related ones do not need versioning.
- The Bxxx constants are redefined as equivalent to their integer
  values and the legacy Bxxx constants are renamed __Bxxx.
- cf[gs]et[io]speed() and cfsetspeed() are versioned accordingly.
- tcgetattr() and cfset[io]speed() are adjusted to always keep the
  c_[io]speed fields correct (unlike earlier versions), but to
  canonicalize the representation to ALSO configure the legacy fields
  if a valid legacy representation exists.
- tcsetattr(), too, canonicalizes the representation in this way
  before passing it to the kernel, to maximize compatibility with
  older applications/tools.
- The old IBAUD0 hack is removed; it is no longer necessary since
  even the legacy c_cflag baud rate fields have had separate input
  values for a long time.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-06-17 09:11:38 -03:00
H. Peter Anvin (Intel)
5f54d8bc48 linux/termios/powerpc: deal with powerpc-unique ioctl emulation
The powerpc architecture, only, emulates the termios ioctls using the
glibc termios structure. Export the real kernel ones as the termios2
interface; although the kernel doesn't call it termios2, it is exactly
the termios2 interface, and it avoids the namespace clash between the
emulated ioctls and the real kernel ioctls.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-06-17 09:11:38 -03:00