]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
22 months agox86: Move wcschr SSE2 implementation to multiarch/wcschr-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:29:07 +0000 (12:29 -0700)] 
x86: Move wcschr SSE2 implementation to multiarch/wcschr-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move strcat SSE2 implementation to multiarch/strcat-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:29:06 +0000 (12:29 -0700)] 
x86: Move strcat SSE2 implementation to multiarch/strcat-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move strchr SSE2 implementation to multiarch/strchr-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:29:05 +0000 (12:29 -0700)] 
x86: Move strchr SSE2 implementation to multiarch/strchr-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move strrchr SSE2 implementation to multiarch/strrchr-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:29:04 +0000 (12:29 -0700)] 
x86: Move strrchr SSE2 implementation to multiarch/strrchr-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move memrchr SSE2 implementation to multiarch/memrchr-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:29:03 +0000 (12:29 -0700)] 
x86: Move memrchr SSE2 implementation to multiarch/memrchr-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move strcpy SSE2 implementation to multiarch/strcpy-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:29:02 +0000 (12:29 -0700)] 
x86: Move strcpy SSE2 implementation to multiarch/strcpy-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move strlen SSE2 implementation to multiarch/strlen-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:29:01 +0000 (12:29 -0700)] 
x86: Move strlen SSE2 implementation to multiarch/strlen-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move strcmp SSE42 implementation to multiarch/strcmp-sse4_2.S
Noah Goldstein [Tue, 12 Jul 2022 19:28:08 +0000 (12:28 -0700)] 
x86: Move strcmp SSE42 implementation to multiarch/strcmp-sse4_2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move wcscmp SSE2 implementation to multiarch/wcscmp-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:28:07 +0000 (12:28 -0700)] 
x86: Move wcscmp SSE2 implementation to multiarch/wcscmp-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Move strcmp SSE2 implementation to multiarch/strcmp-sse2.S
Noah Goldstein [Tue, 12 Jul 2022 19:28:06 +0000 (12:28 -0700)] 
x86: Move strcmp SSE2 implementation to multiarch/strcmp-sse2.S

This commit doesn't affect libc.so.6, its just housekeeping to prepare
for adding explicit ISA level support.

Because strcmp-sse2.S implements so many functions (more from
avx2/evex/sse42) add a new file 'strcmp-naming.h' to assist in
getting the correct symbol name for all the function across
multiarch/non-multiarch builds.

Tested build on x86_64 and x86_32 with/without multiarch.

22 months agox86: Rename STRCASECMP_NONASCII macro to STRCASECMP_L_NONASCII
Noah Goldstein [Tue, 12 Jul 2022 19:28:05 +0000 (12:28 -0700)] 
x86: Rename STRCASECMP_NONASCII macro to STRCASECMP_L_NONASCII

The previous macro name can be confusing given that both
`__strcasecmp_l_nonascii` and `__strcasecmp_nonascii` are
functions and we use the `_l` version.

22 months agonptl: Fix ___pthread_unregister_cancel_restore asynchronous restore
Adhemerval Zanella [Wed, 13 Jul 2022 13:37:32 +0000 (10:37 -0300)] 
nptl: Fix ___pthread_unregister_cancel_restore asynchronous restore

This was due a wrong revert done on 404656009b459658.

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

22 months agox86: Remove __mmask intrinsics in strstr-avx512.c
Noah Goldstein [Tue, 12 Jul 2022 18:48:04 +0000 (11:48 -0700)] 
x86: Remove __mmask intrinsics in strstr-avx512.c

The intrinsics are not available before GCC7 and using standard
operators generates code of equivalent or better quality.

Removed:
    _cvtmask64_u64
    _kshiftri_mask64
    _kand_mask64

Geometric Mean of 5 Runs of Full Benchmark Suite New / Old: 0.958

22 months agox86: Remove generic strncat, strncpy, and stpncpy implementations
Noah Goldstein [Wed, 6 Jul 2022 00:06:41 +0000 (17:06 -0700)] 
x86: Remove generic strncat, strncpy, and stpncpy implementations

These functions all have optimized versions:
__strncat_sse2_unaligned, __strncpy_sse2_unaligned, and
stpncpy_sse2_unaligned which are faster than their respective generic
implementations.  Since the sse2 versions can run on baseline x86_64,
we should use these as the baseline implementation and can remove the
generic implementations.

Geometric mean of N=20 runs of the entire benchmark suite on:
11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz (Tigerlake)

__strncat_sse2_unaligned / __strncat_generic: .944
__strncpy_sse2_unaligned / __strncpy_generic: .726
__stpncpy_sse2_unaligned / __stpncpy_generic: .650

Tested build with and without multiarch and full check with multiarch.

22 months agoi386: Remove -Wa,-mtune=i686
Fangrui Song [Tue, 12 Jul 2022 18:14:32 +0000 (11:14 -0700)] 
i386: Remove -Wa,-mtune=i686

gas -mtune= may change NOP generating patterns but -mtune=i686 has no
difference from the default by inspecting .o and .os files.

Note: Clang doesn't support -Wa,-mtune=i686.

22 months agox86-64: Remove redundant strcspn-generic/strpbrk-generic/strspn-generic
H.J. Lu [Fri, 8 Jul 2022 23:06:04 +0000 (16:06 -0700)] 
x86-64: Remove redundant strcspn-generic/strpbrk-generic/strspn-generic

Remove redundant strcspn-generic, strpbrk-generic and strspn-generic
from sysdep_routines in sysdeps/x86_64/multiarch/Makefile added by

commit c69f960b017b2cdf39335739009526a72fb20379
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Sun Jul 3 21:28:07 2022 -0700

    x86: Add support for building str{c|p}{brk|spn} with explicit ISA level

since they have been added to sysdep_routines in sysdeps/x86_64/Makefile.

22 months agoelf: Rename tst-audit26 to tst-audit28
Florian Weimer [Fri, 8 Jul 2022 10:08:48 +0000 (12:08 +0200)] 
elf: Rename tst-audit26 to tst-audit28

tst-audit26 and tst-audit27 are already used by aarch64.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
22 months agox86-64: Don't mark symbols as hidden in strcmp-XXX.S
H.J. Lu [Thu, 7 Jul 2022 23:20:50 +0000 (16:20 -0700)] 
x86-64: Don't mark symbols as hidden in strcmp-XXX.S

Don't mark symbols as hidden in strcmp-avx2.S, strcmp-evex.S and
strcmp-sse42.S since they are marked as hidden in the IFUNC selectors.

22 months agostdlib: Tests for mbrtoc8, c8rtomb, and the char8_t typedef.
Tom Honermann [Thu, 30 Jun 2022 12:52:15 +0000 (08:52 -0400)] 
stdlib: Tests for mbrtoc8, c8rtomb, and the char8_t typedef.

This change adds tests for the mbrtoc8 and c8rtomb functions adopted for
C++20 via WG21 P0482R6 and for C2X via WG14 N2653, and for the char8_t
typedef adopted for C2X from WG14 N2653.

The tests for mbrtoc8 and c8rtomb specifically exercise conversion to
and from Big5-HKSCS because of special cases that arise with that encoding.
Big5-HKSCS defines some double byte sequences that convert to more than
one Unicode code point.  In order to test this, the locale dependencies
for running tests under wcsmbs is expanded to include zh_HK.BIG5-HKSCS.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
22 months agostdlib: Implement mbrtoc8, c8rtomb, and the char8_t typedef.
Tom Honermann [Thu, 30 Jun 2022 12:52:14 +0000 (08:52 -0400)] 
stdlib: Implement mbrtoc8, c8rtomb, and the char8_t typedef.

This change provides implementations for the mbrtoc8 and c8rtomb
functions adopted for C++20 via WG21 P0482R6 and for C2X via WG14
N2653.  It also provides the char8_t typedef from WG14 N2653.

The mbrtoc8 and c8rtomb functions are declared in uchar.h in C2X
mode or when the _GNU_SOURCE macro or C++20 __cpp_char8_t feature
test macro is defined.

The char8_t typedef is declared in uchar.h in C2X mode or when the
_GNU_SOURCE macro is defined and the C++20 __cpp_char8_t feature
test macro is not defined (if __cpp_char8_t is defined, then char8_t
is a builtin type).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
22 months agogconv: Correct Big5-HKSCS conversion to preserve all state bits. [BZ #25744]
Tom Honermann [Thu, 30 Jun 2022 12:52:13 +0000 (08:52 -0400)] 
gconv: Correct Big5-HKSCS conversion to preserve all state bits. [BZ #25744]

This patch corrects the Big5-HKSCS converter to preserve the lowest 3 bits of
the mbstate_t __count data member when the converter encounters an incomplete
multibyte character.

This fixes BZ #25744.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
22 months agoaarch64: Optimize string functions with shrn instruction
Danila Kutenin [Mon, 27 Jun 2022 16:12:13 +0000 (16:12 +0000)] 
aarch64: Optimize string functions with shrn instruction

We found that string functions were using AND+ADDP
to find the nibble/syndrome mask but there is an easier
opportunity through `SHRN dst.8b, src.8h, 4` (shift
right every 2 bytes by 4 and narrow to 1 byte) and has
same latency on all SIMD ARMv8 targets as ADDP. There
are also possible gaps for memcmp but that's for
another patch.

We see 10-20% savings for small-mid size cases (<=128)
which are primary cases for general workloads.

23 months agotest-container: return UNSUPPORTED for ENOSPC on clone()
Xi Ruoyao [Tue, 28 Jun 2022 10:44:03 +0000 (18:44 +0800)] 
test-container: return UNSUPPORTED for ENOSPC on clone()

Since Linux 4.9, the kernel provides
/proc/sys/user/max_{mnt,pid,user}_namespace as a limitation of number of
namespaces.  Some distros (for example, Slint Linux 14.2.1) set them (or
only max_user_namespace) to zero as a "security policy" for disabling
namespaces.

The clone() call will set errno to ENOSPC under such a limitation.  We
didn't check ENOSPC in the code so the test will FAIL, and report:

    unable to unshare user/fs: No space left on device

This message is, unfortunately, very unhelpful.  It leads people to
check the memory or disk space, instead of finding the real issue.

To improve the situation, we should check for ENOSPC and return
UNSUPPORTED as the test result.  Also refactor check_for_unshare_hints()
to emit a proper message telling people how to make the test work, if
they really need to run the namespaced tests.

Reported-by: Philippe Delavalade <philippe.delavalade@orange.fr>
URL: https://lists.linuxfromscratch.org/sympa/arc/lfs-support/2022-06/msg00022.html
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: DJ Delorie <dj@redhat.com>
23 months agox86: Add support for building {w}memcmp{eq} with explicit ISA level
Noah Goldstein [Wed, 29 Jun 2022 23:11:22 +0000 (16:11 -0700)] 
x86: Add support for building {w}memcmp{eq} with explicit ISA level

1. Refactor files so that all implementations are in the multiarch
   directory
    - Moved the implementation portion of memcmp sse2 from memcmp.S to
      multiarch/memcmp-sse2.S

    - The non-multiarch file now only includes one of the
      implementations in the multiarch directory based on the compiled
      ISA level (only used for non-multiarch builds.  Otherwise we go
      through the ifunc selector).

2. Add ISA level build guards to different implementations.
    - I.e memcmp-avx2-movsb.S which is ISA level 3 will only build if
      compiled ISA level <= 3. Otherwise there is no reason to include
      it as we will always use one of the ISA level 4
      implementations (memcmp-evex-movbe.S).

3. Add new multiarch/rtld-{w}memcmp{eq}.S that just include the
   non-multiarch {w}memcmp{eq}.S which will in turn select the best
   implementation based on the compiled ISA level.

4. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

23 months agox86: Add support for building {w}memset{_chk} with explicit ISA level
Noah Goldstein [Wed, 29 Jun 2022 23:07:06 +0000 (16:07 -0700)] 
x86: Add support for building {w}memset{_chk} with explicit ISA level

1. Refactor files so that all implementations are in the multiarch
   directory
    - Moved the implementation portion of memset sse2 from memset.S to
      multiarch/memset-sse2.S

    - The non-multiarch file now only includes one of the
      implementations in the multiarch directory based on the compiled
      ISA level (only used for non-multiarch builds.  Otherwise we go
      through the ifunc selector).

2. Add ISA level build guards to different implementations.
    - I.e memset-avx2-unaligned-erms.S which is ISA level 3 will only
      build if compiled ISA level <= 3. Otherwise there is no reason
      to include it as we will always use one of the ISA level 4
      implementations (memset-evex-unaligned-erms.S).

3. Add new multiarch/rtld-memset.S that just include the
   non-multiarch memset.S which will in turn select the best
   implementation based on the compiled ISA level.

4. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

23 months agox86: Add support for building {w}memmove{_chk} with explicit ISA level
Noah Goldstein [Tue, 5 Jul 2022 19:41:07 +0000 (12:41 -0700)] 
x86: Add support for building {w}memmove{_chk} with explicit ISA level

1. Refactor files so that all implementations are in the multiarch
   directory
    - Moved the implementation portion of memmove sse2 from memmove.S
      to multiarch/memmove-sse2.S

    - The non-multiarch file now only includes one of the
      implementations in the multiarch directory based on the compiled
      ISA level (only used for non-multiarch builds.  Otherwise we go
      through the ifunc selector).

2. Add ISA level build guards to different implementations.
    - I.e memmove-avx2-unaligned-erms.S which is ISA level 3 will only
      build if compiled ISA level <= 3. Otherwise there is no reason
      to include it as we will always use one of the ISA level 4
      implementations (memmove-evex-unaligned-erms.S).

3. Add new multiarch/rtld-memmove.S that just include the
   non-multiarch memmove.S which will in turn select the best
   implementation based on the compiled ISA level.

4. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.
isa raising memmove

23 months agox86: Add support for building str{c|p}{brk|spn} with explicit ISA level
Noah Goldstein [Mon, 4 Jul 2022 04:28:07 +0000 (21:28 -0700)] 
x86: Add support for building str{c|p}{brk|spn} with explicit ISA level

The changes for these functions are different than the others because
the best implementation (sse4_2) requires the generic
implementation as a fallback to be built as well.

Changes are:

1. Add non-multiarch functions for str{c|p}{brk|spn}.c to statically
   select the best implementation based on the configured ISA build
   level.

2. Add stubs for str{c|p}{brk|spn}-generic and varshift.c to in the
   sysdeps/x86_64 directory so that the the sse4 implementation will
   have all of its dependencies for the non-multiarch / rtld build
   when ISA level >= 2.

3. Add new multiarch/rtld-strcspn.c that just include the
   non-multiarch strcspn.c which will in turn select the best
   implementation based on the compiled ISA level.

4. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

23 months agox86: Add comment explaining no Slow_SSE4_2 check in ifunc-sse4_2
Noah Goldstein [Mon, 4 Jul 2022 04:28:06 +0000 (21:28 -0700)] 
x86: Add comment explaining no Slow_SSE4_2 check in ifunc-sse4_2

Just for clarities sake and so that if a future implementation is
added we remember to add the check.

23 months agoReplace __libc_multiple_threads with __libc_single_threaded
Adhemerval Zanella [Tue, 7 Jun 2022 16:09:40 +0000 (13:09 -0300)] 
Replace __libc_multiple_threads with __libc_single_threaded

And also fixes the SINGLE_THREAD_P macro for SINGLE_THREAD_BY_GLOBAL,
since header inclusion single-thread.h is in the wrong order, the define
needs to come before including sysdeps/unix/sysdep.h.  The macro
is now moved to a per-arch single-threade.h header.

The SINGLE_THREAD_P is used on some more places.

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

23 months agolinux: Add mount_setattr
Adhemerval Zanella [Fri, 24 Jun 2022 19:59:19 +0000 (16:59 -0300)] 
linux: Add mount_setattr

It was added on Linux 5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd)
to allow change the properties of a mount or a mount tree using file
descriptors which the new mount api is based on.

Checked on x86_64-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agolinux: Add tst-mount to check for Linux new mount API
Adhemerval Zanella [Fri, 24 Jun 2022 19:59:18 +0000 (16:59 -0300)] 
linux: Add tst-mount to check for Linux new mount API

The new mount API was added on Linux 5.2 with six new syscalls:
fsopen, fsconfig, fsmount, move_mount, fspick, and open_tree.

The new test verifies minimal functionality along with error paths
for specific arguments and their corner cases.

Checked on x86_64-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agolinux: Add open_tree
Adhemerval Zanella [Fri, 24 Jun 2022 19:59:17 +0000 (16:59 -0300)] 
linux: Add open_tree

It was added on Linux 5.2 (a07b20004793d8926f78d63eb5980559f7813404)
to return a O_PATH-opened file descriptor to an existing mountpoint.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agolinux: Add fspick
Adhemerval Zanella [Fri, 24 Jun 2022 19:59:16 +0000 (16:59 -0300)] 
linux: Add fspick

It was added on Linux 5.2 (cf3cba4a429be43e5527a3f78859b1bfd9ebc5fb)
that can be used to pick an existing mountpoint into an filesystem
context which can thereafter be used to reconfigure a superblock
with fsconfig syscall.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agolinux: Add fsconfig
Adhemerval Zanella [Fri, 24 Jun 2022 19:59:15 +0000 (16:59 -0300)] 
linux: Add fsconfig

It was added on Linux 5.2 (ecdab150fddb42fe6a739335257949220033b782)
as a way to a configure filesystem creation context and trigger
actions upon it, to be used in conjunction with fsopen, fspick and
fsmount.

The fsconfig_command commands are currently only defined as an enum,
so they can't be checked on tst-mount-consts.py with current test
support.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agoAArch64: Reset HWCAP2_AFP bits in FPCR for default fenv
Tejas Belagod [Tue, 5 Jul 2022 10:35:24 +0000 (11:35 +0100)] 
AArch64: Reset HWCAP2_AFP bits in FPCR for default fenv

The AFP feature (Alternate floating-point behavior) was added in armv8.7 and
introduced new FPCR bits.

Currently, HWCAP2_AFP bits (bit 0, 1, 2) in FPCR are preserved when fenv is
set to default environment.  This is a deviation from standard behaviour.
Clear these bits when setting the fenv to default.

There is no libc API to modify the new FPCR bits.  Restoring those bits matters
if the user changed them directly.

23 months agoelf: Fix direction of NODELETE log messages during symbol lookup
Florian Weimer [Tue, 5 Jul 2022 12:40:38 +0000 (14:40 +0200)] 
elf: Fix direction of NODELETE log messages during symbol lookup

NODELETE status is propagated from the referencing object to the
referenced object, not the other way round.  The code is correct, only
the log message has the wrong direction.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agomalloc: Simplify checked_request2size interface
Florian Weimer [Tue, 5 Jul 2022 09:04:45 +0000 (11:04 +0200)] 
malloc: Simplify checked_request2size interface

In-band signaling avoids an uninitialized variable warning when
building with -Og and GCC 12.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
23 months agostdlib: Simplify buffer management in canonicalize
Florian Weimer [Tue, 5 Jul 2022 09:04:45 +0000 (11:04 +0200)] 
stdlib: Simplify buffer management in canonicalize

Move the buffer management from realpath_stk to __realpath.  This
allows returning directly after allocation errors.

Always make a copy of the result buffer using strdup even if it is
already heap-allocated.  (Heap-allocated buffers are somewhat rare.)
This avoids GCC warnings at certain optimization levels.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
23 months agolocaledef: Support building for older C standards
Florian Weimer [Tue, 5 Jul 2022 08:30:20 +0000 (10:30 +0200)] 
localedef: Support building for older C standards

Fixes commit b15538d77c6a7893c8bb42831dcd3a1a12b727d4
("locale: localdef input files are now encoded in UTF-8").

23 months agode_DE: Convert to UTF-8
Florian Weimer [Tue, 5 Jul 2022 07:05:47 +0000 (09:05 +0200)] 
de_DE: Convert to UTF-8

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agolocale: localdef input files are now encoded in UTF-8
Florian Weimer [Tue, 5 Jul 2022 07:05:45 +0000 (09:05 +0200)] 
locale: localdef input files are now encoded in UTF-8

Previously, they were assumed to be in ISO-8859-1, and that the output
charset overlapped with ISO-8859-1 for the characters actually used.
However, this did not work as intended on many architectures even for
an ISO-8859-1 output encoding because of the char signedness bug in
lr_getc.  Therefore, this commit switches to UTF-8 without making
provisions for backwards compatibility.

The following Elisp code can be used to convert locale definition files
to UTF-8:

(defun glibc/convert-localedef (from to)
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region from to)
      (goto-char (point-min))
      (save-match-data
(while (re-search-forward "<U\\([0-9a-fA-F]+\\)>" nil t)
  (let* ((codepoint (string-to-number (match-string 1) 16))
 (converted
  (cond
   ((memq codepoint '(?/ ?\ ?< ?>))
    (string ?/ codepoint))
   ((= codepoint ?\") "<U0022>")
   (t (string codepoint)))))
    (replace-match converted t)))))))

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agolocale: Introduce translate_unicode_codepoint into linereader.c
Florian Weimer [Tue, 5 Jul 2022 07:05:22 +0000 (09:05 +0200)] 
locale: Introduce translate_unicode_codepoint into linereader.c

This will permit reusing the Unicode character processing for
different character encodings, not just the current <U...> encoding.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agolocale: Fix signed char bug in lr_getc
Florian Weimer [Tue, 5 Jul 2022 07:05:22 +0000 (09:05 +0200)] 
locale: Fix signed char bug in lr_getc

The array lr->buf contains characters, which can be signed.  A 0xff
byte in the input could be incorrectly reported as EOF.  More
importantly, get_string in linereader.c converts a signed input byte
to a Unicode code point using ADDWC ((uint32_t) ch), under the
assumption that this decodes the ISO-8859-1 input encoding.  If char
is signed, this does not give the correct result.  This means that
ISO-8859-1 input files for localedef are not actually supported,
contrary to the comment in get_string.  This is a happy accident because
we can therefore change the file encoding to UTF-8 without impacting
backwards compatibility.

While at it, remove the \32 check for MS-DOS end-of-file character (^Z).

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agolocale: Turn ADDC and ADDS into functions in linereader.c
Florian Weimer [Tue, 5 Jul 2022 07:05:22 +0000 (09:05 +0200)] 
locale: Turn ADDC and ADDS into functions in linereader.c

And introduce struct lr_buffer.  The functions addc and adds can
be called from functions, enabling subsequent refactoring.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agolibc-symbols.h: remove unused macros
Fangrui Song [Tue, 5 Jul 2022 04:15:51 +0000 (21:15 -0700)] 
libc-symbols.h: remove unused macros

Beside weak_hidden_alias/declare_symbol_alias/hidden_data_ver, many
*_hidden_* macros are removed.  If there is a rare need to use one, one
may write something like `#if IS_IN (libm)\nhidden_def (...)\n#endif`
instead.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agoFix hurd namespace issues for internal signal functions
Adhemerval Zanella [Mon, 4 Jul 2022 13:41:58 +0000 (10:41 -0300)] 
Fix hurd namespace issues for internal signal functions

It was introduced by "Refactor internal-signals.h
(a1bdd81664aa681364d)".  Use the internal symbols instead.

Checked with a build for i686-gnu.

23 months agoargp: Remove old includes in !_LIBC case
Guilherme Janczak [Wed, 22 Jun 2022 14:42:39 +0000 (14:42 +0000)] 
argp: Remove old includes in !_LIBC case

The headers mempcpy.h, strcase.h, strchrnul.h, and strndup.h are
included if not building argp for glibc. Commit
c5af724c0b214a517f8558887f7a70efcfa2c813 added them in 2003 for gnulib,
but gnulib's current master patches them out:
https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/argp-namefrob.h;h=9c82ac79c215540f986c3e04398edba3ba1b7234;hb=HEAD

23 months agoUse GCC 12 branch in build-many-glibcs.py
Joseph Myers [Mon, 4 Jul 2022 13:15:58 +0000 (13:15 +0000)] 
Use GCC 12 branch in build-many-glibcs.py

This patch makes build-many-glibcs.py use GCC 12 branch by default.

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

23 months agoRefactor internal-signals.h
Adhemerval Zanella [Thu, 21 Apr 2022 12:41:59 +0000 (09:41 -0300)] 
Refactor internal-signals.h

The main drive is to optimize the internal usage and required size
when sigset_t is embedded in other data structures.  On Linux, the
current supported signal set requires up to 8 bytes (16 on mips),
was lower than the user defined sigset_t (128 bytes).

A new internal type internal_sigset_t is added, along with the
functions to operate on it similar to the ones for sigset_t.  The
internal-signals.h is also refactored to remove unused functions

Besides small stack usage on some functions (posix_spawn, abort)
it lower the struct pthread by about 120 bytes (112 on mips).

Checked on x86_64-linux-gnu.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
23 months agoriscv: Use memcpy to handle unaligned access when fixing R_RISCV_RELATIVE
Kito Cheng [Tue, 28 Jun 2022 13:52:19 +0000 (21:52 +0800)] 
riscv: Use memcpy to handle unaligned access when fixing R_RISCV_RELATIVE

Although RISC-V Linux will enable the unaligned memory access handler by
default, that is quite expensive in general, using memcpy will be much cheaper
- just break down that into several load/store byte instructions.

ARM and MIPS has similar issue:

ARM: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51456
MIPS: https://gcc.gnu.org/legacy-ml/gcc-help/2005-07/msg00325.html

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agoAArch64: Add asymmetric faulting mode for tag violations in mem.tagging tunable
Tejas Belagod [Mon, 27 Jun 2022 18:00:50 +0000 (18:00 +0000)] 
AArch64: Add asymmetric faulting mode for tag violations in mem.tagging tunable

The new asymmetric mode is available when HWCAP2_MTE3 is set (support is
available), bit2 is set in the tunable (user request per application),
and the system is configured such that the asymmetric mode is preferred over
sync or async (per-cpu system-wide setting).

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
23 months agolinux: Fix mq_timereceive check for 32 bit fallback code (BZ 29304)
Adhemerval Zanella [Thu, 30 Jun 2022 12:08:31 +0000 (09:08 -0300)] 
linux: Fix mq_timereceive check for 32 bit fallback code (BZ 29304)

On  success,  mq_receive() and mq_timedreceive() return the number of
bytes in the received message, so it requires to check if the value
is larger than 0.

Checked on i686-linux-gnu.

23 months agox86: Add missing IS_IN (libc) check to strncmp-sse4_2.S
Noah Goldstein [Thu, 30 Jun 2022 01:56:18 +0000 (18:56 -0700)] 
x86: Add missing IS_IN (libc) check to strncmp-sse4_2.S

Was missing to for the multiarch build rtld-strncmp-sse4_2.os was
being built and exporting symbols:

build/glibc/string/rtld-strncmp-sse4_2.os:
0000000000000000 T __strncmp_sse42

Introduced in:

commit 11ffcacb64a939c10cfc713746b8ec88837f5c4a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jun 21 12:10:50 2017 -0700

    x86-64: Implement strcmp family IFUNC selectors in C

23 months agox86: Add missing IS_IN (libc) check to strcspn-sse4.c
Noah Goldstein [Thu, 30 Jun 2022 01:56:17 +0000 (18:56 -0700)] 
x86: Add missing IS_IN (libc) check to strcspn-sse4.c

Was missing to for the multiarch build rtld-strcspn-sse4.os was
being built and exporting symbols:

build/glibc/string/rtld-strcspn-sse4.os:
                 U ___m128i_shift_right
                 U __strcspn_generic
0000000000000000 T __strcspn_sse42
                 U strlen

build/glibc/string/rtld-varshift.os:
0000000000000000 R ___m128i_shift_right

Introduced in:

commit 06e51c8f3de38761f8855700841bc49cf495c8c0
Author: H.J. Lu <hongjiu.lu@intel.com>
Date:   Fri Jul 3 02:48:56 2009 -0700

    Add SSE4.2 support for strcspn, strpbrk, and strspn on x86-64.

23 months agox86: Add missing IS_IN (libc) check to memmove-ssse3.S
Noah Goldstein [Thu, 30 Jun 2022 01:56:16 +0000 (18:56 -0700)] 
x86: Add missing IS_IN (libc) check to memmove-ssse3.S

Was missing to for the multiarch build rtld-memmove-ssse3.os was
being built and exporting symbols:

>$ nm string/rtld-memmove-ssse3.os
                 U __GI___chk_fail
0000000000000020 T __memcpy_chk_ssse3
0000000000000040 T __memcpy_ssse3
0000000000000020 T __memmove_chk_ssse3
0000000000000040 T __memmove_ssse3
0000000000000000 T __mempcpy_chk_ssse3
0000000000000010 T __mempcpy_ssse3
                 U __x86_shared_cache_size_half

Introduced after 2.35 in:

commit 26b2478322db94edc9e0e8f577b2f71d291e5acb
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Thu Apr 14 11:47:40 2022 -0500

    x86: Reduce code size of mem{move|pcpy|cpy}-ssse3

23 months agox86-64: Properly indent X86_IFUNC_IMPL_ADD_VN arguments
H.J. Lu [Wed, 29 Jun 2022 20:42:06 +0000 (13:42 -0700)] 
x86-64: Properly indent X86_IFUNC_IMPL_ADD_VN arguments

Properly indent X86_IFUNC_IMPL_ADD_VN arguments for memchr, rawmemchr
and wmemchr.

Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
23 months agox86-64: Small improvements to dl-trampoline.S
Noah Goldstein [Tue, 28 Jun 2022 15:26:26 +0000 (08:26 -0700)] 
x86-64: Small improvements to dl-trampoline.S

1.  Remove sse2 instructions when using the avx512 or avx version.

2.  Fixup some format nits in how the address offsets where aligned.

3.  Use more space efficient instructions in the conditional AVX
    restoral.
        - vpcmpeqq          -> vpcmpeqb
        - cmp imm32, r; jz  -> inc r; jz

4.  Use `rep movsb` instead of `rep movsq`. The former is guranteed to
    be fast with the ERMS flags, the latter is not. The latter also
    wastes an instruction in size setup.

23 months agox86: Move mem{p}{mov|cpy}_{chk_}erms to its own file
Noah Goldstein [Wed, 29 Jun 2022 23:07:15 +0000 (16:07 -0700)] 
x86: Move mem{p}{mov|cpy}_{chk_}erms to its own file

The primary memmove_{impl}_unaligned_erms implementations don't
interact with this function. Putting them in same file both
wastes space and unnecessarily bloats a hot code section.

23 months agox86: Move and slightly improve memset_erms
Noah Goldstein [Wed, 29 Jun 2022 23:07:05 +0000 (16:07 -0700)] 
x86: Move and slightly improve memset_erms

Implementation wise:
    1. Remove the VZEROUPPER as memset_{impl}_unaligned_erms does not
       use the L(stosb) label that was previously defined.

    2. Don't give the hotpath (fallthrough) to zero size.

Code positioning wise:

Move memset_{chk}_erms to its own file.  Leaving it in between the
memset_{impl}_unaligned both adds unnecessary complexity to the
file and wastes space in a relatively hot cache section.

23 months agox86: Add definition for __wmemset_chk AVX2 RTM in ifunc impl list
Noah Goldstein [Wed, 29 Jun 2022 23:07:04 +0000 (16:07 -0700)] 
x86: Add definition for __wmemset_chk AVX2 RTM in ifunc impl list

This was simply missing and meant we weren't testing it properly.

23 months agolinux: Remove unnecessary nice.c and signal.c
Arjun Shankar [Wed, 29 Jun 2022 22:37:34 +0000 (00:37 +0200)] 
linux: Remove unnecessary nice.c and signal.c

These files simply include the sysdeps/posix implementations which would
be used even in the absence of the files.  They have been unnecessary
since 7b17aeda0c5e when nice and signal were removed from the
syscalls.list file.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agonptl: Remove unused members from struct pthread
Adhemerval Zanella [Thu, 21 Apr 2022 12:44:48 +0000 (09:44 -0300)] 
nptl: Remove unused members from struct pthread

It removes both pid_ununsed and cpuclock_offset_ununsed, saving about
12 bytes from struct pthread.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
23 months agoLinux: Forward declaration of struct iovec for process_madvise
Florian Weimer [Wed, 29 Jun 2022 11:50:50 +0000 (13:50 +0200)] 
Linux: Forward declaration of struct iovec for process_madvise

This maintains compatibility between <sys/mman.h> and <linux/uio.h>.
Before that, the addition of process_madvise made those two header
files incompatible.  This has been observed resulting in a build
failure in LLDB's Process/Linux/NativeRegisterContextLinux_s390x.cpp
source file.

Fixes commit d19ee3473d68ca0e794f3a8b7677a0983ae1342e
("linux: Add process_madvise").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agox86: Add more feature definitions to isa-level.h
Noah Goldstein [Tue, 28 Jun 2022 04:07:03 +0000 (21:07 -0700)] 
x86: Add more feature definitions to isa-level.h

This commit doesn't change anything in itself.  It is just to add
definitions that will be needed by future patches.

23 months agoelf: Fix -DNDEBUG warning in _dl_start_args_adjust
Florian Weimer [Tue, 28 Jun 2022 08:40:16 +0000 (10:40 +0200)] 
elf: Fix -DNDEBUG warning in _dl_start_args_adjust

This is another blocker for building glibc with the default
-Werror setting and -DNDEBUG.

23 months agoelf: Fix compile error with -Werror and -DNDEBUG
Yang Yanchao [Fri, 15 Apr 2022 09:25:05 +0000 (17:25 +0800)] 
elf: Fix compile error with -Werror and -DNDEBUG

Using -Werror and -DNDEBUG at the same time will trigger the
following compiler error:

cache.c: In function 'save_cache':
cache.c:758:15: error: unused variable 'old_offset' [-Werror=unused-variable]
  758 |       off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET);
      |               ^~~~~~~~~~

-DNDEBUG disables the assertion, making old_offset unused.
Use __attribute__ ((unused)) to disable this warning.

23 months agox86-64: Only define used SSE/AVX/AVX512 run-time resolvers
H.J. Lu [Mon, 27 Jun 2022 18:36:28 +0000 (11:36 -0700)] 
x86-64: Only define used SSE/AVX/AVX512 run-time resolvers

When glibc is built with x86-64 ISA level v3, SSE run-time resolvers
aren't used.  For x86-64 ISA level v4 build, both SSE and AVX resolvers
are unused.  Check the minimum x86-64 ISA level to exclude the unused
run-time resolvers.

23 months agox86: Move CPU_FEATURE{S}_{USABLE|ARCH}_P to isa-level.h
H.J. Lu [Mon, 27 Jun 2022 19:52:58 +0000 (12:52 -0700)] 
x86: Move CPU_FEATURE{S}_{USABLE|ARCH}_P to isa-level.h

Move X86_ISA_CPU_FEATURE_USABLE_P and X86_ISA_CPU_FEATURES_ARCH_P to
where MINIMUM_X86_ISA_LEVEL and XXX_X86_ISA_LEVEL are defined.

23 months agox86: Fix backwards Prefer_No_VZEROUPPER check in ifunc-evex.h
Noah Goldstein [Fri, 24 Jun 2022 23:15:42 +0000 (16:15 -0700)] 
x86: Fix backwards Prefer_No_VZEROUPPER check in ifunc-evex.h

Add third argument to X86_ISA_CPU_FEATURES_ARCH_P macro so the runtime
CPU_FEATURES_ARCH_P check can be inverted if the
MINIMUM_X86_ISA_LEVEL is not high enough to constantly evaluate
the check.

Use this new macro to correct the backwards check in ifunc-evex.h

23 months agox86: Rename strstr_sse2 to strstr_generic as it uses string/strstr.c
Noah Goldstein [Fri, 24 Jun 2022 16:42:13 +0000 (09:42 -0700)] 
x86: Rename strstr_sse2 to strstr_generic as it uses string/strstr.c

This is in accordance with other files in the multiarch directory.

23 months agox86: Remove unused file wmemcmp-sse4
Noah Goldstein [Fri, 24 Jun 2022 16:42:14 +0000 (09:42 -0700)] 
x86: Remove unused file wmemcmp-sse4

The memcmp-sse4 was removed in:

commit 7cbc03d03091d5664060924789afe46d30a5477e
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Fri Apr 15 12:28:00 2022 -0500

    x86: Remove memcmp-sse4.S

so this file does nothing.

23 months agox86: Put wcs{n}len-sse4.1 in the sse4.1 text section
Noah Goldstein [Fri, 24 Jun 2022 16:42:15 +0000 (09:42 -0700)] 
x86: Put wcs{n}len-sse4.1 in the sse4.1 text section

Previously was missing but the two implementations shouldn't get in
the sse2 (generic) text section.

23 months agox86: Align entry for memrchr to 64-bytes.
Noah Goldstein [Fri, 24 Jun 2022 16:42:12 +0000 (09:42 -0700)] 
x86: Align entry for memrchr to 64-bytes.

The function was tuned around 64-byte entry alignment and performs
better for all sizes with it.

As well different code boths where explicitly written to touch the
minimum number of cache line i.e sizes <= 32 touch only the entry
cache line.

23 months agoMakerules: Remove no-op -Wl,-d when linking libc_pic.os
Fangrui Song [Sun, 26 Jun 2022 22:31:19 +0000 (15:31 -0700)] 
Makerules: Remove no-op -Wl,-d when linking libc_pic.os

In GNU ld, -d assigns space to common symbols for -r (i.e. change common
symbols to STB_GLOBAL definitions).  This option was added in commit
da2d1bc5adf49352232ad0514e79fbd5dcae08e8 (1998) perhaps because ld at
that time had a bug that common symbols did not override shared object
definitions.  -d has been long unneeded and more so since -fno-common
was added to +cflags.

23 months agom68k: optimize RTLD_START
Andreas Schwab [Fri, 24 Jun 2022 19:24:40 +0000 (21:24 +0200)] 
m68k: optimize RTLD_START

23 months agomisc: Optimize internal usage of __libc_single_threaded
Adhemerval Zanella [Tue, 7 Jun 2022 14:11:03 +0000 (11:11 -0300)] 
misc: Optimize internal usage of __libc_single_threaded

By adding an internal alias to avoid the GOT indirection.
On some architecture, __libc_single_thread may be accessed through
copy relocations and thus it requires to update also the copies
default copy.

This is done by adding a new internal macro,
libc_hidden_data_{proto,def}, which has an addition argument that
specifies the alias name (instead of default __GI_ one).

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

Reviewed-by: Fangrui Song <maskray@google.com>
23 months agolinux: Add move_mount
Adhemerval Zanella [Mon, 31 Jan 2022 13:04:57 +0000 (10:04 -0300)] 
linux: Add move_mount

It was added on Linux 5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae)
as way t move a mount from one place to another and, in the next
commit, allow to attach an unattached mount tree.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agolinux: Add fsmount
Adhemerval Zanella [Mon, 31 Jan 2022 12:46:24 +0000 (09:46 -0300)] 
linux: Add fsmount

It was added on 5.2 (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d) to
provide a way by which a filesystem opened with fsopen and configured
by a series of fsconfig calls can have a detached mount object
created for it.

Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agolinux: Add fsopen
Adhemerval Zanella [Mon, 31 Jan 2022 12:45:12 +0000 (09:45 -0300)] 
linux: Add fsopen

It was added on Linux 5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005)
to start the process of preparing to create a superblock that will
then be mountable, using an fd as a context handle.

Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agoresolv/tst-resolv-noaaaa: Support building for older C standards
Florian Weimer [Fri, 24 Jun 2022 17:38:14 +0000 (19:38 +0200)] 
resolv/tst-resolv-noaaaa: Support building for older C standards

This avoids a compilation error:

tst-resolv-noaaaa.c: In function 'response':
tst-resolv-noaaaa.c:74:11: error: a label can only be part of a statement and a declaration is not a statement
           char ipv4[4] = {192, 0, 2, i + 1};
           ^~~~
tst-resolv-noaaaa.c:79:11: error: a label can only be part of a statement and a declaration is not a statement
           char *name = xasprintf ("ptr-%d", i);
           ^~~~

23 months agoresolv: Implement no-aaaa stub resolver option
Florian Weimer [Fri, 24 Jun 2022 16:16:41 +0000 (18:16 +0200)] 
resolv: Implement no-aaaa stub resolver option

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agosupport: Change non-address output format of support_format_dns_packet
Florian Weimer [Fri, 24 Jun 2022 16:16:41 +0000 (18:16 +0200)] 
support: Change non-address output format of support_format_dns_packet

It makes sense to include the owner name (LHS) and record type in the
output, so that they can be checked for correctness.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agoriscv: Use elf_machine_rela_relative to handle R_RISCV_RELATIVE
Kito Cheng [Thu, 23 Jun 2022 15:47:04 +0000 (23:47 +0800)] 
riscv: Use elf_machine_rela_relative to handle R_RISCV_RELATIVE

Minor clean-up, we need to change this part in following patch, clean this up
to prevent we duplicated the change twice.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
23 months agox86: Remove faulty sanity tests for RTLD build with no multiarch
Noah Goldstein [Thu, 23 Jun 2022 17:49:19 +0000 (10:49 -0700)] 
x86: Remove faulty sanity tests for RTLD build with no multiarch

The sanity tests where meant to ensure that the default implementation
was only being built without multiarch with the exception of the
multiarch/rtld-*.S files.

The code used IS_IN (rtld) to check if the build for was for an
multiarch/rtld-*.S file which is incorrect as IS_IN (rtld) is set for
the non-multiarch build as well.

23 months agostdlib: Fixup mbstowcs NULL __dst handling. [BZ #29279]
Noah Goldstein [Wed, 22 Jun 2022 23:34:42 +0000 (16:34 -0700)] 
stdlib: Fixup mbstowcs NULL __dst handling. [BZ #29279]

commit 464d189b9622932a75302290625de84931656ec0 (origin/master, origin/HEAD)
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Wed Jun 22 08:24:21 2022 -0700

    stdlib: Remove attr_write from mbstows if dst is NULL [BZ: 29265]

Incorrectly called `__mbstowcs_chk` in the NULL __dst case which is
incorrect as in the NULL __dst case we are explicitly skipping
the objsize checks.

As well, remove the `__always_inline` attribute which exists in
`__fortify_function`.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
23 months agox86: Replace all sse instructions with vex equivilent in avx+ files
Noah Goldstein [Mon, 20 Jun 2022 20:02:10 +0000 (13:02 -0700)] 
x86: Replace all sse instructions with vex equivilent in avx+ files

Most of these don't really matter as there was no dirty upper state
but we should generally avoid stray sse when its not needed.

The one case that really matters is in svml_d_tanh4_core_avx2.S:

blendvps %xmm0, %xmm8, %xmm7

When there was a dirty upper state.

Tested on x86_64-linux

23 months agox86: Add support for compiling {raw|w}memchr with high ISA level
Noah Goldstein [Wed, 22 Jun 2022 23:51:20 +0000 (16:51 -0700)] 
x86: Add support for compiling {raw|w}memchr with high ISA level

1. Refactor files so that all implementations for in the multiarch
   directory.
    - Essentially moved sse2 {raw|w}memchr.S implementation to
      multiarch/{raw|w}memchr-sse2.S

    - The non-multiarch {raw|w}memchr.S file now only includes one of
      the implementations in the multiarch directory based on the
      compiled ISA level (only used for non-multiarch builds.
      Otherwise we go through the ifunc selector).

2. Add ISA level build guards to different implementations.
    - I.e memchr-avx2.S which is ISA level 3 will only build if
      compiled ISA level <= 3. Otherwise there is no reason to include
      it as we will always use one of the ISA level 4
      implementations (memchr-evex{-rtm}.S).

3. Add new multiarch/rtld-{raw}memchr.S that just include the
   non-multiarch {raw}memchr.S which will in turn select the best
   implementation based on the compiled ISA level.

4. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.
    - Guranteed replacement essentially means that for any ISA level
      build there must be a function that the baseline of the ISA
      supports. So for {raw|w}memchr.S since there is not ISA level 2
      function, the ISA level 2 build still includes the ISA level
      1 (sse2) function. Once we reach the ISA level 3 build, however,
      {raw|w}memchr-avx2{-rtm}.S will always be sufficient so the ISA
      level 1 implementation ({raw|w}memchr-sse2.S) will not be built.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

23 months agox86: Add defines / utilities for making ISA specific x86 builds
Noah Goldstein [Wed, 22 Jun 2022 23:51:19 +0000 (16:51 -0700)] 
x86: Add defines / utilities for making ISA specific x86 builds

1. Factor out some of the ISA level defines in isa-level.c to
   standalone header isa-level.h

2. Add new headers with ISA level dependent macros for handling
   ifuncs.

Note, this file does not change any code.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

23 months agostdlib: Remove attr_write from mbstows if dst is NULL [BZ: 29265]
Noah Goldstein [Wed, 22 Jun 2022 15:24:21 +0000 (08:24 -0700)] 
stdlib: Remove attr_write from mbstows if dst is NULL [BZ: 29265]

mbstows is defined if dst is NULL and is defined to special cased if
dst is NULL so the fortify objsize check if incorrect in that case.

Tested on x86-64 linux.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
23 months agostdlib: Remove trailing whitespace from Makefile
Noah Goldstein [Wed, 22 Jun 2022 17:53:33 +0000 (10:53 -0700)] 
stdlib: Remove trailing whitespace from Makefile

This causes precommit tests to fail when pushing commits that modify
this file.

23 months agodebug: make __read_chk a cancellation point (bug 29274)
Andreas Schwab [Wed, 22 Jun 2022 11:16:30 +0000 (13:16 +0200)] 
debug: make __read_chk a cancellation point (bug 29274)

The __read_chk function, as the implementation behind the fortified read
function, must be a cancellation point, thus it cannot use INLINE_SYSCALL.

23 months agos390: use LC_ALL=C for readelf call
Sam James [Thu, 9 Jun 2022 02:56:23 +0000 (03:56 +0100)] 
s390: use LC_ALL=C for readelf call

Let's use LC_ALL=C as we do elsewhere for consistency.

Tested on s390x-ibm-linux-gnu.

See: 72bd208846535725ea28b8173e79ef60e57a968c
Signed-off-by: Sam James <sam@gentoo.org>
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
23 months agos390: use $READELF
Sam James [Thu, 9 Jun 2022 02:56:22 +0000 (03:56 +0100)] 
s390: use $READELF

We already check for it in root configure.ac with AC_CHECK_TOOL. Let's
use the result.

Tested on s390x-ibm-linux-gnu.

Signed-off-by: Sam James <sam@gentoo.org>
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
23 months agoi386: Fix include paths for strspn, strcspn, and strpbrk
Noah Goldstein [Fri, 17 Jun 2022 18:18:32 +0000 (11:18 -0700)] 
i386: Fix include paths for strspn, strcspn, and strpbrk

commit c22eb807b0c8125101f6a274795425be2bbd0386
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Thu Jun 16 15:07:12 2022 -0700

    x86: Rename generic functions with unique postfix for clarity

Changed the names of the strspn-c, strcspn-c, and strpbrk-c files
in a general refactor. It didn't change the include paths for the
i386 files breaking the i386 build. This commit fixes that.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoelf: Silence GCC 11/12 false positive warning
H.J. Lu [Fri, 17 Jun 2022 01:52:02 +0000 (18:52 -0700)] 
elf: Silence GCC 11/12 false positive warning

Silence GCC 11/12 false positive warning with -mavx512f on dl-load.c:

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

$ gcc -O2 -fPIC -march=x86-64 -mavx512f -S -Wall ...
dl-load.c: In function ‘_dl_map_object_from_fd.constprop’:
dl-load.c:1158:30: warning: ‘(((char *)loadcmds.113_68 + _933 + 16))[329406144173384849].mapend’ may be used uninitialized [-Wmaybe-uninitialized]

23 months agox86: Rename generic functions with unique postfix for clarity
Noah Goldstein [Thu, 16 Jun 2022 22:07:12 +0000 (15:07 -0700)] 
x86: Rename generic functions with unique postfix for clarity

No functions are changed. It just renames generic implementations from
'{func}_sse2' to '{func}_generic'. This is just because the postfix
"_sse2" was overloaded and was used for files that had hand-optimized
sse2 assembly implementations and files that just redirected back
to the generic implementation.

Full xcheck passed on x86_64.

23 months agox86: Add BMI1/BMI2 checks for ISA_V3 check
Noah Goldstein [Thu, 16 Jun 2022 22:01:08 +0000 (15:01 -0700)] 
x86: Add BMI1/BMI2 checks for ISA_V3 check

BMI1/BMI2 are part of the ISA V3 requirements:
https://en.wikipedia.org/wiki/X86-64

And defined by GCC when building with `-march=x86-64-v3`

23 months agox86-64: Handle fewer relocation types for RTLD_BOOTSTRAP
Fangrui Song [Thu, 16 Jun 2022 18:48:15 +0000 (11:48 -0700)] 
x86-64: Handle fewer relocation types for RTLD_BOOTSTRAP

The RTLD_BOOTSTRAP branch is used to relocate ld.so itself.  It only
needs to handle RELATIVE, GLOB_DAT, and JUMP_SLOT.  RELATIVE has been
handled (by _ELF_DYNAMIC_DO_RELOC due to DT_RELACOUNT, or RELR), so the
switch statement only needs to handle GLOB_DAT and JUMP_SLOT.

We can drop these `#if[n]def RTLD_BOOTSTRAP` and add a large
`# ifndef RTLD_BOOTSTRAP` instead.

23 months agoaarch64: Handle fewer relocations for RTLD_BOOTSTRAP
Fangrui Song [Thu, 16 Jun 2022 02:21:53 +0000 (19:21 -0700)] 
aarch64: Handle fewer relocations for RTLD_BOOTSTRAP

The RTLD_BOOTSTRAP branch is used to relocate ld.so itself.  It only
needs to handle RELATIVE, GLOB_DAT, and JUMP_SLOT.
TLSDESC/TLS_DTPMOD/TLS_DTPREL handling can be removed.  Remove
`case AARCH64_R(RELATIVE)` as well as elf_machine_rela has checked it.

Tested on aarch64-linux-gnu.

23 months agoriscv: Change the relocations handled for RTLD_BOOTSTRAP
Fangrui Song [Thu, 16 Jun 2022 01:42:03 +0000 (18:42 -0700)] 
riscv: Change the relocations handled for RTLD_BOOTSTRAP

The RTLD_BOOTSTRAP branch is used to relocate ld.so itself.  It only
needs to handle RELATIVE, GLOB_DAT, and the symbolic relocation type
(R_RISCV_{32,64}).  NONE and IRELATIVE can be removed.

The code relies on ld.so having DT_RELACOUNT so that the RTLD_BOOTSTRAP
branch does not need handle RELATIVE.  Drop this minor size
optimization for clarity.

Acked-by: Palmer Dabbelt <palmer@rivosinc.com>