about summary refs log tree commit diff
path: root/string
Commit message (Collapse)AuthorAgeFilesLines
* string: Sort headers, routines, tests and tests-translationH.J. Lu2022-02-051-44/+166
| | | | | Sort headers, routines, tests and tests-translation. Put one entry per line.
* string: Improve coverage in test-strcmp.c and test-strncmp.cNoah Goldstein2022-02-032-21/+306
| | | | | | | | | Add additional test cases for small / medium sizes. Add tests in test-strncmp.c where `n` is near ULONG_MAX or LONG_MIN to test for overflow bugs in length handling. Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string/test-str*cmp: remove stupid_[strcmp, strncmp, wcscmp, wcsncmp].Noah Goldstein2022-02-032-69/+0
| | | | | | | | These implementations just add to test duration. Since we have simple_* implementations we already have a safe reference implementation. Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
* debug: Synchronize feature guards in fortified functions [BZ #28746]Siddhesh Poyarekar2022-01-121-3/+5
| | | | | | | | | | | | | | | | | | Some functions (e.g. stpcpy, pread64, etc.) had moved to POSIX in the main headers as they got incorporated into the standard, but their fortified variants remained under __USE_GNU. As a result, these functions did not get fortified when _GNU_SOURCE was not defined. Add test wrappers that check all functions tested in tst-chk0 at all levels with _GNU_SOURCE undefined and then use the failures to (1) exclude checks for _GNU_SOURCE functions in these tests and (2) Fix feature macro guards in the fortified function headers so that they're the same as the ones in the main headers. This fixes BZ #28746. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Update copyright dates with scripts/update-copyrightsPaul Eggert2022-01-01143-143/+143
| | | | | | | | | | | | | | | | | | | | | | | I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 7061 files FOO. I then removed trailing white space from math/tgmath.h, support/tst-support-open-dev-null-range.c, and sysdeps/x86_64/multiarch/strlen-vec.S, to work around the following obscure pre-commit check failure diagnostics from Savannah. I don't know why I run into these diagnostics whereas others evidently do not. remote: *** 912-#endif remote: *** 913: remote: *** 914- remote: *** error: lines with trailing whitespace found ... remote: *** error: sysdeps/unix/sysv/linux/statx_cp.c: trailing lines
* String: test-memcpy used unaligned types for buffers [BZ 28572]John David Anglin2021-12-071-2/+3
| | | | | | | | | | | | | | | | | | | | | commit d585ba47fcda99fdf228e3e45a01b11a15efbc5a Author: Noah Goldstein <goldstein.w.n@gmail.com> Date: Mon Nov 1 00:49:48 2021 -0500 string: Make tests birdirectional test-memcpy.c Add tests that had src/dst non 4-byte aligned. Since src/dst are initialized/compared as uint32_t type which is 4-byte aligned this can break on some targets. Fix the issue by specifying a new non-aligned 4-byte `unaligned_uint32_t` for src/dst. Another alternative is to rely on memcpy/memcmp for initializing/testing src/dst. Using memcpy for initializing in memcpy tests, however, could lead to future bugs. Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* x86-64: Use notl in EVEX strcmp [BZ #28646]Noah Goldstein2021-12-031-0/+28
| | | | | | | | Must use notl %edi here as lower bits are for CHAR comparisons potentially out of range thus can be 0 without indicating mismatch. This fixes BZ #28646. Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
* String: Split memcpy tests so that parallel build is fasterNoah Goldstein2021-11-104-298/+367
| | | | | | | | | | | No bug. This commit splits test-memcpy.c into test-memcpy.c and test-memcpy-large.c. The idea is parallel builds will be able to run both in parallel speeding up the process. Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* test-memcpy.c: Double TIMEOUT to (8 * 60)H.J. Lu2021-11-072-1/+4
| | | | | | | | | | | | | | | | | | | | | commit d585ba47fcda99fdf228e3e45a01b11a15efbc5a Author: Noah Goldstein <goldstein.w.n@gmail.com> Date: Mon Nov 1 00:49:48 2021 -0500 string: Make tests birdirectional test-memcpy.c This commit updates the memcpy tests to test both dst > src and dst < src. This is because there is logic in the code based on the Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com> Reviewed-by: H.J. Lu <hjl.tools@gmail.com> significantly increased the number of tests. On Intel Core i7-1165G7, test-memcpy takes 120 seconds to run when machine is idle. Double TIMEOUT to (8 * 60) for test-memcpy to avoid timeout when machine is under heavy load. Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Make tests birdirectional test-memcpy.cNoah Goldstein2021-11-062-28/+214
| | | | | | | | This commit updates the memcpy tests to test both dst > src and dst < src. This is because there is logic in the code based on the Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* String: Add __memcmpeq as build targetNoah Goldstein2021-10-272-1/+25
| | | | | | No bug. This commit just adds __memcmpeq as a build target so that implementations for __memcmpeq that are not just aliases to memcmp can be supported.
* String: Add tests for __memcmpeqNoah Goldstein2021-10-263-14/+45
| | | | | | | | | | No bug. This commit adds tests for the new function __memcmpeq. The new tests use the existing tests in 'test-memcmp.c' but relax the result requirement to only check for zero or non-zero returns. All string tests include test-memcmpeq are passing.
* String: Add hidden defs for __memcmpeq() to enable internal usageNoah Goldstein2021-10-261-0/+1
| | | | | | | | No bug. This commit adds hidden defs for all declarations of __memcmpeq. This enables usage of __memcmpeq without the PLT for usage internal to GLIBC.
* String: Add support for __memcmpeq() ABI on all targetsNoah Goldstein2021-10-264-0/+38
| | | | | | | | | | | | | | | | | | | | | | | | | No bug. This commit adds support for __memcmpeq() as a new ABI for all targets. In this commit __memcmpeq() is implemented only as an alias to the corresponding targets memcmp() implementation. __memcmpeq() is added as a new symbol starting with GLIBC_2.35 and defined in string.h with comments explaining its behavior. Basic tests that it is callable and works where added in string/tester.c As discussed in the proposal "Add new ABI '__memcmpeq()' to libc" __memcmpeq() is essentially a reserved namespace for bcmp(). The means is shares the same specifications as memcmp() except the return value for non-equal byte sequences is any non-zero value. This is less strict than memcmp()'s return value specification and can be better optimized when a boolean return is all that is needed. __memcmpeq() is meant to only be called by compilers if they can prove that the return value of a memcmp() call is only used for its boolean value. All tests in string/tester.c passed. As well build succeeds on x86_64-linux-gnu target.
* Correct access attribute on memfrob (bug 28475)Joseph Myers2021-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | As noted in bug 28475, the access attribute on memfrob in <string.h> is incorrect: the function both reads and writes the memory pointed to by its argument, so it needs to use __read_write__, not __write_only__. This incorrect attribute results in a build failure for accessing uninitialized memory for s390x-linux-gnu-O3 with build-many-glibcs.py using GCC mainline. Correct the attribute. Fixing this shows up that some calls to memfrob in elf/ tests are reading uninitialized memory; I'm not entirely sure of the purpose of those calls, but guess they are about ensuring that the stack space is indeed allocated at that point in the function, and so it matters that they are calling a function whose semantics are unknown to the compiler. Thus, change the first memfrob call in those tests to use explicit_bzero instead, as suggested by Florian in <https://sourceware.org/pipermail/libc-alpha/2021-October/132119.html>, to avoid the use of uninitialized memory. Tested for x86_64, and with build-many-glibcs.py (GCC mainline) for s390x-linux-gnu-O3.
* Don't add access size hints to fortifiable functionsSiddhesh Poyarekar2021-10-202-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the context of a function definition, the size hints imply that the size of an object pointed to by one parameter is another parameter. This doesn't make sense for the fortified versions of the functions since that's the bit it's trying to validate. This is harmless with __builtin_object_size since it has fairly simple semantics when it comes to objects passed as function parameters. With __builtin_dynamic_object_size we could (as my patchset for gcc[1] already does) use the access attribute to determine the object size in the general case but it misleads the fortified functions. Basically the problem occurs when access attributes are present on regular functions that have inline fortified definitions to generate _chk variants; the attributes get inherited by these definitions, causing problems when analyzing them. For example with poll(fds, nfds, timeout), nfds is hinted using the __attr_access as being the size of fds. Now, when analyzing the inline function definition in bits/poll2.h, the compiler sees that nfds is the size of fds and tries to use that information in the function body. In _FORTIFY_SOURCE=3 case, where the object size could be a non-constant expression, this information results in the conclusion that nfds is the size of fds, which defeats the purpose of the implementation because we're trying to check here if nfds does indeed represent the size of fds. Hence for this case, it is best to not have the access attribute. With the attributes gone, the expression evaluation should get delayed until the function is actually inlined into its destinations. Disable the access attribute for fortified function inline functions when building at _FORTIFY_SOURCE=3 to make this work better. The access attributes remain for the _chk variants since they can be used by the compiler to warn when the caller is passing invalid arguments. [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581125.html Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* Remove "Contributed by" linesSiddhesh Poyarekar2021-09-0361-71/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | We stopped adding "Contributed by" or similar lines in sources in 2012 in favour of git logs and keeping the Contributors section of the glibc manual up to date. Removing these lines makes the license header a bit more consistent across files and also removes the possibility of error in attribution when license blocks or files are copied across since the contributed-by lines don't actually reflect reality in those cases. Move all "Contributed by" and similar lines (Written by, Test by, etc.) into a new file CONTRIBUTED-BY to retain record of these contributions. These contributors are also mentioned in manual/contrib.texi, so we just maintain this additional record as a courtesy to the earlier developers. The following scripts were used to filter a list of files to edit in place and to clean up the CONTRIBUTED-BY file respectively. These were not added to the glibc sources because they're not expected to be of any use in future given that this is a one time task: https://gist.github.com/siddhesh/b5ecac94eabfd72ed2916d6d8157e7dc https://gist.github.com/siddhesh/15ea1f5e435ace9774f485030695ee02 Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Fix error message in memmove test to display correct src pointerSunil K Pandey2021-08-261-1/+1
| | | | Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* Update string/test-memmove.c to cover 16KB copyH.J. Lu2021-08-201-0/+48
|
* tests: use xmalloc to allocate implementation arraySiddhesh Poyarekar2021-07-281-2/+3
| | | | | | | | The benchmark and tests must fail in case of allocation failure in the implementation array. Also annotate the x* allocators in support.h so that the compiler has more information about them. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* String: Add three more overflow tests cases to test-strnlen.cNoah Goldstein2021-06-241-0/+4
| | | | | | | | No bug. Just seem like relevant cases given that strnlen will use s + maxlen in many implementations. Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* String: Add overflow tests for strnlen, memchr, and strncat [BZ #27974]Noah Goldstein2021-06-233-3/+130
| | | | | | | | | | | | | | | | | | | | | | This commit adds tests for a bug in the wide char variant of the functions where the implementation may assume that maxlen for wcsnlen or n for wmemchr/strncat will not overflow when multiplied by sizeof(wchar_t). These tests show the following implementations failing on x86_64: wcsnlen-sse4_1 wcsnlen-avx2 wmemchr-sse2 wmemchr-avx2 strncat would fail as well if it where on a system that prefered either of the wcsnlen implementations that failed as it relies on wcsnlen. Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* Improve test coverage of strnlen functionSunil K Pandey2021-06-031-1/+10
| | | | | | | | | This patch covers the following condition: Strings start with different alignments and end with length less than or equal to 512 byte. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* dlfcn: Cleanups after -ldl is no longer requiredFlorian Weimer2021-06-031-1/+0
| | | | | | | | | | | | This commit removes the ELF constructor and internal variables from dlfcn/dlfcn.c. The file now serves the same purpose as nptl/libpthread-compat.c, so it is renamed to dlfcn/libdl-compat.c. The use of libdl-shared-only-routines ensures that libdl.a is empty. This commit adjusts the test suite not to use $(libdl). The libdl.so symbolic link is no longer installed. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Improve test coverage of strlen functionSunil K Pandey2021-06-021-1/+14
| | | | | | | | | | | This patch covers the following conditions: - Strings start with different alignments and end at the page boundary with less than 64 byte length. - Strings starts with different alignments and cross page boundary with fixed length. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* x86: Expand bench-memcmp.c and test-memcmp.cNoah Goldstein2021-05-181-6/+34
| | | | | | | | | | | No bug. This commit adds some additional performance test cases to bench-memcmp.c and test-memcmp.c. The new benchtests include some medium range sizes, as well as small sizes near page cross. The new correctness tests correspond with the new benchtests though add some additional cases for checking the page cross logic. Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* Reindent string/test-memmove.cH.J. Lu2021-04-191-15/+15
|
* x86: Expand test-memset.c and bench-memset.cNoah Goldstein2021-04-191-5/+15
| | | | | | | | | No bug. This commit adds tests cases and benchmarks for page cross and for memset to the end of the page without crossing. As well in test-memset.c this commit adds sentinel on start/end of tstbuf to test for overwrites Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
* x86: Expanding test-memmove.c, test-memcpy.c, bench-memcpy-large.cnoah2021-04-162-53/+76
| | | | | | | | | | | | No Bug. This commit expanding the range of tests / benchmarks for memmove and memcpy. The test expansion is mostly in the vein of increasing the maximum size, increasing the number of unique alignments tested, and testing both source < destination and vice versa. The benchmark expansaion is just to increase the number of unique alignments. test-memcpy, test-memccpy, test-mempcpy, test-memmove, and tst-memmove-overflow all pass. Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
* test-strnlen.c: Check that strnlen won't go beyond the maximum lengthH.J. Lu2021-03-271-0/+30
| | | | | Place strings ending at page boundary without the null byte. If an implementation goes beyond EXP_LEN, it will trigger the segfault.
* test-strnlen.c: Initialize wchar_t string with wmemset [BZ #27655]H.J. Lu2021-03-271-1/+3
| | | | Use wmemset to initialize wchar_t string.
* string: Work around GCC PR 98512 in rawmemchrFlorian Weimer2021-02-191-11/+15
|
* strchr: Add additional benchmarks and testsnoah2021-02-081-1/+25
| | | | | | This patch adds additional benchmarks and tests for string size of 4096 and several benchmarks for string size 256 with different alignments.
* Update copyright dates with scripts/update-copyrightsPaul Eggert2021-01-02139-139/+139
| | | | | | | | | | | | | | | | I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 6694 files FOO. I then removed trailing white space from benchtests/bench-pthread-locks.c and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this diagnostic from Savannah: remote: *** pre-commit check failed ... remote: *** error: lines with trailing whitespace found remote: error: hook declined to update refs/heads/master
* string: Enable __FORTIFY_LEVEL=3Siddhesh Poyarekar2020-12-312-13/+22
| | | | | | This change enhances fortified string functions to use __builtin_dynamic_object_size under _FORTIFY_SOURCE=3 whenever the compiler supports it.
* treewide: fix incorrect spelling of indices in commentsDmitry V. Levin2020-12-111-1/+1
| | | | | | Replace 'indeces' with 'indices', the most annoying of these typos were those found in elf.h which is a public header file copied to other projects.
* Don't use nested function in test-ffsSiddhesh Poyarekar2020-11-121-22/+14
| | | | | There is no real need to use a nested function in that test, so break it out so that it can build with clang too.
* Use __builtin___stpncpy_chk when availableSiddhesh Poyarekar2020-11-121-1/+8
| | | | | | | | | | | | The builtin has been available in gcc since 4.7.0 and in clang since 2.6. This fixes stpncpy fortification with clang since it does a better job of plugging in __stpncpy_chk in the right place than the header hackery. This has been tested by building and running all tests with gcc 10.2.1 and also with clang tip as of a few days ago (just the tests in debug/ since running all tests don't work with clang at the moment) to make sure that both compilers pass the stpncpy tests.
* Remove __warn_memset_zero_len [BZ #25399]Siddhesh Poyarekar2020-11-051-15/+0
| | | | | | | | | | | | | | Non-gcc compilers (clang and possibly other compilers that do not masquerade as gcc 5.0 or later) are unable to use __warn_memset_zero_len since the symbol is no longer available on glibc built with gcc 5.0 or later. While it was likely an oversight that caused this omission, the fact that it wasn't noticed until recently (when clang closed the gap on _FORTIFY_SUPPORT) that the symbol was missing. Given that both gcc and clang are capable of doing this check in the compiler, drop all remaining signs of __warn_memset_zero_len from glibc so that no more objects are built with this symbol in future.
* Amend grammar and add a descriptionJonny Grant2020-10-261-3/+4
| | | | Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* strcmp: Add a testcase for page boundaryH.J. Lu2020-09-241-0/+33
| | | | | Add a strcmp testcase to cover cases where both strings end on the page boundary.
* strncmp: Add a testcase for page boundary [BZ #25933]H.J. Lu2020-09-241-0/+33
| | | | | | | | | | | | | | Add a strncmp testcase to cover cases where one of strings ends on the page boundary with the maximum string length less than the number bytes of each AVX2 loop iteration and different offsets from page boundary. The updated string/test-strncmp fails on Intel Core i7-8559U without ommit 1c6432316bc434a72108d7b0c7cfbfdde64c3124 Author: Sunil K Pandey <skpgkp1@gmail.com> Date: Fri Jun 12 08:57:16 2020 -0700 Fix avx2 strncmp offset compare condition check [BZ #25933]
* Disable -Wstringop-overread for some string testsJoseph Myers2020-09-072-0/+11
| | | | | | | | | | Similarly to Maciej's changes to fix the build of rawmemchr in the presence of GCC 11's -Wstringop-overread, also disable that option in two string function tests that have similar warnings and other string function warnings already disabled. Tested with build-many-glibcs.py for aarch64-linux-gnu and arm-linux-gnueabi that it fixes building the glibc testsuite.
* string: Fix GCC 11 `-Werror=stringop-overread' errorMaciej W. Rozycki2020-09-071-0/+4
| | | | | | | | | | | | | | | Fix a compilation error: In function '__rawmemchr', inlined from '__rawmemchr' at rawmemchr.c:27:1: rawmemchr.c:36:12: error: 'memchr' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overread] 36 | return memchr (s, c, (size_t)-1); | ^~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ../o-iterator.mk:9: recipe for target '.../string/rawmemchr.o' failed introduced with GCC 11 commit d14c547abd48 ("Add -Wstringop-overread for reading past the end by string functions.").
* string: test strncasecmp and strncpy near page boundariesRaphael Moreira Zinsly2020-08-262-0/+78
| | | | | | Add tests to check if strings placed at page boundaries are handled correctly by strncasecmp and strncpy similar to tests for strncmp and strnlen.
* string: Make tst-strerror/tst-strsignal unsupported if msgfmt is not installedAdhemerval Zanella2020-07-133-1/+14
| | | | | | | | | | | | | Without msgfmt libc.mo files are not generated and its loading failure is silent ignored with xsetlocale. Also unset LANGUAGE environment variable to avoid it taking precedence when loading the message catalog. Although not strictly required (since the test is issued with test-container and it sets a strict environment variable) it follows other tests that deal with translation. Checked on x86_64-linux-gnu.
* string: Move tst-strsignal tst-strerror to tests-containerAdhemerval Zanella2020-07-081-1/+3
| | | | | | | Both tests require libc.mo translation files which might not be installed on the system. Checked on x86_64-linux-gnu.
* string: Fix prototype mismatch in sigabbrev_np, __sigdescr_npFlorian Weimer2020-07-082-2/+2
| | | | GCC 6 does not ignore the const specifier on the return type.
* tst-strsignal: fix checking for RT signals supportSamuel Thibault2020-07-071-4/+8
| | | | | | * string/tst-strsignal.c (do_test): Actually check that RT signals are available by comparing SIGRTMAX to SIGRTMIN. Check that SIGRTMAX is 64 before testing for a message reporting 65 for SIGRTMAX+1.
* string: Add strerrorname_np and strerrordesc_npAdhemerval Zanella2020-07-075-1/+61
| | | | | | | | | | | | | | | | | The strerrorname_np returns error number name (e.g. "EINVAL" for EINVAL) while strerrordesc_np returns string describing error number (e.g "Invalid argument" for EINVAL). Different than strerror, strerrordesc_np does not attempt to translate the return description, both functions return NULL for an invalid error number. They should be used instead of sys_errlist and sys_nerr, both are thread and async-signal safe. These functions are GNU extensions. Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, and s390x-linux-gnu. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>