aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2019-08-28Revise the documentation of simple calendar time.zack/y2038-preliminariesZack Weinberg
This is a thorough revision of all the material relating to the functions time, stime, gettimeofday, settimeofday, clock_gettime, clock_getres, clock_settime, and difftime, spilling over into the discussion of time-related data types (which now get their own section) and touching the adjtime family as well (which deserves its own thorough revision, but I'd have to do a bunch of research first). Substantive changes are: * Document clock_gettime, clock_getres, and clock_settime. (Only CLOCK_REALTIME and CLOCK_MONOTONIC are documented; the others are either a bit too Linux-specific, or have more to do with measuring CPU/processor time. That section _also_ deserves its own thorough revision but again I'd have to do a bunch of research first.) * Present gettimeofday, settimeofday, and struct timeval as obsolete relative to clock_*. * Remove the documentation of struct timezone. Matching POSIX, say that the type of the second argument to gettimeofday and settimeofday is [const] void *. * Clarify ISO C and POSIX's requirements on time_t. Clarify the circumstances under which difftime is equivalent to simple subtraction. * Consolidate documentation of most of the time-related data types into a new section "Time Types," right after "Time Basics." (The exceptions are struct tm, which stays in "Broken-down Time," and struct times, which stays in "Processor And CPU Time." * The "Elapsed Time" section is now called "Calculating Elapsed Time" and includes only difftime and the discussion of how to compute timeval differences by hand. * Fold the "Simple Calendar Time," "High Resolution Calendar," and "High Accuracy Clock" sections together into two new sections titled "Getting the Time" and "Setting and Adjusting the Time." ChangeLog: * manual/time.texi: Major revision of text related to simple calendar time. clock_gettime, clock_getres, and clock_settime are now documented. * manual/filesys.texi, manual/llio.texi, manual/threads.texi: Update cross-references to renamed sections in time.texi.
2019-08-28Warn when gettimeofday is called with non-null tzp argument.Zack Weinberg
Since there are no known uses of gettimeofday's vestigial "get time zone" feature that are not bugs, add a fortify-style wrapper inline to sys/time.h that issues a warning whenever gettimeofday is called with a second argument that is not a compile-time null pointer constant. At present this is only possible with GCC; clang does not implement attribute((warning)). The wrapper is only activated when __OPTIMIZE__ is defined because it throws false positives when optimization is off, even though it's an always-inline function. An oversight in the implementation of __builtin_constant_p causes it to fail to detect compile-time *pointer* constants unless they are cast to an integer of a different size. (Loss of data in this cast is harmless; the overall expression is still constant if and only if the original pointer was.) This is GCC bug 95514. Thanks to Kamil Cukrowski <kamilcukrowski@gmail.com> for the workaround. As a precaution, I added a static assertion to debug/warning-nop.c to make sure that the cast _is_ casting to an integer of a different size; this is too unlikely a scenario to be worth checking in the public header, but if someone ever adds a port where short is the same size as intptr_t, we'll still catch it. Also make the public prototype of gettimeofday declare its second argument with type "void *" unconditionally, consistent with POSIX. * time/sys/time.h (__timezone_ptr_t): Delete. (gettimeofday): Always declare second argument with type "void *". When possible, wrap with a fortify-style inline function that detects non-null or non-constant second argument and issues a warning. Improve commentary. (settimeofday): Improve commentary. * time/gettimeofday.c (gettimeofday): Declare second argument with type "void *". * debug/warning-nop.c: Include sys/time.h and stdint.h. Add static_assert to verify the requirements of the workaround for GCC bug 95514.
2019-08-28Use clock_gettime to implement gettimeofday.Zack Weinberg
Remove sysdeps/unix/clock_gettime.c, which implemented clock_gettime using gettimeofday; new OS ports must provide a real implementation of clock_gettime. Rename sysdeps/mach/gettimeofday.c to sysdeps/mach/clock_gettime.c and convert into an implementation of clock_gettime. It only supports CLOCK_REALTIME; Mach does not appear to have any support for monotonic clocks. It uses __host_get_time, which provides at best microsecond resolution. Hurd is currently using sysdeps/posix/clock_getres.c for clock_getres; its output for CLOCK_REALTIME is based on sysconf (_SC_CLK_TCK), and I do not know whether that gives the correct result. Most Linux ports supplied a vDSO symbol for gettimeofday, and some wrapped that with an ifunc, so this patch deletes a lot of code. For ease of future edits to the many copies of _libc_vdso_platform_setup, the variable "p" in each is now declared separately from any use of it. Unlike settimeofday, there are no known uses of gettimeofday's vestigial "get time zone" feature that are not bugs. (The per-process timezone support in localtime and friends is unrelated, and the programs that set the kernel's offset between the hardware clock and UTC do not need to read it back.) Therefore, this feature is dummied out. Henceforth, if gettimeofday's "struct timezone" argument is not NULL, it will write zeroes to both fields. Any program that is actually looking at this data will thus think it is running in UTC, which is probably more correct than whatever it was doing before. [__]gettimeofday no longer has any internal callers, so we can now remove its internal prototype and PLT bypass aliases. The __gettimeofday@GLIBC_2.0 export remains, in case it is used by any third-party code. * time/gettimeofday.c: No longer a stub implementation. Call __clock_gettime. If tz argument is not NULL, clear the object it points to. Remove libc_hidden_* for __gettimeofday and gettimeofday. Optionally override the default symbol version for gettimeofday and __gettimeofday. * include/sys/time.h: Remove internal prototype and libc_hidden_proto for __gettimeofday, and libc_hidden_proto for gettimeofday. * sysdeps/unix/sysv/linux/alpha/gettimeofday.c: Switch to including time/gettimeofday.c. * sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c (gettimeofday@GLIBC_2.0): Use __clock_gettime instead of __gettimeofday. If tz argument is not NULL, clear the object it points to. * sysdeps/unix/sysv/linux/aarch64/init-first.c * sysdeps/unix/sysv/linux/arm/init-first.c * sysdeps/unix/sysv/linux/mips/init-first.c * sysdeps/unix/sysv/linux/powerpc/init-first.c * sysdeps/unix/sysv/linux/riscv/init-first.c * sysdeps/unix/sysv/linux/s390/init-first.c * sysdeps/unix/sysv/linux/sparc/init-first.c: Do not define nor initialize VDSO_SYMBOL(gettimeofday). * sysdeps/unix/sysv/linux/aarch64/libc-vdso.h * sysdeps/unix/sysv/linux/arm/libc-vdso.h * sysdeps/unix/sysv/linux/mips/libc-vdso.h * sysdeps/unix/sysv/linux/powerpc/libc-vdso.h * sysdeps/unix/sysv/linux/riscv/libc-vdso.h * sysdeps/unix/sysv/linux/s390/libc-vdso.h * sysdeps/unix/sysv/linux/sparc/libc-vdso.h: Do not declare VDSO_SYMBOL(gettimeofday). * sysdeps/unix/syscalls.list: Remove entry for gettimeofday. * sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove entries for gettimeofday and osf_gettimeofday. * sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list: Remove entry for gettimeofday. * sysdeps/posix/gettimeofday.c * sysdeps/unix/clock_gettime.c * sysdeps/unix/sysv/linux/aarch64/gettimeofday.c * sysdeps/unix/sysv/linux/gettimeofday.c * sysdeps/unix/sysv/linux/i386/gettimeofday.c * sysdeps/unix/sysv/linux/powerpc/gettimeofday.c * sysdeps/unix/sysv/linux/x86/gettimeofday.c: Delete file. * sysdeps/mach/gettimeofday.c: Rename to sysdeps/mach/clock_gettime.c and convert into an implementation of clock_gettime.
2019-08-28Use clock_gettime to implement timespec_get.Zack Weinberg
timespec_get is the same function as clock_gettime, with an obnoxious coating of NIH painted on it by the ISO C committee. In addition to the rename, it takes its arguments in a different order, it returns 0 on *failure* or a positive number on *success*, and it requires that all of its TIME_* constants be positive. This last means we cannot directly reuse the existing CLOCK_* constants for it, because those have been allocated starting with CLOCK_REALTIME = 0 on all existing platforms. As such I think the most sensible GNUish policy for this function is that we will provide it, but we will not recommend its use, we will not go out of our way to make it efficient, and we will not attempt to extend the set of TIME_* constants beyond the ones defined in ISO C (and in POSIX, if it ever appears in POSIX). This patch simply promotes the sysdeps/posix implementation to universal, and removes the Linux-specific implementation, whose apparent reason for existing was to cut out one function call's worth of overhead. Oh well. * sysdeps/posix/timespec_get.c * sysdeps/unix/sysv/linux/timespec_get.c: Delete file. * time/timespec_get.c: No longer a stub. Replace implementation with the code formerly in sysdeps/posix/timespec_get.c.
2019-08-28Use clock_gettime to implement ftime; withdraw ftime.Zack Weinberg
ftime is an obsolete variation on gettimeofday, offering only millisecond time resolution; it was probably a system call in ooold versions of BSD Unix. For historic reasons, we had three implementations of it. These are all consolidated into time/ftime.c, and then the function is made a compatibility symbol. The public header file that declared it, its result structure, and nothing else, is removed. For some reason, the implementation of ftime in terms of gettimeofday was rounding rather than truncating microseconds to milliseconds. In all the other places where we use a higher-resolution time function to implement a lower-resolution one, we truncate. ftime is changed to match, just for tidiness' sake. Like gettimeofday, ftime tries to report the time zone, and using that information is always a bug. This patch dummies out the reported timezone information; the timezone and dstflag fields of the returned "struct timeb" will always be zero. * time/sys/timeb.h * time/tst-ftime.c * time/sys/timeb.h * sysdeps/unix/bsd/ftime.c * sysdeps/unix/sysv/linux/ftime.c: Delete file. * time/tst-ftime_l.c: Rename to tst-strftime_l.c. * time/ftime.c (ftime): Make a compatibility-only symbol. Replace implementation with the code formerly in sysdeps/unix/bsd/ftime.c, then change that code to use __clock_gettime instead of __gettimeofday and to truncate rather than rounding. Always set the timezone and dstflag fields of the timebuf argument to zero. * time/Makefile (headers): Remove sys/timeb.h. (tests): Remove tst-ftime, change tst-ftime_l to tst-strftime_l. * conform/Makefile: XFAIL all tests related to sys/timeb.h.
2019-08-28Use clock_gettime to implement time.Zack Weinberg
Most ports were using gettimeofday to implement time, or they were making a direct (v)syscall. Unconditionally switch to using clock_gettime instead. All sysdeps implementations of time are removed. * time/time.c (time): No longer a stub implementation. Call __clock_gettime. * sysdeps/unix/sysv/linux/powerpc/Versions (GLIBC_PRIVATE): Remove __vdso_time. * sysdeps/unix/sysv/linux/powerpc/init-first.c (__vdso_time): Delete. (_libc_vdso_platform_setup): Don't initialize __vdso_time. * sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list: Remove entry for time. * sysdeps/posix/time.c * sysdeps/unix/sysv/linux/time.c * sysdeps/unix/sysv/linux/i386/time.c * sysdeps/unix/sysv/linux/powerpc/time.c * sysdeps/unix/sysv/linux/sparc/sparc64/time.c * sysdeps/unix/sysv/linux/x86/time.c: Delete file.
2019-08-28Use clock_settime to implement settimeofday.Zack Weinberg
Unconditionally, on all ports, use clock_settime to implement settimeofday. Remove sysdeps/unix/clock_settime.c, which implemented clock_settime by calling settimeofday; new OS ports must henceforth provide a real implementation of clock_settime. Hurd had a real implementation of settimeofday but not of clock_settime; this patch converts it into an implementation of clock_settime. It only supports CLOCK_REALTIME and microsecond resolution; Hurd/Mach does not appear to have any support for finer-resolution clocks. The vestigial "set time zone" feature of settimeofday complicates the generic settimeofday implementation a little. The only remaining uses of this feature that aren't just bugs, are using it to inform the Linux kernel of the offset between the hardware clock and UTC, on systems where the hardware clock doesn't run in UTC (usually because of dual-booting with Windows). There currently isn't any other way to do this. However, the callers that do this call settimeofday with _only_ the timezone argument non-NULL. Therefore, glibc's new behavior is: callers of settimeofday must supply one and only one of the two arguments. If both arguments are non-NULL, or both arguments are NULL, the call fails and sets errno to EINVAL. When only the timeval argument is supplied, settimeofday calls __clock_settime(CLOCK_REALTIME), same as stime. When only the timezone argument is supplied, settimeofday calls a new internal function called __settimezone. On Linux, only, this function will pass the timezone structure to the settimeofday system call. On all other operating systems, and on Linux architectures that don't define __NR_settimeofday, __settimezone is a stub that always sets errno to ENOSYS and returns -1. The same semantics are implemented for Linux/Alpha's GLIBC_2.0 compat symbol for settimeofday. There are no longer any internal callers of __settimeofday, so the internal prototype is removed. * time/settimeofday.c (settimeofday): No longer a stub implementation. Call __clock_settime or __settimezone depending on arguments. Optionally override the default symbol version for settimeofday. * include/sys/time.h: Remove prototype for __settimeofday. Add prototype for __settimezone. * sysdeps/unix/syscalls.list: Remove entry for settimeofday. * time/settimezone.c: New file. (__settimezone): New stub implementation. * sysdeps/unix/sysv/linux/settimezone.c: New file. (__settimezone): Implement using settimeofday system call, if available. * time/Makefile (routines): Add settimezone. * sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove entries for settimeofday and osf_settimeofday. * sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c New file, defines settimeofday@GLIBC_2.0. * sysdeps/unix/sysv/linux/alpha/settimeofday.c: New file, defines settimeofday@@GLIBC_2.1. * sysdeps/unix/clock_gettime.c: Delete file. * sysdeps/mach/hurd/settimeofday.c: Rename to sysdeps/mach/hurd/clock_settime.c and convert into an implementation of clock_settime.
2019-08-28Use clock_settime to implement stime; withdraw stime.Zack Weinberg
Unconditionally, on all ports, use clock_settime to implement stime, not settimeofday or a direct syscall. Then convert stime into a compatibility symbol and remove its prototype from time.h. * time/stime.c (stime): No longer a stub implementation. Call __clock_settime. Demote to a compatibility symbol. * sysdeps/unix/stime.c: Delete file. * sysdeps/unix/sysv/linux/syscalls.list: Remove entry for stime. * time/time.h: Remove prototype for stime.
2019-08-28Finish move of clock_* functions to libc.Zack Weinberg
In glibc 2.17, the functions clock_getcpuclockid, clock_getres, clock_gettime, clock_nanosleep, and clock_settime were moved from librt.so to libc.so, leaving compatibility stubs behind. Now that the dynamic linker no longer insists on finding versioned symbols in the same library that originally defined them, we do not need the stubs anymore, and this means we don't need GLIBC_PRIVATE __-prefix aliases for most of the functions anymore either. (clock_gettime still needs one.) For ports added before 2.17, libc.so needs to provide two symbol versions for each, the default at GLIBC_2.17 plus a compat version matching what librt had. While I'm at it, move the clock_*.c files and their tests from rt/ to time/. * rt/clock_getcpuclockid.c: Move to time/clock_getcpuclockid.c. * rt/clock_getres.c: Move to time/clock_getres.c. * rt/clock_gettime.c: Move to time/clock_gettime.c. * rt/clock_nanosleep.c: Move to time/clock_nanosleep.c. * rt/clock_settime.c: Move to time/clock_settime.c. * rt/tst-clock.c: Move to time/tst-clock.c. * rt/tst-clock2.c: Move to time/tst-clock2.c. * rt/tst-clock_nanosleep.c: Move to time/tst-clock_nanosleep.c. * rt/tst-cpuclock1.c: Move to time/tst-cpuclock1.c. * rt/clock-compat.c: Delete file. * time/clock_getcpuclockid.c * time/clock_getres.c * time/clock_gettime.c * time/clock_nanosleep.c * time/clock_settime.c * sysdeps/posix/clock_getres.c * sysdeps/unix/clock_gettime.c * sysdeps/unix/clock_nanosleep.c * sysdeps/unix/clock_settime.c * sysdeps/unix/sysv/linux/clock_getcpuclockid.c * sysdeps/unix/sysv/linux/clock_getres.c * sysdeps/unix/sysv/linux/clock_gettime.c * sysdeps/unix/sysv/linux/clock_nanosleep.c * sysdeps/unix/sysv/linux/clock_settime.c: Define the function defined by this file with default symbol version GLIBC_2_17, and optionally a compatibility alias at symbol version GLIBC_2_2. * include/time.h: Remove internal prototypes for clock_getres, clock_nanosleep, and clock_getcpuclockid. * sysdeps/unix/sysv/linux/clock_gettime.c: Prune includes. Remove unused function realtime_gettime. * rt/Makefile (clock-routines, routines): Remove variable. (librt-routines): Remove clock-compat. (tests): Remove tst-clock, tst-clock2, tst-clock_nanosleep, and tst-cpuclock1. * time/Makefile (routines): Add clock_getres, clock_gettime, clock_settime, clock_getcpuclockid, and clock_nanosleep. (tests): Add tst-clock, tst-clock2, tst-clock_nanosleep, and tst-cpuclock1. * rt/Versions (libc): Remove entire stanza. (librt GLIBC_2.2): Remove all clock_* functions. * time/Versions (libc GLIBC_2.2, libc GLIBC_2.17): Add clock_getres, clock_gettime, clock_settime, clock_getcpuclockid, and clock_nanosleep. (libc GLIBC_PRIVATE): Add __clock_gettime. * sysdeps/mach/hurd/i386/librt.abilist * sysdeps/unix/sysv/linux/alpha/librt.abilist * sysdeps/unix/sysv/linux/arm/librt.abilist * sysdeps/unix/sysv/linux/hppa/librt.abilist * sysdeps/unix/sysv/linux/i386/librt.abilist * sysdeps/unix/sysv/linux/ia64/librt.abilist * sysdeps/unix/sysv/linux/m68k/coldfire/librt.abilist * sysdeps/unix/sysv/linux/m68k/m680x0/librt.abilist * sysdeps/unix/sysv/linux/microblaze/librt.abilist * sysdeps/unix/sysv/linux/mips/mips32/librt.abilist * sysdeps/unix/sysv/linux/mips/mips64/librt.abilist * sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist * sysdeps/unix/sysv/linux/powerpc/powerpc64/be/librt.abilist * sysdeps/unix/sysv/linux/s390/s390-32/librt.abilist * sysdeps/unix/sysv/linux/s390/s390-64/librt.abilist * sysdeps/unix/sysv/linux/sh/librt.abilist * sysdeps/unix/sysv/linux/sparc/sparc32/librt.abilist * sysdeps/unix/sysv/linux/sparc/sparc64/librt.abilist * sysdeps/unix/sysv/linux/x86_64/64/librt.abilist * sysdeps/unix/sysv/linux/x86_64/x32/librt.abilist: Remove entries for clock_getres, clock_gettime, clock_settime, clock_getcpuclockid, and clock_nanosleep. * sysdeps/mach/hurd/i386/libc.abilist * sysdeps/unix/sysv/linux/alpha/libc.abilist * sysdeps/unix/sysv/linux/arm/libc.abilist * sysdeps/unix/sysv/linux/hppa/libc.abilist * sysdeps/unix/sysv/linux/i386/libc.abilist * sysdeps/unix/sysv/linux/ia64/libc.abilist * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist * sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist * sysdeps/unix/sysv/linux/sh/libc.abilist * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Add another set of entries for clock_getres, clock_gettime, clock_settime, clock_getcpuclockid, and clock_nanosleep at whatever version GLIBC_2.2 maps to.
2019-08-28Change most internal uses of __gettimeofday to __clock_gettime.Zack Weinberg
Since gettimeofday will shortly be implemented in terms of clock_gettime on all platforms, internal code should use clock_gettime directly; in addition to removing a layer of indirection, this will allow us to remove the PLT-bypass gunk for gettimeofday. (We can't quite do that yet, but it'll be coming later in this patch series.) In many cases, the changed code does fewer conversions. The changed code always assumes __clock_gettime (CLOCK_REALTIME) cannot fail. Most of the call sites were assuming gettimeofday could not fail, but a few places were checking for errors. POSIX says clock_gettime can only fail if the clock constant is invalid or unsupported, and CLOCK_REALTIME is the one and only clock constant that's required to be supported. For consistency I grepped the entire source tree for any other places that checked for errors from __clock_gettime (CLOCK_REALTIME), found one, and changed it too. (For the record, POSIX also says gettimeofday can never fail.) (It would be nice if we could declare that GNU systems will always support CLOCK_MONOTONIC as well as CLOCK_REALTIME; there are several places where we are using CLOCK_REALTIME where _MONOTONIC would be more appropriate, and/or trying to use _MONOTONIC and then falling back to _REALTIME. But the Hurd doesn't support CLOCK_MONOTONIC yet, and it looks like adding it would involve substantial changes to gnumach's internals and API. Oh well.) A few Hurd-specific files were changed to use __host_get_time instead of __clock_gettime, as this seemed tidier. We also assume this cannot fail. Skimming the code in gnumach leads me to believe the only way it could fail is if __mach_host_self also failed, and our Hurd-specific code consistently assumes that can't happen, so I'm going with that. With the exception of support/support_test_main.c, test cases are not modified, mainly because I didn't want to have to figure out which test cases were testing gettimeofday specifically. The definition of GETTIME in sysdeps/generic/memusage.h had a typo and was not reading tv_sec at all. I fixed this. It appears nobody has been generating malloc traces on a machine that doesn't have a superseding definition. There are a whole bunch of places where the code could be simplified by factoring out timespec subtraction and/or comparison logic, but I want to keep this patch as mechanical as possible. * inet/deadline.c (__deadline_current_time) * login/logout.c (logout) * login/logwtmp.c (logwtmp) * nis/nis_call.c (__nisfind_server) * nptl/pthread_join_common.c (timedwait_tid) * nptl/pthread_mutex_timedlock.c (__pthread_mutex_clocklock_common) * nscd/nscd_helper.c (wait_on_socket, open_socket) * resolv/gai_misc.c (handle_requests) * resolv/gai_suspend.c (gai_suspend) * resolv/res_send.c (evNowTime) * sunrpc/auth_des.c (authdes_marshal, authdes_destroy) * sunrpc/auth_unix.c (authunix_create, authunix_refresh) * sunrpc/create_xid.c (_create_xid) * sunrpc/svcauth_des.c (_svcauth_des) * sysdeps/generic/memusage.h (GETTIME) * sysdeps/mach/nanosleep.c (__libc_nanosleep) * sysdeps/posix/tempname.c (RANDOM_BITS) * sysdeps/pthread/aio_misc.c (handle_fildes_io) * sysdeps/pthread/aio_suspend.c (aio_suspend): Use __clock_gettime (CLOCK_REALTIME) instead of __gettimeofday. Assume __clock_gettime (CLOCK_REALTIME) cannot fail. Include time.h if necessary. * sysdeps/posix/timespec_get.c (timespec_get): Assume __clock_gettime (CLOCK_REALTIME) cannot fail. * sysdeps/mach/hurd/getitimer.c (__getitimer) * sysdeps/mach/hurd/setitimer.c (setitimer_locked) * sysdeps/mach/hurd/times.c (__times): Use __host_get_time instead of __gettimeofday. Include mach.h if necessary. Assume __host_get_time (__mach_host_self ()) cannot fail. * sysdeps/mach/usleep.c (usleep): Remove unnecessary calls to __gettimeofday. * support/support_test_main.c (print_timestamp): Take a struct timespec argument, not a struct timeval. (signal_handler): Update to match. Use clock_gettime (CLOCK_REALTIME) instead of gettimeofday. Assume clock_gettime (CLOCK_REALTIME) cannot fail. * sysdeps/generic/memusage.h (GETTIME): Correct typo causing the seconds field of each timestamp to be ignored. * sysdeps/unix/make-syscall.sh: Change an example in a comment from referring to gettimeofday, to referring to sigaction.
2019-08-28Linux/Alpha: don't use timeval32 system calls.Zack Weinberg
Linux/Alpha has two versions of several system call wrappers that take or return data of type "struct timeval" (possibly nested inside a larger structure). The GLIBC_2.0 version is a compat symbol that calls __NR_osf_foo or __NR_old_foo and uses a struct timeval with a 32-bit tv_sec field. The GLIBC_2.1 version is used for current code, calls __NR_foo, and uses a struct timeval with a 64-bit tv_sec field. This patch changes all of the compat symbols of this type to be wrappers around their GLIBC_2.1 counterparts; the compatibility system calls will no longer be used. It serves as a proposal for part of how we do the transition to 64-bit time_t on systems that currently use 32-bit time_t: * The patched glibc will NOT use system calls that involve 32-bit time_t to implement its compatibility symbols. This will make both our lives and the kernel maintainers' lives easier. The primary argument I've seen against it is that the kernel could warn about uses of the old system calls, helping people find old binaries that need to be recompiled. I think there are several other ways we could accomplish this, e.g. scripts to scan the filesystem for binaries with references to the old symbol versions, or issuing diagnostics ourselves. * The compat symbols do NOT report failure after the Y2038 deadline. An earlier revision of this patch had them return -1 and set errno to EOVERFLOW, but Adhemerval pointed out that many of them have already performed side effects at the point where we discover the overflow, so that would break more than it fixes. Also, we don't want people to be _checking_ for EOVERFLOW from these functions; we want them to recompile with 64-bit time_t. So it's not actually useful for them to report failure to the calling code. * What they do do, when they encounter overflow, is saturate the overflowed "struct timeval"(s): tv_sec is set to INT32_MAX and tv_nsec is set to 999999. That means time stops advancing for programs with 32-bit time_t when they reach the deadline. That's obviously going to break stuff, but I think wrapping around is probably going to break _more_ stuff. I'd be interested to hear arguments against, if anyone has one. The new header file tv32-compat.h is currently Alpha-specific but I mean for it to be reused to aid in writing wrappers for all affected architectures. I only put it in sysdeps/unix/sysv/linux/alpha for now because I haven't checked whether the various "foo32" structures it defines agree with the ABI for ports other than Linux/Alpha. * sysdeps/unix/sysv/linux/alpha/tv32-compat.h: New file declaring types and helper functions for 32/64-bit time_t conversion. * sysdeps/unix/sysv/linux/syscalls.list: Remove entry for adjtimex. * sysdeps/unix/sysv/linux/adjtimex.c: New file, allow overriding the version at which adjtimex and ntp_adjtime are defined. * sysdeps/unix/sysv/linux/adjtime.c: Allow overriding the version at which adjtime is defined. (MOD_OFFSET, TIMEVAL, TIMEX, ADJTIME, ADJTIMEX, NO_LOCAL_ADJTIME) (LINKAGE): Remove macros that are no longer needed. * sysdeps/unix/sysv/linux/Makefile (sysdep_routines) [subdir=misc]: Add adjtimex. * sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove entries for osf_gettimeofday, osf_settimeofday, osf_getitimer, osf_setitimer, osf_utimes, osf_getrusage, and osf_wait4. Change entries for gettimeofday, settimeofday, getitimer, setitimer, utimes, getrusage, and wait4 to use argument type codes. * sysdeps/unix/sysv/linux/alpha/adjtime.c: Replace contents; use the generic Linux implementation but override the version of adjtime. * sysdeps/unix/sysv/linux/alpha/adjtimex.c: New file, use the generic Linux implementation but override the versions of adjtimex and ntp_adjtime. * sysdeps/unix/sysv/linux/alpha/osf_adjtime.c * sysdeps/unix/sysv/linux/alpha/osf_getitimer.c * sysdeps/unix/sysv/linux/alpha/osf_getrusage.c * sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c * sysdeps/unix/sysv/linux/alpha/osf_setitimer.c * sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c * sysdeps/unix/sysv/linux/alpha/osf_utimes.c * sysdeps/unix/sysv/linux/alpha/osf_wait4.c: New files defining compatibility symbols formerly defined by alpha/syscalls.list and alpha/adjtime.c. * sysdeps/unix/sysv/linux/alpha/Makefile (sysdep_routines) [subdir=misc]: Add osf_adjtime.
2019-08-28misc: Use allocate_once in getmntentFlorian Weimer
Both the buffer and struct mntent are now allocated on the heap. This results in a slight reduction of RSS usage. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-08-28nptl: Move pthread_attr_setdetachstate implementation into libcFlorian Weimer
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-08-28login: pututxline could fail to overwrite existing entries [BZ #24902]Florian Weimer
The internal_getut_r function updates the file_offset variable and therefore must always update last_entry as well. Previously, if pututxline could not upgrade the read lock to a write lock, internal_getut_r would update file_offset only, without updating last_entry, and a subsequent call would not overwrite the existing utmpx entry at file_offset, instead creating a new entry. This has been observed to cause unbounded file growth in high-load situations. This commit removes the buffer argument to internal_getut_r and updates the last_entry variable directly, along with file_offset. Initially reported and fixed by Ondřej Lysoněk. Reviewed-by: Gabriel F. T. Gomes <gabrielftg@linux.ibm.com>
2019-08-28Fix posix/tst-regex by using a dedicated input-file.Stefan Liebler
The recent commit e6855a3bdfe147c52b29b5e7d70a95a8aa22ece0 changed the encoding of ChangeLog.old/ChangeLog.8 from ISO-8859 to UTF-8. Unfortunately the test posix/tst-regex assumes the former encoding. Furthermore Francesco Potortì is now written with 'ì' instead of 'i`' which would lead to two further matches in the first call to test_expr. This patch just copies the former ChangeLog.8 file to tst-regex.input and adjusts the test in order to use this new input file. ChangeLog: * posix/tst-regex.c (do_test): Use tst-regex.input as input file. * posix/tst-regex.input: New file.
2019-08-23Don't put non-ASCII into installed headersPaul Eggert
Move non-ASCII contributor names from installed headers into contrib.texi when possible, and when it's not (the copyright notice in sysdeps/unix/sysv/linux/mips/sys/user.h) go back to ASCIIfied names. Problem reported by Joseph Myers in: https://www.sourceware.org/ml/libc-alpha/2019-08/msg00646.html
2019-08-23Fix spellings of contributor names in comments and docPaul Eggert
2019-08-23[MIPS] Raise highest supported EI_ABIVERSION value [BZ #24916]Mihailo Stojanovic
This bumps the highest valid EI_ABIVERSION value to ABSOLUTE ABI. New testcase loads the symbol from the GOT with the "lb" instruction so that the EI_ABIVERSION header field of the shared object is set to ABSOLUTE (it doesn't actually check the value of the symbol), and makes sure that the main executable is executed without "ABI version invalid" error. Tested for all three ABIs (o32, n32, n64) using both static linker which handles undefined weak symbols correctly [1] (and sets the EI_ABIVERSION of the test module) and the one that doesn't (EI_ABIVERSION left as 0). [1] https://sourceware.org/ml/binutils/2018-07/msg00268.html [BZ #24916] * sysdeps/mips/Makefile [$(subdir) = elf] (tests): Add tst-undefined-weak. [$(subdir) = elf] (modules-names): Add tst-undefined-weak-lib. [$(subdir) = elf] ($(objpfx)tst-undefined-weak): Add dependency. * sysdeps/mips/tst-undefined-weak-lib.S: New file. * sysdeps/mips/tst-undefined-weak.c: Likewise. * sysdeps/unix/sysv/linux/mips/ldsodefs.h (VALID_ELF_ABIVERSION): Increment highest valid ABIVERSION value.
2019-08-23mips: Force RWX stack for hard-float builds that can run on pre-4.8 kernelsDragan Mladjenovic
Linux/Mips kernels prior to 4.8 could potentially crash the user process when doing FPU emulation while running on non-executable user stack. Currently, gcc doesn't emit .note.GNU-stack for mips, but that will change in the future. To ensure that glibc can be used with such future gcc, without silently resulting in binaries that might crash in runtime, this patch forces RWX stack for all built objects if configured to run against minimum kernel version less than 4.8. * sysdeps/unix/sysv/linux/mips/Makefile (test-xfail-check-execstack): Move under mips-has-gnustack != yes. (CFLAGS-.o*, ASFLAGS-.o*): New rules. Apply -Wa,-execstack if mips-force-execstack == yes. * sysdeps/unix/sysv/linux/mips/configure: Regenerated. * sysdeps/unix/sysv/linux/mips/configure.ac (mips-force-execstack): New var. Set to yes for hard-float builds with minimum_kernel < 4.8.0 or minimum_kernel not set at all. (mips-has-gnustack): New var. Use value of libc_cv_as_noexecstack if mips-force-execstack != yes, otherwise set to no.
2019-08-23linux: Make profil_counter a compat_symbol (BZ#17726)Adhemerval Zanella
As indicated by Joseph's comment on BZ#17726, this symbol is most likely a historical ABI accident. This patch make it on both arm and sparc ABIs a compat_symbol. Checked against a build arm-linux-gnueabihf, sparcv9-linux-gnu, adn sparc64-linux-gnu to see if the symbol is still present. * gmon/Versions (libc) [GLIBC_2.31]: New entry. * sysdeps/unix/sysv/linux/arm/profil-counter.h (profil_counter): Make a compat_symbol. * sysdeps/unix/sysv/linux/sparc/profil-counter.h (__profil_counter_global): Likewise.
2019-08-23Refactor sigcontextinfo.hAdhemerval Zanella
This patch refactor sigcontextinfo.h header to use SA_SIGINFO as default for both gmon and debug implementations. This allows simplify profil-counter.h on Linux to use a single implementation and remove the requirements for newer ports to redefine __sigaction/sigaction to use SA_SIGINFO. The GET_PC macro is also replaced with a function sigcontext_get_pc that returns an uintptr_t instead of a void pointer. It allows easier convertion to integer on ILP32 architecture, such as x32, without the need to suppress compiler warnings. The patch also requires some refactor of register-dump.h file for some architectures (to reflect it is now called from a sa_sigaction instead of sa_handler signal context). - Alpha, i386, and s390 are straighfoward to take in consideration the new argument type. - ia64 takes in consideration the kernel pass a struct sigcontextt as third argument for sa_sigaction. - sparc take in consideration the kernel pass a pt_regs struct as third argument for sa_sigaction. - m68k dummy function is removed and the FP state is dumped on register_dump itself. - For SH the register-dump.h file is consolidate on a common implementation and the floating-point state is checked based on ownedfp field. The register_dump does not change its output format in any affected architecture. I checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, arm-linux-gnueabihf, sparcv9-linux-gnu, sparc64-linux-gnu, powerpc-linux-gnu, powerpc64-linux-gnu, and powerpc64le-linux-gnu. I also checked the libSegFault.so through catchsegv on alpha-linux-gnu, m68k-linux-gnu and sh4-linux-gnu to confirm the output has not changed. Adhemerval Zanella <adhemerval.zanella@linaro.org> Florian Weimer <fweimer@redhat.com> * debug/segfault.c (install_handler): Use SA_SIGINFO if defined. * sysdeps/generic/profil-counter.h (__profil_counter): Cast to uintptr_t. * sysdeps/generic/sigcontextinfo.h (GET_PC): Rename to sigcontext_get_pc and return aligned cast to uintptr_t. * sysdeps/mach/hurd/i386/sigcontextinfo.h (GET_PC): Likewise. * sysdeps/posix/profil.c (profil_count): Change PC argument to uintptr_t. (__profil): Use SA_SIGINFO. * sysdeps/posix/sprofil.c (profil_count): Change PCP argument to uintptr_t. (__sprofil): Use SA_SIGINFO. * sysdeps/unix/sysv/linux/profil-counter.h: New file. * sysdeps/unix/sysv/linux/aarch64/profil-counter.h: Remove file. * sysdeps/unix/sysv/linux/csky/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/hppa/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/i386/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/ia64/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/microblaze/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/mips/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/nios2/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/powerpc/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/x86_64/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/riscv/profil-counter.h: Likewise. * sysdeps/sysv/linux/s390/s390-32/profil-counter.h: Likewise. * sysdeps/sysv/linux/s390/s390-64/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/sh/profil-counter.h: Likewise. * sysdeps/unix/sysv/linux/arm/profil-counter.h (__profil_counter): Assume SA_SIGINFO and use sigcontext_get_pc instead of GET_PC. * sysdeps/unix/sysv/linux/sparc/profil-counter.h: New file. * sysdeps/unix/sysv/linux/sparc/sparc64/profil-counter.h: Remove file. * sysdeps/unix/sysv/linux/sparc/sparc32/profil-counter.h: Likewise. * sysdpes/unix/sysv/linux/aarch64/sigcontextinfo.h (SIGCONTEXT, GET_PC, __sigaction, sigaction): Remove defines. (sigcontext_get_pc): New function. * sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/arm/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/csky/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/hppa/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/i386/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/mips/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/s390/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/microblaze/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/sh/sigcontextinfo.h: Likewise. * sysdeps/sysv/linux/sparc/sparc32/sigcontextinfo.h: Likewise. * sysdeps/sysv/linux/sparc/sparc64/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/alpha/register-dump.h (register_dump): Handle CTX argument as ucontext_t. * sysdeps/unix/sysv/linux/i386/register-dump.h: Likewise. Likewise. * sysdeps/unix/sysv/linux/m68k/register-dump.h: Likewise. * sysdeps/sysv/linux/s390/s390-32/register-dump.h: Likewise. * sysdeps/sysv/linux/s390/s390-64/register-dump.h: Likewise. * sysdeps/unix/sysv/linux/sh/register-dump.h: New file. * sysdeps/unix/sysv/linux/sh/sh4/register-dump.h: Remove File. * sysdeps/unix/sysv/linux/sh/sh3/register-dump.h: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/register-dump.h: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/register-dump.h: Likewise. * sysdeps/unix/sysv/linux/Makefile (tests-internal): Add tst-sigcontextinfo-get_pc. * sysdeps/unix/sysv/linux/tst-sigcontextinfo-get_pc.c: New file. (CFLAGS-tst-sigcontextinfo-get_pc.c): New rule.
2019-08-23Add RTLD_SINGLE_THREAD_P on generic single-thread.hAdhemerval Zanella
* sysdeps/generic/single-thread.h (RTLD_SINGLE_THREAD_P): Add definition.
2019-08-23Chinese locales: Set first_weekday to 2 (bug 24682).Rafal Luzynski
The first day of the week in China (Mainland) should be Monday according to the national standard GB/T 7408-2005. References: * https://www.doc88.com/p-1166696540287.html * https://unicode-org.atlassian.net/browse/CLDR-11510 [BZ #24682] * localedata/locales/bo_CN (first_weekday): Add, set to 2 (Monday). * localedata/locales/ug_CN (first_weekday): Likewise. * localedata/locales/zh_CN (first_weekday): Likewise.
2019-08-22powerpc: Fix typos and field name in commentsGustavo Romero
Fix a couple of typos and v_regs field name in mcontext_t. * sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h: Fix typos and field name in mcontext_t struct. Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
2019-08-22Mark IDN tests unsupported with libidn2 before 2.0.5.Joseph Myers
When using a system (e.g. Ubuntu 18.04) with libidn2 2.0.4 or earlier, test results include: FAIL: resolv/tst-resolv-ai_idn FAIL: resolv/tst-resolv-ai_idn-latin1 It was previously stated <https://sourceware.org/ml/libc-alpha/2018-05/msg00771.html> that "It should fail to indicate you have bugs in your system libidn.". However, the glibc testsuite should be indicating whether there are bugs in glibc, not whether there are bugs in other system pieces - so unless you consider it a glibc bug that it fails to work around the libidn issues, these FAILs are not helpful. And as a general principle, it's best for the expected glibc test results to be clean, with Bugzilla used to track known bugs in glibc itself, rather than people needing to know about the expected FAILs to tell if there are problems with their glibc build. So, while there is an argument that install.texi (not just the old NEWS entries for 2.28) should explain the use of libidn2 and that 2.0.5 or later is recommended, test FAILs are not the right way to indicate the presence of an old libidn2 version. This patch accordingly makes those tests return UNSUPPORTED for older libidn2 versions, just as they do when libidn2 isn't present at all. As implied by that past discussion, it's possible this could result in UNSUPPORTED for systems with older versions but whatever required fixes backported so the tests previously passed, if there are any such systems. Tested for x86_64 on Ubuntu 18.04, including verifying that putting an earlier version in place of 2.0.5 results in the tests FAILing whereas using 2.0.5 as in the patch results in UNSUPPORTED. Florian reports that the tests still run on Fedora 30, with libidn 2.2.0. * resolv/tst-resolv-ai_idn-latin1.c (do_test): Mark test unsupported with libidn2 before 2.0.5. * resolv/tst-resolv-ai_idn.c (do_test): Likewise.
2019-08-22Document strftime %Ob and %OB as C2X features.Joseph Myers
C2X standardizes strftime %Ob and %OB support. This patch updates the glibc manual to say these are C2X features, while noting that the details of what is the alternative form of a month name are not specified in C2X. Note: C2X seems unclear to me about whether %h being equivalent to %b means %Oh is thereby allowed and equivalent to %Ob; I've asked WG14. Tested with "make info" and "make pdf". * manual/time.texi (strftime): Document %Ob and %OB as C2X features.
2019-08-21Remove dead regex codePaul Eggert
* posix/regex_internal.c (re_node_set_insert): Remove unnecessary assignment. Reported by Tim Rühsen in: https://lists.gnu.org/r/bug-gnulib/2019-08/msg00026.html
2019-08-21Fix bad pointer / leak in regex codePaul Eggert
This was found by Coverity (CID 1484201). [BZ#24844] * posix/regex_internal.c (create_cd_newstate): Fix use of bad pointer and/or memory leak when storage is exhausted.
2019-08-21Don't use the argument to time.Zack Weinberg
It doesn't make sense to remove all the internal uses of time. It's still a standard ISO C function, and its callers don't need sub-second resolution and would be unnecessarily complicated if they had to declare a struct timespec instead of just a time_t. However, a handful of places were using the vestigial "result" argument instead of the return value, which is slightly less efficient and also looks strange. Correct this. * misc/syslog.c (__vsyslog_internal) * time/getdate.c (__getdate_r) * time/tst_wcsftime.c (main): Use return value of time, not its argument. * string/strfry.c (strfry) * sysdeps/mach/sleep.c (__sleep): Remove unnecessary casts of NULL in calls to time.
2019-08-21Add tgmath.h macros for narrowing functions.Joseph Myers
When adding some of the TS 18661 narrowing functions for glibc 2.28, I deferred adding corresponding <tgmath.h> support because of unresolved questions about the specification for those type-generic macros, especially in relation to _FloatN and _FloatNx types. Those issues are now clarified in the response to Clarification Request 13 to TS 18661-3, and this patch adds the deferred tgmath.h support. As with other tgmath.h macros, there are fairly straightforward implementations based on __builtin_tgmath for GCC 8 and later, which result in exactly the right function being called in each case, and more complicated implementations for GCC 7 and earlier, which generally result in a function being called whose arguments have the right format (i.e. an alias for the right function), but which might not be exactly the function name specified by TS 18661. In one case with older compilers (f32x* macros, where the type _Float64x exists and all the arguments have type _Float32 or _Float32x), there is a further relaxation and the function called may have arguments narrower than the one specified by the TS, but still wide enough to represent the arguments exactly, so the result of the call is unchanged (as this does not affect any case where rounding of integer arguments might be involved). With GCC 6 or before this is inherently unavoidable (but still harmless and not detectable by how the compiled program behaves, unless it redefines the functions in question like the testcases do) because _Float32x and _Float64 are both typedefs for double in that case but the specified semantics result in different functions, with different argument formats, being called for those two argument types. Tests for the new macros are handled through gen-tgmath-tests.py, which deals with the special-case handling for older GCC. Tested as follows: with the full glibc testsuite on x86_64 and x86 (with GCC 6, 7 and 8); with the math/ tests on aarch64 and arm (with GCC 6, 7 and 8); with build-many-glibcs.py (with GCC 6, 7 and 9). * math/tgmath.h [__HAVE_FLOAT128X]: Give error. [(__HAVE_FLOAT64X && !__HAVE_FLOAT128) || (__HAVE_FLOAT128 && !__HAVE_FLOAT64X)]: Likewise. (__TGMATH_2_NARROW_F): Likewise. (__TGMATH_2_NARROW_D): New macro. (__TGMATH_2_NARROW_F16): Likewise. (__TGMATH_2_NARROW_F32): Likewise. (__TGMATH_2_NARROW_F64): Likewise. (__TGMATH_2_NARROW_F32X): Likewise. (__TGMATH_2_NARROW_F64X): Likewise. [__HAVE_BUILTIN_TGMATH] (__TGMATH_NARROW_FUNCS_F): Likewise. [__HAVE_BUILTIN_TGMATH] (__TGMATH_NARROW_FUNCS_F16): Likewise. [__HAVE_BUILTIN_TGMATH] (__TGMATH_NARROW_FUNCS_F32): Likewise. [__HAVE_BUILTIN_TGMATH] (__TGMATH_NARROW_FUNCS_F64): Likewise. [__HAVE_BUILTIN_TGMATH] (__TGMATH_NARROW_FUNCS_F32X): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT_C2X)] (fadd): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT_C2X)] (dadd): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT_C2X)] (fdiv): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT_C2X)] (ddiv): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT_C2X)] (fmul): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT_C2X)] (dmul): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT_C2X)] (fsub): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT_C2X)] (dsub): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT16] (f16add): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT16] (f16div): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT16] (f16mul): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT16] (f16sub): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT32] (f32add): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT32] (f32div): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT32] (f32mul): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT32] (f32sub): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT64 && (__HAVE_FLOAT64X || __HAVE_FLOAT128)] (f64add): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT64 && (__HAVE_FLOAT64X || __HAVE_FLOAT128)] (f64div): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT64 && (__HAVE_FLOAT64X || __HAVE_FLOAT128)] (f64mul): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT64 && (__HAVE_FLOAT64X || __HAVE_FLOAT128)] (f64sub): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT32X] (f32xadd): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT32X] (f32xdiv): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT32X] (f32xmul): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT32X] (f32xsub): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT64X && (__HAVE_FLOAT128X || __HAVE_FLOAT128)] (f64xadd): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT64X && (__HAVE_FLOAT128X || __HAVE_FLOAT128)] (f64xdiv): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT64X && (__HAVE_FLOAT128X || __HAVE_FLOAT128)] (f64xmul): Likewise. [__GLIBC_USE (IEC_60559_TYPES_EXT) && __HAVE_FLOAT64X && (__HAVE_FLOAT128X || __HAVE_FLOAT128)] (f64xsub): Likewise. * math/gen-tgmath-tests.py (Type): Add members non_standard_real_argument_types_list, long_double_type, complex_float64_type and float32x_ext_type. (Type.__init__): Set the new members. (Type.floating_type): Add new argument floatn. (Type.real_floating_type): Likewise. (Type.can_combine_types): Likewise. (Type.combine_types): Likewise. (Type.init_types): Create internal Float32x_ext type. (Tests.__init__): Define Float32x_ext in generated C code. (Tests.add_tests): Handle narrowing functions. (Tests.add_all_tests): Likewise. (Tests.tests_text): Allow variation in mant_dig for narrowing functions with compilers before GCC 8. * math/Makefile (tgmath3-narrow-types): New variable. (tgmath3-narrow-macros): Likewise. (tgmath3-macros): Add $(tgmath3-narrow-macros).
2019-08-20Update i386 libm-test-ulpsAndreas Schwab
2019-08-19nscd: Improve nscd.conf comments.Carlos O'Donell
This change adds a warning to nscd.conf about running multiple caching services together and that it may lead to unexpected behaviours. Also we add a note that enabling the 'shared' option will cause cache hit rates to be misreported (a side effect of the implementation). v2 - Rewrite comment to avoid implementation details.
2019-08-19nss: Make nsswitch.conf more distribution friendly.Carlos O'Donell
The current default nsswitch.conf file provided by glibc is not very distribution friendly. The file contains some minimal directives that no real distribution uses. This update aims to provide a rich set of comments which are useful for all distributions, and a broader set of service defines which should work for all distributions. Tested defaults on x86_64 and they work. The nsswitch.conf file more closely matches what we have in Fedora now, and I'll adjust Fedora to use this version with minor changes to enable Fedora-specific service providers. v2 - Add missing databases to manual. - Add link to manual from default nsswitch.conf. - Sort nsswitch.conf according to most used database first. v3 - Only mention implemented services in 'NSS Basics.' - Mention 'automount' in 'Services in the NSS configuration.' - Sort services in alphabetical order. v4 - Project name is 'Samba'. v5 - Fix typo in manual/nss.texi. v6 - Fix another typo in manual/nss.texi. Ran spell checker this time.
2019-08-19Do not print backtraces on fatal glibc errorsFlorian Weimer
If the process is in a bad state, we used to print backtraces in many cases. This is problematic because doing so could involve a lot of work, like loading libgcc_s using the dynamic linker, and this could itself be targeted by exploit writers. For example, if the crashing process was forked from a long-lived process, the addresses in the error message could be used to bypass ASLR. Commit ed421fca42fd9b4cab7c66e77894b8dd7ca57ed0 ("Avoid backtrace from __stack_chk_fail [BZ #12189]"), backtraces where no longer printed because backtrace_and_maps was always called with do_abort == 1. Rather than fixing this logic error, this change removes the backtrace functionality from the sources. With the prevalence of external crash handlers, it does not appear to be particularly useful. The crash handler may also destroy useful information for debugging. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-08-16nptl: Move pthread_attr_getdetachstate implementation into libcFlorian Weimer
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-08-16Correct TEST_COMPAT conditions in totalorder compat tests.Joseph Myers
I noticed that the totalorder compat tests mixed TEST_COMPAT conditions using COMPAT_VER (computed as the first symbol version for the symbol being tested) and those with a hardcoded GLIBC_2_25. COMPAT_VER is logically correct here, so this patch changes the tests to use it. GLIBC_2_25 is harmless at present (even for _FloatN / _FloatNx functions added in later glibc versions). However, if in future we support _Float16 functions in glibc for any existing configuration, the test using GLIBC_2_25 would get things wrong (wrongly think that there are compat versions of totalorderf16 and totalordermagf16 to test). (The actual definitions of the compat / versioned symbols for the totalorder functions make no attempt to deal with the possibility of libm function support for a new floating-point format, already supported for other architectures in glibc, being added in some glibc configuration in future, for which the only vaguely plausible case would be if some architecture gets _Float128 support it previously lacked; this is much like functions added after glibc 2.4 not generally attempting to deal with compat support for long double changing away from having the same format as double.) Tested for x86_64, and with build-many-glibcs.py. * math/libm-test-compat_totalorder.inc (do_test) [TEST_COMPAT (libm, GLIBC_2_25, GLIBC_2_31)]: Change condition to [TEST_COMPAT (libm, COMPAT_VER, GLIBC_2_31)]. * math/libm-test-compat_totalordermag.inc (do_test) [TEST_COMPAT (libm, GLIBC_2_25, GLIBC_2_31)]: Likewise.
2019-08-15nptl: Move pthread_attr_init implementation into libcFlorian Weimer
Both the original GLIB_2.0 version and the current GLIBC_2.1 version need to be moved.
2019-08-15elf: Self-dlopen failure with explict loader invocation [BZ #24900]Florian Weimer
In case of an explicit loader invocation, ld.so essentially performs a dlopen call to load the main executable. Since the pathname of the executable is known at this point, it gets stored in the link map. In regular mode, the pathname is not known and "" is used instead. As a result, if a program calls dlopen on the pathname of the main program, the dlopen call succeeds and returns a handle for the main map. This results in an unnecessary difference between glibc testing (without --enable-hardcoded-path-in-tests) and production usage. This commit discards the names when building the link map in _dl_new_object for the main executable, but it still determines the origin at this point in case of an explict loader invocation. The reason is that the specified pathname has to be used; the kernel has a different notion of the main executable.
2019-08-15Make totalorder and totalordermag functions take pointer arguments.Joseph Myers
The resolution of C floating-point Clarification Request 25 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2397.htm#dr_25> is that the totalorder and totalordermag functions should take pointer arguments, and this has been adopted in C2X (with const added; note that the integration of this change into C2X is present in the C standard git repository but postdates the most recent public PDF draft). This patch updates glibc accordingly. As a defect resolution, the API is changed unconditionally rather than supporting any sort of TS 18661-1 mode for compilation with the old version of the API. There are compat symbols for existing binaries that pass floating-point arguments directly. As a consequence of changing to pointer arguments, there are no longer type-generic macros in tgmath.h for these functions. Because of the fairly complicated logic for creating libm function aliases and determining the set of aliases to create in a given glibc configuration, rather than duplicating all that in individual source files to create the versioned and compat symbols, the source files for the various versions of totalorder functions are set up to redefine weak_alias before using libm_alias_* macros to create the symbols required. In turn, this requires creating a separate alias for each symbol version pointing to the same implementation (see binutils bug <https://sourceware.org/bugzilla/show_bug.cgi?id=23840>), which is done automatically using __COUNTER__. (As I noted in <https://sourceware.org/ml/libc-alpha/2018-10/msg00631.html>, it might well make sense for glibc's symbol versioning macros to do that alias creation with __COUNTER__ themselves, which would somewhat simplify the logic in the totalorder source files.) It is of course desirable to test the compat symbols. I did this with the generic libm-test machinery, but didn't wish to duplicate the actual tables of test inputs and outputs, and thought it risky to attempt to have a single object file refer to both default and compat versions of the same function in order to test them together. Thus, I created libm-test-compat_totalorder.inc and libm-test-compat_totalordermag.inc which include the generated .c files (with the processed version of those tables of inputs) from the non-compat tests, and added appropriate dependencies. I think this provides sufficient test coverage for the compat symbols without also needing to make the special ldbl-96 and ldbl-128ibm tests (of peculiarities relating to the representations of those formats that can't be covered in the generic tests) run for the compat symbols. Tests of compat symbols need to be internal tests, meaning _ISOMAC is not defined. Making some libm-test tests into internal tests showed up two other issues. GCC diagnoses duplicate macro definitions of __STDC_* macros, including __STDC_WANT_IEC_60559_TYPES_EXT__; I added an appropriate conditional and filed <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91451> for this issue. On ia64, include/setjmp.h ends up getting included indirectly from libm-symbols.h, resulting in conflicting definitions of the STR macro (also defined in libm-test-driver.c); I renamed the macros in include/setjmp.h. (It's arguable that we should have common internal headers used everywhere for stringizing and concatenation macros.) Tested for x86_64 and x86, and with build-many-glibcs.py. * math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT) || __MATH_DECLARING_FLOATN] (totalorder): Take pointer arguments. [__GLIBC_USE (IEC_60559_BFP_EXT) || __MATH_DECLARING_FLOATN] (totalordermag): Likewise. * manual/arith.texi (totalorder): Likewise. (totalorderf): Likewise. (totalorderl): Likewise. (totalorderfN): Likewise. (totalorderfNx): Likewise. (totalordermag): Likewise. (totalordermagf): Likewise. (totalordermagl): Likewise. (totalordermagfN): Likewise. (totalordermagfNx): Likewise. * math/tgmath.h (__TGMATH_BINARY_REAL_RET_ONLY): Remove macro. [__GLIBC_USE (IEC_60559_BFP_EXT)] (totalorder): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (totalordermag): Likewise. * math/Versions (GLIBC_2.31): Add totalorder, totalorderf, totalorderl, totalordermag, totalordermagf, totalordermagl, totalorderf32, totalorderf64, totalorderf32x, totalordermagf32, totalordermagf64, totalordermagf32x, totalorderf64x, totalordermagf64x, totalorderf128 and totalordermagf128. * math/Makefile (libm-test-funcs-noauto): Add compat_totalorder and compat_totalordermag. (libm-test-funcs-compat): New variable. (libm-tests-compat): Likewise. (tests): Do not include compat tests. (tests-internal): Add compat tests. ($(foreach t,$(libm-tests-base), $(objpfx)$(t)-compat_totalorder.o)): Depend on $(objpfx)libm-test-totalorder.c. ($(foreach t,$(libm-tests-base), $(objpfx)$(t)-compat_totalordermag.o): Depend on $(objpfx)libm-test-totalordermag.c. (tgmath3-macros): Remove totalorder and totalordermag. * math/libm-test-compat_totalorder.inc: New file. * math/libm-test-compat_totalordermag.inc: Likewise. * math/libm-test-driver.c (struct test_ff_i_data): Update comment. (RUN_TEST_fpfp_b): New macro. (RUN_TEST_LOOP_fpfp_b): Likewise. * math/libm-test-totalorder.inc (totalorder_test_data): Use TEST_fpfp_b. (totalorder_test): Condition on [!COMPAT_TEST]. (do_test): Likewise. * math/libm-test-totalordermag.inc (totalordermag_test_data): Use TEST_fpfp_b. (totalordermag_test): Condition on [!COMPAT_TEST]. (do_test): Likewise. * math/gen-tgmath-tests.py (Tests.add_all_tests): Remove totalorder and totalordermag. * math/test-tgmath.c (NCALLS): Change to 132. (F(compile_test)): Do not call totalorder or totalordermag. (F(totalorder)): Remove. (F(totalordermag)): Likewise. * include/float.h (__STDC_WANT_IEC_60559_TYPES_EXT__): Do not define if [__STDC_WANT_IEC_60559_TYPES_EXT__]. * include/setjmp.h [!_ISOMAC] (STR_HELPER): Rename to SJSTR_HELPER. [!_ISOMAC] (STR): Rename to SJSTR. Update call to STR_HELPER. [!_ISOMAC] (TEST_SIZE): Update call to STR. [!_ISOMAC] (TEST_ALIGN): Likewise. [!_ISOMAC] (TEST_OFFSET): Likewise. * sysdeps/ieee754/dbl-64/s_totalorder.c: Include <shlib-compat.h> and <first-versions.h>. (__totalorder): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/dbl-64/s_totalordermag.c: Include <shlib-compat.h> and <first-versions.h>. (__totalordermag): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/dbl-64/wordsize-64/s_totalorder.c: Include <shlib-compat.h> and <first-versions.h>. (__totalorder): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/dbl-64/wordsize-64/s_totalordermag.c: Include <shlib-compat.h> and <first-versions.h>. (__totalordermag): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/float128/float128_private.h (__totalorder_compatl): New macro. (__totalordermag_compatl): Likewise. * sysdeps/ieee754/flt-32/s_totalorderf.c: Include <shlib-compat.h> and <first-versions.h>. (__totalorderf): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/flt-32/s_totalordermagf.c: Include <shlib-compat.h> and <first-versions.h>. (__totalordermagf): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/ldbl-128/s_totalorderl.c: Include <shlib-compat.h> and <first-versions.h>. (__totalorderl): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/ldbl-128/s_totalordermagl.c: Include <shlib-compat.h> and <first-versions.h>. (__totalordermagl): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/ldbl-128ibm/s_totalorderl.c: Include <shlib-compat.h>. (__totalorderl): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/ldbl-128ibm/s_totalordermagl.c: Include <shlib-compat.h>. (__totalordermagl): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/ldbl-96/s_totalorderl.c: Include <shlib-compat.h> and <first-versions.h>. (__totalorderl): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/ldbl-96/s_totalordermagl.c: Include <shlib-compat.h> and <first-versions.h>. (__totalordermagl): Take pointer arguments. Add symbol versions and compat symbols. * sysdeps/ieee754/ldbl-opt/nldbl-totalorder.c (totalorderl): Take pointer arguments. * sysdeps/ieee754/ldbl-opt/nldbl-totalordermag.c (totalordermagl): Likewise. * sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c (do_test): Update calls to totalorderl and totalordermagl. * sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c (do_test): Update calls to totalorderl and totalordermagl. * sysdeps/mach/hurd/i386/libm.abilist: Update. * sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/csky/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/riscv/rv64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2019-08-15login: Add nonstring attributes to struct utmp, struct utmpx [BZ #24899]Florian Weimer
Commit 7532837d7b03b3ca5b9a63d77a5bd81dd23f3d9c ("The -Wstringop-truncation option new in GCC 8 detects common misuses") added __attribute_nonstring__ to bits/utmp.h, but it did not update the parallel bits/utmpx.h header. In struct utmp, the nonstring attribute for ut_id was missing.
2019-08-15login: Use struct flock64 in utmp [BZ #24880]Florian Weimer
Commit 06ab719d30b01da401150068054d3b8ea93dd12f ("Fix Linux fcntl OFD locks for non-LFS architectures (BZ#20251)") introduced the use of fcntl64 into the utmp implementation. However, the lock file structure was not updated to struct flock64 at that point.
2019-08-15login: Disarm timer after utmp lock acquisition [BZ #24879]Florian Weimer
If the file processing takes a long time for some reason, SIGALRM can arrive while the file is still being processed. At that point, file access will fail with EINTR. Disarming the timer after lock acquisition avoids that. (If there was a previous alarm, it is the responsibility of the caller to deal with the EINTR error.)
2019-08-15nptl: Remove pthread_self compatibility symbol from libpthreadFlorian Weimer
The symbol is no longer needed because since glibc 2.30, the dynamic loader continues searching for the symbol in libc.
2019-08-15nptl: Move pthread_attr_destroy implementation into libcFlorian Weimer
2019-08-15Update i386 libm-test-ulpsAndreas Schwab
2019-08-15malloc: Various cleanups for malloc/tst-mxfastFlorian Weimer
2019-08-15login: Fix updwtmp, updwtmx unlockingFlorian Weimer
Commit 5a3afa9738f3dbbaf8c0a35665318c1af782111b (login: Replace macro-based control flow with function calls in utmp) introduced a regression because after it, __libc_updwtmp attempts to unlock the wrong file descriptor.
2019-08-15nptl: Move pthread_equal implementation into libcFlorian Weimer
2019-08-14support: Include <support/descriptors.h> in support_descriptors.cFlorian Weimer
2019-08-14aarch64: Disable using DC ZVA in emag memsetFeng Xue
* sysdeps/aarch64/multiarch/memset_base64.S (DC_ZVA_THRESHOLD): Disable DC ZVA code if this macro is defined as zero. * sysdeps/aarch64/multiarch/memset_emag.S (DC_ZVA_THRESHOLD): Change to zero to disable using DC ZVA.