aboutsummaryrefslogtreecommitdiff
path: root/string
AgeCommit message (Collapse)AuthorFilesLines
2022-11-08string: Add len=0 to {w}memcmp{eq} tests and benchtestsNoah Goldstein1-6/+10
len=0 is valid and fairly common so should be tested. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2022-11-01configure: Use -Wno-ignored-attributes if compiler warns about multiple aliasesAdhemerval Zanella1-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>
2022-10-28Use uintptr_t in string/tester for pointer alignmentSzabolcs Nagy1-6/+7
The code assumed unsigned long can represent pointers. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2022-10-18String: Improve test coverage for memchrSunil K Pandey1-0/+1
This test improves memchr coverage near page boundary. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2022-10-10String: Improve test coverage for memchrSunil K Pandey1-2/+5
This test improves memchr coverage near page boundary. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2022-09-28x86: Fix wcsnlen-avx2 page cross length comparison [BZ #29591]Noah Goldstein1-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.
2022-09-22Use '%z' instead of '%Z' on printf functionsAdhemerval Zanella Netto2-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>
2022-06-08x86: Fix page cross case in rawmemchr-avx2 [BZ #29234]Noah Goldstein1-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>
2022-06-03string.h: Fix boolean spelling in commentsH.J. Lu1-1/+1
2022-05-25String: Improve overflow test coverage for strnlenSunil K Pandey1-0/+2
This patch adds more overflow test coverage for strnlen and wcsnlen. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2022-05-23string.h: fix __fortified_attr_access macro call [BZ #29162]Sergei Trofimovich1-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>
2022-04-13Replace {u}int_fast{16|32} with {u}int32_tNoah Goldstein2-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.
2022-04-09string: Replace outdated comments in strlen().Ricardo Bittencourt1-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>
2022-04-06tests/string: Drop simple/stupid/builtin testsSiddhesh Poyarekar25-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>
2022-04-06test-memcpy: Actually reverse source and destinationSiddhesh Poyarekar1-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>
2022-04-01Increase the test timeout of some string testsSzabolcs Nagy2-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.
2022-03-25string: Expand page cross test cases in test-strncmp.cNoah Goldstein1-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>
2022-03-25string: Expand page cross test cases in test-strcmp.cNoah Goldstein1-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>
2022-03-25string: Expand page cross tests in test-strncasecmp.cNoah Goldstein1-12/+154
Add more robust tests that cover all the page cross edge cases. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2022-03-25string: Expand page cross tests in test-strcasecmp.cNoah Goldstein1-12/+100
Add more robust tests that cover all the page cross edge cases. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2022-02-23ia64: Remove bzero optimizationAdhemerval Zanella1-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).
2022-02-17string: Add a testcase for wcsncmp with SIZE_MAX [BZ #28755]H.J. Lu1-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>
2022-02-16x86: Fix bug in strncmp-evex and strncmp-avx2 [BZ #28895]Noah Goldstein1-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>
2022-02-15String: Strength memset tests in test-memset.cNoah Goldstein1-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>
2022-02-11String: Ensure 'MIN_PAGE_SIZE' is multiple of 'getpagesize'Noah Goldstein2-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.
2022-02-05string: Sort headers, routines, tests and tests-translationH.J. Lu1-44/+166
Sort headers, routines, tests and tests-translation. Put one entry per line.
2022-02-03string: Improve coverage in test-strcmp.c and test-strncmp.cNoah Goldstein2-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>
2022-02-03string/test-str*cmp: remove stupid_[strcmp, strncmp, wcscmp, wcsncmp].Noah Goldstein2-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>
2022-01-12debug: Synchronize feature guards in fortified functions [BZ #28746]Siddhesh Poyarekar1-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>
2022-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert143-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
2021-12-07String: test-memcpy used unaligned types for buffers [BZ 28572]John David Anglin1-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>
2021-12-03x86-64: Use notl in EVEX strcmp [BZ #28646]Noah Goldstein1-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>
2021-11-10String: Split memcpy tests so that parallel build is fasterNoah Goldstein4-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>
2021-11-07test-memcpy.c: Double TIMEOUT to (8 * 60)H.J. Lu2-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>
2021-11-06string: Make tests birdirectional test-memcpy.cNoah Goldstein2-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>
2021-10-27String: Add __memcmpeq as build targetNoah Goldstein2-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.
2021-10-26String: Add tests for __memcmpeqNoah Goldstein3-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.
2021-10-26String: Add hidden defs for __memcmpeq() to enable internal usageNoah Goldstein1-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.
2021-10-26String: Add support for __memcmpeq() ABI on all targetsNoah Goldstein4-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.
2021-10-20Correct access attribute on memfrob (bug 28475)Joseph Myers1-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.
2021-10-20Don't add access size hints to fortifiable functionsSiddhesh Poyarekar2-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>
2021-09-03Remove "Contributed by" linesSiddhesh Poyarekar61-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>
2021-08-26Fix error message in memmove test to display correct src pointerSunil K Pandey1-1/+1
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2021-08-20Update string/test-memmove.c to cover 16KB copyH.J. Lu1-0/+48
2021-07-28tests: use xmalloc to allocate implementation arraySiddhesh Poyarekar1-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>
2021-06-24String: Add three more overflow tests cases to test-strnlen.cNoah Goldstein1-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>
2021-06-23String: Add overflow tests for strnlen, memchr, and strncat [BZ #27974]Noah Goldstein3-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>
2021-06-03Improve test coverage of strnlen functionSunil K Pandey1-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>
2021-06-03dlfcn: Cleanups after -ldl is no longer requiredFlorian Weimer1-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>
2021-06-02Improve test coverage of strlen functionSunil K Pandey1-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>