platform/upstream/glibc.git
2 years agoelf: add missing newlines in lateglobal test
Andreas Schwab [Wed, 8 Jun 2022 13:25:26 +0000 (15:25 +0200)]
elf: add missing newlines in lateglobal test

2 years agonptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214)
Adhemerval Zanella [Tue, 31 May 2022 20:13:35 +0000 (17:13 -0300)]
nptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214)

This was due a wrong revert done on 404656009b459658.

Checked on x86_64-linux-gnu.

2 years agox86: ZERO_UPPER_VEC_REGISTERS_RETURN_XTEST expect no transactions
Noah Goldstein [Fri, 3 Jun 2022 23:52:37 +0000 (18:52 -0500)]
x86: ZERO_UPPER_VEC_REGISTERS_RETURN_XTEST expect no transactions

Give fall-through path to `vzeroupper` and taken-path to `vzeroall`.

Generally even on machines with RTM the expectation is the
string-library functions will not be called in transactions.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agox86: Shrink code size of memchr-evex.S
Noah Goldstein [Tue, 7 Jun 2022 04:11:34 +0000 (21:11 -0700)]
x86: Shrink code size of memchr-evex.S

This is not meant as a performance optimization. The previous code was
far to liberal in aligning targets and wasted code size unnecissarily.

The total code size saving is: 64 bytes

There are no non-negligible changes in the benchmarks.
Geometric Mean of all benchmarks New / Old: 1.000

Full xcheck passes on x86_64.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agox86: Shrink code size of memchr-avx2.S
Noah Goldstein [Tue, 7 Jun 2022 04:11:33 +0000 (21:11 -0700)]
x86: Shrink code size of memchr-avx2.S

This is not meant as a performance optimization. The previous code was
far to liberal in aligning targets and wasted code size unnecissarily.

The total code size saving is: 59 bytes

There are no major changes in the benchmarks.
Geometric Mean of all benchmarks New / Old: 0.967

Full xcheck passes on x86_64.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agox86: Optimize memrchr-avx2.S
Noah Goldstein [Tue, 7 Jun 2022 04:11:32 +0000 (21:11 -0700)]
x86: Optimize memrchr-avx2.S

The new code:
    1. prioritizes smaller user-arg lengths more.
    2. optimizes target placement more carefully
    3. reuses logic more
    4. fixes up various inefficiencies in the logic. The biggest
       case here is the `lzcnt` logic for checking returns which
       saves either a branch or multiple instructions.

The total code size saving is: 306 bytes
Geometric Mean of all benchmarks New / Old: 0.760

Regressions:
There are some regressions. Particularly where the length (user arg
length) is large but the position of the match char is near the
beginning of the string (in first VEC). This case has roughly a
10-20% regression.

This is because the new logic gives the hot path for immediate matches
to shorter lengths (the more common input). This case has roughly
a 15-45% speedup.

Full xcheck passes on x86_64.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agox86: Optimize memrchr-evex.S
Noah Goldstein [Tue, 7 Jun 2022 04:11:31 +0000 (21:11 -0700)]
x86: Optimize memrchr-evex.S

The new code:
    1. prioritizes smaller user-arg lengths more.
    2. optimizes target placement more carefully
    3. reuses logic more
    4. fixes up various inefficiencies in the logic. The biggest
       case here is the `lzcnt` logic for checking returns which
       saves either a branch or multiple instructions.

The total code size saving is: 263 bytes
Geometric Mean of all benchmarks New / Old: 0.755

Regressions:
There are some regressions. Particularly where the length (user arg
length) is large but the position of the match char is near the
beginning of the string (in first VEC). This case has roughly a
20% regression.

This is because the new logic gives the hot path for immediate matches
to shorter lengths (the more common input). This case has roughly
a 35% speedup.

Full xcheck passes on x86_64.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agox86: Optimize memrchr-sse2.S
Noah Goldstein [Tue, 7 Jun 2022 04:11:30 +0000 (21:11 -0700)]
x86: Optimize memrchr-sse2.S

The new code:
    1. prioritizes smaller lengths more.
    2. optimizes target placement more carefully.
    3. reuses logic more.
    4. fixes up various inefficiencies in the logic.

The total code size saving is: 394 bytes
Geometric Mean of all benchmarks New / Old: 0.874

Regressions:
    1. The page cross case is now colder, especially re-entry from the
       page cross case if a match is not found in the first VEC
       (roughly 50%). My general opinion with this patch is this is
       acceptable given the "coldness" of this case (less than 4%) and
       generally performance improvement in the other far more common
       cases.

    2. There are some regressions 5-15% for medium/large user-arg
       lengths that have a match in the first VEC. This is because the
       logic was rewritten to optimize finds in the first VEC if the
       user-arg length is shorter (where we see roughly 20-50%
       performance improvements). It is not always the case this is a
       regression. My intuition is some frontend quirk is partially
       explaining the data although I haven't been able to find the
       root cause.

Full xcheck passes on x86_64.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoBenchtests: Improve memrchr benchmarks
Noah Goldstein [Tue, 7 Jun 2022 04:11:29 +0000 (21:11 -0700)]
Benchtests: Improve memrchr benchmarks

Add a second iteration for memrchr to set `pos` starting from the end
of the buffer.

Previously `pos` was only set relative to the beginning of the
buffer. This isn't really useful for memrchr because the beginning
of the search space is (buf + len).
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agox86: Add COND_VZEROUPPER that can replace vzeroupper if no `ret`
Noah Goldstein [Tue, 7 Jun 2022 04:11:28 +0000 (21:11 -0700)]
x86: Add COND_VZEROUPPER that can replace vzeroupper if no `ret`

The RTM vzeroupper mitigation has no way of replacing inline
vzeroupper not before a return.

This can be useful when hoisting a vzeroupper to save code size
for example:

```
L(foo):
cmpl %eax, %edx
jz L(bar)
tzcntl %eax, %eax
addq %rdi, %rax
VZEROUPPER_RETURN

L(bar):
xorl %eax, %eax
VZEROUPPER_RETURN
```

Can become:

```
L(foo):
COND_VZEROUPPER
cmpl %eax, %edx
jz L(bar)
tzcntl %eax, %eax
addq %rdi, %rax
ret

L(bar):
xorl %eax, %eax
ret
```

This code does not change any existing functionality.

There is no difference in the objdump of libc.so before and after this
patch.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agox86: Create header for VEC classes in x86 strings library
Noah Goldstein [Tue, 7 Jun 2022 04:11:27 +0000 (21:11 -0700)]
x86: Create header for VEC classes in x86 strings library

This patch does not touch any existing code and is only meant to be a
tool for future patches so that simple source files can more easily be
maintained to target multiple VEC classes.

There is no difference in the objdump of libc.so before and after this
patch.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agopowerpc: Fix VSX register number on __strncpy_power9 [BZ #29197]
Matheus Castanho [Tue, 7 Jun 2022 13:27:26 +0000 (10:27 -0300)]
powerpc: Fix VSX register number on __strncpy_power9 [BZ #29197]

__strncpy_power9 initializes VR 18 with zeroes to be used throughout the
code, including when zero-padding the destination string. However, the
v18 reference was mistakenly being used for stxv and stxvl, which take a
VSX vector as operand. The code ended up using the uninitialized VSR 18
register by mistake.

Both occurrences have been changed to use the proper VSX number for VR 18
(i.e. VSR 50).

Tested on powerpc, powerpc64 and powerpc64le.

Signed-off-by: Kewen Lin <linkw@gcc.gnu.org>
2 years agoAArch64: Sort makefile entries
Wilco Dijkstra [Tue, 7 Jun 2022 15:45:46 +0000 (16:45 +0100)]
AArch64: Sort makefile entries

Sort makefile entries to reduce conflicts.

2 years agoAArch64: Add SVE memcpy
Wilco Dijkstra [Tue, 7 Jun 2022 15:44:35 +0000 (16:44 +0100)]
AArch64: Add SVE memcpy

Add an initial SVE memcpy implementation.  Copies up to 32 bytes use SVE
vectors which improves the random memcpy benchmark significantly.
Cleanup the memcpy and memmove ifunc selectors.

2 years agox86_64: Add strstr function with 512-bit EVEX
Raghuveer Devulapalli [Mon, 6 Jun 2022 19:17:43 +0000 (12:17 -0700)]
x86_64: Add strstr function with 512-bit EVEX

Adding a 512-bit EVEX version of strstr. The algorithm works as follows:

(1) We spend a few cycles at the begining to peek into the needle. We
locate an edge in the needle (first occurance of 2 consequent distinct
characters) and also store the first 64-bytes into a zmm register.

(2) We search for the edge in the haystack by looking into one cache
line of the haystack at a time. This avoids having to read past a page
boundary which can cause a seg fault.

(3) If an edge is found in the haystack we first compare the first
64-bytes of the needle (already stored in a zmm register) before we
proceed with a full string compare performed byte by byte.

Benchmarking results: (old = strstr_sse2_unaligned, new = strstr_avx512)

Geometric mean of all benchmarks: new / old =  0.66

Difficult skiptable(0) : new / old =  0.02
Difficult skiptable(1) : new / old =  0.01
Difficult 2-way : new / old =  0.25
Difficult testing first 2 : new / old =  1.26
Difficult skiptable(0) : new / old =  0.05
Difficult skiptable(1) : new / old =  0.06
Difficult 2-way : new / old =  0.26
Difficult testing first 2 : new / old =  1.05
Difficult skiptable(0) : new / old =  0.42
Difficult skiptable(1) : new / old =  0.24
Difficult 2-way : new / old =  0.21
Difficult testing first 2 : new / old =  1.04
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoscripts/glibcelf.py: Add PT_AARCH64_MEMTAG_MTE constant
Adhemerval Zanella [Mon, 6 Jun 2022 17:41:24 +0000 (14:41 -0300)]
scripts/glibcelf.py: Add PT_AARCH64_MEMTAG_MTE constant

It was added in commit 603e5c8ba7257483c162cabb06eb6f79096429b6.
This caused the elf/tst-glibcelf consistency check to fail.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2 years agosocket: Fix mistyped define statement in socket/sys/socket.h (BZ #29225)
Dmitriy Fedchenko [Mon, 6 Jun 2022 15:46:14 +0000 (12:46 -0300)]
socket: Fix mistyped define statement in socket/sys/socket.h (BZ #29225)

2 years agoDeclare timegm for ISO C2X
Joseph Myers [Mon, 6 Jun 2022 14:47:03 +0000 (14:47 +0000)]
Declare timegm for ISO C2X

The next revision of the ISO C standard has added the timegm function
(that was already supported in glibc).  Update the feature test
conditionals on its declaration in <time.h> accordingly.

Tested for x86_64.

2 years agoAdd PT_AARCH64_MEMTAG_MTE from Linux 5.18 to elf.h
Joseph Myers [Mon, 6 Jun 2022 14:45:34 +0000 (14:45 +0000)]
Add PT_AARCH64_MEMTAG_MTE from Linux 5.18 to elf.h

Linux 5.18 defines a new AArch64 ELF segment type
PT_AARCH64_MEMTAG_MTE; add it to elf.h.

Tested with build-many-glibcs.py for aarch64-linux-gnu.

2 years agogrep: egrep -> grep -E, fgrep -> grep -F
Sam James [Sun, 5 Jun 2022 19:09:02 +0000 (12:09 -0700)]
grep: egrep -> grep -E, fgrep -> grep -F

Newer versions of GNU grep (after grep 3.7, not inclusive) will warn on
'egrep' and 'fgrep' invocations.

Convert usages within the tree to their expanded non-aliased counterparts
to avoid irritating warnings during ./configure and the test suite.

Signed-off-by: Sam James <sam@gentoo.org>
Reviewed-by: Fangrui Song <maskray@google.com>
2 years agostring.h: Fix boolean spelling in comments
H.J. Lu [Fri, 3 Jun 2022 17:22:38 +0000 (10:22 -0700)]
string.h: Fix boolean spelling in comments

2 years agoelf: Add #include <errno.h> for use of E* constants.
Carlos O'Donell [Thu, 2 Jun 2022 15:00:54 +0000 (11:00 -0400)]
elf: Add #include <errno.h> for use of E* constants.

In __strerror_r we use errno constants and must include errno.h.

Tested on x86_64 and i686 without regression.

2 years agoelf: Add #include <sys/param.h> for MAX usage.
Carlos O'Donell [Thu, 2 Jun 2022 14:59:14 +0000 (10:59 -0400)]
elf: Add #include <sys/param.h> for MAX usage.

In _dl_audit_pltenter we use MAX and so need to include param.h.

Tested on x86_64 and i686 without regression.

2 years agolinux: Add process_mrelease
Adhemerval Zanella [Fri, 28 Jan 2022 12:53:52 +0000 (12:53 +0000)]
linux: Add process_mrelease

Added in Linux 5.15 (884a7e5964e06ed93c7771c0d7cf19c09a8946f1), the new
syscalls allows a caller to free the memory of a dying target process.

Checked on x86_64-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agolinux: Add process_madvise
Adhemerval Zanella [Wed, 26 Jan 2022 19:05:31 +0000 (16:05 -0300)]
linux: Add process_madvise

It was added on Linux 5.10 (ecb8ac8b1f146915aa6b96449b66dd48984caacc)
with the same functionality as madvise but using a pidfd of the target
process.

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

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agolinux: Set tst-pidfd-consts unsupported for kernels headers older than 5.10
Adhemerval Zanella [Thu, 2 Jun 2022 11:50:58 +0000 (08:50 -0300)]
linux: Set tst-pidfd-consts unsupported for kernels headers older than 5.10

Instead of fail trying to build the compare source file.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Matheus Castanho <msc@linux.ibm.com>
Reviewed-by: Matheus Castanho <msc@linux.ibm.com>
2 years agotestrun.sh: Support passing strace and valgrind arguments
Florian Weimer [Thu, 2 Jun 2022 15:41:33 +0000 (17:41 +0200)]
testrun.sh: Support passing strace and valgrind arguments

This is a bit of a hack, but it works quite well in practice.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoLinux: Adjust struct rseq definition to current kernel version
Florian Weimer [Thu, 2 Jun 2022 14:29:55 +0000 (16:29 +0200)]
Linux: Adjust struct rseq definition to current kernel version

This definition is only used as a fallback with old kernel headers.
The change follows kernel commit bfdf4e6208051ed7165b2e92035b4bf11
("rseq: Remove broken uapi field layout on 32-bit little endian").

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoiconv: Use 64 bit stat for gconv_parseconfdir (BZ# 29213)
Adhemerval Zanella [Tue, 31 May 2022 15:51:43 +0000 (12:51 -0300)]
iconv: Use 64 bit stat for gconv_parseconfdir (BZ# 29213)

The issue is only when used within libc.so (iconvconfig already builds
with _TIME_SIZE=64).

This is a missing spot initially from 52a5fe70a2c77935.

Checked on i686-linux-gnu.

2 years agocatgets: Use 64 bit stat for __open_catalog (BZ# 29211)
Adhemerval Zanella [Tue, 31 May 2022 15:38:55 +0000 (12:38 -0300)]
catgets: Use 64 bit stat for __open_catalog (BZ# 29211)

This is a missing spot initially from 52a5fe70a2c77935.

Checked on i686-linux-gnu.

2 years agoinet: Use 64 bit stat for ruserpass (BZ# 29210)
Adhemerval Zanella [Tue, 31 May 2022 15:34:48 +0000 (12:34 -0300)]
inet: Use 64 bit stat for ruserpass (BZ# 29210)

This is a missing spot initially from 52a5fe70a2c77935.

Checked on i686-linux-gnu.

2 years agosocket: Use 64 bit stat for isfdtype (BZ# 29209)
Adhemerval Zanella [Tue, 31 May 2022 15:28:20 +0000 (12:28 -0300)]
socket: Use 64 bit stat for isfdtype (BZ# 29209)

This is a missing spot initially from 52a5fe70a2c77935.

Checked on i686-linux-gnu.

2 years agoposix: Use 64 bit stat for fpathconf (_PC_ASYNC_IO) (BZ# 29208)
Adhemerval Zanella [Tue, 31 May 2022 15:22:13 +0000 (12:22 -0300)]
posix: Use 64 bit stat for fpathconf (_PC_ASYNC_IO) (BZ# 29208)

This is a missing spot initially from 52a5fe70a2c77935.

Checked on i686-linux-gnu.

2 years agoposix: Use 64 bit stat for posix_fallocate fallback (BZ# 29207)
Adhemerval Zanella [Tue, 31 May 2022 15:17:20 +0000 (12:17 -0300)]
posix: Use 64 bit stat for posix_fallocate fallback (BZ# 29207)

This is a missing spot initially from 52a5fe70a2c77935.

Checked on i686-linux-gnu.

2 years agomisc: Use 64 bit stat for getusershell (BZ# 29203)
Adhemerval Zanella [Tue, 31 May 2022 14:51:46 +0000 (11:51 -0300)]
misc: Use 64 bit stat for getusershell (BZ# 29203)

This is a missing spot initially from 52a5fe70a2c77935.

Checked on i686-linux-gnu.

2 years agomisc: Use 64 bit stat for daemon (BZ# 29203)
Adhemerval Zanella [Tue, 31 May 2022 14:46:59 +0000 (11:46 -0300)]
misc: Use 64 bit stat for daemon (BZ# 29203)

This is a missing spot initially from 52a5fe70a2c77935.

Checked on i686-linux-gnu.

2 years agolinux: use statx for fstat if neither newfstatat nor fstatat64 is present
WANG Xuerui [Wed, 1 Jun 2022 02:12:28 +0000 (10:12 +0800)]
linux: use statx for fstat if neither newfstatat nor fstatat64 is present

LoongArch is going to be the first architecture supported by Linux that
has neither fstat* nor newfstatat [1], instead exclusively relying on
statx. So in fstatat64's implementation, we need to also enable statx
usage if neither fstatat64 nor newfstatat is present, to prepare for
this new case of kernel ABI.

[1]: https://lore.kernel.org/all/20220518092619.1269111-1-chenhuacai@loongson.cn/

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoAdd MADV_DONTNEED_LOCKED from Linux 5.18 to bits/mman-linux.h
Joseph Myers [Wed, 1 Jun 2022 14:45:48 +0000 (14:45 +0000)]
Add MADV_DONTNEED_LOCKED from Linux 5.18 to bits/mman-linux.h

Linux 5.18 adds a constant MADV_DONTNEED_LOCKED (defined in multiple
header files, but with the same value on all architectures).  Add this
constant to bits/mman-linux.h.

Tested for x86_64.

2 years agoAdd HWCAP2_MTE3 from Linux 5.18 to AArch64 bits/hwcap.h
Joseph Myers [Wed, 1 Jun 2022 14:43:06 +0000 (14:43 +0000)]
Add HWCAP2_MTE3 from Linux 5.18 to AArch64 bits/hwcap.h

Linux 5.18 defines a new AArch64 HWCAP value HWCAP2_MTE3; add it to
glibc's sysdeps/unix/sysv/linux/aarch64/bits/hwcap.h.

Tested with build-many-glibcs.py for aarch64-linux-gnu.

2 years agoi686: Use generic sincosf implementation for SSE2 version
Adhemerval Zanella [Tue, 31 May 2022 21:13:54 +0000 (18:13 -0300)]
i686: Use generic sincosf implementation for SSE2 version

The generic implementation shows slight better performance
(gcc 11.2.1 on a Ryzen 9 5900X):

* s_sincosf-sse2.S:
  "sincosf": {
   "workload-random": {
    "duration": 3.89961e+09,
    "iterations": 9.5472e+07,
    "reciprocal-throughput": 40.8429,
    "latency": 40.8483,
    "max-throughput": 2.4484e+07,
    "min-throughput": 2.44808e+07
   }
  }

* generic s_cossinf.c:
  "sincosf": {
   "workload-random": {
    "duration": 3.71953e+09,
    "iterations": 1.48512e+08,
    "reciprocal-throughput": 25.0515,
    "latency": 25.0391,
    "max-throughput": 3.99177e+07,
    "min-throughput": 3.99375e+07
   }
  }

Checked on i686-linux-gnu.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agobenchtests: Add workload name for sincosf
Adhemerval Zanella [Tue, 31 May 2022 21:08:32 +0000 (18:08 -0300)]
benchtests: Add workload name for sincosf

So it can show both reciprocal-throughput and latency.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoi686: Use generic sinf implementation for SSE2 version
Adhemerval Zanella [Tue, 31 May 2022 21:04:47 +0000 (18:04 -0300)]
i686: Use generic sinf implementation for SSE2 version

Performance seems to be similar (gcc 11.2.1 on a Ryzen 9 5900X),
the generic algorithm shows slight better performance for
the 'workload-huge.wrf' input set.

* s_sinf-sse2.S:
  "sinf": {
   "": {
    "duration": 3.72405e+09,
    "iterations": 2.38374e+08,
    "max": 63.973,
    "min": 11.211,
    "mean": 15.6227
   },
   "workload-random.wrf": {
    "duration": 3.76923e+09,
    "iterations": 8.4e+07,
    "reciprocal-throughput": 17.6355,
    "latency": 72.108,
    "max-throughput": 5.67037e+07,
    "min-throughput": 1.38681e+07
   },
   "workload-huge.wrf": {
    "duration": 3.76943e+09,
    "iterations": 6e+07,
    "reciprocal-throughput": 29.3493,
    "latency": 96.2985,
    "max-throughput": 3.40724e+07,
    "min-throughput": 1.03844e+07
   }
  }

* generic s_sinf.c:
  "sinf": {
   "": {
    "duration": 3.70989e+09,
    "iterations": 2.18025e+08,
    "max": 69.782,
    "min": 11.1,
    "mean": 17.0159
   },
   "workload-random.wrf": {
    "duration": 3.77213e+09,
    "iterations": 9.6e+07,
    "reciprocal-throughput": 17.5402,
    "latency": 61.0459,
    "max-throughput": 5.70119e+07,
    "min-throughput": 1.63811e+07
   },
   "workload-huge.wrf": {
    "duration": 3.81576e+09,
    "iterations": 5.6e+07,
    "reciprocal-throughput": 38.2111,
    "latency": 98.0659,
    "max-throughput": 2.61704e+07,
    "min-throughput": 1.01972e+07
   }
  }

Checked on i686-linux-gnu.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoi686: Use generic cosf implementation for SSE2 version
Adhemerval Zanella [Tue, 31 May 2022 20:55:27 +0000 (17:55 -0300)]
i686: Use generic cosf implementation for SSE2 version

Performance seems to be similar (gcc 11.2.1 on a Ryzen 9 5900X):

* s_cosf-sse2.S:
  "cosf": {
   "workload-random": {
    "duration": 3.74987e+09,
    "iterations": 9.616e+07,
    "reciprocal-throughput": 15.8141,
    "latency": 62.1782,
    "max-throughput": 6.32346e+07,
    "min-throughput": 1.60828e+07
   }
  }

* generic s_cosf.c:
  "cosf": {
   "workload-random": {
    "duration": 3.87298e+09,
    "iterations": 1.00968e+08,
    "reciprocal-throughput": 18.3448,
    "latency": 58.3722,
    "max-throughput": 5.45113e+07,
    "min-throughput": 1.71314e+07
   }
  }

Checked on i686-linux-gnu.

2 years agobenchtests: Add workload name for cosf
Adhemerval Zanella [Tue, 31 May 2022 20:48:28 +0000 (17:48 -0300)]
benchtests: Add workload name for cosf

So it can show both reciprocal-throughput and latency.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agox86_64: Optimize sincos where sin/cos is optimized (bug 29193)
Andreas Schwab [Tue, 31 May 2022 11:09:38 +0000 (13:09 +0200)]
x86_64: Optimize sincos where sin/cos is optimized (bug 29193)

The compiler may substitute calls to sin or cos with calls to sincos, thus
we should have the same optimized implementations for sincos.  The
optimized implementations may produce results that differ, that also makes
sure that the sincos call aggrees with the sin and cos calls.

2 years agomanual: fix reference to source file
Andreas Schwab [Tue, 31 May 2022 14:21:32 +0000 (16:21 +0200)]
manual: fix reference to source file

2 years agoAdd SOL_SMC from Linux 5.18 to bits/socket.h
Joseph Myers [Tue, 31 May 2022 13:49:53 +0000 (13:49 +0000)]
Add SOL_SMC from Linux 5.18 to bits/socket.h

Linux 5.18 adds a constant SOL_SMC to the getsockopt / setsockopt
levels; add this constant to bits/socket.h.

Tested for x86_64.

2 years agoelf: Remove _dl_skip_args
Adhemerval Zanella [Thu, 26 May 2022 16:15:56 +0000 (13:15 -0300)]
elf: Remove _dl_skip_args

Now that no architecture uses it anymore.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agox86_64: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:15:28 +0000 (13:15 -0300)]
x86_64: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.   So there is no need to adjust the argc or argv.

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

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agosparc: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:14:37 +0000 (13:14 -0300)]
sparc: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.   So there is no need to adjust the argc or argv.

Checked on sparc64-linux-gnu and sparcv9-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agosh: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:14:04 +0000 (13:14 -0300)]
sh: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.   So there is no need to adjust the argc or argv.

Checked with qemu-user that arguments are correctly passed on both
constructors and main program.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agos390: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:13:05 +0000 (13:13 -0300)]
s390: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.   So there is no need to adjust the argc or argv.

Checked on s390x-linux-gnu and s390-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoriscv: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:12:44 +0000 (13:12 -0300)]
riscv: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.   So there is no need to adjust the argc or argv.

Checked with qemu-user that arguments are correctly passed on both
constructors and main program.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agonios2: Remove _dl_skip_args usage (BZ# 29187)
Adhemerval Zanella [Thu, 26 May 2022 16:12:21 +0000 (13:12 -0300)]
nios2: Remove _dl_skip_args usage (BZ# 29187)

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.   So there is no need to adjust the argc or argv.

Checked with qemu-user that arguments are correctly passed on both
constructors and main program.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agomips: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:11:58 +0000 (13:11 -0300)]
mips: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.   So there is no need to adjust the argc or argv.

Checked with qemu-user that arguments are correctly passed on both
constructors and main program.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agomicroblaze: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:11:17 +0000 (13:11 -0300)]
microblaze: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.   So there is no need to adjust the argc or argv.

Checked with qemu-user that arguments are correctly passed on both
constructors and main program.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agom68k: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:10:38 +0000 (13:10 -0300)]
m68k: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.  So there is no need to adjust the argc or argv.

Checked with qemu-user that arguments are correctly passed on both
constructors and main program.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoia64: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:08:01 +0000 (13:08 -0300)]
ia64: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.

The startup code is changed to read the _dl_argc and _dl_argv values,
and envp is calculated from argc and argv.

Checked on ia64-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoi686: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:07:00 +0000 (13:07 -0300)]
i686: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.  So there is no need to adjust the argc or argv.

Checked on i686-linux-gnu.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agohppa: Remove _dl_skip_args usage (BZ# 29165)
Adhemerval Zanella [Wed, 25 May 2022 11:58:38 +0000 (08:58 -0300)]
hppa: Remove _dl_skip_args usage (BZ# 29165)

Different than other architectures, hppa creates an unrelated stack
frame where ld.so argc/argv adjustments done by ad43cac44a6860eaefc
is not done on the argc/argv saved/restore by _dl_start_user.

Instead load _dl_argc and _dl_argv directlty instead of adjust them
using _dl_skip_args value.

Checked on hppa-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agocsky: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:06:06 +0000 (13:06 -0300)]
csky: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.  It makes the fixup_stack branch ununsed.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoarc: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:04:40 +0000 (13:04 -0300)]
arc: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.  So there is no need to adjust the argc or argv.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoarm: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:03:51 +0000 (13:03 -0300)]
arm: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.  It makes the _fixup_stack branch ununsed.

Checked with qemu-user that arguments are correctly passed on both
constructors and main program.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoalpha: Remove _dl_skip_args usage
Adhemerval Zanella [Thu, 26 May 2022 16:00:48 +0000 (13:00 -0300)]
alpha: Remove _dl_skip_args usage

Since ad43cac44a the generic code already shuffles the argv/envp/auxv
on the stack to remove the ld.so own arguments and thus _dl_skip_args
is always 0.  It makes the fixup_stack branch ununsed.

Checked with qemu-user that arguments are correctly passed on both
constructors and main program.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agobenchtests: Improve benchtests for strstr, memmem, and memchr
Noah Goldstein [Fri, 27 May 2022 23:25:40 +0000 (18:25 -0500)]
benchtests: Improve benchtests for strstr, memmem, and memchr

1. Use json_ctx for output to help standardize format across all
   benchtests.

2. Add some additional tests to strstr and memchr expanding alignments
   and adding more small values.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agodlsym: Make RTLD_NEXT prefer default version definition [BZ #14932]
Fangrui Song [Fri, 27 May 2022 19:34:49 +0000 (12:34 -0700)]
dlsym: Make RTLD_NEXT prefer default version definition [BZ #14932]

When the first object providing foo defines both foo@v1 and foo@@v2,
dlsym(RTLD_NEXT, "foo") returns foo@v1 while dlsym(RTLD_DEFAULT, "foo")
returns foo@@v2.  The issue is that RTLD_DEFAULT uses the
DL_LOOKUP_RETURN_NEWEST flag while RTLD_NEXT doesn't.  Fix the RTLD_NEXT
branch to use DL_LOOKUP_RETURN_NEWEST.

Note: the new behavior matches FreeBSD rtld.  Future sanitizers will not
need to add versioned interceptors like https://reviews.llvm.org/D96348

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agox86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT
H.J. Lu [Sat, 21 May 2022 02:21:48 +0000 (19:21 -0700)]
x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT

According to x86-64 psABI, r_addend should be ignored for R_X86_64_GLOB_DAT
and R_X86_64_JUMP_SLOT.  Since linkers always set their r_addends to 0, we
can ignore their r_addends.

Reviewed-by: Fangrui Song <maskray@google.com>
2 years agox86_64: Implement evex512 version of strlen, strnlen, wcslen and wcsnlen
Sunil K Pandey [Mon, 28 Feb 2022 00:39:47 +0000 (16:39 -0800)]
x86_64: Implement evex512 version of strlen, strnlen, wcslen and wcsnlen

This patch implements following evex512 version of string functions.
Perf gain for evex512 version is up to 50% as compared to evex,
depending on length and alignment.

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

- String length function using 512 bit vectors.
- String N length using 512 bit vectors.
- Wide string length using 512 bit vectors.
- Wide string N length using 512 bit vectors.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
2 years agoUpdate kernel version to 5.18 in header constant tests
Joseph Myers [Thu, 26 May 2022 13:51:17 +0000 (13:51 +0000)]
Update kernel version to 5.18 in header constant tests

This patch updates the kernel version in the tests tst-mman-consts.py
and tst-pidfd-consts.py to 5.18.  (There are no new constants covered
by these tests in 5.18, or in 5.17 in the case of tst-pidfd-consts.py
that previously used version 5.16, that need any other header
changes.)

Tested with build-many-glibcs.py.

2 years agoString: Improve overflow test coverage for strnlen
Sunil K Pandey [Wed, 25 May 2022 20:43:36 +0000 (13:43 -0700)]
String: Improve overflow test coverage for strnlen

This patch adds more overflow test coverage for strnlen and wcsnlen.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agoUpdate syscall-names.list for Linux 5.18
Joseph Myers [Wed, 25 May 2022 14:37:28 +0000 (14:37 +0000)]
Update syscall-names.list for Linux 5.18

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

Tested with build-many-glibcs.py.

2 years agoFix deadlock when pthread_atfork handler calls pthread_atfork or dlclose
Arjun Shankar [Tue, 24 May 2022 15:57:36 +0000 (17:57 +0200)]
Fix deadlock when pthread_atfork handler calls pthread_atfork or dlclose

In multi-threaded programs, registering via pthread_atfork,
de-registering implicitly via dlclose, or running pthread_atfork
handlers during fork was protected by an internal lock.  This meant
that a pthread_atfork handler attempting to register another handler or
dlclose a dynamically loaded library would lead to a deadlock.

This commit fixes the deadlock in the following way:

During the execution of handlers at fork time, the atfork lock is
released prior to the execution of each handler and taken again upon its
return.  Any handler registrations or de-registrations that occurred
during the execution of the handler are accounted for before proceeding
with further handler execution.

If a handler that hasn't been executed yet gets de-registered by another
handler during fork, it will not be executed.   If a handler gets
registered by another handler during fork, it will not be executed
during that particular fork.

The possibility that handlers may now be registered or deregistered
during handler execution means that identifying the next handler to be
run after a given handler may register/de-register others requires some
bookkeeping.  The fork_handler struct has an additional field, 'id',
which is assigned sequentially during registration.  Thus, handlers are
executed in ascending order of 'id' during 'prepare', and descending
order of 'id' during parent/child handler execution after the fork.

Two tests are included:

* tst-atfork3: Adhemerval Zanella <adhemerval.zanella@linaro.org>
  This test exercises calling dlclose from prepare, parent, and child
  handlers.

* tst-atfork4: This test exercises calling pthread_atfork and dlclose
  from the prepare handler.

[BZ #24595, BZ #27054]

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agoUse Linux 5.18 in build-many-glibcs.py
Joseph Myers [Tue, 24 May 2022 13:51:24 +0000 (13:51 +0000)]
Use Linux 5.18 in build-many-glibcs.py

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

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

2 years agostdio-common: Simplify printf_unknown interface in vfprintf-internal.c
Florian Weimer [Tue, 24 May 2022 06:03:11 +0000 (08:03 +0200)]
stdio-common: Simplify printf_unknown interface in vfprintf-internal.c

The called function does not use the args array, so there is no need
to produce it.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agostdio-common: Move union printf_arg int <printf.h>
Florian Weimer [Tue, 24 May 2022 06:03:11 +0000 (08:03 +0200)]
stdio-common: Move union printf_arg int <printf.h>

The type does not depend on wide vs narrow preprocessor macros,
so it does not need to be customized in stdio-common/printf-parse.h.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agostdio-common: Add printf specifier registry to <printf.h>
Florian Weimer [Tue, 24 May 2022 06:03:11 +0000 (08:03 +0200)]
stdio-common: Add printf specifier registry to <printf.h>

Add  __printf_arginfo_table, __printf_function_table,
__printf_va_arg_table, __register_printf_specifier to
include/printf.h.

2 years agoelf/dl-reloc.c: Copyright The GNU Toolchain Authors
Fangrui Song [Tue, 24 May 2022 02:16:05 +0000 (19:16 -0700)]
elf/dl-reloc.c: Copyright The GNU Toolchain Authors

by following 3.5. Update copyright information
on https://sourceware.org/glibc/wiki/Contribution%20checklist .
The change is advised by Carlos O'Donell.

Note: commit a8b11bd1f8dc68795b377138b5d94638ef75a50d missed Signed-off-by tag
from Nicholas Guriev <nicholas@guriev.su>.

2 years agobenchtests: Improve bench-strnlen.c
Noah Goldstein [Mon, 23 May 2022 22:41:55 +0000 (17:41 -0500)]
benchtests: Improve bench-strnlen.c

1. Output results in json format so its easier to parse
2. Increase max alignment to `getpagesize () - 1` to make it possible
   to test page cross cases.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years agomath: Add math-use-builtins-fabs (BZ#29027)
Adhemerval Zanella [Fri, 1 Apr 2022 13:19:57 +0000 (10:19 -0300)]
math: Add math-use-builtins-fabs (BZ#29027)

Both float, double, and _Float128 are assumed to be supported
(float and double already only uses builtins).  Only long double
is parametrized due GCC bug 29253 which prevents its usage on
powerpc.

It allows to remove i686, ia64, x86_64, powerpc, and sparc arch
specific implementation.

On ia64 it also fixes the sNAN handling:

  math/test-float64x-fabs
  math/test-ldouble-fabs

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu,
powerpc64-linux-gnu, sparc64-linux-gnu, and ia64-linux-gnu.

2 years agolinux: Add CLONE_NEWTIME from Linux 5.6 to bits/sched.h
Adhemerval Zanella [Tue, 10 May 2022 16:59:48 +0000 (13:59 -0300)]
linux: Add CLONE_NEWTIME from Linux 5.6 to bits/sched.h

It was added in commit 769071ac9f20b6a447410c7eaa55d1a5233ef40c.

2 years agoRevert "[ARM][BZ #17711] Fix extern protected data handling"
Fangrui Song [Mon, 23 May 2022 20:42:10 +0000 (13:42 -0700)]
Revert "[ARM][BZ #17711] Fix extern protected data handling"

This reverts commit 3bcea719ddd6ce399d7bccb492c40af77d216e42.

Similar to commit e555954e026df1b85b8ef6c101d05f97b1520d7e for aarch64.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2 years agoRevert "[AArch64][BZ #17711] Fix extern protected data handling"
Fangrui Song [Mon, 23 May 2022 20:37:05 +0000 (13:37 -0700)]
Revert "[AArch64][BZ #17711] Fix extern protected data handling"

This reverts commit 0910702c4d2cf9e8302b35c9519548726e1ac489.

Say both a.so and b.so define protected data symbol `var` and the executable
copy relocates var.  ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA has strange
semantics: a.so accesses the copy in the executable while b.so accesses its
own.  This behavior requires that (a) the compiler emits GOT-generating
relocations (b) the linker produces GLOB_DAT instead of RELATIVE.

Without the ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA code, b.so's GLOB_DAT
will bind to the executable (normal behavior).

For aarch64 it makes sense to restore the original behavior and don't
pay the ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA cost.  The behavior is very
unlikely used by anyone.

* Clang code generator treats STV_PROTECTED the same way as STV_HIDDEN:
  no GOT-generating relocation in the first place.
* gold and lld reject copy relocation on a STV_PROTECTED symbol.
* Nowadays -fpie/-fpic modes are popular.  GCC/Clang's codegen uses
  GOT-generating relocation when accessing an default visibility
  external symbol which avoids copy relocation.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2 years agoelf: Rewrite long RESOLVE_MAP macro to an always_inline static function
Nicholas Guriev [Mon, 23 May 2022 19:06:44 +0000 (12:06 -0700)]
elf: Rewrite long RESOLVE_MAP macro to an always_inline static function

An __always_inline static function is better to find where exactly a
crash happens, so one can step into the function with GDB.

Reviewed-by: Fangrui Song <maskray@google.com>
2 years agodlfcn: Move RTLD_DEFAULT/RTLD_NEXT outside __USE_GNU
Fangrui Song [Mon, 23 May 2022 17:23:23 +0000 (10:23 -0700)]
dlfcn: Move RTLD_DEFAULT/RTLD_NEXT outside __USE_GNU

POSIX reserves the RTLD_ namespace, and this is already reflected in our
conform tests.
Note: RTLD_DEFAULT and RTLD_NEXT appear in IEEE Std 1003.1-2004.  Many
systems (e.g. FreeBSD, musl) just define the macros unconditionally.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Tested-by: Florian Weimer <fweimer@redhat.com>
2 years agoelf: Optimize _dl_new_hash in dl-new-hash.h
Noah Goldstein [Thu, 19 May 2022 22:18:03 +0000 (17:18 -0500)]
elf: Optimize _dl_new_hash in dl-new-hash.h

Unroll slightly and enforce good instruction scheduling. This improves
performance on out-of-order machines. The unrolling allows for
pipelined multiplies.

As well, as an optional sysdep, reorder the operations and prevent
reassosiation for better scheduling and higher ILP. This commit
only adds the barrier for x86, although it should be either no
change or a win for any architecture.

Unrolling further started to induce slowdowns for sizes [0, 4]
but can help the loop so if larger sizes are the target further
unrolling can be beneficial.

Results for _dl_new_hash
Benchmarked on Tigerlake: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz

Time as Geometric Mean of N=30 runs
Geometric of all benchmark New / Old: 0.674
  type, length, New Time, Old Time, New Time / Old Time
 fixed,      0,    2.865,     2.72,               1.053
 fixed,      1,    3.567,    2.489,               1.433
 fixed,      2,    2.577,    3.649,               0.706
 fixed,      3,    3.644,    5.983,               0.609
 fixed,      4,    4.211,    6.833,               0.616
 fixed,      5,    4.741,    9.372,               0.506
 fixed,      6,    5.415,    9.561,               0.566
 fixed,      7,    6.649,   10.789,               0.616
 fixed,      8,    8.081,   11.808,               0.684
 fixed,      9,    8.427,   12.935,               0.651
 fixed,     10,    8.673,   14.134,               0.614
 fixed,     11,    10.69,   15.408,               0.694
 fixed,     12,   10.789,   16.982,               0.635
 fixed,     13,   12.169,   18.411,               0.661
 fixed,     14,   12.659,   19.914,               0.636
 fixed,     15,   13.526,   21.541,               0.628
 fixed,     16,   14.211,   23.088,               0.616
 fixed,     32,   29.412,   52.722,               0.558
 fixed,     64,    65.41,  142.351,               0.459
 fixed,    128,  138.505,  295.625,               0.469
 fixed,    256,  291.707,  601.983,               0.485
random,      2,   12.698,   12.849,               0.988
random,      4,   16.065,   15.857,               1.013
random,      8,   19.564,   21.105,               0.927
random,     16,   23.919,   26.823,               0.892
random,     32,   31.987,   39.591,               0.808
random,     64,   49.282,   71.487,               0.689
random,    128,    82.23,  145.364,               0.566
random,    256,  152.209,  298.434,                0.51

Co-authored-by: Alexander Monakov <amonakov@ispras.ru>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agonss: Optimize nss_hash in nss_hash.c
Noah Goldstein [Thu, 19 May 2022 22:18:02 +0000 (17:18 -0500)]
nss: Optimize nss_hash in nss_hash.c

The prior unrolling didn't really do much as it left the dependency
chain between iterations. Unrolled the loop for 4 so 4x multiplies
could be pipelined in out-of-order machines.

Results for __nss_hash
Benchmarked on Tigerlake: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz

Time as Geometric Mean of N=25 runs
Geometric of all benchmark New / Old: 0.845
  type, length, New Time, Old Time, New Time / Old Time
 fixed,      0,    4.019,    3.729,               1.078
 fixed,      1,     4.95,    5.707,               0.867
 fixed,      2,    5.152,    5.657,               0.911
 fixed,      3,    4.641,    5.721,               0.811
 fixed,      4,    5.551,     5.81,               0.955
 fixed,      5,    6.525,    6.552,               0.996
 fixed,      6,    6.711,    6.561,               1.023
 fixed,      7,    6.715,    6.767,               0.992
 fixed,      8,    7.874,    7.915,               0.995
 fixed,      9,    8.888,    9.767,                0.91
 fixed,     10,    8.959,    9.762,               0.918
 fixed,     11,    9.188,    9.987,                0.92
 fixed,     12,    9.708,   10.618,               0.914
 fixed,     13,   10.393,    11.14,               0.933
 fixed,     14,   10.628,   12.097,               0.879
 fixed,     15,   10.982,   12.965,               0.847
 fixed,     16,   11.851,   14.429,               0.821
 fixed,     32,   24.334,   34.414,               0.707
 fixed,     64,   55.618,   86.688,               0.642
 fixed,    128,  118.261,   224.36,               0.527
 fixed,    256,  256.183,  538.629,               0.476
random,      2,   11.194,   11.556,               0.969
random,      4,   17.516,   17.205,               1.018
random,      8,   23.501,   20.985,                1.12
random,     16,   28.131,   29.212,               0.963
random,     32,   35.436,   38.662,               0.917
random,     64,    45.74,   58.868,               0.777
random,    128,   75.394,  121.963,               0.618
random,    256,  139.524,  260.726,               0.535
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agobenchtests: Add benchtests for dl_elf_hash, dl_new_hash and nss_hash
Noah Goldstein [Thu, 19 May 2022 22:18:01 +0000 (17:18 -0500)]
benchtests: Add benchtests for dl_elf_hash, dl_new_hash and nss_hash

Benchtests are for throughput and include random / fixed size
benchmarks.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agonss: Add tests for the nss_hash in nss_hash.h
Noah Goldstein [Thu, 19 May 2022 22:18:00 +0000 (17:18 -0500)]
nss: Add tests for the nss_hash in nss_hash.h

If we want to further optimize the function tests are needed.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agoelf: Add tests for the dl hash funcs (_dl_new_hash and _dl_elf_hash)
Noah Goldstein [Thu, 19 May 2022 22:17:59 +0000 (17:17 -0500)]
elf: Add tests for the dl hash funcs (_dl_new_hash and _dl_elf_hash)

If we want to further optimize the functions tests are needed.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agoelf: Refactor dl_new_hash so it can be tested / benchmarked
Noah Goldstein [Thu, 19 May 2022 22:17:58 +0000 (17:17 -0500)]
elf: Refactor dl_new_hash so it can be tested / benchmarked

No change to the code other than moving the function to
dl-new-hash.h. Changed name so its now in the reserved namespace.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2 years agolocale: Add more cached data to LC_CTYPE
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
locale: Add more cached data to LC_CTYPE

This data will be used in number formatting.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agolocale: Remove private union from struct __locale_data
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
locale: Remove private union from struct __locale_data

This avoids an alias violation later.  This commit also fixes
an incorrect double-checked locking idiom in _nl_init_era_entries.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agolocale: Remove cleanup function pointer from struct __localedata
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
locale: Remove cleanup function pointer from struct __localedata

We can call the cleanup functions directly from _nl_unload_locale
if we pass the category to it.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agolocale: Call _nl_unload_locale from _nl_archive_subfreeres
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
locale: Call _nl_unload_locale from _nl_archive_subfreeres

The function performs the same steps for ld_archive locales
(mapped from an archive), and this code is not performance-critical,
so the specialization does not add value.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agostdio-common: Add tst-memstream-string for open_memstream overflow
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
stdio-common: Add tst-memstream-string for open_memstream overflow

This code path is exercised indirectly by some of the DNS stub
resolver tests, via their own use of xopen_memstream for constructing
strings describing result data.  The relative lack of test suite
coverage became apparent when these tests starting failing after a
printf changes uncovered bug 28949.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years ago__printf_fphex always uses LC_NUMERIC
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
__printf_fphex always uses LC_NUMERIC

There is no hexadecimal currency printing.  strfmon uses
__printf_fp_l exclusively.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agovfprintf: Consolidate some multibyte/wide character processing
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
vfprintf: Consolidate some multibyte/wide character processing

form_character and form_string processing a sufficiently similar
that the logic can be shared.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agovfprintf: Move argument processing into vfprintf-process-arg.c
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
vfprintf: Move argument processing into vfprintf-process-arg.c

This simplies formatting and helps with debugging.  It also allows
the use of localized COMPILE_WPRINTF preprocessor conditionals.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agostdio-common: Add tst-vfprintf-width-i18n to cover numeric field width
Florian Weimer [Mon, 23 May 2022 08:08:18 +0000 (10:08 +0200)]
stdio-common: Add tst-vfprintf-width-i18n to cover numeric field width

Related to bug 28943 and bug 28944.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2 years agostring.h: fix __fortified_attr_access macro call [BZ #29162]
Sergei Trofimovich [Mon, 23 May 2022 08:26:43 +0000 (13:56 +0530)]
string.h: fix __fortified_attr_access macro call [BZ #29162]

commit e938c0274 "Don't add access size hints to fortifiable functions"
converted a few '__attr_access ((...))' into '__fortified_attr_access (...)'
calls.

But one of conversions had double parentheses of '__fortified_attr_access (...)'.

Noticed as a gnat6 build failure:

    /<<NIX>>-glibc-2.34-210-dev/include/bits/string_fortified.h:110:50: error: macro "__fortified_attr_access" requires 3 arguments, but only 1 given

The change fixes parentheses.

This is seen when using compilers that do not support
__builtin___stpncpy_chk, e.g. gcc older than 4.7, clang older than 2.6
or some compiler not derived from gcc or clang.

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>