]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
17 months agoRemove trailing whitespace in gmp.h
Joseph Myers [Fri, 6 Jan 2023 21:14:15 +0000 (21:14 +0000)] 
Remove trailing whitespace in gmp.h

17 months agoRemove trailing whitespace
Joseph Myers [Fri, 6 Jan 2023 21:11:08 +0000 (21:11 +0000)] 
Remove trailing whitespace

For some reason this causes a pre-commit check error for a copyright
date update commit, even though that commit doesn't touch anything
near the line with this whitespace.

17 months agoC2x semantics for <tgmath.h>
Joseph Myers [Fri, 6 Jan 2023 19:33:29 +0000 (19:33 +0000)] 
C2x semantics for <tgmath.h>

<tgmath.h> implements semantics for integer generic arguments that
handle cases involving _FloatN / _FloatNx types as specified in TS
18661-3 plus some defect fixes.

C2x has further changes to the semantics for <tgmath.h> macros with
such types, which should also be considered defect fixes (although
handled through the integration of TS 18661-3 in C2x rather than
through an issue tracking process).  Specifically, the rules were
changed because of problems raised with using the macros with the
evaluation format types such as float_t and _Float32_t: the older
version of the rules didn't allow passing _FloatN / _FloatNx types to
the narrowing macros returning float or double, or passing float /
double / long double to the narrowing macros returning _FloatN /
_FloatNx, which was a problem with the evaluation format types which
could be either kind of type depending on the value of
FLT_EVAL_METHOD.

Thus the new rules allow cases of mixing types which were not allowed
before, and, as part of the changes, the handling of integer arguments
was also changed: if there is any _FloatNx generic argument, integer
generic arguments are treated as _Float32x (not double), while the
rule about treating integer arguments to narrowing macros returning
_FloatN or _FloatNx as _Float64 not double was removed (no longer
needed now double is a valid argument to such macros).

I've implemented the changes in GCC's __builtin_tgmath, which thus
requires updates to glibc's test expectations so that the tests
continue to build with GCC 13 (the test is also updated to test the
argument types that weren't allowed before but are now valid under C2x
rules).

Given those test changes, it's then also necessary to fix the
implementations in <tgmath.h> to have appropriate semantics with older
GCC so that the tests pass with GCC versions before GCC 13 as well.
For some cases (non-narrowing macros with two or three generic
arguments; narrowing macros returning _Float32x), the older version of
__builtin_tgmath doesn't correspond sufficiently well to C2x
semantics, so in those cases <tgmath.h> is adjusted to use the older
macro implementation instead of __builtin_tgmath.  The older macro
implementation is itself adjusted to give the desired semantics, with
GCC 7 and later.  (It's not possible to get the right semantics in all
cases for the narrowing macros with GCC 6 and before when the _FloatN
/ _FloatNx names are typedefs rather than distinct types.)

Tested as follows: with the full glibc testsuite for x86_64, GCC 6, 7,
11, 13; with execution of the math/tests for aarch64, arm, powerpc and
powerpc64le, GCC 6, 7, 12 and 13 (powerpc64le only with GCC 12 and
13); with build-many-glibcs.py with GCC 6, 7, 12 and 13.

17 months agotime: Set daylight to 1 for matching DST/offset change (bug 29951)
Florian Weimer [Thu, 5 Jan 2023 17:21:25 +0000 (18:21 +0100)] 
time: Set daylight to 1 for matching DST/offset change (bug 29951)

The daylight variable is supposed to be set to 1 if DST is ever in
use for the current time zone.  But __tzfile_read used to do this:

  __daylight = rule_stdoff != rule_dstoff;

This check can fail to set __daylight to 1 if the DST and non-DST
offsets happen to be the same.

17 months agoFix ldbl-128 built-in function use
Joseph Myers [Thu, 5 Jan 2023 00:02:54 +0000 (00:02 +0000)] 
Fix ldbl-128 built-in function use

Fix the following issues with built-in function use in
sysdeps/ieee754/ldbl-128 and sysdeps/ieee754/float128:

* fabsl used __builtin_fabsf128 unconditionally, breaking the build
  with GCC 6 for several architectures; it should use __builtin_fabsl
  with an appropriate redirection in float128_private.h.  (I'm not
  particularly concerned with building glibc with GCC 6; rather, I
  want to be able to run the tgmath.h tests with GCC 6, which is a
  significantly different case for tgmath.h compared to GCC 7 and
  later because of the lack of _FloatN / _FloatNx support in the
  compiler, and at present running the tests with a compiler means
  building glibc with that compiler.)

* Some (conditional) uses of built-in functions had been added to
  ldbl-128 without appropriate float128_private.h remapping (there was
  remapping for the macros controlling whether the built-in functions
  are used, just not for the functions themselves).

* s_llrintl.c called __builtin_round not __builtin_llrintl, which is
  obviously wrong.

Tested with build-many-glibcs.py for aarch64-linux-gnu, GCC 6 (where
it fixes the glibc build) and GCC 12, and with the glibc testsuite for
x86_64.

17 months agox86: Check minimum/maximum of non_temporal_threshold [BZ #29953]
H.J. Lu [Tue, 3 Jan 2023 21:06:48 +0000 (13:06 -0800)] 
x86: Check minimum/maximum of non_temporal_threshold [BZ #29953]

The minimum non_temporal_threshold is 0x4040.  non_temporal_threshold may
be set to less than the minimum value when the shared cache size isn't
available (e.g., in an emulator) or by the tunable.  Add checks for
minimum and maximum of non_temporal_threshold.

This fixes BZ #29953.

17 months agoi686: Regenerate ulps
Andreas K. Hüttel [Mon, 2 Jan 2023 17:35:59 +0000 (18:35 +0100)] 
i686: Regenerate ulps

Reviewed-by: Florian Weimer <fweimer@redhat.com>
17 months agohurd getcwd: Fix memory leak on error
Samuel Thibault [Mon, 2 Jan 2023 00:59:53 +0000 (01:59 +0100)] 
hurd getcwd: Fix memory leak on error

17 months agohurd fcntl: Make LOCKED macro more robust
Samuel Thibault [Mon, 2 Jan 2023 00:54:18 +0000 (01:54 +0100)] 
hurd fcntl: Make LOCKED macro more robust

17 months agohurd: Make dl-sysdep __sbrk check __vm_allocate call
Samuel Thibault [Mon, 2 Jan 2023 00:49:59 +0000 (01:49 +0100)] 
hurd: Make dl-sysdep __sbrk check __vm_allocate call

The caller won't be able to progress, but better crash than use random
addr.

17 months agohtl: Drop duplicate check in __pthread_stack_alloc
Samuel Thibault [Mon, 2 Jan 2023 00:47:38 +0000 (01:47 +0100)] 
htl: Drop duplicate check in __pthread_stack_alloc

17 months agohurd hurdstartup: Initialize remaining fields of hurd_startup_data
Samuel Thibault [Mon, 2 Jan 2023 00:36:02 +0000 (01:36 +0100)] 
hurd hurdstartup: Initialize remaining fields of hurd_startup_data

In case we don't have a bootstrap port or __exec_startup_get_info
failed, we should avoid leaking uninitialized fields of data.

17 months agohurd _S_msg_add_auth: Initialize new arrays to 0
Samuel Thibault [Mon, 2 Jan 2023 00:08:38 +0000 (01:08 +0100)] 
hurd _S_msg_add_auth: Initialize new arrays to 0

If make_list fails, they would be undefined, and freeup with free
uninitialized pointers.

17 months agohtl: Check error returned by __getrlimit
Samuel Thibault [Mon, 2 Jan 2023 00:01:28 +0000 (01:01 +0100)] 
htl: Check error returned by __getrlimit

17 months agogetdelim: ensure error indicator is set on error (bug 29917)
Andreas Schwab [Mon, 19 Dec 2022 11:40:45 +0000 (12:40 +0100)] 
getdelim: ensure error indicator is set on error (bug 29917)

POSIX requires that getdelim and getline set the error indicator on the
stream when an error occured, in addition to setting errno.

17 months agohtl: Fix sem_wait race between read and gsync_wait
Samuel Thibault [Thu, 29 Dec 2022 23:40:18 +0000 (00:40 +0100)] 
htl: Fix sem_wait race between read and gsync_wait

If the value changes between sem_wait's read and the gsync_wait call,
the kernel will return KERN_INVALID_ARGUMENT, which we have to interpret
as the value having already changed.

This fixes applications (e.g. libgo) seeing sem_wait erroneously return
KERN_INVALID_ARGUMENT.

18 months agoAvoid use of atoi in malloc
Joseph Myers [Thu, 22 Dec 2022 19:37:09 +0000 (19:37 +0000)] 
Avoid use of atoi in malloc

This patch is analogous to commit
a3708cf6b0a5a68e2ed1ce3db28a03ed21d368d2.

atoi has undefined behavior on out-of-range input, which makes it
problematic to use anywhere in glibc that might be processing input
out-of-range for atoi but not specified to produce undefined behavior
for the function calling atoi.  In conjunction with the C2x strtol
changes, use of atoi in libc can also result in localplt test failures
because the redirection for strtol does not interact properly with the
libc_hidden_proto call for __isoc23_strtol for the call in the inline
atoi implementation.

In malloc/arena.c, this issue shows up for atoi calls that are only
compiled for --disable-tunables (thus with the
x86_64-linux-gnu-minimal configuration of build-many-glibcs.py, for
example).  Change those atoi calls to use strtol directly, as in the
previous such changes.

Tested for x86_64 (--disable-tunables).

18 months agoLinux: Pass size argument of epoll_create to the kernel
Florian Weimer [Thu, 22 Dec 2022 16:22:28 +0000 (17:22 +0100)] 
Linux: Pass size argument of epoll_create to the kernel

The kernel actually verifies it, and a garbage value in the register
causes improper system call failures.

Fixes commit c1c0dea38833751f36a145c32 ("Linux: Remove epoll_create,
inotify_init from syscalls.list") and commit d1d23b134244d59c4d6ef2295
("Lninux: consolidate epoll_create implementation").

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
18 months agoSimplify scripts/cross-test-ssh.sh configuration.
Carlos O'Donell [Wed, 21 Dec 2022 22:21:05 +0000 (17:21 -0500)] 
Simplify scripts/cross-test-ssh.sh configuration.

With modern ssh clients and daemons it is required to use AcceptEnv and
SendEnv configuration options to correctly support testing the DSO sort
ordering tests.  This requirement is present because
scripts/dso-ordering-test.py injects GLIBC_TUNABLES to the left of the
${test_wrapper_env} and so it must both be sent by the ssh client and
accepted by the ssh daemon.  This requirement is removed in this change
and the injected GLIBC_TUNABLES is placed after ${run_program_env} and
so still correctly provides the override that the test requires.
This is similar to existing tests like elf/tst-pathopt.sh,
elf/tst-rtld-load-self.sh, and locale/tst-locale-locpath.sh.

Tested that it fixes two failures when cross-testing on aarch64 with
scripts/cross-test-ssh.sh and an ssh client and daemon that do not pass
GLIBC_TUNABLES. Without this fix such a configuration will report the
following failures (since the GLIBC_TUNABLES not preserved):
FAIL: elf/tst-bz15311
FAIL: elf/tst-bz28937

Tested without regression on native x86_64 and aarch64 builds.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoDefine MADV_COLLAPSE from Linux 6.1
Joseph Myers [Thu, 22 Dec 2022 15:12:52 +0000 (15:12 +0000)] 
Define MADV_COLLAPSE from Linux 6.1

Add the MADV_COLLAPSE constant from Linux 6.1 to bits/mman-linux.h and
the hppa bits/mman.h.

Tested for x86_64.

18 months agopowerpc64: Increase SIGSTKSZ and MINSIGSTKSZ
Rajalakshmi Srinivasaraghavan [Wed, 21 Dec 2022 23:48:35 +0000 (17:48 -0600)] 
powerpc64: Increase SIGSTKSZ and MINSIGSTKSZ

This patch increases the value of SIGSTKSZ and MINSIGSTKSZ
for powerpc64 similar to the kernel commit
2f82ec19757f58549467db568c56e7dfff8af283 to allow
further expansion of the signal stack frame size.

18 months agoUpdate all PO files in preparation for release.
Carlos O'Donell [Wed, 21 Dec 2022 22:15:37 +0000 (17:15 -0500)] 
Update all PO files in preparation for release.

18 months agoUpdate kernel version to 6.1 in header constant tests
Joseph Myers [Wed, 21 Dec 2022 15:49:37 +0000 (15:49 +0000)] 
Update kernel version to 6.1 in header constant tests

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

Tested with build-many-glibcs.py.

18 months agoUpdate syscall lists for Linux 6.1
Joseph Myers [Tue, 20 Dec 2022 15:24:29 +0000 (15:24 +0000)] 
Update syscall lists for Linux 6.1

Linux 6.1 has no new syscalls.  Update the version number in
syscall-names.list to reflect that it is still current for 6.1.

18 months agolibio: Convert __vswprintf_internal to buffers (bug 27857)
Florian Weimer [Mon, 19 Dec 2022 17:56:55 +0000 (18:56 +0100)] 
libio: Convert __vswprintf_internal to buffers (bug 27857)

Always null-terminate the buffer and set E2BIG if the buffer is too
small.  This fixes bug 27857.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agolibio: Convert __obstack_vprintf_internal to buffers (bug 27124)
Florian Weimer [Mon, 19 Dec 2022 17:56:55 +0000 (18:56 +0100)] 
libio: Convert __obstack_vprintf_internal to buffers (bug 27124)

This fixes bug 27124 because the problematic built-in vtable is gone.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agolibio: Convert __vdprintf_internal to buffers
Florian Weimer [Mon, 19 Dec 2022 17:56:55 +0000 (18:56 +0100)] 
libio: Convert __vdprintf_internal to buffers

The internal buffer size is set to 2048 bytes.  This is less than
the original BUFSIZ value used by buffered_vfprintf before
the conversion, but it hopefully covers all cases where write
boundaries matter.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agolibio: Convert __vasprintf_internal to buffers
Florian Weimer [Mon, 19 Dec 2022 17:56:55 +0000 (18:56 +0100)] 
libio: Convert __vasprintf_internal to buffers

The buffer resizing algorithm is slightly different.  The initial
buffer is on the stack, and small buffers are directly allocated
on the heap using the exact required size.  The overhead of the
additional copy is compensated by the lowered setup cost for buffers
compared to libio streams.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agolibio: Convert __vsprintf_internal to buffers
Florian Weimer [Mon, 19 Dec 2022 17:56:55 +0000 (18:56 +0100)] 
libio: Convert __vsprintf_internal to buffers

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agostdio-common: Add lock optimization to vfprintf and vfwprintf
Florian Weimer [Mon, 19 Dec 2022 17:56:54 +0000 (18:56 +0100)] 
stdio-common: Add lock optimization to vfprintf and vfwprintf

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

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agostdio-common: Convert vfprintf and related functions to buffers
Florian Weimer [Mon, 19 Dec 2022 17:56:54 +0000 (18:56 +0100)] 
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.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agostdio-common: Add __translated_number_width
Florian Weimer [Mon, 19 Dec 2022 17:56:54 +0000 (18:56 +0100)] 
stdio-common: Add __translated_number_width

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

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agostdio-common: Add __printf_function_invoke
Florian Weimer [Mon, 19 Dec 2022 17:56:54 +0000 (18:56 +0100)] 
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.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agostdio-common: Introduce buffers for implementing printf
Florian Weimer [Mon, 19 Dec 2022 17:56:54 +0000 (18:56 +0100)] 
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.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agolocale: Implement struct grouping_iterator
Florian Weimer [Mon, 19 Dec 2022 17:56:54 +0000 (18:56 +0100)] 
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>
18 months agoUse Linux 6.1 in build-many-glibcs.py
Joseph Myers [Mon, 19 Dec 2022 15:04:37 +0000 (15:04 +0000)] 
Use Linux 6.1 in build-many-glibcs.py

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

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

18 months agoAvoid use of atoi in some places in libc
Joseph Myers [Mon, 19 Dec 2022 14:45:44 +0000 (14:45 +0000)] 
Avoid use of atoi in some places in libc

This patch is split out of
<https://sourceware.org/pipermail/libc-alpha/2022-December/144122.html>.

atoi has undefined behavior on out-of-range input, which makes it
problematic to use anywhere in glibc that might be processing input
out-of-range for atoi but not specified to produce undefined behavior
for the function calling atoi.  Change some uses of atoi to call
strtol instead; this avoids the undefined behavior, though there is no
guarantee that the overflow handling of strtol is really right in
those places either.  This also serves to avoid localplt test failures
given an installed header redirection for strtol (which means that the
call from the inline atoi implementation doesn't end up at a hidden
alias from libc_hidden_proto).

Certainly, the use of atoi is questionable in argp-help.c (shared with
gnulib, so shouldn't depend on glibc implementation details, and
processing user-provided input), and maybe also in argp-parse.c (I'm
not sure what that code in argp-parse.c is meant to be used for).  I
also changed inet/rexec.c and resolv/res_init.c similarly to use
strtol to avoid such localplt failures, although given those files (in
those versions) are only used in glibc it's not problematic for them
to rely on the specific behavior of glibc's atoi on out-of-range input
(in the absence of compiler optimizations based on the undefined
behavior) in the same way it's problematic for gnulib code to do so.

There may be other uses of atoi (or atol or atoll), in any of glibc's
installed code, for which it would also be appropriate to avoid the
undefined behavior on out-of-range input; this patch only fixes the
specific cases needed to avoid localplt failures.

Tested for x86_64.

18 months agoLinux: Remove epoll_create, inotify_init from syscalls.list
Florian Weimer [Mon, 19 Dec 2022 10:03:35 +0000 (11:03 +0100)] 
Linux: Remove epoll_create, inotify_init from syscalls.list

Their presence causes stub warnings to be created on architectures
which do not implement them.

Fixes commit d1d23b134244d59c4d6ef2295 ("Lninux: consolidate
epoll_create implementation") and commit 842128f160a48e5545900ea3b
("Linux: consolidate inotify_init implementation").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agoLinux: Reflow and sort some Makefile variables
Florian Weimer [Mon, 19 Dec 2022 10:01:37 +0000 (11:01 +0100)] 
Linux: Reflow and sort some Makefile variables

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agomach: Drop remnants of old_CFLAGS
Samuel Thibault [Mon, 19 Dec 2022 01:38:38 +0000 (02:38 +0100)] 
mach: Drop remnants of old_CFLAGS

18 months agomach: Fix passing -ffreestanding when checking for gnumach headers
Samuel Thibault [Mon, 19 Dec 2022 01:34:55 +0000 (02:34 +0100)] 
mach: Fix passing -ffreestanding when checking for gnumach headers

8b8c768e3c70 ("Force use of -ffreestanding when checking for gnumach
headers") was passing -ffreestanding to CFLAGS only, but headers checks are
performed with the preprocessor, so we rather need to pass it to CPPFLAGS.

18 months agoForce use of -ffreestanding when checking for gnumach headers
Flavio Cruz [Mon, 19 Dec 2022 00:46:15 +0000 (19:46 -0500)] 
Force use of -ffreestanding when checking for gnumach headers

Without this ./configure assumes that we are in a fully hosted
environment, which might not be the case. After this patch, we can rely on
the freestanding header files provided by GCC such as stdint.h.
Message-Id: <Y5+0V9osFc/zXMq0@mars>

18 months agoelf: Fix tst-relro-symbols.py argument passing
Adhemerval Zanella [Wed, 14 Dec 2022 21:18:34 +0000 (18:18 -0300)] 
elf: Fix tst-relro-symbols.py argument passing

Current scheme only consideres the first argument for both --required
and --optional, where the idea is to append a new item.

Checked on x86_64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agox86: Prevent SIGSEGV in memcmp-sse2 when data is concurrently modified [BZ #29863]
Noah Goldstein [Wed, 14 Dec 2022 18:52:10 +0000 (10:52 -0800)] 
x86: Prevent SIGSEGV in memcmp-sse2 when data is concurrently modified [BZ #29863]

In the case of INCORRECT usage of `memcmp(a, b, N)` where `a` and `b`
are concurrently modified as `memcmp` runs, there can be a SIGSEGV
in `L(ret_nonzero_vec_end_0)` because the sequential logic
assumes that `(rdx - 32 + rax)` is a positive 32-bit integer.

To be clear, this change does not mean the usage of `memcmp` is
supported.  The program behaviour is undefined (UB) in the
presence of data races, and `memcmp` is incorrect when the values
of `a` and/or `b` are modified concurrently (data race). This UB
may manifest itself as a SIGSEGV. That being said, if we can
allow the idiomatic use cases, like those in yottadb with
opportunistic concurrency control (OCC), to execute without a
SIGSEGV, at no cost to regular use cases, then we can aim to
minimize harm to those existing users.

The fix replaces a 32-bit `addl %edx, %eax` with the 64-bit variant
`addq %rdx, %rax`. The 1-extra byte of code size from using the
64-bit instruction doesn't contribute to overall code size as the
next target is aligned and has multiple bytes of `nop` padding
before it. As well all the logic between the add and `ret` still
fits in the same fetch block, so the cost of this change is
basically zero.

The relevant sequential logic can be seen in the following
pseudo-code:
```
    /*
     * rsi = a
     * rdi = b
     * rdx = len - 32
     */
    /* cmp a[0:15] and b[0:15]. Since length is known to be [17, 32]
    in this case, this check is also assumed to cover a[0:(31 - len)]
    and b[0:(31 - len)].  */
    movups  (%rsi), %xmm0
    movups  (%rdi), %xmm1
    PCMPEQ  %xmm0, %xmm1
    pmovmskb %xmm1, %eax
    subl    %ecx, %eax
    jnz L(END_NEQ)

    /* cmp a[len-16:len-1] and b[len-16:len-1].  */
    movups  16(%rsi, %rdx), %xmm0
    movups  16(%rdi, %rdx), %xmm1
    PCMPEQ  %xmm0, %xmm1
    pmovmskb %xmm1, %eax
    subl    %ecx, %eax
    jnz L(END_NEQ2)
    ret

L(END2):
    /* Position first mismatch.  */
    bsfl    %eax, %eax

    /* The sequential version is able to assume this value is a
    positive 32-bit value because the first check included bytes in
    range a[0:(31 - len)] and b[0:(31 - len)] so `eax` must be
    greater than `31 - len` so the minimum value of `edx` + `eax` is
    `(len - 32) + (32 - len) >= 0`. In the concurrent case, however,
    `a` or `b` could have been changed so a mismatch in `eax` less or
    equal than `(31 - len)` is possible (the new low bound is `(16 -
    len)`. This can result in a negative 32-bit signed integer, which
    when zero extended to 64-bits is a random large value this out
    out of bounds. */
    addl %edx, %eax

    /* Crash here because 32-bit negative number in `eax` zero
    extends to out of bounds 64-bit offset.  */
    movzbl  16(%rdi, %rax), %ecx
    movzbl  16(%rsi, %rax), %eax
```

This fix is quite simple, just make the `addl %edx, %eax` 64 bit (i.e
`addq %rdx, %rax`). This prevents the 32-bit zero extension
and since `eax` is still a low bound of `16 - len` the `rdx + rax`
is bound by `(len - 32) - (16 - len) >= -16`. Since we have a
fixed offset of `16` in the memory access this must be in bounds.

18 months agoAllow _Qp_fgt in sparc64 localplt.data
Joseph Myers [Tue, 13 Dec 2022 22:16:22 +0000 (22:16 +0000)] 
Allow _Qp_fgt in sparc64 localplt.data

A recent GCC change resulted in localplt test failures on sparc64
because of references to _Qp_fgt.  This is analogous to all the other
floating-point symbols allowed in localplt.data, so it seems
appropriate to allow this one as well.

Tested with build-many-glibcs.py for sparc64-linux-gnu (GCC mainline),
where it fixes the test failure.

18 months agostdlib: Move _IO_cleanup to call_function_static_weak
Adhemerval Zanella [Sun, 13 Nov 2022 18:49:27 +0000 (15:49 -0300)] 
stdlib: Move _IO_cleanup to call_function_static_weak

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoelf: Do not assume symbol order on tst-audit25{a,b}
Adhemerval Zanella [Thu, 10 Nov 2022 17:49:33 +0000 (14:49 -0300)] 
elf: Do not assume symbol order on tst-audit25{a,b}

The static linker might impose any order or internal function
position, so change the test to check if the audit prints the
symbol only once in any order.

18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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).

18 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>
18 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.

18 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

18 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>
18 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>
18 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>
18 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>
18 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>

18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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.

18 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.

18 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.

18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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
18 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.