]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
2 months agosignal: Avoid system signal disposition to interfere with tests
Adhemerval Zanella [Wed, 14 Feb 2024 17:33:41 +0000 (17:33 +0000)] 
signal: Avoid system signal disposition to interfere with tests

Both tst-sigset2 and tst-signal1 expectes that SIGINT disposition
is set to SIG_DFL.

2 months agoRISC-V: Fix the static-PIE non-relocated object check
Palmer Dabbelt [Thu, 22 Feb 2024 23:24:00 +0000 (15:24 -0800)] 
RISC-V: Fix the static-PIE non-relocated object check

The value of l_scope is only valid post relocation, so this original
check was triggering undefined behavior.  Instead just directly check to
see if the object has been relocated, at which point using l_scope is
safe.

Reported-by: Andreas Schwab <schwab@suse.de>
Closes: BZ #31317
Fixes: e0590f41fe ("RISC-V: Enable static-pie.")
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2 months agohtl: Implement some support for TLS_DTV_AT_TP
Sergey Bugaev [Sat, 23 Mar 2024 17:32:59 +0000 (20:32 +0300)] 
htl: Implement some support for TLS_DTV_AT_TP

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-19-bugaevc@gmail.com>

2 months agohtl: Respect GL(dl_stack_flags) when allocating stacks
Sergey Bugaev [Sat, 23 Mar 2024 17:32:47 +0000 (20:32 +0300)] 
htl: Respect GL(dl_stack_flags) when allocating stacks

Previously, HTL would always allocate non-executable stacks.  This has
never been noticed, since GNU Mach on x86 ignores VM_PROT_EXECUTE and
makes all pages implicitly executable.  Since GNU Mach on AArch64
supports non-executable pages, HTL forgetting to pass VM_PROT_EXECUTE
immediately breaks any code that (unfortunately, still) relies on
executable stacks.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-7-bugaevc@gmail.com>

2 months agohurd: Use the RETURN_ADDRESS macro
Sergey Bugaev [Sat, 23 Mar 2024 17:32:46 +0000 (20:32 +0300)] 
hurd: Use the RETURN_ADDRESS macro

This gives us PAC stripping on AArch64.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-6-bugaevc@gmail.com>

2 months agohurd: Disable Prefer_MAP_32BIT_EXEC on non-x86_64 for now
Sergey Bugaev [Sat, 23 Mar 2024 17:32:45 +0000 (20:32 +0300)] 
hurd: Disable Prefer_MAP_32BIT_EXEC on non-x86_64 for now

While we could support it on any architecture, the tunable is currently
only defined on x86_64.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-5-bugaevc@gmail.com>

2 months agoAllow glibc to be compiled without EXEC_PAGESIZE
Sergey Bugaev [Sat, 23 Mar 2024 17:32:44 +0000 (20:32 +0300)] 
Allow glibc to be compiled without EXEC_PAGESIZE

We would like to avoid statically defining any specific page size on
aarch64-gnu, and instead make sure that everything uses the dynamic
page size, available via vm_page_size and GLRO(dl_pagesize).

There are currently a few places in glibc that require EXEC_PAGESIZE
to be defined. Per Roland's suggestion [0], drop the static
GLRO(dl_pagesize) initializers (for now, only if EXEC_PAGESIZE is not
defined), and don't require EXEC_PAGESIZE definition for libio to
enable mmap usage.

[0]: https://mail.gnu.org/archive/html/bug-hurd/2011-10/msg00035.html

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-4-bugaevc@gmail.com>

2 months agohurd: Stop relying on VM_MAX_ADDRESS
Sergey Bugaev [Sat, 23 Mar 2024 17:32:43 +0000 (20:32 +0300)] 
hurd: Stop relying on VM_MAX_ADDRESS

We'd like to avoid committing to a specific size of virtual address
space (i.e. the value of VM_AARCH64_T0SZ) on AArch64.  While the current
version of GNU Mach still exports VM_MAX_ADDRESS for compatibility, we
should try to avoid relying on it when we can.  This piece of logic in
_hurdsig_getenv () doesn't actually care about the size of user-
accessible virtual address space, it just wants to preempt faults on any
addresses starting from the value of the P pointer and above.  So, use
(unsigned long int) -1 instead of VM_MAX_ADDRESS.

While at it, change the casts to (unsigned long int) and not just
(long int), since the type of struct hurd_signal_preemptor.{first,last}
is unsigned long int.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-3-bugaevc@gmail.com>

2 months agohurd: Move internal functions to internal header
Sergey Bugaev [Sat, 23 Mar 2024 17:32:42 +0000 (20:32 +0300)] 
hurd: Move internal functions to internal header

Move _hurd_self_sigstate (), _hurd_critical_section_lock (), and
_hurd_critical_section_unlock () inline implementations (that were
already guarded by #if defined _LIBC) to the internal version of the
header.  While at it, add <tls.h> to the includes, and use
__LIBC_NO_TLS () unconditionally.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-2-bugaevc@gmail.com>

2 months agostdlib: Fix tst-makecontext2 log when swapcontext fails
Stafford Horne [Fri, 3 Mar 2023 17:03:00 +0000 (02:03 +0900)] 
stdlib: Fix tst-makecontext2 log when swapcontext fails

The log incorrectly prints, setcontext failed.  Update this to indicate
that actually swapcontext failed.

Signed-off-by: Stafford Horne <shorne@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 months agoor1k: Add prctl wrapper to unwrap variadic args
Stafford Horne [Tue, 19 Mar 2024 21:01:24 +0000 (21:01 +0000)] 
or1k: Add prctl wrapper to unwrap variadic args

On OpenRISC variadic functions and regular functions have different
calling conventions so this wrapper is needed to translate.  This
wrapper is copied from x86_64/x32.  I don't know the build system enough
to find a cleaner way to share the code between x86_64/x32 and or1k
(maybe Implies?), so I went with the straight copy.

This fixes test failures:

  misc/tst-prctl
  nptl/tst-setgetname

2 months agoor1k: Only define fpu rouding and exceptions with hard-float
Stafford Horne [Tue, 19 Mar 2024 20:53:37 +0000 (20:53 +0000)] 
or1k: Only define fpu rouding and exceptions with hard-float

This test failure:

  math/test-fenv

If rounding mode and exception macros are defined then the fenv tests
run and always fail.  This patch adds an ifdef using the
__or1k_hard_float__ macro provided by gcc to avoid defining these fenv
macros when they cnnot be used.  This is similar to what is done in csky.

Note, I will post the or1k hard-float support soon. So, I prefer to
leave the hard-float bits here for now.

2 months agoor1k: Update libm test ulps
Stafford Horne [Mon, 18 Mar 2024 15:27:56 +0000 (15:27 +0000)] 
or1k: Update libm test ulps

To fix test failures:

    FAIL: math/test-float-hypot
    FAIL: math/test-float32-hypot

2 months agoAArch64: Check kernel version for SVE ifuncs
Wilco Dijkstra [Thu, 21 Mar 2024 16:48:33 +0000 (16:48 +0000)] 
AArch64: Check kernel version for SVE ifuncs

Old Linux kernels disable SVE after every system call.  Calling the
SVE-optimized memcpy afterwards will then cause a trap to reenable SVE.
As a result, applications with a high use of syscalls may run slower with
the SVE memcpy.  This is true for kernels between 4.15.0 and before 6.2.0,
except for 5.14.0 which was patched.  Avoid this by checking the kernel
version and selecting the SVE ifunc on modern kernels.

Parse the kernel version reported by uname() into a 24-bit kernel.major.minor
value without calling any library functions.  If uname() is not supported or
if the version format is not recognized, assume the kernel is modern.

Tested-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2 months agopowerpc: Placeholder and infrastructure/build support to add Power11 related changes.
Amrita H S [Wed, 20 Mar 2024 00:08:47 +0000 (19:08 -0500)] 
powerpc: Placeholder and infrastructure/build support to add Power11 related changes.

The following three changes have been added to provide initial Power11 support.
    1. Add the directories to hold Power11 files.
    2. Add support to select Power11 libraries based on AT_PLATFORM.
    3. Let submachine=power11 be set automatically.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
2 months agopowerpc: Add HWCAP3/HWCAP4 data to TCB for Power Architecture.
Manjunath Matti [Tue, 19 Mar 2024 20:29:48 +0000 (15:29 -0500)] 
powerpc: Add HWCAP3/HWCAP4 data to TCB for Power Architecture.

This patch adds a new feature for powerpc.  In order to get faster
access to the HWCAP3/HWCAP4 masks, similar to HWCAP/HWCAP2 (i.e. for
implementing __builtin_cpu_supports() in GCC) without the overhead of
reading them from the auxiliary vector, we now reserve space for them
in the TCB.

This is an ABI change for GLIBC 2.39.

Suggested-by: Peter Bergner <bergner@linux.ibm.com>
Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
2 months agoelf: Enable TLS descriptor tests on aarch64
Adhemerval Zanella [Tue, 12 Mar 2024 16:21:20 +0000 (13:21 -0300)] 
elf: Enable TLS descriptor tests on aarch64

The aarch64 uses 'trad' for traditional tls and 'desc' for tls
descriptors, but unlike other targets it defaults to 'desc'.  The
gnutls2 configure check does not set aarch64 as an ABI that uses
TLS descriptors, which then disable somes stests.

Also rename the internal machinery fron gnu2 to tls descriptors.

Checked on aarch64-linux-gnu.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 months agoarm: Update _dl_tlsdesc_dynamic to preserve caller-saved registers (BZ 31372)
Adhemerval Zanella [Tue, 12 Mar 2024 16:21:19 +0000 (13:21 -0300)] 
arm: Update _dl_tlsdesc_dynamic to preserve caller-saved registers (BZ 31372)

ARM _dl_tlsdesc_dynamic slow path has two issues:

  * The ip/r12 is defined by AAPCS as a scratch register, and gcc is
    used to save the stack pointer before on some function calls.  So it
    should also be saved/restored as well.  It fixes the tst-gnu2-tls2.

  * None of the possible VFP registers are saved/restored.  ARM has the
    additional complexity to have different VFP bank sizes (depending of
    VFP support by the chip).

The tst-gnu2-tls2 test is extended to check for VFP registers, although
only for hardfp builds.  Different than setcontext, _dl_tlsdesc_dynamic
does not have  HWCAP_ARM_IWMMXT (I don't have a way to properly test
it and it is almost a decade since newer hardware was released).

With this patch there is no need to mark tst-gnu2-tls2 as XFAIL.

Checked on arm-linux-gnueabihf.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 months agoIgnore undefined symbols for -mtls-dialect=gnu2
Adhemerval Zanella [Tue, 12 Mar 2024 16:21:18 +0000 (13:21 -0300)] 
Ignore undefined symbols for -mtls-dialect=gnu2

So it does not fail for arm config that defaults to -mtp=soft (which
issues a call to __aeabi_read_tp).
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 months agoAdd tst-gnu2-tls2mod1 to test-internal-extras
Andreas Schwab [Tue, 19 Mar 2024 12:49:50 +0000 (13:49 +0100)] 
Add tst-gnu2-tls2mod1 to test-internal-extras

That allows sysdeps/x86_64/tst-gnu2-tls2mod1.S to use internal headers.

Fixes: 717ebfa85c ("x86-64: Allocate state buffer space for RDI, RSI and RBX")
2 months agox86-64: Allocate state buffer space for RDI, RSI and RBX
H.J. Lu [Mon, 18 Mar 2024 13:40:16 +0000 (06:40 -0700)] 
x86-64: Allocate state buffer space for RDI, RSI and RBX

_dl_tlsdesc_dynamic preserves RDI, RSI and RBX before realigning stack.
After realigning stack, it saves RCX, RDX, R8, R9, R10 and R11.  Define
TLSDESC_CALL_REGISTER_SAVE_AREA to allocate space for RDI, RSI and RBX
to avoid clobbering saved RDI, RSI and RBX values on stack by xsave to
STATE_SAVE_OFFSET(%rsp).

   +==================+<- stack frame start aligned at 8 or 16 bytes
   |                  |<- RDI saved in the red zone
   |                  |<- RSI saved in the red zone
   |                  |<- RBX saved in the red zone
   |                  |<- paddings for stack realignment of 64 bytes
   |------------------|<- xsave buffer end aligned at 64 bytes
   |                  |<-
   |                  |<-
   |                  |<-
   |------------------|<- xsave buffer start at STATE_SAVE_OFFSET(%rsp)
   |                  |<- 8-byte padding for 64-byte alignment
   |                  |<- 8-byte padding for 64-byte alignment
   |                  |<- R11
   |                  |<- R10
   |                  |<- R9
   |                  |<- R8
   |                  |<- RDX
   |                  |<- RCX
   +==================+<- RSP aligned at 64 bytes

Define TLSDESC_CALL_REGISTER_SAVE_AREA, the total register save area size
for all integer registers by adding 24 to STATE_SAVE_OFFSET since RDI, RSI
and RBX are saved onto stack without adjusting stack pointer first, using
the red-zone.  This fixes BZ #31501.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
2 months agoriscv: Update nofpu libm test ulps
Darius Rad [Mon, 18 Mar 2024 10:28:50 +0000 (11:28 +0100)] 
riscv: Update nofpu libm test ulps

Fix two test failures.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 months agoAdd STATX_MNT_ID_UNIQUE from Linux 6.8 to bits/statx-generic.h
Joseph Myers [Fri, 15 Mar 2024 22:22:50 +0000 (22:22 +0000)] 
Add STATX_MNT_ID_UNIQUE from Linux 6.8 to bits/statx-generic.h

Linux 6.8 adds a new STATX_MNT_ID_UNIQUE constant.  Add it to glibc's
bits/statx-generic.h.

Tested for x86_64.

2 months agolinux: Use rseq area unconditionally in sched_getcpu (bug 31479)
Florian Weimer [Fri, 15 Mar 2024 18:08:24 +0000 (19:08 +0100)] 
linux: Use rseq area unconditionally in sched_getcpu (bug 31479)

Originally, nptl/descr.h included <sys/rseq.h>, but we removed that
in commit 2c6b4b272e6b4d07303af25709051c3e96288f2d ("nptl:
Unconditionally use a 32-byte rseq area").  After that, it was
not ensured that the RSEQ_SIG macro was defined during sched_getcpu.c
compilation that provided a definition.  This commit always checks
the rseq area for CPU number information before using the other
approaches.

This adds an unnecessary (but well-predictable) branch on
architectures which do not define RSEQ_SIG, but its cost is small
compared to the system call.  Most architectures that have vDSO
acceleration for getcpu also have rseq support.

Fixes: 2c6b4b272e6b4d07303af25709051c3e96288f2d
Fixes: 1d350aa06091211863e41169729cee1bca39f72f
Reviewed-by: Arjun Shankar <arjun@redhat.com>
2 months agoaarch64: fix check for SVE support in assembler
Szabolcs Nagy [Wed, 13 Mar 2024 14:34:14 +0000 (14:34 +0000)] 
aarch64: fix check for SVE support in assembler

Due to GCC bug 110901 -mcpu can override -march setting when compiling
asm code and thus a compiler targetting a specific cpu can fail the
configure check even when binutils gas supports SVE.

The workaround is that explicit .arch directive overrides both -mcpu
and -march, and since that's what the actual SVE memcpy uses the
configure check should use that too even if the GCC issue is fixed
independently.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 months agoUpdate kernel version to 6.8 in header constant tests
Joseph Myers [Wed, 13 Mar 2024 19:46:21 +0000 (19:46 +0000)] 
Update kernel version to 6.8 in header constant tests

This patch updates the kernel version in the tests tst-mman-consts.py,
tst-mount-consts.py and tst-pidfd-consts.py to 6.8.  (There are no new
constants covered by these tests in 6.8 that need any other header
changes.)

Tested with build-many-glibcs.py.

2 months agoUpdate syscall lists for Linux 6.8
Joseph Myers [Wed, 13 Mar 2024 13:57:56 +0000 (13:57 +0000)] 
Update syscall lists for Linux 6.8

Linux 6.8 adds five 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.

2 months agoUse Linux 6.8 in build-many-glibcs.py
Joseph Myers [Wed, 13 Mar 2024 13:30:30 +0000 (13:30 +0000)] 
Use Linux 6.8 in build-many-glibcs.py

This patch makes build-many-glibcs.py use Linux 6.8.

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

2 months agopowerpc: Remove power8 strcasestr optimization
Adhemerval Zanella [Tue, 5 Mar 2024 20:13:48 +0000 (17:13 -0300)] 
powerpc: Remove power8 strcasestr optimization

Similar to strstr (1e9a550ba4), power8 strcasestr does not show much
improvement compared to the generic implementation.  The geomean
on bench-strcasestr shows:

            __strcasestr_power8  __strcasestr_ppc
  power10                  1159              1120
  power9                   1640              1469
  power8                   1787              1904

The strcasestr uses the same 'trick' as power7 strstr to detect
potential quadradic behavior, which only adds overheads for input
that trigger quadradic behavior and it is really a hack.

Checked on powerpc64le-linux-gnu.
Reviewed-by: DJ Delorie <dj@redhat.com>
2 months agoriscv: Fix alignment-ignorant memcpy implementation
Adhemerval Zanella [Tue, 5 Mar 2024 17:02:57 +0000 (14:02 -0300)] 
riscv: Fix alignment-ignorant memcpy implementation

The memcpy optimization (commit 587a1290a1af7bee6db) has a series
of mistakes:

  - The implementation is wrong: the chunk size calculation is wrong
    leading to invalid memory access.

  - It adds ifunc supports as default, so --disable-multi-arch does
    not work as expected for riscv.

  - It mixes Linux files (memcpy ifunc selection which requires the
    vDSO/syscall mechanism)  with generic support (the memcpy
    optimization itself).

  - There is no __libc_ifunc_impl_list, which makes testing only
    check the selected implementation instead of all supported
    by the system.

This patch also simplifies the required bits to enable ifunc: there
is no need to memcopy.h; nor to add Linux-specific files.

The __memcpy_noalignment tail handling now uses a branchless strategy
similar to aarch64 (overlap 32-bits copies for sizes 4..7 and byte
copies for size 1..3).

Checked on riscv64 and riscv32 by explicitly enabling the function
on __libc_ifunc_impl_list on qemu-system.

Changes from v1:
* Implement the memcpy in assembly to correctly handle RISCV
  strict-alignment.
Reviewed-by: Evan Green <evan@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
2 months agolinux/sigsetops: fix type confusion (bug 31468)
Andreas Schwab [Mon, 11 Mar 2024 14:13:09 +0000 (15:13 +0100)] 
linux/sigsetops: fix type confusion (bug 31468)

Each mask in the sigset array is an unsigned long, so fix __sigisemptyset
to use that instead of int.  The __sigword function returns a simple array
index, so it can return int instead of unsigned long.

2 months agoLoongArch: Correct {__ieee754, _}_scalb -> {__ieee754, _}_scalbf
caiyinyu [Mon, 11 Mar 2024 08:07:48 +0000 (16:07 +0800)] 
LoongArch: Correct {__ieee754, _}_scalb -> {__ieee754, _}_scalbf

2 months agoduplocale: protect use of global locale (bug 23970)
Andreas Schwab [Wed, 6 Mar 2024 11:59:47 +0000 (12:59 +0100)] 
duplocale: protect use of global locale (bug 23970)

Protect the global locale from being modified while we compute the size of
the locale category names.  That allows the use of the global locale in a
single thread, while all other threads use the thread safe locale
functions.

3 months agox86-64: Simplify minimum ISA check ifdef conditional with if
Sunil K Pandey [Fri, 1 Mar 2024 01:57:02 +0000 (17:57 -0800)] 
x86-64: Simplify minimum ISA check ifdef conditional with if

Replace minimum ISA check ifdef conditional with if.  Since
MINIMUM_X86_ISA_LEVEL and AVX_X86_ISA_LEVEL are compile time constants,
compiler will perform constant folding optimization, getting same
results.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 months agomanual/tunables - Add entry for enable_secure tunable.
Joe Talbott [Fri, 1 Mar 2024 17:42:10 +0000 (17:42 +0000)] 
manual/tunables - Add entry for enable_secure tunable.

3 months agoNEWS: Move enable_secure_tunable from 2.39 to 2.40.
Joe Talbott [Fri, 1 Mar 2024 17:37:22 +0000 (17:37 +0000)] 
NEWS: Move enable_secure_tunable from 2.39 to 2.40.

3 months agoriscv: Add and use alignment-ignorant memcpy
Evan Green [Tue, 27 Feb 2024 22:56:43 +0000 (14:56 -0800)] 
riscv: Add and use alignment-ignorant memcpy

For CPU implementations that can perform unaligned accesses with little
or no performance penalty, create a memcpy implementation that does not
bother aligning buffers. It will use a block of integer registers, a
single integer register, and fall back to bytewise copy for the
remainder.

Signed-off-by: Evan Green <evan@rivosinc.com>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
3 months agoriscv: Add ifunc helper method to hwprobe.h
Evan Green [Tue, 27 Feb 2024 22:56:42 +0000 (14:56 -0800)] 
riscv: Add ifunc helper method to hwprobe.h

Add a little helper method so it's easier to fetch a single value from
the hwprobe function when used within an ifunc selector.

Signed-off-by: Evan Green <evan@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
3 months agoriscv: Enable multi-arg ifunc resolvers
Evan Green [Tue, 27 Feb 2024 22:56:41 +0000 (14:56 -0800)] 
riscv: Enable multi-arg ifunc resolvers

RISC-V is apparently the first architecture to pass more than one
argument to ifunc resolvers. The helper macros in libc-symbols.h,
__ifunc_resolver(), __ifunc(), and __ifunc_hidden(), are incompatible
with this. These macros have an "arg" (non-final) parameter that
represents the parameter signature of the ifunc resolver. The result is
an inability to pass the required comma through in a single preprocessor
argument.

Rearrange the __ifunc_resolver() macro to be variadic, and pass the
types as those variable parameters. Move the guts of __ifunc() and
__ifunc_hidden() into new macros, __ifunc_args(), and
__ifunc_args_hidden(), that pass the variable arguments down through to
__ifunc_resolver(). Then redefine __ifunc() and __ifunc_hidden(), which
are used in a bunch of places, to simply shuffle the arguments down into
__ifunc_args[_hidden]. Finally, define a riscv-ifunc.h header, which
provides convenience macros to those looking to write ifunc selectors
that use both arguments.

Signed-off-by: Evan Green <evan@rivosinc.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
3 months agoriscv: Add __riscv_hwprobe pointer to ifunc calls
Evan Green [Tue, 27 Feb 2024 22:56:40 +0000 (14:56 -0800)] 
riscv: Add __riscv_hwprobe pointer to ifunc calls

The new __riscv_hwprobe() function is designed to be used by ifunc
selector functions. This presents a challenge for applications and
libraries, as ifunc selectors are invoked before all relocations have
been performed, so an external call to __riscv_hwprobe() from an ifunc
selector won't work. To address this, pass a pointer to the
__riscv_hwprobe() function into ifunc selectors as the second
argument (alongside dl_hwcap, which was already being passed).

Include a typedef as well for convenience, so that ifunc users don't
have to go through contortions to call this routine. Users will need to
remember to check the second argument for NULL, to account for older
glibcs that don't pass the function.

Signed-off-by: Evan Green <evan@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
3 months agoriscv: Add hwprobe vdso call support
Evan Green [Tue, 27 Feb 2024 22:56:39 +0000 (14:56 -0800)] 
riscv: Add hwprobe vdso call support

The new riscv_hwprobe syscall also comes with a vDSO for faster answers
to your most common questions. Call in today to speak with a kernel
representative near you!

Signed-off-by: Evan Green <evan@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
3 months agolinux: Introduce INTERNAL_VSYSCALL
Evan Green [Tue, 27 Feb 2024 22:56:38 +0000 (14:56 -0800)] 
linux: Introduce INTERNAL_VSYSCALL

Add an INTERNAL_VSYSCALL() macro that makes a vDSO call, falling back to
a regular syscall, but without setting errno. Instead, the return value
is plumbed straight out of the macro.

Signed-off-by: Evan Green <evan@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
3 months agoriscv: Add Linux hwprobe syscall support
Evan Green [Tue, 27 Feb 2024 22:56:37 +0000 (14:56 -0800)] 
riscv: Add Linux hwprobe syscall support

Add awareness and a thin wrapper function around a new Linux system call
that allows callers to get architecture and microarchitecture
information about the CPUs from the kernel. This can be used to
do things like dynamically choose a memcpy implementation.

Signed-off-by: Evan Green <evan@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
3 months agortld: Add glibc.rtld.enable_secure tunable.
Joe Simmons-Talbott [Thu, 29 Feb 2024 19:55:58 +0000 (19:55 +0000)] 
rtld: Add glibc.rtld.enable_secure tunable.

Add a tunable for setting __libc_enable_secure to 1.  Do not set
__libc_enable_secure to 0 if the tunable is set to 0.  Ignore all
tunables if glib.rtld.enable_secure is set.  One use-case for this
addition is to enable testing code paths that depend on
__libc_enable_secure being set without the need to use setxid binaries.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
3 months agox86-64: Update _dl_tlsdesc_dynamic to preserve AMX registers
H.J. Lu [Wed, 28 Feb 2024 20:08:03 +0000 (12:08 -0800)] 
x86-64: Update _dl_tlsdesc_dynamic to preserve AMX registers

_dl_tlsdesc_dynamic should also preserve AMX registers which are
caller-saved.  Add X86_XSTATE_TILECFG_ID and X86_XSTATE_TILEDATA_ID
to x86-64 TLSDESC_CALL_STATE_SAVE_MASK.  Compute the AMX state size
and save it in xsave_state_full_size which is only used by
_dl_tlsdesc_dynamic_xsave and _dl_tlsdesc_dynamic_xsavec.  This fixes
the AMX part of BZ #31372.  Tested on AMX processor.

AMX test is enabled only for compilers with the fix for

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

GCC 14 and GCC 11/12/13 branches have the bug fix.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
3 months agox86_64: Suppress false positive valgrind error
H.J. Lu [Mon, 26 Feb 2024 00:03:26 +0000 (16:03 -0800)] 
x86_64: Suppress false positive valgrind error

When strcmp-avx2.S is used as the default, elf/tst-valgrind-smoke fails
with

==1272761== Conditional jump or move depends on uninitialised value(s)
==1272761==    at 0x4022C98: strcmp (strcmp-avx2.S:462)
==1272761==    by 0x400B05B: _dl_name_match_p (dl-misc.c:75)
==1272761==    by 0x40085F3: _dl_map_object (dl-load.c:1966)
==1272761==    by 0x401AEA4: map_doit (rtld.c:644)
==1272761==    by 0x4001488: _dl_catch_exception (dl-catch.c:237)
==1272761==    by 0x40015AE: _dl_catch_error (dl-catch.c:256)
==1272761==    by 0x401B38F: do_preload (rtld.c:816)
==1272761==    by 0x401C116: handle_preload_list (rtld.c:892)
==1272761==    by 0x401EDF5: dl_main (rtld.c:1842)
==1272761==    by 0x401A79E: _dl_sysdep_start (dl-sysdep.c:140)
==1272761==    by 0x401BEEE: _dl_start_final (rtld.c:494)
==1272761==    by 0x401BEEE: _dl_start (rtld.c:581)
==1272761==    by 0x401AD87: ??? (in */elf/ld.so)

The assembly codes are:

   0x0000000004022c80 <+144>: vmovdqu 0x20(%rdi),%ymm0
   0x0000000004022c85 <+149>: vpcmpeqb 0x20(%rsi),%ymm0,%ymm1
   0x0000000004022c8a <+154>: vpcmpeqb %ymm0,%ymm15,%ymm2
   0x0000000004022c8e <+158>: vpandn %ymm1,%ymm2,%ymm1
   0x0000000004022c92 <+162>: vpmovmskb %ymm1,%ecx
   0x0000000004022c96 <+166>: inc    %ecx
=> 0x0000000004022c98 <+168>: jne    0x4022c32 <strcmp+66>

strcmp-avx2.S has 32-byte vector loads of strings which are shorter than
32 bytes:

(gdb) p (char *) ($rdi + 0x20)
$6 = 0x1ffeffea20 "memcheck-amd64-linux.so"
(gdb) p (char *) ($rsi + 0x20)
$7 = 0x4832640 "core-amd64-linux.so"
(gdb) call (int) strlen ((char *) ($rsi + 0x20))
$8 = 19
(gdb) call (int) strlen ((char *) ($rdi + 0x20))
$9 = 23
(gdb)

It triggers the valgrind error.  The above code is safe since the loads
don't cross the page boundary.  Update tst-valgrind-smoke.sh to accept
an optional suppression file and pass a suppression file to valgrind when
strcmp-avx2.S is the default implementation of strcmp.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
3 months agox86: Don't check XFD against /proc/cpuinfo
H.J. Lu [Tue, 27 Feb 2024 19:43:39 +0000 (11:43 -0800)] 
x86: Don't check XFD against /proc/cpuinfo

Since /proc/cpuinfo doesn't report XFD, don't check it against
/proc/cpuinfo.

3 months agox86-64: Don't use SSE resolvers for ISA level 3 or above
H.J. Lu [Wed, 28 Feb 2024 17:51:14 +0000 (09:51 -0800)] 
x86-64: Don't use SSE resolvers for ISA level 3 or above

When glibc is built with ISA level 3 or above enabled, SSE resolvers
aren't available and glibc fails to build:

ld: .../elf/librtld.os: in function `init_cpu_features':
.../elf/../sysdeps/x86/cpu-features.c:1200:(.text+0x1445f): undefined reference to `_dl_runtime_resolve_fxsave'
ld: .../elf/librtld.os: relocation R_X86_64_PC32 against undefined hidden symbol `_dl_runtime_resolve_fxsave' can not be used when making a shared object
/usr/local/bin/ld: final link failed: bad value

For ISA level 3 or above, don't use _dl_runtime_resolve_fxsave nor
_dl_tlsdesc_dynamic_fxsave.

This fixes BZ #31429.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
3 months agox86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers
H.J. Lu [Mon, 26 Feb 2024 14:37:03 +0000 (06:37 -0800)] 
x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers

Compiler generates the following instruction sequence for GNU2 dynamic
TLS access:

leaq tls_var@TLSDESC(%rip), %rax
call *tls_var@TLSCALL(%rax)

or

leal tls_var@TLSDESC(%ebx), %eax
call *tls_var@TLSCALL(%eax)

CALL instruction is transparent to compiler which assumes all registers,
except for EFLAGS and RAX/EAX, are unchanged after CALL.  When
_dl_tlsdesc_dynamic is called, it calls __tls_get_addr on the slow
path.  __tls_get_addr is a normal function which doesn't preserve any
caller-saved registers.  _dl_tlsdesc_dynamic saved and restored integer
caller-saved registers, but didn't preserve any other caller-saved
registers.  Add _dl_tlsdesc_dynamic IFUNC functions for FNSAVE, FXSAVE,
XSAVE and XSAVEC to save and restore all caller-saved registers.  This
fixes BZ #31372.

Add GLRO(dl_x86_64_runtime_resolve) with GLRO(dl_x86_tlsdesc_dynamic)
to optimize elf_machine_runtime_setup.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
3 months agosysdeps/unix/sysv/linux/x86_64/Makefile: Add the end marker
H.J. Lu [Wed, 28 Feb 2024 13:46:40 +0000 (05:46 -0800)] 
sysdeps/unix/sysv/linux/x86_64/Makefile: Add the end marker

Add the end marker to tests, tests-container and modules-names.

3 months agocdefs: Drop access attribute for _FORTIFY_SOURCE=3 (BZ #31383)
Siddhesh Poyarekar [Thu, 15 Feb 2024 12:40:56 +0000 (07:40 -0500)] 
cdefs: Drop access attribute for _FORTIFY_SOURCE=3 (BZ #31383)

When passed a pointer to a zero-sized struct, the access attribute
without the third argument misleads -Wstringop-overflow diagnostics to
think that a function is writing 1 byte into the zero-sized structs.
The attribute doesn't add that much value in this context, so drop it
completely for _FORTIFY_SOURCE=3.

Resolves: BZ #31383
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agos390: Improve static-pie configure tests
Adhemerval Zanella [Tue, 27 Feb 2024 17:06:06 +0000 (14:06 -0300)] 
s390: Improve static-pie configure tests

Instead of tying based on the linker name and version, check for the
required support:

  * whether it does not generate dynamic TLS relocations in PIE
    (binutils PR ld/22263);
  * if it accepts --no-dynamic-linker (by using -static-pie);
  * and if it adds a DT_JMPREL pointing to .rela.iplt with static pie.

The patch also trims the comments, for binutils one of the tests should
already cover it.  The kernel ones are not clear which version should
have the backport, nor it is something that glibc can do much about
it.  Finally, the glibc is somewhat confusing, since it refers
to commits not related to s390x.

Checked with a build for s390x-linux-gnu.

Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
3 months agox86: Change ENQCMD test to CHECK_FEATURE_PRESENT
H.J. Lu [Tue, 27 Feb 2024 19:43:31 +0000 (11:43 -0800)] 
x86: Change ENQCMD test to CHECK_FEATURE_PRESENT

Since ENQCMD is mainly used in kernel, change the ENQCMD test to
CHECK_FEATURE_PRESENT.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
3 months agodebug: Improve mqueue.h fortify warnings with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:22 +0000 (15:46 -0300)] 
debug: Improve mqueue.h fortify warnings with clang

It improve mq_open.  The compile and runtime checks have similar
coverage as with GCC.

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agodebug: Improve fcntl.h fortify warnings with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:21 +0000 (15:46 -0300)] 
debug: Improve fcntl.h fortify warnings with clang

It improves open, open64, openat, and openat64.  The compile and runtime
checks have similar coverage as with GCC.

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agowcsmbs: Improve fortify with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:20 +0000 (15:46 -0300)] 
wcsmbs: Improve fortify with clang

It improve fortify checks for wmemcpy, wmemmove, wmemset, wcscpy,
wcpcpy, wcsncpy, wcpncpy, wcscat, wcsncat, wcslcpy, wcslcat, swprintf,
fgetws, fgetws_unlocked, wcrtomb, mbsrtowcs, wcsrtombs, mbsnrtowcs, and
wcsnrtombs.  The compile and runtime checks have similar coverage as
with GCC.

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agosyslog: Improve fortify with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:19 +0000 (15:46 -0300)] 
syslog: Improve fortify with clang

It improve fortify checks for syslog and vsyslog.  The compile
and runtime hecks have similar coverage as with GCC.

The syslog fortify wrapper calls the va_arg version, since clang does
not support __va_arg_pack.

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agosocket: Improve fortify with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:18 +0000 (15:46 -0300)] 
socket: Improve fortify with clang

It improve fortify checks recv, recvfrom, poll, and ppoll.  The compile
and runtime hecks have similar coverage as with GCC.

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agounistd: Improve fortify with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:17 +0000 (15:46 -0300)] 
unistd: Improve fortify with clang

It improve fortify checks for read, pread, pread64, readlink,
readlinkat, getcwd, getwd, confstr, getgroups, ttyname_r, getlogin_r,
gethostname, and getdomainname.  The compile and runtime checks have
similar coverage as with GCC.

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agostdlib: Improve fortify with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:16 +0000 (15:46 -0300)] 
stdlib: Improve fortify with clang

It improve fortify checks for realpath, ptsname_r, wctomb, mbstowcs,
and wcstombs.  The runtime and compile checks have similar coverage as
with GCC.

Checked on aarch64, armhf, x86_64, and i686.
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 months agostring: Improve fortify with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:15 +0000 (15:46 -0300)] 
string: Improve fortify with clang

It improve fortify checks for strcpy, stpcpy, strncpy, stpncpy, strcat,
strncat, strlcpy, and strlcat.  The runtime and compile checks have
similar coverage as with GCC.

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agolibio: Improve fortify with clang
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:14 +0000 (15:46 -0300)] 
libio: Improve fortify with clang

It improve fortify checks for sprintf, vsprintf, vsnsprintf, fprintf,
dprintf, asprintf, __asprintf, obstack_printf, gets, fgets,
fgets_unlocked, fread, and fread_unlocked.  The runtime checks have
similar support coverage as with GCC.

For function with variadic argument (sprintf, snprintf, fprintf, printf,
dprintf, asprintf, __asprintf, obstack_printf) the fortify wrapper calls
the va_arg version since clang does not support __va_arg_pack.

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agocdefs.h: Add clang fortify directives
Adhemerval Zanella [Thu, 8 Feb 2024 18:46:13 +0000 (15:46 -0300)] 
cdefs.h: Add clang fortify directives

For instance, the read wrapper is currently expanded as:

  extern __inline
  __attribute__((__always_inline__))
  __attribute__((__artificial__))
  __attribute__((__warn_unused_result__))
  ssize_t read (int __fd, void *__buf, size_t __nbytes)
  {
     return __glibc_safe_or_unknown_len (__nbytes,
                                         sizeof (char),
                                         __glibc_objsize0 (__buf))
            ? __read_alias (__fd, __buf, __nbytes)
            : __glibc_unsafe_len (__nbytes,
                                  sizeof (char),
                                  __glibc_objsize0 (__buf))
              ? __read_chk_warn (__fd,
                                 __buf,
                                 __nbytes,
                                 __builtin_object_size (__buf, 0))
              : __read_chk (__fd,
                            __buf,
                            __nbytes,
                            __builtin_object_size (__buf, 0));
  }

The wrapper relies on __builtin_object_size call lowers to a constant at
compile-time and many other operations in the wrapper depends on
having a single, known value for parameters.   Because this is
impossible to have for function parameters, the wrapper depends heavily
on inlining to work and While this is an entirely viable approach on
GCC, it is not fully reliable on clang.  This is because by the time llvm
gets to inlining and optimizing, there is a minimal reliable source and
type-level information available (more information on a more deep
explanation on how to fortify wrapper works on clang [1]).

To allow the wrapper to work reliably and with the same functionality as
with GCC, clang requires a different approach:

  * __attribute__((diagnose_if(c, “str”, “warning”))) which is a function
    level attribute; if the compiler can determine that 'c' is true at
    compile-time, it will emit a warning with the text 'str1'.  If it would
    be better to emit an error, the wrapper can use "error" instead of
    "warning".

  * __attribute__((overloadable)) which is also a function-level attribute;
    and it allows C++-style overloading to occur on C functions.

  * __attribute__((pass_object_size(n))) which is a parameter-level
    attribute; and it makes the compiler evaluate
    __builtin_object_size(param, n) at each call site of the function
    that has the parameter, and passes it in as a hidden parameter.

    This attribute has two side-effects that are key to how FORTIFY works:

    1. It can overload solely on pass_object_size (e.g. there are two
       overloads of foo in

         void foo(char * __attribute__((pass_object_size(0))) c);
         void foo(char *);

      (The one with pass_object_size attribute has precende over the
      default one).

    2. A function with at least one pass_object_size parameter can never
       have its address taken (and overload resolution respects this).

Thus the read wrapper can be implemented as follows, without
hindering any fortify coverage compile and runtime:

  extern __inline
  __attribute__((__always_inline__))
  __attribute__((__artificial__))
  __attribute__((__overloadable__))
  __attribute__((__warn_unused_result__))
  ssize_t read (int __fd,
                 void *const __attribute__((pass_object_size (0))) __buf,
                 size_t __nbytes)
     __attribute__((__diagnose_if__ ((((__builtin_object_size (__buf, 0)) != -1ULL
                                        && (__nbytes) > (__builtin_object_size (__buf, 0)) / (1))),
                                     "read called with bigger length than size of the destination buffer",
                                     "warning")))
  {
    return (__builtin_object_size (__buf, 0) == (size_t) -1)
      ? __read_alias (__fd,
                      __buf,
                      __nbytes)
      : __read_chk (__fd,
                    __buf,
                    __nbytes,
                    __builtin_object_size (__buf, 0));
  }

To avoid changing the current semantic for GCC, a set of macros is
defined to enable the clang required attributes, along with some changes
on internal macros to avoid the need to issue the symbol_chk symbols
(which are done through the __diagnose_if__ attribute for clang).
The read wrapper is simplified as:

  __fortify_function __attribute_overloadable__ __wur
  ssize_t read (int __fd,
                __fortify_clang_overload_arg0 (void *, ,__buf),
                size_t __nbytes)
       __fortify_clang_warning_only_if_bos0_lt (__nbytes, __buf,
                                                "read called with bigger length than "
                                                "size of the destination buffer")

  {
    return __glibc_fortify (read, __nbytes, sizeof (char),
                            __glibc_objsize0 (__buf),
                            __fd, __buf, __nbytes);
  }

There is no expected semantic or code change when using GCC.

Also, clang does not support __va_arg_pack, so variadic functions are
expanded to call va_arg implementations.  The error function must not
have bodies (address takes are expanded to nonfortified calls), and
with the __fortify_function compiler might still create a body with the
C++ mangling name (due to the overload attribute).  In this case, the
function is defined with __fortify_function_error_function macro
instead.

[1] https://docs.google.com/document/d/1DFfZDICTbL7RqS74wJVIJ-YnjQOj1SaoqfhbgddFYSM/edit

Checked on aarch64, armhf, x86_64, and i686.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 months agoUpdate SHARED-FILES and license for Unicode 15.1.0.
Carlos O'Donell [Wed, 21 Feb 2024 14:33:17 +0000 (09:33 -0500)] 
Update SHARED-FILES and license for Unicode 15.1.0.

In 2018 the license changed to use Unicode-3.0 license.
The Unicode License is a permissive MIT type of license.
Automation is updated to fetch the correct license file to
keep it in sync with the data files.

The new license is OSI approved and has an SPDX identifer:
https://opensource.org/license/unicode-license-v3
https://spdx.org/licenses/Unicode-3.0.html

The FSF and the GNU Project have been contacted to update
the license list for this license:
https://www.gnu.org/licenses/license-list.html

3 months agoaarch64/fpu: Sync libmvec routines from 2.39 and before with AOR
Joe Ramsay [Tue, 20 Feb 2024 16:44:13 +0000 (16:44 +0000)] 
aarch64/fpu: Sync libmvec routines from 2.39 and before with AOR

This includes a fix for big-endian in AdvSIMD log, some cosmetic
changes, and numerous small optimisations mainly around inlining and
using indexed variants of MLA intrinsics.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agoS390: Do not clobber r7 in clone [BZ #31402]
Stefan Liebler [Thu, 22 Feb 2024 14:03:27 +0000 (15:03 +0100)] 
S390: Do not clobber r7 in clone [BZ #31402]

Starting with commit e57d8fc97b90127de4ed3e3a9cdf663667580935
"S390: Always use svc 0"
clone clobbers the call-saved register r7 in error case:
function or stack is NULL.

This patch restores the saved registers also in the error case.
Furthermore the existing test misc/tst-clone is extended to check
all error cases and that clone does not clobber registers in this
error case.

3 months agox86_64: Exclude SSE, AVX and FMA4 variants in libm multiarch
Sunil K Pandey [Tue, 13 Feb 2024 20:23:14 +0000 (12:23 -0800)] 
x86_64: Exclude SSE, AVX and FMA4 variants in libm multiarch

When glibc is built with ISA level 3 or higher by default, the resulting
glibc binaries won't run on SSE or FMA4 processors.  Exclude SSE, AVX and
FMA4 variants in libm multiarch when ISA level 3 or higher is enabled by
default.

When glibc is built with ISA level 2 enabled by default, only keep SSE4.1
variant.

Fixes BZ 31335.

NB: elf/tst-valgrind-smoke test fails with ISA level 4, because valgrind
doesn't support AVX512 instructions:

https://bugs.kde.org/show_bug.cgi?id=383010

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 months agohurd: Reformat Makefile.
Carlos O'Donell [Fri, 9 Jun 2023 21:46:34 +0000 (17:46 -0400)] 
hurd: Reformat Makefile.

Reflow and sort Makefile.

Code generation changes present due to link order changes.

No regressions on x86_64 and i686.

Tested with build-many-glibcs.py for x86_64-gnu.

3 months agohtl/tests: Reformat Makefile.
Carlos O'Donell [Fri, 9 Jun 2023 21:45:23 +0000 (17:45 -0400)] 
htl/tests: Reformat Makefile.

Reflow and sort Makefile.

No code generation changes in non-test binary artifacts.

No regressions on x86_64 and i686.

Tested with build-many-glibcs.py for x86_64-gnu.

3 months agohtl: Reformat Makefile.
Carlos O'Donell [Fri, 9 Jun 2023 21:44:50 +0000 (17:44 -0400)] 
htl: Reformat Makefile.

Reflow and sort Makefile.

Code generation changes present due to link order changes.

No regressions on x86_64 and i686.

3 months agohesiod: Reformat Makefile.
Carlos O'Donell [Fri, 9 Jun 2023 20:44:19 +0000 (16:44 -0400)] 
hesiod: Reformat Makefile.

Reflow and sort Makefile.

No code generation changes in non-test binary artifacts.

No regressions on x86_64 and i686.

3 months agogmon: Reformat Makefile.
Carlos O'Donell [Thu, 8 Jun 2023 11:58:00 +0000 (07:58 -0400)] 
gmon: Reformat Makefile.

Reflow and sort Makefile.

Code generation changes present due to link order changes.

No regressions on x86_64 and i686.

3 months agodlfcn: Reformat Makefile.
Carlos O'Donell [Thu, 8 Jun 2023 16:17:00 +0000 (12:17 -0400)] 
dlfcn: Reformat Makefile.

Reflow and sort Makefile.

No code generation changes in non-test binary artifacts.

No regressions on x86_64 and i686.

3 months agodirent: Reformat Makefile.
Carlos O'Donell [Thu, 8 Jun 2023 11:30:33 +0000 (07:30 -0400)] 
dirent: Reformat Makefile.

Reflow and sort Makefile.

Code generation changes present due to link order changes.

No regressions on x86_64 and i686.

3 months agoctype: Reformat Makefile.
Carlos O'Donell [Thu, 8 Jun 2023 10:43:44 +0000 (06:43 -0400)] 
ctype: Reformat Makefile.

Reflow and sort Makefile.

Code generation changes present due to link order changes.

No regressions on x86_64 and i686.

3 months agocsu: Reformat Makefile.
Carlos O'Donell [Tue, 6 Jun 2023 12:27:20 +0000 (08:27 -0400)] 
csu: Reformat Makefile.

Reflow and sort Makefile.

Code generation changes present due to link order changes.

No regressions on x86_64 and i686.

3 months agoconform: Reformat Makefile.
Carlos O'Donell [Mon, 5 Jun 2023 11:14:41 +0000 (07:14 -0400)] 
conform: Reformat Makefile.

Reflow and sort Makefile.

No code changes in generated binary artifacts.

No regressions on x86_64 and i686.

3 months agoSupport compiling .S files with additional options
H.J. Lu [Sun, 25 Feb 2024 12:22:03 +0000 (04:22 -0800)] 
Support compiling .S files with additional options

Add $(sysdep-ASFLAGS) $(ASFLAGS-$(<F)) $(ASFLAGS-$(@F)) to compile.S and
COMPILE.S to support compiling .S files with additional options.

3 months agox86-64: Save APX registers in ld.so trampoline
H.J. Lu [Fri, 16 Feb 2024 15:17:10 +0000 (07:17 -0800)] 
x86-64: Save APX registers in ld.so trampoline

Add APX registers to STATE_SAVE_MASK so that APX registers are saved in
ld.so trampoline.  This fixes BZ #31371.

Also update STATE_SAVE_OFFSET and STATE_SAVE_MASK for i386 which will
be used by i386 _dl_tlsdesc_dynamic.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
3 months agobenchtests: Add more benchtests for rounding functions.
Junxian Zhu [Mon, 22 Jan 2024 02:16:19 +0000 (10:16 +0800)] 
benchtests: Add more benchtests for rounding functions.

This patch adds more benchtests for rounding functions.
The double inputs are copied from trunc-inputs, the float inputs are copied from truncf-inputs. and the rintf is copied from rint-inputs.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agotests: gracefully handle AppArmor userns containment
Simon Chopin [Fri, 16 Feb 2024 16:38:49 +0000 (17:38 +0100)] 
tests: gracefully handle AppArmor userns containment

Recent AppArmor containment allows restricting unprivileged user
namespaces, which is enabled by default on recent Ubuntu systems.
When this happens, as is common with Linux Security Modules, the syscall
will fail with -EACCESS.

When that happens, the affected tests will now be considered unsupported
rather than simply failing.

Further information:

* https://gitlab.com/apparmor/apparmor/-/wikis/unprivileged_userns_restriction
* https://ubuntu.com/blog/ubuntu-23-10-restricted-unprivileged-user-namespaces
* https://manpages.ubuntu.com/manpages/jammy/man5/apparmor.d.5.html (for
  the return code)

V2:
* Fix duplicated line in check_unshare_hints
* Also handle similar failure in tst-pidfd_getpid

V3:
* Comment formatting
* Aded some more documentation on syscall return value

Signed-off-by: Simon Chopin <simon.chopin@canonical.com>
3 months agotreewide: python-scripts: use `is None` for none-equality
Konstantin Kharlamov [Sun, 18 Feb 2024 20:02:34 +0000 (23:02 +0300)] 
treewide: python-scripts: use `is None` for none-equality

Testing for `None`-ness with `==` operator is frowned upon and causes
warnings in at least "LGTM" python linter. Fix that.

Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agopowerpc: Remove power7 strstr optimization
Adhemerval Zanella [Mon, 19 Feb 2024 20:46:55 +0000 (17:46 -0300)] 
powerpc: Remove power7 strstr optimization

The optimization is not faster than the generic algorithm,
using the bench-strstr the geometric mean running on a POWER10 machine
using gcc 13.1.1 is 482.47 while the default __strstr_ppc is 340.97
(which uses the generic implementation).

Also, there is no need to redirect the internal str*/mem* call
to optimized version, internal ifunc is supported and enabled
for internal calls (meaning that the generic implementation
will use any asm optimization if available).

Checked on powerpc64le-linux-gnu.
Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
3 months agoarm: Use _dl_find_object on __gnu_Unwind_Find_exidx (BZ 31405)
Adhemerval Zanella [Thu, 22 Feb 2024 13:42:55 +0000 (10:42 -0300)] 
arm: Use _dl_find_object on __gnu_Unwind_Find_exidx (BZ 31405)

Instead of __dl_iterate_phdr. On ARM dlfo_eh_frame/dlfo_eh_count
maps to PT_ARM_EXIDX vaddr start / length.

On a Neoverse N1 machine with 160 cores, the following program:

  $ cat test.c
  #include <stdlib.h>
  #include <pthread.h>
  #include <assert.h>

  enum {
    niter = 1024,
    ntimes = 128,
  };

  static void *
  tf (void *arg)
  {
    int a = (int) arg;

    for (int i = 0; i < niter; i++)
      {
        void *p[ntimes];
        for (int j = 0; j < ntimes; j++)
   p[j] = malloc (a * 128);
        for (int j = 0; j < ntimes; j++)
   free (p[j]);
      }

    return NULL;
  }

  int main (int argc, char *argv[])
  {
    enum { nthreads = 16 };
    pthread_t t[nthreads];

    for (int i = 0; i < nthreads; i ++)
      assert (pthread_create (&t[i], NULL, tf, (void *) i) == 0);

    for (int i = 0; i < nthreads; i++)
      {
        void *r;
        assert (pthread_join (t[i], &r) == 0);
        assert (r == NULL);
      }

    return 0;
  }
  $ arm-linux-gnueabihf-gcc -fsanitize=address test.c -o test

Improves from ~15s to 0.5s.

Checked on arm-linux-gnueabihf.

3 months agomath: Update mips64 ulps
Xi Ruoyao [Thu, 22 Feb 2024 20:26:55 +0000 (21:26 +0100)] 
math: Update mips64 ulps

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoelf: Add new LoongArch reloc types (110 to 126) into elf.h
Xi Ruoyao [Thu, 22 Feb 2024 10:57:43 +0000 (18:57 +0800)] 
elf: Add new LoongArch reloc types (110 to 126) into elf.h

These reloc types have been added in LoongArch psABI v2.30.

Link: https://github.com/loongson/la-abi-specs/blob/v2.30/laelf.adoc#relocation-types
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
3 months agobuild-many-glibcs.py: Add s390 --disable-multi-arch / multi-arch configurations.
Stefan Liebler [Wed, 31 Jan 2024 12:02:57 +0000 (13:02 +0100)] 
build-many-glibcs.py: Add s390 --disable-multi-arch / multi-arch configurations.

This patch adds some --disable-multi-arch variants for s390x.

As the used IFUNC variants and __GI symbols depend on the used
gcc -march=cpu-level, there are multiple new configurations.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agosparc: Treat the version field in the FPU control word as reserved
Daniel Cederman [Mon, 19 Feb 2024 13:55:50 +0000 (10:55 -0300)] 
sparc: Treat the version field in the FPU control word as reserved

The FSR version field is read-only and might be non-zero.

This allows math/test-fpucw* to correctly pass when the version is
non-zero.

Signed-off-by: Daniel Cederman <cederman@gaisler.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agoImplement setcontext/getcontext/makecontext/swapcontext for Hurd x86_64
Flavio Cruz [Sat, 17 Feb 2024 20:25:35 +0000 (15:25 -0500)] 
Implement setcontext/getcontext/makecontext/swapcontext for Hurd x86_64

Tested with the tests provided by glibc plus some other toy examples.
Message-ID: <20240217202535.1860803-1-flaviocruz@gmail.com>

3 months agoUse proc_getchildren_rusage when available in getrusage and times.
Flavio Cruz [Sat, 17 Feb 2024 16:48:46 +0000 (11:48 -0500)] 
Use proc_getchildren_rusage when available in getrusage and times.

Message-ID: <20240217164846.1837223-1-flaviocruz@gmail.com>

3 months agoLinux: Switch back to assembly syscall wrapper for prctl (bug 29770)
Florian Weimer [Sat, 17 Feb 2024 08:17:04 +0000 (09:17 +0100)] 
Linux: Switch back to assembly syscall wrapper for prctl (bug 29770)

Commit ff026950e280bc3e9487b41b460fb31bc5b57721 ("Add a C wrapper for
prctl [BZ #25896]") replaced the assembler wrapper with a C function.
However, on powerpc64le-linux-gnu, the C variadic function
implementation requires extra work in the caller to set up the
parameter save area.  Calling a function that needs a parameter save
area without one (because the prototype used indicates the function is
not variadic) corrupts the caller's stack.   The Linux manual pages
project documents prctl as a non-variadic function.  This has resulted
in various projects over the years using non-variadic prototypes,
including the sanitizer libraries in LLVm and GCC (GCC PR 113728).

This commit switches back to the assembler implementation on most
targets and only keeps the C implementation for x86-64 x32.

Also add the __prctl_time64 alias from commit
b39ffab860cd743a82c91946619f1b8158b0b65e ("Linux: Add time64 alias for
prctl") to sysdeps/unix/sysv/linux/syscalls.list; it was not yet
present in commit ff026950e280bc3e9487b41b460fb31bc5b57721.

This restores the old ABI on powerpc64le-linux-gnu, thus fixing
bug 29770.

Reviewed-By: Simon Chopin <simon.chopin@canonical.com>
3 months agoi386: Use generic memrchr in libc (bug 31316)
Florian Weimer [Fri, 16 Feb 2024 06:40:37 +0000 (07:40 +0100)] 
i386: Use generic memrchr in libc (bug 31316)

Before this change, we incorrectly used the SSE2 variant in the
implementation, without checking that the system actually supports
SSE2.

Tested-by: Sam James <sam@gentoo.org>
3 months agoApply the Makefile sorting fix
H.J. Lu [Thu, 15 Feb 2024 19:19:56 +0000 (11:19 -0800)] 
Apply the Makefile sorting fix

Apply the Makefile sorting fix generated by sort-makefile-lines.py.

3 months agosysdeps/x86_64/Makefile (tests): Add the end marker
H.J. Lu [Thu, 15 Feb 2024 19:12:13 +0000 (11:12 -0800)] 
sysdeps/x86_64/Makefile (tests): Add the end marker

3 months agosort-makefile-lines.py: Allow '_' in name and "^# name"
H.J. Lu [Thu, 15 Feb 2024 11:22:55 +0000 (03:22 -0800)] 
sort-makefile-lines.py: Allow '_' in name and "^# name"

'_' is used in Makefile variable names and many variables end with
"^# name".  Relax sort-makefile-lines.py to allow '_' in name and
"^# name" as variable end.  This fixes BZ #31385.

3 months agotrivial doc fix: remove weird phrase "syscall takes zero to five arguments"
Askar Safin [Mon, 12 Feb 2024 16:48:55 +0000 (19:48 +0300)] 
trivial doc fix: remove weird phrase "syscall takes zero to five arguments"

"number of arguments, from zero to five" is wrong, because on Linux maximal number
of arguments is 6, not 5. Also, maximal number of arguments is kernel-dependent,
so let's not include it here at all.

Moreover, "Each kind of system call has a definite number of arguments" is questionable.
Think about SYS_open on Linux, which takes 2 or 3 arguments. Or SYS_clone on Linux x86_64, which
takes 2 to 5 arguments. So I propose to fully remove this sentence.

Signed-off-by: Askar Safin <safinaskar@zohomail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agomips: Use builtins for ffs and ffsll
Junxian Zhu [Tue, 6 Feb 2024 08:34:56 +0000 (16:34 +0800)] 
mips: Use builtins for ffs and ffsll

__builtin_ffs{,ll} basically on __builtin_ctz{,ll} in MIPS GCC compiler.
The hardware ctz instructions were available after MIPS{32,64} Release1. By using builtin ctz. It can also reduce code size of ffs/ffsll.

Checked on mips o32. mips64.

Signed-off-by: Junxian Zhu <zhujunxian@oss.cipunited.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
3 months agox86: Expand the comment on when REP STOSB is used on memset
Adhemerval Zanella [Thu, 8 Feb 2024 13:08:40 +0000 (10:08 -0300)] 
x86: Expand the comment on when REP STOSB is used on memset

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 months agox86: Do not prefer ERMS for memset on Zen3+
Adhemerval Zanella [Thu, 8 Feb 2024 13:08:39 +0000 (10:08 -0300)] 
x86: Do not prefer ERMS for memset on Zen3+

For AMD Zen3+ architecture, the performance of the vectorized loop is
slightly better than ERMS.

Checked on x86_64-linux-gnu on Zen3.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 months agox86: Fix Zen3/Zen4 ERMS selection (BZ 30994)
Adhemerval Zanella [Thu, 8 Feb 2024 13:08:38 +0000 (10:08 -0300)] 
x86: Fix Zen3/Zen4 ERMS selection (BZ 30994)

The REP MOVSB usage on memcpy/memmove does not show much performance
improvement on Zen3/Zen4 cores compared to the vectorized loops.  Also,
as from BZ 30994, if the source is aligned and the destination is not
the performance can be 20x slower.

The performance difference is noticeable with small buffer sizes, closer
to the lower bounds limits when memcpy/memmove starts to use ERMS.  The
performance of REP MOVSB is similar to vectorized instruction on the
size limit (the L2 cache).  Also, there is no drawback to multiple cores
sharing the cache.

Checked on x86_64-linux-gnu on Zen3.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>