Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libc/src/__support/macros/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ LIBC_THREAD_MODE_EXTERNAL.
#define LIBC_HAS_VECTOR_TYPE 0
#endif

#if __has_attribute(no_sanitize)
// Disable regular and hardware-supported ASan for functions that may
// intentionally make out-of-bounds access. Disable TSan as well, as it detects
// out-of-bounds accesses to heap memory.
#define LIBC_NOSANITIZE_OOB_ACCESS \
__attribute__((no_sanitize("address", "hwaddress", "thread")))
#else
#define LIBC_NOSANITIZE_OOB_ACCESS
#endif

#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H
1 change: 1 addition & 0 deletions libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_header_library(
libc.src.__support.CPP.type_traits
libc.src.__support.CPP.simd
libc.src.__support.common
libc.src.__support.macros.attributes
libc.src.string.memory_utils.inline_memcpy
${string_config_options}
)
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/aarch64/inline_strlen.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace LIBC_NAMESPACE_DECL {

namespace neon {
[[gnu::no_sanitize_address]] [[maybe_unused]] LIBC_INLINE static size_t
[[maybe_unused]] LIBC_NOSANITIZE_OOB_ACCESS LIBC_INLINE static size_t
string_length(const char *src) {
using Vector __attribute__((may_alias)) = uint8x8_t;

Expand Down
3 changes: 1 addition & 2 deletions libc/src/string/memory_utils/generic/inline_strlen.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ LIBC_INLINE constexpr cpp::simd_mask<char> shift_mask(cpp::simd_mask<char> m,
return cpp::bit_cast<cpp::simd_mask<char>>(r);
}

[[clang::no_sanitize("address")]] LIBC_INLINE size_t
string_length(const char *src) {
LIBC_NOSANITIZE_OOB_ACCESS LIBC_INLINE size_t string_length(const char *src) {
constexpr cpp::simd<char> null_byte = cpp::splat('\0');

size_t alignment = alignof(cpp::simd<char>);
Expand Down
4 changes: 2 additions & 2 deletions libc/src/string/memory_utils/x86_64/inline_strlen.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ namespace LIBC_NAMESPACE_DECL {
namespace string_length_internal {
// Return a bit-mask with the nth bit set if the nth-byte in block_ptr is zero.
template <typename Vector, typename Mask>
[[gnu::no_sanitize_address]] LIBC_INLINE static Mask
LIBC_NOSANITIZE_OOB_ACCESS LIBC_INLINE static Mask
compare_and_mask(const Vector *block_ptr);

template <typename Vector, typename Mask,
decltype(compare_and_mask<Vector, Mask>)>
[[gnu::no_sanitize_address]] LIBC_INLINE static size_t
LIBC_NOSANITIZE_OOB_ACCESS LIBC_INLINE static size_t
string_length_vector(const char *src) {
uintptr_t misalign_bytes = reinterpret_cast<uintptr_t>(src) % sizeof(Vector);

Expand Down
3 changes: 2 additions & 1 deletion libc/src/string/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "hdr/types/size_t.h"
#include "src/__support/CPP/bitset.h"
#include "src/__support/CPP/type_traits.h" // cpp::is_same_v
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/string/memory_utils/inline_memcpy.h"
Expand Down Expand Up @@ -119,7 +120,7 @@ template <typename T> LIBC_INLINE size_t string_length(const T *src) {
}

template <typename Word>
[[gnu::no_sanitize_address]] LIBC_INLINE void *
LIBC_NOSANITIZE_OOB_ACCESS LIBC_INLINE void *
find_first_character_wide_read(const unsigned char *src, unsigned char ch,
size_t n) {
const unsigned char *char_ptr = src;
Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5320,6 +5320,7 @@ libc_support_library(
":__support_common",
":__support_cpp_bitset",
":__support_cpp_type_traits",
":__support_macros_attributes",
":__support_macros_optimization",
":hdr_limits_macros",
":llvm_libc_types_size_t",
Expand Down
Loading