diff options
author | Michael Jones <michaelrj@google.com> | 2022-07-14 15:17:18 -0700 |
---|---|---|
committer | Michael Jones <michaelrj@google.com> | 2022-11-30 16:48:35 -0800 |
commit | a3b745818d2e13b2899260239c7cab4bf75070f7 (patch) | |
tree | da000bba92c4a4ffc7553d5fd871dc26a8912415 /libc/common_libc_tuners.cmake | |
parent | 6c2140943cbe257c85f7121349c5bca950a26e0d (diff) | |
download | llvm-a3b745818d2e13b2899260239c7cab4bf75070f7.tar.gz |
[libc] add unsafe mode to strlen
The only safe way to implement strlen involves reading the string one
char at a time. It is faster to read in larger blocks, but this leads to
reading beyond the string boundary, which is undefined behavior. This
patch adds an implementation and flag to use this fast but unsafe
version of strlen.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D129808
Diffstat (limited to 'libc/common_libc_tuners.cmake')
-rw-r--r-- | libc/common_libc_tuners.cmake | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libc/common_libc_tuners.cmake b/libc/common_libc_tuners.cmake new file mode 100644 index 000000000000..cde28fadcbf0 --- /dev/null +++ b/libc/common_libc_tuners.cmake @@ -0,0 +1,14 @@ +# ------------------------------------------------------------------------------ +# Common tuning option definitions. +# ------------------------------------------------------------------------------ + +set(LIBC_COMMON_TUNE_OPTIONS "") + +option(LIBC_UNSAFE_STRING_WIDE_READ "Functions searching for the first character in a string such as strlen will read the string as int sized blocks instead of bytes. This relies on undefined behavior and may fail on some systems, but improves performance on long strings." OFF) +if(LIBC_UNSAFE_STRING_WIDE_READ) + if(LLVM_USE_SANITIZER) + message(FATAL_ERROR "LIBC_UNSAFE_STRING_WIDE_READ is set at the same time as a sanitizer. LIBC_UNSAFE_STRING_WIDE_READ causes strlen and memchr to read beyond the end of their target strings, which is undefined behavior caught by sanitizers.") + else() + list(APPEND LIBC_COMMON_TUNE_OPTIONS "-DLIBC_UNSAFE_STRING_WIDE_READ") + endif() +endif() |