about summary refs log tree commit diff
path: root/string
Commit message (Collapse)AuthorAgeFilesLines
...
* x86: Fix strncat-avx2.S reading past length [BZ #30065]Noah Goldstein2023-01-311-1/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Occurs when `src` has no null-term. Two cases: 1) Zero-length check is doing: ``` test %rdx, %rdx jl L(zero_len) ``` which doesn't actually check zero (was at some point `decq` and the flag never got updated). The fix is just make the flag `jle` i.e: ``` test %rdx, %rdx jle L(zero_len) ``` 2) Length check in page-cross case checking if we should continue is doing: ``` cmpq %r8, %rdx jb L(page_cross_small) ``` which means we will continue searching for null-term if length ends at the end of a page and there was no null-term in `src`. The fix is to make the flag: ``` cmpq %r8, %rdx jbe L(page_cross_small) ```
* string: Suppress -Wmaybe-unitialized for wordcopy [BZ #19444]Adhemerval Zanella2023-01-121-0/+24
| | | | | | | | | | | | | When compiling with GCC 6+ the sparc build warns that some variables might be used uninitialized. However it does not seem the fact, since the variables are really initialized (and also other targets that use the same code, like powerpc, do not warn about it). So suppress the warning for now. Changes from v1: * Update patch description and the explanation for the suppresion. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Update copyright dates with scripts/update-copyrightsJoseph Myers2023-01-06143-143/+143
|
* string: Add len=0 to {w}memcmp{eq} tests and benchtestsNoah Goldstein2022-11-081-6/+10
| | | | | len=0 is valid and fairly common so should be tested. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* configure: Use -Wno-ignored-attributes if compiler warns about multiple aliasesAdhemerval Zanella2022-11-011-0/+9
| | | | | | | | | clang emits an warning when a double alias redirection is used, to warn the the original symbol will be used even when weak definition is overridden. However, this is a common pattern for weak_alias, where multiple alias are set to same symbol. Reviewed-by: Fangrui Song <maskray@google.com>
* Use uintptr_t in string/tester for pointer alignmentSzabolcs Nagy2022-10-281-6/+7
| | | | | | The code assumed unsigned long can represent pointers. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* String: Improve test coverage for memchrSunil K Pandey2022-10-181-0/+1
| | | | | | This test improves memchr coverage near page boundary. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* String: Improve test coverage for memchrSunil K Pandey2022-10-101-2/+5
| | | | | | This test improves memchr coverage near page boundary. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* x86: Fix wcsnlen-avx2 page cross length comparison [BZ #29591]Noah Goldstein2022-09-281-29/+41
| | | | | | | | | | | Previous implementation was adjusting length (rsi) to match bytes (eax), but since there is no bound to length this can cause overflow. Fix is to just convert the byte-count (eax) to length by dividing by sizeof (wchar_t) before the comparison. Full check passes on x86-64 and build succeeds w/ and w/o multiarch.
* Use '%z' instead of '%Z' on printf functionsAdhemerval Zanella Netto2022-09-222-3/+3
| | | | | | | | The Z modifier is a nonstandard synonymn for z (that predates z itself) and compiler might issue an warning for in invalid conversion specifier. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* x86: Fix page cross case in rawmemchr-avx2 [BZ #29234]Noah Goldstein2022-06-081-1/+56
| | | | | | | | | | | | | | | | | | | | | | | commit 6dcbb7d95dded20153b12d76d2f4e0ef0cda4f35 Author: Noah Goldstein <goldstein.w.n@gmail.com> Date: Mon Jun 6 21:11:33 2022 -0700 x86: Shrink code size of memchr-avx2.S Changed how the page cross case aligned string (rdi) in rawmemchr. This was incompatible with how `L(cross_page_continue)` expected the pointer to be aligned and would cause rawmemchr to read data start started before the beginning of the string. What it would read was in valid memory but could count CHAR matches resulting in an incorrect return value. This commit fixes that issue by essentially reverting the changes to the L(page_cross) case as they didn't really matter. Test cases added and all pass with the new code (and where confirmed to fail with the old code). Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* string.h: Fix boolean spelling in commentsH.J. Lu2022-06-031-1/+1
|
* String: Improve overflow test coverage for strnlenSunil K Pandey2022-05-251-0/+2
| | | | | | This patch adds more overflow test coverage for strnlen and wcsnlen. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* string.h: fix __fortified_attr_access macro call [BZ #29162]Sergei Trofimovich2022-05-231-1/+1
| | | | | | | | | | | | | | | | | | | | | commit e938c0274 "Don't add access size hints to fortifiable functions" converted a few '__attr_access ((...))' into '__fortified_attr_access (...)' calls. But one of conversions had double parentheses of '__fortified_attr_access (...)'. Noticed as a gnat6 build failure: /<<NIX>>-glibc-2.34-210-dev/include/bits/string_fortified.h:110:50: error: macro "__fortified_attr_access" requires 3 arguments, but only 1 given The change fixes parentheses. This is seen when using compilers that do not support __builtin___stpncpy_chk, e.g. gcc older than 4.7, clang older than 2.6 or some compiler not derived from gcc or clang. Signed-off-by: Sergei Trofimovich <slyich@gmail.com> Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* Replace {u}int_fast{16|32} with {u}int32_tNoah Goldstein2022-04-132-5/+5
| | | | | | | | | On 32-bit machines this has no affect. On 64-bit machines {u}int_fast{16|32} are set as {u}int64_t which is often not ideal. Particularly x86_64 this change both saves code size and may save instruction cost. Full xcheck passes on x86_64.
* string: Replace outdated comments in strlen().Ricardo Bittencourt2022-04-091-11/+5
| | | | | | | | | | | | | | | | | | | | | | | Copyright The GNU Toolchain Authors. The comments on strlen() don't match what the actual code does. They describe an older algorithm which is no longer in use. This change replace the old comments with new ones describing the algorithm used. I am a first time contributor, and I believe there is no need for copyright assignment, since the file changed is not in the shared source files list. This patch only changes comments, but for safety I have run the tests in my x64 ubuntu machine, with the following results: Summary of test results: 5051 PASS 80 UNSUPPORTED 16 XFAIL 6 XPASS Signed-off-by: Ricardo Bittencourt <bluepenguin@gmail.com>
* tests/string: Drop simple/stupid/builtin testsSiddhesh Poyarekar2022-04-0625-230/+43
| | | | | | | | | | | | | | | In most cases the simple/stupid/builtin functions were in there to benchmark optimized implementations against. Only in some cases the functions are used to check expected results. Remove these tests from IMPL() and only keep them in wherever they're used for a specific purpose, e.g. to generate expected results. This improves timing of `make subdirs=string` by over a minute and a half (over 15%) on a Whiskey Lake laptop. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: Noah Goldstein <libc-alpha@sourceware.org>
* test-memcpy: Actually reverse source and destinationSiddhesh Poyarekar2022-04-061-22/+24
| | | | | | | | Looks like an oversight in memcpy tests resulted in s2 and s1 not being swapped for the second iteration of the memcpy test. Fix it. Also fix a formatting nit. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* Increase the test timeout of some string testsSzabolcs Nagy2022-04-012-0/+2
| | | | | | Recent changes in test-strncasecmp and test-strncmp pushed the run time of the tests above the 4 minute limit specified in test-string.h on an arm tester machine.
* string: Expand page cross test cases in test-strncmp.cNoah Goldstein2022-03-251-1/+26
| | | | | | Test cases for when both `s1` and `s2` are near the end of a page where previously missing. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* string: Expand page cross test cases in test-strcmp.cNoah Goldstein2022-03-251-1/+14
| | | | | | Test cases for when both `s1` and `s2` are near the end of a page where previously missing. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* string: Expand page cross tests in test-strncasecmp.cNoah Goldstein2022-03-251-12/+154
| | | | | Add more robust tests that cover all the page cross edge cases. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* string: Expand page cross tests in test-strcasecmp.cNoah Goldstein2022-03-251-12/+100
| | | | | Add more robust tests that cover all the page cross edge cases. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* ia64: Remove bzero optimizationAdhemerval Zanella2022-02-231-2/+2
| | | | | | | The symbol is not present current POSIX specification and compiler already generates memset call. The arch specific implementation is just to avoid the __bzero symbol creation (which ia64 abi does not export).
* string: Add a testcase for wcsncmp with SIZE_MAX [BZ #28755]H.J. Lu2022-02-171-0/+13
| | | | | | | | | | | | | | | | | | | | | | | Verify that wcsncmp (L("abc"), L("abd"), SIZE_MAX) == 0. The new test fails without commit ddf0992cf57a93200e0c782e2a94d0733a5a0b87 Author: Noah Goldstein <goldstein.w.n@gmail.com> Date: Sun Jan 9 16:02:21 2022 -0600 x86: Fix __wcsncmp_avx2 in strcmp-avx2.S [BZ# 28755] and commit 7e08db3359c86c94918feb33a1182cd0ff3bb10b Author: Noah Goldstein <goldstein.w.n@gmail.com> Date: Sun Jan 9 16:02:28 2022 -0600 x86: Fix __wcsncmp_evex in strcmp-evex.S [BZ# 28755] This is for BZ #28755. Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
* x86: Fix bug in strncmp-evex and strncmp-avx2 [BZ #28895]Noah Goldstein2022-02-161-0/+23
| | | | | | | | | | | | | Logic can read before the start of `s1` / `s2` if both `s1` and `s2` are near the start of a page. To avoid having the result contimated by these comparisons the `strcmp` variants would mask off these comparisons. This was missing in the `strncmp` variants causing the bug. This commit adds the masking to `strncmp` so that out of range comparisons don't affect the result. test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass as well a full xcheck on x86_64 linux. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* String: Strength memset tests in test-memset.cNoah Goldstein2022-02-151-15/+21
| | | | | | | | | The prior sentinel logic was broken and was checking the SIMPLE_MEMSET as opposed to the tested implementation. As well `s` (the test buffer) was not reset between implementation tests so it was possible for a buggy implementation to be hidden by a previously executed correct one. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* String: Ensure 'MIN_PAGE_SIZE' is multiple of 'getpagesize'Noah Goldstein2022-02-112-16/+16
| | | | | When 'TEST_LEN' was defined as (4096 * 3) the allocation size Would not be a multiple of system page size if system page size > 4096.
* 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>