Florian Weimer [Tue, 29 Mar 2016 09:27:32 +0000 (11:27 +0200)]
nss_db: Propagate ERANGE error if parse_line fails [BZ #19837]
Reproducer (needs to run as root):
perl -e \
'print "large:x:999:" . join(",", map {"user$_"} (1 .. 135))."\n"' \
>> /etc/group
cd /var/db
make
getent -s db group
After the fix, the last command should list the "large" group.
The magic number 135 has been chosen so that the line is shorter than
1024 bytes, but the pointers required to encode the member array will
cross the threshold, triggering the bug.
H.J. Lu [Tue, 29 Mar 2016 02:22:59 +0000 (19:22 -0700)]
Initial Enhanced REP MOVSB/STOSB (ERMS) support
The newer Intel processors support Enhanced REP MOVSB/STOSB (ERMS) which
has a feature bit in CPUID. This patch adds the Enhanced REP MOVSB/STOSB
(ERMS) bit to x86 cpu-features.
H.J. Lu [Mon, 28 Mar 2016 20:15:59 +0000 (13:15 -0700)]
Make __memcpy_avx512_no_vzeroupper an alias
Since x86-64 memcpy-avx512-no-vzeroupper.S implements memmove, make
__memcpy_avx512_no_vzeroupper an alias of __memmove_avx512_no_vzeroupper
to reduce code size of libc.so.
* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Remove
memcpy-avx512-no-vzeroupper.
* sysdeps/x86_64/multiarch/memcpy-avx512-no-vzeroupper.S: Renamed
to ...
* sysdeps/x86_64/multiarch/memmove-avx512-no-vzeroupper.S: This.
(MEMCPY): Don't define.
(MEMCPY_CHK): Likewise.
(MEMPCPY): Likewise.
(MEMPCPY_CHK): Likewise.
(MEMPCPY_CHK): Renamed to ...
(__mempcpy_chk_avx512_no_vzeroupper): This.
(MEMPCPY_CHK): Renamed to ...
(__mempcpy_chk_avx512_no_vzeroupper): This.
(MEMCPY_CHK): Renamed to ...
(__memmove_chk_avx512_no_vzeroupper): This.
(MEMCPY): Renamed to ...
(__memmove_avx512_no_vzeroupper): This.
(__memcpy_avx512_no_vzeroupper): New alias.
(__memcpy_chk_avx512_no_vzeroupper): Likewise.
H.J. Lu [Mon, 28 Mar 2016 11:39:48 +0000 (04:39 -0700)]
[x86] Add a feature bit: Fast_Unaligned_Copy
On AMD processors, memcpy optimized with unaligned SSE load is
slower than emcpy optimized with aligned SSSE3 while other string
functions are faster with unaligned SSE load. A feature bit,
Fast_Unaligned_Copy, is added to select memcpy optimized with
unaligned SSE load.
[BZ #19583]
* sysdeps/x86/cpu-features.c (init_cpu_features): Set
Fast_Unaligned_Copy with Fast_Unaligned_Load for Intel
processors. Set Fast_Copy_Backward for AMD Excavator
processors.
* sysdeps/x86/cpu-features.h (bit_arch_Fast_Unaligned_Copy):
New.
(index_arch_Fast_Unaligned_Copy): Likewise.
* sysdeps/x86_64/multiarch/memcpy.S (__new_memcpy): Check
Fast_Unaligned_Copy instead of Fast_Unaligned_Load.
Florian Weimer [Fri, 25 Mar 2016 10:49:51 +0000 (11:49 +0100)]
resolv: Always set *resplen2 out parameter in send_dg [BZ #19791]
Since commit 44d20bca52ace85850012b0ead37b360e3ecd96e (Implement
second fallback mode for DNS requests), there is a code path which
returns early, before *resplen2 is initialized. This happens if the
name server address is immediately recognized as invalid (because of
lack of protocol support, or if it is a broadcast address such
255.255.255.255, or another invalid address).
If this happens and *resplen2 was non-zero (which is the case if a
previous query resulted in a failure), __libc_res_nquery would reuse
an existing second answer buffer. This answer has been previously
identified as unusable (for example, it could be an NXDOMAIN
response). Due to the presence of a second answer, no name server
switching will occur. The result is a name resolution failure,
although a successful resolution would have been possible if name
servers have been switched and queries had proceeded along the search
path.
The above paragraph still simplifies the situation. Before glibc
2.23, if the second answer needed malloc, the stub resolver would
still attempt to reuse the second answer, but this is not possible
because __libc_res_nsearch has freed it, after the unsuccessful call
to __libc_res_nquerydomain, and set the buffer pointer to NULL. This
eventually leads to an assertion failure in __libc_res_nquery:
/* Make sure both hp and hp2 are defined */
assert((hp != NULL) && (hp2 != NULL));
If assertions are disabled, the consequence is a NULL pointer
dereference on the next line.
Starting with glibc 2.23, as a result of commit e9db92d3acfe1822d56d11abcea5bfc4c41cf6ca (CVE-2015-7547: getaddrinfo()
stack-based buffer overflow (Bug 18665)), the second answer is always
allocated with malloc. This means that the assertion failure happens
with small responses as well because there is no buffer to reuse, as
soon as there is a name resolution failure which triggers a search for
an answer along the search path.
This commit addresses the issue by ensuring that *resplen2 is
initialized before the send_dg function returns.
This commit also addresses a bug where an invalid second reply is
incorrectly returned as a valid to the caller.
Joseph Myers [Thu, 24 Mar 2016 01:32:52 +0000 (01:32 +0000)]
Fix x86_64 / x86 powl inaccuracy for integer exponents (bug 19848).
Bug 19848 reports cases where powl on x86 / x86_64 has error
accumulation, for small integer exponents, larger than permitted by
glibc's accuracy goals, at least in some rounding modes. This patch
further restricts the exponent range for which the
small-integer-exponent logic is used to limit the possible error
accumulation.
Tested for x86_64 and x86 and ulps updated accordingly.
[BZ #19848]
* sysdeps/i386/fpu/e_powl.S (p3): Rename to p2 and change value
from 8 to 4.
(__ieee754_powl): Compare integer exponent against 4 not 8.
* sysdeps/x86_64/fpu/e_powl.S (p3): Rename to p2 and change value
from 8 to 4.
(__ieee754_powl): Compare integer exponent against 4 not 8.
* math/auto-libm-test-in: Add more tests of pow.
* math/auto-libm-test-out: Regenerated.
* sysdeps/i386/i686/fpu/multiarch/libm-test-ulps: Update.
* sysdeps/x86_64/fpu/libm-test-ulps: Likewise.
Nick Alcock [Wed, 23 Mar 2016 12:40:14 +0000 (13:40 +0100)]
x86, pthread_cond_*wait: Do not depend on %eax not being clobbered
The x86-specific versions of both pthread_cond_wait and
pthread_cond_timedwait have (in their fall-back-to-futex-wait slow
paths) calls to __pthread_mutex_cond_lock_adjust followed by
__pthread_mutex_unlock_usercnt, which load the parameters before the
first call but then assume that the first parameter, in %eax, will
survive unaffected. This happens to have been true before now, but %eax
is a call-clobbered register, and this assumption is not safe: it could
change at any time, at GCC's whim, and indeed the stack-protector canary
checking code clobbers %eax while checking that the canary is
uncorrupted.
So reload %eax before calling __pthread_mutex_unlock_usercnt. (Do this
unconditionally, even when stack-protection is not in use, because it's
the right thing to do, it's a slow path, and anything else is dicing
with death.)
H.J. Lu [Tue, 22 Mar 2016 14:46:56 +0000 (07:46 -0700)]
Set index_arch_AVX_Fast_Unaligned_Load only for Intel processors
Since only Intel processors with AVX2 have fast unaligned load, we
should set index_arch_AVX_Fast_Unaligned_Load only for Intel processors.
Move AVX, AVX2, AVX512, FMA and FMA4 detection into get_common_indeces
and call get_common_indeces for other processors.
Add CPU_FEATURES_CPU_P and CPU_FEATURES_ARCH_P to aoid loading
GLRO(dl_x86_cpu_features) in cpu-features.c.
[BZ #19583]
* sysdeps/x86/cpu-features.c (get_common_indeces): Remove
inline. Check family before setting family, model and
extended_model. Set AVX, AVX2, AVX512, FMA and FMA4 usable
bits here.
(init_cpu_features): Replace HAS_CPU_FEATURE and
HAS_ARCH_FEATURE with CPU_FEATURES_CPU_P and
CPU_FEATURES_ARCH_P. Set index_arch_AVX_Fast_Unaligned_Load
for Intel processors with usable AVX2. Call get_common_indeces
for other processors with family == NULL.
* sysdeps/x86/cpu-features.h (CPU_FEATURES_CPU_P): New macro.
(CPU_FEATURES_ARCH_P): Likewise.
(HAS_CPU_FEATURE): Use CPU_FEATURES_CPU_P.
(HAS_ARCH_FEATURE): Use CPU_FEATURES_ARCH_P.
Samuel Thibault [Tue, 22 Mar 2016 08:58:48 +0000 (09:58 +0100)]
Fix malloc threaded tests link on non-Linux
* malloc/Makefile ($(objpfx)tst-malloc-backtrace,
$(objpfx)tst-malloc-thread-exit, $(objpfx)tst-malloc-thread-fail): Use
$(shared-thread-library) instead of hardcoding the path to libpthread.
Joseph Myers [Tue, 22 Mar 2016 00:32:20 +0000 (00:32 +0000)]
Remove __ASSUME_GETDENTS64_SYSCALL.
This patch removes the __ASSUME_GETDENTS64_SYSCALL macro, as its
definition is constant given the new kernel version requirements (and
was constant anyway before those requirements except for MIPS n32).
Note that the "#ifdef __NR_getdents64" conditional *is* still needed,
because MIPS n64 only has the getdents syscall (being a 64-bit ABI,
that syscall is 64-bit; the difference between the two on 64-bit
architectures is where d_type goes). If MIPS n64 were to gain the
getdents64 syscall and we wanted to use it conditionally on the kernel
version at runtime we'd have to revert this patch, but I think that's
unlikely (and in any case, we could follow the simpler approach of
undefining __NR_getdents64 if the syscall can't be assumed, just like
we do for accept4 / recvmmsg / sendmmsg syscalls on architectures
where socketcall support came first).
Most of the getdents.c changes are reindentation.
Tested for x86_64 and x86 that installed stripped shared libraries are
unchanged by the patch.
Joseph Myers [Mon, 21 Mar 2016 16:30:05 +0000 (16:30 +0000)]
Remove __ASSUME_SIGNALFD4.
Current Linux kernel version requirements mean the signalfd4 syscall
can always be assumed to be available. This patch removes
__ASSUME_SIGNALFD4 and associated conditionals.
Tested for x86_64 and x86 that installed stripped shared libraries are
unchanged by the patch.
* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_SIGNALFD4):
Remove macro.
* sysdeps/unix/sysv/linux/signalfd.c: Do not include
<kernel-features.h>.
(signalfd) [__NR_signalfd4]: Make code unconditional.
(signalfd) [!__ASSUME_SIGNALFD4]: Remove conditional code.
H.J. Lu [Mon, 21 Mar 2016 13:38:17 +0000 (06:38 -0700)]
Use JUMPTARGET in x86-64 pthread
When PLT may be used, JUMPTARGET should be used instead calling the
function directly.
* sysdeps/unix/sysv/linux/x86_64/cancellation.S
(__pthread_enable_asynccancel): Use JUMPTARGET to call
__pthread_unwind.
* sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
(__condvar_cleanup2): Use JUMPTARGET to call _Unwind_Resume.
* sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
(__condvar_cleanup1): Likewise.
Dylan Alex Simon [Tue, 15 Mar 2016 17:20:01 +0000 (13:20 -0400)]
math: don't clobber old libm.so on install [BZ #19822]
When installing glibc (w/mathvec enabled) in-place on a system with
a glibc w/out mathvec enabled, the install will clobber the existing
libm.so (e.g., /lib64/libm-2.21.so) with a linker script. This is
because libm.so is a symlink to libm.so.6 which is a symlink to the
final libm-2.21.so file. When the makefile writes the linker script
directly to libm.so, it gets clobbered.
The simple patch below to math/Makefile fixes this. It is based on
the nptl Makefile, which does exactly the same thing in a safer way.
Samuel Thibault [Sun, 20 Mar 2016 16:56:47 +0000 (17:56 +0100)]
hurd: Do not hide rtld symbols which need to be preempted
* sysdeps/generic/dl-fcntl.h: New file, adds attribute_hidden to __open
and __fcntl.
* sysdeps/mach/hurd/dl-fcntl.h: New file, adds attribute_hidden to
__fcntl only.
* include/fcntl.h [IS_IN (rtld)]: Include <dl-fcntl.h> instead of
adding attribute_hidden to __open and __fcntl.
Generating errnos.d does not actually need libc-modules.h.
* sysdeps/mach/hurd/Makefile ($(common-objpfx)errnos.d): Strip
"-include $(common-objpfx)libc-modules.h" from CPPFLAGS, and do not
depend on libc-modules.h,
Joseph Myers [Thu, 17 Mar 2016 19:07:39 +0000 (19:07 +0000)]
Remove __ASSUME_EVENTFD2, move eventfd to syscalls.list.
Given current Linux kernel version requirements, we can assume the
presence of the eventfd2 syscall. This means that __ASSUME_EVENTFD2
can be removed, and a syscalls.list entry suffices for eventfd instead
of needing a .c file. This patch implements those changes.
Tested for x86_64 and x86 (not that that means much, given the lack of
testsuite coverage for eventfd).
Joseph Myers [Thu, 17 Mar 2016 12:15:51 +0000 (12:15 +0000)]
Remove __ASSUME_FALLOCATE.
Given current Linux kernel version requirements, we can always assume
the fallocate syscall to be available. This patch removes
__ASSUME_FALLOCATE and a test for whether __NR_fallocate is defined.
Tested for x86_64 and x86 that installed stripped shared libraries are
unchanged by the patch.
* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_FALLOCATE):
Remove macro.
* sysdeps/unix/sysv/linux/wordsize-64/posix_fallocate.c: Do not
include <kernel-features.h>.
[!__ASSUME_FALLOCATE]: Remove conditional code.
(posix_fallocate) [__NR_fallocate]: Make code unconditional.
Carlos O'Donell [Wed, 16 Mar 2016 03:16:47 +0000 (23:16 -0400)]
Fix building glibc master with NDEBUG and --with-cpu.
When building on i686, x86_64, and arm, and with NDEBUG, or --with-cpu
there are various variables and functions which are unused based on
these settings.
This patch marks all such variables with __attribute__((unused)) to
avoid the compiler warnings when building with the aformentioned
options.
Joseph Myers [Tue, 15 Mar 2016 21:11:07 +0000 (21:11 +0000)]
Remove __ASSUME_PPOLL.
With current kernel version requirements, the ppoll Linux syscall can
be assumed to be present on all architectures; this patch removes the
__ASSUME_PPOLL macro and conditionals on it and on whether __NR_ppoll
is defined. (Note that the same can't yet be done for pselect,
because MicroBlaze only wired that up in the syscall table in 3.15.)
Tested for x86_64 and x86 that installed stripped shared libraries are
unchanged by the patch.
* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_PPOLL):
Remove macro.
* sysdeps/unix/sysv/linux/ppoll.c: Do not include
<kernel-features.h>.
[__NR_ppoll]: Make code unconditional.
[!__ASSUME_PPOLL]: Remove conditional code.
Joseph Myers [Tue, 15 Mar 2016 21:09:33 +0000 (21:09 +0000)]
Adjust kernel-features.h defaults for socket syscalls.
This patch adjusts the defaults for kernel-features.h macros relating
to availability of accept4, recvmmsg and sendmmsg. It is not intended
to affect which macros end up getting defined in any configuration.
At present, all architectures with syscalls for those functions need
to define __ASSUME_*_SYSCALL macros; in particular, any new
architecture needs its own kernel-features.h file for that purpose,
though it may not otherwise need such a header. Those macros are then
used together with __ASSUME_SOCKETCALL to define macros for whether
the functions in question are available.
This patch changes the defaults so that the syscalls are assumed to be
available by default with recent-enough kernels, and it is the
responsibility of architecture headers to undefine the macros if they
are unavailable in supported kernels at least as recent as the version
where the architecture-independent functionality was introduced. The
__ASSUME_<function> macros are defaulted similarly instead of being
defined based on other macros (defining based on other macros would no
longer work because the #undefs appear after the generic header is
included), so where the syscall being unavailable means the function
is unavailable this means the architecture header has to undefine the
__ASSUME_<function> macro; this only affects __ASSUME_ACCEPT4 for
ia64, as other cases where the syscalls were added late enough to be
relevant with current kernel version requirements are all on
socketcall architectures.
As a consequence, the AArch64 and Nios II kernel-features.h header
files are removed, and others simplified. When the minimum kernel
version becomes 4.3 or later on all architectures, the syscalls in
question can just be assumed unconditionally, permitting further
simplification.
Tested for x86_64, x86 and powerpc (that installed shared libraries
are unchanged by the patch, and testsuite for x86_64 and x86).
* sysdeps/unix/sysv/linux/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Define unconditionally.
(__ASSUME_ACCEPT4): Likewise.
[__LINUX_KERNEL_VERSION >= 0x020621] (__ASSUME_RECVMMSG_SYSCALL):
Define.
[__LINUX_KERNEL_VERSION >= 0x020621] (__ASSUME_RECVMMSG):
Likewise.
[__LINUX_KERNEL_VERSION >= 0x030000] (__ASSUME_SENDMMSG_SYSCALL):
Likewise.
[__LINUX_KERNEL_VERSION >= 0x030000] (__ASSUME_SENDMMSG):
Likewise.
* sysdeps/unix/sysv/linux/aarch64/kernel-features.h: Remove file.
* sysdeps/unix/sysv/linux/nios2/kernel-features.h: Likewise.
* sysdeps/unix/sysv/linux/alpha/kernel-features.h
(__ASSUME_RECVMMSG_SYSCALL): Do not define.
(__ASSUME_ACCEPT4_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/arm/kernel-features.h
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_ACCEPT4_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/hppa/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Likewise.
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/i386/kernel-features.h
[__LINUX_KERNEL_VERSION >= 0x020621] (__ASSUME_RECVMMSG_SYSCALL):
Likewise.
[__LINUX_KERNEL_VERSION >= 0x030000] (__ASSUME_SENDMMSG_SYSCALL):
Likewise.
(__ASSUME_ACCEPT4_SYSCALL): Undefine if [__LINUX_KERNEL_VERSION <
0x040300] instead of defining if [__LINUX_KERNEL_VERSION >=
0x040300].
* sysdeps/unix/sysv/linux/ia64/kernel-features.h
(__ASSUME_RECVMMSG_SYSCALL): Do not define.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
(__ASSUME_ACCEPT4_SYSCALL): Undefine if [__LINUX_KERNEL_VERSION <
0x030300] instead of defining if [__LINUX_KERNEL_VERSION >=
0x030300].
[__LINUX_KERNEL_VERSION < 0x030300] (__ASSUME_ACCEPT4): Undefine.
* sysdeps/unix/sysv/linux/m68k/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Undefine if [__LINUX_KERNEL_VERSION <
0x040300] instead of defining if [__LINUX_KERNEL_VERSION >=
0x040300].
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Do not define.
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Undefine if [__LINUX_KERNEL_VERSION <
0x030300] instead of defining if [__LINUX_KERNEL_VERSION >=
0x030300].
* sysdeps/unix/sysv/linux/mips/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Do not define.
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Likewise.
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/s390/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Undefine if [__LINUX_KERNEL_VERSION <
0x040300] instead of defining if [__LINUX_KERNEL_VERSION >=
0x040300].
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/sh/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Do not define.
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/sparc/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Likewise.
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/tile/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Likewise.
(__ASSUME_RECVMMSG_SYSCALL): Likewise.
(__ASSUME_SENDMMSG_SYSCALL): Likewise.
* sysdeps/unix/sysv/linux/x86_64/kernel-features.h
(__ASSUME_ACCEPT4_SYSCALL): Likewise.
[__LINUX_KERNEL_VERSION >= 0x020621] (__ASSUME_RECVMMSG_SYSCALL):
Likewise.
[__LINUX_KERNEL_VERSION >= 0x030000] (__ASSUME_SENDMMSG_SYSCALL):
Likewise.
Andreas Schwab [Wed, 18 Nov 2015 14:45:59 +0000 (15:45 +0100)]
Fix resource leak in resolver (bug 19257)
The number of currently defined nameservers is stored in ->nscount,
whereas ->_u._ext.nscount is set by __libc_res_nsend only after local
initializations.
Joseph Myers [Thu, 10 Mar 2016 23:48:46 +0000 (23:48 +0000)]
Allow spurious underflow / inexact for ldbl-128ibm.
A large number of the test-ldouble failures seen for ldbl-128ibm are
spurious "underflow" and "inexact" exceptions. These arise from such
exceptions in the underlying arithmetic; unlike other spurious
exceptions from that arithmetic, they do not in general relate to
cases where the returned result is also substantially inaccurate, are
not so readily avoidable by appropriately conditional libgcc patches,
and are widespread enough to be hard to handle through individual
XFAILing of the affected tests.
Thus, this patch documents relaxed accuracy goals for libm functions
for IBM long double and makes libm-test.inc reflect these spurious
exceptions in ldbl-128ibm arithmetic and always allow them in
ldbl-128ibm testing (while still not allowing these exceptions to be
missing where required to be present). Tested for powerpc.
* manual/math.texi (Errors in Math Functions): Document relaxed
accuracy goals for IBM long double.
* math/libm-test.inc (test_exceptions): Always allow spurious
"underflow" and "inexact" exceptions for IBM long double.
H.J. Lu [Thu, 10 Mar 2016 13:26:46 +0000 (05:26 -0800)]
Add _arch_/_cpu_ to index_*/bit_* in x86 cpu-features.h
index_* and bit_* macros are used to access cpuid and feature arrays o
struct cpu_features. It is very easy to use bits and indices of cpuid
array on feature array, especially in assembly codes. For example,
sysdeps/i386/i686/multiarch/bcopy.S has
HAS_CPU_FEATURE (Fast_Rep_String)
which should be
HAS_ARCH_FEATURE (Fast_Rep_String)
We change index_* and bit_* to index_cpu_*/index_arch_* and
bit_cpu_*/bit_arch_* so that we can catch such error at build time.
[BZ #19762]
* sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h
(EXTRA_LD_ENVVARS): Add _arch_ to index_*/bit_*.
* sysdeps/x86/cpu-features.c (init_cpu_features): Likewise.
* sysdeps/x86/cpu-features.h (bit_*): Renamed to ...
(bit_arch_*): This for feature array.
(bit_*): Renamed to ...
(bit_cpu_*): This for cpu array.
(index_*): Renamed to ...
(index_arch_*): This for feature array.
(index_*): Renamed to ...
(index_cpu_*): This for cpu array.
[__ASSEMBLER__] (HAS_FEATURE): Add and use field.
[__ASSEMBLER__] (HAS_CPU_FEATURE)): Pass cpu to HAS_FEATURE.
[__ASSEMBLER__] (HAS_ARCH_FEATURE)): Pass arch to HAS_FEATURE.
[!__ASSEMBLER__] (HAS_CPU_FEATURE): Replace index_##name and
bit_##name with index_cpu_##name and bit_cpu_##name.
[!__ASSEMBLER__] (HAS_ARCH_FEATURE): Replace index_##name and
bit_##name with index_arch_##name and bit_arch_##name.
Aurelien Jarno [Tue, 8 Mar 2016 23:25:00 +0000 (00:25 +0100)]
mips: terminate the FDE before the return trampoline in makecontext
In makecontext the FDE needs to be terminated before the return
trampoline otherwise backtrace called within a context created by
makecontext yields infinite backtrace.
This bug has been present for a long time, stdlib/tst-makecontext did
not fail until recent commit e535ce25. Tested on mips-linux-gnu and
mips64el-linux-gnuabi64 and mips-linux-gnu, no regression.
Joseph Myers [Wed, 9 Mar 2016 00:30:59 +0000 (00:30 +0000)]
Fix ldbl-128ibm nearbyintl in non-default rounding modes (bug 19790).
The ldbl-128ibm implementation of nearbyintl uses logic that only
works in round-to-nearest mode. This contrasts with rintl, which
works in all rounding modes.
Now, arguably nearbyintl could simply be aliased to rintl, given that
spurious "inexact" is generally allowed for ldbl-128ibm, even for the
underlying arithmetic operations. But given that the only point of
nearbyintl is to avoid "inexact", this patch follows the more
conservative approach of adding conditionals to the rintl
implementation to make it suitable for use to implement nearbyintl,
then builds it for nearbyintl with USE_AS_NEARBYINTL defined. The
test test-nearbyint-except-2 shows up issues when traps on "inexact"
are enabled, which turn out to be problems with the powerpc
fenv_private.h implementation (two functions that should disable
exception traps potentially failing to do so in some cases); this
patch duly fixes that as well (I don't see any other existing cases
where this would be user-visible; there isn't much use of *_NOEX,
*hold* etc. in libm that requires exceptions to be discarded and not
trapped on).
Tested for powerpc.
[BZ #19790]
* sysdeps/ieee754/ldbl-128ibm/s_rintl.c [USE_AS_NEARBYINTL]
(rintl): Define as macro.
[USE_AS_NEARBYINTL] (__rintl): Likewise.
(__rintl) [USE_AS_NEARBYINTL]: Use SET_RESTORE_ROUND_NOEX instead
of fesetround. Ensure results are evaluated before end of scope.
* sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c: Define
USE_AS_NEARBYINTL and include s_rintl.c.
* sysdeps/powerpc/fpu/fenv_private.h (libc_feholdsetround_ppc):
Disable exception traps in new environment.
(libc_feholdsetround_ppc_ctx): Likewise.
powerpc: Remove uses of operand modifier (%s) in inline asm
The operand modifier %s on powerpc is an undocumented internal implementation
detail of GCC. Besides that, the GCC community wants to remove it. This patch
rewrites the expressions that use this modifier with logically equivalent
expressions that don't require it.
Explanation for the substitution:
The %s modifier takes an immediate operand and prints 32 less such immediate.
Thus, in the previous code, the expression resulted in:
32 - __builtin_ffs(e)
where e was guaranteed to have exactly a single bit set, by the following
expressions:
(e & (e-1) == 0) : e has at most one bit set.
(e != 0) : e is not zero, thus it has at least one bit set.
Since we guarantee that there is exactly only one bit set, the following
statement is true:
32 - __builtin_ffs(e) == __builtin_clz(e)
Thus, we can replace __builtin_ffs with __builtin_clz and remove the %s operand
modifier.
HWCAP-related code should had been updated when the 32 bits of HWCAP were
used. This patch updates the code in dl-procinfo.h to loop through all
the 32 bits in HWCAP and updates _dl_powerpc_cap_flags accordingly.
Joseph Myers [Tue, 8 Mar 2016 00:27:21 +0000 (00:27 +0000)]
Fix ldbl-128ibm remainderl equality test for zero low part (bug 19677).
The ldbl-128ibm implementation of remainderl has logic resulting in
incorrect tests for equality of the absolute values of the arguments
in the case of zero low parts. If the low parts are both zero but
with different signs, this can wrongly cause equal arguments to be
treated as different, resulting in turn in incorrect signs of zero
result in nondefault rounding modes arising from the subtractions done
when the arguments are not equal.
This patch fixes the logic to convert -0 low parts into +0 before the
comparison (remquo already has separate logic to deal with signs of
zero results, so doesn't need such a change). Tests are added for
remainderl and remquol similar to that for fmodl, and based on a
refactoring of it, since the bug depends on low parts which should not
be relied upon in tests not setting the representation explicitly
(although in fact the bug shows up in test-ldouble with current GCC).
Tested for powerpc.
[BZ #19677]
* sysdeps/ieee754/ldbl-128ibm/e_remainderl.c
(__ieee754_remainderl): Put zero low parts in canonical form.
* sysdeps/ieee754/ldbl-128ibm/test-fmodrem-ldbl-128ibm.c: New
file. Based on
sysdeps/ieee754/ldbl-128ibm/test-fmodl-ldbl-128ibm.c.
* sysdeps/ieee754/ldbl-128ibm/test-fmodl-ldbl-128ibm.c: Replace
with wrapper round test-fmodrem-ldbl-128ibm.c.
* sysdeps/ieee754/ldbl-128ibm/test-remainderl-ldbl-128ibm.c: New
file.
* sysdeps/ieee754/ldbl-128ibm/test-remquol-ldbl-128ibm.c:
Likewise.
* sysdeps/ieee754/ldbl-128ibm/Makefile (tests): Add
test-remainderl-ldbl-128ibm and test-remquol-ldbl-128ibm.
Hongjiu Zhang [Mon, 7 Mar 2016 01:18:21 +0000 (20:18 -0500)]
sln: use stat64
When using sln on some filesystems which return 64-bit inodes,
the stat call might fail during install like so:
.../elf/sln .../elf/symlink.list
/lib32/libc.so.6: invalid destination: Value too large for defined data type
/lib32/ld-linux.so.2: invalid destination: Value too large for defined data type
Makefile:104: recipe for target 'install-symbolic-link' failed
Switch to using stat64 all the time to avoid this.
Florian Weimer [Mon, 7 Mar 2016 12:48:47 +0000 (13:48 +0100)]
test-skeleton.c: Do not set RLIMIT_DATA [BZ #19648]
With older kernels, it is mostly ineffective because it causes malloc
to switch from sbrk to mmap (potentially invalidating malloc testing
compared to what real appliations do). With newer kernels which
have switched to enforcing RLIMIT_DATA for mmap as well, some test
cases will fail in an unintended fashion because the limit which was
set previously does not include room for all mmap mappings.
This patch implements a new posix_spawn{p} implementation for Linux. The main
difference is it uses the clone syscall directly with CLONE_VM and CLONE_VFORK
flags and a direct allocated stack. The new stack and start function solves
most the vfork limitation (possible parent clobber due stack spilling). The
remaning issue are related to signal handling:
1. That no signal handlers must run in child context, to avoid corrupt
parent's state.
2. Child must synchronize with parent to enforce stack deallocation and
to possible return execv issues.
The first one is solved by blocking all signals in child, even NPTL-internal
ones (SIGCANCEL and SIGSETXID). The second issue is done by a stack allocation
in parent and a synchronization with using a pipe or waitpid (in case or error).
The pipe has the advantage of allowing the child signal an exec error (checked
with new tst-spawn2 test).
There is an inherent race condition in pipe2 usage for architectures that do not
support the syscall directly. In such cases the a pipe plus fctnl is used
instead and it may lead to file descriptor leak in parent (as decribed by fcntl
documentation).
The child process stack is allocate with a mmap with MAP_STACK flag using
default architecture stack size. Although it is slower than use a stack buffer
from parent, it allows some slack for the compatibility code to run scripts
with no shebang (which may use a buffer with size depending of argument list
count).
Performance should be similar to the vfork default posix implementation and
way faster than fork path (vfork on mostly linux ports are basically
clone with CLONE_VM plus CLONE_VFORK). The only difference is the syscalls
required for the stack allocation/deallocation.
This patch removes all the dynamic allocation on execvpe code and
instead use direct stack allocation. This is QoI approach to make
it possible use in scenarios where memory is shared with parent
(vfork or clone with CLONE_VM).
For default process spawn (script file without a shebang), stack
allocation is bounded by NAME_MAX plus PATH_MAX plus 1. Large
file arguments returns an error (ENAMETOOLONG). This differs than
current GLIBC pratice in general, but it used to limit stack
allocation for large inputs. Also, path in PATH environment variable
larger than PATH_MAX are ignored.
The shell direct execution exeception, where execve returns ENOEXEC,
might requires a large stack allocation due large input argument list.
posix: Remove dynamic memory allocation from execl{e,p}
GLIBC execl{e,p} implementation might use malloc if the total number of
arguments exceed initial assumption size (1024). This might lead to
issues in two situations:
1. execl/execle is stated to be async-signal-safe by POSIX [1]. However
if execl is used in a signal handler with a large argument set (that
may call malloc internally) and if the resulting call fails it might
lead malloc in the program in a bad state.
2. If the functions are used in a vfork/clone(VFORK) situation it also
might issue malloc internal bad state.
This patch fixes it by using stack allocation instead. It also fixes
BZ#19534.
H.J. Lu [Fri, 4 Mar 2016 16:37:40 +0000 (08:37 -0800)]
x86-64: Fix memcpy IFUNC selection
Chek Fast_Unaligned_Load, instead of Slow_BSF, and also check for
Fast_Copy_Backward to enable __memcpy_ssse3_back. Existing selection
order is updated with following selection order:
1. __memcpy_avx_unaligned if AVX_Fast_Unaligned_Load bit is set.
2. __memcpy_sse2_unaligned if Fast_Unaligned_Load bit is set.
3. __memcpy_sse2 if SSSE3 isn't available.
4. __memcpy_ssse3_back if Fast_Copy_Backward bit it set.
5. __memcpy_ssse3
[BZ #18880]
* sysdeps/x86_64/multiarch/memcpy.S: Check Fast_Unaligned_Load,
instead of Slow_BSF, and also check for Fast_Copy_Backward to
enable __memcpy_ssse3_back.
Joseph Myers [Fri, 26 Feb 2016 16:17:25 +0000 (16:17 +0000)]
Remove kernel-features.h conditionals on pre-3.2 kernels.
This patch follows up on the increase in minimum kernel version by
removing conditionals in non-x86, non-x86_64 kernel-features.h headers
that are now constant for all supported kernel versions.
Carlos O'Donell [Thu, 25 Feb 2016 01:06:04 +0000 (20:06 -0500)]
Enable --localedir to set message catalog directory (Bug 14259)
In 1999 the project split "localedir" into "localedir" (path to compiled
locale archives) and "msgcatdir" (path to message catalogs). This
predates the 2002 change in the GNU Coding Standard to document the use
of "localedir" for the path to the message catalogs. It appears that
newlib, gcc, and several other projects also used "msgcatdir" at one
point or another in the past, and so it is in line with historical
precedent that glibc would also use "msgcatdir." However, given that the
GNU Coding Standard uses "localedir", we will switch to that for
consistency as a GNU project. Previous uses of --localdir didn't work
anyway (see bug 14259).
I am committing this patch in the understanding that nobody would object
to fixing #14259 as part of aligning our variable usage to the GNU
Coding Standard.
Given that previous "localedir" uses were converted to "complocaledir"
by [1], we can now convert "msgcatdir" to "localedir" and complete the
transition. With an addition to config.make.in we also fix bug 14259 and
allow users to specify the locale dependent data directory with
"--localedir" at configure time. There is still no way to control at
configure time the location of the *compiled* locale directory.
Tested on x86_64 with no regressions.
Tested using "--localedir" to specify alternate locale dependent data
directory and verified with "make install DESTDIR=/tmp/glibc".
Joseph Myers [Wed, 24 Feb 2016 17:15:12 +0000 (17:15 +0000)]
Require Linux 3.2 except on x86 / x86_64, 3.2 headers everywhere.
In <https://sourceware.org/ml/libc-alpha/2016-01/msg00885.html> I
proposed a minimum Linux kernel version of 3.2 for glibc 2.24, since
Linux 2.6.32 has reached EOL.
In the discussion in February, some concerns were expressed about
compatibility with OpenVZ containers. It's not clear that these are
real issues, given OpenVZ backporting kernel features and faking the
kernel version for guest software, as discussed in
<https://sourceware.org/ml/libc-alpha/2016-02/msg00278.html>. It's
also not clear that supporting running GNU/Linux distributions from
late 2016 (at the earliest) on a kernel series from 2009 is a sensible
expectation. However, as an interim step, this patch increases the
requirement everywhere except x86 / x86_64 (since the controversy was
only about those architectures); the special caveats and settings can
easily be removed later when we're ready to increase the requirements
on x86 / x86_64 (and if someone would like to raise the issue on LWN
as suggested in the previous discussion, that would be welcome). 3.2
kernel headers are required everywhere by this patch.
(x32 already requires 3.4 or later, so is unaffected by this patch.)
As usual for such a change, this patch only changes the configure
scripts and associated documentation. The intent is to follow up with
removal of dead __LINUX_KERNEL_VERSION conditionals. Each __ASSUME_*
or other macro that becomes dead can then be removed independently.
Tested for x86_64 and x86.
* sysdeps/unix/sysv/linux/configure.ac (LIBC_LINUX_VERSION):
Define to 3.2.0.
(arch_minimum_kernel): Likewise.
* sysdeps/unix/sysv/linux/configure: Regenerated.
* sysdeps/unix/sysv/linux/i386/configure.ac (arch_minimum_kernel):
Define to 2.6.32.
* sysdeps/unix/sysv/linux/i386/configure: Regenerated.
* sysdeps/unix/sysv/linux/x86_64/64/configure.ac
(arch_minimum_kernel): Define to 2.6.32.
* sysdeps/unix/sysv/linux/x86_64/64/configure: Regenerated.
* README: Document Linux 3.2 requirement.
* manual/install.texi (Linux): Document Linux 3.2 headers
requirement.
* INSTALL: Regenerated.
HAVE_BUILTIN_EXPECT macro was removed by commit glibc-2.14-280-g3ce1f29,
but then its use was unintentionally reintroduced during merge with GNU
gettext 0.19.3 by commit glibc-2.20-324-g6d24885, effectively disabling
all optimization based on __builtin_expect. As intl files are also part
of GNU gettext, HAVE_BUILTIN_EXPECT macro cannot be removed, so define
it unconditionally in config.h.in instead.
[BZ #19512]
* config.h.in (HAVE_BUILTIN_EXPECT): New macro.