]> sourceware.org Git - glibc.git/log
glibc.git
5 weeks agoAdd tests of fread
Joseph Myers [Tue, 24 Sep 2024 14:06:22 +0000 (14:06 +0000)]
Add tests of fread

There seem to be no glibc tests specifically for the fread function.
Add basic tests of that function.

Tested for x86_64.

(cherry picked from commit d14c977c65aac7db35bb59380ef99d6582c4f930)

5 weeks agostdio-common: Add new test for fdopen
Sergey Kolosov [Wed, 25 Sep 2024 13:51:23 +0000 (15:51 +0200)]
stdio-common: Add new test for fdopen

This commit adds fdopen test with all modes.
Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 1d72fa3cfa046f7293421a7e58f2a272474ea901)

8 weeks agolibio: Attempt wide backup free only for non-legacy code
Siddhesh Poyarekar [Tue, 3 Sep 2024 18:58:33 +0000 (14:58 -0400)]
libio: Attempt wide backup free only for non-legacy code

_wide_data and _mode are not available in legacy code, so do not attempt
to free the wide backup buffer in legacy code.

Resolves: BZ #32137 and BZ #27821

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit ae4d44b1d501421ad9a3af95279b8f4d1546f1ce)

8 weeks agodebug: Fix read error handling in pcprofiledump
Florian Weimer [Tue, 10 Sep 2024 10:40:27 +0000 (12:40 +0200)]
debug: Fix read error handling in pcprofiledump

The reading loops did not check for read failures.  Addresses
a static analysis report.

Manually tested by compiling a program with the GCC's
-finstrument-functions option, running it with
“LD_PRELOAD=debug/libpcprofile.so PCPROFILE_OUTPUT=output-file”,
and reviewing the output of “debug/pcprofiledump output-file”.

(cherry picked from commit 89b088bf70c651c231bf27e644270d093b8f144a)

8 weeks agoelf: Fix tst-dlopen-tlsreinit1.out test dependency
Florian Weimer [Mon, 9 Sep 2024 19:10:23 +0000 (21:10 +0200)]
elf: Fix tst-dlopen-tlsreinit1.out test dependency

Fixes commit 5097cd344fd243fb8deb6dec96e8073753f962f9
("elf: Avoid re-initializing already allocated TLS in dlopen
(bug 31717)").

Reported-by: Patsy Griffin <patsy@redhat.com>
Reviewed-by: Patsy Griffin <patsy@redhat.com>
(cherry picked from commit e82a7cb1622bff08d8e3a144d7c5516a088f1cbc)

8 weeks agoelf: Avoid re-initializing already allocated TLS in dlopen (bug 31717)
Florian Weimer [Thu, 1 Aug 2024 21:31:30 +0000 (23:31 +0200)]
elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717)

The old code used l_init_called as an indicator for whether TLS
initialization was complete.  However, it is possible that
TLS for an object is initialized, written to, and then dlopen
for this object is called again, and l_init_called is not true at
this point.  Previously, this resulted in TLS being initialized
twice, discarding any interim writes (technically introducing a
use-after-free bug even).

This commit introduces an explicit per-object flag, l_tls_in_slotinfo.
It indicates whether _dl_add_to_slotinfo has been called for this
object.  This flag is used to avoid double-initialization of TLS.
In update_tls_slotinfo, the first_static_tls micro-optimization
is removed because preserving the initalization flag for subsequent
use by the second loop for static TLS is a bit complicated, and
another per-object flag does not seem to be worth it.  Furthermore,
the l_init_called flag is dropped from the second loop (for static
TLS initialization) because l_need_tls_init on its own prevents
double-initialization.

The remaining l_init_called usage in resize_scopes and update_scopes
is just an optimization due to the use of scope_has_map, so it is
not changed in this commit.

The isupper check ensures that libc.so.6 is TLS is not reverted.
Such a revert happens if l_need_tls_init is not cleared in
_dl_allocate_tls_init for the main_thread case, now that
l_init_called is not checked anymore in update_tls_slotinfo
in elf/dl-open.c.

Reported-by: Jonathon Anderson <janderson@rice.edu>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 5097cd344fd243fb8deb6dec96e8073753f962f9)

8 weeks agoelf: Clarify and invert second argument of _dl_allocate_tls_init
Florian Weimer [Thu, 1 Aug 2024 21:31:23 +0000 (23:31 +0200)]
elf: Clarify and invert second argument of _dl_allocate_tls_init

Also remove an outdated comment: _dl_allocate_tls_init is
called as part of pthread_create.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit fe06fb313bddf7e4530056897d4a706606e49377)

2 months agonptl: Use <support/check.h> facilities in tst-setuid3
Maciej W. Rozycki [Fri, 26 Jul 2024 12:21:34 +0000 (13:21 +0100)]
nptl: Use <support/check.h> facilities in tst-setuid3

Remove local FAIL macro in favor to FAIL_EXIT1 from <support/check.h>,
which provides equivalent reporting, with the name of the file and the
line number within of the failure site additionally included.  Remove
FAIL_ERR altogether and include ": %m" explicitly with the format string
supplied to FAIL_EXIT1 as there seems little value to have a separate
macro just for this.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 8c98195af6e6f1ce21743fc26c723e0f7e45bcf2)

2 months agoposix: Use <support/check.h> facilities in tst-truncate and tst-truncate64
Maciej W. Rozycki [Fri, 26 Jul 2024 12:21:34 +0000 (13:21 +0100)]
posix: Use <support/check.h> facilities in tst-truncate and tst-truncate64

Remove local FAIL macro in favor to FAIL_RET from <support/check.h>,
which provides equivalent reporting, with the name of the file of the
failure site additionally included, for the tst-truncate-common core
shared between the tst-truncate and tst-truncate64 tests.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit fe47595504a55e7bb992f8928533df154b510383)

2 months agoungetc: Fix backup buffer leak on program exit [BZ #27821]
Siddhesh Poyarekar [Wed, 14 Aug 2024 01:08:49 +0000 (21:08 -0400)]
ungetc: Fix backup buffer leak on program exit [BZ #27821]

If a file descriptor is left unclosed and is cleaned up by _IO_cleanup
on exit, its backup buffer remains unfreed, registering as a leak in
valgrind.  This is not strictly an issue since (1) the program should
ideally be closing the stream once it's not in use and (2) the program
is about to exit anyway, so keeping the backup buffer around a wee bit
longer isn't a real problem.  Free it anyway to keep valgrind happy
when the streams in question are the standard ones, i.e. stdout, stdin
or stderr.

Also, the _IO_have_backup macro checks for _IO_save_base,
which is a roundabout way to check for a backup buffer instead of
directly looking for _IO_backup_base.  The roundabout check breaks when
the main get area has not been used and user pushes a char into the
backup buffer with ungetc.  Fix this to use the _IO_backup_base
directly.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 3e1d8d1d1dca24ae90df2ea826a8916896fc7e77)

2 months agoungetc: Fix uninitialized read when putting into unused streams [BZ #27821]
Siddhesh Poyarekar [Wed, 14 Aug 2024 01:00:06 +0000 (21:00 -0400)]
ungetc: Fix uninitialized read when putting into unused streams [BZ #27821]

When ungetc is called on an unused stream, the backup buffer is
allocated without the main get area being present.  This results in
every subsequent ungetc (as the stream remains in the backup area)
checking uninitialized memory in the backup buffer when trying to put a
character back into the stream.

Avoid comparing the input character with buffer contents when in backup
to avoid this uninitialized read.  The uninitialized read is harmless in
this context since the location is promptly overwritten with the input
character, thus fulfilling ungetc functionality.

Also adjust wording in the manual to drop the paragraph that says glibc
cannot do multiple ungetc back to back since with this change, ungetc
can actually do this.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit cdf0f88f97b0aaceb894cc02b21159d148d7065c)

2 months agoMake tst-ungetc use libsupport
Siddhesh Poyarekar [Wed, 14 Aug 2024 23:20:04 +0000 (19:20 -0400)]
Make tst-ungetc use libsupport

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 3f7df7e757f4efec38e45d4068e5492efcac4856)

2 months agostdio-common: Add test for vfscanf with matches longer than INT_MAX [BZ #27650]
Maciej W. Rozycki [Fri, 26 Jul 2024 12:21:34 +0000 (13:21 +0100)]
stdio-common: Add test for vfscanf with matches longer than INT_MAX [BZ #27650]

Complement commit b03e4d7bd25b ("stdio: fix vfscanf with matches longer
than INT_MAX (bug 27650)") and add a test case for the issue, inspired
by the reproducer provided with the bug report.

This has been verified to succeed as from the commit referred and fail
beforehand.

As the test requires 2GiB of data to be passed around its performance
has been evaluated using a choice of systems and the execution time
determined to be respectively in the range of 9s for POWER9@2.166GHz,
24s for FU740@1.2GHz, and 40s for 74Kf@950MHz.  As this is on the verge
of and beyond the default timeout it has been increased by the factor of
8.  Regardless, following recent practice the test has been added to the
standard rather than extended set.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 89cddc8a7096f3d9225868304d2bc0a1aaf07d63)

2 months agosupport: Add FAIL test failure helper
Maciej W. Rozycki [Fri, 26 Jul 2024 12:21:34 +0000 (13:21 +0100)]
support: Add FAIL test failure helper

Add a FAIL test failure helper analogous to FAIL_RET, that does not
cause the current function to return, providing a standardized way to
report a test failure with a message supplied while permitting the
caller to continue executing, for further reporting, cleaning up, etc.

Update existing test cases that provide a conflicting definition of FAIL
by removing the local FAIL definition and then as follows:

- tst-fortify-syslog: provide a meaningful message in addition to the
  file name already added by <support/check.h>; 'support_record_failure'
  is already called by 'support_print_failure_impl' invoked by the new
  FAIL test failure helper.

- tst-ctype: no update to FAIL calls required, with the name of the file
  and the line number within of the failure site additionally included
  by the new FAIL test failure helper, and error counting plus count
  reporting upon test program termination also already provided by
  'support_record_failure' and 'support_report_failure' respectively,
  called by 'support_print_failure_impl' and 'adjust_exit_status' also
  respectively.  However in a number of places 'printf' is called and
  the error count adjusted by hand, so update these places to make use
  of FAIL instead.  And last but not least adjust the final summary just
  to report completion, with any error count following as reported by
  the test driver.

- test-tgmath2: no update to FAIL calls required, with the name of the
  file of the failure site additionally included by the new FAIL test
  failure helper.  Also there is no need to track the return status by
  hand as any call to FAIL will eventually cause the test case to return
  an unsuccesful exit status regardless of the return status from the
  test function, via a call to 'adjust_exit_status' made by the test
  driver.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 1b97a9f23bf605ca608162089c94187573fb2a9e)

2 months agostring: strerror, strsignal cannot use buffer after dlmopen (bug 32026)
Florian Weimer [Mon, 19 Aug 2024 13:48:03 +0000 (15:48 +0200)]
string: strerror, strsignal cannot use buffer after dlmopen (bug 32026)

Secondary namespaces have a different malloc.  Allocating the
buffer in one namespace and freeing it another results in
heap corruption.  Fix this by using a static string (potentially
translated) in secondary namespaces.  It would also be possible
to use the malloc from the initial namespace to manage the
buffer, but these functions would still not be safe to use in
auditors etc. because a call to strerror could still free a
buffer while it is used by the application.  Another approach
could use proper initial-exec TLS, duplicated in secondary
namespaces, but that would need a callback interface for freeing
libc resources in namespaces on thread exit, which does not exist
today.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 25a5eb4010df94b412c67db9e346029de316d06b)

2 months agoDefine __libc_initial for the static libc
Florian Weimer [Fri, 9 Aug 2024 14:17:14 +0000 (16:17 +0200)]
Define __libc_initial for the static libc

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit eb0e50e9a1cf80a2ba6f33f990a08ef37a3267fb)

2 months agox86: Fix bug in strchrnul-evex512 [BZ #32078]
Noah Goldstein [Tue, 13 Aug 2024 15:29:14 +0000 (23:29 +0800)]
x86: Fix bug in strchrnul-evex512 [BZ #32078]

Issue was we were expecting not matches with CHAR before the start of
the string in the page cross case.

The check code in the page cross case:
```
    and    $0xffffffffffffffc0,%rax
    vmovdqa64 (%rax),%zmm17
    vpcmpneqb %zmm17,%zmm16,%k1
    vptestmb %zmm17,%zmm17,%k0{%k1}
    kmovq  %k0,%rax
    inc    %rax
    shr    %cl,%rax
    je     L(continue)
```

expects that all characters that neither match null nor CHAR will be
1s in `rax` prior to the `inc`. Then the `inc` will overflow all of
the 1s where no relevant match was found.

This is incorrect in the page-cross case, as the
`vmovdqa64 (%rax),%zmm17` loads from before the start of the input
string.

If there are matches with CHAR before the start of the string, `rax`
won't properly overflow.

The fix is quite simple. Just replace:

```
    inc    %rax
    shr    %cl,%rax
```
With:
```
    sar    %cl,%rax
    inc    %rax
```

The arithmetic shift will clear any matches prior to the start of the
string while maintaining the signbit so the 1s can properly overflow
to zero in the case of no matches.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit 7da08862471dfec6fdae731c2a5f351ad485c71f)

2 months agox32/cet: Support shadow stack during startup for Linux 6.10
H.J. Lu [Tue, 23 Jul 2024 00:47:22 +0000 (17:47 -0700)]
x32/cet: Support shadow stack during startup for Linux 6.10

Use RXX_LP in RTLD_START_ENABLE_X86_FEATURES.  Support shadow stack during
startup for Linux 6.10:

commit 2883f01ec37dd8668e7222dfdb5980c86fdfe277
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Mar 15 07:04:33 2024 -0700

    x86/shstk: Enable shadow stacks for x32

    1. Add shadow stack support to x32 signal.
    2. Use the 64-bit map_shadow_stack syscall for x32.
    3. Set up shadow stack for x32.

Add the map_shadow_stack system call to <fixup-asm-unistd.h> and regenerate
arch-syscall.h.  Tested on Intel Tiger Lake with CET enabled x32.  There
are no regressions with CET enabled x86-64.  There are no changes in CET
enabled x86-64 _dl_start_user.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 8344c1f5514b1b5b1c8c6e48f4b802653bd23b71)

2 months agox86-64: Remove sysdeps/x86_64/x32/dl-machine.h
H.J. Lu [Tue, 23 Jul 2024 00:47:21 +0000 (17:47 -0700)]
x86-64: Remove sysdeps/x86_64/x32/dl-machine.h

Remove sysdeps/x86_64/x32/dl-machine.h by folding x32 ARCH_LA_PLTENTER,
ARCH_LA_PLTEXIT and RTLD_START into sysdeps/x86_64/dl-machine.h.  There
are no regressions on x86-64 nor x32.  There are no changes in x86-64
_dl_start_user.  On x32, _dl_start_user changes are

 <_dl_start_user>:
  mov    %eax,%r12d
+ mov    %esp,%r13d
  mov    (%rsp),%edx
  mov    %edx,%esi
- mov    %esp,%r13d
  and    $0xfffffff0,%esp
  mov    0x0(%rip),%edi        # <_dl_start_user+0x14>
  lea    0x8(%r13,%rdx,4),%ecx

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 652c6cf26927352fc0e37e4e60c6fc98ddf6d3b4)

2 months agosupport: Add options list terminator to the test driver
Florian Weimer [Fri, 9 Aug 2024 15:01:17 +0000 (17:01 +0200)]
support: Add options list terminator to the test driver

This avoids crashes if a test is passed unknown options.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit c2a474f4617ede7a8bf56b7257acb37dc757b2d1)

3 months agomanual/stdio: Further clarify putc, putwc, getc, and getwc
Arjun Shankar [Tue, 30 Jul 2024 09:37:57 +0000 (11:37 +0200)]
manual/stdio: Further clarify putc, putwc, getc, and getwc

This is a follow-up to 10de4a47ef3f481592e3c62eb07bcda23e9fde4d that
reworded the manual entries for putc and putwc and removed any
performance claims.

This commit further clarifies these entries and brings getc and getwc in
line with the descriptions of putc and putwc, removing any performance
claims from them as well.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 942670c81dc8071dd75d6213e771daa5d2084cb6)

3 months agoFix name space violation in fortify wrappers (bug 32052)
Andreas Schwab [Mon, 5 Aug 2024 08:55:51 +0000 (10:55 +0200)]
Fix name space violation in fortify wrappers (bug 32052)

Rename the identifier sz to __sz everywhere.

Fixes: a643f60c53 ("Make sure that the fortified function conditionals are constant")
(cherry picked from commit 39ca997ab378990d5ac1aadbaa52aaf1db6d526f)

3 months agox86: Tunables may incorrectly set Prefer_PMINUB_for_stringop (bug 32047)
Florian Weimer [Fri, 2 Aug 2024 13:22:14 +0000 (15:22 +0200)]
x86: Tunables may incorrectly set Prefer_PMINUB_for_stringop (bug 32047)

Fixes commit 5bcf6265f215326d14dfacdce8532792c2c7f8f8 ("x86:
Disable non-temporal memset on Skylake Server").

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 7a630f7d3392ca391a399486ce2846f9e4b4ee63)

3 months agoresolv: Fix tst-resolv-short-response for older GCC (bug 32042)
Florian Weimer [Thu, 1 Aug 2024 08:46:10 +0000 (10:46 +0200)]
resolv: Fix tst-resolv-short-response for older GCC (bug 32042)

Previous GCC versions do not support the C23 change that
allows labels on declarations.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit ec119972cb2598c04ec7d4219e20506006836f64)

3 months agoAdd mremap tests
H.J. Lu [Wed, 24 Jul 2024 21:05:15 +0000 (14:05 -0700)]
Add mremap tests

Add tests for MREMAP_MAYMOVE and MREMAP_FIXED.  On Linux, also test
MREMAP_DONTUNMAP.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit ff0320bec2810192d453c579623482fab87bfa01)

3 months agomremap: Update manual entry
H.J. Lu [Wed, 24 Jul 2024 21:05:14 +0000 (14:05 -0700)]
mremap: Update manual entry

Update mremap manual entry:

1. Change mremap to variadic.
2. Document MREMAP_FIXED and MREMAP_DONTUNMAP.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit cb2dee4eccf46642eef588bee64f9c875c408f1c)

3 months agolinux: Update the mremap C implementation [BZ #31968]
H.J. Lu [Wed, 24 Jul 2024 21:05:13 +0000 (14:05 -0700)]
linux: Update the mremap C implementation [BZ #31968]

Update the mremap C implementation to support the optional argument for
MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct
to implement a variadic function as a non-variadic function on all Linux
targets.  Return MAP_FAILED and set errno to EINVAL for unknown flag bits.
This fixes BZ #31968.

Note: A test must be added when a new flag bit is introduced.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 6c40cb0e9f893d49dc7caee580a055de53562206)

3 months agoEnhanced test coverage for strncmp, wcsncmp
Florian Weimer [Thu, 27 Jun 2024 14:26:56 +0000 (16:26 +0200)]
Enhanced test coverage for strncmp, wcsncmp

Add string/test-strncmp-nonarray and
wcsmbs/test-wcsncmp-nonarray.

This is the test that uncovered bug 31934.  Test run time
is more than one minute on a fairly current system, so turn
these into xtests that do not run automatically.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 54252394c25ddf0062e288d4a6ab7a885f8ae009)

3 months agoEnhance test coverage for strnlen, wcsnlen
Florian Weimer [Wed, 26 Jun 2024 09:27:54 +0000 (11:27 +0200)]
Enhance test coverage for strnlen, wcsnlen

This commit adds string/test-strnlen-nonarray and
wcsmbs/test-wcsnlen-nonarray.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 783d4c0b81889c39a9ddf13b60d0fde4040fb1c0)

3 months agomanual: make setrlimit() description less ambiguous
Lukas Bulwahn [Mon, 29 Jul 2024 09:08:17 +0000 (11:08 +0200)]
manual: make setrlimit() description less ambiguous

The existing description for setrlimit() has some ambiguity. It could be
understood to have the semantics of getrlimit(), i.e., the limits from the
process are stored in the provided rlp pointer.

Make the description more explicit that rlp are the input values, and that
the limits of the process is changed with this function.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit aedbf08891069fc029ed021e4dba933eb877b394)

3 months agomanual/stdio: Clarify putc and putwc
Arjun Shankar [Mon, 29 Jul 2024 12:30:59 +0000 (14:30 +0200)]
manual/stdio: Clarify putc and putwc

The manual entry for `putc' described what "most systems" do instead of
describing the glibc implementation and its guarantees.  This commit
fixes that by warning that putc may be implemented as a macro that
double-evaluates `stream', and removing the performance claim.

Even though the current `putc' implementation does not double-evaluate
`stream', offering this obscure guarantee as an extension to what
POSIX allows does not seem very useful.

The entry for `putwc' is also edited to bring it in line with `putc'.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 10de4a47ef3f481592e3c62eb07bcda23e9fde4d)

3 months agomalloc: add multi-threaded tests for aligned_alloc/calloc/malloc
Miguel Martín [Tue, 16 Jul 2024 15:14:57 +0000 (17:14 +0200)]
malloc: add multi-threaded tests for aligned_alloc/calloc/malloc

Improve aligned_alloc/calloc/malloc test coverage by adding
multi-threaded tests with random memory allocations and with/without
cross-thread memory deallocations.

Perform a number of memory allocation calls with random sizes limited
to 0xffff.

Use the existing DSO ('malloc/tst-aligned_alloc-lib.c') to randomize
allocator selection.

The multi-threaded allocation/deallocation is staged as described below:

- Stage 1: Half of the threads will be allocating memory and the
  other half will be waiting for them to finish the allocation.
- Stage 2: Half of the threads will be allocating memory and the
  other half will be deallocating memory.
- Stage 3: Half of the threads will be deallocating memory and the
  second half waiting on them to finish.

Add 'malloc/tst-aligned-alloc-random-thread.c' where each thread will
deallocate only the memory that was previously allocated by itself.

Add 'malloc/tst-aligned-alloc-random-thread-cross.c' where each thread
will deallocate memory that was previously allocated by another thread.

The intention is to be able to utilize existing malloc testing to ensure
that similar allocation APIs are also exposed to the same rigors.
Reviewed-by: Arjun Shankar <arjun@redhat.com>
(cherry picked from commit b0fbcb7d0051a68baf26b2aed51a8a31c34d68e5)

3 months agomalloc: avoid global locks in tst-aligned_alloc-lib.c
Miguel Martín [Tue, 16 Jul 2024 15:14:56 +0000 (17:14 +0200)]
malloc: avoid global locks in tst-aligned_alloc-lib.c

Make sure the DSO used by aligned_alloc/calloc/malloc tests does not get
a global lock on multithreaded tests.
Reviewed-by: Arjun Shankar <arjun@redhat.com>
(cherry picked from commit 9a27b566b2048f599048f2f4afe1cce06c4ef43d)

3 months agoFix version number in NEWS file
Florian Weimer [Wed, 24 Jul 2024 11:42:16 +0000 (13:42 +0200)]
Fix version number in NEWS file

3 months agomanual: Do not mention STATIC_TLS in dynamic linker hardening recommendations
Florian Weimer [Wed, 24 Jul 2024 10:50:17 +0000 (12:50 +0200)]
manual: Do not mention STATIC_TLS in dynamic linker hardening recommendations

The current toolchain does not consistently generate it, and
glibc does not use it.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
(cherry picked from commit 90842d3980064ef410b998b22170ad409b76b9fd)

3 months agoresolv: Do not wait for non-existing second DNS response after error (bug 30081)
Florian Weimer [Wed, 24 Jul 2024 10:06:47 +0000 (12:06 +0200)]
resolv: Do not wait for non-existing second DNS response after error (bug 30081)

In single-request mode, there is no second response after an error
because the second query has not been sent yet.  Waiting for it
introduces an unnecessary timeout.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit af625987d619388a100b153520d3ee308bda9889)

3 months agoresolv: Allow short error responses to match any query (bug 31890)
Florian Weimer [Wed, 24 Jul 2024 10:06:47 +0000 (12:06 +0200)]
resolv: Allow short error responses to match any query (bug 31890)

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 691a3b2e9bfaba842e46a5ccb7f5e6ea144c3ade)

3 months agoReplace advisories directory
Andreas K. Hüttel [Sun, 21 Jul 2024 17:02:10 +0000 (19:02 +0200)]
Replace advisories directory

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoAdd ChangeLog file glibc-2.40
Andreas K. Hüttel [Sun, 21 Jul 2024 16:33:37 +0000 (18:33 +0200)]
Add ChangeLog file

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoIncrease version number to 2.40
Andreas K. Hüttel [Sun, 21 Jul 2024 16:23:25 +0000 (18:23 +0200)]
Increase version number to 2.40

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agopo/*: regenerate (only line number changes)
Andreas K. Hüttel [Sun, 21 Jul 2024 15:50:35 +0000 (17:50 +0200)]
po/*: regenerate (only line number changes)

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agocontrib.texi: Fix format of MIPS and RISC-V
Andreas K. Hüttel [Sun, 21 Jul 2024 12:12:30 +0000 (14:12 +0200)]
contrib.texi: Fix format of MIPS and RISC-V

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agolibc.pot: regenerate (only line number changes)
Andreas K. Hüttel [Sat, 20 Jul 2024 22:33:43 +0000 (00:33 +0200)]
libc.pot: regenerate (only line number changes)

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoinstall.texi: bump "latest verified" versions
Andreas K. Hüttel [Sat, 20 Jul 2024 22:27:35 +0000 (00:27 +0200)]
install.texi: bump "latest verified" versions

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoNEWS: drop 2.40 section "Changes to build and runtime requirements"
Andreas K. Hüttel [Sat, 20 Jul 2024 21:42:05 +0000 (23:42 +0200)]
NEWS: drop 2.40 section "Changes to build and runtime requirements"

Can't find anything that should go here.

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agocontrib.texi: update
Andreas K. Hüttel [Sat, 20 Jul 2024 17:47:52 +0000 (19:47 +0200)]
contrib.texi: update

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoNEWS: add fixed security advisories list
Andreas K. Hüttel [Sat, 20 Jul 2024 16:55:07 +0000 (18:55 +0200)]
NEWS: add fixed security advisories list

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoNEWS: add resolved bugs list
Andreas K. Hüttel [Sat, 20 Jul 2024 16:52:15 +0000 (18:52 +0200)]
NEWS: add resolved bugs list

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoNEWS: add more major improvements for 2.40
Andreas K. Hüttel [Sat, 20 Jul 2024 14:22:54 +0000 (16:22 +0200)]
NEWS: add more major improvements for 2.40

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agolinux: Trivial test output fix in tst-pkey
Andreas K. Hüttel [Fri, 19 Jul 2024 20:57:23 +0000 (22:57 +0200)]
linux: Trivial test output fix in tst-pkey

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoelf: Fix localplt.awk for DT_RELR-enabled builds (BZ 31978)
Adhemerval Zanella [Tue, 16 Jul 2024 10:57:45 +0000 (07:57 -0300)]
elf: Fix localplt.awk for DT_RELR-enabled builds (BZ 31978)

For each input readelf output, localplt.awk parses each 'Relocation
section' entry, checks its offset against the dynamic section entry, and
saves each DT_JMPREL, DT_RELA, and DT_REL offset value it finds. After
all lines are read, the script checks if any segment offset differed
from 0, meaning at least one 'Relocation section' was matched.

However, if the shared object was built with RELR support and the static
linker could place all the relocation on DT_RELR, there would be no
DT_JMPREL, DT_RELA, and DT_REL entries; only a DT_RELR.

For the current three ABIs that support (aarch64, x86, and powerpc64),
the powerpc64 ld.so shows the behavior above. Both x86_64 and aarch64
show extra relocations on '.rela.dyn', which makes the script check to
succeed.

This patch fixes by handling DT_RELR, where the offset is checked
against the dynamic section entries and if the shared object contains an
entry it means that there are no extra PLT entries (since all
relocations are relative).

It fixes the elf/check-localplt failure on powerpc.

Checked with a build/check for aarch64-linux-gnu, x86_64-linux-gnu,
i686-linux-gnu, arm-linux-gnueabihf, s390x-linux-gnu, powerpc-linux-gnu,
powerpc64-linux-gnu, and powerpc64le-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 months agolinux: Also check pkey_get for ENOSYS on tst-pkey (BZ 31996)
Adhemerval Zanella [Fri, 19 Jul 2024 14:23:15 +0000 (11:23 -0300)]
linux: Also check pkey_get for ENOSYS on tst-pkey (BZ 31996)

The powerpc pkey_get/pkey_set support was only added for 64-bit [1],
and tst-pkey only checks if the support was present with pkey_alloc
(which does not fail on powerpc32, at least running a 64-bit kernel).

Checked on powerpc-linux-gnu.

[1] https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a803367bab167f5ec4fde1f0d0ec447707c29520
Reviewed-By: Andreas K. Huettel <dilfridge@gentoo.org>
3 months agopowerpc: Update soft-fp ulps
Adhemerval Zanella [Fri, 19 Jul 2024 14:22:58 +0000 (11:22 -0300)]
powerpc: Update soft-fp ulps

Results based on regen-ulps using gcc 11.2.1 on a POWER8 machine.

3 months agoFix usage of _STACK_GROWS_DOWN and _STACK_GROWS_UP defines [BZ 31989]
John David Anglin [Fri, 19 Jul 2024 14:10:17 +0000 (10:10 -0400)]
Fix usage of _STACK_GROWS_DOWN and _STACK_GROWS_UP defines [BZ 31989]

Signed-off-by: John David Anglin <dave.anglin@bell.net>
Reviewed-By: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agoAdjust check-local-headers test for libaudit 4.0
Florian Weimer [Fri, 19 Jul 2024 13:57:46 +0000 (15:57 +0200)]
Adjust check-local-headers test for libaudit 4.0

The new version introduces /usr/include/audit_logging.h and
/usr/include/audit-records.h.

3 months agoelf: Parse the auxv values as unsigned on tst-tunables-enable_secure-env.c (BZ 31890)
Adhemerval Zanella [Thu, 18 Jul 2024 12:15:44 +0000 (09:15 -0300)]
elf: Parse the auxv values as unsigned on tst-tunables-enable_secure-env.c (BZ 31890)

AT_HWCAP on some architecture can indeed use all bits.

Checked on x86_64-linux-gnu and powerpc-linux-gnu.
Reviewed-By: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agox32: xfail elf/tst-platform-1 [BZ #22363]
H.J. Lu [Thu, 18 Jul 2024 22:23:50 +0000 (15:23 -0700)]
x32: xfail elf/tst-platform-1 [BZ #22363]

Xfail elf/tst-platform-1 on x32 since kernel passes i686 in AT_PLATFORM.
See https://sourceware.org/bugzilla/show_bug.cgi?id=22363

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
3 months agoelf/tst-rtld-does-not-exist: Pass --inhibit-cache to rtld
Xi Ruoyao [Wed, 17 Jul 2024 10:09:15 +0000 (18:09 +0800)]
elf/tst-rtld-does-not-exist: Pass --inhibit-cache to rtld

This avoids a test failure when the system has no /etc/ld.so.cache.

Tested on x86_64-linux-gnu.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agoRevert "LoongArch: Add cfi instructions for _dl_tlsdesc_dynamic"
Andreas K. Hüttel [Wed, 17 Jul 2024 13:19:47 +0000 (15:19 +0200)]
Revert "LoongArch: Add cfi instructions for _dl_tlsdesc_dynamic"

We're in freeze for the 2.40 release.

This reverts commit 43224b1379d60b1ad98d29ef3d7905d55f828a9f.

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agohtl: Fix __pthread_init_thread declaration and definition
Samuel Thibault [Wed, 17 Jul 2024 12:56:14 +0000 (14:56 +0200)]
htl: Fix __pthread_init_thread declaration and definition

0e75c4a4634f ("hurd: Fix pthread_self() without libpthread") added a
declaration for ___pthread_init_thread instead of __pthread_init_thread,
and missed defining the external hidden symbol.

3 months agohurd: Fix pthread_self() without libpthread
Samuel Thibault [Wed, 17 Jul 2024 12:06:25 +0000 (14:06 +0200)]
hurd: Fix pthread_self() without libpthread

5476f8cd2e68 ("htl: move pthread_self info libc.") moved the htl
pthread_self() function from libpthread to libc, replacing the previous libc
stub that just returns 0. And 53da64d1cf36 ("htl: Initialize ___pthread_self
early") added initialization code which is needed before being able to
call pthread_self. It is currently in libpthread, and thus never called
before programs can call pthread_self from libc, which then segfaults
when accessing _pthread_self()->thread.

This moves the initialization to libc itself, as initialized variables, so
pthread_self can always be called fine.

3 months agoLoongArch: Add cfi instructions for _dl_tlsdesc_dynamic
mengqinggang [Fri, 5 Jul 2024 02:40:33 +0000 (10:40 +0800)]
LoongArch: Add cfi instructions for _dl_tlsdesc_dynamic

In _dl_tlsdesc_dynamic, there are three 'addi.d sp, sp, -size'
instructions to allocate stack size for Float/LSX/LASX registers.
Every 'addi.d sp, sp, -size' needs a cfi_adjust_cfa_offset because
of sp is used to compute CFA. But only one 'addi.d sp, sp, -size'
will be run according to HWCAP value. And all cfi_adjust_cfa_offset
will be executed in stack unwinding, it result in incorrect CFA.

Change _dl_tlsdesc_dynamic to _dl_tlsdesc_dynamic,
_dl_tlsdesc_dynamic_lsx and _dl_tlsdesc_dynamic_lasx.
Conflicting cfi instructions can be distributed to the three functions.
And cfi instructions can correspond to stack down instructions.

3 months agox86: Disable non-temporal memset on Skylake Server
Noah Goldstein [Mon, 15 Jul 2024 08:19:17 +0000 (16:19 +0800)]
x86: Disable non-temporal memset on Skylake Server

The original commit enabling non-temporal memset on Skylake Server had
erroneous benchmarks (actually done on ICX).

Further benchmarks indicate non-temporal stores may in fact by a
regression on Skylake Server.

This commit may be over-cautious in some cases, but should avoid any
regressions for 2.40.

Tested using qemu on all x86_64 cpu arch supported by both qemu +
GLIBC.

Reviewed-by: DJ Delorie <dj@redhat.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 months agoAdd pthread_getname_np and pthread_setname_np for Hurd
Flavio Cruz [Thu, 11 Jul 2024 22:37:35 +0000 (23:37 +0100)]
Add pthread_getname_np and pthread_setname_np for Hurd

We use thread_get_name and thread_set_name to get and set the thread
name, so nothing is stored in the thread structure since these functions
are supposed to be called sparingly.

One notable difference with Linux is that the thread name is up to 32
chars, whereas Linux's is 16.

Also added a mach_RPC_CHECK to check for the existing of gnumach RPCs.

3 months agomath: Update alpha ulps
Andreas K. Hüttel [Sun, 14 Jul 2024 10:44:15 +0000 (12:44 +0200)]
math: Update alpha ulps

Linux alphadev 6.9.8-gentoo-alpha #1 Sun Jul  7 00:45:49 EDT 2024 alpha EV68CB Titan GNU/Linux
gcc (Gentoo 14.1.1_p20240622 p2) 14.1.1 20240622
GNU ld (Gentoo 2.42 p6) 2.42.0

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agohurd: Fix restoring message to be retried
Samuel Thibault [Sat, 13 Jul 2024 15:00:55 +0000 (17:00 +0200)]
hurd: Fix restoring message to be retried

save_data stores the start of the original message to be retried,
overwritten by the EINTR reply. In 64b builds the overwrite is however
rounded up to the 64b pointer size, so we have to save more than just
the 32b err.

Thanks a lot to Luca Dariz for the investigation!

3 months agonptl: Convert tst-sem11 and tst-sem12 tests to use the test driver
Maciej W. Rozycki [Thu, 11 Jul 2024 13:17:20 +0000 (14:17 +0100)]
nptl: Convert tst-sem11 and tst-sem12 tests to use the test driver

Fix an issue with commit 2af4e3e5668f ("Test of semaphores.") by making
the tst-sem11 and tst-sem12 tests use the test driver, preventing them
from ever causing testing to hang forever and never complete, such as
currently happening with the 'mips-linux-gnu' (o32 ABI) target.  Adjust
the name of the PREPARE macro, which clashes with the interpretation of
its presence by the test driver, by using a TF_ prefix in reference to
the name of the 'tf' function.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agonptl: Add copyright notice tst-sem11 and tst-sem12 tests
Maciej W. Rozycki [Thu, 11 Jul 2024 13:17:15 +0000 (14:17 +0100)]
nptl: Add copyright notice tst-sem11 and tst-sem12 tests

Add a copyright notice to the tst-sem11 and tst-sem12 tests, observing
that they have been originally contributed back in 2007, with commit
2af4e3e5668f ("Test of semaphores.").
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agotests: XFAIL audit tests failing on all mips configurations, bug 29404
Andreas K. Hüttel [Fri, 12 Jul 2024 16:36:44 +0000 (18:36 +0200)]
tests: XFAIL audit tests failing on all mips configurations, bug 29404

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agotime/Makefile: Split and sort tests
Samuel Dobron [Thu, 11 Jul 2024 03:31:11 +0000 (05:31 +0200)]
time/Makefile: Split and sort tests

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 months agos390x: Fix segfault in wcsncmp [BZ #31934]
Stefan Liebler [Thu, 11 Jul 2024 09:28:53 +0000 (11:28 +0200)]
s390x: Fix segfault in wcsncmp [BZ #31934]

The z13/vector-optimized wcsncmp implementation segfaults if n=1
and there is only one character (equal on both strings) before
the page end.  Then it loads and compares one character and misses
to check n again.  The following load fails.

This patch removes the extra load and compare of the first character
and just start with the loop which uses vector-load-to-block-boundary.
This code-path also checks n.

With this patch both tests are passing:
- the simplified one mentioned in the bugzilla 31934
- the full one in Florian Weimer's patch:
"manual: Document a GNU extension for strncmp/wcsncmp"
(https://patchwork.sourceware.org/project/glibc/patch/874j9eml6y.fsf@oldenburg.str.redhat.com/):
On s390x-linux-gnu (z16), the new wcsncmp test fails due to bug 31934.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 months agoLinux: Make __rseq_size useful for feature detection (bug 31965)
Florian Weimer [Mon, 8 Jul 2024 19:14:00 +0000 (21:14 +0200)]
Linux: Make __rseq_size useful for feature detection (bug 31965)

The __rseq_size value is now the active area of struct rseq
(so 20 initially), not the full struct size including padding
at the end (32 initially).

Update misc/tst-rseq to print some additional diagnostics.

Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 months agopo: incorporate translations (bg)
Andreas K. Hüttel [Tue, 9 Jul 2024 11:35:12 +0000 (13:35 +0200)]
po: incorporate translations (bg)

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
3 months agomanual: add syscalls
DJ Delorie [Mon, 8 Jul 2024 21:52:15 +0000 (17:52 -0400)]
manual: add syscalls

The purpose of this patch is to add some system calls that (1) aren't
otherwise documented, and (2) are merely redirected to the kernel, so
can refer to their documentation; and define a standard way of doing
so in the future.  A more detailed explaination of how system calls
are wrapped is added along with reference to the Linux Man-Pages
project.

Default version of man-pages is in configure.ac but can be overridden
by --with-man-pages=X.Y

Reviewed-by: Alejandro Colomar <alx@kernel.org>
3 months agolibio: handle opening a file when all files are closed (bug 31963)
Andreas Schwab [Mon, 8 Jul 2024 13:52:35 +0000 (15:52 +0200)]
libio: handle opening a file when all files are closed (bug 31963)

_IO_list_all becomes NULL when all files (including standard files) are
closed.

4 months agoldconfig: Ignore all GDB extension files
Adam Sampson [Mon, 6 May 2024 17:16:33 +0000 (18:16 +0100)]
ldconfig: Ignore all GDB extension files

ldconfig already ignores files with the -gdb.py suffix, but GDB also
looks for -gdb.gdb and -gdb.scm files. These aren't as widely used, but
libguile at least comes with a -gdb.scm file.

Rename is_gdb_python_file to is_gdb_extension_file, and make it
recognise all three types of GDB extension.

Signed-off-by: Adam Sampson <ats@offog.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agoldconfig: Move endswithn into a new header file
Adam Sampson [Mon, 6 May 2024 17:16:32 +0000 (18:16 +0100)]
ldconfig: Move endswithn into a new header file

is_gdb_python_file is doing a similar test, so it can use this helper
function as well.

Signed-off-by: Adam Sampson <ats@offog.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agomath: Update m68k ULPs
Andreas K. Hüttel [Mon, 8 Jul 2024 19:51:03 +0000 (21:51 +0200)]
math: Update m68k ULPs

This hasn't been looked at for a loong time (already guessing from
the number of missing entries), and it ain't pretty.
There are some 9-ulps results for float.

- ZaZaZebra (qemu-system-m68k clone of PowerBook 190 system)
- GCC 13.3.1 20240614 (Gentoo 13.3.1_p20240614 p17)
- ld GNU ld (Gentoo 2.42 p6) 2.42.0
- Linux ZaZaZebra  4.19.0-5-m68k #1 Gentoo 4.19.37-5 (2019-06-19) m68k 68040 68040 GNU/Linux
- manual build
- ../glibc/configure --enable-fortify-source --prefix=/usr
- Tested by Immolo (via Andreas K. Hüttel)

Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
4 months agostdlib: fix arc4random fallback to /dev/urandom (BZ 31612)
Adhemerval Zanella [Fri, 5 Apr 2024 13:27:29 +0000 (10:27 -0300)]
stdlib: fix arc4random fallback to /dev/urandom (BZ 31612)

The __getrandom_nocancel used by __arc4random_buf uses
INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for
the return value instead of errno to fallback to /dev/urandom.

The malloc code now uses __getrandom_nocancel_nostatus, which uses
INTERNAL_SYSCALL_CALL, so there is no need to use the variant that does
not set errno (BZ#29624).

Checked on x86_64-linux-gnu.

Reviewed-by: Xi Ruoyao <xry111@xry111.site>
4 months agoelf: Make dl-rseq-symbols Linux only
Adhemerval Zanella [Thu, 4 Jul 2024 13:09:07 +0000 (10:09 -0300)]
elf: Make dl-rseq-symbols Linux only

And avoid a Hurd build failures.

Checked on x86_64-linux-gnu.

4 months agonptl: fix potential merge of __rseq_* relro symbols
Michael Jeanson [Wed, 3 Jul 2024 16:35:34 +0000 (12:35 -0400)]
nptl: fix potential merge of __rseq_* relro symbols

While working on a patch to add support for the extensible rseq ABI, we
came across an issue where a new 'const' variable would be merged with
the existing '__rseq_size' variable. We tracked this to the use of
'-fmerge-all-constants' which allows the compiler to merge identical
constant variables. This means that all 'const' variables in a compile
unit that are of the same size and are initialized to the same value can
be merged.

In this specific case, on 32 bit systems 'unsigned int' and 'ptrdiff_t'
are both 4 bytes and initialized to 0 which should trigger the merge.
However for reasons we haven't delved into when the attribute 'section
(".data.rel.ro")' is added to the mix, only variables of the same exact
types are merged. As far as we know this behavior is not specified
anywhere and could change with a new compiler version, hence this patch.

Move the definitions of these variables into an assembler file and add
hidden writable aliases for internal use. This has the added bonus of
removing the asm workaround to set the values on rseq registration.

Tested on Debian 12 with GCC 12.2.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoriscv: Update nofpu libm test ulps
Darius Rad [Wed, 3 Jul 2024 18:50:59 +0000 (14:50 -0400)]
riscv: Update nofpu libm test ulps

Fixes 32 test failures.

4 months agomanual: Recommendations for dynamic linker hardening
Florian Weimer [Thu, 2 May 2024 14:26:36 +0000 (16:26 +0200)]
manual: Recommendations for dynamic linker hardening

This new section in the manual provides recommendations for
use of glibc in environments with higher integrity requirements.
It's reflecting both current implementation shortcomings, and
challenges we inherit from ELF and psABI requirements.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
4 months agosocket: Add new test for shutdown
Sergey Kolosov [Tue, 25 Jun 2024 09:19:03 +0000 (11:19 +0200)]
socket: Add new test for shutdown

This commit adds shutdown test with SHUT_RD, SHUT_WR, SHUT_RDWR for an
UNIX socket connection.

Reviewed-by: DJ Delorie <dj@redhat.com>
4 months agoelf/rtld: Fix auxiliary vector for enable_secure
Stefan Liebler [Tue, 2 Jul 2024 13:25:20 +0000 (15:25 +0200)]
elf/rtld: Fix auxiliary vector for enable_secure

Starting with commit
59974938fe1f4add843f5325f78e2a7ccd8db853
elf/rtld: Count skipped environment variables for enable_secure

The new testcase elf/tst-tunables-enable_secure-env segfaults on s390 (31bit).
There _start parses the auxiliary vector for some additional checks.

Therefore it skips over the zeros after the environment variables ...
0x7fffac20:     0x7fffbd17      0x7fffbd32      0x7fffbd69      0x00000000
------------------------------------------------^^^last environment variable

... and then it parses the auxiliary vector and stops at AT_NULL.
0x7fffac30:     0x00000000      0x00000021      0x00000000      0x00000000
--------------------------------^^^AT_SYSINFO_EHDR--------------^^^AT_NULL
----------------^^^newp-----------------------------------------^^^oldp
Afterwards it tries to access AT_PHDR which points to somewhere and segfaults.

Due to not incorporating the skip_env variable in the computation of oldp
when shuffling down the auxv in rtld.c, it just copies one entry with AT_NULL
and value 0x00000021 and stops the loop.  In reality we have skipped
GLIBC_TUNABLES environment variable (=> skip_env=1). Thus we should copy from
here:
0x7fffac40:     0x00000021      0x7ffff000      0x00000010      0x007fffff
----------------^^^fixed-oldp

This patch fixes the computation of oldp when shuffling down auxiliary vector.
It also adds some checks in the testcase.  Those checks also fail on
s390x (64bit) and x86_64 without the fix.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agohppa/vdso: Provide 64-bit clock_gettime() vDSO only
John David Anglin [Tue, 2 Jul 2024 20:26:32 +0000 (16:26 -0400)]
hppa/vdso: Provide 64-bit clock_gettime() vDSO only

Adhemerval noticed that the gettimeofday() and 32-bit clock_gettime()
vDSO calls won't be used by glibc on hppa, so there is no need to
declare them.  Both syscalls will be emulated by utilizing return values
of the 64-bit clock_gettime() vDSO instead.

Signed-off-by: Helge Deller <deller@gmx.de>
Suggested-by: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
4 months agodebug: Fix clang open fortify wrapper (BZ 31927)
Adhemerval Zanella [Fri, 28 Jun 2024 19:20:15 +0000 (16:20 -0300)]
debug: Fix clang open fortify wrapper (BZ 31927)

The clang open fortify wrapper from 4228baef1a94e8bde84ad74 added
a restriction where open with 3 arguments where flags do not
contain O_CREAT or O_TMPFILE are handled as invalid.  They are
not invalid, since the third argument is ignored, and the gcc
wrapper also allows it.

Checked x86_64-linux-gnu and with a yocto build for some affected
packages.
Tested-by: “Khem Raj <raj.khen@gmail.com>”
4 months agoAdd --disable-static-c++-tests option [BZ #31797]
H.J. Lu [Thu, 20 Jun 2024 22:28:13 +0000 (15:28 -0700)]
Add --disable-static-c++-tests option [BZ #31797]

By default, if the C++ toolchain lacks support for static linking,
configure fails to find the C++ header files and the glibc build fails.
The --disable-static-c++-link-check option allows the glibc build to
finish, but static C++ tests will fail if the C++ toolchain doesn't
have the necessary static C++ libraries which may not be easily installed.
Add --disable-static-c++-tests option to skip the static C++ link check
and tests.  This fixes BZ #31797.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 months agoAdd --disable-static-c++-link-check option [BZ #31412]
H.J. Lu [Thu, 20 Jun 2024 22:28:12 +0000 (15:28 -0700)]
Add --disable-static-c++-link-check option [BZ #31412]

The current minimum GCC version of glibc build is GCC 6.2 or newer. But
building i686 glibc with GCC 6.4 on Fedora 40 failed since the C++ header
files couldn't be found which was caused by the static C++ link check
failure due to missing __divmoddi4 which was referenced in i686 libc.a
and added to GCC 7.  Add --disable-static-c++-link-check configure option
to disable the static C++ link test.  The newly built i686 libc.a can be
used by GCC 6.4 to create static C++ tests.  This fixes BZ #31412.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 months agoUpdate mmap() flags and errors lists
DJ Delorie [Fri, 10 May 2024 18:52:09 +0000 (14:52 -0400)]
Update mmap() flags and errors lists

Extend the list of MAP_* macros to include all macros available
to the average program (gcc -E -dM | grep MAP_*)

Extend the list of errno codes.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
4 months agoMIPSr6/math: Use builtin fma and fmaf
YunQiang Su [Thu, 20 Jun 2024 16:07:56 +0000 (00:07 +0800)]
MIPSr6/math: Use builtin fma and fmaf

MIPSr6 has MADDF.s/MADDF.d instructions, which are fused.

In MIPS ISA, double support can be subsetted.  Only FMAF is enabled
for this case.

* sysdeps/mips/fpu/math-use-builtins-fma.h

Signed-off-by: YunQiang Su <syq@gcc.gnu.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agoelf: Support recursive use of dynamic TLS in interposed malloc
Florian Weimer [Mon, 1 Jul 2024 15:42:04 +0000 (17:42 +0200)]
elf: Support recursive use of dynamic TLS in interposed malloc

It turns out that quite a few applications use bundled mallocs that
have been built to use global-dynamic TLS (instead of the recommended
initial-exec TLS).  The previous workaround from
commit afe42e935b3ee97bac9a7064157587777259c60e ("elf: Avoid some
free (NULL) calls in _dl_update_slotinfo") does not fix all
encountered cases unfortunatelly.

This change avoids the TLS generation update for recursive use
of TLS from a malloc that was called during a TLS update.  This
is possible because an interposed malloc has a fixed module ID and
TLS slot.  (It cannot be unloaded.)  If an initially-loaded module ID
is encountered in __tls_get_addr and the dynamic linker is already
in the middle of a TLS update, use the outdated DTV, thus avoiding
another call into malloc.  It's still necessary to update the
DTV to the most recent generation, to get out of the slow path,
which is why the check for recursion is needed.

The bookkeeping is done using a global counter instead of per-thread
flag because TLS access in the dynamic linker is tricky.

All this will go away once the dynamic linker stops using malloc
for TLS, likely as part of a change that pre-allocates all TLS
during pthread_create/dlopen.

Fixes commit d2123d68275acc0f061e73d5f86ca504e0d5a344 ("elf: Fix slow
tls access after dlopen [BZ #19924]").

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
4 months agoFix conditionals on mtrace-based tests (bug 31892)
Carlos O'Donell [Wed, 19 Jun 2024 15:48:05 +0000 (11:48 -0400)]
Fix conditionals on mtrace-based tests (bug 31892)

The conditionals for several mtrace-based tests in catgets, elf, libio,
malloc, misc, nptl, posix, and stdio-common were incorrect leading to
test failures when bootstrapping glibc without perl.

The correct conditional for mtrace-based tests requires three checks:
first checking for run-built-tests, then build-shared, and lastly that
PERL is not equal to "no" (missing perl).
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agosignal/Makefile: Split and sort tests
Michel Lind [Fri, 14 Jun 2024 13:45:48 +0000 (15:45 +0200)]
signal/Makefile: Split and sort tests

This will make it easier to add tests later; see also the test section
in malloc/Makefile that inspires this.

Signed-off-by: Michel Lind <salimma@fedoraproject.org>
Suggested-by: Arjun Shankar <arjun@redhat.com>
Reviewed-by: Arjun Shankar <arjun@redhat.com>
4 months agox86: Set default non_temporal_threshold for Zhaoxin processors
MayShao-oc [Sat, 29 Jun 2024 03:58:28 +0000 (11:58 +0800)]
x86: Set default non_temporal_threshold for Zhaoxin processors

Current 'non_temporal_threshold' set to 'non_temporal_threshold_lowbound'
on Zhaoxin processors without ERMS. The default
'non_temporal_threshold_lowbound' is too small for the KH-40000 and KX-7000
Zhaoxin processors, this patch updates the value to
'shared / cachesize_non_temporal_divisor'.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
4 months agox86_64: Optimize large size copy in memmove-ssse3
MayShao-oc [Sat, 29 Jun 2024 03:58:27 +0000 (11:58 +0800)]
x86_64: Optimize large size copy in memmove-ssse3

This patch optimizes large size copy using normal store when src > dst
and overlap.  Make it the same as the logic in memmove-vec-unaligned-erms.S.

Current memmove-ssse3 use '__x86_shared_cache_size_half' as the non-
temporal threshold, this patch updates that value to
'__x86_shared_non_temporal_threshold'.  Currently, the
__x86_shared_non_temporal_threshold is cpu-specific, and different CPUs
will have different values based on the related nt-benchmark results.
However, in memmove-ssse3, the nontemporal threshold uses
'__x86_shared_cache_size_half', which sounds unreasonable.

The performance is not changed drastically although shows overall
improvements without any major regressions or gains.

Results on Zhaoxin KX-7000:
bench-memcpy geometric_mean(N=20) New / Original: 0.999

bench-memcpy-random geometric_mean(N=20) New / Original: 0.999

bench-memcpy-large geometric_mean(N=20) New / Original: 0.978

bench-memmove geometric_mean(N=20) New / Original: 1.000

bench-memmmove-large geometric_mean(N=20) New / Original: 0.962

Results on Intel Core i5-6600K:
bench-memcpy geometric_mean(N=20) New / Original: 1.001

bench-memcpy-random geometric_mean(N=20) New / Original: 0.999

bench-memcpy-large geometric_mean(N=20) New / Original: 1.001

bench-memmove geometric_mean(N=20) New / Original: 0.995

bench-memmmove-large geometric_mean(N=20) New / Original: 0.936
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
4 months agox86: Set preferred CPU features on the KH-40000 and KX-7000 Zhaoxin processors
MayShao-oc [Sat, 29 Jun 2024 03:58:26 +0000 (11:58 +0800)]
x86: Set preferred CPU features on the KH-40000 and KX-7000 Zhaoxin processors

Fix code formatting under the Zhaoxin branch and add comments for
different Zhaoxin models.

Unaligned AVX load are slower on KH-40000 and KX-7000, so disable
the AVX_Fast_Unaligned_Load.

Enable Prefer_No_VZEROUPPER and Fast_Unaligned_Load features to
use sse2_unaligned version of memset,strcpy and strcat.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
4 months agoAarch64: Add new memset for Qualcomm's oryon-1 core
Andrew Pinski [Wed, 12 Jun 2024 22:53:36 +0000 (15:53 -0700)]
Aarch64: Add new memset for Qualcomm's oryon-1 core

Qualcom's new core, oryon-1, has a different characteristics for
memset than the current versions of memset. For non-zero, larger
sizes, using GPRs rather than the SIMD stores is ~30% faster.
For even larger sizes, using the nontemporal stores is needed
not to polute the L1/L2 caches.

For zero values, using `dc zva` should be used. Since we
know the size will always be 64 bytes, we don't need to figure
out the size there.

I started with the emag memset and added back the `dc zva` code.

Changes since v1:
* v3: Fix comment formating

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agoAarch64: Add memcpy for qualcomm's oryon-1 core
Andrew Pinski [Wed, 12 Jun 2024 22:53:35 +0000 (15:53 -0700)]
Aarch64: Add memcpy for qualcomm's oryon-1 core

Qualcomm's new core (oryon-1) has a different performance characteristic
than other cores. For memcpy, it is faster to use the GPRs to
do the copy for large sizes (2x faster). For even larger sizes,
it is better to use the nontemporal load/store instructions so
we don't pollute the L1/L2 caches.

For smaller sizes, the characteristic are very similar to
other cores.
I used the thunderx memcpy as a starting point and expanded from there.

Changes since v1:
* v2: Fix ordering in Makefile.
* v3: Fix comment grammar about the ldnp/stnp instructions.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
4 months agodebug: Fix clang open fortify wrapper (BZ 31927)
Adhemerval Zanella [Tue, 25 Jun 2024 14:57:15 +0000 (11:57 -0300)]
debug: Fix clang open fortify wrapper (BZ 31927)

The fcntl.h fortify wrapper for clang added by 86889e22db329abac61
missed the __fortify_clang_overload_arg and and also added the
mode argument for the __fortify_function_error_function function,
which leads clang to be able to correct resolve which overloaded
function it should emit.

Checked on x86_64-linux-gnu.

Reported-by: Khem Raj <raj.khem@gmail.com>
Tested-by: Khem Raj <raj.khem@gmail.com>
This page took 0.113244 seconds and 5 git commands to generate.