]> sourceware.org Git - glibc.git/log
glibc.git
22 months agostdio-common: Add lock optimization to vfprintf and vfwprintf
Florian Weimer [Thu, 18 Aug 2022 06:49:54 +0000 (08:49 +0200)]
stdio-common: Add lock optimization to vfprintf and vfwprintf

After the rewrite and the implicit unbuffered streams handling, this
is very straightforward to add.

22 months agostdio-common: Convert vfprintf and related functions to buffers
Florian Weimer [Thu, 18 Aug 2022 06:49:54 +0000 (08:49 +0200)]
stdio-common: Convert vfprintf and related functions to buffers

vfprintf is entangled with vfwprintf (of course), __printf_fp,
__printf_fphex, __vstrfmon_l_internal, and the strfrom family of
functions.  The latter use the internal snprintf functionality,
so vsnprintf is converted as well.

The simples conversion is __printf_fphex, followed by
__vstrfmon_l_internal and __printf_fp, and finally
__vfprintf_internal and __vfwprintf_internal.  __vsnprintf_internal
and strfrom* are mostly consuming the new interfaces, so they
are comparatively simple.

__printf_fp is a public symbol, so the FILE *-based interface
had to preserved.

The __printf_fp rewrite does not change the actual binary-to-decimal
conversion algorithm, and digits are still not emitted directly to
the target buffer.  However, the staging buffer now uses bytes
instead of wide characters, and one buffer copy is eliminated.

The changes are at least performance-neutral in my testing.
Floating point printing and snprintf improved measurably, so that
this Lua script

  for i=1,5000000 do
      print(i, i * math.pi)
  end

runs about 5% faster for me.  To preserve fprintf performance for
a simple "%d" format, this commit has some logic changes under
LABEL (unsigned_number) to avoid additional function calls.  There
are certainly some very easy performance improvements here: binary,
octal and hexadecimal formatting can easily avoid the temporary work
buffer (the number of digits can be computed ahead-of-time using one
of the __builtin_clz* built-ins). Decimal formatting can use a
specialized version of _itoa_word for base 10.

The existing (inconsistent) width handling between strfmon and printf
is preserved here.  __print_fp_buffer_1 would have to use
__translated_number_width to achieve ISO conformance for printf.

Test expectations in libio/tst-vtables-common.c are adjusted because
the internal staging buffer merges all virtual function calls into
one.

In general, stack buffer usage is greatly reduced, particularly for
unbuffered input streams.  __printf_fp can still use a large buffer
in binary128 mode for %g, though.

22 months agostdio-common: Add __translated_number_width
Florian Weimer [Thu, 18 Aug 2022 06:49:54 +0000 (08:49 +0200)]
stdio-common: Add __translated_number_width

This function will be used to compute the width of a number
after i18n digit translation.

22 months agostdio-common: Add __printf_function_invoke
Florian Weimer [Thu, 18 Aug 2022 06:49:54 +0000 (08:49 +0200)]
stdio-common: Add __printf_function_invoke

And __wprintf_function_invoke.  These functions will be used to
to call registered printf specifier callbacks on printf buffers
after vfprintf and vfwprintf have been converted to buffers.  The new
implementation avoids alloca/variable length arrays.

22 months agostdio-common: Introduce buffers for implementing printf
Florian Weimer [Thu, 18 Aug 2022 06:49:54 +0000 (08:49 +0200)]
stdio-common: Introduce buffers for implementing printf

These buffers will eventually be used instead of FILE * objects
to implement printf functions.  The multibyte buffer is struct
__printf_buffer, the wide buffer is struct __wprintf_buffer.

To enable writing type-generic code, the header files
printf_buffer-char.h and printf_buffer-wchar_t.h define the
Xprintf macro differently, enabling Xprintf (buffer) to stand
for __printf_buffer and __wprintf_buffer as appropriate.  For
common cases, macros like Xprintf_buffer are provided as a more
syntactically convenient shortcut.

Buffer-specific flush callbacks are implemented with a switch
statement instead of a function pointer, to avoid hardening issues
similar to those of libio vtables.  struct __printf_buffer_as_file
is needed to support custom printf specifiers because the public
interface for that requires passing a FILE *, which is why there
is a trapdoor back from these buffers to FILE * streams.

Since the immediate user of these interfaces knows when processing
has finished, there is no flush callback for the end of processing,
only a flush callback for the intermediate buffer flush.

22 months agolocale: Implement struct grouping_iterator
Florian Weimer [Thu, 18 Aug 2022 06:49:54 +0000 (08:49 +0200)]
locale: Implement struct grouping_iterator

The iterator allows grouping while scanning forward through
the digits.  This enables emitting digits as they are processed.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
22 months agotime: Use 64 bit time on tzfile
Adhemerval Zanella Netto [Wed, 26 Oct 2022 19:04:25 +0000 (16:04 -0300)]
time: Use 64 bit time on tzfile

The tzfile_mtime is already compared to 64 bit time_t stat call.
Reviewed-by: DJ Delorie <dj@redhat.com>
22 months agonscd: Use 64 bit time_t on libc nscd routines (BZ# 29402)
Adhemerval Zanella Netto [Wed, 26 Oct 2022 19:04:24 +0000 (16:04 -0300)]
nscd: Use 64 bit time_t on libc nscd routines (BZ# 29402)

Although the nscd module is built with 64 bit time_t, the routines
linked direct to libc.so need to use the internal symbols.
Reviewed-by: DJ Delorie <dj@redhat.com>
22 months agonis: Build libnsl with 64 bit time_t
Adhemerval Zanella Netto [Wed, 26 Oct 2022 19:04:23 +0000 (16:04 -0300)]
nis: Build libnsl with 64 bit time_t

And remove the usage of glibc reserved names.
Reviewed-by: DJ Delorie <dj@redhat.com>
23 months agorealloc: Return unchanged if request is within usable size
Siddhesh Poyarekar [Mon, 28 Nov 2022 17:26:46 +0000 (12:26 -0500)]
realloc: Return unchanged if request is within usable size

If there is enough space in the chunk to satisfy the new size, return
the old pointer as is, thus avoiding any locks or reallocations.  The
only real place this has a benefit is in large chunks that tend to get
satisfied with mmap, since there is a large enough spare size (up to a
page) for it to matter.  For allocations on heap, the extra size is
typically barely a few bytes (up to 15) and it's unlikely that it would
make much difference in performance.

Also added a smoke test to ensure that the old pointer is returned
unchanged if the new size to realloc is within usable size of the old
pointer.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: DJ Delorie <dj@redhat.com>
23 months agoLinux: Consolidate typesizes.h
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:32 +0000 (19:14 -0300)]
Linux: Consolidate typesizes.h

The generic (sysdeps/unix/sysv/linux/generic/bits/typesizes.h) and
default (bits/typesizes.h) differs in two fields:

                    bits/typesizes.h    Linux generic
__NLINK_T_TYPE      __UWORD_TYPE        __U32_TYPE
__BLKSIZE_T_TYPE    __SLONGWORD_TYPE    __S32_TYPE

Sinceit leads to different C++ mangling names, the default typesize.h
is copied for the requires archtiectures and the generic is make the
default Linux one.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: Make generic fcntl.h the default one
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:31 +0000 (19:14 -0300)]
Linux: Make generic fcntl.h the default one

It is currently used for csky, arc, nios2, and or1k.  Newer 64 bit
architecture, like riscv32 and loongarch, reimplement it to override
F_GETLK64/F_SETLK64/F_SETLKW64.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: make generic xstatver.h the default one
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:30 +0000 (19:14 -0300)]
Linux: make generic xstatver.h the default one

And copy the current default one to required ABIs.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: Remove generic sysdep
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:29 +0000 (19:14 -0300)]
Linux: Remove generic sysdep

The includes chain is added on each architecture sysdep.h and
the __NR__llseek hack is moved to lseek.c and lseek64.c.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: Assume and consolidate shutdown wire-up syscall
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:27 +0000 (19:14 -0300)]
Linux: Assume and consolidate shutdown wire-up syscall

And disable if kernel does not support it.

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: Assume and consolidate listen wire-up syscall
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:24 +0000 (19:14 -0300)]
Linux: Assume and consolidate listen wire-up syscall

And disable if kernel does not support it.

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: Assume and consolidate socketpair wire-up syscall
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:23 +0000 (19:14 -0300)]
Linux: Assume and consolidate socketpair wire-up syscall

And disable if kernel does not support it.

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: Assume and consolidate socket wire-up syscall
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:22 +0000 (19:14 -0300)]
Linux: Assume and consolidate socket wire-up syscall

And disable if kernel does not support it.

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: Assume and consolidate bind wire-up syscall
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:21 +0000 (19:14 -0300)]
Linux: Assume and consolidate bind wire-up syscall

And disable if kernel does not support it.

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate ____longjmp_chk
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:20 +0000 (19:14 -0300)]
Linux: consolidate ____longjmp_chk

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate sendfile implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:18 +0000 (19:14 -0300)]
Linux: consolidate sendfile implementation

This is similar to other LFS consolidation, where the non-LFS is only
built if __OFF_T_MATCHES_OFF64_T is not defined and the LFS version
is aliased to non-LFS name if __OFF_T_MATCHES_OFF64_T is defined.

For non-LFS variant, use sendfile syscall if defined, otherwise use
sendfile64 plus the offset overflow check (as generic implementation).

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate unlink implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:17 +0000 (19:14 -0300)]
Linux: consolidate unlink implementation

Use unlink syscall if defined, otherwise use unlinkat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate symlink implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:16 +0000 (19:14 -0300)]
Linux: consolidate symlink implementation

Use symlink syscall if defined, otherwise use symlinkat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate rmdir implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:15 +0000 (19:14 -0300)]
Linux: consolidate rmdir implementation

Use rmdir syscall if defined, otherwise use unlinkat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate readlink implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:14 +0000 (19:14 -0300)]
Linux: consolidate readlink implementation

Use readlink syscall if defined, otherwise readlinkat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate mkdir implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:13 +0000 (19:14 -0300)]
Linux: consolidate mkdir implementation

Use mkdir syscall if defined, otherwise use mkdirat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate link implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:12 +0000 (19:14 -0300)]
Linux: consolidate link implementation

Use link syscall if defined, otherwise use linkat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate lchown implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:11 +0000 (19:14 -0300)]
Linux: consolidate lchown implementation

Use lchown syscall if defined, otherwise use fchownat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate inotify_init implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:10 +0000 (19:14 -0300)]
Linux: consolidate inotify_init implementation

Use inotify_init syscall if defined, otherwise use inotify_init1.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLninux: consolidate epoll_create implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:09 +0000 (19:14 -0300)]
Lninux: consolidate epoll_create implementation

Use epoll_create syscall if defined, otherwise use epoll_create1.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate dup2 implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:08 +0000 (19:14 -0300)]
Linux: consolidate dup2 implementation

Use dup2 syscall if defined, otherwise use dup3.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate chown implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:07 +0000 (19:14 -0300)]
Linux: consolidate chown implementation

Use chown syscall if defined, otherwise use fchownat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agoLinux: consolidate chmod implementation
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:06 +0000 (19:14 -0300)]
Linux: consolidate chmod implementation

Use chmod syscall if defined, otherwise use fchmodat.

Checked on x86_64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
23 months agolinux: Consolidate dl-origin.c
Adhemerval Zanella Netto [Wed, 19 Oct 2022 22:14:05 +0000 (19:14 -0300)]
linux: Consolidate dl-origin.c

Use the generic implementation as the default, since the syscall
is supported by all architectures.

Also cleanup some headers and remove the INTERNAL_SYSCALL_ERROR_P
usage (the INTERNAL_SYSCALL_CALL macro already returns an negative
value if an error occurs).

23 months agolinux: Use long int for syscall return value
Xing Li [Tue, 29 Nov 2022 11:24:43 +0000 (19:24 +0800)]
linux: Use long int for syscall return value

The linux syscall ABI returns long, so the generic syscall code for
linux should use long for the return value.

This fixes the truncation of the return value of the syscall function
when that does not fit into an int.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agoLoongArch: Use medium cmodel build libc_nonshared.a.
Chenghua Xu [Wed, 7 Sep 2022 02:33:00 +0000 (10:33 +0800)]
LoongArch: Use medium cmodel build libc_nonshared.a.

This patch is used to fix address out-of-bounds error when building
Chrome.

23 months agox86_64: State assembler is being tested on sysdeps/x86/configure
Adhemerval Zanella [Tue, 6 Dec 2022 16:47:47 +0000 (13:47 -0300)]
x86_64: State assembler is being tested on sysdeps/x86/configure

23 months agoconfigure: Remove AS check
Adhemerval Zanella [Fri, 2 Dec 2022 19:00:28 +0000 (16:00 -0300)]
configure: Remove AS check

The assembler is not issued directly, but rather always through CC
wrapper.  The binutils version check if done with LD instead.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agoconfigure: Remove check if ld is GNU
Adhemerval Zanella [Fri, 2 Dec 2022 19:00:27 +0000 (16:00 -0300)]
configure: Remove check if ld is GNU

Assume linker has gnu argument input style.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agoconfigure: Remove check if as is GNU
Adhemerval Zanella [Fri, 2 Dec 2022 19:00:26 +0000 (16:00 -0300)]
configure: Remove check if as is GNU

It is not used in any place.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agoconfigure: Move locale tools early
Adhemerval Zanella [Fri, 2 Dec 2022 19:00:25 +0000 (16:00 -0300)]
configure: Move locale tools early

When using --with-binutils, the configure might not use the specified
linker or assembler while checking for expected support.  Move the
tools check early, before any compiler usage test.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
23 months agohurd: Make getrandom cache the server port
Sergey Bugaev [Fri, 2 Dec 2022 13:55:58 +0000 (16:55 +0300)]
hurd: Make getrandom cache the server port

Previously, getrandom would, each time it's called, traverse the file
system to find /dev/urandom, fetch some random data from it, then throw
away that port. This is quite slow, while calls to getrandom are
genrally expected to be fast.

Additionally, this means that getrandom can not work when /dev/urandom
is unavailable, such as inside a chroot that lacks one. User programs
expect calls to getrandom to work inside a chroot if they first call
getrandom outside of the chroot.

In particular, this is known to break the OpenSSH server, and in that
case the issue is exacerbated by the API of arc4random, which prevents
it from properly reporting errors, forcing glibc to abort on failure.
This causes sshd to just die once it tries to generate a random number.

Caching the random server port, in a manner similar to how socket
server ports are cached, both improves the performance and works around
the chroot issue.

Tested on i686-gnu with the following program:

pthread_barrier_t barrier;

void *worker(void*) {
    pthread_barrier_wait(&barrier);
    uint32_t sum = 0;
    for (int i = 0; i < 10000; i++) {
        sum += arc4random();
    }
    return (void *)(uintptr_t) sum;
}

int main() {
    pthread_t threads[THREAD_COUNT];

    pthread_barrier_init(&barrier, NULL, THREAD_COUNT);

    for (int i = 0; i < THREAD_COUNT; i++) {
        pthread_create(&threads[i], NULL, worker, NULL);
    }
    for (int i = 0; i < THREAD_COUNT; i++) {
        void *retval;
        pthread_join(threads[i], &retval);
        printf("Thread %i: %lu\n", i, (unsigned long)(uintptr_t) retval);
    }

In my totally unscientific benchmark, with this patch, this completes
in about 7 seconds, whereas previously it took about 50 seconds. This
program was also used to test that getrandom () doesn't explode if the
random server dies, but instead reopens the /dev/urandom anew. I have
also verified that with this patch, OpenSSH can once again accept
connections properly.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20221202135558.23781-1-bugaevc@gmail.com>

23 months agopowerpc64: Remove old strncmp optimization
Rajalakshmi Srinivasaraghavan [Fri, 2 Dec 2022 20:26:41 +0000 (14:26 -0600)]
powerpc64: Remove old strncmp optimization

This patch cleans up the power4 strncmp optimization for powerpc64 which
is unlikely to be used anywhere.

Tested on ppc64le with and without --disable-multi-arch flag.

Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agox86-64 strncpy: Properly handle the length parameter [BZ# 29839]
H.J. Lu [Fri, 2 Dec 2022 00:36:02 +0000 (16:36 -0800)]
x86-64 strncpy: Properly handle the length parameter [BZ# 29839]

On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes strncpy for x32.  Tested on x86-64 and x32.  On x86-64,
libc.so is the same with and without the fix.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
23 months agox86-64 strncat: Properly handle the length parameter [BZ# 24097]
H.J. Lu [Fri, 2 Dec 2022 00:37:11 +0000 (16:37 -0800)]
x86-64 strncat: Properly handle the length parameter [BZ# 24097]

On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes strncat for x32.  Tested on x86-64 and x32.  On x86-64,
libc.so is the same with and without the fix.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
23 months agoARC: update definitions in elf/elf.h
Shahab Vahedi [Sun, 27 Nov 2022 17:38:25 +0000 (18:38 +0100)]
ARC: update definitions in elf/elf.h

While porting ARCv2 to elfutils [1], it was brought up that the
necessary changes to the project's libelf/elf.h must come from
glibc, because they sync it from glibc [2].  Therefore, this patch
is to update ARC entries in elf/elf.h.

The majority of the update is about adding new definitions,
specially for the relocations.  However, there is one rename, one
deletion, and one change:

- R_ARC_JUMP_SLOT renamed to R_ARC_JMP_SLOT to match binutils.
- R_ARC_B26 removed because it is unused and deprecated.
- R_ARC_TLS_DTPOFF_S9 changed from 0x4a to the correct value 0x49.

Finally, a specific SHT class for ARC has been added to glibcelf.py.
Else, it would result in a collision:

  _register_elf_h(Sht, ranges=True,
 File "/src/glibc/scripts/glibcelf.py", line x, in _register_elf_h
   raise ValueError('duplicate value {}: {}, {}'.format(
                    ValueError: duplicate value 1879048193:
                    SHT_ARC_ATTRIBUTES, SHT_X86_64_UNWIND

[1]
https://sourceware.org/pipermail/elfutils-devel/2022q4/005530.html

[2]
https://sourceware.org/pipermail/elfutils-devel/2022q4/005548.html

No regression has been observed after applying this patch.  Below
follows the result:

UNSUPPORTED: crypt/cert
UNSUPPORTED: elf/tst-audit22
FAIL: elf/tst-audit25a
FAIL: elf/tst-audit25b
FAIL: elf/tst-bz15311
FAIL: elf/tst-bz28937
FAIL: elf/tst-dlmopen4
UNSUPPORTED: elf/tst-dlopen-self-container
UNSUPPORTED: elf/tst-dlopen-tlsmodid-container
UNSUPPORTED: elf/tst-glibc-hwcaps-prepend-cache
UNSUPPORTED: elf/tst-ldconfig-bad-aux-cache
UNSUPPORTED: elf/tst-ldconfig-ld_so_conf-update
UNSUPPORTED: elf/tst-pldd
UNSUPPORTED: elf/tst-preload-pthread-libc
XPASS: elf/tst-protected1a
XPASS: elf/tst-protected1b
FAIL: elf/tst-tls-allocation-failure-static-patched
FAIL: elf/tst-tls1
FAIL: elf/tst-tls3
FAIL: elf/tst-tlsalign-extern
UNSUPPORTED: elf/tst-valgrind-smoke
UNSUPPORTED: grp/tst-initgroups1
UNSUPPORTED: grp/tst-initgroups2
UNSUPPORTED: io/tst-getcwd-smallbuff
UNSUPPORTED: locale/tst-localedef-path-norm
FAIL: localedata/sort-test
UNSUPPORTED: localedata/tst-localedef-hardlinks
FAIL: malloc/tst-malloc-thread-fail-malloc-check
FAIL: malloc/tst-malloc_info-malloc-check
UNSUPPORTED: math/test-fesetexcept-traps
UNSUPPORTED: math/test-fexcept-traps
UNSUPPORTED: math/test-nearbyint-except
UNSUPPORTED: math/test-nearbyint-except-2
UNSUPPORTED: misc/tst-adjtimex
UNSUPPORTED: misc/tst-clock_adjtime
FAIL: misc/tst-misalign-clone
FAIL: misc/tst-misalign-clone-internal
UNSUPPORTED: misc/tst-ntp_adjtime
UNSUPPORTED: misc/tst-pkey
UNSUPPORTED: misc/tst-rseq
UNSUPPORTED: misc/tst-rseq-disable
UNSUPPORTED: misc/tst-syslog
UNSUPPORTED: misc/tst-ttyname
FAIL: nptl/test-cond-printers
FAIL: nptl/test-condattr-printers
FAIL: nptl/test-mutex-printers
FAIL: nptl/test-mutexattr-printers
FAIL: nptl/test-rwlock-printers
FAIL: nptl/test-rwlockattr-printers
UNSUPPORTED: nptl/tst-pthread-gdb-attach
UNSUPPORTED: nptl/tst-pthread-gdb-attach-static
UNSUPPORTED: nptl/tst-pthread-getattr
UNSUPPORTED: nptl/tst-rseq-nptl
UNSUPPORTED: nss/tst-nss-compat1
UNSUPPORTED: nss/tst-nss-db-endgrent
UNSUPPORTED: nss/tst-nss-db-endpwent
UNSUPPORTED: nss/tst-nss-files-hosts-long
UNSUPPORTED: nss/tst-nss-gai-actions
UNSUPPORTED: nss/tst-nss-test3
UNSUPPORTED: nss/tst-reload1
UNSUPPORTED: nss/tst-reload2
UNSUPPORTED: posix/bug-ga2
UNSUPPORTED: posix/bug-ga2-mem
FAIL: posix/globtest
UNSUPPORTED: posix/tst-vfork3
UNSUPPORTED: posix/tst-vfork3-mem
UNSUPPORTED: resolv/mtrace-tst-leaks2
UNSUPPORTED: resolv/tst-leaks2
UNSUPPORTED: resolv/tst-resolv-ai_idn
UNSUPPORTED: resolv/tst-resolv-ai_idn-latin1
UNSUPPORTED: resolv/tst-resolv-res_init
UNSUPPORTED: resolv/tst-resolv-res_init-thread
UNSUPPORTED: rt/tst-bz28213
UNSUPPORTED: rt/tst-mqueue1
UNSUPPORTED: rt/tst-mqueue10
UNSUPPORTED: rt/tst-mqueue2
UNSUPPORTED: rt/tst-mqueue3
UNSUPPORTED: rt/tst-mqueue4
UNSUPPORTED: rt/tst-mqueue5
UNSUPPORTED: rt/tst-mqueue6
UNSUPPORTED: rt/tst-mqueue8
UNSUPPORTED: rt/tst-mqueue8x
UNSUPPORTED: rt/tst-mqueue9
UNSUPPORTED: stdlib/test-bz22786
UNSUPPORTED: stdlib/tst-system
UNSUPPORTED: string/test-bcopy
UNSUPPORTED: string/test-memmove
UNSUPPORTED: string/tst-memmove-overflow
UNSUPPORTED: string/tst-strerror
UNSUPPORTED: string/tst-strsignal
UNSUPPORTED: time/tst-clock_settime
UNSUPPORTED: time/tst-settimeofday
Summary of test results:
     21 FAIL
   4184 PASS
     69 UNSUPPORTED
     16 XFAIL
      2 XPASS

Signed-off-by: Shahab Vahedi <shahab@synopsys.com>
Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
23 months agoscripts: Add "|" operator support to glibcpp's parsing
Shahab Vahedi [Sun, 27 Nov 2022 17:38:24 +0000 (18:38 +0100)]
scripts: Add "|" operator support to glibcpp's parsing

From the tests point of view, this is a necessary step for another
patch [1] and allows parsing macros such as "#define A | B".  Without
it, a few tests [2] choke when the other patch [1] is applied:

/src/glibc/scripts/../elf/elf.h:4167: error: uninterpretable macro
token sequence: ( EF_ARC_MACH_MSK | EF_ARC_OSABI_MSK )
Traceback (most recent call last):
    File "/src/glibc/elf/tst-glibcelf.py", line 23, in <module>
      import glibcelf
    File "/src/glibc/scripts/glibcelf.py", line 226, in <module>
      _elf_h = _parse_elf_h()
               ^^^^^^^^^^^^^^
    File "/src/glibc/scripts/glibcelf.py", line 223, in _parse_elf_h
      raise IOError('parse error in elf.h')
  OSError: parse error in elf.h

[1] ARC: update definitions in elf/elf.h
https://sourceware.org/pipermail/libc-alpha/2022-November/143503.html

[2]
tst-glibcelf, tst-relro-ldso, and tst-relro-libc

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Shahab Vahedi <shahab@synopsys.com>
23 months agoApply asm redirections in syslog.h before first use [BZ #27087]
Tulio Magno Quites Machado Filho [Fri, 11 Nov 2022 20:00:15 +0000 (17:00 -0300)]
Apply asm redirections in syslog.h before first use [BZ #27087]

Similar to d0fa09a770, but for syslog.h when _FORTIFY_SOURCE > 0.
Fixes [BZ #27087] by applying long double-related asm redirections
before using functions in bits/syslog.h.

Tested with build-many-glibcs.py.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agoLoongArch: Add support for ilogb[f]
Xiaolin Tang [Wed, 23 Nov 2022 03:49:26 +0000 (11:49 +0800)]
LoongArch: Add support for ilogb[f]

Add inline assembler for the ilogb functions. Passes GLIBC regression.

23 months agoLoongArch: Add support for scalb[f]
Xiaolin Tang [Wed, 23 Nov 2022 03:49:25 +0000 (11:49 +0800)]
LoongArch: Add support for scalb[f]

Add inline assembler for the scalb functions. Passes GLIBC regression.

23 months agoLoongArch: Add support for scalbn[f]
Xiaolin Tang [Wed, 23 Nov 2022 03:49:24 +0000 (11:49 +0800)]
LoongArch: Add support for scalbn[f]

Add inline assembler for the scalbn functions. Passes GLIBC regression.

GCC 13, LoongArch support ___builtin_scalbn{,f} with -fno-math-errno,
but only "libm" can use -fno-math-errno in GLIBC, and scalbn is in libc
instead of libm because __printf_fp calls it.

23 months agoLoongArch: Use __builtin_logb{,f} with GCC >= 13
Xiaolin Tang [Wed, 23 Nov 2022 03:45:01 +0000 (11:45 +0800)]
LoongArch: Use __builtin_logb{,f} with GCC >= 13

GCC 13 compiles these built-ins instead of generic
implementation for function logb.

Link: https://gcc.gnu.org/r13-3922
Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
23 months agoUse GCC builtins for logb functions if desired.
Xiaolin Tang [Wed, 23 Nov 2022 03:45:00 +0000 (11:45 +0800)]
Use GCC builtins for logb functions if desired.

This patch is using the corresponding GCC builtin for logbf, logb,
logbl and logbf128 if the USE_FUNCTION_BUILTIN macros are defined to one
in math-use-builtins-function.h.

Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
23 months agoLoongArch: Use __builtin_llrint{,f} with GCC >= 13
Xiaolin Tang [Wed, 23 Nov 2022 03:44:59 +0000 (11:44 +0800)]
LoongArch: Use __builtin_llrint{,f} with GCC >= 13

GCC 13 compiles these built-ins instead of generic
implementation for function llrint.

Link: https://gcc.gnu.org/r13-3920
Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
23 months agoUse GCC builtins for llrint functions if desired.
Xiaolin Tang [Wed, 23 Nov 2022 03:44:58 +0000 (11:44 +0800)]
Use GCC builtins for llrint functions if desired.

This patch is using the corresponding GCC builtin for llrintf, llrint,
llrintl and llrintf128 if the USE_FUNCTION_BUILTIN macros are defined to one
in math-use-builtins-function.h.

Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
23 months agoLoongArch: Use __builtin_lrint{,f} with GCC >= 13
Xiaolin Tang [Wed, 23 Nov 2022 03:44:57 +0000 (11:44 +0800)]
LoongArch: Use __builtin_lrint{,f} with GCC >= 13

GCC 13 compiles these built-ins instead of generic
implementation for function lrint.

Link: https://gcc.gnu.org/r13-3920
Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
23 months agoUse GCC builtins for lrint functions if desired.
Xiaolin Tang [Wed, 23 Nov 2022 03:44:56 +0000 (11:44 +0800)]
Use GCC builtins for lrint functions if desired.

This patch is using the corresponding GCC builtin for lrintf, lrint,
lrintl and lrintf128 if the USE_FUNCTION_BUILTIN macros are defined to one
in math-use-builtins-function.h.

Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
23 months agoLoongArch: Use __builtin_rint{,f} with GCC >= 13
Xi Ruoyao [Wed, 23 Nov 2022 03:44:55 +0000 (11:44 +0800)]
LoongArch: Use __builtin_rint{,f} with GCC >= 13

GCC 13 compiles these built-ins to frint.{d,s} instruction.

Link: https://gcc.gnu.org/r13-3919
23 months agox86/fpu: Factor out shared avx2/avx512 code in svml_{s|d}_wrapper_impl.h
Noah Goldstein [Sat, 19 Nov 2022 00:13:32 +0000 (16:13 -0800)]
x86/fpu: Factor out shared avx2/avx512 code in svml_{s|d}_wrapper_impl.h

Code is exactly the same for the two so better to only maintain one
version.

All math and mathvec tests pass on x86.

23 months agox86/fpu: Cleanup code in svml_{s|d}_wrapper_impl.h
Noah Goldstein [Sat, 19 Nov 2022 00:13:31 +0000 (16:13 -0800)]
x86/fpu: Cleanup code in svml_{s|d}_wrapper_impl.h

1. Remove unnecessary spills.
2. Fix some small nit missed optimizations.

All math and mathvec tests pass on x86.

23 months agox86/fpu: Reformat svml_{s|d}_wrapper_impl.h
Noah Goldstein [Sat, 19 Nov 2022 00:13:30 +0000 (16:13 -0800)]
x86/fpu: Reformat svml_{s|d}_wrapper_impl.h

Just reformat with the style convention used in other x86 assembler
files.  This doesn't change libm.so or libmvec.so.

23 months agox86/fpu: Fix misspelled evex512 section in variety of svml files
Noah Goldstein [Fri, 18 Nov 2022 20:00:36 +0000 (12:00 -0800)]
x86/fpu: Fix misspelled evex512 section in variety of svml files

```
.section .text.evex512, "ax", @progbits
```

With misspelled as:

```
.section .text.exex512, "ax", @progbits
```

23 months agox86/fpu: Add missing ISA sections to variety of svml files
Noah Goldstein [Fri, 18 Nov 2022 21:06:11 +0000 (13:06 -0800)]
x86/fpu: Add missing ISA sections to variety of svml files

Many sse4/avx2/avx512 files where just in .text.

23 months agostdio-common: Add missing dependencies (bug 29780)
Andreas Schwab [Mon, 21 Nov 2022 12:08:17 +0000 (13:08 +0100)]
stdio-common: Add missing dependencies (bug 29780)

Handle all object suffixes for dependencies of errlist-data and siglist
objects.

23 months agoi386: Avoid rely on linker optimization to avoid relocation
Adhemerval Zanella Netto [Thu, 17 Nov 2022 18:13:08 +0000 (15:13 -0300)]
i386: Avoid rely on linker optimization to avoid relocation

lld does not implement all the linker optimization to avoid the GOT
relocation as done by binutils (bfd/elf32-i386.c:elf_i386_convert_load_reloc).
The current 'movl main@GOT(%ebx), %eax' will then create a GOT
relocation when building with lld, which make static-pie status to
not being able to start the provided main function.

The change uses a __wrap_main local symbol, which in turn calls main
(similar as used by aarch64 and s390x).

Checked on i686-linux-gnu with binutils and lld.
Reviewed-by: Fangrui Song <maskray@google.com>
23 months agoelf: Fix rtld-audit trampoline for aarch64
Vladislav Khmelevsky [Thu, 17 Nov 2022 08:47:29 +0000 (12:47 +0400)]
elf: Fix rtld-audit trampoline for aarch64

This patch fixes two problems with audit:

  1. The DL_OFFSET_RV_VPCS offset was mixed up with DL_OFFSET_RG_VPCS,
     resulting in x2 register value nulling in RG structure.

  2. We need to preserve the x8 register before function call, but
     don't have to save it's new value and restore it before return.

Anyway the final restore was using OFFSET_RV instead of OFFSET_RG value
which is wrong (althoug doesn't affect anything).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agoDefine in_int32_t_range to check if the 64 bit time_t syscall should be used
YunQiang Su [Tue, 8 Nov 2022 04:49:46 +0000 (12:49 +0800)]
Define in_int32_t_range to check if the 64 bit time_t syscall should be used

Currently glibc uses in_time_t_range to detects time_t overflow,
and if it occurs fallbacks to 64 bit syscall version.

The function name is confusing because internally time_t might be
either 32 bits or 64 bits (depending on __TIMESIZE).

This patch refactors the in_time_t_range by replacing it with
in_int32_t_range for the case to check if the 64 bit time_t syscall
should be used.

The in_time_t range is used to detect overflow of the
syscall return value.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agoelf/tst-tlsopt-powerpc fails when compiled with -mcpu=power10 (BZ# 29776)
Alan Modra [Sat, 12 Nov 2022 00:50:31 +0000 (11:20 +1030)]
elf/tst-tlsopt-powerpc fails when compiled with -mcpu=power10 (BZ# 29776)

Supports pcrel addressing of TLS GOT entry.  Also tweak the non-pcrel
asm constraint to better reflect how the reg is used.

23 months agoLoongArch: Hard Float Support for fmaximum_mag_num{f/ }, fminimum_mag_num{f/ }.
Xiaolin Tang [Mon, 7 Nov 2022 14:08:21 +0000 (22:08 +0800)]
LoongArch: Hard Float Support for fmaximum_mag_num{f/ }, fminimum_mag_num{f/ }.

Use hardware Floating-point instruction f{maxa/mina}.{s/d}, fclass.{s/d}
to implement fmaximum_mag_num{f/ }, fminimum_mag_num{f/ }.

       *  sysdeps/loongarch/fpu/s_fmaximum_mag_num.c: New file.
       *  sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminimum_mag_num.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminimum_mag_numf.c: Likewise.

23 months agoLoongArch: Hard Float Support for fmaximum_mag{f/ }, fminimum_mag{f/ }.
Xiaolin Tang [Mon, 7 Nov 2022 14:08:20 +0000 (22:08 +0800)]
LoongArch: Hard Float Support for fmaximum_mag{f/ }, fminimum_mag{f/ }.

Use hardware Floating-point instruction f{maxa/mina}.{s/d}, fclass.{s/d}
to implement fmaximum_mag{f/ }, fminimum_mag{f/ }.

       *  sysdeps/loongarch/fpu/s_fmaximum_mag.c: New file.
       *  sysdeps/loongarch/fpu/s_fmaximum_magf.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminimum_mag.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminimum_magf.c: Likewise.

23 months agoLoongArch: Hard Float Support for fmaxmag{f/ }, fminmag{f/ }.
Xiaolin Tang [Mon, 7 Nov 2022 14:08:19 +0000 (22:08 +0800)]
LoongArch: Hard Float Support for fmaxmag{f/ }, fminmag{f/ }.

Use hardware Floating-point instruction f{maxa/mina}.{s/d},
to implement fmaxmag{f/ }, fminmag{f/ }.

       *  sysdeps/loongarch/fpu/s_fmaxmag.c: New file.
       *  sysdeps/loongarch/fpu/s_fmaxmagf.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminmag.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminmagf.c: Likewise.

23 months agoLoongArch: Hard Float Support for fmaximum_num{f/ }, fminimum_num{f/ }.
Xiaolin Tang [Mon, 7 Nov 2022 14:07:48 +0000 (22:07 +0800)]
LoongArch: Hard Float Support for fmaximum_num{f/ }, fminimum_num{f/ }.

Use hardware Floating-point instruction f{max/min}.{s/d}, fclass.{s/d}
to implement fmaximum_num{f/ }, fminimum_num{f/ }.

       *  sysdeps/loongarch/fpu/s_fmaximum_num.c: New file.
       *  sysdeps/loongarch/fpu/s_fmaximum_numf.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminimum_num.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminimum_numf.c: Likewise.

23 months agoLoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ }.
Xiaolin Tang [Mon, 7 Nov 2022 14:05:19 +0000 (22:05 +0800)]
LoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ }.

Use hardware Floating-point instruction f{max/min}.{s/d}, fclass.{s/d}
to implement fmaximum{f/ }, fminimum{f/ }.

       *  sysdeps/loongarch/fpu/s_fmaximum.c: New file.
       *  sysdeps/loongarch/fpu/s_fmaximumf.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminimum.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fminimumf.c: Likewise.

23 months agoLoongArch: Hard Float Support for float-point classification functions.
Xiaolin Tang [Mon, 7 Nov 2022 14:05:16 +0000 (22:05 +0800)]
LoongArch: Hard Float Support for float-point classification functions.

Use hardware Floating-point instruction fclass.{s/d} to implement
classification functions, i.e finite{f/ }, fpclassify{f/ }, isnan{f/ },
isinf{f/ }, issignaling{f/ }.

       *  sysdeps/loongarch/fpu/s_finite.c: New file.
       *  sysdeps/loongarch/fpu/s_finitef.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fpclassify.c: Likewise.
       *  sysdeps/loongarch/fpu/s_fpclassifyf.c: Likewise.
       *  sysdeps/loongarch/fpu/s_isinf.c: Likewise.
       *  sysdeps/loongarch/fpu/s_isinff.c: Likewise.
       *  sysdeps/loongarch/fpu/s_isnan.c: Likewise.
       *  sysdeps/loongarch/fpu/s_isnanf.c: Likewise.
       *  sysdeps/loongarch/fpu/s_issignaling.c: Likewise.
       *  sysdeps/loongarch/fpu/s_issignalingf.c: Likewise.
       *  sysdeps/loongarch/fpu_control.h: Add _FCLASS_* macro.

23 months agoLoongArch: Use __builtin_{fma, fmaf} to implement function {fma, fmaf}.
Xiaolin Tang [Mon, 7 Nov 2022 14:05:15 +0000 (22:05 +0800)]
LoongArch: Use __builtin_{fma, fmaf} to implement function {fma, fmaf}.

Use __builtin_{fma, fmaf} to implement function {fma, fmaf} instead of
the generic implementation.

       *  sysdeps/loongarch/fpu/math-use-builtins-fma.h: New file.

23 months agoLinux: Support __IPC_64 in sysvctl *ctl command arguments (bug 29771)
Florian Weimer [Tue, 8 Nov 2022 13:15:02 +0000 (14:15 +0100)]
Linux: Support __IPC_64 in sysvctl *ctl command arguments (bug 29771)

Old applications pass __IPC_64 as part of the command argument because
old glibc did not check for unknown commands, and passed through the
arguments directly to the kernel, without adding __IPC_64.
Applications need to continue doing that for old glibc compatibility,
so this commit enables this approach in current glibc.

For msgctl and shmctl, if no translation is required, make
direct system calls, as we did before the time64 changes.  If
translation is required, mask __IPC_64 from the command argument.

For semctl, the union-in-vararg argument handling means that
translation is needed on all architectures.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
23 months agoriscv: Get level 3 cache's information
Zong Li [Wed, 9 Nov 2022 14:40:59 +0000 (11:40 -0300)]
riscv: Get level 3 cache's information

RISC-V architecture extends the cache information for level 3 cache
in AUX vector in Linux v.6.1-rc1. This patch supports sysconf to get
the level 3 cache information.

Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
23 months agodebug: Fix typo in tests-unsupported rule
Adhemerval Zanella [Wed, 9 Nov 2022 14:24:45 +0000 (11:24 -0300)]
debug: Fix typo in tests-unsupported rule

From commit 2e274cd8c1ebd0bd0c43a7f2e5433685740938ca.

23 months agoiconvdata/tst-table-charmap.sh: remove handling of old, borrowed format
наб [Wed, 9 Nov 2022 12:48:46 +0000 (13:48 +0100)]
iconvdata/tst-table-charmap.sh: remove handling of old, borrowed format

This "Old POSIX/DKUUG borrowed format" handling is original to the file
and doesn't seem to have ever been used, i.e. id/t-t-c doesn't seem to
have ever been called with argv[1] == POSIX.

Upcoming is a POSIX charmap, which would inadvertently trigger this.

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
23 months agoMakerules: Generate shlib.lds with -fuse-ld=bfd
Fangrui Song [Wed, 9 Nov 2022 04:56:59 +0000 (20:56 -0800)]
Makerules: Generate shlib.lds with -fuse-ld=bfd

lld does not dump a linker script with --verbose (it does not use a
linker script driven design and lots of linker processing is not
serializable as a linker script anyway).  With the default
--with-default-link=no build, $@T is empty and makes `test -s $@T` fail.

Just dump the linker script with -fuse-ld=bfd.  lld since 15
(https://reviews.llvm.org/D124656) supports custom RELRO sections in the
GNU ld dumped linker script.

Reviewed-by: Sam James <sam@gentoo.org>
23 months agox86: Add avx2 optimized functions for the wchar_t strcpy family
Noah Goldstein [Wed, 9 Nov 2022 01:38:41 +0000 (17:38 -0800)]
x86: Add avx2 optimized functions for the wchar_t strcpy family

Implemented:
    wcscat-avx2  (+ 744 bytes
    wcscpy-avx2  (+ 539 bytes)
    wcpcpy-avx2  (+ 577 bytes)
    wcsncpy-avx2 (+1108 bytes)
    wcpncpy-avx2 (+1214 bytes)
    wcsncat-avx2 (+1085 bytes)

Performance Changes:
    Times are from N = 10 runs of the benchmark suite and are reported
    as geometric mean of all ratios of New Implementation / Best Old
    Implementation. Best Old Implementation was determined with the
    highest ISA implementation.

    wcscat-avx2     -> 0.975
    wcscpy-avx2     -> 0.591
    wcpcpy-avx2     -> 0.698
    wcsncpy-avx2    -> 0.730
    wcpncpy-avx2    -> 0.711
    wcsncat-avx2    -> 0.954

Code Size Changes:
    This change  increase the size of libc.so by ~5.5kb bytes. For
    reference the patch optimizing the normal strcpy family functions
    decreases libc.so by ~5.2kb.

Full check passes on x86-64 and build succeeds for all ISA levels w/
and w/o multiarch.

23 months agox86: Add evex optimized functions for the wchar_t strcpy family
Noah Goldstein [Wed, 9 Nov 2022 01:38:40 +0000 (17:38 -0800)]
x86: Add evex optimized functions for the wchar_t strcpy family

Implemented:
    wcscat-evex  (+ 905 bytes)
    wcscpy-evex  (+ 674 bytes)
    wcpcpy-evex  (+ 709 bytes)
    wcsncpy-evex (+1358 bytes)
    wcpncpy-evex (+1467 bytes)
    wcsncat-evex (+1213 bytes)

Performance Changes:
    Times are from N = 10 runs of the benchmark suite and are reported
    as geometric mean of all ratios of New Implementation / Best Old
    Implementation. Best Old Implementation was determined with the
    highest ISA implementation.

    wcscat-evex     -> 0.991
    wcscpy-evex     -> 0.587
    wcpcpy-evex     -> 0.695
    wcsncpy-evex    -> 0.719
    wcpncpy-evex    -> 0.694
    wcsncat-evex    -> 0.979

Code Size Changes:
    This change  increase the size of libc.so by ~6.3kb bytes. For
    reference the patch optimizing the normal strcpy family functions
    decreases libc.so by ~5.7kb.

Full check passes on x86-64 and build succeeds for all ISA levels w/
and w/o multiarch.

23 months agox86: Optimize and shrink st{r|p}{n}{cat|cpy}-avx2 functions
Noah Goldstein [Wed, 9 Nov 2022 01:38:39 +0000 (17:38 -0800)]
x86: Optimize and shrink st{r|p}{n}{cat|cpy}-avx2 functions

Optimizations are:
    1. Use more overlapping stores to avoid branches.
    2. Reduce how unrolled the aligning copies are (this is more of a
       code-size save, its a negative for some sizes in terms of
       perf).
    3. For st{r|p}n{cat|cpy} re-order the branches to minimize the
       number that are taken.

Performance Changes:

    Times are from N = 10 runs of the benchmark suite and are
    reported as geometric mean of all ratios of
    New Implementation / Old Implementation.

    strcat-avx2      -> 0.998
    strcpy-avx2      -> 0.937
    stpcpy-avx2      -> 0.971

    strncpy-avx2     -> 0.793
    stpncpy-avx2     -> 0.775

    strncat-avx2     -> 0.962

Code Size Changes:
    function         -> Bytes New / Bytes Old -> Ratio

    strcat-avx2      ->  685 / 1639 -> 0.418
    strcpy-avx2      ->  560 /  903 -> 0.620
    stpcpy-avx2      ->  592 /  939 -> 0.630

    strncpy-avx2     -> 1176 / 2390 -> 0.492
    stpncpy-avx2     -> 1268 / 2438 -> 0.520

    strncat-avx2     -> 1042 / 2563 -> 0.407

Notes:
    1. Because of the significant difference between the
       implementations they are split into three files.

           strcpy-avx2.S    -> strcpy, stpcpy, strcat
           strncpy-avx2.S   -> strncpy
           strncat-avx2.S    > strncat

       I couldn't find a way to merge them without making the
       ifdefs incredibly difficult to follow.

Full check passes on x86-64 and build succeeds for all ISA levels w/
and w/o multiarch.

23 months agox86: Optimize and shrink st{r|p}{n}{cat|cpy}-evex functions
Noah Goldstein [Wed, 9 Nov 2022 01:38:38 +0000 (17:38 -0800)]
x86: Optimize and shrink st{r|p}{n}{cat|cpy}-evex functions

Optimizations are:
    1. Use more overlapping stores to avoid branches.
    2. Reduce how unrolled the aligning copies are (this is more of a
       code-size save, its a negative for some sizes in terms of
       perf).
    3. Improve the loop a bit (similiar to what we do in strlen with
       2x vpminu + kortest instead of 3x vpminu + kmov + test).
    4. For st{r|p}n{cat|cpy} re-order the branches to minimize the
       number that are taken.

Performance Changes:

    Times are from N = 10 runs of the benchmark suite and are
    reported as geometric mean of all ratios of
    New Implementation / Old Implementation.

    stpcpy-evex      -> 0.922
    strcat-evex      -> 0.985
    strcpy-evex      -> 0.880

    strncpy-evex     -> 0.831
    stpncpy-evex     -> 0.780

    strncat-evex     -> 0.958

Code Size Changes:
    function         -> Bytes New / Bytes Old -> Ratio

    strcat-evex      ->  819 / 1874 -> 0.437
    strcpy-evex      ->  700 / 1074 -> 0.652
    stpcpy-evex      ->  735 / 1094 -> 0.672

    strncpy-evex     -> 1397 / 2611 -> 0.535
    stpncpy-evex     -> 1489 / 2691 -> 0.553

    strncat-evex     -> 1184 / 2832 -> 0.418

Notes:
    1. Because of the significant difference between the
       implementations they are split into three files.

           strcpy-evex.S    -> strcpy, stpcpy, strcat
           strncpy-evex.S   -> strncpy
           strncat-evex.S    > strncat

       I couldn't find a way to merge them without making the
       ifdefs incredibly difficult to follow.

    2. All implementations can be made evex512 by including
       "x86-evex512-vecs.h" at the top.

    3. All implementations have an optional define:
        `USE_EVEX_MASKED_STORE`
       Setting to one uses evex-masked stores for handling short
       strings.  This saves code size and branches.  It's disabled
       for all implementations are the moment as there are some
       serious drawbacks to masked stores in certain cases, but
       that may be fixed on future architectures.

Full check passes on x86-64 and build succeeds for all ISA levels w/
and w/o multiarch.

23 months agobenchtests: Make str{n}{cat|cpy} benchmarks output json
Noah Goldstein [Fri, 4 Nov 2022 08:20:21 +0000 (01:20 -0700)]
benchtests: Make str{n}{cat|cpy} benchmarks output json

Json output is easier to parse and most other benchmarks already do
the same.

23 months agox86: Use VMM API in memcmpeq-evex.S and minor changes
Noah Goldstein [Sat, 29 Oct 2022 20:19:59 +0000 (15:19 -0500)]
x86: Use VMM API in memcmpeq-evex.S and minor changes

Changes to generated code are:
    1. In a few places use `vpcmpeqb` instead of `vpcmpneq` to save a
       byte of code size.
    2. Add a branch for length <= (VEC_SIZE * 6) as opposed to doing
       the entire block of [VEC_SIZE * 4 + 1, VEC_SIZE * 8] in a
       single basic-block (the space to add the extra branch without
       changing code size is bought with the above change).

Change (2) has roughly a 20-25% speedup for sizes in [VEC_SIZE * 4 +
1, VEC_SIZE * 6] and negligible to no-cost for [VEC_SIZE * 6 + 1,
VEC_SIZE * 8]

From N=10 runs on Tigerlake:

align1,align2 ,length ,result               ,New Time ,Cur Time ,New Time / Old Time
0     ,0      ,129    ,0                    ,5.404    ,6.887    ,0.785
0     ,0      ,129    ,1                    ,5.308    ,6.826    ,0.778
0     ,0      ,129    ,18446744073709551615 ,5.359    ,6.823    ,0.785
0     ,0      ,161    ,0                    ,5.284    ,6.827    ,0.774
0     ,0      ,161    ,1                    ,5.317    ,6.745    ,0.788
0     ,0      ,161    ,18446744073709551615 ,5.406    ,6.778    ,0.798

0     ,0      ,193    ,0                    ,6.804    ,6.802    ,1.000
0     ,0      ,193    ,1                    ,6.950    ,6.754    ,1.029
0     ,0      ,193    ,18446744073709551615 ,6.792    ,6.719    ,1.011
0     ,0      ,225    ,0                    ,6.625    ,6.699    ,0.989
0     ,0      ,225    ,1                    ,6.776    ,6.735    ,1.003
0     ,0      ,225    ,18446744073709551615 ,6.758    ,6.738    ,0.992
0     ,0      ,256    ,0                    ,5.402    ,5.462    ,0.989
0     ,0      ,256    ,1                    ,5.364    ,5.483    ,0.978
0     ,0      ,256    ,18446744073709551615 ,5.341    ,5.539    ,0.964

Rewriting with VMM API allows for memcmpeq-evex to be used with
evex512 by including "x86-evex512-vecs.h" at the top.

Complete check passes on x86-64.

23 months agox86: Use VMM API in memcmp-evex-movbe.S and minor changes
Noah Goldstein [Sat, 29 Oct 2022 20:19:58 +0000 (15:19 -0500)]
x86: Use VMM API in memcmp-evex-movbe.S and minor changes

The only change to the existing generated code is `tzcnt` -> `bsf` to
save a byte of code size here and there.

Rewriting with VMM API allows for memcmp-evex-movbe to be used with
evex512 by including "x86-evex512-vecs.h" at the top.

Complete check passes on x86-64.

23 months agostring: Add len=0 to {w}memcmp{eq} tests and benchtests
Noah Goldstein [Sat, 29 Oct 2022 20:19:57 +0000 (15:19 -0500)]
string: Add len=0 to {w}memcmp{eq} tests and benchtests

len=0 is valid and fairly common so should be tested.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
23 months agoLinux: Add ppoll fortify symbol for 64 bit time_t (BZ# 29746)
Adhemerval Zanella [Fri, 4 Nov 2022 19:02:52 +0000 (16:02 -0300)]
Linux: Add ppoll fortify symbol for 64 bit time_t (BZ# 29746)

Similar to ppoll, the poll.h header needs to redirect the poll call
to a proper fortified ppoll with 64 bit time_t support.

The implementation is straightforward, just need to add a similar
check as __poll_chk and call the 64 bit time_t ppoll version.  The
debug fortify tests are also extended to cover 64 bit time_t for
affected ABIs.

Unfortunately it requires an aditional symbol, which makes backport
tricky.  One possibility is to add a static inline version if compiler
supports is and call abort instead of __chk_fail, so fortified version
will call __poll64 in the end.

Another possibility is to just remove the fortify support for
_TIME_BITS=64.

Checked on i686-linux-gnu.

2 years agohurd: Add sigtimedwait and sigwaitinfo support
Samuel Thibault [Mon, 7 Nov 2022 20:14:39 +0000 (21:14 +0100)]
hurd: Add sigtimedwait and sigwaitinfo support

This simply needed to add the timeout parameter to mach_msg, and copy
information from struct hurd_signal_detail.

2 years agoApply asm redirection in gmp.h before first use
Adhemerval Zanella [Thu, 10 Mar 2022 22:04:47 +0000 (19:04 -0300)]
Apply asm redirection in gmp.h before first use

For clang the redeclaration after the first use, the visibility attribute
is silently ignored (symbol is STV_DEFAULT) while the asm label attribute
causes an error.

Reviewed-by: Fangrui Song <maskray@google.com>
2 years agoRewrite find_cxx_header config configure.ac
Adhemerval Zanella [Wed, 2 Nov 2022 14:55:57 +0000 (11:55 -0300)]
Rewrite find_cxx_header config configure.ac

With clang if the main file is <stdin>, the first non-main-file
dependency is not listed in the -MP output.  Although it was fixed
on clang-16 [1], this change adds portability for older version.

[1] https://github.com/llvm/llvm-project/commit/ff9576f74514b836e1ba0268409a2ecb919d7118

Reviewed-by: Fangrui Song <maskray@google.com>
2 years agoelf/tlsdeschtab.h: Add the Malloc return value check in _dl_make_tlsdesc_dynamic()
Xiaoming Ni [Fri, 4 Nov 2022 09:30:00 +0000 (17:30 +0800)]
elf/tlsdeschtab.h: Add the Malloc return value check in _dl_make_tlsdesc_dynamic()

Check the return value of malloc based on the function header comment of
 _dl_make_tlsdesc_dynamic(). If the return value fails, NULL is returned.

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2 years agoelf: Disable some subtests of ifuncmain1, ifuncmain5 for !PIE
Florian Weimer [Fri, 4 Nov 2022 17:37:16 +0000 (18:37 +0100)]
elf: Disable some subtests of ifuncmain1, ifuncmain5 for !PIE

2 years agoposix: Make posix_spawn extensions available by default
Florian Weimer [Fri, 4 Nov 2022 06:43:59 +0000 (07:43 +0100)]
posix: Make posix_spawn extensions available by default

Some sources merely include <spawn.h> without -D_GNU_SOURCE and expect
declarations for posix_spawn_file_actions_addchdir_np to be available.
For consistency, declare posix_spawn_file_actions_addfchdir_np,
posix_spawn_file_actions_addclosefrom_np,
posix_spawn_file_actions_addtcsetpgrp_np as well.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agox86_64: Implement evex512 version of strrchr and wcsrchr
Sunil K Pandey [Tue, 9 Aug 2022 14:57:29 +0000 (07:57 -0700)]
x86_64: Implement evex512 version of strrchr and wcsrchr

Changes from v1:
  Use vec api for register.
  Replace VPCMP with VPCMPEQ
  Restructure and remove 1 unconditional jump.
  Change page cross logic to use sall.

This patch implements following evex512 version of string functions.
evex512 version takes up to 30% less cycle as compared to evex,
depending on length and alignment.

- strrchr function using 512 bit vectors.
- wcsrchr function using 512 bit vectors.

Code size data:

strrchr-evex.o 879 byte
strrchr-evex512.o 601 byte (-32%)

wcsrchr-evex.o 882 byte
wcsrchr-evex512.o 572 byte (-35%)

Placeholder function, not used by any processor at the moment.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
2 years agoelf: Introduce <dl-call_tls_init_tp.h> and call_tls_init_tp (bug 29249)
Florian Weimer [Thu, 3 Nov 2022 16:28:03 +0000 (17:28 +0100)]
elf: Introduce <dl-call_tls_init_tp.h> and call_tls_init_tp (bug 29249)

This makes it more likely that the compiler can compute the strlen
argument in _startup_fatal at compile time, which is required to
avoid a dependency on strlen this early during process startup.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2 years agoLoongArch: Fix ABI related macros in elf.h to keep consistent with binutils[1].
caiyinyu [Wed, 12 Oct 2022 12:28:42 +0000 (20:28 +0800)]
LoongArch: Fix ABI related macros in elf.h to keep consistent with binutils[1].

[1]:
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=c4a7e6b56218e1d5a858682186b542e2eae01a4a;hp=0d94a8735055432029237612a6eb9165db1ec9dd
[2]:
Reference: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version

2 years agoscripts/glibcelf.py: Properly report <elf.h> parsing failures
Florian Weimer [Thu, 3 Nov 2022 11:24:17 +0000 (12:24 +0100)]
scripts/glibcelf.py: Properly report <elf.h> parsing failures

Without this change, parse failures result in an exception:

Traceback (most recent call last):
  File "tst-glibcelf.py", line 23, in <module>
    import glibcelf
  File "/path/to/git/scripts/glibcelf.py", line 226, in <module>
    _elf_h = _parse_elf_h()
  File "/path/to/git/scripts/glibcelf.py", line 221, in _parse_elf_h
    result = glibcpp.macro_eval(glibcpp.macro_definitions(tokens), reporter)
  File "/path/to/git/scripts/glibcpp.py", line 379, in macro_eval
    reporter.error(md.line, 'macro {} redefined'.format(md.name))
  File "/path/to/git/scripts/glibcelf.py", line 214, in error
    errors += 1
UnboundLocalError: local variable 'errors' referenced before assignment

2 years agoelf: Rework exception handling in the dynamic loader [BZ #25486]
Florian Weimer [Thu, 3 Nov 2022 08:39:31 +0000 (09:39 +0100)]
elf: Rework exception handling in the dynamic loader [BZ #25486]

The old exception handling implementation used function interposition
to replace the dynamic loader implementation (no TLS support) with the
libc implementation (TLS support).  This results in problems if the
link order between the dynamic loader and libc is reversed (bug 25486).

The new implementation moves the entire implementation of the
exception handling functions back into the dynamic loader, using
THREAD_GETMEM and THREAD_SETMEM for thread-local data support.
These depends on Hurd support for these macros, added in commit
b65a82e4e757c1e6cb7073916 ("hurd: Add THREAD_GET/SETMEM/_NC").

One small obstacle is that the exception handling facilities are used
before the TCB has been set up, so a check is needed if the TCB is
available.  If not, a regular global variable is used to store the
exception handling information.

Also rename dl-error.c to dl-catch.c, to avoid confusion with the
dlerror function.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
This page took 0.092802 seconds and 5 git commands to generate.