platform/upstream/glibc.git
3 years agoLinux: Move aio_error, aio_error64 into libc
Florian Weimer [Fri, 25 Jun 2021 08:30:36 +0000 (10:30 +0200)]
Linux: Move aio_error, aio_error64 into libc

The symbols were moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoLinux: Move aio_cancel, aio_cancel64 into libc
Florian Weimer [Fri, 25 Jun 2021 08:30:36 +0000 (10:30 +0200)]
Linux: Move aio_cancel, aio_cancel64 into libc

The symbols were moved using scripts/move-symbol-to-libc.py.

A version placeholder symbol is needed on alpha and sparc because
of the additional symbols formerly at version GLIBC_2.3.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>:
3 years agoLinux: Move aio_init from librt into libc
Florian Weimer [Fri, 25 Jun 2021 08:30:35 +0000 (10:30 +0200)]
Linux: Move aio_init from librt into libc

This commit also moves the aio_misc and aio_sigquue helper,
so GLIBC_PRIVATE exports need to be added.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agosupport: Fix xclone build failures on ia64 and hppa
Florian Weimer [Fri, 25 Jun 2021 07:30:00 +0000 (09:30 +0200)]
support: Fix xclone build failures on ia64 and hppa

3 years agoelf: Disable most of TLS modid gaps processing [BZ #27135]
Florian Weimer [Fri, 25 Jun 2021 06:09:08 +0000 (08:09 +0200)]
elf: Disable most of TLS modid gaps processing [BZ #27135]

Revert "elf: Fix DTV gap reuse logic [BZ #27135]"

This reverts commit 572bd547d57a39b6cf0ea072545dc4048921f4c3.

It turns out that the _dl_next_tls_modid in _dl_map_object_from_fd keeps
returning the same modid over and over again if there is a gap and
more than TLS-using module is loaded in one dlopen call.  This corrupts
TLS data structures.  The bug is still present after a revert, but
empirically it is much more difficult to trigger (because it involves a
dlopen failure).

3 years agoelf: Fix glibc-hwcaps priorities with cache flags mismatches [BZ #27046]
Florian Weimer [Fri, 25 Jun 2021 06:02:30 +0000 (08:02 +0200)]
elf: Fix glibc-hwcaps priorities with cache flags mismatches [BZ #27046]

If lib->flags (in the cache) did not match GLRO (dl_correct_cache_id),
searching for further glibc-hwcaps entries did not happen, and it
was possible that the best glibc-hwcaps was not found.  By accident,
this causes a test failure for elf/tst-glibc-hwcaps-prepend-cache
on armv7l.

This commit changes the cache lookup logic to continue searching
if (a) no match has been found, (b) a named glibc-hwcaps match
has been found(), or (c) non-glibc-hwcaps match has been found
and the entry flags and cache default flags do not match.

_DL_CACHE_DEFAULT_ID is used instead of GLRO (dl_correct_cache_id)
because the latter is only written once on i386 if loading
of libc.so.5 libraries is selected, so GLRO (dl_correct_cache_id)
should probably removed in a future change.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
3 years ago* NEWS: Clarify _TIME_BITS change.
Paul Eggert [Fri, 25 Jun 2021 04:12:19 +0000 (21:12 -0700)]
* NEWS: Clarify _TIME_BITS change.

3 years agox86: Remove unnecessary overflow check from wcsnlen-sse4_1.S
Noah Goldstein [Wed, 23 Jun 2021 23:19:34 +0000 (19:19 -0400)]
x86: Remove unnecessary overflow check from wcsnlen-sse4_1.S

No bug. The way wcsnlen will check if near the end of maxlen
is the following macro:

mov %r11, %rsi; \
subq %rax, %rsi; \
andq $-64, %rax; \
testq $-64, %rsi; \
je L(strnlen_ret)

Which words independently of s + maxlen overflowing. So the
second overflow check is unnecissary for correctness and
just extra overhead in the common no overflow case.

test-strlen.c, test-wcslen.c, test-strnlen.c and test-wcsnlen.c are
all passing

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agoString: Add three more overflow tests cases to test-strnlen.c
Noah Goldstein [Wed, 23 Jun 2021 23:17:29 +0000 (19:17 -0400)]
String: Add three more overflow tests cases to test-strnlen.c

No bug. Just seem like relevant cases given that strnlen will
use s + maxlen in many implementations.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agoConsolidate pthread_atfork
Adhemerval Zanella [Wed, 20 Jan 2021 17:06:56 +0000 (14:06 -0300)]
Consolidate pthread_atfork

The pthread_atfork is similar between Linux and Hurd, only the compat
version bits differs.  The generic version is place at sysdeps/pthread
with a common name.

It also fixes an issue with Hurd license, where the static-only object
did not use LGPL + exception.

Checked on x86_64-linux-gnu, i686-linux-gnu, and with a build for
i686-gnu.

3 years agoposix: Do not clobber errno by atfork handlers
Adhemerval Zanella [Thu, 21 Jan 2021 13:20:54 +0000 (10:20 -0300)]
posix: Do not clobber errno by atfork handlers

Checked on x86_64-linux-gnu.

3 years agoposix: Consolidate fork implementation
Adhemerval Zanella [Mon, 18 Jan 2021 18:18:13 +0000 (15:18 -0300)]
posix: Consolidate fork implementation

The Linux nptl implementation is used as base for generic fork
implementation to handle the internal locks and mutexes.  The
system specific bits are moved a new internal _Fork symbol.

(This new implementation will be used to provide a async-signal-safe
_Fork now that POSIX has clarified that fork might not be
async-signal-safe [1]).

For Hurd it means that the __nss_database_fork_prepare_parent and
__nss_database_fork_subprocess will be run in a slight different
order.

[1] https://austingroupbugs.net/view.php?id=62

3 years agosupport: Add xclone
Adhemerval Zanella [Wed, 10 Mar 2021 15:26:30 +0000 (12:26 -0300)]
support: Add xclone

It is a wrapper for Linux clone syscall, to simplify the call to the
use only the most common arguments and remove architecture specific
handling (such as ia64 different name and signature).

3 years agox86: Fix tst-cpu-features-cpuinfo on Ryzen 9 (BZ #27873)
Adhemerval Zanella [Tue, 22 Jun 2021 19:41:28 +0000 (16:41 -0300)]
x86: Fix tst-cpu-features-cpuinfo on Ryzen 9 (BZ #27873)

AMD define different flags for IRPB, IBRS, and STIPBP [1], so new
x86_64_cpu are added and IBRS_IBPB is only tested for Intel.

The SSDB is also defined and implemented different on AMD [2],
and also a new AMD_SSDB flag is added.  It should map to the
cpuinfo 'ssdb' on recent AMD cpus.

It fixes tst-cpu-features-cpuinfo and tst-cpu-features-cpuinfo-static
on recent AMD cpus.

Checked on x86_64-linux-gnu on AMD Ryzen 9 5900X.

[1] https://developer.amd.com/wp-content/resources/Architecture_Guidelines_Update_Indirect_Branch_Control.pdf
[2] https://bugzilla.kernel.org/show_bug.cgi?id=199889

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agox86: Copy IBT and SHSTK usable only if CET is enabled
H.J. Lu [Wed, 23 Jun 2021 21:27:58 +0000 (14:27 -0700)]
x86: Copy IBT and SHSTK usable only if CET is enabled

IBT and SHSTK usable bits are copied from CPUID feature bits and later
cleared if kernel doesn't support CET.  Copy IBT and SHSTK usable only
if CET is enabled so that they aren't set on CET capable processors
with non-CET enabled glibc.

3 years agox86: Fix overflow bug in wcsnlen-sse4_1 and wcsnlen-avx2 [BZ #27974]
Noah Goldstein [Wed, 23 Jun 2021 05:56:29 +0000 (01:56 -0400)]
x86: Fix overflow bug in wcsnlen-sse4_1 and wcsnlen-avx2 [BZ #27974]

This commit fixes the bug mentioned in the previous commit.

The previous implementations of wmemchr in these files relied
on maxlen * sizeof(wchar_t) which was not guranteed by the standard.

The new overflow tests added in the previous commit now
pass (As well as all the other tests).

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agox86: Fix overflow bug with wmemchr-sse2 and wmemchr-avx2 [BZ #27974]
Noah Goldstein [Wed, 9 Jun 2021 20:25:32 +0000 (16:25 -0400)]
x86: Fix overflow bug with wmemchr-sse2 and wmemchr-avx2 [BZ #27974]

This commit fixes the bug mentioned in the previous commit.

The previous implementations of wmemchr in these files relied
on n * sizeof(wchar_t) which was not guranteed by the standard.

The new overflow tests added in the previous commit now
pass (As well as all the other tests).

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agoString: Add overflow tests for strnlen, memchr, and strncat [BZ #27974]
Noah Goldstein [Wed, 9 Jun 2021 20:17:14 +0000 (16:17 -0400)]
String: Add overflow tests for strnlen, memchr, and strncat [BZ #27974]

This commit adds tests for a bug in the wide char variant of the
functions where the implementation may assume that maxlen for wcsnlen
or n for wmemchr/strncat will not overflow when multiplied by
sizeof(wchar_t).

These tests show the following implementations failing on x86_64:

wcsnlen-sse4_1
wcsnlen-avx2

wmemchr-sse2
wmemchr-avx2

strncat would fail as well if it where on a system that prefered
either of the wcsnlen implementations that failed as it relies on
wcsnlen.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agox86-64: Add wcslen optimize for sse4.1
Noah Goldstein [Wed, 23 Jun 2021 05:19:34 +0000 (01:19 -0400)]
x86-64: Add wcslen optimize for sse4.1

No bug. This comment adds the ifunc / build infrastructure
necessary for wcslen to prefer the sse4.1 implementation
in strlen-vec.S. test-wcslen.c is passing.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agox86-64: Move strlen.S to multiarch/strlen-vec.S
H.J. Lu [Wed, 23 Jun 2021 03:42:10 +0000 (20:42 -0700)]
x86-64: Move strlen.S to multiarch/strlen-vec.S

Since strlen.S contains SSE2 version of strlen/strnlen and SSE4.1
version of wcslen/wcsnlen, move strlen.S to multiarch/strlen-vec.S
and include multiarch/strlen-vec.S from SSE2 and SSE4.1 variants.
This also removes the unused symbols, __GI___strlen_sse2 and
__GI___wcsnlen_sse4_1.

3 years agohurd: Fix build after 52a5fe70a2
Adhemerval Zanella [Wed, 23 Jun 2021 17:14:48 +0000 (14:14 -0300)]
hurd: Fix build after 52a5fe70a2

Hurd does not support 64-bit time_t internally.

3 years agonptl: Use SA_RESTART for SIGCANCEL handler
Adhemerval Zanella [Thu, 17 Jun 2021 12:45:03 +0000 (09:45 -0300)]
nptl: Use SA_RESTART for SIGCANCEL handler

The usage of signals to implementation pthread cancellation is an
implementation detail and should not be visible through cancellation
entrypoints.

However now that pthread_cancel always send the SIGCANCEL, some
entrypoint might be interruptable and return EINTR to the caller
(for instance on sem_wait).

Using SA_RESTART hides this, since the cancellation handler should
either act uppon cancellation (if asynchronous cancellation is enable)
or ignore the cancellation internal signal.

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

3 years agodoc: _TIME_BITS defaults may change
Paul Eggert [Wed, 23 Jun 2021 15:57:35 +0000 (08:57 -0700)]
doc: _TIME_BITS defaults may change

* NEWS: Don't imply the default will always be 32-bit.
* manual/creature.texi (Feature Test Macros):
Say that _TIME_BITS and _FILE_OFFSET_BITS defaults
may change in future releases.

3 years agoMore mcheck -> malloc-check refactoring
Siddhesh Poyarekar [Tue, 22 Jun 2021 10:16:11 +0000 (15:46 +0530)]
More mcheck -> malloc-check refactoring

Refactored malloc-check rules for tests that are automatically
generated and executed with MALLOC_CHECK_=3.

3 years agoAdd NEWS item for gconv-modules.d change
Siddhesh Poyarekar [Thu, 10 Jun 2021 11:15:10 +0000 (16:45 +0530)]
Add NEWS item for gconv-modules.d change

Reviewed-by: DJ Delorie <dj@redhat.com>
3 years agoHandle DT_UNKNOWN in gconv-modules.d
Siddhesh Poyarekar [Thu, 10 Jun 2021 09:26:37 +0000 (14:56 +0530)]
Handle DT_UNKNOWN in gconv-modules.d

On filesystems that do not support dt_type, a regular file shows up as
DT_UNKNOWN.  Fall back to using lstat64 to read file properties in
such cases.

Reviewed-by: DJ Delorie <dj@redhat.com>
3 years agoiconvconfig: Use common gconv module parsing function
Siddhesh Poyarekar [Thu, 10 Jun 2021 09:01:57 +0000 (14:31 +0530)]
iconvconfig: Use common gconv module parsing function

Drop local copy of gconv file parsing and use the one in
gconv_parseconfdir.h instead.  Now there is a single implementation of
configuration file parsing.

Reviewed-by: DJ Delorie <dj@redhat.com>
3 years agogconv_conf: Split out configuration file processing
Siddhesh Poyarekar [Thu, 10 Jun 2021 08:37:27 +0000 (14:07 +0530)]
gconv_conf: Split out configuration file processing

Split configuration file processing into a separate header file and
include it.  Macroize all calls that need to go through internal
interfaces so that iconvconfig can also use them.

Reviewed-by: DJ Delorie <dj@redhat.com>
3 years agogconv_conf: Remove unused variables
Siddhesh Poyarekar [Thu, 10 Jun 2021 04:21:50 +0000 (09:51 +0530)]
gconv_conf: Remove unused variables

The modules and nmodules parameters passed to add_modules, add_alias,
etc. are not used and are hence unnecessary.  Remove them so that
their signatures match the functions in iconvconfig.

Reviewed-by: DJ Delorie <dj@redhat.com>
Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
3 years agoiconv: Remove alloca use in gconv-modules configuration parsing
Siddhesh Poyarekar [Wed, 9 Jun 2021 19:11:35 +0000 (00:41 +0530)]
iconv: Remove alloca use in gconv-modules configuration parsing

The alloca sizes ought to be constrained to PATH_MAX, but replace them
with dynamic allocation to be safe.  A static PATH_MAX array would
have worked too but Hurd does not have PATH_MAX and the code path is
not hot enough to micro-optimise this allocation.  Revisit if any of
those realities change.

Reviewed-by: DJ Delorie <dj@redhat.com>
3 years agoRemove unsused symbols from nptl/Versions
Andreas Schwab [Tue, 15 Jun 2021 21:09:25 +0000 (23:09 +0200)]
Remove unsused symbols from nptl/Versions

The (private) symbols __pthread_clock_gettime, __pthread_clock_settime and
__pthread_initialize_minimal haven't been defined by libpthread for some
time.

3 years agolinux: Only use 64-bit syscall if required for clock_nanosleep
Adhemerval Zanella [Wed, 16 Jun 2021 14:12:25 +0000 (11:12 -0300)]
linux: Only use 64-bit syscall if required for clock_nanosleep

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for internal futex
Adhemerval Zanella [Wed, 16 Jun 2021 14:04:47 +0000 (11:04 -0300)]
linux: Only use 64-bit syscall if required for internal futex

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for utimensat family
Adhemerval Zanella [Wed, 16 Jun 2021 13:43:57 +0000 (10:43 -0300)]
linux: Only use 64-bit syscall if required for utimensat family

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.

The large timeout are already tests by io/tst-utimensat-skeleton.c.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for sigtimedwait
Adhemerval Zanella [Wed, 16 Jun 2021 12:58:29 +0000 (09:58 -0300)]
linux: Only use 64-bit syscall if required for sigtimedwait

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for mq_timedsend
Adhemerval Zanella [Wed, 16 Jun 2021 12:50:53 +0000 (09:50 -0300)]
linux: Only use 64-bit syscall if required for mq_timedsend

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for mq_timedreceive
Adhemerval Zanella [Wed, 16 Jun 2021 02:05:21 +0000 (23:05 -0300)]
linux: Only use 64-bit syscall if required for mq_timedreceive

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for timerfd_settime
Adhemerval Zanella [Wed, 16 Jun 2021 01:56:12 +0000 (22:56 -0300)]
linux: Only use 64-bit syscall if required for timerfd_settime

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for semtimedop
Adhemerval Zanella [Wed, 16 Jun 2021 01:43:51 +0000 (22:43 -0300)]
linux: Only use 64-bit syscall if required for semtimedop

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: timerfd_gettime minor cleanup
Adhemerval Zanella [Wed, 16 Jun 2021 01:59:22 +0000 (22:59 -0300)]
linux: timerfd_gettime minor cleanup

The __NR_timerfd_gettime64 is always defined.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Remove time64-support
Adhemerval Zanella [Wed, 16 Jun 2021 01:17:01 +0000 (22:17 -0300)]
linux: Remove time64-support

It breaks the usage case of live migration like CRIU or similar
and most usages can be optimized away by either building glibc with
a minimum 5.1 kernel or by using the 32-bit syscall for the common
case.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Remove supports_time64 () from clock_gettime
Adhemerval Zanella [Wed, 16 Jun 2021 01:10:26 +0000 (22:10 -0300)]
linux: Remove supports_time64 () from clock_gettime

It breaks the usage case of live migration like CRIU or similar.
The performance drawback is it would require an extra syscall
on older kernels without 64-bit time support.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Remove supports_time64 () from clock_getres
Adhemerval Zanella [Wed, 16 Jun 2021 00:35:10 +0000 (21:35 -0300)]
linux: Remove supports_time64 () from clock_getres

It breaks the usage case of live migration like CRIU or similar.
The performance drawback is it would require an extra syscall
on older kernels without 64-bit time support.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for select
Adhemerval Zanella [Wed, 16 Jun 2021 00:00:50 +0000 (21:00 -0300)]
linux: Only use 64-bit syscall if required for select

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.  This also avoids the need
to use supports_time64() (which breaks the usage case of live migration
like CRIU or similar).

It also fixes an issue on 32-bit select call for !__ASSUME_PSELECT
(microblase with older kernels only) where the expected timeout
is a 'struct timeval' instead of 'struct timespec'.

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for pselect
Adhemerval Zanella [Tue, 15 Jun 2021 19:59:50 +0000 (16:59 -0300)]
linux: Only use 64-bit syscall if required for pselect

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.  This also avoids the need
to use supports_time64() (which breaks the usage case of live migration
like CRIU or similar).

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agolinux: Only use 64-bit syscall if required for ppoll
Adhemerval Zanella [Tue, 15 Jun 2021 18:41:00 +0000 (15:41 -0300)]
linux: Only use 64-bit syscall if required for ppoll

For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one.  The 64-bit usage should
be rare since the timeout is a relative one.  This also avoids the need
to use supports_time64() (which breaks the usage case of live migration
like CRIU or similar).

Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agosupport: Add support_create_timer
Adhemerval Zanella [Wed, 16 Jun 2021 16:44:03 +0000 (13:44 -0300)]
support: Add support_create_timer

It is a simple wrapper over timer_create, timer_settime, and
sigaction.  It will be used to check for large timeout to trigger an
EINTR and to avoid use a large timeout (as for alarm()).

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agoUse 64 bit time_t stat internally
Adhemerval Zanella [Tue, 2 Mar 2021 20:06:02 +0000 (17:06 -0300)]
Use 64 bit time_t stat internally

For the legacy ABI with supports 32-bit time_t it calls the 64-bit
time directly, since the LFS symbols calls the 64-bit time_t ones
internally.

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

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agomalloc: Drop __malloc_initialized from Versions
Siddhesh Poyarekar [Tue, 22 Jun 2021 14:43:40 +0000 (20:13 +0530)]
malloc: Drop __malloc_initialized from Versions

__malloc_initialized is mentioned in Versions when it is actually an
internal symbol.  The resultant binaries are identical.

3 years agotst-mcheck: Rename to tst-malloc-check
Siddhesh Poyarekar [Tue, 22 Jun 2021 08:57:15 +0000 (14:27 +0530)]
tst-mcheck: Rename to tst-malloc-check

MALLOC_CHECK_ and mcheck() are two different malloc checking features.
tst-mcheck does not check mcheck(), instead it checks MALLOC_CHECK_,
so rename the file to avoid confusion.

3 years agoAdd hidden prototypes for fsync, fdatasync
Florian Weimer [Tue, 22 Jun 2021 07:50:27 +0000 (09:50 +0200)]
Add hidden prototypes for fsync, fdatasync

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonptl: Move pthreadP.h into sysdeps directory
Florian Weimer [Tue, 22 Jun 2021 07:50:27 +0000 (09:50 +0200)]
nptl: Move pthreadP.h into sysdeps directory

This mirrors the situation on Hurd.  These directories are on
the include search part, so #include <pthreadP.h> works after this
change on both Hurd and nptl.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agort: Move generic implementation from sysdeps/pthread to rt
Florian Weimer [Tue, 22 Jun 2021 07:50:27 +0000 (09:50 +0200)]
rt: Move generic implementation from sysdeps/pthread to rt

The pthread-based implementation is the generic one.  Replacing
the stubs makes it clear that they do not have to be adjusted for
the libpthread move.

Result of:

    git mv -f sysdeps/pthread/aio_misc.h sysdeps/generic/
    git mv sysdeps/pthread/timer_routines.c sysdeps/htl/
    git mv -f sysdeps/pthread/{aio,lio,timer}_*.c rt/

Followed by manual adjustment of the #include paths in
sysdeps/unix/sysv/linux/wordsize-64, and a move of the version
definitions formerly in sysdeps/pthread/Versions.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agort: Move shm_unlink into libc
Florian Weimer [Mon, 21 Jun 2021 06:25:15 +0000 (08:25 +0200)]
rt: Move shm_unlink into libc

This function has no dependency on libpthread, so the move is also
applied to Hurd.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agort: Move shm_open into libc
Florian Weimer [Mon, 21 Jun 2021 06:25:15 +0000 (08:25 +0200)]
rt: Move shm_open into libc

This function has no dependency on libpthread, so the move is also
applied to Hurd.

To avoid localplt failures, use __open64_nocancel instead of
pthread_setcancelstate and open.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agort: Replace generic stub of shm_unlink with the posix version
Florian Weimer [Mon, 21 Jun 2021 06:25:15 +0000 (08:25 +0200)]
rt: Replace generic stub of shm_unlink with the posix version

Result of: git mv -f sysdeps/posix/shm_unlink.c rt
and manual removal of the _POSIX_MAPPED_FILES preprocessor condition.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agort: Replace generic stub of shm_open with the posix version
Florian Weimer [Mon, 21 Jun 2021 06:25:15 +0000 (08:25 +0200)]
rt: Replace generic stub of shm_open with the posix version

Result of: git mv -f sysdeps/posix/shm_open.c rt
and manual removal of the _POSIX_MAPPED_FILES preprocessor condition.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoFix librt-routines-var issues for !PTHREAD_IN_LIBC
Florian Weimer [Mon, 21 Jun 2021 06:25:15 +0000 (08:25 +0200)]
Fix librt-routines-var issues for !PTHREAD_IN_LIBC

The variable name was incorrect, and the existing librt-routines
variable needs to be augmented (not assigned) in rt/Makefile.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agort: Lexicographically sort Versions file; librt-routines in Makefile
Florian Weimer [Mon, 21 Jun 2021 06:25:15 +0000 (08:25 +0200)]
rt: Lexicographically sort Versions file; librt-routines in Makefile

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoelf: Use _dl_catch_error from base namespace in dl-libc.c [BZ #27646]
Florian Weimer [Thu, 17 Jun 2021 13:06:43 +0000 (15:06 +0200)]
elf: Use _dl_catch_error from base namespace in dl-libc.c [BZ #27646]

dlerrror_run in elf/dl-libc.c needs to call GLRO (dl_catch_error)
from the base namespace, just like the exported dlerror
implementation.

Fixes commit b2964eb1d9a6b8ab1250e8a881cf406182da5875 ("dlfcn:
Failures after dlmopen should not terminate process [BZ #24772]").

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
3 years agoMakeconfig: Fix time64-compat.mk target
Siddhesh Poyarekar [Thu, 17 Jun 2021 08:52:21 +0000 (14:22 +0530)]
Makeconfig: Fix time64-compat.mk target

The time64-compat.i needed for the time64-compat.mk Makeconfig include
ends up trying to include libc-modules.h, which is not generated until
later.  This results in an error during build which is not noticed
because it somehow does not terminate the build.

Exclude the modules cppflags from the pre-processing command and fix
up the time64-compat.mk target so that the build runs without issues.

Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
3 years agonptl: Export _pthread_cleanup_push, _pthread_cleanup_pop again
Florian Weimer [Tue, 15 Jun 2021 15:00:29 +0000 (17:00 +0200)]
nptl: Export _pthread_cleanup_push, _pthread_cleanup_pop again

These were turned into compat symbols as part of the libpthread
move.  It turns out they are used by language run-time libraries
(e.g., the GCC D front end), so it makes to preserve them as
external symbols even though they are not declared in any header
file.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agos390x: Align child stack while clone. [BZ #27968]
Stefan Liebler [Tue, 8 Jun 2021 13:37:32 +0000 (15:37 +0200)]
s390x: Align child stack while clone. [BZ #27968]

Starting with recent commit 92a7d1343991897f77afe01041f3b77712445e47
"x86-64: Align child stack to 16 bytes [BZ #27902]"
the new test misc/tst-misalign-clone has failed on s390x/s390.

This patch is now aligning the stack to a double
word boundary as also done in start.S files.

3 years agoy2038: Add test coverage
Adhemerval Zanella [Wed, 17 Feb 2021 18:59:34 +0000 (15:59 -0300)]
y2038: Add test coverage

It is enabled through a new rule, tests-y2038, which is built only
when the ABI supports the comapt 64-bit time_t (defined by the
header time64-compat.h, which also enables the creation of the
symbol Version for Linux).  It means the tests are not built
for ABI which already provide default 64-bit time_t.

The new rule already adds the required LFS and 64-bit time_t
compiler flags.

The current coverage is:

  * libc:
    - adjtime                       tst-adjtime-time64
    - adjtimex                      tst-adjtimex-time64
    - clock_adjtime                 tst-clock_adjtime-time64
    - clock_getres                  tst-clock-time64, tst-cpuclock1-time64
    - clock_gettime                 tst-clock-time64, tst-clock2-time64,
    tst-cpuclock1-time64
    - clock_nanosleep               tst-clock_nanosleep-time64,
    tst-cpuclock1-time64
    - clock_settime                 tst-clock2-time64
    - cnd_timedwait                 tst-cnd-timedwait-time64
    - ctime                         tst-ctime-time64
    - ctime_r                       tst-ctime-time64
    - difftime                      tst-difftime-time64
    - fstat                         tst-stat-time64
    - fstatat                       tst-stat-time64
    - futimens                      tst-futimens-time64
    - futimes                       tst-futimes-time64
    - futimesat                     tst-futimesat-time64
    - fts_*                         tst-fts-time64
    - getitimer                     tst-itimer-timer64
    - getrusage
    - gettimeofday                  tst-clock_nanosleep-time64
    - glob / globfree               tst-gnuglob64-time64
    - gmtime                        tst-gmtime-time64
    - gmtime_r                      tst-gmtime-time64
    - lstat                         tst-stat-time64
    - localtime                     tst-y2039-time64
    - localtime_t                   tst-y2039-time64
    - lutimes                       tst-lutimes-time64
    - mktime                        tst-mktime4-time64
    - mq_timedreceive               tst-mqueue{1248}-time64
    - mq_timedsend                  tst-mqueue{1248}-time64
    - msgctl                        test-sysvmsg-time64
    - mtx_timedlock                 tst-mtx-timedlock-time64
    - nanosleep                     tst-cpuclock{12}-time64,
    tst-mqueue8-time64, tst-clock-time64
    - nftw / ftw                    ftwtest-time64
    - ntp_adjtime                   tst-ntp_adjtime-time64
    - ntp_gettime                   tst-ntp_gettime-time64
    - ntp_gettimex                  tst-ntp_gettimex-time64
    - ppoll                         tst-ppoll-time64
    - pselect                       tst-pselect-time64
    - pthread_clockjoin_np          tst-join14-time64
    - pthread_cond_clockwait        tst-cond11-time64
    - pthread_cond_timedwait        tst-abstime-time64
    - pthread_mutex_clocklock       tst-abstime-time64
    - pthread_mutex_timedlock       tst-abstime-time64
    - pthread_rwlock_clockrdlock    tst-abstime-time64, tst-rwlock14-time64
    - pthread_rwlock_clockwrlock    tst-abstime-time64, tst-rwlock14-time64
    - pthread_rwlock_timedrdlock    tst-abstime-time64, tst-rwlock14-time64
    - pthread_rwlock_timedwrlock    tst-abstime-time64, tst-rwlock14-time64
    - pthread_timedjoin_np          tst-join14-time64
    - recvmmsg                      tst-cancel4_2-time64
    - sched_rr_get_interval         tst-sched_rr_get_interval-time64
    - select                        tst-select-time64
    - sem_clockwait                 tst-sem5-time64
    - sem_timedwait                 tst-sem5-time64
    - semctl                        test-sysvsem-time64
    - semtimedop                    test-sysvsem-time64
    - setitimer                     tst-mqueue2-time64, tst-itimer-timer64
    - settimeofday                  tst-settimeofday-time64
    - shmctl                        test-sysvshm-time64
    - sigtimedwait                  tst-sigtimedwait-time64
    - stat                          tst-stat-time64
    - thrd_sleep                    tst-thrd-sleep-time64
    - time                          tst-mqueue{1248}-time64
    - timegm                        tst-timegm-time64
    - timer_gettime                 tst-timer4-time64
    - timer_settime                 tst-timer4-time64
    - timerfd_gettime               tst-timerfd-time64
    - timerfd_settime               tst-timerfd-time64
    - timespec_get                  tst-timespec_get-time64
    - timespec_getres               tst-timespec_getres-time64
    - utime                         tst-utime-time64
    - utimensat                     tst-utimensat-time64
    - utimes                        tst-utimes-time64
    - wait3                         tst-wait3-time64
    - wait4                         tst-wait4-time64

  * librt:
    - aio_suspend                   tst-aio6-time64
    - mq_timedreceive               tst-mqueue{1248}-time64
    - mq_timedsend                  tst-mqueue{1248}-time64
    - timer_gettime                 tst-timer4-time64
    - timer_settime                 tst-timer4-time64

  * libanl:
    - gai_suspend

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agolibsupport: Add 64-bit time_t support for stat functions
Adhemerval Zanella [Fri, 26 Feb 2021 12:59:27 +0000 (09:59 -0300)]
libsupport: Add 64-bit time_t support for stat functions

The patch adds redirections for xstat, xlstat, and xfstat when
_TIME_BITS=64 is defined.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agolibsupport: Add 64-bit time_t support for time functions
Adhemerval Zanella [Thu, 25 Feb 2021 19:57:25 +0000 (16:57 -0300)]
libsupport: Add 64-bit time_t support for time functions

The patch adds redirections for xclock_gettime, xclock_settime,
timespec_add, timespec_sub, test_timespec_before_impl,
test_timespec_equal_or_after_impl, support_timespec_ns,
support_timespec_normalize, and support_timespec_check_in_range when
_TIME_BITS=64 is defined.

Co-authored-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoio: Add ftw64 with 64-bit time_t support
Adhemerval Zanella [Wed, 3 Mar 2021 12:36:18 +0000 (09:36 -0300)]
io: Add ftw64 with 64-bit time_t support

Similar to fts, ftw routines passes a stat pointer that might
differ of size and layout when 64-bit time API is used.

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

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoio: Add fts64 with 64-bit time_t support
Adhemerval Zanella [Wed, 3 Mar 2021 12:00:13 +0000 (09:00 -0300)]
io: Add fts64 with 64-bit time_t support

Similar to glob, fts routines passes a stat pointer that might
differ of size and layout when 64-bit time API is used.

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

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoposix: Add glob64 with 64-bit time_t support
Adhemerval Zanella [Tue, 2 Mar 2021 23:17:07 +0000 (20:17 -0300)]
posix: Add glob64 with 64-bit time_t support

The glob might pass a different stat struct for gl_stat and gl_lstat
when GLOB_ALTDIRFUNC is used.  This requires add a new 64-bit time
version that also uses 64-bit time stat functions.

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

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Add support for 64-bit time on legacy ABIs
Adhemerval Zanella [Wed, 17 Feb 2021 16:35:19 +0000 (13:35 -0300)]
y2038: Add support for 64-bit time on legacy ABIs

A new build flag, _TIME_BITS, enables the usage of the newer 64-bit
time symbols for legacy ABI (where 32-bit time_t is default).  The 64
bit time support is only enabled if LFS (_FILE_OFFSET_BITS=64) is
also used.

Different than LFS support, the y2038 symbols are added only for the
required ABIs (armhf, csky, hppa, i386, m68k, microblaze, mips32,
mips64-n32, nios2, powerpc32, sparc32, s390-32, and sh).  The ABIs with
64-bit time support are unchanged, both for symbol and types
redirection.

On Linux the full 64-bit time support requires a minimum of kernel
version v5.1.  Otherwise, the 32-bit fallbacks are used and might
results in error with overflow return code (EOVERFLOW).

The i686-gnu does not yet support 64-bit time.

This patch exports following rediretions to support 64-bit time:

  * libc:
    adjtime
    adjtimex
    clock_adjtime
    clock_getres
    clock_gettime
    clock_nanosleep
    clock_settime
    cnd_timedwait
    ctime
    ctime_r
    difftime
    fstat
    fstatat
    futimens
    futimes
    futimesat
    getitimer
    getrusage
    gettimeofday
    gmtime
    gmtime_r
    localtime
    localtime_r
    lstat_time
    lutimes
    mktime
    msgctl
    mtx_timedlock
    nanosleep
    nanosleep
    ntp_gettime
    ntp_gettimex
    ppoll
    pselec
    pselect
    pthread_clockjoin_np
    pthread_cond_clockwait
    pthread_cond_timedwait
    pthread_mutex_clocklock
    pthread_mutex_timedlock
    pthread_rwlock_clockrdlock
    pthread_rwlock_clockwrlock
    pthread_rwlock_timedrdlock
    pthread_rwlock_timedwrlock
    pthread_timedjoin_np
    recvmmsg
    sched_rr_get_interval
    select
    sem_clockwait
    semctl
    semtimedop
    sem_timedwait
    setitimer
    settimeofday
    shmctl
    sigtimedwait
    stat
    thrd_sleep
    time
    timegm
    timerfd_gettime
    timerfd_settime
    timespec_get
    utime
    utimensat
    utimes
    utimes
    wait3
    wait4

  * librt:
    aio_suspend
    mq_timedreceive
    mq_timedsend
    timer_gettime
    timer_settime

  * libanl:
    gai_suspend

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agotime: Add 64-bit time support for getdate
Adhemerval Zanella [Tue, 2 Mar 2021 12:02:02 +0000 (09:02 -0300)]
time: Add 64-bit time support for getdate

The getdate is basically a wrapper localtime and mktime.  The 64-bit
time support is done calling the 64-bit internal functions, there is
no need to add a new symbol version.

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

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Add __USE_TIME_BITS64 support for socket-constants.h
Adhemerval Zanella [Wed, 24 Feb 2021 13:37:02 +0000 (13:37 +0000)]
y2038: Add __USE_TIME_BITS64 support for socket-constants.h

It is only used for !__USE_MISC, the default way uses the kernel
headers.  The patch also adds the SO_TIMESTAMP, SO_TIMESTAMPNS, and
SO_TIMESTAMPING which uses new values for 64-bit time_t kernel
interfaces.

The __USE_TIME_BITS64 is not defined internally yet, although the
internal header is used when building the 64-bit stat implementations.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Use a common definition for shmid_ds
Adhemerval Zanella [Wed, 17 Feb 2021 21:38:09 +0000 (18:38 -0300)]
y2038: Use a common definition for shmid_ds

Instead of replicate the same definitions from struct_shmid64_ds.h
on the multiple struct_shmid_ds.h, use a common header which is included
when required (struct_shmid64_ds_helper.h).

The __USE_TIME_BITS64 is not defined internally yet, although the
internal header is used when building the 64-bit semctl implementation.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Use a common definition for semid_ds
Adhemerval Zanella [Wed, 17 Feb 2021 21:30:08 +0000 (18:30 -0300)]
y2038: Use a common definition for semid_ds

Instead of replicate the same definitions from struct_semid64_ds.h
on the multiple struct_semid_ds.h, use a common header which is included
when required (struct_semid64_ds_helper.h).

The __USE_TIME_BITS64 is not defined internally yet, although the
internal header is used when building the 64-bit semctl implementation.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Use a common definition for msqid_ds
Lukasz Majewski [Thu, 22 Oct 2020 10:04:40 +0000 (12:04 +0200)]
y2038: Use a common definition for msqid_ds

Instead of replicate the same definitions from struct_msqid64_ds.h
on the multiple struct_msqid_ds.h, use a common header which is included
when required (struct_msqid64_ds_helper.h).

The __USE_TIME_BITS64 is not defined internally yet, although the
internal header is used when building the 64-bit stat implementations.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Use a common definition for stat
Lukasz Majewski [Thu, 15 Oct 2020 07:30:59 +0000 (09:30 +0200)]
y2038: Use a common definition for stat

Instead of replicate the same definitions from struct_stat_time64.h
on the multiple struct_stat.h, use a common header which is included
when required (struct_stat_time64_helper.h).  The 64-bit time support
is added only for LFS support.

The __USE_TIME_BITS64 is not defined internally yet, although the
internal header is used when building the 64-bit stat implementations.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: linux: Add __USE_TIME_BITS64 support for struct timex
Adhemerval Zanella [Wed, 17 Feb 2021 19:20:43 +0000 (16:20 -0300)]
y2038: linux: Add __USE_TIME_BITS64 support for struct timex

The __USE_TIME_BITS64 is not defined internally yet.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Add __USE_TIME_BITS64 support for struct utimbuf
Adhemerval Zanella [Wed, 17 Feb 2021 19:20:18 +0000 (16:20 -0300)]
y2038: Add __USE_TIME_BITS64 support for struct utimbuf

The __USE_TIME_BITS64 is not defined internally yet.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Add __USE_TIME_BITS64 support for struct timespec
Adhemerval Zanella [Wed, 17 Feb 2021 19:19:45 +0000 (16:19 -0300)]
y2038: Add __USE_TIME_BITS64 support for struct timespec

The __USE_TIME_BITS64 is not defined internally yet.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Add __USE_TIME_BITS64 support for struct timeval
Adhemerval Zanella [Wed, 17 Feb 2021 19:19:23 +0000 (16:19 -0300)]
y2038: Add __USE_TIME_BITS64 support for struct timeval

The __USE_TIME_BITS64 is not defined internally yet.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoy2038: Add __USE_TIME_BITS64 support for time_t
Adhemerval Zanella [Wed, 17 Feb 2021 19:18:42 +0000 (16:18 -0300)]
y2038: Add __USE_TIME_BITS64 support for time_t

The __USE_TIME_BITS64 is not defined internally yet.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agolinux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
Adhemerval Zanella [Tue, 8 Sep 2020 12:08:10 +0000 (09:08 -0300)]
linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}

Handle the SO_TIMESTAMP{NS} similar to recvmsg: for
!__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time SO_TIMESTAMP
or SO_TIMESTAMPNS and appends it to the control buffer if has extra
space or returns MSG_CTRUNC otherwise.  The 32-bit time field is kept
as-is.

Also for !__ASSUME_TIME64_SYSCALLS it limits the maximum number of
'struct mmsghdr *' to IOV_MAX (and also increases the stack size
requirement to IOV_MAX times sizeof (socklen_t)).  The Linux imposes
a similar limit to sendmmsg, so bound the array size on recvmmsg is not
unreasonable.  And this will be used only on older when building with
32-bit time support.

Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15
kernel).

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agolinux: Add fallback for 64-bit time_t SO_TIMESTAMP{NS}
Adhemerval Zanella [Mon, 7 Sep 2020 20:08:46 +0000 (17:08 -0300)]
linux: Add fallback for 64-bit time_t SO_TIMESTAMP{NS}

The recvmsg handling is more complicated because it requires check the
returned kernel control message and make some convertions.  For
!__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time SO_TIMESTAMP
or SO_TIMESTAMPNS and appends it to the control buffer if has extra
space or returns MSG_CTRUNC otherwise.  The 32-bit time field is kept
as-is.

Calls with __TIMESIZE=32 will see the converted 64-bit time control
messages as spurious control message of unknown type.  Calls with
__TIMESIZE=64 running on pre-time64 kernels will see the original
message as a spurious control ones of unknown typ while running on
kernel with native 64-bit time support will only see the time64 version
of the control message.

Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15
kernel).

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agolinux: Add fallback for 64-bit time_t SO_{RCV,SND}TIMEO
Adhemerval Zanella [Mon, 7 Sep 2020 17:13:58 +0000 (14:13 -0300)]
linux: Add fallback for 64-bit time_t SO_{RCV,SND}TIMEO

The constant values will be changed for __TIMESIZE=64, so binaries built
with 64-bit time support might fail to work properly on old kernels.
Both {get,set}sockopt will retry the syscall with the old constant
values and the timeout value adjusted when kernel returns ENOTPROTOPT.

It also adds an internal only SO_{RCV,SND}TIMEO where
COMPAT_SO_{RCV,SND}TIMEO_OLD indicates pre 32-bit time support and
COMPAT_SO_{RCV,SND}TIMEO_NEW indicates time64 support.  It allows to
refer to constant independently of the time_t ABI and kernel version
used.

Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15
kernel).

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agolinux: s390: Add libanl.abilist in s390 and s390x
Adhemerval Zanella [Mon, 22 Feb 2021 21:11:35 +0000 (21:11 +0000)]
linux: s390: Add libanl.abilist in s390 and s390x

The s390 will require the 64-bit time symbols for y2038 support.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agolinux: mips: Split libanl.abilist in n32 and n64
Adhemerval Zanella [Mon, 22 Feb 2021 21:10:28 +0000 (21:10 +0000)]
linux: mips: Split libanl.abilist in n32 and n64

The n32 will require the 64-bit time symbols for y2038 support.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agolinux: mips: Split librt.abilist in n32 and n64
Adhemerval Zanella [Mon, 22 Mar 2021 18:18:41 +0000 (15:18 -0300)]
linux: mips: Split librt.abilist in n32 and n64

The n32 will require the 64-bit time symbols for y2038 support.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoReinstate gconv-modules as the default configuration file
Siddhesh Poyarekar [Mon, 14 Jun 2021 05:39:56 +0000 (11:09 +0530)]
Reinstate gconv-modules as the default configuration file

Reinstate gconv-modules as the main file so that the configuration
files in gconv-modules.d/ become add-on configuration.  With this, the
effective user visible change is that GCONV_PATH can now have
supplementary configuration in GCONV_PATH/gconv-modules.d/ in addition
to the main GCONV_PATH/gconv-modules file.

3 years agoAdd build option to disable usage of scv on powerpc
Matheus Castanho [Fri, 9 Apr 2021 17:47:27 +0000 (14:47 -0300)]
Add build option to disable usage of scv on powerpc

Commit 68ab82f56690ada86ac1e0c46bad06ba189a10ef added support for the scv
syscall ABI on powerpc.  Since then systems that have kernel and processor
support started using scv.  However adding the proper support for a new syscall
ABI requires changes to several other projects (e.g. qemu, valgrind, strace,
kernel), which are gradually receiving support.

Meanwhile, having a way to disable scv on glibc at build time can be useful for
distros that may encounter conflicts with projects that still do not support the
scv ABI, buying time until proper support is added.

This commit adds a --disable-scv option that disables scv support and uses sc
for all syscalls, like before commit 68ab82f56690ada86ac1e0c46bad06ba189a10ef.

Reviewed-by: Raphael M Zinsly <rzinsly@linux.ibm.com>
3 years agoio: Fix sporadic test failures in io/tst-stat
Florian Weimer [Thu, 10 Jun 2021 08:09:51 +0000 (10:09 +0200)]
io: Fix sporadic test failures in io/tst-stat

support_stat_nanoseconds cannot restore the ctime time, and
this may lead to sporadic test failures.  Therefore, probe for
nanoseconds support before the initial statx call.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonptl: Avoid async cancellation to wrongly update __nptl_nthreads (BZ #19366)
Adhemerval Zanella [Thu, 27 May 2021 15:42:13 +0000 (12:42 -0300)]
nptl: Avoid async cancellation to wrongly update __nptl_nthreads (BZ #19366)

The testcase provided on BZ#19366 may update __nptl_nthreads in a wrong
order, triggering an early process exit because the thread decrement
the value twice.

The issue is once the thread exits without acting on cancellation,
it decreaments '__nptl_nthreads' and then atomically set
 'cancelhandling' with EXITING_BIT (thus preventing further cancellation
handler to act).  The issue happens if a SIGCANCEL is received between
checking '__ntpl_nthreads' and setting EXITING_BIT.  To avoid it, the
'__nptl_nthreads' decrement is moved after EXITING_BIT.

It does fully follow the POSIX XSH 2.9.5 Thread Cancellation under
the heading Thread Cancellation Cleanup Handlers that states that
when a cancellation request is acted upon, or when a thread calls
pthread_exit(), the thread first disables cancellation by setting its
cancelability state to PTHREAD_CANCEL_DISABLE and its cancelability type
to PTHREAD_CANCEL_DEFERRED.  The issue is '__pthread_enable_asynccancel'
explicit enabled assynchrnous cancellation, so an interrupted syscall
within the cancellation cleanup handlers might see an invalid cancelling
type (a possible fix might be possible with my proposed solution to
BZ#12683).

Trying to come up with a test is quite hard since it requires to
mimic the timing issue described below, however I see that the
bug report reproducer does not early exit anymore.

Checked on x86_64-linux-gnu.

3 years agonptl: Use pthread_kill on pthread_cancel
Adhemerval Zanella [Mon, 7 Dec 2020 20:17:24 +0000 (17:17 -0300)]
nptl: Use pthread_kill on pthread_cancel

It consolidates the tgkill call and it is the first step of making
pthread_cancel async-signal-safe.  It also fix a possible issue
where the 'struct pthread' tid is not read atomically, which might
send an invalid cancellation signal (similar to what
db988e50a87f613cb6b9e98a2fc66a4848bc3546 fixed for pthread_join).

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

3 years agonptl: Implement raise in terms of pthread_kill
Adhemerval Zanella [Mon, 7 Dec 2020 19:21:55 +0000 (16:21 -0300)]
nptl: Implement raise in terms of pthread_kill

Now that pthread_kill is provided by libc.so it is possible to
implement the generic POSIX implementation as
'pthread_kill(pthread_self(), sig)'.

For Linux implementation, pthread_kill read the targeting TID from
the TCB.  For raise, this it not possible because it would make raise
fail when issue after vfork (where creates the resulting process
has a different TID from the parent, but its TCB is not updated as
for pthread_create).  To make raise use pthread_kill, it is make
usable from vfork by getting the target thread id through gettid
syscall.

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

3 years agonptl: Move cancel type out of cancelhandling
Adhemerval Zanella [Tue, 31 Mar 2020 20:24:39 +0000 (17:24 -0300)]
nptl: Move cancel type out of cancelhandling

Now that the thread cancellation type is not accessed concurrently
anymore, it is possible to move it out the cancelhandling.

By removing the cancel state out of the internal thread cancel handling
state there is no need to check if cancelled bit was set in CAS
operation.

It allows simplifing the cancellation wrappers and the
CANCEL_CANCELED_AND_ASYNCHRONOUS is removed.

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

3 years agonptl: Move cancel state out of cancelhandling
Adhemerval Zanella [Tue, 31 Mar 2020 18:43:25 +0000 (15:43 -0300)]
nptl: Move cancel state out of cancelhandling

Now that thread cancellation state is not accessed concurrently anymore,
it is possible to move it out the 'cancelhandling'.

The code is also simplified: CANCELLATION_P is replaced with a
internal pthread_testcancel call and the CANCELSTATE_BIT{MASK} is
removed.

With this behavior pthread_setcancelstate does not require to act on
cancellation if cancel type is asynchronous (is already handled either
by pthread_setcanceltype or by the signal handler).

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

3 years agonptl: Remove CANCELING_BITMASK
Adhemerval Zanella [Tue, 25 May 2021 17:31:30 +0000 (14:31 -0300)]
nptl: Remove CANCELING_BITMASK

The CANCELING_BITMASK is used as an optimization to avoid sending
the signal when pthread_cancel is called in a concurrent manner.

This requires then to put both the cancellation state and type on a
shared state (cancelhandling), since 'pthread_cancel' checks whether
cancellation is enabled and asynchrnous to either cancel itself of
 sending the signal.

It also requires handle the CANCELING_BITMASK on
__pthread_disable_asynccancel, however this incurs in the same issues
described on BZ#12683: the cancellation is acted upon even *after*
syscall returns with user visible side-effects.

This patch removes this optimization and simplifies the pthread
cancellation implementation: pthread_cancel now first checks if
cancellation is already pending and if not always, sends a signal
if the target is not itself.  The SIGCANCEL handler is also simpified
since there is not need to setup a CAS loop.

It also allows to move both the cancellation state and mode out of
'cancelhadling' (it is done in subsequent patches).

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

3 years agonptl: Install cancellation handler on pthread_cancel
Adhemerval Zanella [Mon, 24 May 2021 21:56:59 +0000 (18:56 -0300)]
nptl: Install cancellation handler on pthread_cancel

Now that cancellation is not used anymore to handle thread setup
creation failure, the sighandle can be installed only when
pthread_cancel is actually used.

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

3 years agonptl: Deallocate the thread stack on setup failure (BZ #19511)
Adhemerval Zanella [Fri, 21 May 2021 17:19:23 +0000 (14:19 -0300)]
nptl: Deallocate the thread stack on setup failure (BZ #19511)

To setup either the thread scheduling parameters or affinity,
pthread_create enforce synchronization on created thread to wait until
its parent either release PD ownership or send a cancellation signal if
a failure occurs.

However, cancelling the thread does not deallocate the newly created
stack since cancellation expects that a pthread_join to deallocate any
allocated thread resouces (threads stack or TLS).

This patch changes on how the thread resource is deallocate in case of
failure to be synchronous, where the creating thread will signal the
created thread to exit early so it could be joined.  The creating thread
will be reponsible for the resource cleanup before returning to the
caller.

To signal the creating thread that a failure has occured, an unused
'struct pthread' member, parent_cancelhandling_unsed, now indicates
whether the setup has failed so creating thread can proper exit.

This strategy also simplifies by not using thread cancellation and
thus not running libgcc_so load in the signal handler (which is
avoided in thread cancellation since 'pthread_cancel' is the one
responsible to dlopen libgcc_s).  Another advantage is since the
early exit is move to first step at thread creation, the signal
mask is not already set and thus it can not act on change ID setxid
handler.

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

3 years agoRemove stale references to libdl.a
Florian Weimer [Wed, 9 Jun 2021 11:38:44 +0000 (13:38 +0200)]
Remove stale references to libdl.a

Since commit 0c1c3a771eceec46e66ce1183cf988e2303bd373
("dlfcn: Move dlopen into libc") libdl.a is empty, so linking
against it is no longer necessary.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoFix elf/tst-tls9-static after libdl cleanups.
Stefan Liebler [Wed, 9 Jun 2021 11:19:51 +0000 (13:19 +0200)]
Fix elf/tst-tls9-static after libdl cleanups.

The testcase elf/tst-tls9-static sometimes fails with:
cannot open 'tst-tlsmod5.so': tst-tlsmod5.so: cannot open shared object file: No such file or directory
cannot open 'tst-tlsmod6.so': tst-tlsmod6.so: cannot open shared object file: No such file or directory

After recent commit
6f1c701026287f6928d3bdd1aea7359308635abe
"dlfcn: Cleanups after -ldl is no longer required"
the libdl variable is not set anymore and thus the
dependencies were missing.