summaryrefslogtreecommitdiff
path: root/string
AgeCommit message (Collapse)Author
2018-07-26Fix string/tst-xbzero-opt if build with gcc head.Stefan Liebler
On s390x, the test string/tst-xbzero-opt is failing if build with gcc head: FAIL: no clear/prepare: expected 32 got 0 FAIL: no clear/test: expected some got 0 FAIL: ordinary clear/prepare: expected 32 got 0 INFO: ordinary clear/test: found 0 patterns (memset not eliminated) PASS: explicit clear/prepare: expected 32 got 32 PASS: explicit clear/test: expected 0 got 0 In setup_no_clear / setup_ordinary_clear, GCC is omitting the memcpy loop in prepare_test_buffer. Thus count_test_patterns does not find any of the test_pattern. This patch calls use_test_buffer in order to force the compiler to really copy the pattern to buf. ChangeLog: * string/tst-xbzero-opt.c (use_test_buffer): New function. (prepare_test_buffer): Call use_test_buffer as compiler barrier.
2018-07-24Add <bits/indirect-return.h>H.J. Lu
Add <bits/indirect-return.h> and include it in <ucontext.h>. __INDIRECT_RETURN defined in <bits/indirect-return.h> indicates if swapcontext requires special compiler treatment. The default __INDIRECT_RETURN is empty. On x86, when shadow stack is enabled, __INDIRECT_RETURN is defined with indirect_return attribute, which has been added to GCC 9, to indicate that swapcontext returns via indirect branch. Otherwise __INDIRECT_RETURN is defined with returns_twice attribute. When shadow stack is enabled, remove always_inline attribute from prepare_test_buffer in string/tst-xbzero-opt.c to avoid: tst-xbzero-opt.c: In function ‘prepare_test_buffer’: tst-xbzero-opt.c:105:1: error: function ‘prepare_test_buffer’ can never be inlined because it uses setjmp prepare_test_buffer (unsigned char *buf) when indirect_return attribute isn't available. Reviewed-by: Carlos O'Donell <carlos@redhat.com> * bits/indirect-return.h: New file. * misc/sys/cdefs.h (__glibc_has_attribute): New. * sysdeps/x86/bits/indirect-return.h: Likewise. * stdlib/Makefile (headers): Add bits/indirect-return.h. * stdlib/ucontext.h: Include <bits/indirect-return.h>. (swapcontext): Add __INDIRECT_RETURN. * string/tst-xbzero-opt.c (ALWAYS_INLINE): New. (prepare_test_buffer): Use it.
2018-07-16Improve strstr performanceWilco Dijkstra
Improve strstr performance. Strstr tends to be slow because it uses many calls to memchr and a slow byte loop to scan for the next match. Performance is significantly improved by using strnlen on larger blocks and using strchr to search for the next matching character. strcasestr can also use strnlen to scan ahead, and memmem can use memchr to check for the next match. On the GLIBC bench tests the performance gains on Cortex-A72 are: strstr: +25% strcasestr: +4.3% memmem: +18% On a 256KB dataset strstr performance improves by 67%, strcasestr by 47%. Reviewd-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2018-06-29libc: Extend __libc_freeres framework (Bug 23329).Carlos O'Donell
The __libc_freeres framework does not extend to non-libc.so objects. This causes problems in general for valgrind and mtrace detecting unfreed objects in both libdl.so and libpthread.so. This change is a pre-requisite to properly moving the malloc hooks out of malloc since such a move now requires precise accounting of all allocated data before destructors are run. This commit adds a proper hook in libc.so.6 for both libdl.so and for libpthread.so, this ensures that shm-directory.c which uses freeit () to free memory is called properly. We also remove the nptl_freeres hook and fall back to using weak-ref-and-check idiom for a loaded libpthread.so, thus making this process similar for all DSOs. Lastly we follow best practice and use explicit free calls for both libdl.so and libpthread.so instead of the generic hook process which has undefined order. Tested on x86_64 with no regressions. Signed-off-by: DJ Delorie <dj@redhat.com> Signed-off-by: Carlos O'Donell <carlos@redhat.com>
2018-06-26Run thread shutdown functions in an explicit orderFlorian Weimer
This removes the __libc_thread_subfreeres hook in favor of explict calls. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2018-06-20Fix tst-cmp.c build with GCC mainline.Joseph Myers
Building the testsuite with GCC mainline fails with -Wstringop-overflow= errors in string/tst-cmp.c. These are for calls to strncmp and strncasecmp with SIZE_MAX size argument. The tests are deliberately using this size that would be dubious in normal code, so this patch disables the warning for the calls in question. Tested with build-many-glibcs.py for aarch64-linux-gnu. * string/tst-cmp.c: Include <libc-diag.h>. (strncmp_max): Disable -Wstringop-overflow= around call to strncmp. (strncasecmp_max): Disable -Wstringop-overflow= around call to strncasecmp.
2018-06-20Fix bug-strspn1.c, bug-strpbrk1.c build with GCC mainline.Joseph Myers
Building the testsuite with GCC mainline fails with: bug-strspn1.c: In function 'main': bug-strspn1.c:14:3: error: right-hand operand of comma expression has no effect [-Werror=unused-value] strspn (b++, ""); ^~~~~~~~~~~~~~~~ and a similar error for bug-strpbrk1.c. I'm not sure what GCC change introduced this, and the wording of the message is a bit off (in the source it's not a comma expression, that must reflect GCC's IR). But the warning is correct (strspn is a pure function, the call is useless, and if there wasn't an argument with a side effect much older GCC would have warned); the point of the test is to verify that the side effect in an argument still occurs for this useless call that can otherwise be optimized to an (unused) constant (testing for a bug there once was in an old strspn macro). This patch duly arranges for the warning to be disabled for this code. Tested with build-many-glibcs.py for aarch64-linux-gnu. * string/bug-strpbrk1.c: Include <libc-diag.h>. (main): Disable -Wunused-value around call to strpbrk. * string/bug-strspn1.c: Include <libc-diag.h>. (main): Disable -Wunused-value around call to strspn.
2018-06-14Ignore -Wrestrict for one strncat test.Joseph Myers
With current GCC mainline, one strncat test involving a size close to SIZE_MAX results in a -Wrestrict warning that that buffer size would imply that the two buffers must overlap. This patch fixes the build by adding disabling of -Wrestrict (for GCC versions supporting that option) to the already-present disabling of -Wstringop-overflow= and -Warray-bounds for this test. Tested with build-many-glibcs.py that this restores the testsuite build with GCC mainline for aarch64-linux-gnu. * string/tester.c (test_strncat) [__GNUC_PREREQ (7, 0)]: Also ignore -Wrestrict for one test.
2018-05-23Add a test case for [BZ #23196]H.J. Lu
[BZ #23196] * string/test-memcpy.c (do_test1): New function. (test_main): Call it.
2018-05-23Don't write beyond destination in __mempcpy_avx512_no_vzeroupper (bug 23196)Andreas Schwab
When compiled as mempcpy, the return value is the end of the destination buffer, thus it cannot be used to refer to the start of it.
2018-03-23Fix i386 memmove issue (bug 22644).Andrew Senkevich
[BZ #22644] * sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S: Fixed branch conditions. * string/test-memmove.c (do_test2): New testcase.
2018-02-26Fix another -Os strcoll build issue.Joseph Myers
While there are now clean -Os build and test results on x86_64 (given my patch <https://sourceware.org/ml/libc-alpha/2018-02/msg00602.html>, pending review), testing with -Os with build-many-glibcs.py shows the build is still failing with -Os everywhere except for x86_64, x86 and s390x. There are a variety of different build failures, but the most common seem to be in strcoll / wcscoll, similar to existing such cases where DIAG_* are used to disable -Wmaybe-uninitialized. There are various different failures even within those functions. This patch fixes one particular case that seems quite common, where the warning appears at the declarations of seq1 and seq2. Tested with build-many-glibcs.py that this fixes the -Os build for aarch64-linux-gnu with GCC 7. * string/strcoll_l.c: Include <libc-diag.h>. (STRCOLL): Ignore -Wmaybe-uninitialized for -Os around declarations of seq1 and seq2.
2018-02-15Use libc_hidden_* for argz_next, __argz_next (bug 15105).Joseph Myers
Among other localplt test failures when building with -Os, there are libc.so PLT references for argz_next and __argz_next. This is a simple case of functions that are inlined for -O2 but not for -Os; this patch adds libc_hidden_proto / libc_hidden_def for them to avoid localplt failures even when not inlined. Tested for x86_64 (both that it removes these particular localplt failures for -Os - but other such failures remain so the bug can't yet be closed - and that the testsuite continues to pass without -Os). [BZ #15105] * include/argz.h (argz_next): Use libc_hidden_proto. (__argz_next): Likewise. * string-argz-next.c (__argz_next): Use libc_hidden_def. (argz_next): Use libc_hidden_weak.
2018-02-06Unify and simplify bits/byteswap.h, bits/byteswap-16.h headers (bug 14508, ↵Joseph Myers
bug 15512, bug 17082, bug 20530). We have a general principle of preferring optimizations for library facilities to use compiler built-in functions rather than being located in library headers, where the compiler can reasonably optimize code without needing to know glibc implementation details. This patch applies this principle to bits/byteswap.h, eliminating all the architecture-specific variants and bits/byteswap-16.h. The __bswap_16, __bswap_32 and __bswap_64 interfaces all become inline functions, never macros, using the GCC built-in functions where available and otherwise a single architecture-independent definition using shifts and masking (which compilers may well be able to detect and optimize; GCC has detection of various byte-swapping idioms). The __bswap_constant_32 macro needs to stay around because of uses in static initializers within glibc and its tests, and so for consistency all __bswap_constant_* are kept rather than just being inlined into the old-GCC-or-non-GCC parts of the __bswap_* inline function definitions. Various open bugs are addressed by this cleanup, with caveats about exactly what is covered by those bugs and when the bugs applied at all. Bug 14508 reports -Wformat warnings building glibc because __bswap_* sometimes returned the wrong types. Obviously we already don't have such warnings any more or the build would be failing, given -Werror, and I suspect that bug was originally for wrong types for x86_64, as fixed by commit d394eb742a3565d7fe7a4b02710a60b5f219ee64 (glibc 2.17). The only case I saw removed by this patch where the types would still have been wrong was the non-__GNUC__ case of __bswap_64 in the s390 header (using unsigned long long int, but uint64_t would be unsigned long int for 64-bit). In any case, the single header consistently uses __uintN_t types after this patch, thereby eliminating all such bugs. The existing string/test-endian-types.c test already suffices to verify that the types are correct with the compiler used to build glibc and its tests. Bug 15512 reports an error from __bswap_constant_16 with -Werror -Wsign-conversion. I am unable to reproduce this with any GCC version supporting -Wsign-conversion - all seem to be able to avoid warning for ((x) >> 8) & 0xffu, where x is uint16_t, which while it formally does involve an implicit conversion from int to unsigned int, is also a case where it should be easy for the compiler to see that the value converted is never negative. But in this patch __bswap_constant_16 is changed to use signed 0xff so that no such implicit conversion occurs at all, and a test with -Werror -Wsign-conversion is added. Bug 17082 objects to the use of ({}) statement expressions in these macros preventing use at file scope (in C, that's in sizeof etc.; in C++, more generally in static initializers). The particular case of these interfaces is fixed by this patch as it changes them to inline functions, eliminating all uses of ({}) in bits/byteswap.h, and a corresponding testcase is added. The bug tries to raise a more general policy question about use of ({}) in macros in installed headers, referring to "many other libc functions" (unspecified which functions are being considered). Since such policy questions belong on libc-alpha, and since there *are* macros in installed headers which can't really avoid using ({}) (where they are type-generic, so can't use an inline function, but need a temporary variable, and a few where the interface involves returning memory from alloca so can't use an inline function either), I propose to consider that bug fixed with this change. That is without prejudice to any other new bugs anyone wishes to file *for precisely defined sets of macros* requesting moving away from ({}) *where it is clearly possible for those interfaces*. Where ({}) can be avoided, typically by use of an inline function, I think that's a good idea - that inline functions are typically to be preferred to ({}) for header interfaces where such optimizations are useful but the interface is suited to being defined using an inline function. Bug 20530 requests use of __builtin_bswap16 when available (GCC 4.8 and later), which this patch implements. Tested for x86_64, and with build-many-glibcs.py. Also did an x86_64 test with the __GNUC_PREREQ conditionals changed to "#if 0" to verify the old-GCC/non-GCC case in the headers. (There are already existing tests for correctness of results of these interfaces.) [BZ #14508] [BZ #15512] [BZ #17082] [BZ #20530] * bits/byteswap.h: Update file comment. Do not include <bits/byteswap-16.h>. (__bswap_constant_16): Cast result to __uint16_t. Use signed 0xff constant. (__bswap_16): Define as inline function. (__bswap_constant_32): Reformat definition. (__bswap_32): Always define as inline function, not macro, using __uint32_t. Use __builtin_bswap32 if [__GNUC_PREREQ (4, 3)], otherwise __bswap_constant_32. (__bswap_constant_64): Reformat definition. Do not use __extension__ here. (__bswap_64): Always define as inline function, not macro. Use __extension__ on function definition. Use __builtin_bswap64 if [__GNUC_PREREQ (4, 3)], otherwise __bswap_constant_64. * string/test-endian-file-scope.c: New file. * string/test-endian-sign-conversion.c: Likewise. * string/Makefile (headers): Remove bits/byteswap-16.h. (tests): Add test-endian-file-scope and test-endian-sign-conversion. (CFLAGS-test-endian-sign-conversion.c): New variable. * bits/byteswap-16.h: Remove file. * sysdeps/ia64/bits/byteswap-16.h: Likewise. * sysdeps/ia64/bits/byteswap.h: Likewise. * sysdeps/m68k/bits/byteswap.h: Likewise. * sysdeps/s390/bits/byteswap-16.h: Likewise. * sysdeps/s390/bits/byteswap.h: Likewise. * sysdeps/tile/bits/byteswap.h: Likewise. * sysdeps/x86/bits/byteswap-16.h: Likewise. * sysdeps/x86/bits/byteswap.h: Likewise.
2018-02-06Move string/testcopy.c to test-driver.c and xmalloc (bug 19667).Joseph Myers
Bug 19667 reports unchecked malloc calls in the test string/testcopy.c. This patch makes that test use xmalloc and the support/test-driver.c test framework. Tested for x86_64. [BZ #19667] * string/testcopy.c: Include <support/support.h>. Do not include <malloc.h>. Use <support/test-driver.c>. (main): Rename to do_test. Make static. Use xmalloc instead of malloc.
2018-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers
* All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
2017-12-18Disable strncat test array-bounds warnings for GCC 8.Joseph Myers
Some strncat tests fail to build with GCC 8 because of -Warray-bounds warnings. These tests are deliberately test over-large size arguments passed to strncat, and already disable -Wstringop-overflow warnings, but now the warnings for these tests come under -Warray-bounds so that option needs disabling for them as well, which this patch does (with an update on the comments; the DIAG_IGNORE_NEEDS_COMMENT call for -Warray-bounds doesn't need to be conditional itself, because that option is supported by all versions of GCC that can build glibc). Tested compilation with build-many-glibcs.py for aarch64-linux-gnu. * string/tester.c (test_strncat): Also disable -Warray-bounds warnings for two tests.
2017-12-11string: Replace = with += in CFLAGS-xxx.cH.J. Lu
Replace = with += in CFLAGS-xxx.c to allow Makefile under sysdeps to define CFLAGS-xx.c. * string/Makefile (CFLAGS-inl-tester.c): Replace = with +=. (CFLAGS-noinl-tester.c): Likewise. (CFLAGS-tst-strlen.c): Likewise. (CFLAGS-stratcliff.c): Likewise. (CFLAGS-test-ffs.c): Likewise. (CFLAGS-tst-inlcall.c): Likewise. (CFLAGS-tst-xbzero-opt.c): Likewise. (CFLAGS-memcpy.c): Likewise. (CFLAGS-wordcopy.c): Likewise.
2017-11-14Fix string/tester.c build with GCC 8.Joseph Myers
GCC 8 warns about more cases of string functions truncating their output or not copying a trailing NUL byte. This patch fixes testsuite build failures caused by such warnings in string/tester.c. In general, the warnings are disabled around the relevant calls using DIAG_* macros, since the relevant cases are being deliberately tested. In one case, the warning is with -Wstringop-overflow= instead of -Wstringop-truncation; in that case, the conditional is __GNUC_PREREQ (7, 0) (being the version where -Wstringop-overflow= was introduced), to allow the conditional to be removed sooner, since it's harmless to disable the warning for a GCC version where it doesn't actually occur. In the case of warnings for strncpy calls in test_memcmp, the calls in question are changed to use memcpy, as they don't copy a trailing NUL and the point of that code is to test memcmp rather than strncpy. Tested (compilation) with GCC 8 for x86_64-linux-gnu with build-many-glibcs.py (in conjunction with Martin's patch to allow glibc to build). * string/tester.c (test_stpncpy): Disable -Wstringop-truncation for stpncpy calls for GCC 8. (test_strncat): Disable -Wstringop-truncation warning for strncat calls for GCC 8. Disable -Wstringop-overflow= warning for one strncat call for GCC 7. (test_strncpy): Disable -Wstringop-truncation warning for strncpy calls for GCC 8. (test_memcmp): Use memcpy instead of strncpy for calls not copying trailing NUL.
2017-11-14Fix string/bug-strncat1.c build with GCC 8.Joseph Myers
GCC 8 warns about strncat calls with truncated output. string/bug-strncat1.c tests such a call; this patch disables the warning for it. Tested (compilation) with GCC 8 for x86_64-linux-gnu with build-many-glibcs.py (in conjunction with Martin's patch to allow glibc to build). * string/bug-strncat1.c: Include <libc-diag.h>. (main): Disable -Wstringop-truncation for strncat call for GCC 8.
2017-10-30ffsl, ffsll: Declare under __USE_MISC, not just __USE_GNUFlorian Weimer
Recent BSDs declare these functions, too.
2017-10-01Hide internal __strsep function [BZ #18822]H.J. Lu
Hide internal __strsep function to allow direct access within libc.so and libc.a without using GOT nor PLT. [BZ #18822] * include/string.h (__strsep): Add libc_hidden_proto. * string/strsep.c (__strsep): Add libc_hidden_def.
2017-08-23string/stratcliff.c: Replace int with size_t [BZ #21982]H.J. Lu
Fix GCC 7 errors when string/stratcliff.c is compiled with -O3: stratcliff.c: In function ‘do_test’: cc1: error: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Werror=strict-overflow] [BZ #21982] * string/stratcliff.c (do_test): Declare size, nchars, inner, middle and outer with size_t instead of int. Repleace %d and %Zd with %zu in printf. Update "MAX (0, nchars - 128)" and "MAX (outer, nchars - 64)" to support unsigned outer and nchars. Also exit loop when outer == 0.
2017-08-18Mark internal argz functions with attribute_hidden [BZ #18822]H.J. Lu
Move internal argz function prototypes to include/argz.h and mark them with attribute_hidden to allow direct access within libc.so and libc.a without using GOT nor PLT. This also brings string/argz.h closer to the gnulib version. [BZ #18822] * include/argz.h (__argz_create_sep): New function prototype. (__argz_append): Likewise. (__argz_add): Likewise. (__argz_add_sep): Likewise. (__argz_delete): Likewise. (__argz_insert): Likewise. (__argz_replace): Likewise. * string/argz.h (__argz_create_sep): Removed. (__argz_append): Likewise. (__argz_add): Likewise. (__argz_add_sep): Likewise. (__argz_delete): Likewise. (__argz_insert): Likewise. (__argz_replace): Likewise.
2017-08-08Do not use __ptr_t.Joseph Myers
sys/cdefs.h has a macro __ptr_t, which a few places in glibc use instead of void *. void * is a well-understood standard type for that purpose and in a post-C89 context there is no need for a macro for it; this patch changes those places to use void * directly instead. Unlike __long_double_t, __ptr_t is widely used outside glibc (or at least has many hits on codesearch.debian.net). I don't know how many of those uses would break if sys/cdefs.h ceased to define the macro, but there's enough risk that this patch leaves the definition and just removes the uses within glibc; removal of the definition can be considered separately if desired. Tested for x86_64, and with build-many-glibcs.py. * malloc/mcheck.c (old_free_hook): Use void * instead of __ptr_t. (old_malloc_hook): Likewise. (old_memalign_hook): Likewise. (old_realloc_hook): Likewise. (struct hdr): Likewise. (flood): Likewise. (freehook): Likewise. (mallochook): Likewise. (memalignhook): Likewise. (reallochook): Likewise. (mprobe): Likewise. * malloc/mtrace.c (mallwatch): Likewise. (tr_old_free_hook): Likewise. (tr_old_malloc_hook): Likewise. (tr_old_realloc_hook): Likewise. (tr_old_memalign_hook): Likewise. (tr_where): Likewise. (lock_and_info): Likewise. (tr_freehook): Likewise. (tr_mallochook): Likewise. (tr_reallochook): Likewise. (tr_memalignhook): Likewise. * misc/err.h [!__GNUC_VA_LIST] (__gnuc_va_list): Likewise. * misc/mmap.c (__mmap): Likewise. * misc/mmap64.c (__mmap64): Likewise. * misc/mprotect.c (__mprotect): Likewise. * misc/msync.c (msync): Likewise. * misc/munmap.c (__munmap): Likewise. * posix/posix_madvise.c (posix_madvise): Likewise. * socket/send.c (__send): Likewise. * socket/sendto.c (__sendto): Likewise. * socket/setsockopt.c (__setsockopt): Likewise. * string/memcmp.c (__ptr_t): Remove macro. (MEMCMP): Use void * instead of ptr_t. * string/memrchr.c (__ptr_t): Remove macro. (__memrchr): Use void * instead of ptr_t. * sysdeps/mach/hurd/dl-sysdep.c (__mmap): Likewise. * sysdeps/mach/hurd/mmap.c (__mmap): Likewise. * sysdeps/mach/hurd/mmap64.c (__mmap64): Likewise. * sysdeps/mach/mprotect.c (__mprotect): Likewise. * sysdeps/mach/msync.c (msync): Likewise. * sysdeps/mach/munmap.c (__munmap): Likewise. * sysdeps/mips/bits/setjmp.h (struct __jmp_buf_internal_tag): Likewise. * sysdeps/posix/getcwd.c (__getcwd): Likewise. * sysdeps/powerpc/powerpc32/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc32/power4/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc32/power4/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc32/power6/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc32/power6/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc32/power7/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc32/power7/mempcpy.S (__mempcpy): Likewise. * sysdeps/powerpc/powerpc32/power7/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc64/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/power4/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc64/power4/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/power6/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc64/power6/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/power7/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc64/power7/mempcpy.S (__mempcpy): Likewise. * sysdeps/powerpc/powerpc64/power7/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/power8/memset.S (memset): Likewise. * sysdeps/tile/memcmp.c (__ptr_t): Remove macro. (MEMCMP): Use void * instead of ptr_t. * sysdeps/unix/sysv/linux/alpha/oldglob.c (old_glob_t): Likewise. * sysdeps/unix/sysv/linux/mmap.c (__mmap): Likewise.
2017-07-06Increase some test timeouts.Joseph Myers
This patch increases the timeouts for some tests that I've seen timing out on slow systems in my 2.26 release testing. (In the case of tst-tsearch.c, increasing the timeout means removing a setting of 10 that was put there before the default timeout was increased to 20 seconds, so putting the default into effect.) * iconvdata/tst-loading.c (TIMEOUT): Define to 30. * misc/tst-tsearch.c (TIMEOUT): Remove. * nptl/tst-create-detached.c (TIMEOUT): Define to 100. * nptl/tst-robust-fork.c (TIMEOUT): Likewise. * nptl/tst-rwlock19.c (TIMEOUT): Likewise. * string/tst-cmp.c (TIMEOUT): Define to 600.
2017-06-23x86-64: memcmp-avx2-movbe.S needs saturating subtraction [BZ #21662]Florian Weimer
This code: L(between_2_3): /* Load as big endian with overlapping loads and bswap to avoid branches. */ movzwl -2(%rdi, %rdx), %eax movzwl -2(%rsi, %rdx), %ecx shll $16, %eax shll $16, %ecx movzwl (%rdi), %edi movzwl (%rsi), %esi orl %edi, %eax orl %esi, %ecx bswap %eax bswap %ecx subl %ecx, %eax ret needs a saturating subtract because the full register is used. With this commit, only the lower 24 bits of the register are used, so a regular subtraction suffices. The test case change adds coverage for these kinds of bugs.
2017-06-20Use locale_t, not __locale_t, throughout glibcZack Weinberg
<locale.h> is specified to define locale_t in POSIX.1-2008, and so are all of the headers that define functions that take locale_t arguments. Under _GNU_SOURCE, the additional headers that define such functions have also always defined locale_t. Therefore, there is no need to use __locale_t in public function prototypes, nor in any internal code. * ctype/ctype-c99_l.c, ctype/ctype.h, ctype/ctype_l.c * include/monetary.h, include/stdlib.h, include/time.h * include/wchar.h, locale/duplocale.c, locale/freelocale.c * locale/global-locale.c, locale/langinfo.h, locale/locale.h * locale/localeinfo.h, locale/newlocale.c * locale/nl_langinfo_l.c, locale/uselocale.c * localedata/bug-usesetlocale.c, localedata/tst-xlocale2.c * stdio-common/vfscanf.c, stdlib/monetary.h, stdlib/stdlib.h * stdlib/strfmon_l.c, stdlib/strtod_l.c, stdlib/strtof_l.c * stdlib/strtol.c, stdlib/strtol_l.c, stdlib/strtold_l.c * stdlib/strtoll_l.c, stdlib/strtoul_l.c, stdlib/strtoull_l.c * string/strcasecmp.c, string/strcoll_l.c, string/string.h * string/strings.h, string/strncase.c, string/strxfrm_l.c * sysdeps/ieee754/float128/strtof128_l.c * sysdeps/ieee754/float128/wcstof128.c * sysdeps/ieee754/float128/wcstof128_l.c * sysdeps/ieee754/ldbl-128ibm/strtold_l.c * sysdeps/ieee754/ldbl-64-128/strtold_l.c * sysdeps/ieee754/ldbl-opt/nldbl-compat.c * sysdeps/ieee754/ldbl-opt/nldbl-strfmon_l.c * sysdeps/ieee754/ldbl-opt/nldbl-strtold_l.c * sysdeps/ieee754/ldbl-opt/nldbl-wcstold_l.c * sysdeps/powerpc/powerpc32/power7/strcasecmp.S * sysdeps/powerpc/powerpc64/power7/strcasecmp.S * sysdeps/x86_64/strcasecmp_l-nonascii.c * sysdeps/x86_64/strncase_l-nonascii.c, time/strftime_l.c * time/strptime_l.c, time/time.h, wcsmbs/mbsrtowcs_l.c * wcsmbs/wchar.h, wcsmbs/wcscasecmp.c, wcsmbs/wcsncase.c * wcsmbs/wcstod.c, wcsmbs/wcstod_l.c, wcsmbs/wcstof.c * wcsmbs/wcstof_l.c, wcsmbs/wcstol_l.c, wcsmbs/wcstold.c * wcsmbs/wcstold_l.c, wcsmbs/wcstoll_l.c, wcsmbs/wcstoul_l.c * wcsmbs/wcstoull_l.c, wctype/iswctype_l.c * wctype/towctrans_l.c, wctype/wcfuncs_l.c * wctype/wctrans_l.c, wctype/wctype.h, wctype/wctype_l.c: Change all uses of __locale_t to locale_t.
2017-06-20Rename xlocale.h to bits/types/__locale_t.h.Zack Weinberg
xlocale.h is already a single-type micro-header, defining struct __locale_struct and the typedefs __locale_t and locale_t. This patch brings it into the bits/types/ scheme: there are now bits/types/__locale_t.h which defines only __locale_struct and __locale_t, and bits/types/locale_t.h which defines locale_t as well as the other two. None of *our* headers need __locale_t.h, but it appears to me that libstdc++ could make use of it. There are a lot of external uses of xlocale.h, but all the uses I checked had an autoconf test or equivalent for its existence. It has never been available from other C libraries, and it has always contained a comment reading "This file is not standardized, don't rely on it, it can go away without warning" so I think dropping it is pretty safe. I also took the opportunity to clean up comments in various public header files that still talk about the *_l interfaces as though they were completely nonstandard. There are a few of them, notably the strtoX_l and wcstoX_l families, that haven't been standardized, but the bulk are in POSIX.1-2008. * locale/xlocale.h: Rename to... * locale/bits/types/__locale_t.h: ...here. Adjust commentary. Only define struct __locale_struct and __locale_t, not locale_t. * locale/bits/types/locale_t.h: New file; define locale_t here. * locale/Makefile (headers): Update to match. * include/xlocale.h: Delete wrapper. * include/bits/types/__locale_t.h: New wrapper. * include/bits/types/locale_t.h: New wrapper. * ctype/ctype.h, include/printf.h, include/time.h * locale/langinfo.h, locale/locale.h, stdlib/monetary.h * stdlib/stdlib.h, string/string.h, string/strings.h, time/time.h * wcsmbs/wchar.h, wctype/wctype.h: Use bits/types/locale_t.h. Correct outdated comments regarding the standardization status of the functions that take locale_t arguments. * stdlib/strtod_l.c, stdlib/strtof_l.c, stdlib/strtol_l.c * stdlib/strtold_l.c, stdlib/strtoul_l.c, stdlib/strtoull_l.c * sysdeps/ieee754/ldbl-128ibm/strtold_l.c * sysdeps/ieee754/ldbl-64-128/strtold_l.c * wcsmbs/wcstod.c, wcsmbs/wcstod_l.c, wcsmbs/wcstof.c * wcsmbs/wcstof_l.c, wcsmbs/wcstold.c, wcsmbs/wcstold_l.c: Don't include xlocale.h. If necessary, include locale.h instead. * stdlib/strtold_l.c: Unconditionally include wchar.h.
2017-06-20Fix fallout from bits/string.h removal.Zack Weinberg
Remove one more string inline that was defined directly in string.h; in the absence of the rest of the inlines, it broke the build. Like other ifunc shims for these functions, x86_64/multiarch/{mem,st}pcpy.c need to define __NO_STRING_INLINES and NO_MEMPCPY_STPCPY_REDIRECT. * string/string.h (__mempcpy_inline): Delete. * sysdeps/x86_64/multiarch/mempcpy.c * sysdeps/x86_64/multiarch/stpcpy.c: Define NO_MEMPCPY_STPCPY_REDIRECT and __NO_STRING_INLINES before including string.h.
2017-06-20Remove bits/string.h.Zack Weinberg
These machine-dependent inline string functions have never been on by default, and even if they were a good idea at the time they were introduced, they haven't really been touched in ten to fifteen years and probably aren't a good idea on current-gen processors. Current thinking is that this class of optimization is best left to the compiler. * bits/string.h, string/bits/string.h * sysdeps/aarch64/bits/string.h * sysdeps/m68k/m680x0/m68020/bits/string.h * sysdeps/s390/bits/string.h, sysdeps/sparc/bits/string.h * sysdeps/x86/bits/string.h: Delete file. * string/string.h: Don't include bits/string.h. * string/bits/string3.h: Rename to bits/string_fortified.h. No need to undef various symbols that the removed headers might have defined as macros. * string/Makefile (headers): Remove bits/string.h, change bits/string3.h to bits/string_fortified.h. * string/string-inlines.c: Update commentary. Remove definitions of various macros that nothing looks at anymore. Don't directly include bits/string.h. Set _STRING_INLINE_unaligned here, based on compiler-predefined macros. * string/strncat.c: If STRNCAT is not defined, or STRNCAT_PRIMARY _is_ defined, provide internal hidden alias __strncat. * include/string.h: Declare internal hidden alias __strncat. Only forward __stpcpy to __builtin_stpcpy if __NO_STRING_INLINES is not defined. * include/bits/string3.h: Rename to bits/string_fortified.h, update to match above. * sysdeps/i386/string-inlines.c: Define compat symbols for everything formerly defined by sysdeps/x86/bits/string.h. Make existing definitions into compat symbols as well. Remove some no-longer-necessary messing around with macros. * sysdeps/powerpc/powerpc32/power4/multiarch/mempcpy.c * sysdeps/powerpc/powerpc64/multiarch/mempcpy.c * sysdeps/powerpc/powerpc64/multiarch/stpcpy.c * sysdeps/s390/multiarch/mempcpy.c No need to define _HAVE_STRING_ARCH_mempcpy. Do define __NO_STRING_INLINES and NO_MEMPCPY_STPCPY_REDIRECT. * sysdeps/i386/i686/multiarch/strncat-c.c * sysdeps/s390/multiarch/strncat-c.c * sysdeps/x86_64/multiarch/strncat-c.c Define STRNCAT_PRIMARY. Don't change definition of libc_hidden_def.
2017-06-14Remove __need macros from errno.h (__need_Emath, __need_error_t).Zack Weinberg
This is fairly complicated, not because the users of __need_Emath and __need_error_t have complicated requirements, but because the core changes had a lot of fallout. __need_error_t exists for gnulib compatibility in argz.h and argp.h. error_t itself is a Hurdism, an enum containing all the E-constants, so you can do 'p (error_t) errno' in gdb and get a symbolic value. argz.h and argp.h use it for function return values, and they want to fall back to 'int' when that's not available. There is no reason why these nonstandard headers cannot just go ahead and include all of errno.h; so we do that. __need_Emath is defined only by .S files; what they _really_ need is for errno.h to avoid declaring anything other than the E-constants (e.g. 'extern int __errno_location(void);' is a syntax error in assembly language). This is replaced with a check for __ASSEMBLER__ in errno.h, plus a carefully documented requirement for bits/errno.h not to define anything other than macros. That in turn has the consequence that bits/errno.h must not define errno - fortunately, all live ports use the same definition of errno, so I've moved it to errno.h. The Hurd bits/errno.h must also take care not to define error_t when __ASSEMBLER__ is defined, which involves repeating all of the definitions twice, but it's a generated file so that's okay. * stdlib/errno.h: Remove __need_Emath and __need_error_t logic. Reorganize file. Declare errno here. When __ASSEMBLER__ is defined, don't declare anything other than the E-constants. * include/errno.h: Change conditional for exposing internal declarations to (not _ISOMAC and not __ASSEMBLER__). * bits/errno.h: Remove logic for __need_Emath. Document requirements for a port-specific bits/errno.h. * sysdeps/unix/sysv/linux/bits/errno.h * sysdeps/unix/sysv/linux/alpha/bits/errno.h * sysdeps/unix/sysv/linux/hppa/bits/errno.h * sysdeps/unix/sysv/linux/mips/bits/errno.h * sysdeps/unix/sysv/linux/sparc/bits/errno.h: Add multiple-include guard and check against improper inclusion. Remove __need_Emath logic. Don't declare errno here. Ensure all constants are defined as simple integer literals. Consistent formatting. * sysdeps/mach/hurd/errnos.awk: Likewise. Only define error_t and enum __error_t_codes if __ASSEMBLER__ is not defined. * sysdeps/mach/hurd/bits/errno.h: Regenerate. * argp/argp.h, string/argz.h: Don't define __need_error_t before including errno.h. * sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S * sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S * sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S * sysdeps/x86_64/fpu/s_cosf.S * sysdeps/x86_64/fpu/s_sincosf.S * sysdeps/x86_64/fpu/s_sinf.S: Just include errno.h; don't define __need_Emath or include bits/errno.h directly.
2017-06-12Fix build issue on x86.Wilco Dijkstra
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-122017-06-12 Wilco Dijkstra <wdijkstr@arm.com>Wilco Dijkstra
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-08Add more tests for memchrH.J. Lu
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-05-25Add memchr tests for n == 0H.J. Lu
* string/test-memchr.c (test_main): Add tests for n == 0.
2017-05-11Suppress internal declarations for most of the testsuite.Zack Weinberg
This patch adds a new build module called 'testsuite'. IS_IN (testsuite) implies _ISOMAC, as do IS_IN_build and __cplusplus (which means several ad-hoc tests for __cplusplus can go away). libc-symbols.h now suppresses almost all of *itself* when _ISOMAC is defined; in particular, _ISOMAC mode does not get config.h automatically anymore. There are still quite a few tests that need to see internal gunk of one variety or another. For them, we now have 'tests-internal' and 'test-internal-extras'; files in this category will still be compiled with MODULE_NAME=nonlib, and everything proceeds as it always has. The bulk of this patch is moving tests from 'tests' to 'tests-internal'. There is also 'tests-static-internal', which has the same effect on files in 'tests-static', and 'modules-names-tests', which has the *inverse* effect on files in 'modules-names' (it's inverted because most of the things in modules-names are *not* tests). For both of these, the file must appear in *both* the new variable and the old one. There is also now a special case for when libc-symbols.h is included without MODULE_NAME being defined at all. (This happens during the creation of libc-modules.h, and also when preprocessing Versions files.) When this happens, IS_IN is set to be always false and _ISOMAC is *not* defined, which was the status quo, but now it's explicit. The remaining changes to C source files in this patch seemed likely to cause problems in the absence of the main change. They should be relatively self-explanatory. In a few cases I duplicated a definition from an internal header rather than move the test to tests-internal; this was a judgement call each time and I'm happy to change those however reviewers feel is more appropriate. * Makerules: New subdir configuration variables 'tests-internal' and 'test-internal-extras'. Test files in these categories will still be compiled with MODULE_NAME=nonlib. Test files in the existing categories (tests, xtests, test-srcs, test-extras) are now compiled with MODULE_NAME=testsuite. New subdir configuration variable 'modules-names-tests'. Files which are in both 'modules-names' and 'modules-names-tests' will be compiled with MODULE_NAME=testsuite instead of MODULE_NAME=extramodules. (gen-as-const-headers): Move to tests-internal. (do-tests-clean, common-mostlyclean): Support tests-internal. * Makeconfig (built-modules): Add testsuite. * Makefile: Change libof-check-installed-headers-c and libof-check-installed-headers-cxx to 'testsuite'. * Rules: Likewise. Support tests-internal. * benchtests/strcoll-inputs/filelist#en_US.UTF-8: Remove extra-modules.mk. * config.h.in: Don't check for __OPTIMIZE__ or __FAST_MATH__ here. * include/libc-symbols.h: Move definitions of _GNU_SOURCE, PASTE_NAME, PASTE_NAME1, IN_MODULE, IS_IN, and IS_IN_LIB to the very top of the file and rationalize their order. If MODULE_NAME is not defined at all, define IS_IN to always be false, and don't define _ISOMAC. If any of IS_IN (testsuite), IS_IN_build, or __cplusplus are true, define _ISOMAC and suppress everything else in this file, starting with the inclusion of config.h. Do check for inappropriate definitions of __OPTIMIZE__ and __FAST_MATH__ here, but only if _ISOMAC is not defined. Correct some out-of-date commentary. * include/math.h: If _ISOMAC is defined, undefine NO_LONG_DOUBLE and _Mlong_double_ before including math.h. * include/string.h: If _ISOMAC is defined, don't expose _STRING_ARCH_unaligned. Move a comment to a more appropriate location. * include/errno.h, include/stdio.h, include/stdlib.h, include/string.h * include/time.h, include/unistd.h, include/wchar.h: No need to check __cplusplus nor use __BEGIN_DECLS/__END_DECLS. * misc/sys/cdefs.h (__NTHNL): New macro. * sysdeps/m68k/m680x0/fpu/bits/mathinline.h (__m81_defun): Use __NTHNL to avoid errors with GCC 6. * elf/tst-env-setuid-tunables.c: Include config.h with _LIBC defined, for HAVE_TUNABLES. * inet/tst-checks-posix.c: No need to define _ISOMAC. * intl/tst-gettext2.c: Provide own definition of N_. * math/test-signgam-finite-c99.c: No need to define _ISOMAC. * math/test-signgam-main.c: No need to define _ISOMAC. * stdlib/tst-strtod.c: Convert to test-driver. Split locale_test to... * stdlib/tst-strtod1i.c: ...this new file. * stdlib/tst-strtod5.c: Convert to test-driver and add copyright notice. Split tests of __strtod_internal to... * stdlib/tst-strtod5i.c: ...this new file. * string/test-string.h: Include stdint.h. Duplicate definition of inhibit_loop_to_libcall here (from libc-symbols.h). * string/test-strstr.c: Provide dummy definition of libc_hidden_builtin_def when including strstr.c. * sysdeps/ia64/fpu/libm-symbols.h: Suppress entire file in _ISOMAC mode; no need to test __STRICT_ANSI__ nor __cplusplus as well. * sysdeps/x86_64/fpu/math-tests-arch.h: Include cpu-features.h. Don't include init-arch.h. * sysdeps/x86_64/multiarch/test-multiarch.h: Include cpu-features.h. Don't include init-arch.h. * elf/Makefile: Move tst-ptrguard1-static, tst-stackguard1-static, tst-tls1-static, tst-tls2-static, tst-tls3-static, loadtest, unload, unload2, circleload1, neededtest, neededtest2, neededtest3, neededtest4, tst-tls1, tst-tls2, tst-tls3, tst-tls6, tst-tls7, tst-tls8, tst-dlmopen2, tst-ptrguard1, tst-stackguard1, tst-_dl_addr_inside_object, and all of the ifunc tests to tests-internal. Don't add $(modules-names) to test-extras. * inet/Makefile: Move tst-inet6_scopeid_pton to tests-internal. Add tst-deadline to tests-static-internal. * malloc/Makefile: Move tst-mallocstate and tst-scratch_buffer to tests-internal. * misc/Makefile: Move tst-atomic and tst-atomic-long to tests-internal. * nptl/Makefile: Move tst-typesizes, tst-rwlock19, tst-sem11, tst-sem12, tst-sem13, tst-barrier5, tst-signal7, tst-tls3, tst-tls3-malloc, tst-tls5, tst-stackguard1, tst-sem11-static, tst-sem12-static, and tst-stackguard1-static to tests-internal. Link tests-internal with libpthread also. Don't add $(modules-names) to test-extras. * nss/Makefile: Move tst-field to tests-internal. * posix/Makefile: Move bug-regex5, bug-regex20, bug-regex33, tst-rfc3484, tst-rfc3484-2, and tst-rfc3484-3 to tests-internal. * stdlib/Makefile: Move tst-strtod1i, tst-strtod3, tst-strtod4, tst-strtod5i, tst-tls-atexit, and tst-tls-atexit-nodelete to tests-internal. * sunrpc/Makefile: Move tst-svc_register to tests-internal. * sysdeps/powerpc/Makefile: Move test-get_hwcap and test-get_hwcap-static to tests-internal. * sysdeps/unix/sysv/linux/Makefile: Move tst-setgetname to tests-internal. * sysdeps/x86_64/fpu/Makefile: Add all libmvec test modules to modules-names-tests.
2017-05-10Fix rawmemchr build with GCC 8.Joseph Myers
The default rawmemchr implementation uses memchr with size (size_t)-1, which produces a warning with current GCC mainline. The warning seems reasonable for normal code, so this patch uses the DIAG_* macros to disable it. Tested (compilation of glibc only) with build-many-glibcs.py for arm-linux-gnueabi and powerpc64le-linux-gnu, two architectures for which the build was previously failing. Note that the glibc testsuite will still fail to build with GCC mainline because of <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80669>. * string/rawmemchr.c: Include <libc-diag.h>. (RAWMEMCHR): Disable -Wstringop-overflow around call to memchr with size (size_t)-1.
2017-04-05Add page tests to string/test-strnlen.Wainer dos Santos Moschetta
May be tricky for otimized implementations to handle strings around page boundary once, for instance, it is performed unaligned loads or when maxlen is used as a hint for vectorized loops. The test cases should unveil regression bugs on these cases. To some extend do_random_tests in string/test-strnlen tests strings placed at page end but it does not cover all cases. So this change adds tests which consists of placing strings of varying sizes ending at the page boundary. It also combines with different values of maxlen. Tested on ppc64le and x86_64. * string/test-strnlen.c (do_page_tests): New function to check length of strings ending at the page boundary. (test_main): Added call to the do_page_tests function.
2017-03-29Fix i686 memchr overflow calculation (BZ#21182)Adhemerval Zanella
This patch fixes the regression added by 23d2770 for final address overflow calculation. The subtraction of the considered size (16) at line 120 is at wrong place, for sizes less than 16 subsequent overflow check will not take in consideration an invalid size (since the subtraction will be negative). Also, the lea instruction also does not raise the carry flag (CF) that is used in subsequent jbe to check for overflow. The fix is to follow x86_64 logic from 3daef2c where the overflow is first check and a sub instruction is issued. In case of resulting negative size, CF will be set by the sub instruction and a NULL result will be returned. The patch also add similar tests reported in bug report. Checked on i686-linux-gnu and x86_64-linux-gnu. * string/test-memchr.c (do_test): Add BZ#21182 checks for address near end of a page. * sysdeps/i386/i686/multiarch/memchr-sse2.S (__memchr): Fix overflow calculation.
2017-03-23Update string tests to use the support test driver.Wainer dos Santos Moschetta
Replaced all imports of test-skeleton.c with support/test-driver.c. In some cases it was needed to adjust do_test to return int instead of static int since that is the method's signature expected by test-driver.c. Checked on x86_64. * string/test-string.h (TEST_FUNCTION): Use test_main instead of test_main (). (CMDLINE_PROCESS): Use function instead of defined macro. * debug/test-strcpy_chk.c: Import support/test-driver.c and also <suppport/support.h> to use set_fortify_handler(). * string/bug-envz1.c: Import support/test-driver.c instead of test-skeleton.c. * string/bug-strcoll2.c: Likewise. * string/bug-strtok1.c: Likewise. * string/stratcliff.c: Likewise. * string/test-ffs.c: Likewise. * string/test-memccpy.c: Likewise. * string/test-memchr.c: Likewise. * string/test-memcmp.c: Likewise. * string/test-memcpy.c: Likewise. * string/test-memmem.c: Likewise. * string/test-memmove.c: Likewise. * string/test-memrchr.c: Likewise. * string/test-memset.c: Likewise. * string/test-rawmemchr.c: Likewise. * string/test-strcasecmp.c: Likewise. * string/test-strcasestr.c: Likewise. * string/test-strcat.c: Likewise. * string/test-strchr.c: Likewise. * string/test-strcmp.c: Likewise. * string/test-strcpy.c: Likewise. * string/test-string.h: Likewise. * string/test-strlen.c: Likewise. * string/test-strncasecmp.c: Likewise. * string/test-strncat.c: Likewise. * string/test-strncmp.c: Likewise. * string/test-strncpy.c: Likewise. * string/test-strnlen.c: Likewise. * string/test-strpbrk.c: Likewise. * string/test-strrchr.c: Likewise. * string/test-strspn.c: Likewise. * string/test-strstr.c: Likewise. * string/tst-bswap.c: Likewise. * string/tst-cmp.c: Likewise. * string/tst-endian.c: Likewise. * string/tst-inlcall.c: Likewise. * string/tst-strcoll-overflow.c: Likewise. * string/tst-strfry.c: Likewise. * string/tst-strlen.c: Likewise. * string/tst-strtok.c: Likewise. * string/tst-strtok_r.c: Likewise. * string/tst-strxfrm.c: Likewise. * string/tst-strxfrm2.c: Likewise. * string/tst-svc.c: Likewise. * string/tst-svc2.c: Likewise.
2017-03-16Remove C++ namespace handling from glibc headers.Joseph Myers
glibc headers include some code (not particularly consistent or systematic) to put various declarations in C++ namespaces std and __c99, if _GLIBCPP_USE_NAMESPACES is defined. As noted in <https://gcc.gnu.org/ml/libstdc++/2017-03/msg00025.html>, this macro was removed from libstdc++ in 2000. I don't expect compilation with such old versions of libstdc++ to work with current glibc headers anyway (whereas old *binaries* are expected to stay working with current glibc); this patch (which should be a no-op with any libstdc++ version postdating that removal) removes all this code from the glibc headers. The begin-end-check.pl test, whose comments say it is about checking these namespace macro calls, is also removed. The code in that test would have covered __BEGIN_DECLS / __END_DECLS as well, but if those weren't properly matched it would show up with the check-installed-headers-cxx tests, so I don't think there is an actual use for keeping begin-end-check.pl with the namespace code removed. Tested for x86_64 and x86 (testsuite, and that installed stripped shared libraries are unchanged by the patch). * misc/sys/cdefs.h (__BEGIN_NAMESPACE_STD): Remove macro. (__END_NAMESPACE_STD): Likewise. (__USING_NAMESPACE_STD): Likewise. (__BEGIN_NAMESPACE_C99): Likewise. (__END_NAMESPACE_C99): Likewise. (__USING_NAMESPACE_C99): Likewise. * math/math.h (_Mdouble_BEGIN_NAMESPACE): Do not define and undefine macro. (_Mdouble_END_NAMESPACE): Likewise. * ctype/ctype.h: Do not handle C++ namespaces. * libio/bits/stdio-ldbl.h: Likewise. * libio/stdio.h: Likewise. * locale/locale.h: Likewise. * math/bits/mathcalls.h: Likewise. * setjmp/setjmp.h: Likewise. * signal/signal.h: Likewise. * stdlib/bits/stdlib-float.h: Likewise. * stdlib/bits/stdlib-ldbl.h: Likewise. * stdlib/stdlib.h: Likewise. * string/string.h: Likewise. * sysdeps/x86/fpu/bits/mathinline.h: Likewise. * time/bits/types/clock_t.h: Likewise. * time/bits/types/struct_tm.h: Likewise. * time/bits/types/time_t.h: Likewise. * time/time.h: Likewise. * wcsmbs/bits/wchar-ldbl.h: Likewise. * wcsmbs/uchar.h: Likewise. * wcsmbs/wchar.h: Likewise. [_GLIBCPP_USE_NAMESPACES] (wint_t): Remove conditional definition. * wctype/wctype.h: Do not handle C++ namespaces. * scripts/begin-end-check.pl: Remove. * Makefile (installed-headers): Likewise. (tests-special): Do not add $(objpfx)begin-end-check.out. ($(objpfx)begin-end-check.out): Remove.
2017-03-13 Remove the str(n)dup inlines from string/bits/string2.h. Although inliningWilco Dijkstra
calls with constant strings shows a small (~10%) performance gain, strdup is typically used in error reporting code, so not performance critical. Remove the now unused __need_malloc_and_calloc related defines from stdlib.h. Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt or linkname space failures (partial fix for BZ #15105 and BZ #19463). [BZ #15105] [BZ #19463] * elf/dl-cache.c (_dl_load_cache_lookup): Use __strdup. * inet/rcmd.c (rcmd_af): Likewise. * inet/rexec.c (rexec_af): Likewise. * intl/dcigettext.c (_LIBC): Likewise. * intl/finddomain.c (_nl_find_domain): Use strdup expansion. * locale/loadarchive.c (_nl_load_locale_from_archive): Use __strdup. * locale/setlocale.c (setlocale): Likewise. * posix/spawn_faction_addopen.c (posix_spawn_file_actions_addopen): Likewise. * stdlib/putenv.c (putenv): Use __strndup. * sunrpc/svc_simple.c (__registerrpc): Use __strdup. * sysdeps/posix/getaddrinfo.c (gaih_inet): Use __strdup/__strndup. * include/stdlib.h (__need_malloc_and_calloc): Remove uses. (__Need_M_And_C) Remove define/undef. * stdlib/stdlib.h (__need_malloc_and_calloc): Remove uses. (__malloc_and_calloc_defined): Remove define. * string/bits/string2.h (__strdup): Remove define. (strdup): Likewise. (__strndup): Likewise. (strndup): Likewise.
2017-03-01Narrowing the visibility of libc-internal.h even further.Zack Weinberg
posix/wordexp-test.c used libc-internal.h for PTR_ALIGN_DOWN; similar to what was done with libc-diag.h, I have split the definitions of cast_to_integer, ALIGN_UP, ALIGN_DOWN, PTR_ALIGN_UP, and PTR_ALIGN_DOWN to a new header, libc-pointer-arith.h. It then occurred to me that the remaining declarations in libc-internal.h are mostly to do with early initialization, and probably most of the files including it, even in the core code, don't need it anymore. Indeed, only 19 files actually need what remains of libc-internal.h. 23 others need libc-diag.h instead, and 12 need libc-pointer-arith.h instead. No file needs more than one of them, and 16 don't need any of them! So, with this patch, libc-internal.h stops including libc-diag.h as well as losing the pointer arithmetic macros, and all including files are adjusted. * include/libc-pointer-arith.h: New file. Define cast_to_integer, ALIGN_UP, ALIGN_DOWN, PTR_ALIGN_UP, and PTR_ALIGN_DOWN here. * include/libc-internal.h: Definitions of above macros moved from here. Don't include libc-diag.h anymore either. * posix/wordexp-test.c: Include stdint.h and libc-pointer-arith.h. Don't include libc-internal.h. * debug/pcprofile.c, elf/dl-tunables.c, elf/soinit.c, io/openat.c * io/openat64.c, misc/ptrace.c, nptl/pthread_clock_gettime.c * nptl/pthread_clock_settime.c, nptl/pthread_cond_common.c * string/strcoll_l.c, sysdeps/nacl/brk.c * sysdeps/unix/clock_settime.c * sysdeps/unix/sysv/linux/i386/get_clockfreq.c * sysdeps/unix/sysv/linux/ia64/get_clockfreq.c * sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c * sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c: Don't include libc-internal.h. * elf/get-dynamic-info.h, iconv/loop.c * iconvdata/iso-2022-cn-ext.c, locale/weight.h, locale/weightwc.h * misc/reboot.c, nis/nis_table.c, nptl_db/thread_dbP.h * nscd/connections.c, resolv/res_send.c, soft-fp/fmadf4.c * soft-fp/fmasf4.c, soft-fp/fmatf4.c, stdio-common/vfscanf.c * sysdeps/ieee754/dbl-64/e_lgamma_r.c * sysdeps/ieee754/dbl-64/k_rem_pio2.c * sysdeps/ieee754/flt-32/e_lgammaf_r.c * sysdeps/ieee754/flt-32/k_rem_pio2f.c * sysdeps/ieee754/ldbl-128/k_tanl.c * sysdeps/ieee754/ldbl-128ibm/k_tanl.c * sysdeps/ieee754/ldbl-96/e_lgammal_r.c * sysdeps/ieee754/ldbl-96/k_tanl.c, sysdeps/nptl/futex-internal.h: Include libc-diag.h instead of libc-internal.h. * elf/dl-load.c, elf/dl-reloc.c, locale/programs/locarchive.c * nptl/nptl-init.c, string/strcspn.c, string/strspn.c * malloc/malloc.c, sysdeps/i386/nptl/tls.h * sysdeps/nacl/dl-map-segments.h, sysdeps/x86_64/atomic-machine.h * sysdeps/unix/sysv/linux/spawni.c * sysdeps/x86_64/nptl/tls.h: Include libc-pointer-arith.h instead of libc-internal.h. * elf/get-dynamic-info.h, sysdeps/nacl/dl-map-segments.h * sysdeps/x86_64/atomic-machine.h: Add multiple include guard.
2017-03-01Miscellaneous low-risk changes preparing for _ISOMAC testsuite.Zack Weinberg
These are a grab bag of changes where the testsuite was using internal symbols of some variety, but this was straightforward to fix, and the fixed code should work with or without the change to compile the testsuite under _ISOMAC. Four of these are just more #include adjustments, but I want to highlight sysdeps/powerpc/fpu/tst-setcontext-fpscr.c, which appears to have been written before the advent of sys/auxv.h. I think a big chunk of this file could be replaced by a simple call to getauxval, but I'll let someone who actually has a powerpc machine to test on do that. dlfcn/tst-dladdr.c was including ldsodefs.h just so it could use DL_LOOKUP_ADDRESS to print an additional diagnostic; as requested by Carlos, I have removed this. math/test-misc.c was using #ifndef NO_LONG_DOUBLE, which is an internal configuration macro, to decide whether to do certain tests involving 'long double'. I changed the test to #if LDBL_MANT_DIG > DBL_MANT_DIG instead, which uses only public float.h macros and is equivalent on all supported platforms. (Note that NO_LONG_DOUBLE doesn't mean 'the compiler doesn't support long double', it means 'long double is the same as double'.) tst-writev.c has a configuration macro 'ARTIFICIAL_LIMIT' that the Makefiles are expected to define, and sysdeps/unix/sysv/linux/Makefile was using the internal __getpagesize in the definition; changed to sysconf(_SC_PAGESIZE) which is the POSIX equivalent. ia64-linux doesn't supply 'clone', only '__clone2', which is not defined in the public headers(!) All the other clone tests have local extern declarations of __clone2, but tst-clone.c doesn't; it was getting away with this because include/sched.h does declare __clone2. * nss/tst-cancel-getpwuid_r.c: Include nss.h. * string/strcasestr.c: No need to include config.h. * sysdeps/powerpc/fpu/tst-setcontext-fpscr.c: Include sys/auxv.h. Don't include sysdep.h. * sysdeps/powerpc/tst-set_ppr.c: Don't include dl-procinfo.h. * dlfcn/tst-dladdr.c: Don't include ldsodefs.h. Don't use DL_LOOKUP_ADDRESS. * math/test-misc.c: Instead of testing NO_LONG_DOUBLE, test whether LDBL_MANT_DIG is greater than DBL_MANT_DIG. * sysdeps/unix/sysv/linux/Makefile (CFLAGS-tst-writev.c): Use sysconf (_SC_PAGESIZE) instead of __getpagesize in definition of ARTIFICIAL_LIMIT. * sysdeps/unix/sysv/linux/tst-clone.c [__ia64__]: Add extern declaration of __clone2.
2017-02-25Split DIAG_* macros to new header libc-diag.h.Zack Weinberg
Quite a few tests include libc-internal.h just for the DIAG_* macros. Split those macros to their own file, which can be included safely in _ISOMAC mode. I also moved ignore_value, since it seems logically related, even though I didn't notice any tests needing it. Also add -Wnonnull suppressions to two tests that _should_ have them, but the error is masked when compiling against internal headers. * include/libc-diag.h: New file. Define ignore_value, DIAG_PUSH_NEEDS_COMMENT, DIAG_POP_NEEDS_COMMENT, DIAG_IGNORE_NEEDS_COMMENT, and DIAG_IGNORE_Os_NEEDS_COMMENT here. * include/libc-internal.h: Definitions of above macros moved from here. Include libc-diag.h. Add copyright notice. * malloc/tst-malloc.c, malloc/tst-memcheck.c, malloc/tst-realloc.c * misc/tst-error1.c, posix/tst-dir.c, stdio-common/bug21.c * stdio-common/scanf14.c, stdio-common/scanf4.c, stdio-common/scanf7.c * stdio-common/test-vfprintf.c, stdio-common/tst-printf.c * stdio-common/tst-printfsz.c, stdio-common/tst-sprintf.c * stdio-common/tst-unlockedio.c, stdio-common/tstdiomisc.c * stdlib/bug-getcontext.c, string/tester.c, string/tst-endian.c * time/tst-strptime2.c, wcsmbs/tst-wcstof.c: Include libc-diag.h instead of libc-internal.h. * stdlib/tst-environ.c: Include libc-diag.h. Suppress -Wnonnull for call to unsetenv (NULL). * nptl/tst-mutex1.c: Include libc-diag.h. Suppress -Wnonnull for call to pthread_mutexattr_destroy (NULL).
2017-02-16Add missing header files throughout the testsuite.Zack Weinberg
* crypt/md5.h: Test _LIBC with #if defined, not #if. * dirent/opendir-tst1.c: Include sys/stat.h. * dirent/tst-fdopendir.c: Include sys/stat.h. * dirent/tst-fdopendir2.c: Include stdlib.h. * dirent/tst-scandir.c: Include stdbool.h. * elf/tst-auditmod1.c: Include link.h and stddef.h. * elf/tst-tls15.c: Include stdlib.h. * elf/tst-tls16.c: Include stdlib.h. * elf/tst-tls17.c: Include stdlib.h. * elf/tst-tls18.c: Include stdlib.h. * iconv/tst-iconv6.c: Include endian.h. * iconvdata/bug-iconv11.c: Include limits.h. * io/test-utime.c: Include stdint.h. * io/tst-faccessat.c: Include sys/stat.h. * io/tst-fchmodat.c: Include sys/stat.h. * io/tst-fchownat.c: Include sys/stat.h. * io/tst-fstatat.c: Include sys/stat.h. * io/tst-futimesat.c: Include sys/stat.h. * io/tst-linkat.c: Include sys/stat.h. * io/tst-mkdirat.c: Include sys/stat.h and stdbool.h. * io/tst-mkfifoat.c: Include sys/stat.h and stdbool.h. * io/tst-mknodat.c: Include sys/stat.h and stdbool.h. * io/tst-openat.c: Include stdbool.h. * io/tst-readlinkat.c: Include sys/stat.h. * io/tst-renameat.c: Include sys/stat.h. * io/tst-symlinkat.c: Include sys/stat.h. * io/tst-unlinkat.c: Include stdbool.h. * libio/bug-memstream1.c: Include stdlib.h. * libio/bug-wmemstream1.c: Include stdlib.h. * libio/tst-fwrite-error.c: Include stdlib.h. * libio/tst-memstream1.c: Include stdlib.h. * libio/tst-memstream2.c: Include stdlib.h. * libio/tst-memstream3.c: Include stdlib.h. * malloc/tst-interpose-aux.c: Include stdint.h. * misc/tst-preadvwritev-common.c: Include sys/stat.h. * nptl/tst-basic7.c: Include limits.h. * nptl/tst-cancel25.c: Include pthread.h, not pthreadP.h. * nptl/tst-cancel4.c: Include stddef.h, limits.h, and sys/stat.h. * nptl/tst-cancel4_1.c: Include stddef.h. * nptl/tst-cancel4_2.c: Include stddef.h. * nptl/tst-cond16.c: Include limits.h. Use sysconf(_SC_PAGESIZE) instead of __getpagesize. * nptl/tst-cond18.c: Include limits.h. Use sysconf(_SC_PAGESIZE) instead of __getpagesize. * nptl/tst-cond4.c: Include stdint.h. * nptl/tst-cond6.c: Include stdint.h. * nptl/tst-stack2.c: Include limits.h. * nptl/tst-stackguard1.c: Include stddef.h. * nptl/tst-tls4.c: Include stdint.h. Don't include tls.h. * nptl/tst-tls4moda.c: Include stddef.h. Don't include stdio.h, unistd.h, or tls.h. * nptl/tst-tls4modb.c: Include stddef.h. Don't include stdio.h, unistd.h, or tls.h. * nptl/tst-tls5.h: Include stddef.h. Don't include stdlib.h or tls.h. * posix/tst-getaddrinfo2.c: Include stdio.h. * posix/tst-getaddrinfo5.c: Include stdio.h. * posix/tst-pathconf.c: Include sys/stat.h. * posix/tst-posix_fadvise-common.c: Include stdint.h. * posix/tst-preadwrite-common.c: Include sys/stat.h. * posix/tst-regex.c: Include stdint.h. Don't include spawn.h or spawn_int.h. * posix/tst-regexloc.c: Don't include spawn.h or spawn_int.h. * posix/tst-vfork3.c: Include sys/stat.h. * resolv/tst-bug18665-tcp.c: Include stdlib.h. * resolv/tst-res_hconf_reorder.c: Include stdlib.h. * resolv/tst-resolv-search.c: Include stdlib.h. * stdio-common/tst-fmemopen2.c: Include stdint.h. * stdio-common/tst-vfprintf-width-prec.c: Include stdlib.h. * stdlib/test-canon.c: Include sys/stat.h. * stdlib/tst-tls-atexit.c: Include stdbool.h. * string/test-memchr.c: Include stdint.h. * string/tst-cmp.c: Include stdint.h. * sysdeps/pthread/tst-timer.c: Include stdint.h. * sysdeps/unix/sysv/linux/tst-sync_file_range.c: Include stdint.h. * sysdeps/wordsize-64/tst-writev.c: Include limits.h and stdint.h. * sysdeps/x86_64/fpu/math-tests-arch.h: Include cpu-features.h. Don't include init-arch.h. * sysdeps/x86_64/multiarch/test-multiarch.h: Include cpu-features.h. Don't include init-arch.h. * sysdeps/x86_64/tst-auditmod10b.c: Include link.h and stddef.h. * sysdeps/x86_64/tst-auditmod3b.c: Include link.h and stddef.h. * sysdeps/x86_64/tst-auditmod4b.c: Include link.h and stddef.h. * sysdeps/x86_64/tst-auditmod5b.c: Include link.h and stddef.h. * sysdeps/x86_64/tst-auditmod6b.c: Include link.h and stddef.h. * sysdeps/x86_64/tst-auditmod6c.c: Include link.h and stddef.h. * sysdeps/x86_64/tst-auditmod7b.c: Include link.h and stddef.h. * time/clocktest.c: Include stdint.h. * time/tst-posixtz.c: Include stdint.h. * timezone/tst-timezone.c: Include stdint.h.
2017-02-16Clean up redundancies between string.h and strings.h.Zack Weinberg
* string/string.h [__USE_MISC]: Include strings.h. (__bzero, bcmp, bcopy, bzero, index, rindex) (strcasecmp, strncasecmp, strcasecmp_l, strncasecmp_l) (ffs, ffsl, ffsll): Don't declare. * string/strings.h: Do not suppress the file if string.h has already been included. (bcmp, bcopy, bzero, strcasecmp, strncasecmp): Add __nonnull annotations. (index, rindex): Define inline forwarders even if __CORRECT_ISO_CPP_STRING_H_PROTO is defined. (ffs): Use __attribute_const__. (ffsl, ffsll): Declare here. (strcasecmp_l, strncasecmp_l): Correct comments; these functions have now been standardized. * include/string.h (__bzero): Declare here.
2017-02-15Remove the str(n)cmp inlines from string/bits/string2.h. The strncmpWilco Dijkstra
optimization seems unlikely to ever be useful, but if it occurs in real code it should be added to GCC. Expanding strcmp of small strings does appear useful (benchmarking shows it is 2-3x faster), so this would be useful to implement in GCC (PR 78809). * string/bits/string2.h (strcmp): Remove define. (__strcmp_cg): Likewise. (strncmp): Likewise.
2017-02-10GLIBC uses strchr (s, '\0') as an idiom to find the end of a string.Wilco Dijkstra
This is transformed into rawmemchr by the bits/string2.h header. However this is generally slower than strlen on most targets, even when an optimized rawmemchr implementation exists. Since GCC7 optimizes strchr (s, '\0') to strlen (s) + s, the GLIBC headers should not transform this to rawmemchr. As GCC recognizes strchr as a builtin, defining strchr as the builtin is not useful. * string/bits/string2.h (strchr): Remove define.