]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
2 years agoRemove unreliable parts of rt/tst-cpuclock2
DJ Delorie [Tue, 5 Oct 2021 18:52:05 +0000 (14:52 -0400)] 
Remove unreliable parts of rt/tst-cpuclock2

This is a follow-up to the tst-cpuclock1.c change here:
9a29f1a2ae3d4bb253ee368e0d71db0ca9494120

This test, like tst-cpuclock1, may fail on heavily loaded VM
servers (and has occasionally failed on the 32bit trybot),
so tests that rely on "wall time" have been removed.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoelf: Avoid nested functions in the loader [BZ #27220]
Fangrui Song [Thu, 7 Oct 2021 18:55:02 +0000 (11:55 -0700)] 
elf: Avoid nested functions in the loader [BZ #27220]

dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).

The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)

Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
  elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
  elf_machine_lazy_rel can drop the `scope` parameter.

Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoAdd run-time check for indirect external access
H.J. Lu [Fri, 18 Jun 2021 23:50:39 +0000 (16:50 -0700)] 
Add run-time check for indirect external access

When performing symbol lookup for references in executable without
indirect external access:

1. Disallow copy relocations in executable against protected data symbols
in a shared object with indirect external access.
2. Disallow non-zero symbol values of undefined function symbols in
executable, which are used as the function pointer, against protected
function symbols in a shared object with indirect external access.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoInitial support for GNU_PROPERTY_1_NEEDED
H.J. Lu [Fri, 18 Jun 2021 18:53:55 +0000 (11:53 -0700)] 
Initial support for GNU_PROPERTY_1_NEEDED

1. Add GNU_PROPERTY_1_NEEDED:

 #define GNU_PROPERTY_1_NEEDED      GNU_PROPERTY_UINT32_OR_LO

to indicate the needed properties by the object file.
2. Add GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS:

 #define GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS (1U << 0)

to indicate that the object file requires canonical function pointers and
cannot be used with copy relocation.
3. Scan GNU_PROPERTY_1_NEEDED property and store it in l_1_needed.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoio: Fix ftw internal realloc buffer (BZ #28126)
Adhemerval Zanella [Wed, 25 Aug 2021 14:17:06 +0000 (11:17 -0300)] 
io: Fix ftw internal realloc buffer (BZ #28126)

The 106ff08526d3ca did not take in consideration the buffer might be
reallocated if the total path is larger than PATH_MAX.  The realloc
uses 'dirbuf', where 'dirstreams' is the allocated buffer.

Checked on x86_64-linux-gnu.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoFix subscript error with odd TZif file [BZ #28338]
Paul Eggert [Tue, 14 Sep 2021 05:49:45 +0000 (22:49 -0700)] 
Fix subscript error with odd TZif file [BZ #28338]

* time/tzfile.c (__tzfile_compute): Fix unlikely off-by-one bug
that accessed before start of an array when an oddball-but-valid
TZif file was queried with an unusual time_t value.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoS390: Add PCI_MIO and SIE HWCAPs
Stefan Liebler [Tue, 5 Oct 2021 14:14:10 +0000 (16:14 +0200)] 
S390: Add PCI_MIO and SIE HWCAPs

Both new HWCAPs were introduced in these kernel commits:
7e8403ecaf884f307b627f3c371475913dd29292
  "s390: add HWCAP_S390_PCI_MIO to ELF hwcaps"
7e82523f2583e9813e4109df3656707162541297
  "s390/hwcaps: make sie capability regular hwcap"

Also note that the kernel commit 511ad531afd4090625def4d9aba1f5227bd44b8e
"s390/hwcaps: shorten HWCAP defines" has shortened the prefix of the macros
from "HWCAP_S390_" to "HWCAP_".  For compatibility reasons, we do not
change the prefix in public glibc header file.

2 years agosupport: Also return fd when it is 0
Siddhesh Poyarekar [Wed, 6 Oct 2021 16:18:35 +0000 (21:48 +0530)] 
support: Also return fd when it is 0

The fd validity check in open_dev_null checks if fd > 0, which would
lead to a leaked fd if it is == 0.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agold.so: Don't fill the DT_DEBUG entry in ld.so [BZ #28129]
H.J. Lu [Mon, 2 Aug 2021 20:52:36 +0000 (13:52 -0700)] 
ld.so: Don't fill the DT_DEBUG entry in ld.so [BZ #28129]

Linker creates the DT_DEBUG entry only in executables.  Don't fill the
non-existent DT_DEBUG entry in ld.so with the run-time address of the
r_debug structure.  This fixes BZ #28129.

2 years agoS390: update libm test ulps
Stefan Liebler [Wed, 6 Oct 2021 14:34:40 +0000 (16:34 +0200)] 
S390: update libm test ulps

Update after

 commit 6bbf7298323bf31bc43494b2201465a449778e10.
 Fixed inaccuracy of j0f (BZ #28185)

See also e.g.
commit c75b106145c30e6c7bcf87f384a5c68ce56406e9
aarch64: update libm test ulps

2 years agopowerpc: update libm test ulps
Adhemerval Zanella [Wed, 6 Oct 2021 13:49:28 +0000 (16:49 +0300)] 
powerpc: update libm test ulps

Update after commit 6bbf7298323bf31bc43494b2201465a449778e10
(Fixed inaccuracy of j0f (BZ #28185)).

2 years agomath: Also xfail the new j0f tests for ibm128-libgcc
Adhemerval Zanella [Wed, 6 Oct 2021 13:47:52 +0000 (16:47 +0300)] 
math: Also xfail the new j0f tests for ibm128-libgcc

From commit 6bbf7298323bf31b.

Checked on powerpc64-linux-gnu.

2 years agoy2038: Use a common definition for stat for sparc32
Adhemerval Zanella [Wed, 6 Oct 2021 11:10:13 +0000 (08:10 -0300)] 
y2038: Use a common definition for stat for sparc32

The sparc32 misses support for support done by 4e8521333bea6.

Checked on sparcv9-linux-gnu.

2 years agoFix stdlib/tst-setcontext.c for GCC 12 -Warray-compare
Joseph Myers [Tue, 5 Oct 2021 14:25:40 +0000 (14:25 +0000)] 
Fix stdlib/tst-setcontext.c for GCC 12 -Warray-compare

Building stdlib/tst-setcontext.c fails with GCC mainline:

tst-setcontext.c: In function 'f2':
tst-setcontext.c:61:16: error: comparison between two arrays [-Werror=array-compare]
   61 |   if (on_stack < st2 || on_stack >= st2 + sizeof (st2))
      |                ^
tst-setcontext.c:61:16: note: use '&on_stack[0] < &st2[0]' to compare the addresses

The comparison in this case is deliberate, so adjust it as suggested
in that note.

Tested with build-many-glibcs.py (GCC mainline) for aarch64-linux-gnu.

2 years agoaarch64: update libm test ulps
Szabolcs Nagy [Tue, 5 Oct 2021 12:43:26 +0000 (13:43 +0100)] 
aarch64: update libm test ulps

Update after

 commit 6bbf7298323bf31bc43494b2201465a449778e10.
 Fixed inaccuracy of j0f (BZ #28185)

2 years agoFixed inaccuracy of j0f (BZ #28185)
Paul Zimmermann [Tue, 5 Oct 2021 08:32:36 +0000 (10:32 +0200)] 
Fixed inaccuracy of j0f (BZ #28185)

The largest errors over the full binary32 range are after this
patch (on x86_64):

RNDN: libm wrong by up to 9.00e+00 ulp(s) [9] for x=0x1.04c39cp+6
RNDZ: libm wrong by up to 9.00e+00 ulp(s) [9] for x=0x1.04c39cp+6
RNDU: libm wrong by up to 9.00e+00 ulp(s) [9] for x=0x1.04c39cp+6
RNDD: libm wrong by up to 8.98e+00 ulp(s) [9] for x=0x1.4b7066p+7

Inputs that were yielding huge errors have been added to "make check".
Reviewed-by: Adhemeral Zanella <adhemerval.zanella@linaro.org>
2 years agoFix stdio-common tests for GCC 12 -Waddress
Joseph Myers [Mon, 4 Oct 2021 19:10:43 +0000 (19:10 +0000)] 
Fix stdio-common tests for GCC 12 -Waddress

My glibc bot shows failures building the testsuite with GCC mainline
across all architectures:

tst-vfprintf-width-prec.c: In function 'do_test':
tst-vfprintf-width-prec.c:90:16: error: the comparison will always evaluate as 'false' for the address of 'result' will never be NULL [-Werror=address]
   90 |     if (result == NULL)
      |                ^~
tst-vfprintf-width-prec.c:89:13: note: 'result' declared here
   89 |     wchar_t result[100];
      |             ^~~~~~

This is clearly a correct warning; the comparison against NULL is
clearly a cut-and-paste mistake from an earlier case in the test that
does use calloc.  Thus, remove the unnecessary check for NULL shown up
by the warning.

Similarly, two other tests have bogus comparisons against NULL; remove
those as well:

scanf14a.c:95:13: error: the comparison will always evaluate as 'false' for the address of 'fname' will never be NULL [-Werror=address]
   95 |   if (fname == NULL)
      |             ^~
scanf14a.c:93:8: note: 'fname' declared here
   93 |   char fname[strlen (tmpdir) + sizeof "/tst-scanf14.XXXXXX"];
      |        ^~~~~

scanf16a.c:125:13: error: the comparison will always evaluate as 'false' for the address of 'fname' will never be NULL [-Werror=address]
  125 |   if (fname == NULL)
      |             ^~
scanf16a.c:123:8: note: 'fname' declared here
  123 |   char fname[strlen (tmpdir) + sizeof "/tst-scanf16.XXXXXX"];
      |        ^~~~~

Tested with build-many-glibcs.py (GCC mainline) for aarch64-linux-gnu.

2 years agobenchtests: Building benchmarks as static executables
H.J. Lu [Fri, 30 Jul 2021 19:15:27 +0000 (12:15 -0700)] 
benchtests: Building benchmarks as static executables

Building benchmarks as static executables:
=========================================

To build benchmarks as static executables, on the build system, run:

  $ make STATIC-BENCHTESTS=yes bench-build

You can copy benchmark executables to another machine and run them
without copying the source nor build directories.

2 years agoelf: Avoid deadlock between pthread_create and ctors [BZ #28357]
Szabolcs Nagy [Wed, 15 Sep 2021 14:16:19 +0000 (15:16 +0100)] 
elf: Avoid deadlock between pthread_create and ctors [BZ #28357]

The fix for bug 19329 caused a regression such that pthread_create can
deadlock when concurrent ctors from dlopen are waiting for it to finish.
Use a new GL(dl_load_tls_lock) in pthread_create that is not taken
around ctors in dlopen.

The new lock is also used in __tls_get_addr instead of GL(dl_load_lock).

The new lock is held in _dl_open_worker and _dl_close_worker around
most of the logic before/after the init/fini routines.  When init/fini
routines are running then TLS is in a consistent, usable state.
In _dl_open_worker the new lock requires catching and reraising dlopen
failures that happen in the critical section.

The new lock is reinitialized in a fork child, to keep the existing
behaviour and it is kept recursive in case malloc interposition or TLS
access from signal handlers can retake it.  It is not obvious if this
is necessary or helps, but avoids changing the preexisting behaviour.

The new lock may be more appropriate for dl_iterate_phdr too than
GL(dl_load_write_lock), since TLS state of an incompletely loaded
module may be accessed.  If the new lock can replace the old one,
that can be a separate change.

Fixes bug 28357.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agotime: Ignore interval nanoseconds on tst-itimer
Adhemerval Zanella [Mon, 12 Jul 2021 21:50:22 +0000 (18:50 -0300)] 
time: Ignore interval nanoseconds on tst-itimer

Running the test on a 4.4 kernel within KVM, the precision used on
ITIMER_VIRTUAL and ITIMER_PROF seems to different than the one used
for ITIMER_REAL (it seems the same used for CLOCK_REALTIME_COARSE and
CLOCK_MONOTONIC_COARSE).  I did not see it on other kernels, for
instance 5.11 and 4.15.

To avoid trying to guess the resolution used, do not check the
nanosecond internal values for the specific timers.

Checked on i686-linux-gnu with a 4.4 kernel.

2 years agoio: Do not skip timestamps tests for 32-bit time_t
Adhemerval Zanella [Mon, 12 Jul 2021 20:35:06 +0000 (17:35 -0300)] 
io: Do not skip timestamps tests for 32-bit time_t

The first test in the set do not require 64-bit time_t support, so there
is no need to return UNSUPPORTED for the whole test.  The patch also adds
another test with arbitrary date prior y2038.

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

2 years agoUpdate to Unicode 14.0.0 [BZ #28390]
Mike FABIAN [Mon, 27 Sep 2021 13:27:36 +0000 (15:27 +0200)] 
Update to Unicode 14.0.0 [BZ #28390]

Unicode 14.0.0 Support: Character encoding, character type info, and
transliteration tables are all updated to Unicode 14.0.0, using
the generator scripts contributed by Mike FABIAN (Red Hat).

Total added characters in newly generated CHARMAP: 838
Total removed characters in newly generated WIDTH: 1
    (Characters not in WIDTH get width 1 by default, i.e. these have width 1 now.)
    removed: <U1734> 0 : eaw=N category=Mc bidi=L   name=HANUNOO SIGN PAMUDPOD
    That seems intentional, the character had category Mn (Mark, nonspacing) before
    and now has Mc (Mark, spacing combining)
Total changed characters in newly generated WIDTH: 0
Total added characters in newly generated WIDTH: 175

2 years agonptl: pthread_kill must send signals to a specific thread [BZ #28407]
Florian Weimer [Fri, 1 Oct 2021 16:16:41 +0000 (18:16 +0200)] 
nptl: pthread_kill must send signals to a specific thread [BZ #28407]

The choice between the kill vs tgkill system calls is not just about
the TID reuse race, but also about whether the signal is sent to the
whole process (and any thread in it) or to a specific thread.

This was caught by the openposix test suite:

  LTP: openposix test suite - FAIL: SIGUSR1 is member of new thread pendingset.
  <https://gitlab.com/cki-project/kernel-tests/-/issues/764>

Fixes commit 526c3cf11ee9367344b6b15d669e4c3cb461a2be ("nptl: Fix race
between pthread_kill and thread exit (bug 12889)").

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2 years agosupport: Add check for TID zero in support_wait_for_thread_exit
Florian Weimer [Fri, 1 Oct 2021 16:16:41 +0000 (18:16 +0200)] 
support: Add check for TID zero in support_wait_for_thread_exit

Some kernel versions (observed with kernel 5.14 and earlier) can list
"0" entries in /proc/self/task.  This happens when a thread exits
while the task list is being constructed.  Treat this entry as not
present, like the proposed kernel patch does:

[PATCH] procfs: Do not list TID 0 in /proc/<pid>/task
<https://lore.kernel.org/all/8735pn5dx7.fsf@oldenburg.str.redhat.com/>

Fixes commit 032d74eaf6179100048a5bf0ce942e97dc8b9a60 ("support: Add
support_wait_for_thread_exit").

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2 years agonptl: Add CLOCK_MONOTONIC support for PI mutexes
Adhemerval Zanella [Wed, 11 Aug 2021 18:17:41 +0000 (18:17 +0000)] 
nptl: Add CLOCK_MONOTONIC support for PI mutexes

Linux added FUTEX_LOCK_PI2 to support clock selection
(commit bf22a6976897977b0a3f1aeba6823c959fc4fdae).  With the new
flag we can now proper support CLOCK_MONOTONIC for
pthread_mutex_clocklock with Priority Inheritance.  If kernel
does not support, EINVAL is returned instead.

The difference is the futex operation will be issued and the kernel
will advertise the missing support (instead of hard-code error
return).

Checked on x86_64-linux-gnu and i686-linux-gnu on Linux 5.14, 5.11,
and 4.15.

2 years agosupport: Add support_mutex_pi_monotonic
Adhemerval Zanella [Wed, 11 Aug 2021 18:16:51 +0000 (18:16 +0000)] 
support: Add support_mutex_pi_monotonic

Returns true if Priority Inheritance support CLOCK_MONOTONIC.

2 years agonptl: Use FUTEX_LOCK_PI2 when available
Adhemerval Zanella [Fri, 25 Jun 2021 08:11:00 +0000 (10:11 +0200)] 
nptl: Use FUTEX_LOCK_PI2 when available

This patch uses the new futex PI operation provided by Linux v5.14
when it is required.

The futex_lock_pi64() is moved to futex-internal.c (since it used on
two different places and its code size might be large depending of the
kernel configuration) and clockid is added as an argument.

Co-authored-by: Kurt Kanzenbach <kurt@linutronix.de>
2 years agoLinux: Add FUTEX_LOCK_PI2
Kurt Kanzenbach [Fri, 25 Jun 2021 08:10:59 +0000 (10:10 +0200)] 
Linux: Add FUTEX_LOCK_PI2

Linux v5.14.0 introduced a new futex operation called FUTEX_LOCK_PI2.

This kernel feature can be used to implement
pthread_mutex_clocklock(MONOTONIC)/PI.

Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoAdd C2X _PRINTF_NAN_LEN_MAX
Joseph Myers [Thu, 30 Sep 2021 20:53:34 +0000 (20:53 +0000)] 
Add C2X _PRINTF_NAN_LEN_MAX

C2X adds a macro _PRINTF_NAN_LEN_MAX to <stdio.h>, giving the maximum
length of printf output for a NaN.  glibc never includes an
n-char-sequence in its printf output for NaNs, so the correct value
for glibc is 4 ("-nan" or "-NAN"); define the macro accordingly.

This patch makes the macro definition conditional on __GLIBC_USE
(ISOC2X), as is generally done with features from new standard
versions.  The name is in the implementation namespace for older
standards, so it would also be possible to define it unconditionally.

Tested for x86_64.

2 years agoAdd exp10 macro to <tgmath.h> (bug 26108)
Joseph Myers [Thu, 30 Sep 2021 20:40:34 +0000 (20:40 +0000)] 
Add exp10 macro to <tgmath.h> (bug 26108)

glibc has had exp10 functions since long before they were
standardized; now they are standardized in TS 18661-4 and C2X, they
are also specified there to have a corresponding type-generic macro.
Add one to <tgmath.h>, so fixing bug 26108.

glibc doesn't have other functions from TS 18661-4 yet, but when
added, it will be natural to add the type-generic macro for each
function family at the same time as the functions.

Tested for x86_64.

2 years agoelf: Replace nsid with args.nsid [BZ #27609]
H.J. Lu [Thu, 30 Sep 2021 17:29:17 +0000 (10:29 -0700)] 
elf: Replace nsid with args.nsid [BZ #27609]

commit ec935dea6332cb22f9881cd1162bad156173f4b0
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Apr 24 22:31:15 2020 +0200

    elf: Implement __libc_early_init

has

@@ -856,6 +876,11 @@ no more namespaces available for dlmopen()"));
   /* See if an error occurred during loading.  */
   if (__glibc_unlikely (exception.errstring != NULL))
     {
+      /* Avoid keeping around a dangling reference to the libc.so link
+   map in case it has been cached in libc_map.  */
+      if (!args.libc_already_loaded)
+  GL(dl_ns)[nsid].libc_map = NULL;
+

do_dlopen calls _dl_open with nsid == __LM_ID_CALLER (-2), which calls
dl_open_worker with args.nsid = nsid.  dl_open_worker updates args.nsid
if it is __LM_ID_CALLER.  After dl_open_worker returns, it is wrong to
use nsid.

Replace nsid with args.nsid after dl_open_worker returns.  This fixes
BZ #27609.

2 years agoAdd missing braces to bsearch inline implementation [BZ #28400]
Florian Weimer [Thu, 30 Sep 2021 16:44:06 +0000 (18:44 +0200)] 
Add missing braces to bsearch inline implementation [BZ #28400]

GCC treats the pragma as a statement, so that the else branch only
consists of the pragma, not the return statement.

Fixes commit a725ff1de965f4cc4f36a7e8ae795d40ca0350d7 ("Suppress
-Wcast-qual warnings in bsearch").

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoUpdate alpha libm-test-ulps
Adhemerval Zanella [Thu, 30 Sep 2021 12:06:03 +0000 (09:06 -0300)] 
Update alpha libm-test-ulps

2 years agoSuppress -Wcast-qual warnings in bsearch
Jonathan Wakely [Wed, 19 May 2021 15:48:19 +0000 (16:48 +0100)] 
Suppress -Wcast-qual warnings in bsearch

The first cast to (void *) is redundant but should be (const void *)
anyway, because that's the type of the lvalue being assigned to.

The second cast is necessary and intentionally not const-correct, so
tell the compiler not to warn about it.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 years agoelf: Copy l_addr/l_ld when adding ld.so to a new namespace
H.J. Lu [Wed, 18 Aug 2021 02:36:04 +0000 (19:36 -0700)] 
elf: Copy l_addr/l_ld when adding ld.so to a new namespace

When add ld.so to a new namespace, we don't actually load ld.so.  We
create a new link map and refers the real one for almost everything.
Copy l_addr and l_ld from the real ld.so link map to avoid GDB warning:

warning: .dynamic section for ".../elf/ld-linux-x86-64.so.2" is not at the expected address (wrong library or version mismatch?)

when handling shared library loaded by dlmopen.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agopowerpc: Fix unrecognized instruction errors with recent binutils
Paul A. Clarke [Sat, 25 Sep 2021 14:57:15 +0000 (09:57 -0500)] 
powerpc: Fix unrecognized instruction errors with recent binutils

Recent versions of binutils (with commit
b25f942e18d6ecd7ec3e2d2e9930eb4f996c258a) stopped preserving "sticky"
options across a base `.machine` directive, nullifying the use of
passing "-many" through GCC to the assembler.  As a result, some
instructions which were recognized even under older, more stringent
`.machine` directives become unrecognized instructions in that
context.

In `sysdeps/powerpc/tst-set_ppr.c`, the use of the `mfppr32` extended
mnemonic became unrecognized, as the default compilation with GCC for
32bit powerpc adds a `.machine ppc` in the resulting assembly, so the
command line option `-Wa,-many` is essentially ignored, and the ISA 2.06
instructions and mnemonics, like `mfppr32`, are unrecognized.

The compilation of `sysdeps/powerpc/tst-set_ppr.c` fails with:
Error: unrecognized opcode: `mfppr32'

Add appropriate `.machine` directives in the assembly to bracket the
`mfppr32` instruction.

Part of a 2019 fix (commit 9250e6610fdb0f3a6f238d2813e319a41fb7a810) to
the above test's Makefile to add `-many` to the compilation when GCC
itself stopped passing `-many` to the assember no longer has any effect,
so remove that.

Reported-by: Joseph Myers <joseph@codesourcery.com>
2 years agoDo not declare fmax, fmin _FloatN, _FloatNx versions for C2X
Joseph Myers [Wed, 29 Sep 2021 18:20:32 +0000 (18:20 +0000)] 
Do not declare fmax, fmin _FloatN, _FloatNx versions for C2X

At the last WG14 meeting,
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2711.htm> was
accepted, which places more emphasis on the new fmaximum / fminimum
functions and less on the old fmax / fmin functions.  Some of the
changes are to examples, notes or otherwise don't require
implementation changes.  However, the changes include removing the
_FloatN / _FloatNx versions of the fmax and fmin functions that came
from TS 18661-3.

Thus, those function versions should only be declared under similar
conditions to the _FloatN / _FloatNx versions of fmaxmag and fminmag:
for _GNU_SOURCE and pre-C2X use of __STDC_WANT_IEC_60559_TYPES_EXT__,
but not for C2X without _GNU_SOURCE.

In turn this requires a tgmath.h change so that the corresponding
tgmath.h macros, for C2X with __STDC_WANT_IEC_60559_TYPES_EXT__ but
without _GNU_SOURCE, don't try to use function variants that aren't
declared.  (That issue doesn't arise for the tgmath.h macros for
fmaxmag and fminmag, because those aren't defined at all in those
circumstances unless __STDC_WANT_IEC_60559_BFP_EXT__ (from TS 18661-1
and not specified at all by C2X) is also defined, and in that case the
_FloatN / _FloatNx versions of fmaxmag and fminmag get declared - this
is only ever an issue when it's possible for some functions
corresponding to a type-generic-macro to be declared, and for _FloatN
/ _FloatNx functions in general to be declared, but without the
_FloatN / _FloatNx functions corresponding to that particular macro
being declared.)

Tested for x86_64.

2 years agoDo not define tgmath.h fmaxmag, fminmag macros for C2X (bug 28397)
Joseph Myers [Wed, 29 Sep 2021 17:38:32 +0000 (17:38 +0000)] 
Do not define tgmath.h fmaxmag, fminmag macros for C2X (bug 28397)

C2X does not include fmaxmag and fminmag.  When I updated feature test
macro handling accordingly (commit
858045ad1c5ac1682288bbcb3676632b97a21ddf, "Update floating-point
feature test macro handling for C2X", included in 2.34), I missed
updating tgmath.h so it doesn't define the corresponding type-generic
macros unless __STDC_WANT_IEC_60559_BFP_EXT__ is defined; I've now
reported this as bug 28397.  Adjust the conditionals in tgmath.h
accordingly.

Tested for x86_64.

2 years agoAdd fmaximum, fminimum functions
Joseph Myers [Tue, 28 Sep 2021 23:31:35 +0000 (23:31 +0000)] 
Add fmaximum, fminimum functions

C2X adds new <math.h> functions for floating-point maximum and
minimum, corresponding to the new operations that were added in IEEE
754-2019 because of concerns about the old operations not being
associative in the presence of signaling NaNs.  fmaximum and fminimum
handle NaNs like most <math.h> functions (any NaN argument means the
result is a quiet NaN).  fmaximum_num and fminimum_num handle both
quiet and signaling NaNs the way fmax and fmin handle quiet NaNs (if
one argument is a number and the other is a NaN, return the number),
but still raise "invalid" for a signaling NaN argument, making them
exceptions to the normal rule that a function with a floating-point
result raising "invalid" also returns a quiet NaN.  fmaximum_mag,
fminimum_mag, fmaximum_mag_num and fminimum_mag_num are corresponding
functions returning the argument with greatest or least absolute
value.  All these functions also treat +0 as greater than -0.  There
are also corresponding <tgmath.h> type-generic macros.

Add these functions to glibc.  The implementations use type-generic
templates based on those for fmax, fmin, fmaxmag and fminmag, and test
inputs are based on those for those functions with appropriate
adjustments to the expected results.  The RISC-V maintainers might
wish to add optimized versions of fmaximum_num and fminimum_num (for
float and double), since RISC-V (F extension version 2.2 and later)
provides instructions corresponding to those functions - though it
might be at least as useful to add architecture-independent built-in
functions to GCC and teach the RISC-V back end to expand those
functions inline, which is what you generally want for functions that
can be implemented with a single instruction.

Tested for x86_64 and x86, and with build-many-glibcs.py.

2 years agoLinux: Simplify __opensock and fix race condition [BZ #28353]
Florian Weimer [Tue, 28 Sep 2021 16:55:49 +0000 (18:55 +0200)] 
Linux: Simplify __opensock and fix race condition [BZ #28353]

AF_NETLINK support is not quite optional on modern Linux systems
anymore, so it is likely that the first attempt will always succeed.
Consequently, there is no need to cache the result.  Keep AF_UNIX
and the Internet address families as a fallback, for the rare case
that AF_NETLINK is missing.  The other address families previously
probed are totally obsolete be now, so remove them.

Use this simplified version as the generic implementation, disabling
Netlink support as needed.

2 years agopthread/tst-cancel28: Fix barrier re-init race condition
Stafford Horne [Sat, 25 Sep 2021 08:02:06 +0000 (17:02 +0900)] 
pthread/tst-cancel28: Fix barrier re-init race condition

When running this test on the OpenRISC port I am working on this test
fails with a timeout.  The test passes when being straced or debugged.
Looking at the code there seems to be a race condition in that:

  1 main thread: calls xpthread_cancel
  2 sub thread : receives cancel signal
  3 sub thread : cleanup routine waits on barrier
  4 main thread: re-inits barrier
  5 main thread: waits on barrier

After getting to 5 the main thread and sub thread wait forever as the 2
barriers are no longer the same.

Removing the barrier re-init seems to fix this issue.  Also, the barrier
does not need to be reinitialized as that is done by default.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agopowerpc: Delete unneeded ELF_MACHINE_BEFORE_RTLD_RELOC
Fangrui Song [Mon, 27 Sep 2021 17:12:50 +0000 (10:12 -0700)] 
powerpc: Delete unneeded ELF_MACHINE_BEFORE_RTLD_RELOC

Reviewed-by: Raphael M Zinsly <rzinsly@linux.ibm.com>
2 years agoposix: Remove spawni.c
Adhemerval Zanella [Tue, 15 Jun 2021 00:15:51 +0000 (21:15 -0300)] 
posix: Remove spawni.c

Although it provide an alternate implementation that communicates
using pipe() instead of shared memory, no port uses and it adds extra
burden for posix_spawn() extensions.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 years agoDisable symbol hack in libc_nonshared.a
H.J. Lu [Thu, 23 Sep 2021 18:08:11 +0000 (11:08 -0700)] 
Disable symbol hack in libc_nonshared.a

Don't reference __GI_memmove, __GI_memset, __GI_memcpy, __divdi3_internal,
__udivdi3_internal and __moddi3_internal in libc_nonshared.a.

2 years agolinux: Revert the use of sched_getaffinity on get_nproc (BZ #28310)
Adhemerval Zanella [Mon, 6 Sep 2021 17:19:51 +0000 (14:19 -0300)] 
linux: Revert the use of sched_getaffinity on get_nproc (BZ #28310)

The use of sched_getaffinity on get_nproc and
sysconf (_SC_NPROCESSORS_ONLN) done in 903bc7dcc2acafc40 (BZ #27645)
breaks the top command in common hypervisor configurations and also
other monitoring tools.

The main issue using sched_getaffinity changed the symbols semantic
from system-wide scope of online CPUs to per-process one (which can
be changed with kernel cpusets or book parameters in VM).

This patch reverts mostly of the 903bc7dcc2acafc40, with the
exceptions:

  * No more cached values and atomic updates, since they are inherent
    racy.

  * No /proc/cpuinfo fallback, since /proc/stat is already used and
    it would require to revert more arch-specific code.

  * The alloca is replace with a static buffer of 1024 bytes.

So the implementation first consult the sysfs, and fallbacks to procfs.

Checked on x86_64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 years agolinux: Simplify get_nprocs
Adhemerval Zanella [Mon, 6 Sep 2021 15:28:24 +0000 (12:28 -0300)] 
linux: Simplify get_nprocs

This patch simplifies the memory allocation code and uses the sched
routines instead of reimplement it.  This still uses a stack
allocation buffer, so it can be used on malloc initialization code.

Linux currently supports at maximum of 4096 cpus for most architectures:

$ find -iname Kconfig | xargs git grep -A10 -w NR_CPUS | grep -w range
arch/alpha/Kconfig- range 2 32
arch/arc/Kconfig- range 2 4096
arch/arm/Kconfig- range 2 16 if DEBUG_KMAP_LOCAL
arch/arm/Kconfig- range 2 32 if !DEBUG_KMAP_LOCAL
arch/arm64/Kconfig- range 2 4096
arch/csky/Kconfig- range 2 32
arch/hexagon/Kconfig- range 2 6 if SMP
arch/ia64/Kconfig- range 2 4096
arch/mips/Kconfig- range 2 256
arch/openrisc/Kconfig- range 2 32
arch/parisc/Kconfig- range 2 32
arch/riscv/Kconfig- range 2 32
arch/s390/Kconfig- range 2 512
arch/sh/Kconfig- range 2 32
arch/sparc/Kconfig- range 2 32 if SPARC32
arch/sparc/Kconfig- range 2 4096 if SPARC64
arch/um/Kconfig- range 1 1
arch/x86/Kconfig-# [NR_CPUS_RANGE_BEGIN ... NR_CPUS_RANGE_END] range.
arch/x86/Kconfig- range NR_CPUS_RANGE_BEGIN NR_CPUS_RANGE_END
arch/xtensa/Kconfig- range 2 32

With x86 supporting 8192:

arch/x86/Kconfig
 976 config NR_CPUS_RANGE_END
 977         int
 978         depends on X86_64
 979         default 8192 if  SMP && CPUMASK_OFFSTACK
 980         default  512 if  SMP && !CPUMASK_OFFSTACK
 981         default    1 if !SMP

So using a maximum of 32k cpu should cover all cases (and I would
expect once we start to have many more CPUs that Linux would provide
a more straightforward way to query for such information).

A test is added to check if sched_getaffinity can successfully return
with large buffers.

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

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 years agomisc: Add __get_nprocs_sched
Adhemerval Zanella [Mon, 6 Sep 2021 15:22:54 +0000 (12:22 -0300)] 
misc: Add __get_nprocs_sched

This is an internal function meant to return the number of avaliable
processor where the process can scheduled, different than the
__get_nprocs which returns a the system available online CPU.

The Linux implementation currently only calls __get_nprocs(), which
in tuns calls sched_getaffinity.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 years agohtl: Fix sigset of main thread
Samuel Thibault [Sun, 26 Sep 2021 00:40:26 +0000 (02:40 +0200)] 
htl: Fix sigset of main thread

d482ebfa6785 ('htl: Keep thread signals blocked during its initialization')
fixed not letting signals get delivered too early during thread creation,
but it also affected the main thread, thus making it block signals by
default.  We need to just let the main thread sigset as it is.

2 years agohtl: make pthread_sigstate read/write set/oset outside sigstate section
Samuel Thibault [Sat, 25 Sep 2021 23:02:54 +0000 (01:02 +0200)] 
htl: make pthread_sigstate read/write set/oset outside sigstate section

so that if a segfault occurs, the handler can run fine.

2 years agoAvoid warning: overriding recipe for .../tst-ro-dynamic-mod.so
H.J. Lu [Fri, 24 Sep 2021 15:56:42 +0000 (08:56 -0700)] 
Avoid warning: overriding recipe for .../tst-ro-dynamic-mod.so

Add tst-ro-dynamic-mod to modules-names-nobuild to avoid

../Makerules:767: warning: ignoring old recipe for target '.../elf/tst-ro-dynamic-mod.so'

This updates BZ #28340 fix.

2 years agobenchtests: Improve reliability of memcmp benchmarks
Noah Goldstein [Sat, 18 Sep 2021 21:13:34 +0000 (16:13 -0500)] 
benchtests: Improve reliability of memcmp benchmarks

No bug. Remove reallocation of bufs between implementation tests. Move
initialization outside of foreach implementation test loop. Increase
iteration count.

Generally before this commit was seeing a great deal of variability
between runs. The goal of this commit is to make the results more
reliable.

Benchtests build and bench-memcmp succeeding.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
2 years agoDefine __STDC_IEC_60559_BFP__ and __STDC_IEC_60559_COMPLEX__
Joseph Myers [Fri, 24 Sep 2021 20:11:56 +0000 (20:11 +0000)] 
Define __STDC_IEC_60559_BFP__ and __STDC_IEC_60559_COMPLEX__

TS 18661-1 and C2X specify predefined macros __STDC_IEC_60559_BFP__
and __STDC_IEC_60559_COMPLEX__, making __STDC_IEC_559__ and
__STDC_IEC_559_COMPLEX__ obsolescent (but still included in the
standard).  Now that we have all the functions from TS 18661-1, define
these macros in stdc-predef.h, under the same conditions in which the
older macros are defined, since support for the floating-point
features in TS 18661-1 is now at the same level as that for those in
C11 and before (all library functions and other library APIs present,
but no standard pragma support).

The macros are defined for now with their TS 18661-1 values.  C2X will
give them new values (listed as yyyymmL in the working drafts until
the final standard), at which point there will be the question of what
value to use in stdc-predef.h (where it could depend on
__STDC_VERSION__, but not on feature test macros defined by the user).
My inclination then would be to use the C2X value unconditionally
rather than using an older value to indicate TS support, and only have
any C standard version conditionals for the value when subsequent C
standard versions define further values.

(Note that I'm also inclined, when we implement the C2X change to the
return types of fromfp functions, to make that change unconditional
much like the change made to the types of totalorder functions, with
the old version only supported with compat symbols for already-linked
programs and not as an API for newly built objects.  So using the C2X
value would also accurately reflect not supporting the versions of
APIs in the TS where those ended up being incompatible with the first
version actually added to the standard.)

Tested for x86_64.

2 years agobuild-many-glibcs.py: add powerpc64le glibc variant without multiarch
Paul E. Murphy [Thu, 23 Sep 2021 20:25:00 +0000 (15:25 -0500)] 
build-many-glibcs.py: add powerpc64le glibc variant without multiarch

This configuration tests the float128 to ldouble128 redirect support
on powerpc64le without the extra wrappers needed to support ifunc
on this target.

2 years agoFix sysdeps/x86/fpu/s_ffma.c for 32-bit FMA processor case
Joseph Myers [Fri, 24 Sep 2021 17:59:22 +0000 (17:59 +0000)] 
Fix sysdeps/x86/fpu/s_ffma.c for 32-bit FMA processor case

It turns out the __SSE2_MATH__ conditional in sysdeps/x86/fpu/s_ffma.c
does not cover all cases where the x86 fenv_private.h macros might
manipulate one of the SSE and 387 floating-point state, while the
actual fma implementation uses the other.  Specifically, in the 32-bit
case, with a compiler not defaulting to -mfpmath=sse, but testing on a
processor with hardware FMA support, the multiarch fma function
implementations will end up using SSE, while the fenv_private.h macros
will use the 387 state for double.  Change the conditional to use the
default macros rather than the optimized ones in all cases except when
the compiler inlines an fma instruction (in which case, since all
those instructions are SSE instructions and -mfpmath=sse must be in
effect for them to be inlined, the optimized macros will only use the
SSE state and it's OK for them to only use the SSE state).

Tested for x86_64 and x86.  H.J. reports in
<https://sourceware.org/pipermail/libc-alpha/2021-September/131367.html>
that it fixes the problems he observed.

2 years agoLinux: Avoid closing -1 on failure in __closefrom_fallback
Florian Weimer [Fri, 24 Sep 2021 17:51:41 +0000 (19:51 +0200)] 
Linux: Avoid closing -1 on failure in __closefrom_fallback

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoi386: Port elf_machine_{load_address,dynamic} from x86-64
Fangrui Song [Fri, 24 Sep 2021 16:36:32 +0000 (09:36 -0700)] 
i386: Port elf_machine_{load_address,dynamic} from x86-64

This drops reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time
address of _DYNAMIC.

The code sequence length does not change.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoaarch64: Disable A64FX memcpy/memmove BTI unconditionally
Naohiro Tamura [Fri, 24 Sep 2021 07:49:59 +0000 (07:49 +0000)] 
aarch64: Disable A64FX memcpy/memmove BTI unconditionally

This patch disables A64FX memcpy/memmove BTI instruction insertion
unconditionally such as A64FX memset patch [1] for performance.

[1] commit 07b427296b8d59f439144029d9a948f6c1ce0a31

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2 years agoxsysconf: Only fail on error results and errno set
Stafford Horne [Fri, 24 Sep 2021 02:29:33 +0000 (11:29 +0900)] 
xsysconf: Only fail on error results and errno set

When testing nptl/tst-pthread-attr-affinity-fail fails with:

    error: xsysconf.c:33: sysconf (83): Cannot allocate memory
    error: 1 test failures

This happens as xsysconf checks the errno after running sysconf.
Internally the sysconf request for _SC_NPROCESSORS_CONF on linux
allocates memory.  But there is a problem, even though malloc succeeds
errno is getting set to ENOMEM.

POSIX allows successful calls to clobber errno.  So xsysconf just
checking errno is wrong.  Fix xsysconf by only failing if we have an
error result and errno is set.

2 years agopowerpc64le: Avoid conflicting types for f64xfmaf128 when IFUNC is not used
Tulio Magno Quites Machado Filho [Thu, 23 Sep 2021 17:04:21 +0000 (14:04 -0300)] 
powerpc64le: Avoid conflicting types for f64xfmaf128 when IFUNC is not used

Avoid defining f64xfmaf128 twice when building s_fmaf128.c.
This can be reproduced on powerpc64le whenever f128 functions do not
have IFUNC enabled, e.g. using "--with-cpu=power8 --disable-multi-arch", or
when using "-with-cpu=power9".

Fixes: b3f27d8150d4f ("Add narrowing fma functions")
2 years agoFix ffma use of round-to-odd on x86
Joseph Myers [Thu, 23 Sep 2021 21:18:31 +0000 (21:18 +0000)] 
Fix ffma use of round-to-odd on x86

On 32-bit x86 with -mfpmath=sse, and on x86_64 with
--disable-multi-arch, the tests of ffma and its aliases (fma narrowing
from binary64 to binary32) fail.  This is probably the issue reported
by H.J. in
<https://sourceware.org/pipermail/libc-alpha/2021-September/131277.html>.

The problem is the use of fenv_private.h macros in the round-to-odd
implementation.  Those macros are set up to manipulate only one of the
SSE and 387 floating-point state, whichever is relevant for the type
indicated by the suffix on the macro name.  But x86 configurations
sometimes use the ldbl-96 implementation of binary64 fma (that's where
--disable-multi-arch is relevant for x86_64: it causes the ldbl-96
implementation to be used, instead of an IFUNC implementation that
falls back to the dbl-64 version), contrary to the expectations of
those macros for functions operating on double when __SSE2_MATH__ is
defined.

This can be addressed by using the default versions of those macros
(giving x86 its own version of s_ffma.c), as is done for the *f128
macro variants where it depends on the details of how GCC was
configured when building libgcc which floating-point state is affected
by _Float128 arithmetic.  The issue only applies when __SSE2_MATH__ is
defined, and doesn't apply when __FP_FAST_FMA is defined (because in
that case, fma will be inlined by the compiler, meaning it's
definitely an SSE operation; for the same reason, this is not an issue
for narrowing sqrt, as hardware sqrt is always inlined in that
implementation for x86), but in other cases it's safest to use the
default versions of the fenv_private.h macros to ensure things work
whichever fma implementation is used.

Tested for x86_64 (with and without --disable-multi-arch) and x86
(with and without -mfpmath=sse).

2 years agovfprintf: Unify argument handling in process_arg
Florian Weimer [Thu, 23 Sep 2021 09:16:02 +0000 (11:16 +0200)] 
vfprintf: Unify argument handling in process_arg

Instead of checking a pointer argument for NULL, use helper macros
defined differently in the non-positional and positional cases.
This avoids frequent conditional checks and a GCC 12 warning
about comparing pointers against NULL which cannot be NULL.

2 years agovfprintf: Handle floating-point cases outside of process_arg macro
Florian Weimer [Thu, 23 Sep 2021 09:16:02 +0000 (11:16 +0200)] 
vfprintf: Handle floating-point cases outside of process_arg macro

A lot of the code is unique to the positional and non-positional
code.  Also unify the decimal and hexadecimal cases via the new
helper function __printf_fp_spec.

2 years agonptl: Avoid setxid deadlock with blocked signals in thread exit [BZ #28361]
Florian Weimer [Thu, 23 Sep 2021 07:55:54 +0000 (09:55 +0200)] 
nptl: Avoid setxid deadlock with blocked signals in thread exit [BZ #28361]

As part of the fix for bug 12889, signals are blocked during
thread exit, so that application code cannot run on the thread that
is about to exit.  This would cause problems if the application
expected signals to be delivered after the signal handler revealed
the thread to still exist, despite pthread_kill can no longer be used
to send signals to it.  However, glibc internally uses the SIGSETXID
signal in a way that is incompatible with signal blocking, due to the
way the setxid handshake delays thread exit until the setxid operation
has completed.  With a blocked SIGSETXID, the handshake can never
complete, causing a deadlock.

As a band-aid, restore the previous handshake protocol by not blocking
SIGSETXID during thread exit.

The new test sysdeps/pthread/tst-pthread-setuid-loop.c is based on
a downstream test by Martin Osvald.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2 years agoAdd narrowing fma functions
Joseph Myers [Wed, 22 Sep 2021 21:25:31 +0000 (21:25 +0000)] 
Add narrowing fma functions

This patch adds the narrowing fused multiply-add functions from TS
18661-1 / TS 18661-3 / C2X to glibc's libm: ffma, ffmal, dfmal,
f32fmaf64, f32fmaf32x, f32xfmaf64 for all configurations; f32fmaf64x,
f32fmaf128, f64fmaf64x, f64fmaf128, f32xfmaf64x, f32xfmaf128,
f64xfmaf128 for configurations with _Float64x and _Float128;
__f32fmaieee128 and __f64fmaieee128 aliases in the powerpc64le case
(for calls to ffmal and dfmal when long double is IEEE binary128).
Corresponding tgmath.h macro support is also added.

The changes are mostly similar to those for the other narrowing
functions previously added, especially that for sqrt, so the
description of those generally applies to this patch as well.  As with
sqrt, I reused the same test inputs in auto-libm-test-in as for
non-narrowing fma rather than adding extra or separate inputs for
narrowing fma.  The tests in libm-test-narrow-fma.inc also follow
those for non-narrowing fma.

The non-narrowing fma has a known bug (bug 6801) that it does not set
errno on errors (overflow, underflow, Inf * 0, Inf - Inf).  Rather
than fixing this or having narrowing fma check for errors when
non-narrowing does not (complicating the cases when narrowing fma can
otherwise be an alias for a non-narrowing function), this patch does
not attempt to check for errors from narrowing fma and set errno; the
CHECK_NARROW_FMA macro is still present, but as a placeholder that
does nothing, and this missing errno setting is considered to be
covered by the existing bug rather than needing a separate open bug.
missing-errno annotations are duly added to many of the
auto-libm-test-in test inputs for fma.

This completes adding all the new functions from TS 18661-1 to glibc,
so will be followed by corresponding stdc-predef.h changes to define
__STDC_IEC_60559_BFP__ and __STDC_IEC_60559_COMPLEX__, as the support
for TS 18661-1 will be at a similar level to that for C standard
floating-point facilities up to C11 (pragmas not implemented, but
library functions done).  (There are still further changes to be done
to implement changes to the types of fromfp functions from N2548.)

Tested as followed: natively with the full glibc testsuite for x86_64
(GCC 11, 7, 6) and x86 (GCC 11); with build-many-glibcs.py with GCC
11, 7 and 6; cross testing of math/ tests for powerpc64le, powerpc32
hard float, mips64 (all three ABIs, both hard and soft float).  The
different GCC versions are to cover the different cases in tgmath.h
and tgmath.h tests properly (GCC 6 has _Float* only as typedefs in
glibc headers, GCC 7 has proper _Float* support, GCC 8 adds
__builtin_tgmath).

2 years agold.so: Replace DL_RO_DYN_SECTION with dl_relocate_ld [BZ #28340]
H.J. Lu [Thu, 16 Sep 2021 15:15:29 +0000 (08:15 -0700)] 
ld.so: Replace DL_RO_DYN_SECTION with dl_relocate_ld [BZ #28340]

We can't relocate entries in dynamic section if it is readonly:

1. Add a l_ld_readonly field to struct link_map to indicate if dynamic
section is readonly and set it based on p_flags of PT_DYNAMIC segment.
2. Replace DL_RO_DYN_SECTION with dl_relocate_ld to decide if dynamic
section should be relocated.
3. Remove DL_RO_DYN_TEMP_CNT.
4. Don't use a static dynamic section to make readonly dynamic section
in vDSO writable.
5. Remove the temp argument from elf_get_dynamic_info.

This fixes BZ #28340.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agoAdjust new narrowing div/mul tests for IBM long double, update powerpc ULPs
Joseph Myers [Wed, 22 Sep 2021 12:35:44 +0000 (12:35 +0000)] 
Adjust new narrowing div/mul tests for IBM long double, update powerpc ULPs

Testing for powerpc shows some of the new narrowing div/mul tests need
XFAILing for IBM long double and some ULPs updates are needed for
those tests.

2 years agoMention today's regex merge in SHARED-FILES
Paul Eggert [Wed, 22 Sep 2021 00:53:13 +0000 (17:53 -0700)] 
Mention today's regex merge in SHARED-FILES

2 years agoFix f64xdivf128, f64xmulf128 spurious underflows (bug 28358)
Joseph Myers [Tue, 21 Sep 2021 21:54:37 +0000 (21:54 +0000)] 
Fix f64xdivf128, f64xmulf128 spurious underflows (bug 28358)

As described in bug 28358, the round-to-odd computations used in the
libm functions that round their results to a narrower format can yield
spurious underflow exceptions in the following circumstances: the
narrowing only narrows the precision of the type and not the exponent
range (i.e., it's narrowing _Float128 to _Float64x on x86_64, x86 or
ia64), the architecture does after-rounding tininess detection (which
applies to all those architectures), the result is inexact, tiny
before rounding but not tiny after rounding (with the chosen rounding
mode) for _Float64x (which is possible for narrowing mul, div and fma,
not for narrowing add, sub or sqrt), so the underflow exception
resulting from the toward-zero computation in _Float128 is spurious
for _Float64x.

Fixed by making ROUND_TO_ODD call feclearexcept (FE_UNDERFLOW) in the
problem cases (as indicated by an extra argument to the macro); there
is never any need to preserve underflow exceptions from this part of
the computation, because the conversion of the round-to-odd value to
the narrower type will underflow in exactly the cases in which the
function should raise that exception, but it may be more efficient to
avoid the extra manipulation of the floating-point environment when
not needed.

Tested for x86_64 and x86, and with build-many-glibcs.py.

2 years agoregex: copy back from Gnulib
Paul Eggert [Tue, 21 Sep 2021 14:47:45 +0000 (07:47 -0700)] 
regex: copy back from Gnulib

Copy regex-related files back from Gnulib, to fix a problem with
static checking of regex calls noted by Martin Sebor.  This merges the
following changes:

* New macro __attribute_nonnull__ in misc/sys/cdefs.h, for use later
when copying other files back from Gnulib.

* Use __GNULIB_CDEFS instead of __GLIBC__ when deciding
whether to include bits/wordsize.h etc.

* Avoid duplicate entries in epsilon closure table.

* New regex.h macro _REGEX_NELTS to let regexec say that its pmatch
arg should contain nmatch elts.  Use that for regexec, instead of
__attr_access (which is incorrect).

* New regex.h macro _Attr_access_ which is like __attr_access except
portable to non-glibc platforms.

* Add some DEBUG_ASSERTs to pacify gcc -fanalyzer and to catch
recently-fixed performance bugs if they recur.

* Add Gnulib-specific stuff to port the dynarray- and lock-using parts
of regex code to non-glibc platforms.

* Fix glibc bug 11053.

* Avoid some undefined behavior when popping an empty fail stack.

2 years agonptl: Fix type of pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np...
Florian Weimer [Tue, 21 Sep 2021 05:12:56 +0000 (07:12 +0200)] 
nptl: Fix type of pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np (bug 28036)

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2 years agopowerpc: Fix unrecognized instruction errors with recent GCC
Paul A. Clarke [Tue, 14 Sep 2021 18:13:33 +0000 (13:13 -0500)] 
powerpc: Fix unrecognized instruction errors with recent GCC

Recent binutils commit b25f942e18d6ecd7ec3e2d2e9930eb4f996c258a
changes the behavior of `.machine` directives to override, rather
than augment, the base CPU. This can result in _reduced_ functionality
when, for example, compiling for default machine "power8", but explicitly
asking for ".machine power5", which loses Altivec instructions.

In tst-ucontext-ppc64-vscr.c, while the instructions provoking the new
error messages are bracketed by ".machine power5", which is ostensibly
Power ISA 2.03 (POWER5), the POWER5 processor did not support the
VSX subset, so these instructions are not recognized as "power5".

Error: unrecognized opcode: `vspltisb'
Error: unrecognized opcode: `vpkuwus'
Error: unrecognized opcode: `mfvscr'
Error: unrecognized opcode: `stvx'

Manually adding the VSX subset via ".machine altivec" is sufficient.

Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
2 years agoelf: Include <sysdep.h> in elf/dl-debug-symbols.S
Florian Weimer [Mon, 20 Sep 2021 13:50:00 +0000 (15:50 +0200)] 
elf: Include <sysdep.h> in elf/dl-debug-symbols.S

This is necessary to generate assembler marker sections on some
targets.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2 years agonptl: pthread_kill needs to return ESRCH for old programs (bug 19193)
Florian Weimer [Mon, 20 Sep 2021 12:56:08 +0000 (14:56 +0200)] 
nptl: pthread_kill needs to return ESRCH for old programs (bug 19193)

The fix for bug 19193 breaks some old applications which appear
to use pthread_kill to probe if a thread is still running, something
that is not supported by POSIX.

2 years agoExtend struct r_debug to support multiple namespaces [BZ #15971]
H.J. Lu [Wed, 18 Aug 2021 02:35:48 +0000 (19:35 -0700)] 
Extend struct r_debug to support multiple namespaces [BZ #15971]

Glibc does not provide an interface for debugger to access libraries
loaded in multiple namespaces via dlmopen.

The current rtld-debugger interface is described in the file:

elf/rtld-debugger-interface.txt

under the "Standard debugger interface" heading.  This interface only
provides access to the first link-map (LM_ID_BASE).

1. Bump r_version to 2 when multiple namespaces are used.  This triggers
the GDB bug:

https://sourceware.org/bugzilla/show_bug.cgi?id=28236

2. Add struct r_debug_extended to extend struct r_debug into a linked-list,
where each element correlates to an unique namespace.
3. Initialize the r_debug_extended structure.  Bump r_version to 2 for
the new namespace and add the new namespace to the namespace linked list.
4. Add _dl_debug_update to return the address of struct r_debug' of a
namespace.
5. Add a hidden symbol, _r_debug_extended, for struct r_debug_extended.
6. Provide the symbol, _r_debug, with size of struct r_debug, as an alias
of _r_debug_extended, for programs which reference _r_debug.

This fixes BZ #15971.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 years agoUse $(pie-default) with conformtest
Joseph Myers [Fri, 17 Sep 2021 19:24:14 +0000 (19:24 +0000)] 
Use $(pie-default) with conformtest

My glibc bot showed that my conformtest changes fail the build of the
conformtest execution tests for x86_64-linux-gnu-static-pie, because
linking the newly built object with the newly built libc and the
associated options normally used for linking requires it to be built
as PIE.  Add $(pie-default) to the compiler command used so that PIE
options are used when required.

There's a case for using the whole of $(CFLAGS-.o) (which includes
$(pie-default)), but that raises questions of any impact from using
optimization flags from CFLAGS in these tests.  So for now just use
$(pie-default) as the key part of $(CFLAGS-.o) that's definitely
needed.

Tested with build-many-glibcs.py for x86_64-linux-gnu-static-pie.

2 years agoRun conform/ tests using newly built libc
Joseph Myers [Fri, 17 Sep 2021 13:12:10 +0000 (13:12 +0000)] 
Run conform/ tests using newly built libc

Although the conform/ header tests are built using the headers of the
glibc under test, the execution tests from conformtest (a few tests of
the values of macros evaluating to string constants) are linked and
run with system libc, not the newly built libc.

Apart from preventing testing in cross environments, this can be a
problem even for native testing.  Specifically, it can be useful to do
native testing when building with a cross compiler that links with a
libc that is not the system libc; for example, on x86_64, you can test
all three ABIs that way if the kernel support is present, even if the
host OS lacks 32-bit or x32 libraries or they are older than the
libraries in the sysroot used by the compiler used to build glibc.
This works for almost all tests, but not for these conformtest tests.

Arrange for conformtest to link and run test programs similarly to
other tests, with consequent refactoring of various variables in
Makeconfig to allow passing relevant parts of the link-time command
lines down to conformtest.  In general, the parts of the link command
involving $@ or $^ are separated out from the parts that should be
passed to conformtest (the variables passed to conformtest still
involve various variables whose names involve $(@F), but those
variables simply won't be defined for the conformtest makefile rules
and I think their presence there is harmless).

This is also most of the support that would be needed to allow running
those tests of string constants for cross testing when test-wrapper is
defined.  That will also need changes to where conformtest.py puts the
test executables, so it puts them in the main object directory
(expected to be shared with a test system in cross testing) rather
than /tmp (not expected to be shared) as at present.

Tested for x86_64.

2 years agoposix: Fix attribute access mode on getcwd [BZ #27476]
Aurelien Jarno [Fri, 10 Sep 2021 17:39:35 +0000 (19:39 +0200)] 
posix: Fix attribute access mode on getcwd [BZ #27476]

There is a GNU extension that allows to call getcwd(NULL, >0). It is
described in the documentation, but also directly in the unistd.h
header, just above the declaration.

Therefore the attribute access mode added in commit 06febd8c6705
is not correct. Drop it.

2 years agoFix build-many-glibcs.py --strip for installed library renaming
Joseph Myers [Thu, 16 Sep 2021 14:08:05 +0000 (14:08 +0000)] 
Fix build-many-glibcs.py --strip for installed library renaming

The renaming of installed shared libraries to use the SONAME directly
rather than linking to a versioned name stopped build-many-glibcs.py
--strip (used to facilitate comparing binaries before and after
changes that aren't meant to change any generated code in installed
glibc shared libraries) from stripping most of the installed shared
libraries, because it stripped only the *.so names.  Fix it to strip
*.so* names instead and to detect the case of linker scripts using
grep instead of hardcoding particular files that are linker scripts.

Tested with build-many-glibcs.py --strip.

2 years agobenchtests: Fix validate_benchout.py exceptions
Naohiro Tamura [Thu, 16 Sep 2021 03:49:55 +0000 (09:19 +0530)] 
benchtests: Fix validate_benchout.py exceptions

This patch fixed validate_benchout.py two exceptions,
1) AttributeError
   if benchout_strings.schema.json is specified, and
2) json.decoder.JSONDecodeError
   if benchout file is not JSON.

$ ~/glibc/benchtests/scripts/validate_benchout.py bench-memset.out \
~/glibc/benchtests/scripts/benchout_strings.schema.json
Traceback (most recent call last):
  File "/home/naohirot/glibc/benchtests/scripts/validate_benchout.py", line 86, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/home/naohirot/glibc/benchtests/scripts/validate_benchout.py", line 69, in main
    bench.parse_bench(args[0], args[1])
  File "/home/naohirot/glibc/benchtests/scripts/import_bench.py", line 139, in parse_bench
    do_for_all_timings(bench, lambda b, f, v:
  File "/home/naohirot/glibc/benchtests/scripts/import_bench.py", line 107, in do_for_all_timings
    if 'timings' not in bench['functions'][func][k].keys():
AttributeError: 'str' object has no attribute 'keys'

$ ~/glibc/benchtests/scripts/validate_benchout.py bench-math-inlines.out \
~/glibc/benchtests/scripts/benchout_strings.schema.json
Traceback (most recent call last):
  File "/home/naohirot/glibc/benchtests/scripts/validate_benchout.py", line 86, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/home/naohirot/glibc/benchtests/scripts/validate_benchout.py", line 69, in main
    bench.parse_bench(args[0], args[1])
  File "/home/naohirot/glibc/benchtests/scripts/import_bench.py", line 137, in parse_bench
    bench = json.load(benchfile)
  File "/usr/lib/python3.6/json/__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 342, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 17 (char 16)

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agoelf: Remove THREAD_GSCOPE_IN_TCB
Sergey Bugaev [Wed, 15 Sep 2021 17:11:10 +0000 (20:11 +0300)] 
elf: Remove THREAD_GSCOPE_IN_TCB

All the ports now have THREAD_GSCOPE_IN_TCB set to 1. Remove all
support for !THREAD_GSCOPE_IN_TCB, along with the definition itself.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20210915171110.226187-4-bugaevc@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2 years agohtl: Reimplement GSCOPE
Sergey Bugaev [Wed, 15 Sep 2021 17:11:09 +0000 (20:11 +0300)] 
htl: Reimplement GSCOPE

This is a new implementation of GSCOPE which largely mirrors its NPTL
counterpart. Same as in NPTL, instead of a global flag shared between
threads, there is now a per-thread GSCOPE flag stored in each thread's
TCB. This makes entering and exiting a GSCOPE faster at the expense of
making THREAD_GSCOPE_WAIT () slower.

The largest win is the elimination of many redundant gsync_wake () RPC
calls; previously, even simplest programs would make dozens of fully
redundant gsync_wake () calls.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20210915171110.226187-3-bugaevc@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2 years agohtl: Move thread table to ld.so
Sergey Bugaev [Wed, 15 Sep 2021 17:11:08 +0000 (20:11 +0300)] 
htl: Move thread table to ld.so

The next commit is going to introduce a new implementation of
THREAD_GSCOPE_WAIT which needs to access the list of threads.
Since it must be usable from the dynamic laoder, we have to move
the symbols for the list of threads into the loader.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20210915171110.226187-2-bugaevc@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2 years agoRedirect fma calls to __fma in libm
Joseph Myers [Wed, 15 Sep 2021 22:57:35 +0000 (22:57 +0000)] 
Redirect fma calls to __fma in libm

include/math.h has a mechanism to redirect internal calls to various
libm functions, that can often be inlined by the compiler, to call
non-exported __* names for those functions in the case when the calls
aren't inlined, with the redirection being disabled when
NO_MATH_REDIRECT.  Add fma to the functions to which this mechanism is
applied.

At present, libm-internal fma calls (generally to __builtin_fma*
functions) are only done when it's known the call will be inlined,
with alternative code not relying on an fma operation being used in
the caller otherwise.  This patch is in preparation for adding the TS
18661 / C2X narrowing fma functions to glibc; it will be natural for
the narrowing function implementations to call the underlying fma
functions unconditionally, with this either being inlined or resulting
in an __fma* call.  (Using two levels of round-to-odd computation like
that, in the case where there isn't an fma hardware instruction, isn't
optimal but is certainly a lot simpler for the initial implementation
than writing different narrowing fma implementations for all the
various pairs of formats.)

Tested with build-many-glibcs.py that installed stripped shared
libraries are unchanged by the patch (using
<https://sourceware.org/pipermail/libc-alpha/2021-September/130991.html>
to fix installed library stripping in build-many-glibcs.py).  Also
tested for x86_64.

2 years agotime: Fix compile error in itimer test affecting hurd
Stafford Horne [Thu, 19 Aug 2021 14:47:07 +0000 (23:47 +0900)] 
time: Fix compile error in itimer test affecting hurd

The recent change to use __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 to avoid
doing 64-bit checks on some platforms broke the test for hurd where
__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 is not defined.  With error:

    tst-itimer.c: In function 'do_test':
    tst-itimer.c:103:11: error: '__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64' undeclared (first use in this function)
      103 |       if (__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64)
  |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    tst-itimer.c:103:11: note: each undeclared identifier is reported only once for each function it appears in

Define a support helper to detect when setitimer and getitimer support
64-bit time_t.

Fixes commit 6e8a0aac2f ("time: Fix overflow itimer tests on 32-bit
systems").

Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Joseph Myers <joseph@codesourcery.com>
2 years agomach lll_lock/unlock: Explicitly request private locking
Samuel Thibault [Tue, 14 Sep 2021 23:36:08 +0000 (01:36 +0200)] 
mach lll_lock/unlock: Explicitly request private locking

0 was actually LLL_PRIVATE, so this does not actually change the code.

2 years agoelf: Replace most uses of THREAD_GSCOPE_IN_TCB
Sergey Bugaev [Tue, 7 Sep 2021 13:33:21 +0000 (16:33 +0300)] 
elf: Replace most uses of THREAD_GSCOPE_IN_TCB

While originally this definition was indeed used to distinguish between
the cases where the GSCOPE flag was stored in TCB or not, it has since
become used as a general way to distinguish between HTL and NPTL.

THREAD_GSCOPE_IN_TCB will be removed in the following commits, as HTL,
which currently is the only port that does not put the flag into TCB,
will get ported to put the GSCOPE flag into the TCB as well. To prepare
for that change, migrate all code that wants to distinguish between HTL
and NPTL to use PTHREAD_IN_LIBC instead, which is a better choice since
the distinction mostly has to do with whether libc has access to the
list of thread structures and therefore can initialize thread-local
storage.

The parts of code that actually depend on whether the GSCOPE flag is in
TCB are left unchanged.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20210907133325.255690-2-bugaevc@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2 years agoAdd MADV_POPULATE_READ and MADV_POPULATE_WRITE from Linux 5.14 to bits/mman-linux.h
Joseph Myers [Tue, 14 Sep 2021 14:19:24 +0000 (14:19 +0000)] 
Add MADV_POPULATE_READ and MADV_POPULATE_WRITE from Linux 5.14 to bits/mman-linux.h

Linux 5.14 adds constants MADV_POPULATE_READ and MADV_POPULATE_WRITE
(with the same values on all architectures).  Add these to glibc's
bits/mman-linux.h.

Tested for x86_64.

2 years agoUpdate kernel version to 5.14 in tst-mman-consts.py
Joseph Myers [Tue, 14 Sep 2021 13:51:58 +0000 (13:51 +0000)] 
Update kernel version to 5.14 in tst-mman-consts.py

This patch updates the kernel version in the test tst-mman-consts.py
to 5.14.  (There are no new MAP_* constants covered by this test in
5.14 that need any other header changes.)

Tested with build-many-glibcs.py.

2 years agoconfigure: Fix check for INSERT in linker script
Fangrui Song [Mon, 13 Sep 2021 19:39:20 +0000 (12:39 -0700)] 
configure: Fix check for INSERT in linker script

GCC/Clang use local access when referencing a const variable,
so the conftest.so may have no dynamic relocation.
LLD reports `error: unable to insert .foo after .rela.dyn` when the
destination section does not exist.

Use a non-const int to ensure that .rela.dyn exists.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agoiconvconfig: Fix behaviour with --prefix [BZ #28199]
Siddhesh Poyarekar [Mon, 13 Sep 2021 15:18:35 +0000 (20:48 +0530)] 
iconvconfig: Fix behaviour with --prefix [BZ #28199]

The consolidation of configuration parsing broke behaviour with
--prefix, where the prefix bled into the modules cache.  Accept a
prefix which, when non-NULL, is prepended to the path when looking for
configuration files but only the original directory is added to the
modules cache.

This has no effect on the codegen of gconv_conf since it passes NULL.

Reported-by: Patrick McCarty <patrick.mccarty@intel.com>
Reported-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
2 years agonptl: Fix race between pthread_kill and thread exit (bug 12889)
Florian Weimer [Mon, 13 Sep 2021 09:06:08 +0000 (11:06 +0200)] 
nptl: Fix race between pthread_kill and thread exit (bug 12889)

A new thread exit lock and flag are introduced.  They are used to
detect that the thread is about to exit or has exited in
__pthread_kill_internal, and the signal is not sent in this case.

The test sysdeps/pthread/tst-pthread_cancel-select-loop.c is derived
from a downstream test originally written by Marek Polacek.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agonptl: pthread_kill, pthread_cancel should not fail after exit (bug 19193)
Florian Weimer [Mon, 13 Sep 2021 09:06:08 +0000 (11:06 +0200)] 
nptl: pthread_kill, pthread_cancel should not fail after exit (bug 19193)

This closes one remaining race condition related to bug 12889: if
the thread already exited on the kernel side, returning ESRCH
is not correct because that error is reserved for the thread IDs
(pthread_t values) whose lifetime has ended.  In case of a
kernel-side exit and a valid thread ID, no signal needs to be sent
and cancellation does not have an effect, so just return 0.

sysdeps/pthread/tst-kill4.c triggers undefined behavior and is
removed with this commit.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agobenchtests: Remove redundant assert.h
Naohiro Tamura [Mon, 13 Sep 2021 03:38:26 +0000 (09:08 +0530)] 
benchtests: Remove redundant assert.h

This patch removed redundant "#include <assert.h>" from
bench-memset-large.c and bench-memset-walk.c.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agobenchtests: Enable scripts/plot_strings.py to read stdin
Naohiro Tamura [Mon, 13 Sep 2021 03:34:21 +0000 (09:04 +0530)] 
benchtests: Enable scripts/plot_strings.py to read stdin

This patch enables scripts/plot_strings.py to read a benchmark result
file from stdin.
To keep backward compatibility, that is to keep accepting multiple of
benchmark result files in argument, blank argument doesn't mean stdin,
but '-' does.
Therefore nargs parameter of ArgumentParser.add_argument() method is
not changed to '?', but keep '+'.

ex:
  $ jq '.' bench-memset.out | plot_strings.py -
  $ jq '.' bench-memset.out | plot_strings.py - bench-memset-large.out
  $ plot_strings.py bench-memset.out bench-memset-large.out

error ex:
  $ jq '.' bench-memset.out | plot_strings.py

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agoAdd narrowing square root functions
Joseph Myers [Fri, 10 Sep 2021 20:56:22 +0000 (20:56 +0000)] 
Add narrowing square root functions

This patch adds the narrowing square root functions from TS 18661-1 /
TS 18661-3 / C2X to glibc's libm: fsqrt, fsqrtl, dsqrtl, f32sqrtf64,
f32sqrtf32x, f32xsqrtf64 for all configurations; f32sqrtf64x,
f32sqrtf128, f64sqrtf64x, f64sqrtf128, f32xsqrtf64x, f32xsqrtf128,
f64xsqrtf128 for configurations with _Float64x and _Float128;
__f32sqrtieee128 and __f64sqrtieee128 aliases in the powerpc64le case
(for calls to fsqrtl and dsqrtl when long double is IEEE binary128).
Corresponding tgmath.h macro support is also added.

The changes are mostly similar to those for the other narrowing
functions previously added, so the description of those generally
applies to this patch as well.  However, the not-actually-narrowing
cases (where the two types involved in the function have the same
floating-point format) are aliased to sqrt, sqrtl or sqrtf128 rather
than needing a separately built not-actually-narrowing function such
as was needed for add / sub / mul / div.  Thus, there is no
__nldbl_dsqrtl name for ldbl-opt because no such name was needed
(whereas the other functions needed such a name since the only other
name for that entry point was e.g. f32xaddf64, not reserved by TS
18661-1); the headers are made to arrange for sqrt to be called in
that case instead.

The DIAG_* calls in sysdeps/ieee754/soft-fp/s_dsqrtl.c are because
they were observed to be needed in GCC 7 testing of
riscv32-linux-gnu-rv32imac-ilp32.  The other sysdeps/ieee754/soft-fp/
files added didn't need such DIAG_* in any configuration I tested with
build-many-glibcs.py, but if they do turn out to be needed in more
files with some other configuration / GCC version, they can always be
added there.

I reused the same test inputs in auto-libm-test-in as for
non-narrowing sqrt rather than adding extra or separate inputs for
narrowing sqrt.  The tests in libm-test-narrow-sqrt.inc also follow
those for non-narrowing sqrt.

Tested as followed: natively with the full glibc testsuite for x86_64
(GCC 11, 7, 6) and x86 (GCC 11); with build-many-glibcs.py with GCC
11, 7 and 6; cross testing of math/ tests for powerpc64le, powerpc32
hard float, mips64 (all three ABIs, both hard and soft float).  The
different GCC versions are to cover the different cases in tgmath.h
and tgmath.h tests properly (GCC 6 has _Float* only as typedefs in
glibc headers, GCC 7 has proper _Float* support, GCC 8 adds
__builtin_tgmath).

2 years ago_Static_assert needs two arguments for compatibility with GCC before 9
Florian Weimer [Fri, 10 Sep 2021 11:18:36 +0000 (13:18 +0200)] 
_Static_assert needs two arguments for compatibility with GCC before 9

This macro definition enforces two arguments even with newer compilers
that accept the single-argument form, too.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agotestrun.sh: Add support for --tool=rpctrace
Sergey Bugaev [Tue, 7 Sep 2021 13:33:25 +0000 (16:33 +0300)] 
testrun.sh: Add support for --tool=rpctrace

rpctrace(1) is a Hurd RPC tracer tool, which is used similar to how
strace(1) is used on GNU/Linux.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20210907133325.255690-6-bugaevc@gmail.com>
Acked-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2 years agoUpdate syscall lists for Linux 5.14
Joseph Myers [Wed, 8 Sep 2021 12:42:06 +0000 (12:42 +0000)] 
Update syscall lists for Linux 5.14

Linux 5.14 has two new syscalls, memfd_secret (on some architectures
only) and quotactl_fd.  Update syscall-names.list and regenerate the
arch-syscall.h headers with build-many-glibcs.py update-syscalls.

Tested with build-many-glibcs.py.

2 years agoFix failing nss/tst-nss-files-hosts-long with local resolver
Aurelien Jarno [Thu, 2 Sep 2021 22:28:14 +0000 (00:28 +0200)] 
Fix failing nss/tst-nss-files-hosts-long with local resolver

When a local resolver like unbound is listening on the IPv4 loopback
address 127.0.0.1, the nss/tst-nss-files-hosts-long test fails. This is
due to:
- the default resolver in the absence of resolv.conf being 127.0.0.1
- the default DNS NSS database configuration in the absence of
  nsswitch.conf being 'hosts: dns [!UNAVAIL=return] file'

This causes the requests for 'test4' and 'test6' to first be sent to the
local resolver, which responds with NXDOMAIN in the likely case those
records do no exist. In turn that causes the access to /etc/hosts to be
skipped, which is the purpose of that test.

Fix that by providing a simple nsswitch.conf file forcing access to
/etc/hosts for that test. I have tested that the only changed result in
the testsuite is that test.

2 years agoMIPS: Setup errno for {f,l,}xstat
Jiaxun Yang [Tue, 7 Sep 2021 05:31:42 +0000 (13:31 +0800)] 
MIPS: Setup errno for {f,l,}xstat

{f,l,}xstat stub for MIPS is using INTERNAL_SYSCALL
to do xstat syscall for glibc ver, However it leaves
errno untouched and thus giving bad errno output.

Setup errno properly when syscall returns non-zero.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>