Commit Graph

20618 Commits

Author SHA1 Message Date
Alan Modra 4b6e7667db PowerPC64 sysdep.h tidy
.align on some targets takes a byte alignment, on others like powerpc,
log2 of the byte alignment.  It's a good idea to avoid .align,
particularly since x86 and powerpc are different.  This patch fixes
the occurrences of .align in powerpc64/sysdep.h, renames DOT_LABEL
since the macro doesn't have anything to do with adding dots, removes
extraneous semicolons, and fixes some formatting.

	* sysdeps/powerpc/powerpc64/sysdep.h: Formatting.
	(FUNC_LABEL): Rename from DOT_LABEL.
	(ENTRY_1): Use FUNC_LABEL and remove leading space from label.
	Use .p2align rather than .align.
	(TRACEBACK, TRACEBACK_MASK): Use .p2align rather than .align.
	(ABORT_TRANSACTION): Likewise.
	(ENTRY_1, ENTRY_2, END_2, LOCALENTRY): Remove unnecessary semicolons,
	particularly at end.  Add semicolon at invocation as necessary.
	(TRACEBACK, TRACEBACK_MASK, PSEUDO, PSEUDO_NOERRNO): Likewise.
	(PSEUDO_ERRVAL, PPC64_LOAD_FUNCPTR, OPD_ENT): Likewise.
	* sysdeps/powerpc/powerpc64/multiarch/strrchr-power8.S (ENTRY,
	END): Adjust to suit.
2017-06-14 10:44:03 +09:30
Alan Modra fb499eb04e PowerPC64 FRAME_PARM_SAVE
I think FRAME_PARM[1-9]_SAVE confuse the code, particularly
FRAME_PARM9_SAVE.  There are only 8 parameter save slots!

	* sysdeps/powerpc/powerpc64/sysdep.h: (FRAME_BACKCHAIN,
	FRAME_CR_SAVE, FRAME_LR_SAVE): Move out of conditional.
	(FRAME_PARM1_SAVE, FRAME_PARM2_SAVE, FRAME_PARM3_SAVE,
	FRAME_PARM4_SAVE, FRAME_PARM5_SAVE, FRAME_PARM6_SAVE,
	FRAME_PARM7_SAVE, FRAME_PARM8_SAVE, FRAME_PARM9_SAVE): Delete.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S: Replace
	uses of FRAME_PARM[1-9]_SAVE with FRAME_PARM_SAVE plus offset.
2017-06-14 10:43:33 +09:30
Alan Modra dd8854361b PowerPC64, fix calls to _mcount
The macros used in assembly were broken on powerpc64 ELFv1.

	* sysdeps/powerpc/powerpc64/sysdep.h: (call_mcount_parm_offset): Delete.
	(SAVE_ARG, REST_ARG, CFI_SAVE_ARG): Correct.
2017-06-14 10:42:42 +09:30
Gordana Cmiljanovic b309f058cf mips: Fix store/load gp registers to/from ucontext_t
General purpose registers in mcontext_t structure
are 8 bytes long for both MIPS32/MIPS64.

get/set/make/swap context implementations for MIPS O32
incorrectly assume that general purpose registers
in this structure are 4 bytes long.

This patch is fixing that.

Tested for MIPS O32 LE and BE.
Compared objdump of modified functions for mips n32 and mips n64.

	[BZ #21548]
	* sysdeps/unix/sysv/linux/mips/getcontext.S: Define MCONTEXT_SZGREG as
	8 and use it when copying general purpose registers.
	* sysdeps/unix/sysv/linux/mips/makecontext.S: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/Makefile: Include new test for
	mips o32.
	* sysdeps/unix/sysv/linux/mips/mips32/bug-getcontext-mips-gp.c: Added
	new test for mips o32.
	* sysdeps/unix/sysv/linux/mips/setcontext.S: Define MCONTEXT_SZGREG as
	8 and use it when copying general purpose registers.
	* sysdeps/unix/sysv/linux/mips/swapcontext.S: Likewise.
2017-06-13 21:34:45 +00:00
Florian Weimer c2528fef3b configure: Suppress expected compiler error message 2017-06-13 22:24:38 +02:00
Florian Weimer f8bf87face dynarray: Implement begin/end functions in the spirit of C++ 2017-06-13 21:55:10 +02:00
H.J. Lu a65ea28d18 Make copy of <bits/std_abs.h> from GCC 7 [BZ #21573]
<bits/std_abs.h> from GCC 7 will include /usr/include/stdlib.h from
"#include_next" (instead of stdlib/stdlib.h in the glibc source
directory), and this turns up as a make dependency.  Also make a copy
of <bits/std_abs.h> to prevent it from including /usr/include/stdlib.h.

	[BZ #21573]
	* Makerules [$(c++-bits-std_abs-h) != ""] (before-compile): Add
	$(common-objpfx)bits/std_abs.h.
	[$(c++-bits-std_abs-h) != ""] ($(common-objpfx)bits/std_abs.h):
	New target.
	* config.make.in (c++-bits-std_abs-h): New.
	* configure.ac (find_cxx_header): Use "\,$1," with sed.
	(CXX_BITS_STD_ABS_H): New.
	(AC_SUBST(CXX_BITS_STD_ABS_H)): Likewise.
	* configure: Regenerated.
2017-06-13 10:53:45 -07:00
Zack Weinberg 19cf2879fe Correct indentation in posix/bits/cpu-set.h.
* posix/bits/cpu-set.h: Correct indentation of preprocessor
	directives.
2017-06-13 06:59:57 -04:00
Zack Weinberg 46ee3da55e Remove __need_schedparam and __cpu_set_t_defined.
bits/sched.h has logic to expose only an impl-namespace variant of
struct sched_param (i.e. struct __sched_param), but nothing uses it,
and the only header that includes bits/sched.h is sched.h.  The
__need_schedparam logic can therefore be removed.

bits/sched.h also has a great deal of code relating to cpu_set_t
objects that was *almost* the same between the two versions of
bits/sched.h in the tree; a little spelunking indicated that this is
because some bug fixes got applied to the Linux-specific bits/sched.h
but not the generic one.  Introduce a new header, bits/cpu-set.h,
containing the version of that code with the bugfixes, have sched.h
include it directly, and delete all of the code from both versions of
bits/sched.h.

Also remove the unnecessary name mangling in the definition of struct
sched_param -- POSIX specifies a field 'sched_priority', so there is
no reason to define it as '__sched_priority' and then paper over that
with a macro.  (Just in case someone was using the internal name,
'sched_priority' remains a macro defined to expand to itself, and
'__sched_priority' now expands to 'sched_priority'.)

Finally, as long as I'm touching these files anyway, merge new
constants from linux/sched.h into the Linux bits/sched.h.

	* bits/sched.h: Remove __need_schedparam logic and replace with a
	normal multiple-include guard.  Change field name in struct
	sched_param from __sched_priority to sched_priority.  Delete
	everything under #ifndef __cpu_set_t_defined.
	* sysdeps/unix/sysv/linux/bits/sched.h: Likewise.  Also sync with
	kernel sched.h, adding SCHED_ISO and SCHED_DEADLINE constants.

	* posix/sched.h: Include bits/cpu-set.h as well as bits/sched.h.
	For compatibility, #define sched_priority to itself, and #define
	__sched_priority as sched_priority.
	* posix/bits/cpu-set.h: New file containing, verbatim, the code
	that was under #ifndef __cpu_set_t_defined in
	sysdeps/unix/sysv/linux/bits/sched.h.
	* include/bits/cpu-set.h: New wrapper.
	* posix/Makefile: Install bits/cpu-set.h.
2017-06-12 17:11:36 -04:00
Wilco Dijkstra 4bad368d9f Fix build issue on x86.
Add an undef of __stpcpy in string-inlines.c to avoid a redefinition
error on x86.

	* string/string-inlines.c: Add undef of __stpcpy to fix build issue.
2017-06-12 19:59:09 +01:00
Paul E. Murphy 3c023dbf57 float128: Add test-{float128,ifloat128,float128-finite}
This adds test support for float128, and lays some groundwork for future
_FloatN types.

	* math/gen-libm-test.pl (@all_floats): Add ifloat128 and float128.
	(%all_floats_pfx): Add macro prefix for float128 (FLT128).
	* math/libm-test-exp10.inc (pow10_test): Do not test for _FloatN,
	* math/libm-test-isfinite.inc (finite_test): Likewise.
	* math/libm-test-lgamma.inc (gamma_test): Likewise.
	* math/libm-test-nexttoward.inc (nexttoward_test): Likewise.
	(nexttoward_test_data}: Likewise.
	* math/libm-test-remainder.inc (drem_test): Likewise.
	* math/libm-test-scalb.inc (scalb_test): Likewise.
	(scalb_test_data): Likewise.
	* math/libm-test-significand.inc (significand_test): Likewise.
	(significand_test_data): Likewise.
	* math/libm-test-support.c (check_complex): Replace __complex__
	FLOAT with CFLOAT to get the support for old compiler.
	* math/libm-test-support.h (check_complex): Likewise.
	* math/test-double.h (CFLOAT, TEST_FLOATN): New macros.
	* math/test-float.h (CFLOAT, TEST_FLOATN): Likewise.
	* math/test-ldouble.h (CFLOAT, TEST_FLOATN): Likewise.
	* math/test-float128.h: New file.
	* math/test-math-floatn.h: New file.
2017-06-12 14:48:54 -03:00
Gabriel F. T. Gomes 8fd3101431 Allow macros prefixed with FLT128 in include/float.h
TS 18661-3 specifies that macros prefixed with FLTN_ can be defined in
float.h, only if __STDC_WANT_IEC_60559_TYPES_EXT__ is defined as a macro
before the inclusion of float.h.  Since GCC 7.0, these macros are provided
under this condition, however, for older versions of GCC, these macros are
not provided at all.  This patch allows the definitions of such macros in
include/float.h for older compilers, if the condition above is met, and
even if _ISOMAC is defined.

	* include/float.h: Allow the definition of macros prefixed with
	FLT128 even if _ISOMAC is defined, but provided that
	__STDC_WANT_IEC_60559_TYPES_EXT__ is defined as a macro.
2017-06-12 14:48:53 -03:00
Gabriel F. T. Gomes 7d641c411d float128: Add strfromf128, strtof128, and wcstof128 to the manual
* manual/math.texi (Mathematics): Add description for _FloatN and
	_FloatNx types and mentions that they are not support in glibc for
	any architecture, so far.
	* manual/arith.texi (wcstof, wcstold): Replace the mention to
	stdlib.h with wchar.h.
	(Parsing of Floats): Add descriptions for strtofN and wcstofN.
	(Printing of Floats): Add description for strfromfN.
2017-06-12 14:48:53 -03:00
Paul E. Murphy 45f39d4588 float128: Add strtof128, wcstof128, and related functions.
The implementations are contained with sysdeps/ieee754/float128 as
they are only built when _Float128 is enabled within libc/m.

	* include/gmp.h (__mpn_construct_float128): New declaration.
	* include/stdlib.h: Include bits/floatn.h for _Float128 tests.
	(__strtof128_l): New declaration.
	(__strtof128_nan): Likewise.
	(__wcstof128_nan): Likewise.
	(__strtof128_internal): Likewise.
	(____strtof128_l_internal): Likewise.
	* include/wchar.h: Include bits/floatn.h for _Float128 tests.
	(__wcstof128_l): New declaration.
	(__wcstof128_internal): Likewise.

	* stdlib/Makefile (bug-strtod2): Link libm too.

	* stdlib/stdlib.h (strtof128): New declaration.
	(strtof128_l): Likewise.

	* stdlib/tst-strtod-nan-locale-main.c: Updated to use
	tst-strtod.h macros to ensure float128 gets tested too.

	* stdlib/tst-strtod-round-skeleton.c (CHOOSE_f128): New macro.

	* stdlib/tst-strtod.h: Include bits/floatn.h for _Float128
	tests.
	(IF_FLOAT128): New macro.
	(GEN_TEST_STRTOD): Update to optionally include _Float128 in
	the tests.
	(STRTOD_TEST_FOREACH): Likewise.

	* sysdeps/ieee754/float128/Makefile: Insert new strtof128 and
	wcstof128 functions into libc.

	* sysdeps/ieee754/float128/Versions: Add exports for the above
	new functions.

	* sysdeps/ieee754/float128/mpn2float128.c: New file.
	* sysdeps/ieee754/float128/strtod_nan_float128.h: New file.
	* sysdeps/ieee754/float128/strtof128.c: New file.
	* sysdeps/ieee754/float128/strtof128_l.c: New file.
	* sysdeps/ieee754/float128/strtof128_nan.c: New file.
	* sysdeps/ieee754/float128/wcstof128.c: New file.
	* sysdeps/ieee754/float128/wcstof128_l.c: New file.
	* sysdeps/ieee754/float128/wcstof128_nan.c: New fike.
	* wcsmbs/Makefile: (CFLAGS-wcstof128.c): Append strtox-CFLAGS.
	(CFLAGS-wcstof128_l): Likewise.

	* wcsmbs/wchar.h: Include bits/floatn.h for _Float128 tests.
	(wcstof128): New declaration.
	(wcstof128_l): Likewise.
2017-06-12 14:48:53 -03:00
Joseph Myers 9527ae8291 Fix XPG4 bsd_signal namespace (bug 21552).
bsd_signal was added in XPG4.2, so should be declared for
__USE_XOPEN_EXTENDED, instead of the present __USE_XOPEN condition.
This patch fixes the condition accordingly.

Tested for x86_64.

	[BZ #21552]
	* signal/signal.h (bsd_signal): Declare if [__USE_XOPEN_EXTENDED],
	not [__USE_XOPEN].
	* conform/Makefile (test-xfail-XPG4/signal.h/conform): Remove.
2017-06-12 17:39:47 +00:00
Joseph Myers a0f8b11520 Fix sigwait namespace (bug 21550).
sigwait was added to POSIX in 1995; it is not in older POSIX versions
or XPG4 / XPG4.2.  Thus it should be declared only if
__USE_POSIX199506; signal.h wrongly declares it for __USE_POSIX.
(sigwaitinfo is correctly conditioned on __USE_POSIX199309.)  This
patch fixes the condition on the declaration of sigwait.

Tested for x86_64.  Because of other namespace problems this does not
allow any conform/ XFAILs to be removed.

	[BZ #21550]
	* signal/signal.h (sigwait): Only declare if [__USE_POSIX199506].
2017-06-12 17:38:20 +00:00
H.J. Lu 5a103908c0 x86-64: Implement strcpy family IFUNC selectors in C
Implement strcpy family IFUNC selectors in C.

All internal calls within libc.so can use IFUNC on x86-64 since unlike
x86, x86-64 supports PC-relative addressing to access the GOT entry so
that it can call via PLT without using an extra register.  For libc.a,
we can't use IFUNC for functions which are called before IFUNC has been
initialized.  Use IFUNC internally reduces the icache footprint since
libc.so and other codes in the process use the same implementations.
This patch uses IFUNC for strcpy family functions within libc.

	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	strcpy-sse2 and stpcpy-sse2.
	* sysdeps/x86_64/multiarch/ifunc-unaligned-ssse3.h: New file.
	* sysdeps/x86_64/multiarch/stpcpy-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/stpcpy.c: Likewise.
	* sysdeps/x86_64/multiarch/stpncpy.c: Likewise.
	* sysdeps/x86_64/multiarch/strcpy-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/strcpy.c: Likewise.
	* sysdeps/x86_64/multiarch/strncpy.c: Likewise.
	* sysdeps/x86_64/multiarch/stpcpy.S: Removed.
	* sysdeps/x86_64/multiarch/stpncpy.S: Likewise.
	* sysdeps/x86_64/multiarch/strcpy.S: Likewise.
	* sysdeps/x86_64/multiarch/strncpy.S: Likewise.
	* sysdeps/x86_64/multiarch/stpncpy-c.c (weak_alias): New.
	(libc_hidden_def): Always defined as empty.
	* sysdeps/x86_64/multiarch/strncpy-c.c (libc_hidden_builtin_def):
	Always Defined as empty.
2017-06-12 09:06:09 -07:00
Wilco Dijkstra 18b10de7ce 2017-06-12 Wilco Dijkstra <wdijkstr@arm.com>
There is no longer a need for string2.h, so remove it and all mention of it.
Move the redirect for __stpcpy to include/string.h since it is still required
until all internal uses have been renamed.
This fixes several linknamespace/localplt failures when building with -Os.

	[BZ #15105]
	[BZ #19463]
	* include/string.h: Add internal redirect for __stpcpy.
	* string/Makefile: Remove bits/string2.h.
	* string/string.h: Update comment.
	* string/string-inlines.c: Remove bits/string2.h include and comment.
	* string/bits/string2.h: Remove file.
2017-06-12 15:22:17 +01:00
Wilco Dijkstra d99431e519 Replace all internal uses of __bzero with memset. This removes the need
to redirect it to a builtin and means memset is inlined whenever possible,
including with -Os.

	* sunrpc/bindrsvprt.c (bindresvport): Change __bzero to memset.
	* sunrpc/clnt_gen.c (clnt_create): Likewise.
	* sunrpc/des_impl.c (_des_crypt): Likewise.
	* sunrpc/key_call.c (key_gendes): Likewise.
	* sunrpc/pmap_rmt.c (clnt_broadcast): Likewise.
	* sunrpc/svc_simple.c (universal): Likewise.
	* sunrpc/svc_tcp.c (svctcp_create): Likewise.
	* sunrpc/svc_udp.c (svcudp_bufcreate): Likewise.
	* sysdeps/arm/aeabi_memclr.c (__aeabi_memclr): Likewise.
2017-06-12 14:56:53 +01:00
Zack Weinberg 8458956a62 Correct an outdated comment in stdlib/errno.h. 2017-06-10 13:08:36 -04:00
Paul Clarke cdfbe5037f powerpc: add sysconf support for cache geometries
There is currently no "cross-platform" (x86 and POWER) support for
determining the cacheline size.

This patch adds support to sysconf() to correctly report cacheline sizes
based on the information in the auxilliary vector.

Thus, using sysconf() is a cross-platform (x86 and POWER) solution for
determining cacheline sizes.

Support is added (on powerpc) for:
_SC_LEVEL1_ICACHE_SIZE _SC_LEVEL1_ICACHE_ASSOC _SC_LEVEL1_ICACHE_LINESIZE
_SC_LEVEL1_DCACHE_SIZE _SC_LEVEL1_DCACHE_ASSOC _SC_LEVEL1_DCACHE_LINESIZE
_SC_LEVEL2_CACHE_SIZE  _SC_LEVEL2_CACHE_ASSOC  _SC_LEVEL2_CACHE_LINESIZE
_SC_LEVEL3_CACHE_SIZE  _SC_LEVEL3_CACHE_ASSOC  _SC_LEVEL3_CACHE_LINESIZE

	* sysdeps/unix/sysv/linux/powerpc/sysconf.c: New file.
	Add powerpc-specific overrides for L1, L2, L3 CACHE_SIZEs,
	CACHE_ASSOCs, and CACHE_LINESIZEs, retrieving from auxv.
	* sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c:
	New file.  Invoke newly supported sysconf values for powerpc,
	and report results.  If none are supported, report so.
	* sysdeps/unix/sysv/linux/powerpc/Makefile (tests):  Add new test,
	tst-sysconf.
2017-06-09 14:36:22 -03:00
Tulio Magno Quites Machado Filho d6bd839b9a Add a way to bypass the PLT when calling getauxval
* include/sys/auxv.h (__getauxval): Add a prototype and its
	libc_hidden_proto.
	* misc/getauxval.c (__getauxval): Use libc_hidden_def.
2017-06-09 14:36:22 -03:00
Joseph Myers a17973efc6 Fix waitid namespace (bug 21561).
In sys/wait.h, waitid and associated constants and types are UX-shaded
in XPG4.2 (so not in XPG4), and XSI-shaded in POSIX before 2008, so
should be appropriately conditional in the headers.  This patch fixes
the conditionals accordingly.  (WCONTINUED is actually still
XSI-shaded in POSIX.1:2008, but W* is also reserved there without
XSI-shading, so nothing special needs to be done about the
conditionals on WCONTINUED to conform to POSIX.1:2008 namespace
rules.)

Tested for x86_64.

	[BZ #21561]
	* posix/sys/wait.h (idtype_t): Change [__USE_XOPEN] condition to
	[__USE_XOPEN_EXTENDED].
	(id_t): Likewise.
	(include of <bits/types/siginfo_t.h): Likewise.
	(waitid): Likewise.
	* sysdeps/unix/sysv/linux/bits/waitflags.h (WSTOPPED): Condition
	on [__USE_XOPEN_EXTENDED || __USE_XOPEN2K8].
	(WEXITED): Likewise.
	(WCONTINUED): Likewise.
	(WNOWAIT): Likewise.
	* conform/Makefile (test-xfail-XPG4/stdlib.h/conform): Remove.
	(test-xfail-XPG4/sys/wait.h/conform): Likewise.
	(test-xfail-POSIX/sys/wait.h/conform): Likewise.
2017-06-09 16:28:07 +00:00
Joseph Myers 10d33c5a86 Update nios2, sparc32 localplt.data files for recent GCC change.
A recent GCC change to expand floating-point classification built-in
functions inline using integer rather than floating-point arithmetic
in some cases resulted in localplt test failures for nios2 and sparc32
<https://sourceware.org/ml/libc-testresults/2017-q2/msg00320.html>.
This patch updates the localplt.data files in question to mark the
relevant symbols as optional / add a new optional symbol.  (The GCC
patch has been reverted because of other problems it caused, but one
can assume it will be applied again, without changes that would affect
the PLT entries generated, once those issues have been resolved.)

Tested with build-many-glibcs.py.

	* sysdeps/unix/sysv/linux/nios2/localplt.data (__gtdf2): Mark
	libc.so PLT entry optional.
	(__gtsf2): Likewise.
	(__unorddf2): Likewise.
	(__unordsf2): Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data (_Q_fgt):
	New optional libc.so PLT entry.
2017-06-09 16:26:06 +00:00
Joseph Myers b85995291e Fix sigpause namespace (bug 21554).
The sigpause function is declared for __USE_XOPEN.  As it's new in
XPG4.2 it should be declared only for __USE_XOPEN_EXTENDED.  This
patch fixes the declaration accordingly.

Tested for x86_64.

	[BZ #21554]
	* signal/signal.h (sigpause):: Declare if [__USE_XOPEN_EXTENDED],
	not [__USE_XOPEN].
2017-06-09 13:49:10 +00:00
Joseph Myers 0862cdcdc8 Condition signal.h inclusion in sys/wait.h (bug 21560).
sys/wait.h includes signal.h unconditionally.  But the permission to
do so is UX-shaded in XPG4.2, and XSI-shaded in POSIX before 2008, so
this should not be unconditional.  This patch fixes this
conservatively: the include is kept, but conditioned on the standards
that permit it (meaning it is still present by default, because
non-XSI POSIX.1:2008 is enabled by default).  <bits/types.h> is now
included unconditionally to provide the required definition of
__pid_t; it was previously included via <signal.h>.  Some standards
require pid_t to be defined here, and all allow it to be defined here;
previously defined via <signal.h>, it's now defined directly in this
header.

Tested for x86_64.  This does not fix any of the sys/wait.h
conformtest failures, but substantially reduces the number of
namespace failures for sys/wait.h for XPG4 and POSIX.

	[BZ #21560]
	* posix/sys/wait.h: Condition include of <signal.h> on
	[__USE_XOPEN_EXTENDED || __USE_XOPEN2K8].  Include <bits/types.h>
	unconditionally.
	[!__pid_t_defined] (pid_t): Define typedef.
2017-06-09 13:45:37 +00:00
Zack Weinberg b4971123e9 Remove bare use of __attribute__ in include/errno.h.
This is just a style fix; we always prefer the shorthand macros over
bare uses of __attribute__, even in private headers.

	* include/errno.h (__errno_location): Use __attribute_const__
	instead of bare __attribute__.
2017-06-09 09:37:55 -04:00
Zack Weinberg 65b6d8b79c Polish the treatment of dl-tunable-list.h in Makeconfig.
Like basically all before-compile headers, dl-tunable-list.h should be
generated using a stamp file to minimize unnecessary rebuilding; it
wasn't being added to common-generated, so it wouldn't get cleaned up;
and it was in between the rules for libc-modules.h/.stmp and their own
addition to common-generated.

	* Makeconfig (dl-tunable-list.h): Generate using a stamp file.
	(common-generated): Add libc-modules.h and libc-modules.stmp in a
	more appropriate location. Also add dl-tunable-list.h and
	dl-tunable-list.stmp.
2017-06-09 09:35:31 -04:00
H.J. Lu 6b6710e55b x86-64: Correct comments in ifunc-impl-list.c
* sysdeps/x86_64/multiarch/ifunc-impl-list.c: Correct comments.
2017-06-09 05:53:45 -07:00
H.J. Lu d2538b9156 x86-64: Optimize strrchr/wcsrchr with AVX2
Optimize strrchr/wcsrchr with AVX2 to check 32 bytes with vector
instructions.  It is as fast as SSE2 version for small data sizes
and up to 1X faster for large data sizes on Haswell.  Select AVX2
version on AVX2 machines where vzeroupper is preferred and AVX
unaligned load is fast.

	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	strrchr-sse2, strrchr-avx2, wcsrchr-sse2 and wcsrchr-avx2.
	* sysdeps/x86_64/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add tests for __strrchr_avx2,
	__strrchr_sse2, __wcsrchr_avx2 and __wcsrchr_sse2.
	* sysdeps/x86_64/multiarch/strrchr-avx2.S: New file.
	* sysdeps/x86_64/multiarch/strrchr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/strrchr.c: Likewise.
	* sysdeps/x86_64/multiarch/wcsrchr-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/wcsrchr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/wcsrchr.c: Likewise.
2017-06-09 05:45:52 -07:00
H.J. Lu 5ac7aa1d7c x86-64: Optimize memrchr with AVX2
Optimize memrchr with AVX2 to search 32 bytes with a single vector
compare instruction.  It is as fast as SSE2 memrchr for small data
sizes and up to 1X faster for large data sizes on Haswell.  Select
AVX2 memrchr on AVX2 machines where vzeroupper is preferred and AVX
unaligned load is fast.

	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	memrchr-sse2 and memrchr-avx2.
	* sysdeps/x86_64/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add tests for __memrchr_avx2 and
	__memrchr_sse2.
	* sysdeps/x86_64/multiarch/memrchr-avx2.S: New file.
	* sysdeps/x86_64/multiarch/memrchr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/memrchr.c: Likewise.
2017-06-09 05:44:41 -07:00
H.J. Lu 8fe57365bf x86-64: Optimize strchr/strchrnul/wcschr with AVX2
Optimize strchr/strchrnul/wcschr with AVX2 to search 32 bytes with vector
instructions.  It is as fast as SSE2 versions for size <= 16 bytes and up
to 1X faster for or size > 16 bytes on Haswell.  Select AVX2 version on
AVX2 machines where vzeroupper is preferred and AVX unaligned load is fast.

NB: It uses TZCNT instead of BSF since TZCNT produces the same result
as BSF for non-zero input.  TZCNT is faster than BSF and is executed
as BSF if machine doesn't support TZCNT.

	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	strchr-sse2, strchrnul-sse2, strchr-avx2, strchrnul-avx2,
	wcschr-sse2 and wcschr-avx2.
	* sysdeps/x86_64/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add tests for __strchr_avx2,
	__strchrnul_avx2, __strchrnul_sse2, __wcschr_avx2 and
	__wcschr_sse2.
	* sysdeps/x86_64/multiarch/strchr-avx2.S: New file.
	* sysdeps/x86_64/multiarch/strchr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/strchr.c: Likewise.
	* sysdeps/x86_64/multiarch/strchrnul-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/strchrnul-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/strchrnul.c: Likewise.
	* sysdeps/x86_64/multiarch/wcschr-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/wcschr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/wcschr.c: Likewise.
	* sysdeps/x86_64/multiarch/strchr.S: Removed.
2017-06-09 05:42:29 -07:00
H.J. Lu dc485ceb2a x86-64: Optimize strlen/strnlen/wcslen/wcsnlen with AVX2
Optimize strlen/strnlen/wcslen/wcsnlen with AVX2 to check 32 bytes with
a single vector compare instruction.  It is as fast as SSE2 versions for
size <= 16 bytes and up to 1X faster for or size > 16 bytes on Haswell.
Select AVX2 version on AVX2 machines where vzeroupper is preferred and
AVX unaligned load is fast.

NB: It uses TZCNT instead of BSF since TZCNT produces the same result
as BSF for non-zero input.  TZCNT is faster than BSF and is executed
as BSF if machine doesn't support TZCNT.

	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	strlen-sse2, strnlen-sse2, strlen-avx2, strnlen-avx2,
	wcslen-sse2, wcslen-avx2 and wcsnlen-avx2.
	* sysdeps/x86_64/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add tests for __strlen_avx2,
	__strlen_sse2, __strnlen_avx2, __strnlen_sse2, __wcslen_avx2,
	__wcslen_sse2 and __wcsnlen_avx2.
	* sysdeps/x86_64/multiarch/strlen-avx2.S: New file.
	* sysdeps/x86_64/multiarch/strlen-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/strlen.c: Likewise.
	* sysdeps/x86_64/multiarch/strnlen-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/strnlen-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/strnlen.c: Likewise.
	* sysdeps/x86_64/multiarch/wcslen-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/wcslen-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/wcslen.c: Likewise.
	* sysdeps/x86_64/multiarch/wcsnlen-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/wcsnlen.c (OPTIMIZE (avx2)): New.
	(IFUNC_SELECTOR): Return OPTIMIZE (avx2) on AVX2 machines where
	vzeroupper is preferred and AVX unaligned load is fast.
2017-06-09 05:18:18 -07:00
H.J. Lu 2f5d20ac99 x86-64: Optimize memchr/rawmemchr/wmemchr with SSE2/AVX2
SSE2 memchr is extended to support wmemchr.  AVX2 memchr/rawmemchr/wmemchr
are added to search 32 bytes with a single vector compare instruction.
AVX2 memchr/rawmemchr/wmemchr are as fast as SSE2 memchr/rawmemchr/wmemchr
for small sizes and up to 1.5X faster for larger sizes on Haswell and
Skylake.  Select AVX2 memchr/rawmemchr/wmemchr on AVX2 machines where
vzeroupper is preferred and AVX unaligned load is fast.

NB: It uses TZCNT instead of BSF since TZCNT produces the same result
as BSF for non-zero input.  TZCNT is faster than BSF and is executed
as BSF if machine doesn't support TZCNT.

	* sysdeps/x86_64/memchr.S (MEMCHR): New.  Depending on if
	USE_AS_WMEMCHR is defined.
	(PCMPEQ): Likewise.
	(memchr): Renamed to ...
	(MEMCHR): This.  Support wmemchr if USE_AS_WMEMCHR is defined.
	Replace pcmpeqb with PCMPEQ.
	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	memchr-sse2, rawmemchr-sse2, memchr-avx2, rawmemchr-avx2,
	wmemchr-sse4_1, wmemchr-avx2 and wmemchr-c.
	* sysdeps/x86_64/multiarch/ifunc-avx2.h: New file.
	* sysdeps/x86_64/multiarch/memchr-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/memchr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/memchr.c: Likewise.
	* sysdeps/x86_64/multiarch/rawmemchr-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/rawmemchr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/rawmemchr.c: Likewise.
	* sysdeps/x86_64/multiarch/wmemchr-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/wmemchr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/wmemchr.c: Likewise.
	* sysdeps/x86_64/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Test __memchr_avx2, __memchr_sse2,
	__rawmemchr_avx2, __rawmemchr_sse2, __wmemchr_avx2 and
	__wmemchr_sse2.
2017-06-09 05:13:31 -07:00
Florian Weimer 990c32b93a malloc: Remove tst-dynarray, tst-dynarray-fail from test-srcs
They are already covered through the tests variable.
2017-06-09 14:08:57 +02:00
Florian Weimer 48bd8cda09 support: Expose TEST_VERIFY_EXIT behavior to GCC optimizers
Previously, the implementation would conditionally exit based on the
status argument, which GCC did not know about.  This leads to
false uninitialized variable warnings when data is accessed after a
TEST_VERIFY_EXIT failure (from code which would never execute).
2017-06-09 14:08:13 +02:00
Siddhesh Poyarekar 6c85cc2852 aarch64: Fix undefined behavior in _dl_procinfo
1 << 31 is undefined, so replace it with a cleaner check.  Also remove
magic numbers in comments.

	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h: Remove
	mention of magic numbers in comments.
	(_dl_procinfo): Fix undefined behavior
2017-06-09 14:18:12 +05:30
Joseph Myers ab70273bb7 conformtest: Correct sys/wait.h expectations for XPG4.
This patch corrects the conformtest expectations for sys/wait.h for
XPG4.  This does not change the test results for this header at the
makefile level since it fixes some spurious failures for this header
while introducing other failures previously hidden by incorrect
expectations.  However, it shows up issues with stdlib.h for XPG4
defining W* names that are not permitted in this case (previously
wrongly allowed; the W* reservation is UX-shaded in XPG4.2 /
XSI-shaded in POSIX before 2008); that test is thus XFAILed.

Tested for x86_64.

	* conform/data/sys/wait.h-data (WIFCONTINUED): Do not expect for
	[XPG4].
	(WEXITED): Likewise.
	(WSTOPPED): Likewise.
	(WCONTINUED): Likewise.
	(WNOHANG): Likewise.
	(WNOWAIT): Likewise.
	(idtype_t): Likewise.
	(P_ALL): Likewise.
	(P_PID): Likewise.
	(P_PGID): Likewise.
	(id_t): Likewise.
	(siginfo_t): Likewise.
	(wait3): Likewise.
	(waitid): Likewise.
	(signal.h): Do not allow header for [XPG4].
	(sys/resource.h): Likewise.
	(si_*): Do not allow for [XPG4].
	(W*): Likewise.
	(P_*): Likewise.
	(BUS_): Likewise.
	(CLD_): Likewise.
	(FPE_): Likewise.
	(ILL_): Likewise.
	(POLL_): Likewise.
	(SEGV_): Likewise.
	(SI_): Likewise.
	(TRAP_): Likewise.
	* conform/Makefile (test-xfail-XPG4/stdlib.h/conform): New
	variable.
2017-06-08 22:34:58 +00:00
H.J. Lu 37b66c0b1a ld.so: Consolidate 2 strtouls into _dl_strtoul [BZ #21528]
There are 2 minimal strtoul implementations in ld.so:

1. __strtoul_internal in elf/dl-minimal.c.
2. tunables_strtoul in elf/dl-tunables.c.

This patch adds _dl_strtoul to replace them.  Tested builds with and
without --enable-tunables.

	[BZ #21528]
	* elf/dl-minimal.c (__strtoul_internal): Removed.
	(strtoul): Likewise.
	* elf/dl-misc.c (_dl_strtoul): New function.
	* elf/dl-tunables.c (tunables_strtoul): Removed.
	(tunable_initialize): Replace tunables_strtoul with _dl_strtoul.
	* elf/rtld.c (process_envvars): Likewise.
	* sysdeps/unix/sysv/linux/dl-librecon.h (_dl_osversion_init):
	Likewise.
	* sysdeps/generic/ldsodefs.h (_dl_strtoul): New prototype.
2017-06-08 12:52:42 -07:00
Zack Weinberg 199fc19d3a Remove __need macros from stdio.h and wchar.h.
wint_t is a little finicky because it might be defined by stddef.h, which
belongs to the compiler.

In addition to the _types_, a bunch of other declarations shared between
wctype.h and wchar.h are factored out to their own header.

	* libio/bits/types/FILE.h, libio/bits/types/__FILE.h
	* wcsmbs/bits/types/mbstate_t.h, wcsmbs/bits/types/__mbstate_t.h
	* wcsmbs/bits/types/wint_t.h: New single-type definition files.
	* wctype/bits/wctype-wchar.h: New file holding declarations shared
	between wctype.h and wchar.h.

	* libio/Makefile, wcsmbs/Makefile, wctype/Makefile:
	Install them.

	* include/bits/types/FILE.h, include/bits/types/__FILE.h
	* include/bits/types/mbstate_t.h, include/bits/types/__mbstate_t.h
	* include/bits/types/wint_t.h, include/bits/wcsmbs-wchar.h:
	New wrappers.
	* include/stdio.h, include/wchar.h, include/wctype.h:
	No need to handle __need macros.

	* grp/grp.h, gshadow/gshadow.h, hurd/hurd.h, iconv/gconv.h
	* libio/stdio.h, mach/mach.h, misc/mntent.h, pwd/pwd.h
	* shadow/shadow.h, stdio-common/printf.h, wcsmbs/uchar.h
	* wcsmbs/wchar.h, wctype/wctype.h
	* sysdeps/generic/_G_config.h, sysdeps/unix/sysv/linux/_G_config.h
	Use the new files instead of __need macros.
2017-06-08 13:58:17 -04:00
H.J. Lu 4615f5aefe Add more tests for memchr
This patch adds tests for len == 0 and tests for positions close to the
beginning, which are equivalent to positions close to the end for memchr.

	* string/test-memrchr.c (test_main): Add tests for len == 0
	and tests for positions close to the beginning, which are
	equivalent to positions close to the end for memchr.
2017-06-08 09:56:01 -07:00
H.J. Lu 5e1122827a x86-64: Rename wmemset.h to ifunc-wmemset.h
No code changes.

	* sysdeps/x86_64/multiarch/wmemset.c: Include ifunc-wmemset.h
	instead of wmemset.h.
	* sysdeps/x86_64/multiarch/wmemset_chk.c: Likewise.
	* sysdeps/x86_64/multiarch/wmemset.h: Renamed to ...
	* sysdeps/x86_64/multiarch/ifunc-wmemset.h: This.
2017-06-07 14:48:34 -07:00
Gabriel F. T. Gomes cf2046ec7d float128: Add strfromf128
Add strfromf128 to stdlib when _Float128 support is enabled.

	* stdio-common/printf-parsemb.c (__parse_one_specmb): Initialize
	spec->info.is_binary128 to zero.
	* stdio-common/printf.h (printf_info): Add new member is_binary128
	to indicate that the number being converted to string is compatible
	with the IEC 60559 binary128 format.
	* stdio-common/printf_fp.c (__printf_fp_l): Add code to deal with
	_Float128 numbers.
	* stdio-common/printf_fphex.c: Include ieee754_float128.h and
	ldbl-128/printf_fphex_macros.h
	(__printf_fphex): Add code to deal with _Float128 numbers.
	* stdio-common/printf_size.c (__printf_size): Likewise.
	* stdio-common/vfprintf.c (process_arg): Initialize member
	info.is_binary128 to zero.
	* stdlib/fpioconst.h (FLT128_MAX_10_EXP_LOG): New macro.
	* stdlib/stdlib.h: Include bits/floatn.h for _Float128 support.
	(strfromf128): New declaration.
	* stdlib/strfrom-skeleton.c (STRFROM): Set member info.is_binary128
	to one.
	* sysdeps/ieee754/float128/Makefile: Add strfromf128.
	* sysdeps/ieee754/float128/Versions: Likewise.
	* sysdeps/ieee754/float128/strfromf128.c: New file.
2017-06-07 17:08:21 -03:00
Gabriel F. T. Gomes 2bc646c9e9 Refactor PRINT_FPHEX_LONG_DOUBLE into a reusable macro
This patch refactors the macro PRINT_FPHEX_LONG_DOUBLE from the file
sysdeps/ieee754/ldbl-128/printf_fphex.c into a function-like macro to
enable its use for both long double and _Float128, when they are
ABI-distinct.

	* sysdeps/ieee754/ldbl-128/printf_fphex.c: Include
	ldbl-128/printf_fphex_macros.h for the definition of PRINT_FPHEX.
	(PRINT_FPHEX_LONG_DOUBLE): Define based on PRINT_FPHEX.
	* sysdeps/ieee754/ldbl-128/printf_fphex_macros.h
	(PRINT_FPHEX): New function-like macro that can be used for long
	double, as well as for _Float128
2017-06-07 17:06:31 -03:00
Gabriel F. T. Gomes aab0f374e7 Remove duplicated code from __printf_fp_l, __printf_fphex, and __printf_size
In __printf_fp_l, __printf_fphex, and __printf_size the blocks of code that are
used to read a double or long double argument, check for special values and
convert to multiprecision are similar.  When adding float128 support to libc,
more code would be duplicated to deal with the extra type.  This patch moves
the repetitive code to a macro which is now used by double and long double and
will be used for float128 when support is added, thus avoiding more
duplication.

Tested for powerpc64le and s390x.

	* stdio-common/printf_fp.c (PRINTF_FP_FETCH): New macro.
	(__printf_fp_l): Use the new macro to avoid duplicating code.
	* stdio-common/printf_fphex.c (PRINTF_FPHEX_FETCH): New macro.
	(__printf_fphex): Use the new macro to avoid duplicating code.
	* stdio-common/printf_size.c (PRINTF_SIZE_FETCH): New macro.
	(__printf_size): Use the new macro to avoid duplicating code.
2017-06-07 17:04:58 -03:00
Gabriel F. T. Gomes 32bf1d09da float128: Add conversion from float128 to mpn
Reuse the code for __mpn_extract_long_double to implement
__mpn_extract_float128.

	* include/gmp.h: Include bits/floatn.h
	(__mpn_extract_float128): Declare when __HAVE_DISTINCT_FLOAT128 is 1.
	* stdlib/gmp-impl.h: Also check if alloca is not defined before
	including stack-alloc.h.  It could have been defined by other header
	which not necessarily defines HAVE_ALLOCA.
	* sysdeps/ieee754/float128/Makefile: New file.
	* sysdeps/ieee754/float128/float1282mpn.c: New file.
	* sysdeps/ieee754/float128/float128_private.h: Include gmp.h before
	redefining __mpn_extract_long_double to __mpn_extract_float128, then
	redefine __mpn_extract_long_double to __mpn_extract_float128.
	* sysdeps/ieee754/ldbl-128/ldbl2mpn.c: Replace long double with
	_Float128 to allow float128_private.h overrides.
2017-06-07 17:03:43 -03:00
Paul E. Murphy 82c19bdfe3 float128: Extend the power of ten tables
Update the power of ten tables used by the common implementation when long
double is not the most expressive real type.

	* stdlib/fpioconst.h: Include bits/floatn.h.
	(FPIOCONST_HAVE_EXTENDED_RANGE): New macro for testing how big the
	power of ten table should be.
	(FPIOCONST_POW10_ARRAY_SIZE): Use larger table if above is true.
	* stdlib/fpioconst.c (__tens): Use FPIOCONST_HAVE_EXTENDED_RANGE
	to include larger tables when _Float128 support is enabled.
	(_fpioconst_pow10): Likewise.
2017-06-07 16:58:42 -03:00
Joseph Myers 81df4d253d Fix include paths in include/bits/types/*.h.
Various include/bits/types/*.h files do

where the path specified is relative to the toplevel glibc source
directory.

That has the wrong number of ../ components to achieve the desired
effect; it actually searches relative to include/ for a file that does
not exist there, then goes on to search the #include <> paths
specified with -I, eventually finding the desired file via such a path
(e.g. sysdeps/nptl/) with the right number of directory components.
Before that it searches include/../.. because of the -Iinclude,
meaning that an appropriately named file outside the glibc source tree
can affect the build.

This patch changes all those files to do #include <path> without the
../../, as some such files already do.

Tested for x86_64.

	* include/bits/types/clock_t.h: Use #include <path> instead of
	#include "../../path".
	* include/bits/types/clockid_t.h: Likewise.
	* include/bits/types/struct_iovec.h: Likewise.
	* include/bits/types/struct_itimerspec.h: Likewise.
	* include/bits/types/struct_osockaddr.h: Likewise.
	* include/bits/types/struct_sigstack.h: Likewise.
	* include/bits/types/struct_timespec.h: Likewise.
	* include/bits/types/struct_timeval.h: Likewise.
	* include/bits/types/struct_tm.h: Likewise.
	* include/bits/types/time_t.h: Likewise.
	* include/bits/types/timer_t.h: Likewise.
2017-06-07 17:59:50 +00:00
Joseph Myers bd6193907a Fix tst-timezone race (bug 14096).
I observed a failure of timezone/tst-timezone with the same symptoms
as reported in bug 14096.

I was unable to reproduce the failure on testing again.  However, from
inspection, the cause is as follows.  tst-timezone uses time zones
compiled from the northamerica file, but has no dependency on any such
zones, so with a parallel build it is possible that they do not get
compiled until after tst-timezone is run.  This patch adds a
dependency on the compiled America/New_York zone (the one used as a
makefile target to cause such zones to be compiled, rather than one
which is actually used in that test) to fix the race.

Tested for x86_64.

	[BZ #14096]
	* timezone/Makefile ($(objpfx)tst-timezone.out): Depend on
	America/New_York.
2017-06-07 17:14:28 +00:00
H.J. Lu 2e87c7d158 x86-64: Fold ifunc-sse4_1.h into wcsnlen.c
Since ifunc-sse4_1.h is included only by wcsnlen.c, we can fold it
into wcsnlen.c.  No code changes in wcsnlen.o.

2017-06-07  H.J. Lu  <hongjiu.lu@intel.com>

	* sysdeps/x86_64/multiarch/ifunc-sse4_1.h: Removed and folded
	into ...
	* sysdeps/x86_64/multiarch/wcsnlen.c: Here.  Don't include
	ifunc-sse4_1.h.
2017-06-07 09:04:40 -07:00
Arjun Shankar 8f0a947cf5 Remove check for NULL buffer passed to `ptsname_r'
`ptsname_r' is declared in stdlib.h to only accept a `nonnull'
second argument and therefore GCC may choose to make optimizations
based on the assumption that this argument is NULL. This means
that potentially, GCC can optimize away the NULL check at some
point in the future. Since this is a programming interface, we
might as well remove the NULL check ourselves.

This also warrants a change to the `ptsname_r' manual page that
must be submitted to the corresponding mailing list.

In addition, remove the NULL buffer test in login/tst-ptsname.c.
2017-06-07 17:37:59 +02:00
Arjun Shankar fdc543919a Use test-driver in sysdeps/unix/sysv/linux/tst-clone2.c 2017-06-07 14:05:42 +02:00
Siddhesh Poyarekar ea01a4da21 aarch64: Add hwcap string routines
Add support for routines in dl-procinfo.h to show string versions of
HWCAP entries when a program is invoked with the LD_SHOW_AUXV
environment variable set and also to aid in path resolution for
ldconfig.

	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c
	(_dl_aarch64_cap_flags): New array.
	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
	(_dl_hwcap_string, _dl_string_hwcap, _dl_procinfo): Implement
	functions.
2017-06-07 11:11:40 +05:30
Siddhesh Poyarekar 511c5a1087 Make LD_HWCAP_MASK usable for static binaries
The LD_HWCAP_MASK environment variable was ignored in static binaries,
which is inconsistent with the behaviour of dynamically linked
binaries.  This seems to have been because of the inability of
ld_hwcap_mask being read early enough to influence anything but now
that it is in tunables, the mask is usable in static binaries as well.

This feature is important for aarch64, which relies on HWCAP_CPUID
being masked out to disable multiarch.  A sanity test on x86_64 shows
that there are no failures.  Likewise for aarch64.

	* elf/dl-hwcaps.h [HAVE_TUNABLES]: Always read hwcap_mask.
	* sysdeps/sparc/sparc32/dl-machine.h [HAVE_TUNABLES]:
	Likewise.
	* sysdeps/x86/cpu-features.c (init_cpu_features): Always set
	up hwcap and hwcap_mask.
2017-06-07 11:11:40 +05:30
Siddhesh Poyarekar f82e9672ad aarch64: Allow overriding HWCAP_CPUID feature check using HWCAP_MASK
Now that LD_HWCAP_MASK (or glibc.tune.hwcap_mask) is read early enough
to influence cpu feature check in aarch64, use it to influence
multiarch selection.  Setting LD_HWCAP_MASK such that it clears
HWCAP_CPUID will now disable multiarch for the binary.

HWCAP_CPUID is also now set in HWCAP_IMPORTANT so that it is set by
default.  With this patch, this feature is only usable with
dyanmically linked binaries because LD_HWCAP_MASK is not read for
static binaries.  A future patch fixes that.

	* sysdeps/unix/sysv/linux/aarch64/cpu-features.c
	(init_cpu_features): Use glibc.tune.hwcap_mask.
	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h: New file.
2017-06-07 11:11:39 +05:30
Siddhesh Poyarekar ff08fc59e3 tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask
Drop _dl_hwcap_mask when building with tunables.  This completes the
transition of hwcap_mask reading from _dl_hwcap_mask to tunables.

	* elf/dl-hwcaps.h: New file.
	* elf/dl-hwcaps.c: Include it.
	(_dl_important_hwcaps)[HAVE_TUNABLES]: Read and update
	glibc.tune.hwcap_mask.
	* elf/dl-cache.c: Include dl-hwcaps.h.
	(_dl_load_cache_lookup)[HAVE_TUNABLES]: Read
	glibc.tune.hwcap_mask.
	* sysdeps/sparc/sparc32/dl-machine.h: Likewise.
	* elf/dl-support.c (_dl_hwcap2)[HAVE_TUNABLES]: Drop
	_dl_hwcap_mask.
	* elf/rtld.c (rtld_global_ro)[HAVE_TUNABLES]: Drop
	_dl_hwcap_mask.
	(process_envvars)[HAVE_TUNABLES]: Likewise.
	* sysdeps/generic/ldsodefs.h (rtld_global_ro)[HAVE_TUNABLES]:
	Likewise.
	* sysdeps/x86/cpu-features.c (init_cpu_features): Don't
	initialize dl_hwcap_mask when tunables are enabled.
2017-06-07 11:11:38 +05:30
Siddhesh Poyarekar 6482e63403 Add include guards to dl-procinfo.h
The dl-procinfo.h for linux/s390 and linux/i386 don't have include
guards, which causes them to fail since addition of LD_HWCAP_MASK to
tunables.  Add _DL_I386_PROCINFO_H guard to avoid redefining
_dl_procinfo on multiple includes and also allow the subsequent
include of another dl-procinfo.h to work.

Verified with a build test on i686.

	* sysdeps/unix/sysv/linux/i386/dl-procinfo.h: Add include
	guard.
	* sysdeps/unix/sysv/linux/s390/dl-procinfo.h: Likewise.
2017-06-07 11:11:38 +05:30
Siddhesh Poyarekar ea9b0ecbf0 tunables: Add LD_HWCAP_MASK to tunables
Add LD_HWCAP_MASK to tunables in preparation of it being removed from
rtld.c.  This allows us to read LD_HWCAP_MASK much earlier so that it
can influence IFUNC resolution in aarch64.

This patch does not actually do anything other than read the
LD_HWCAP_MASK variable and add the tunables way to set the
LD_HWCAP_MASK, i.e. via the glibc.tune.hwcap_mask tunable.  In a
follow-up patch, the _dl_hwcap_mask will be replaced with
glibc.tune.hwcap_mask to complete the transition.

	* elf/dl-tunables.list: Add glibc.tune.hwcap_mask.
	* scripts/gen-tunables.awk: Include dl-procinfo.h.
	* manual/tunables.texi: Document glibc.tune.hwcap_mask.
2017-06-07 11:11:37 +05:30
Siddhesh Poyarekar 44330b6d32 tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined.  This patch is an attempt
to do just that.

This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*.  If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable.  The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism).  For example:

    val = TUNABLE_GET (check, int32_t, check_callback)

returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.

Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself.  For example:

  TUNABLE_SET (check, int32_t, 2)

will set glibc.malloc.check to 2.  Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.

To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:

  TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
  TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)

In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is.  However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.

	* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
	* elf/dl-tunables.c: Likewise.
	(do_tunable_update_val): New function.
	(__tunable_set_val): New function.
	(__tunable_get_val): Call CB only if the tunable was externally
	initialized.
	(tunables_strtoul): Replace strval with initialized.
	* elf/dl-tunables.h (strval): Replace with a bool initialized.
	(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
	prevent collision.
	(__tunable_set_val): New function.
	(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
	(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
	(TUNABLE_SET_VAL): Remove.
	(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
	* README.tunables: Document the new macros.
	* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-07 11:11:36 +05:30
H.J. Lu d4cc385c6e x86-64: Move wcsnlen.S to multiarch/wcsnlen-sse4_1.S
Since wcsnlen.S uses pminud which is the part of SSE4.1, move wcsnlen.S
to multiarch/wcsnlen-sse4_1.S.

	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	wcsnlen-sse4_1 and wcsnlen-c.
	* sysdeps/x86_64/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Test __wcsnlen_sse4_1 and
	__wcsnlen_sse2.
	* sysdeps/x86_64/multiarch/ifunc-sse4_1.h: New file.
	* sysdeps/x86_64/multiarch/wcsnlen-c.c: Likewise.
	* sysdeps/x86_64/multiarch/wcsnlen-sse4_1.S: Likewise.
	* sysdeps/x86_64/multiarch/wcsnlen.c: Likewise.
	* sysdeps/x86_64/wcsnlen.S: Removed.
2017-06-06 06:12:32 -07:00
Stefan Liebler 4bf7abaeb3 S390: Use generic spinlock code.
This patch removes the s390 specific implementation of spinlock code
and is now using the generic one.

ChangeLog:

	* sysdeps/s390/nptl/pthread_spin_init.c: Delete File.
	* sysdeps/s390/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/s390/nptl/pthread_spin_trylock.c: Likewise.
	* sysdeps/s390/nptl/pthread_spin_unlock.c: Likewise.
2017-06-06 09:41:56 +02:00
Stefan Liebler 12d2dd7060 Optimize generic spinlock code and use C11 like atomic macros.
This patch optimizes the generic spinlock code.

The type pthread_spinlock_t is a typedef to volatile int on all archs.
Passing a volatile pointer to the atomic macros which are not mapped to the
C11 atomic builtins can lead to extra stores and loads to stack if such
a macro creates a temporary variable by using "__typeof (*(mem)) tmp;".
Thus, those macros which are used by spinlock code - atomic_exchange_acquire,
atomic_load_relaxed, atomic_compare_exchange_weak - have to be adjusted.
According to the comment from  Szabolcs Nagy, the type of a cast expression is
unqualified (see http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_423.htm):
__typeof ((__typeof (*(mem)) *(mem)) tmp;
Thus from spinlock perspective the variable tmp is of type int instead of
type volatile int.  This patch adjusts those macros in include/atomic.h.
With this construct GCC >= 5 omits the extra stores and loads.

The atomic macros are replaced by the C11 like atomic macros and thus
the code is aligned to it.  The pthread_spin_unlock implementation is now
using release memory order instead of sequentially consistent memory order.
The issue with passed volatile int pointers applies to the C11 like atomic
macros as well as the ones used before.

I've added a glibc_likely hint to the first atomic exchange in
pthread_spin_lock in order to return immediately to the caller if the lock is
free.  Without the hint, there is an additional jump if the lock is free.

I've added the atomic_spin_nop macro within the loop of plain reads.
The plain reads are also realized by C11 like atomic_load_relaxed macro.

The new define ATOMIC_EXCHANGE_USES_CAS determines if the first try to acquire
the spinlock in pthread_spin_lock or pthread_spin_trylock is an exchange
or a CAS.  This is defined in atomic-machine.h for all architectures.

The define SPIN_LOCK_READS_BETWEEN_CMPXCHG is now removed.
There is no technical reason for throwing in a CAS every now and then,
and so far we have no evidence that it can improve performance.
If that would be the case, we have to adjust other spin-waiting loops
elsewhere, too!  Using a CAS loop without plain reads is not a good idea
on many targets and wasn't used by one.  Thus there is now no option to
do so.

Architectures are now using the generic spinlock automatically if they
do not provide an own implementation.  Thus the pthread_spin_lock.c files
in sysdeps folder are deleted.

ChangeLog:

	* NEWS: Mention new spinlock implementation.
	* include/atomic.h:
	(__atomic_val_bysize): Cast type to omit volatile qualifier.
	(atomic_exchange_acq): Likewise.
	(atomic_load_relaxed): Likewise.
	(ATOMIC_EXCHANGE_USES_CAS): Check definition.
	* nptl/pthread_spin_init.c (pthread_spin_init):
	Use atomic_store_relaxed.
	* nptl/pthread_spin_lock.c (pthread_spin_lock):
	Use C11-like atomic macros.
	* nptl/pthread_spin_trylock.c (pthread_spin_trylock):
	Likewise.
	* nptl/pthread_spin_unlock.c (pthread_spin_unlock):
	Use atomic_store_release.
	* sysdeps/aarch64/nptl/pthread_spin_lock.c: Delete File.
	* sysdeps/arm/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/hppa/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/m68k/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/microblaze/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/mips/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/nios2/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/aarch64/atomic-machine.h (ATOMIC_EXCHANGE_USES_CAS): Define.
	* sysdeps/alpha/atomic-machine.h: Likewise.
	* sysdeps/arm/atomic-machine.h: Likewise.
	* sysdeps/i386/atomic-machine.h: Likewise.
	* sysdeps/ia64/atomic-machine.h: Likewise.
	* sysdeps/m68k/coldfire/atomic-machine.h: Likewise.
	* sysdeps/m68k/m680x0/m68020/atomic-machine.h: Likewise.
	* sysdeps/microblaze/atomic-machine.h: Likewise.
	* sysdeps/mips/atomic-machine.h: Likewise.
	* sysdeps/powerpc/powerpc32/atomic-machine.h: Likewise.
	* sysdeps/powerpc/powerpc64/atomic-machine.h: Likewise.
	* sysdeps/s390/atomic-machine.h: Likewise.
	* sysdeps/sparc/sparc32/atomic-machine.h: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/atomic-machine.h: Likewise.
	* sysdeps/sparc/sparc64/atomic-machine.h: Likewise.
	* sysdeps/tile/tilegx/atomic-machine.h: Likewise.
	* sysdeps/tile/tilepro/atomic-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/hppa/atomic-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/atomic-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/nios2/atomic-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/sh/atomic-machine.h: Likewise.
	* sysdeps/x86_64/atomic-machine.h: Likewise.
2017-06-06 09:41:56 +02:00
H.J. Lu 48e7bc7a55 x86: Don't use dl_x86_cpu_features in cacheinfo.c
Since cpu_features is available, use it instead of dl_x86_cpu_features.

	* sysdeps/x86/cacheinfo.c (intel_check_word): Accept cpu_features
	and use it instead of dl_x86_cpu_features.
	(handle_intel): Replace maxidx with cpu_features.  Pass
	cpu_features to intel_check_word.
	(__cache_sysconf): Pass cpu_features to handle_intel.
	(init_cacheinfo): Likewise.  Use cpu_features instead of
	dl_x86_cpu_features.
2017-06-05 16:20:11 -07:00
H.J. Lu 935971ba6b x86-64: Optimize memcmp/wmemcmp with AVX2 and MOVBE
Optimize x86-64 memcmp/wmemcmp with AVX2.  It uses vector compare as
much as possible.  It is as fast as SSE4 memcmp for size <= 16 bytes
and up to 2X faster for size > 16 bytes on Haswell and Skylake.  Select
AVX2 memcmp/wmemcmp on AVX2 machines where vzeroupper is preferred and
AVX unaligned load is fast.

NB: It uses TZCNT instead of BSF since TZCNT produces the same result
as BSF for non-zero input.  TZCNT is faster than BSF and is executed
as BSF if machine doesn't support TZCNT.

Key features:

1. For size from 2 to 7 bytes, load as big endian with movbe and bswap
   to avoid branches.
2. Use overlapping compare to avoid branch.
3. Use vector compare when size >= 4 bytes for memcmp or size >= 8
   bytes for wmemcmp.
4. If size is 8 * VEC_SIZE or less, unroll the loop.
5. Compare 4 * VEC_SIZE at a time with the aligned first memory area.
6. Use 2 vector compares when size is 2 * VEC_SIZE or less.
7. Use 4 vector compares when size is 4 * VEC_SIZE or less.
8. Use 8 vector compares when size is 8 * VEC_SIZE or less.

	* sysdeps/x86/cpu-features.h (index_cpu_MOVBE): New.
	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	memcmp-avx2 and wmemcmp-avx2.
	* sysdeps/x86_64/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Test __memcmp_avx2 and __wmemcmp_avx2.
	* sysdeps/x86_64/multiarch/memcmp-avx2.S: New file.
	* sysdeps/x86_64/multiarch/wmemcmp-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/memcmp.S: Use __memcmp_avx2 on AVX
	2 machines if AVX unaligned load is fast and vzeroupper is
	preferred.
	* sysdeps/x86_64/multiarch/wmemcmp.S: Use __wmemcmp_avx2 on AVX
	2 machines if AVX unaligned load is fast and vzeroupper is
	preferred.
2017-06-05 12:52:55 -07:00
H.J. Lu ef9c4cb6c7 x86-64: Optimize wmemset with SSE2/AVX2/AVX512
The difference between memset and wmemset is byte vs int.  Add stubs
to SSE2/AVX2/AVX512 memset for wmemset with updated constant and size:

SSE2 wmemset:
	shl    $0x2,%rdx
	movd   %esi,%xmm0
	mov    %rdi,%rax
	pshufd $0x0,%xmm0,%xmm0
	jmp	entry_from_wmemset

SSE2 memset:
	movd   %esi,%xmm0
	mov    %rdi,%rax
	punpcklbw %xmm0,%xmm0
	punpcklwd %xmm0,%xmm0
	pshufd $0x0,%xmm0,%xmm0
entry_from_wmemset:

Since the ERMS versions of wmemset requires "rep stosl" instead of
"rep stosb", only the vector store stubs of SSE2/AVX2/AVX512 wmemset
are added.  The SSE2 wmemset is about 3X faster and the AVX2 wmemset
is about 6X faster on Haswell.

	* include/wchar.h (__wmemset_chk): New.
	* sysdeps/x86_64/memset.S (VDUP_TO_VEC0_AND_SET_RETURN): Renamed
	to MEMSET_VDUP_TO_VEC0_AND_SET_RETURN.
	(WMEMSET_VDUP_TO_VEC0_AND_SET_RETURN): New.
	(WMEMSET_CHK_SYMBOL): Likewise.
	(WMEMSET_SYMBOL): Likewise.
	(__wmemset): Add hidden definition.
	(wmemset): Add weak hidden definition.
	* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
	wmemset_chk-nonshared.
	* sysdeps/x86_64/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add __wmemset_sse2_unaligned,
	__wmemset_avx2_unaligned, __wmemset_avx512_unaligned,
	__wmemset_chk_sse2_unaligned, __wmemset_chk_avx2_unaligned
	and __wmemset_chk_avx512_unaligned.
	* sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms.S
	(VDUP_TO_VEC0_AND_SET_RETURN): Renamed to ...
	(MEMSET_VDUP_TO_VEC0_AND_SET_RETURN): This.
	(WMEMSET_VDUP_TO_VEC0_AND_SET_RETURN): New.
	(WMEMSET_SYMBOL): Likewise.
	* sysdeps/x86_64/multiarch/memset-avx512-unaligned-erms.S
	(VDUP_TO_VEC0_AND_SET_RETURN): Renamed to ...
	(MEMSET_VDUP_TO_VEC0_AND_SET_RETURN): This.
	(WMEMSET_VDUP_TO_VEC0_AND_SET_RETURN): New.
	(WMEMSET_SYMBOL): Likewise.
	* sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S: Updated.
	(WMEMSET_CHK_SYMBOL): New.
	(WMEMSET_CHK_SYMBOL (__wmemset_chk, unaligned)): Likewise.
	(WMEMSET_SYMBOL (__wmemset, unaligned)): Likewise.
	* sysdeps/x86_64/multiarch/memset.S (WMEMSET_SYMBOL): New.
	(libc_hidden_builtin_def): Also define __GI_wmemset and
	__GI___wmemset.
	(weak_alias): New.
	* sysdeps/x86_64/multiarch/wmemset.c: New file.
	* sysdeps/x86_64/multiarch/wmemset.h: Likewise.
	* sysdeps/x86_64/multiarch/wmemset_chk-nonshared.S: Likewise.
	* sysdeps/x86_64/multiarch/wmemset_chk.c: Likewise.
	* sysdeps/x86_64/wmemset.c: Likewise.
	* sysdeps/x86_64/wmemset_chk.c: Likewise.
2017-06-05 11:09:59 -07:00
H.J. Lu 9cd30491dd x86: Add macros to implement ifunce selection in C
These macros are used to implement ifunc selection in C.  To implement
an ifunc function, foo, which returns the address of __foo_sse2 or
__foo_avx2:

   __foo_avx2:

   #define foo __redirect_foo
   #define __foo __redirect___foo
   #include <foo.h>
   #undef foo
   #undef __foo
   #define SYMBOL_NAME foo
   #include <init-arch.h>

   extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
   extern __typeof (REDIRECT_NAME) OPTIMIZE (avx2) attribute_hidden;

   static inline void *
   foo_selector (void)
   {
     if (use AVX2)
      return OPTIMIZE (avx2);

     return OPTIMIZE (sse2);
   }

   libc_ifunc_redirected (__redirect_foo, foo, foo_selector ());

	* sysdeps/x86/init-arch.h (PASTER1): New.
	(EVALUATOR1): Likewise.
	(PASTER2): Likewise.
	(EVALUATOR2): Likewise.
	(REDIRECT_NAME): Likewise.
	(OPTIMIZE): Likewise.
	(IFUNC_SELECTOR): Likewise.
2017-06-05 08:28:13 -07:00
H.J. Lu 30cb625a21 x86-64: Update strlen.S to support wcslen/wcsnlen
The difference between strlen and wcslen is byte vs int.  We can
replace pminub and pcmpeqb with pminud and pcmpeqd to turn strlen
into wcslen.

	* sysdeps/x86_64/strlen.S (PMINU): New.
	(PCMPEQ): Likewise.
	(SHIFT_RETURN): Likewise.
	(FIND_ZERO): Replace pcmpeqb with PCMPEQ.
	(strlen): Add SHIFT_RETURN before ret.  Replace pcmpeqb and
	pminub with PCMPEQ and PMINU.
	* sysdeps/x86_64/wcsnlen.S: New file.
2017-06-05 07:58:23 -07:00
H.J. Lu 7395928b95 x86_64: Remove redundant REX bytes from memrchr.S
By x86-64 specification, 32-bit destination registers are zero-extended
to 64 bits.  There is no need to use 64-bit registers when only the lower
32 bits are non-zero.  Also 2 instructions in:

	mov	%rdi, %rcx
	and	$15, %rcx
	jz	L(length_less16_offset0)

	mov	%rdi, %rcx		<<< redundant
	and	$15, %rcx		<<< redundant

are redundant.

	* sysdeps/x86_64/memrchr.S (__memrchr): Use 32-bit registers for
	the lower 32 bits.  Remove redundant instructions.
2017-06-05 07:41:26 -07:00
H.J. Lu d8a7d10324 x86-64: Update LO_HI_LONG for p{readv,writev}{64}v2
The kernel interface for p{readv,writev}{64}v is

(unsigned long fd, {const }struct iovec *iov, unsigned long vlen,
 unsigned long pos_l, unsigned long pos_h)

Except for targets which define __ARCH_WANT_COMPAT_SYS_PREADV64 and
__ARCH_WANT_COMPAT_SYS_PWRITEV64,

(unsigned long fd, {const }struct iovec *iov, unsigned long vlen,
 off64_t pos)

is used for p{readv,writev}{64}v.  X32 is the only such target.  The
LO_HI_LONG macro is used to pass offset to the pos_l and pos_h pair.
Since pos_h is ignored when size of offset == sizeof of pos_l, x86-64
has

 #define LO_HI_LONG(val) (val)

But the kernel interface for p{readv,writev}{64}v2 is

(unsigned long fd, {const }struct iovec *iov, unsigned long vlen,
 unsigned long pos_l, unsigned long pos_h, int flags)

Except for targets which define __ARCH_WANT_COMPAT_SYS_PREADV64V2 and
__ARCH_WANT_COMPAT_SYS_PWRITEV64V2,

(unsigned long fd, {const }struct iovec *iov, unsigned long vlen,
 off64_t pos, int flags)

is used for p{readv,writev}{64}v2.  X32 is the only such target.  Update
x86-64 LO_HI_LONG to pass 0 as the high part of the offset argument for
p{readv,writev}{64}v2 and define a different LO_HI_LONG for x32 to only
pass one argument for offset.

Tested on x32 and x86-64.

	* sysdeps/unix/sysv/linux/x86_64/sysdep.h (LO_HI_LONG): Pass
	0 as the high part of offset.
	* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (LO_HI_LONG): New.
2017-06-05 07:21:57 -07:00
Joseph Myers c4c96f92f7 Define SIG_HOLD for XPG4 (bug 21538).
Various bits/signum.h headers define SIG_HOLD if __USE_UNIX98.  That
should be __USE_XOPEN, as this macro is in XPG4.  This patch fixes the
conditionals accordingly.  Because of other header bugs, this does not
allow any XFAILs to be removed (however, the XPG4/signal.h/conform
XFAIL only depends on a few such straightforward header bugs, not on
the more complicated to fix ucontext_t issues, as ucontext_t isn't
included in signal.h in XPG4).

Tested for x86_64.

	[BZ #21538]
	* bits/signum.h (SIG_HOLD): Define if [__USE_XOPEN], not
	[__USE_UNIX98].
	* sysdeps/unix/bsd/bits/signum.h (SIG_HOLD): Likewise.
	* sysdeps/unix/sysv/linux/alpha/bits/signum.h (SIG_HOLD):
	Likewise.
	* sysdeps/unix/sysv/linux/bits/signum.h (SIG_HOLD): Likewise.
	* sysdeps/unix/sysv/linux/hppa/bits/signum.h (SIG_HOLD): Likewise.
	* sysdeps/unix/sysv/linux/mips/bits/signum.h (SIG_HOLD): Likewise.
	* sysdeps/unix/sysv/linux/sparc/bits/signum.h (SIG_HOLD):
	Likewise.
2017-06-05 10:19:03 +00:00
Joseph Myers 7553131847 Fix struct sigaltstack namespace (bug 21517).
glibc defines the stack_t type with the tag struct sigaltstack.  This
is not permitted by POSIX; sigaltstack is only reserved with file
scope in the namespace of ordinary identifiers, not the tag namespace,
and in the case where stack_t is obtained from ucontext.h rather than
signal.h, it's not reserved with file scope at all.

This patch removes the tag accordingly and updates uses in glibc of
struct sigaltstack.  This is similar to the removal of the "struct
siginfo" tag a few years ago: C++ name mangling changes are an
unavoidable consequence.  A NEWS item is added to note the changed
mangling.  There is inevitably some risk of breaking builds of
anything that relies on the struct sigaltstack name (though the first
few hits I looked at from codesearch.debian.net generally seemed to
involve code that could use the stack_t name conditionally, so
depending on how they determine the conditionals they may work with
glibc not defining the struct tag anyway).

Tested for x86_64 and x86, and with build-many-glibcs.py.

	[BZ #21517]
	* bits/types/stack_t.h (stack_t): Remove struct tag.
	* sysdeps/unix/sysv/linux/bits/types/stack_t.h (stack_t):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h (stack_t):
	Likewise.
	* debug/segfault.c (install_handler): Use stack_t instead of
	struct sigaltstack.
	* hurd/hurd/signal.h (struct hurd_sigstate): Likewise.
	* hurd/trampoline.c (_hurd_setup_sighandler): Likewise.
	* include/signal.h (__sigaltstack): Likwise.
	* signal/sigaltstack.c (__sigaltstack): Likewise.
	* signal/signal.h (sigaltstack): Likewise.
	* sysdeps/mach/hurd/i386/signal-defines.sym
	(SIGALTSTACK__SS_SP__OFFSET): Likewise.
	(SIGALTSTACK__SS_SIZE__OFFSET): Likewise.
	(SIGALTSTACK__SS_FLAGS__OFFSET): Likewise.
	* sysdeps/mach/hurd/sigaltstack.c (__sigaltstack): Likewise.
	* sysdeps/mach/hurd/sigstack.c (sigstack): Likewise.
	* sysdeps/unix/sysv/linux/alpha/sys/procfs.h (struct
	elf_prstatus): Likewise.
	* sysdeps/unix/sysv/linux/hppa/____longjmp_chk.c (CHECK_SP):
	Likewise.
	* sysdeps/unix/sysv/linux/ia64/sys/procfs.h (struct elf_prstatus):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/____longjmp_chk.c (CHECK_SP):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sys/procfs.h (struct
	elf_prstatus): Likewise.
	* sysdeps/unix/sysv/linux/sh/sys/procfs.h (struct elf_prstatus):
	Likewise.
	* sysdeps/unix/sysv/linux/sys/procfs.h (struct elf_prstatus):
	Likewise.
2017-06-05 10:17:46 +00:00
Zack Weinberg 8951dd0b14 Regenerate sysdeps/gnu/errlist.c.
This file needs to be regenerated whenever errno.texi changes.
2017-06-04 15:27:14 -04:00
H.J. Lu 6b69f98dcd benchtests: Add more tests for memrchr
bench-memchr.c is shared with bench-memrchr.c.  This patch adds some
tests for positions close to the beginning for memrchr, which are
equivalent to positions close to the end for memchr.

	* benchtests/bench-memchr.c (do_test): Print out both length
	and position.
	(test_main): Also test the position close to the beginning for
	memrchr.
2017-06-04 09:45:09 -07:00
Zack Weinberg d36c52becb Add forgotten changelog entry for 82f43dd2d1 2017-06-04 11:34:14 -04:00
Florian Weimer 363911ce13 getaddrinfo: Eliminate another strdup call 2017-06-03 08:37:31 +02:00
H.J. Lu 808fd9e6fe x86: Update __x86_shared_non_temporal_threshold
__x86_shared_non_temporal_threshold was set to 6 times of per-core
shared cache size, based on the large memcpy micro benchmark in glibc
on a 8-core processor.  For a processor with more than 8 cores, the
threshold is too low.  Set __x86_shared_non_temporal_threshold to the
3/4 of the total shared cache size so that it is unchanged on 8-core
processors.  On processors with less than 8 cores, the threshold is
lower.

	* sysdeps/x86/cacheinfo.c (__x86_shared_non_temporal_threshold):
	Set to the 3/4 of the total shared cache size.
2017-06-02 17:32:37 -07:00
Rical Jasan 3e6def237a manual: Provide consistent errno documentation.
The @errno macro is extended to render the canonical error string in
every documented errno error.  Redundant entries and "???" are
removed.  Sixty-six errors now at least contain the error string as
the description, where no description (or "???") existed before.

	* manual/errno.texi: Remove redundant error strings.
	* manual/macros.texi (@errno): Render the error string in
	every description.
2017-06-02 13:49:20 -07:00
Joseph Myers 9c65eec494 Fix sigevent namespace (bug 21543).
signal.h defines the sigevent structure and constants if defined
__USE_POSIX199309 || defined __USE_XOPEN_EXTENDED.  The
__USE_XOPEN_EXTENDED condition is incorrect; this structure does not
appear in XSI standards before Unix98 (which implies
__USE_POSIX199309).  This patch fixes the conditionals accordingly
(the existing conditional is correct for siginfo_t, just not for
sigevent).

Tested for x86_64.  This does not allow any conform/ XFAILs to be
removed because of other signal.h namespace bugs.

	[BZ #21543]
	* signal/signal.h: Only include <bits/types/sigevent_t.h> and
	<bits/sigevent-consts.h> if [__USE_POSIX199309], not if
	[__USE_XOPEN_EXTENDED].
2017-06-02 19:47:03 +00:00
Florian Weimer 6257fcfd58 getaddrinfo: Fix localplt failure involving strdup 2017-06-02 16:35:13 +02:00
Adhemerval Zanella ca4b396ebe posix: Add missing build flags for p{write,read}v2
This patch adds the missing compiler flags for correct pthread cancellation
on some architectures for the p{read,write}v2 implementation (52bd938169).

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

	* misc/Makefile (CFLAGS-preadv2.c): New rule.
	(CFLAGS-preadv64v2.c): Likewise.
	(CFLAGS-pwritev2.c): Likewise.
	(CFLAGS-pwritev64v2.c): Likewise.
2017-06-02 11:12:29 -03:00
Florian Weimer 2714c5f3c9 resolv: Tests for various versions of res_init 2017-06-02 15:50:36 +02:00
Florian Weimer 673cb072a4 getaddrinfo: Always allocate canonical name on the heap
A further simplification could eliminate the canon variable in
gaih_inet and replace it with canonbuf.  However, canonbuf is
used as a flag in the nscd code, which makes this somewhat
non-straightforward.
2017-06-02 14:54:56 +02:00
Florian Weimer 91b6eb1140 Add internal facility for dynamic array handling
This is intended as a type-safe alternative to obstacks and
hand-written realloc constructs.  The implementation avoids
writing function pointers to the heap.
2017-06-02 11:59:28 +02:00
Gabriel F. T. Gomes 09103e4025 Include sys/param.h in stdlib/gmp-impl.h instead of redefining MAX/MIN
In stdlib/gmp-impl.h, the macros MAX and MIN are defined exactly the same
as in sys/param.h.  This patch removes the redefinition and makes
gmp-impl.h include sys/param.h instead.

Tested for powerpc64le and s390x.

	* stdlib/gmp-impl.h: Include sys/param.h instead of redefining the
	macros MAX and MIN.
2017-06-01 20:44:22 -03:00
Joseph Myers 6da85a0daf conformtest: Correct signal.h expectations for XPG4 / XPG42.
Various of the signal.h conform/ failures for XPG4 and XPG42 are
actually the result of incorrect test expectations rather than header
bugs.  This patch fixes the expectations to accord with those
standards (this does not however allow any XFAILs to be removed, as
some header bugs remain).  Note for anyone comparing with the
standards: corrigendum U013/16 removes the mention of a sigmask
function in signal.h (C435 lists such a function in the definition of
signal.h, but without any actual specification for the function
itself), so sigmask is not included in the expectations.

Tested for x86_64.

	* conform/data/signal.h-data (sa_sigaction): Do not expect for
	[XPG4].
	(SA_SIGINFO): Likewise.
	(SA_ONSTACK): Likewise.
	(SA_RESETHAND): Likewise.
	(SA_RESTART): Likewise.
	(SA_NOCLDWAIT): Likewise.
	(SA_NODEFER): Likewise.
	(SS_ONSTACK): Likewise.
	(SS_DISABLE): Likewise.
	(MINSIGSTKSZ): Likewise.
	(SIGSTKSZ): Likewise.
	(ucontext_t): Likewise.
	(stack_t): Likewise.
	(struct sigstack): Likewise.
	(SI_USER): Do not expect for [XPG4 || XPG42].
	(SI_QUEUE): Likewise.
	(SI_TIMER): Likewise.
	(SI_ASYNCIO): Likewise.
	(SI_MESGQ): Likewise.
	(bsd_signal): Do not expect for [XPG4].
	(killpg): Likewise.
	(sigaltstack): Likewise.
	(sighold): Likewise.
	(sigignore): Likewise.
	(siginterrupt): Likewise.
	(sigpause): Likewise.
	(sigrelse): Likewise.
	(sigset): Likewise.
	(sigwait): Do not expect for [XPG4 || XPG42].
2017-06-01 17:17:43 +00:00
Zack Weinberg 72b81552a1 Add shim header for bits/syscall.h.
On Linux-based configurations, bits/syscall.h is a generated file.
To avoid build-ordering problems, the Linux sys/syscall.h only includes
bits/syscall.h if _LIBC is not defined.  After the _ISOMAC-testsuite
changes, this means any test case that includes sys/syscall.h tries to
pull in bits/syscall.h.  This would be fine, because it'll definitely
have been generated by the time we start compiling tests, except that
the generated <builddir>/misc/bits/syscall.h is not visible in the
include path, because nothing needed it till now.  So we either get
the bits/syscall.h from the host system, or the build fails.

The fix is simple: add a shim header for bits/syscall.h.  I put it in
sysdeps/unix/sysv/linux/include instead of the top-level include/
because bits/syscall.h doesn't exist at all on other configurations as
far as I can tell.

This is known to affect nptl/tst-cond2[45].  Thanks to John David
Anglin for noticing the problem.

	[BZ #21514]
	* sysdeps/unix/sysv/linux/include/bits/syscall.h: New shim header
	pointing to the generated file in <builddir>/misc/bits/syscall.h.
2017-06-01 10:56:10 -04:00
Joseph Myers 139904b7e4 Fix more namespace issues in sys/ucontext.h (bug 21457).
Continuing the fixes for namespace issues in sys/ucontext.h, this
patch moves various symbols into the implementation namespace in the
absence of __USE_MISC.  As with previous changes, it is nonexhaustive,
just covering more straightforward cases.

Structure fields are generally changed to have a prefix __ in the
absence of __USE_MISC, via a macro __ctx (used without a space before
the open parenthesis, since the result is a single identifier).
Various macros such as NGREG also have leading __ added.  No changes
are made to structure tags (and thus to C++ name mangling), except
that in the (unused) file sysdeps/i386/sys/ucontext.h, structures
defined inside other structures as the type for a field have their
tags removed in the non-__USE_MISC case (those structure tags would
not in any case have been visible in C++, because in C++ the scope of
such a tag is limited to the containing structure).  No changes are
made to the contents of bits/sigcontext.h, or to whether it is
included.  Because of remaining namespace issues, this patch does not
yet fix the bug or allow any XFAILs to be removed.

Tested for x86_64 and x86, and with build-many-glibcs.py.

	[BZ #21457]
	* sysdeps/arm/sys/ucontext.h (NGREG): Rename to __NGREG and define
	NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(mcontext_t): Use __ctx in defining fields.
	* sysdeps/i386/sys/ucontext.h (NGREG): Rename to __NGREG and
	define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(__ctxt): Likewise.
	(fpregset_t): Use __ctx and __ctxt in defining fields.
	(mcontext_t): Likewise.
	* sysdeps/m68k/sys/ucontext.h (NGREG): Rename to __NGREG and
	define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(mcontext_t): Use __ctx in defining fields.
	* sysdeps/mips/sys/ucontext.h (NGREG): Rename to __NGREG and
	define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(fpregset_t): Use __ctx in defining fields.
	(mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/alpha/sys/ucontext.h (NGREG): Rename to
	__NGREG and define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(NFPREG): Rename to __NFPREG and define NFPREG to __NFPREG if
	[__USE_MISC].
	(fpregset_t): Define using __NFPREG.
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h (NGREG): Rename to
	__NGREG and define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(fpregset_t): Use __ctx in defining fields.
	(mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h (NGREG): Rename to
	__NGREG and define NGREG to __NGREG if [__USE_MISC].
	(NFPREG): Rename to __NFPREG and define NFPREG to __NFPREG if
	[__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(fpregset_t): Use __ctx in defining fields.
	(mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h (__ctx): New macro.
	(mcontext_t): Use __ctx in defining fields.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h (__ctx): New
	macro.
	[__WORDSIZE == 32] (NGREG): Rename to __NGREG and define NGREG to
	__NGREG if [__USE_MISC].
	[__WORDSIZE == 32] (gregset_t): Define using __NGREG.
	[__WORDSIZE == 32] (fpregset_t): Use __ctx in defining fields.
	(mcontext_t): Likewise.
	[__WORDSIZE != 32] (NGREG): Rename to __NGREG and define NGREG to
	__NGREG if [__USE_MISC].
	[__WORDSIZE != 32] (NFPREG): Rename to __NFPREG and define NFPREG
	to __NFPREG if [__USE_MISC].
	[__WORDSIZE != 32] (NVRREG): Rename to __NVRREG and define NVRREG
	to __NVRREG if [__USE_MISC].
	[__WORDSIZE != 32] (gregset_t): Define using __NGREG.
	[__WORDSIZE != 32] (fpregset_t): Define using __NFPREG.
	[__WORDSIZE != 32] (vscr_t): Use __ctx in defining fields.
	[__WORDSIZE != 32] (vrregset_t): Likewise.
	[__WORDSIZE != 32] (mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h (__ctx): New macro.
	(__psw_t): Use __ctx in defining fields.
	(NGREG): Rename to __NGREG and define NGREG to __NGREG if
	[__USE_MISC].
	(gregset_t): Define using __NGREG.
	(fpreg_t): Use __ctx in defining fields.
	(fpregset_t): Likewise.
	(mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h (NGREG): Rename to
	__NGREG and define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(NFPREG): Rename to __NFPREG and define NFPREG to __NFPREG if
	[__USE_MISC].
	(fpregset_t): Define using __NFPREG.
	(__ctx): New macro.
	(mcontext_t): Use __ctx in defining fields.
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h (__ctx): New macro.
	[__x86_64__] (NGREG): Rename to __NGREG and define NGREG to
	__NGREG if [__USE_MISC].
	[__x86_64__] (gregset_t): Define using __NGREG.
	[__x86_64__] (struct _libc_fpxreg): Use __ctx in defining fields.
	[__x86_64__] (struct _libc_fpstate): Likewise.
	[__x86_64__] (mcontext_t): Likewise.
	[!__x86_64__] (NGREG): Rename to __NGREG and define NGREG to
	__NGREG if [__USE_MISC].
	[!__x86_64__] (gregset_t): Define using __NGREG.
	[!__x86_64__] (struct _libc_fpreg): Use __ctx in defining fields.
	[!__x86_64__] (struct _libc_fpstate): Likewise.
	[!__x86_64__] (mcontext_t): Likewise.
2017-06-01 14:07:40 +00:00
Zack Weinberg 491bb0858e Avoid tickling a linker bug from microblaze pt-vfork.S.
libpthread used to have its own vfork implementation that differed
from libc's only in having a pointless micro-optimization.  There is
no longer any use to having a separate copy in libpthread, but the
historical ABI requires a compatibility shim.  microblaze was trying
to be slightly too clever about how it did this, and tickled a linker
bug.  The linker bug should get fixed eventually, but there's no
reason for us to keep tickling it in the meantime.

This doesn't reuse the generic pt-vfork.c because microblaze doesn't
have IFUNC support yet, and it doesn't reuse aarch64/pt-vfork.c
because that fails to generate a tailcall (with GCC 7.1.1).

	* sysdeps/unix/sysv/linux/microblaze/pt-vfork.S: Don't include
	alpha/pt-vfork.S.  Provide own compat shim for vfork and __vfork.
	* sysdeps/unix/sysv/linux/microblaze/vfork.S: Add __libc_vfork alias.
	* sysdeps/unix/sysv/linux/microblaze/localplt.data:
	libpthread.so no longer references __errno_location.
2017-06-01 08:53:56 -04:00
Adhemerval Zanella 52bd938169 posix: Implement preadv2 and pwritev2
This patch adds support of preadv2 and pwritev2 which are similar to
preadv/pwritev but with an extra flag argument.  As for preadv/pwritev
both interfaces are added a non-standard GNU API.

For default 'posix' implementation trying to emulate the Linux supported
flags is troublesome:

   * We can not temporary change the file state of the O_DSYNC and O_SYNC
     flags to emulate RWF_{D}SYNC (attempts to change the state of using
     fcntl are silently ignored).

   * IOCB_HIPRI requires the file opened in O_DIRECT and uses an internal
     semantic not provided by any other flag (O_NONBLOCK for instance).

So default sysdeps/posix implementations fails with EOPNOTSUPP for any non
supported flag (which are none currently) calls generic preadv/pwritev.
Basically this implementation supports only preadv2 called as preadv (with
flags sets to 0).

The Linux one uses the preadv2/pwritev2 syscall if defined, otherwise it
call preadv/writev.  Instead of using the previous __ASSUME_* to
unconditionally issue the syscall (and avoid building the fallback routine),
it call pread/write if the preadv2/pwritev2 syscalls fails.  The idea
is just avoid adding another __ASSUME_* and checking each architecture
on every kernel bump and simplify code conditionals.

Checked on x86_64-linux-gnu and on i686-linux-gnu and a check with
run-built-tests=no on aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
ia64-linux-gnu, m68k-linux-gnu, microblaze-linux-gnu, mips{64,64n32}-linux-gnu,
nios2-linux-gnu, powerpc{64,64le}-linux-gnu, s390{x}-linux-gnu,
sparc{64,v9}-linux-gnu, tile{gx,pro}-linux-gnu, and sh4-linux-gnu (all using
gcc 6.3).

	* NEWS: Add note about pwritev2 and preadv2 inclusion.
	* misc/Makefile (routines): Add preadv2, preadv64v2, pwritev2, and
	pwritev64v2.
	(tests): Add tst-preadvwritev2 and tst-preadvwritev64v2.
	* misc/Versions (GLIBC_2.26): Add preadv2, preadv64v2, pwritev2, and
	pwritev64v2.
	* misc/preadv2.c: New file.
	* misc/preadv64v2.c: Likewise.
	* misc/pwritev2.c: Likewise.
	* misc/pwritev64v2.c: Likewise.
	* misc/tst-preadvwritev2.c: Likewise.
	* misc/tst-preadvwritev64v2.c: Likewise.
	* manual/llio.texi: Add preadv2 and pwritev2 documentation.
	* misc/sys/uio.h [__USE_GNU && !__USE_FILE_OFFSET64] (preadv2): New
	prototype.
	[__USE_GNU && !__USE_FILE_OFFSET64] (pwritev2):	Likewise.
	[__USE_GNU && __USE_FILE_OFFSET64] (preadv64v2): Likewise.
	[__USE_GNU && __USE_FILE_OFFSET64] (pwritev64v2): Likewise.
	* misc/tst-preadvwritev-common.c (PREADV): Define if not defined.
	(PWRITEV): Likewise.
	(do_test_with_offset): Use PREADV and PWRITEV macros and check for
	ENOSYS.
	* nptl/tst-cancel4.c (tf_pwritev2): New test.
	(tf_preadv2): Likewise.
	(tf_fsync): Add tf_pwritev2 and tf_preadv2.
	* sysdeps/posix/preadv2.c: Likewise.
	* sysdeps/posix/preadv64v2.c: Likewise.
	* sysdeps/posix/pwritev2.c: Likewise.
	* sysdeps/posix/pwritev64v2.c: Likewise.
	* sysdeps/unix/sysv/linux/kernel-features.h: Add comment for syscall
	support in kernel.
	* sysdeps/unix/sysv/linux/preadv2.c: Likewise.
	* sysdeps/unix/sysv/linux/preadv64v2.c: Likewise.
	* sysdeps/unix/sysv/linux/pwritev2.c: Likewise.
	* sysdeps/unix/sysv/linux/pwritev64v2.c: Likewise.
	* sysdeps/unix/sysv/linux/preadv.c (preadv): Add libc_hidden_def.
	* sysdeps/unix/sysv/linux/preadv64.c (preadv64): Likewise.
	* sysdeps/unix/sysv/linux/pwritev.c (pwritev): Likewise.
	* sysdeps/unix/sysv/linux/pwritev64.c (pwritev64): Likewise.
	* sysdeps/unix/sysv/linux/bits/uio.h: Add supported preadv2/pwritev2
	support flags on Linux.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist (GLIBC_2.26): Add
	preadv2, preadv64v2, pwritev2, pwritev64v2.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
	(GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
	(GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
	(GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/sysv/linux/tile/tilegx/tilegx32/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/sysv/linux/tile/tilegx/tilegx64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist (GLIBC_2.26):
	Likewise.
2017-05-31 17:35:46 -03:00
Andreas Schwab cfa9bb61cd Use test-driver in nptl/tst-fork3.c 2017-05-31 09:45:38 +02:00
Siddhesh Poyarekar 4158ba082c Delay initialization of CPU features struct in static binaries
Allow the CPU features structure set up to be overridden by tunables
by delaying it to until after tunables are initialized.  The
initialization is already delayed in dynamically linked glibc, it is
only in static binaries that the initialization is set early to allow
it to influence IFUNC relocations that happen in libc-start.  It is a
bit too early however and there is a good place between tunables
initialization and IFUNC relocations where this can be done.

Verified that this does not regress the testsuite.

	* csu/libc-start.c [!ARCH_INIT_CPU_FEATURES]: Define
	ARCH_INIT_CPU_FEATURES.
	(LIBC_START_MAIN): Call it.
	* sysdeps/unix/sysv/linux/aarch64/libc-start.c
	(__libc_start_main): Remove.
	(ARCH_INIT_CPU_FEATURES): New macro.
	* sysdeps/x86/libc-start.c (__libc_start_main): Remove.
	(ARCH_INIT_CPU_FEATURES): New macro.
2017-05-31 06:38:33 +05:30
Dennis Wölfing 2e0bbbfbf9 Add reallocarray function
The reallocarray function is an extension from OpenBSD.  It is an
integer-overflow-safe replacement for realloc(p, X*Y) and
malloc(X*Y) (realloc(NULL, X*Y)).  It can therefore help in preventing
certain security issues in code.

This is an updated version of a patch originally submitted by Rüdiger
Sonderfeld in May 2014 [1].

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

[1] <https://sourceware.org/ml/libc-alpha/2014-05/msg00481.html>.

2017-05-30  Dennis Wölfing  <denniswoelfing@gmx.de>
            Rüdiger Sonderfeld  <ruediger@c-plusplus.de>

	* include/stdlib.h (__libc_reallocarray): New declaration.
	* malloc/Makefile (routines): Add reallocarray.
	(tests): Add tst-reallocarray.c.
	* malloc/Versions: Add reallocarray and __libc_reallocarray.
	* malloc/malloc-internal.h (check_mul_overflow_size_t): New inline
	function.
	* malloc/malloc.h (reallocarray): New declaration.
	* stdlib/stdlib.h (reallocarray): Likewise.
	* malloc/reallocarray.c: New file.
	* malloc/tst-reallocarray.c: New test file.
	* manual/memory.texi: Document reallocarray.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add reallocarray.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tilepro/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
2017-05-30 18:27:57 -03:00
H.J. Lu 4f26ef1b67 x86_64: Remove redundant REX bytes from memchr.S
By x86-64 specification, 32-bit destination registers are zero-extended
to 64 bits.  There is no need to use 64-bit registers when only the lower
32 bits are non-zero.

	* sysdeps/x86_64/memchr.S (MEMCHR): Use 32-bit registers for
	the lower 32 bits.
2017-05-30 12:39:14 -07:00
Andreas Schwab 542a34783c m68k: handle default PIE 2017-05-29 08:41:50 +02:00
H.J. Lu acf6d579e0 Add memchr tests for n == 0
* string/test-memchr.c (test_main): Add tests for n == 0.
2017-05-25 11:38:01 -07:00
Tulio Magno Quites Machado Filho 6e75b0110d Move tst-mutex*8* to tests-internal
The following tests depend on ENABLE_LOCK_ELISION, which is only
available on tests-internal.

 - nptl/tst-mutex8
 - nptl/tst-mutex8-static
 - nptl/tst-mutexpi8
 - nptl/tst-mutexpi8-static

	* nptl/Makefile (tests): Move nptl/tst-mutex8, nptl/tst-mutex8-static,
	nptl/tst-mutexpi8 and nptl/tst-mutexpi8-static to...
	(tests-internal): ... here.
2017-05-25 14:53:40 -03:00
H.J. Lu 81efada528 Make __tunables_init hidden and avoid PLT
Since __tunables_init is internal to ld.so, we should mark it hidden
to avoid PLT.  We should also avoid PLT when calling __tunable_set_val
within ld.so.

2017-05-25   Siddhesh Poyarekar  <siddhesh@sourceware.org>
	     H.J. Lu  <hongjiu.lu@intel.com>

	* elf/dl-tunables.c (__tunable_set_val): Make a hidden alias.
	* elf/dl-tunables.h (__tunables_init): Mark it hidden in rtld.
	(__tunable_set_val): Likewise.
2017-05-25 06:55:58 -07:00
H.J. Lu ee8015b9ea Support dl-tunables.list in subdirectories
We can put processor specific tunables in dl-tunables.list under
sysdeps instead of in elf/dl-tunables.list.

	* Makeconfig ($(common-objpfx)dl-tunable-list.h): Also check
	dl-tunables.list in subdirectories.
2017-05-25 05:41:18 -07:00
Paul E. Murphy 302bb1a3c3 float128: Add wrappers to override ldbl-128 as float128.
This change defines float128_private.h which contains
macros used to override long double naming conventions
when building a ldbl file.

	* math/math.h [__HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)]
	(SNANF128): New macro.
	* math/e_sqrtf128.c: New file.
	* math/s_fmaxmag_template.c: Include math_private.h in order to
	make inline expansion of fabs128().
	* math/s_fminmag_template.c: Likewise.

	* sysdeps/ieee754/float128/e_acosf128.c: New file.
	* sysdeps/ieee754/float128/e_acoshf128.c: New file.
	* sysdeps/ieee754/float128/e_asinf128.c: New file.
	* sysdeps/ieee754/float128/e_atan2f128.c: New file.
	* sysdeps/ieee754/float128/e_atanhf128.c: New file.
	* sysdeps/ieee754/float128/e_coshf128.c: New file.
	* sysdeps/ieee754/float128/e_exp10f128.c: New file.
	* sysdeps/ieee754/float128/e_expf128.c: New file.
	* sysdeps/ieee754/float128/e_fmodf128.c: New file.
	* sysdeps/ieee754/float128/e_gammaf128_r.c: New file.
	* sysdeps/ieee754/float128/e_hypotf128.c: New file.
	* sysdeps/ieee754/float128/e_ilogbf128.c: New file.
	* sysdeps/ieee754/float128/e_j0f128.c: New file.
	* sysdeps/ieee754/float128/e_j1f128.c: New file.
	* sysdeps/ieee754/float128/e_jnf128.c: New file.
	* sysdeps/ieee754/float128/e_lgammaf128_r.c: New file.
	* sysdeps/ieee754/float128/e_log10f128.c: New file.
	* sysdeps/ieee754/float128/e_log2f128.c: New file.
	* sysdeps/ieee754/float128/e_logf128.c: New file.
	* sysdeps/ieee754/float128/e_powf128.c: New file.
	* sysdeps/ieee754/float128/e_rem_pio2f128.c: New file.
	* sysdeps/ieee754/float128/e_remainderf128.c: New file.
	* sysdeps/ieee754/float128/e_scalbf128.c: New file.
	* sysdeps/ieee754/float128/e_sinhf128.c: New file.
	* sysdeps/ieee754/float128/float128_private.h: New file.
	* sysdeps/ieee754/float128/gamma_productf128.c: New file.
	* sysdeps/ieee754/float128/ieee754_float128.h: New file.
	* sysdeps/ieee754/float128/k_cosf128.c: New file.
	* sysdeps/ieee754/float128/k_sincosf128.c: New file.
	* sysdeps/ieee754/float128/k_sinf128.c: New file.
	* sysdeps/ieee754/float128/k_tanf128.c: New file.
	* sysdeps/ieee754/float128/lgamma_negf128.c: New file.
	* sysdeps/ieee754/float128/lgamma_productf128.c: New file.
	* sysdeps/ieee754/float128/s_asinhf128.c: New file.
	* sysdeps/ieee754/float128/s_atanf128.c: New file.
	* sysdeps/ieee754/float128/s_cbrtf128.c: New file.
	* sysdeps/ieee754/float128/s_ceilf128.c: New file.
	* sysdeps/ieee754/float128/s_copysignf128.c: New file.
	* sysdeps/ieee754/float128/s_cosf128.c: New file.
	* sysdeps/ieee754/float128/s_erff128.c: New file.
	* sysdeps/ieee754/float128/s_expm1f128.c: New file.
	* sysdeps/ieee754/float128/s_fabsf128.c: New file.
	* sysdeps/ieee754/float128/s_finitef128.c: New file.
	* sysdeps/ieee754/float128/s_floorf128.c: New file.
	* sysdeps/ieee754/float128/s_fmaf128.c: New file.
	* sysdeps/ieee754/float128/s_fpclassifyf128.c: New file.
	* sysdeps/ieee754/float128/s_frexpf128.c: New file.
	* sysdeps/ieee754/float128/s_fromfpf128.c: New file.
	* sysdeps/ieee754/float128/s_fromfpxf128.c: New file.
	* sysdeps/ieee754/float128/s_getpayloadf128.c: New file.
	* sysdeps/ieee754/float128/s_isinff128.c: New file.
	* sysdeps/ieee754/float128/s_isnanf128.c: New file.
	* sysdeps/ieee754/float128/s_issignalingf128.c: New file.
	* sysdeps/ieee754/float128/s_llrintf128.c: New file.
	* sysdeps/ieee754/float128/s_llroundf128.c: New file.
	* sysdeps/ieee754/float128/s_log1pf128.c: New file.
	* sysdeps/ieee754/float128/s_logbf128.c: New file.
	* sysdeps/ieee754/float128/s_lrintf128.c: New file.
	* sysdeps/ieee754/float128/s_lroundf128.c: New file.
	* sysdeps/ieee754/float128/s_modff128.c: New file.
	* sysdeps/ieee754/float128/s_nearbyintf128.c: New file.
	* sysdeps/ieee754/float128/s_nextafterf128.c: New file.
	* sysdeps/ieee754/float128/s_nexttowardf128.c: New file.
	* sysdeps/ieee754/float128/s_nextupf128.c: New file.
	* sysdeps/ieee754/float128/s_remquof128.c: New file.
	* sysdeps/ieee754/float128/s_rintf128.c: New file.
	* sysdeps/ieee754/float128/s_roundevenf128.c: New file.
	* sysdeps/ieee754/float128/s_roundf128.c: New file.
	* sysdeps/ieee754/float128/s_scalblnf128.c: New file.
	* sysdeps/ieee754/float128/s_scalbnf128.c: New file.
	* sysdeps/ieee754/float128/s_setpayloadf128.c: New file.
	* sysdeps/ieee754/float128/s_setpayloadsigf128.c: New file.
	* sysdeps/ieee754/float128/s_signbitf128.c: New file.
	* sysdeps/ieee754/float128/s_significandf128.c: New file.
	* sysdeps/ieee754/float128/s_sincosf128.c: New file.
	* sysdeps/ieee754/float128/s_sinf128.c: New file.
	* sysdeps/ieee754/float128/s_tanf128.c: New file.
	* sysdeps/ieee754/float128/s_tanhf128.c: New file.
	* sysdeps/ieee754/float128/s_totalorderf128.c: New file.
	* sysdeps/ieee754/float128/s_totalordermagf128.c: New file.
	* sysdeps/ieee754/float128/s_truncf128.c: New file.
	* sysdeps/ieee754/float128/s_ufromfpf128.c: New file.
	* sysdeps/ieee754/float128/s_ufromfpxf128.c: New file.
	* sysdeps/ieee754/float128/t_sincosf128.c: New file.
	* sysdeps/ieee754/float128/x2y2m1f128.c: New file.

	* sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h:
	(__iscanonicalf128): Define as a macro.
2017-05-25 09:01:37 -03:00
Steve Ellcey 6a2c695266 aarch64: Thunderx specific memcpy and memmove
* sysdeps/aarch64/memcpy.S (MEMMOVE, MEMCPY): New macros.
	(memmove): Use MEMMOVE for name.
	(memcpy): Use MEMCPY for name.  Change internal labels
	to external labels.
	* sysdeps/aarch64/multiarch/Makefile: New file.
	* sysdeps/aarch64/multiarch/ifunc-impl-list.c: Likewise.
	* sysdeps/aarch64/multiarch/init-arch.h: Likewise.
	* sysdeps/aarch64/multiarch/memcpy.c: Likewise.
	* sysdeps/aarch64/multiarch/memcpy_generic.S: Likewise.
	* sysdeps/aarch64/multiarch/memcpy_thunderx.S: Likewise.
	* sysdeps/aarch64/multiarch/memmove.c: Likewise.
2017-05-24 16:46:48 -07:00