Commit Graph

37368 Commits

Author SHA1 Message Date
Florian Weimer
d03511f48f nptl: Eliminate the __static_tls_size, __static_tls_align_m1 variables
Use the  __nptl_tls_static_size_for_stack inline function instead,
and the GLRO (dl_tls_static_align) value directly.

The computation of GLRO (dl_tls_static_align)  in
_dl_determine_tlsoffset ensures that the alignment is at least
TLS_TCB_ALIGN, which at least STACK_ALIGN (see allocate_stack).
Therefore, the additional rounding-up step is removed.

ALso move the initialization of the default stack size from
__pthread_initialize_minimal_internal to __pthread_early_init.
This introduces an extra system call during single-threaded startup,
but this simplifies the initialization sequence.  No locking is
needed around the writes to __default_pthread_attr because the
process is single-threaded at this point.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-21 22:35:00 +02:00
Florian Weimer
2f69522d46 nptl: Perform signal initialization upon pthread_create
Install signal handlers and unblock signals before pthread_create
creates the first thread.

create_thread in sysdeps/unix/sysv/linux/createthread.c can send
SIGCANCEL to the current thread, so the SIGCANCEL handler is currently
needed even if pthread_cancel is never called.  (The way timer_create
uses SIGCANCEL does not need a signal handler; both SIG_DFL and SIG_IGN
dispositions should work.)

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-21 22:35:00 +02:00
Florian Weimer
06a36b70f9 nptl: Remove unused __libc_pthread_init function
Fixes commit 732139dabe
("Linux: Move __reclaim_stacks into the fork implementation in
libc").
2021-05-21 12:09:07 +02:00
Noah Goldstein
6abf27980a x86: Improve memset-vec-unaligned-erms.S
No bug. This commit makes a few small improvements to
memset-vec-unaligned-erms.S. The changes are 1) only aligning to 64
instead of 128. Either alignment will perform equally well in a loop
and 128 just increases the odds of having to do an extra iteration
which can be significant overhead for small values. 2) Align some
targets and the loop. 3) Remove an ALU from the alignment process. 4)
Reorder the last 4x VEC so that they are stored after the loop. 5)
Move the condition for leq 8x VEC to before the alignment
process. test-memset and test-wmemset are both passing.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2021-05-20 17:28:33 -04:00
Florian Weimer
f5e196b5a0 Hurd: Define ARCH_MIN_GUARD_SIZE in internal <pthread.h>
This macro is always defined on Linux.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2021-05-20 18:56:57 +02:00
Florian Weimer
9ec7fff6cd elf: Initialize GLRO (dl_minsigstacksize) after static dlopen
This is another field of _rtld_global_ro that benefits from
initialization in __rtld_static_init.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2021-05-20 18:56:42 +02:00
Florian Weimer
eb0e4756cf nptl: Add missing __pthread_cond_wait alias in static builds
Fixes commit cf3fff1c19 ("nptl: Move
cnd_wait into libc").

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
2021-05-19 22:16:28 +02:00
Adhemerval Zanella
f294306ba1 Remove --enable-stackguard-randomization (BZ #27872)
Last ENABLE_STACKGUARD_RANDOMIZE usage was removed by 4a103975c4.
2021-05-19 10:22:19 -03:00
Florian Weimer
1805bf753f s390x: Check HWCAP bits against compiler flags
When compiled with GCC 11.1 and -march=z14 -O3 build flags, running
ld.so (or any dynamically linked program) prints:

Fatal glibc error: CPU lacks VXE support (z14 or later required)

Co-Authored-By: Stefan Liebler <stli@linux.ibm.com>
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
2021-05-19 11:09:57 +02:00
Florian Weimer
d337345ce1 powerpc64le: Check HWCAP bits against compiler build flags
When built with GCC 11.1 and -mcpu=power9, ld.so prints this error
message when running on POWER8:

Fatal glibc error: CPU lacks ISA 3.00 support (POWER9 or later required)
2021-05-19 11:09:57 +02:00
Florian Weimer
eb24865637 elf: Add hook for checking HWCAP bits after auxiliary vector parsing
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
2021-05-19 11:09:57 +02:00
Noah Goldstein
4ad473e97a x86: Optimize memcmp-evex-movbe.S
No bug. This commit optimizes memcmp-evex.S. The optimizations include
adding a new vec compare path for small sizes, reorganizing the entry
control flow, removing some unnecissary ALU instructions from the main
loop, and most importantly replacing the heavy use of vpcmp + kand
logic with vpxor + vptern. test-memcmp and test-wmemcmp are both
passing.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2021-05-18 22:57:51 -04:00
Noah Goldstein
16d12015c5 x86: Optimize memcmp-avx2-movbe.S
No bug. This commit optimizes memcmp-avx2.S. The optimizations include
adding a new vec compare path for small sizes, reorganizing the entry
control flow, and removing some unnecissary ALU instructions from the
main loop. test-memcmp and test-wmemcmp are both passing.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2021-05-18 22:57:44 -04:00
Noah Goldstein
e68d6fccca x86: Expand bench-memcmp.c and test-memcmp.c
No bug. This commit adds some additional performance test cases to
bench-memcmp.c and test-memcmp.c. The new benchtests include some
medium range sizes, as well as small sizes near page cross. The new
correctness tests correspond with the new benchtests though add some
additional cases for checking the page cross logic.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2021-05-18 22:57:39 -04:00
Adhemerval Zanella
3f500e7202 linux: Fix clock_getres fallback
The tst-timespec_getres (e5ac7bd679) triggers an issue on 32-bit
architecture on Linux older than 5.1, where the fallback syscall
is used.

Checked on powerpc-linux-gnu.
2021-05-18 16:59:56 -03:00
Joseph Myers
8382f4c3e5 Do not declare asctime_r and ctime_r for C2X
ISO C2X added the asctime_r, ctime_r, gmtime_r and localtime_r
functions from POSIX.  It's now removed asctime_r and ctime_r again,
reflecting that they are marked obsolescent in POSIX; update glibc's
time.h accordingly.

The same change that removed those two functions from C2X also marked
asctime and ctime as deprecated (reflecting how POSIX shows them as
obsolescent), i.e. using the [[deprecated]] attribute in the
prototypes shown in C2X.  It's less clear if we should explicitly
deprecate those functions like that in the glibc headers; this patch
does nothing regarding such a deprecation (there's no normative
requirement from C2X showing the functions as deprecated).

Tested for x86_64 and x86.
2021-05-18 19:47:49 +00:00
Samuel Thibault
af46a4d638 htl: Add __libpthread_freeres 2021-05-18 17:46:12 +00:00
Samuel Thibault
4d4bb451d5 hurd: Add execveat 2021-05-18 09:36:00 +00:00
Stefan Liebler
2457175e8b Fix stringop-overflow warning in bug-regex19.c.
Starting with commit
26492c0a14
"Annotate additional APIs with GCC attribute access.",
gcc emits this warning on s390x:
In function 'do_one_test',
    inlined from 'do_mb_tests' at bug-regex19.c:385:11:
bug-regex19.c:271:9: error: 're_search' specified size 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
  271 |   res = re_search (&regbuf, test->string, strlen (test->string),
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  272 |      test->start, strlen (test->string) - test->start, NULL);
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/regex.h:2,
                 from bug-regex19.c:22:
bug-regex19.c: In function 'do_mb_tests':
../posix/regex.h:554:17: note: in a call to function 're_search' declared with attribute 'read_only (2, 3)'
  554 | extern regoff_t re_search (struct re_pattern_buffer *__buffer,
      |                 ^~~~~~~~~
...

The function do_one_test is inlined into do_mb_tests on s390x (at least with
gcc 10).  If do_one_test is marked with __attribute__ ((noinline)), there are
no warnings on s390x. If do_one_test is marked with
__attribute__ ((always_inline)), there are the same warnings on x86_64.

test->string points to a variable length array on stack of do_mb_tests
and the content is generated based on the passed test struct.

According to Martin Sebor, this is a false positive caused by the same bug as
the one in nss/makedb.c.  It's fixed in GCC 11 and will also be available in
the next GCC 10.4 release.
2021-05-18 10:07:30 +02:00
Florian Weimer
f17164bd51 localedata: Use U+00AF MACRON in more EBCDIC charsets [BZ #27882]
This updates IBM256, IBM277, IBM278, IBM280, IBM284, IBM297, IBM424
in the same way that IBM273 was updated for bug 23290.

IBM256 and IBM424 still have holes after this change, so HAS_HOLES
is not updated.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2021-05-18 07:21:45 +02:00
Siddhesh Poyarekar
22866ed858 ldconfig: Avoid boolean coercion of opt_chroot
Generated code is unchanged.
2021-05-18 09:34:04 +05:30
Siddhesh Poyarekar
468d772e81 ldconfig: Fix memory leaks
Coverity discovered that paths allocated by chroot_canon are not freed
in a couple of routines in ldconfig.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-18 09:29:02 +05:30
Siddhesh Poyarekar
c8c3c5e89a charmap_conversion: Free conversion table on exit
The conversion table is allocated using xcalloc but never freed.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-18 09:25:40 +05:30
Siddhesh Poyarekar
a85cdcdb35 elf/cache.c: Fix resource leaks identified by static analyzers
A coverity run identified a number of resource leaks in cache.c.
There are a couple of simple memory leaks where a local allocation is
not freed before function return.  Then there is a mmap leak and a
file descriptor leak where a map is not unmapped in the error case and
a file descriptor remains open respectively.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-18 09:08:41 +05:30
Siddhesh Poyarekar
2317101658 show_archive_content: Fix trivial memory leak
Fix trivial leak identified by coverity.  The program runs to exit and
the leak doesn't grow, but it's just cleaner to free the allocated
memory.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-18 09:07:06 +05:30
Joseph Myers
e5ac7bd679 Add C2X timespec_getres
ISO C2X adds a timespec_getres function alongside the C11
timespec_get, with functionality similar to that of POSIX clock_getres
(including allowing a NULL pointer to be passed to the function).
Implement this function for glibc, similarly to the implementation of
timespec_get.

This includes a basic test like that of timespec_get, but no
documentation in the manual, given that TIME_UTC and timespec_get
aren't documented in the manual at all.  The handling of 64-bit time
follows that in timespec_get; people maintaining patch series for
64-bit time will need to update them accordingly (to export
__timespec_getres64, redirect calls in time.h and run the test for
_TIME_BITS=64).

Tested for x86_64 and x86, and (previous version; only testcase
differs) with build-many-glibcs.py.
2021-05-17 20:55:21 +00:00
Andreas Schwab
c6b6b4f2c7 Missing ENOMEM in realloc_check wrapper (bug 27870)
When MALLOC_CHECK_ is non-zero, the realloc hook missed to set errno to
ENOMEM when called with too big size.  Run the test tst-malloc-too-large
also with MALLOC_CHECK_=3 to catch that.
2021-05-17 21:39:23 +02:00
Matheus Castanho
f4605e611a benchtests: Use JSON for bench-rawmemchr output
Convert the output of benchtests/bench-rawmemchr to JSON like other string
benchmarks.  This makes the output more parseable and allows usage of
compare_strings.py, for example.

Reviewed-by: Lucas A. M. Magalhaes <lamm@linux.ibm.com>
2021-05-17 11:10:19 -03:00
Matheus Castanho
1a594aa986 powerpc: Add optimized rawmemchr for POWER10
Reuse code for optimized strlen to implement a faster version of rawmemchr.
This takes advantage of the same benefits provided by the strlen implementation,
but needs some extra steps. __strlen_power10 code should be unchanged after this
change.

rawmemchr returns a pointer to the char found, while strlen returns only the
length, so we have to take that into account when preparing the return value.

To quickly check 64B, the loop on __strlen_power10 merges the whole block into
16B by using unsigned minimum vector operations (vminub) and checks if there are
any \0 on the resulting vector. The same code is used by rawmemchr if the char c
is 0. However, this approach does not work when c != 0.  We first need to
subtract each byte by c, so that the value we are looking for is converted to a
0, then taking the minimum and checking for nulls works again.

The new code branches after it has compared ~256 bytes and chooses which of the
two strategies above will be used in the main loop, based on the char c. This
extra branch adds some overhead (~5%) for length ~256, but is quickly amortized
by the faster loop for larger sizes.

Compared to __rawmemchr_power9, this version is ~20% faster for length < 256.
Because of the optimized main loop, the improvement becomes ~35% for c != 0
and ~50% for c = 0 for strings longer than 256.

Reviewed-by: Lucas A. M. Magalhaes <lamm@linux.ibm.com>
Reviewed-by: Raphael M Zinsly <rzinsly@linux.ibm.com>
2021-05-17 10:30:35 -03:00
Florian Weimer
2d53566ec3 nptl: Move pthread_sigqueue into libc
The symbol was moved using scripts/move-symbol-to-libc.py.

The GLIBC_2.11 version is now empty, so add a placeholder symbol.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:25:12 +02:00
Florian Weimer
56f823abd4 nptl: Move pthread_setschedprio into libc
The symbol was moved using scripts/move-symbol-to-libc.py.

The GLIBC_2.3.4 version is now empty, so add a placeholder symbol.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:25:12 +02:00
Florian Weimer
8bc6a6d73c nptl: Move pthread_setname_np into libc
The symbol was moved using scripts/move-symbol-to-libc.py.

Add __libpthread_version_placeholder@@GLIBC_2.12 for the targets
that need it.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:25:12 +02:00
Florian Weimer
7b300ec7f9 nptl: Move pthread_setaffinity_np into libc
The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:25:12 +02:00
Florian Weimer
c924e44acd nptl: Move pthread_getname_np into libc
The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:25:12 +02:00
Florian Weimer
310e59e64c nptl: Move pthread_getcpuclockid into libc
The symbol was moved using scripts/move-symbol-to-libc.py.

__libpthread_version_placeholder@@GLIBC_2.2 is needed by this change;
the Versions entry for GLIBC_2.2 in libpthread had leftover symbols
due to an error in a previous conflict resolution.  The condition
for the placeholder symbol is complicated because some architectures
have earlier symbols at the GLIBC_2.2 symbol versions, so the
placeholder is not required there (yet).

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:25:11 +02:00
Florian Weimer
e948be4db3 nptl: Replace pthread_getcpuclockid with Linux implementation
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:25:11 +02:00
Florian Weimer
8f72bed1aa nptl: Move pthread_getattr_default_np into libc
The symbol was moved using scripts/move-symbol-to-libc.py.

A new placeholder symbol __libpthread_version_placeholder@GLIBC_2.18
is needed to keep the GLIBC_2.18 symbol version in libpthread.
The __pthread_getattr_default_np@@GLIBC_PRIVATE export is used
from pthread_create.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:25:11 +02:00
Florian Weimer
9dc21009a4 elf: Move static TLS size and alignment into _rtld_global_ro
This helps to clarify that the caching of these fields in libpthread
(in __static_tls_size, __static_tls_align_m1) is unnecessary.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:17:41 +02:00
Florian Weimer
0b3e92bdf3 elf: Remove DL_STATIC_INIT
All users have been converted to the __rtld_static_init mechanism.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:08:19 +02:00
Florian Weimer
b7fc189f7f powerpc: Remove _dl_var_init
The generic __rtld_static_init code handles GLRO (dl_pagesize),
GLRO (dl_auxv), GLRO (dl_hwcap), GLRO (dl_hwcap2).
GLRO (dl_cache_line_size) is handled in an __rtld_static_init_arch
override.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:08:17 +02:00
Florian Weimer
d0cae071f3 mips: Remove _dl_var_init
The generic __rtld_static_init code handles GLRO (dl_pagesize).

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:08:14 +02:00
Florian Weimer
9da94f4594 m68k: Remove _dl_var_init
The generic __rtld_static_init code handles GLRO (dl_pagesize).

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:08:12 +02:00
Florian Weimer
b097f280cd ia64: Remove _dl_var_init
The generic __rtld_static_init code handles GLRO (dl_pagesize)
and GLRO (dl_clktck).

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:08:09 +02:00
Florian Weimer
65e1340e32 arc: Remove _dl_var_init
The generic __rtld_static_init code handles GLRO (dl_pagesize).

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:08:05 +02:00
Florian Weimer
bdc90abc48 aarch64: Remove _dl_var_init
The generic __rtld_static_init code handles GLRO (dl_pagesize).

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:07:44 +02:00
Florian Weimer
78b31cc834 elf: Partially initialize ld.so after static dlopen (bug 20802)
After static dlopen, a copy of ld.so is loaded into the inner
namespace, but that copy is not initialized at all.  Some
architectures run into serious problems as result, which is why the
_dl_var_init mechanism was invented.  With libpthread moving into
libc and parts into ld.so, more architectures impacted, so it makes
sense to switch to a generic mechanism which performs the partial
initialization.

As a result, getauxval now works after static dlopen (bug 20802).

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:06:57 +02:00
Florian Weimer
23ce1cf35a nptl: Move __nptl_create_event, __nptl_death_event into libc
In libthread_db, use the exported GLIBC_PRIVATE symbols directly
instead of relying on _thread_db_* variables in libpthread
(which used to be created by the DB_FUNCTION macros).

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:06:44 +02:00
Florian Weimer
a78e5979a9 nptl: Move __nptl_initial_report_events into ld.so/startup code
The initialization of the report_events TCB field is now performed
in __tls_init_tp instead of __pthread_initialize_minimal_internal
(in libpthread).

The events interface is difficult to test because GDB stopped using it
in 2015.  The td_thr_get_info change to ignore lookup issues is enough
to support GDB with this change.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-17 10:04:06 +02:00
Martin Sebor
c1760eaf3b Enable support for GCC 11 -Wmismatched-dealloc.
To help detect common kinds of memory (and other resource) management
bugs, GCC 11 adds support for the detection of mismatched calls to
allocation and deallocation functions.  At each call site to a known
deallocation function GCC checks the set of allocation functions
the former can be paired with and, if the two don't match, issues
a -Wmismatched-dealloc warning (something similar happens in C++
for mismatched calls to new and delete).  GCC also uses the same
mechanism to detect attempts to deallocate objects not allocated
by any allocation function (or pointers past the first byte into
allocated objects) by -Wfree-nonheap-object.

This support is enabled for built-in functions like malloc and free.
To extend it beyond those, GCC extends attribute malloc to designate
a deallocation function to which pointers returned from the allocation
function may be passed to deallocate the allocated objects.  Another,
optional argument designates the positional argument to which
the pointer must be passed.

This change is the first step in enabling this extended support for
Glibc.
2021-05-16 15:21:18 -06:00
Adhemerval Zanella
390c43ba1f nptl: Fix tst-pthread-gdb-attach for ptrace_scope equal 1
This is similar to the fix for elf/tst-pldd (2f9046fb05):
it checks ptrace_scope value (values higher than 2 are too restrictive
to allow the test to run) and it rearranges the spawned processes
to make the target process the gdb child.

Checked on x86_64-linux-gnu with ptrace_scope set to 1.
2021-05-14 13:28:29 -03:00