about summary refs log tree commit diff
path: root/string
Commit message (Collapse)AuthorAgeFilesLines
* Fix stringop-overflow warning in test-strncat.Stefan Liebler2023-03-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | Starting with commit b2c474f8de4c92bfe7435853a96805ec32d68dfa "x86: Fix strncat-avx2.S reading past length [BZ #30065]" Building on s390 the test fails due warnings like: In function ‘do_one_test’, inlined from ‘do_overflow_tests’ at test-strncat.c:175:7: test-strncat.c:31:18: error: ‘strnlen’ specified bound [4294966546, 4294967295] exceeds maximum object size 2147483647 [-Werror=stringop-overflow=] 31 | # define STRNLEN strnlen | ^ test-strncat.c:83:16: note: in expansion of macro ‘STRNLEN’ 83 | size_t len = STRNLEN (src, n); | ^~~~~~~ In all werror cases, the call to strnlen (.., SIZE_MAX) is inlined. Therefore this patch just marks the do_one_test function as noinline. Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
* string: Disable stack protector in early static initializationAdhemerval Zanella2023-02-081-0/+2
| | | | | | | For powerpc, strncmp is used on _dl_string_platform issued by __tcb_parse_hwcap_and_convert_at_platform. Reviewed-by: Carlos Eduardo Seo <carlos.seo@linaro.org>
* string: Add libc_hidden_proto for memrchrAdhemerval Zanella2023-02-081-0/+1
| | | | | | | Although static linker can optimize it to local call, it follows the internal scheme to provide hidden proto and definitions. Reviewed-by: Carlos Eduardo Seo <carlos.seo@linaro.org>
* string: Add libc_hidden_proto for strchrnulAdhemerval Zanella2023-02-081-0/+1
| | | | | | | Although static linker can optimize it to local call, it follows the internal scheme to provide hidden proto and definitions. Reviewed-by: Carlos Eduardo Seo <carlos.seo@linaro.org>
* string: Hook up the default implementation on test-strrchrAdhemerval Zanella2023-02-061-14/+24
| | | | | | And remove SIMPLE_STRRCHR, which is not used anywhere. Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-memrchrAdhemerval Zanella2023-02-061-0/+7
| | | | Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-memchrAdhemerval Zanella2023-02-061-11/+20
| | | | | | And remove SIMPLE_MEMCHR, which is not used anywhere. Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-strcpyAdhemerval Zanella2023-02-061-10/+24
| | | | Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-stpcpyAdhemerval Zanella2023-02-061-11/+21
| | | | Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-strncmpAdhemerval Zanella2023-02-061-0/+16
| | | | Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-strcmpAdhemerval Zanella2023-02-061-0/+22
| | | | Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-strchrAdhemerval Zanella2023-02-061-15/+38
| | | | | | Also remove the simple_STRCHR, which can be easily replaced. Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-strnlenAdhemerval Zanella2023-02-061-11/+24
| | | | | | Also remove the SIMPLE_STRNLEN, which is not used anywhere. Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Hook up the default implementation on test-strlenAdhemerval Zanella2023-02-061-17/+14
| | | | | | | Also remove the simple_STRLEN and builtin_strlen, which are not used anywhere. Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Improve generic strrchr with memrchr and strlenAdhemerval Zanella2023-02-061-17/+1
| | | | | | | | | | | Now that both strlen and memrchr have word vectorized implementation, it should be faster to implement strrchr based on memrchr over the string length instead of calling strchr on a loop. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits).
* string: Improve generic memrchrAdhemerval Zanella2023-02-061-157/+39
| | | | | | | | | | | | | | New algorithm read the lastaligned address and mask off the unwanted bytes. The loop now read word-aligned address and check using the has_eq macro. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Improve generic strnlen with memchrAdhemerval Zanella2023-02-061-132/+5
| | | | | | | | It also cleanups the multiple inclusion by leaving the ifunc implementation to undef the weak_alias and libc_hidden_def. Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Improve generic memchrAdhemerval Zanella2023-02-061-125/+51
| | | | | | | | | | | | | | | | | New algorithm read the first aligned address and mask off the unwanted bytes (this strategy is similar to arch-specific implementations used on powerpc, sparc, and sh). The loop now read word-aligned address and check using the has_eq macro. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Improve generic strcpyAdhemerval Zanella2023-02-061-1/+5
| | | | | | | | | | | | | Now that stpcpy is vectorized based on op_t, it should be better to call it instead of strlen plus memcpy. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Improve generic stpcpyAdhemerval Zanella2023-02-061-6/+86
| | | | | | | | | | | | | | | | | | | | | | | It follows the strategy: - Align the destination on word boundary using byte operations. - If source is also word aligned, read a word per time, check for null (using has_zero from string-fzb.h), and write the remaining bytes. - If source is not word aligned, loop by aligning the source, and merging the result of two reads. Similar to aligned case, check for null with has_zero, and write the remaining bytes if null is found. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Improve generic strncmpAdhemerval Zanella2023-02-061-37/+101
| | | | | | | | | | | | | | | | | | | | | It follows the strategy: - Align the first input to word boundary using byte operations. - If second input is also word aligned, read a word per time, check for null (using has_zero), and check final words using byte operation. - If second input is not word aligned, loop by aligning the source, and merge the result of two reads. Similar to aligned case, check for null with has_zero, and check final words using byte operation. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* string: Improve generic strcmpAdhemerval Zanella2023-02-061-16/+94
| | | | | | | | | | | | | | | | | | | | | It follows the strategy: - Align the first input to word boundary using byte operations. - If second input is also word aligned, read a word per time, check for null (using has_zero), and check final words using byte operation. - If second input is not word aligned, loop by aligning the source, and merging the result of two reads. Similar to aligned case, check for null with has_zero, and check final words using byte operation. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Improve generic strchrAdhemerval Zanella2023-02-061-156/+8
| | | | | | | | | | | | New algorithm now calls strchrnul. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Improve generic strchrnulAdhemerval Zanella2023-02-061-133/+22
| | | | | | | | | | | | | | | | | New algorithm read the first aligned address and mask off the unwanted bytes (this strategy is similar to arch-specific implementations used on powerpc, sparc, and sh). The loop now read word-aligned address and check using the has_zero_eq function. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* string: Improve generic strlenAdhemerval Zanella2023-02-061-70/+22
| | | | | | | | | | | | | | | | | New algorithm read the first aligned address and mask off the unwanted bytes (this strategy is similar to arch-specific implementations used on powerpc, sparc, and sh). The loop now read word-aligned address and check using the has_zero macro. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powercp64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
* Parameterize OP_T_THRES from memcopy.hRichard Henderson2023-02-061-3/+0
| | | | | | | | | | | | It moves OP_T_THRES out of memcopy.h to its own header and adjust each architecture that redefines it. Checked with a build and check with run-built-tests=no for all major Linux ABIs. Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Reviewed-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* Parameterize op_t from memcopy.hAdhemerval Zanella2023-02-061-1/+0
| | | | | | | | | | It moves the op_t definition out to an specific header, adds the attribute 'may-alias', and cleanup its duplicated definitions. Checked with a build and check with run-built-tests=no for all major Linux ABIs. Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* Replace rawmemchr (s, '\0') with strchrWilco Dijkstra2023-02-061-1/+1
| | | | | | | | | Almost all uses of rawmemchr find the end of a string. Since most targets use a generic implementation, replacing it with strchr is better since that is optimized by compilers into strlen (s) + s. Also fix the generic rawmemchr implementation to use a cast to unsigned char in the if statement. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* 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>