Skip to content

Commit 4b95caa

Browse files
committed
rebas
Created using spr 1.3.7
2 parents 7c368b9 + 70d379f commit 4b95caa

File tree

121 files changed

+804
-708
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+804
-708
lines changed

.github/workflows/llvm-abi-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ on:
1010
- 'release/**'
1111
paths:
1212
- 'llvm/**'
13-
- '.github/workflows/llvm-tests.yml'
13+
- '.github/workflows/llvm-abi-tests.yml'
1414
pull_request:
1515
branches:
1616
- 'release/**'
1717
paths:
1818
- 'llvm/**'
19-
- '.github/workflows/llvm-tests.yml'
19+
- '.github/workflows/llvm-abi-tests.yml'
2020

2121
concurrency:
2222
# Skip intermediate builds: always.

compiler-rt/lib/scudo/standalone/combined.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ class Allocator {
171171
Primary.Options.set(OptionBit::DeallocTypeMismatch);
172172
if (getFlags()->delete_size_mismatch)
173173
Primary.Options.set(OptionBit::DeleteSizeMismatch);
174-
if (systemSupportsMemoryTagging())
174+
if (allocatorSupportsMemoryTagging<AllocatorConfig>() &&
175+
systemSupportsMemoryTagging())
175176
Primary.Options.set(OptionBit::UseMemoryTagging);
176177

177178
QuarantineMaxChunkSize =

compiler-rt/lib/scudo/standalone/memtag.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ inline bool systemSupportsMemoryTagging() {
6666
#ifndef HWCAP2_MTE
6767
#define HWCAP2_MTE (1 << 18)
6868
#endif
69-
static bool SupportsMemoryTagging = getauxval(AT_HWCAP2) & HWCAP2_MTE;
70-
return SupportsMemoryTagging;
69+
return getauxval(AT_HWCAP2) & HWCAP2_MTE;
7170
}
7271

7372
inline bool systemDetectsMemoryTagFaultsTestOnly() {
@@ -262,7 +261,9 @@ inline uptr loadTag(uptr Ptr) {
262261

263262
#else
264263

265-
inline bool systemSupportsMemoryTagging() { return false; }
264+
inline NORETURN bool systemSupportsMemoryTagging() {
265+
UNREACHABLE("memory tagging not supported");
266+
}
266267

267268
inline NORETURN bool systemDetectsMemoryTagFaultsTestOnly() {
268269
UNREACHABLE("memory tagging not supported");

compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ TEST(MemtagBasicDeathTest, Unsupported) {
2828
EXPECT_DEATH(untagPointer((uptr)0), "not supported");
2929
EXPECT_DEATH(extractTag((uptr)0), "not supported");
3030

31+
EXPECT_DEATH(systemSupportsMemoryTagging(), "not supported");
3132
EXPECT_DEATH(systemDetectsMemoryTagFaultsTestOnly(), "not supported");
3233
EXPECT_DEATH(enableSystemMemoryTaggingTestOnly(), "not supported");
3334

compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
const scudo::uptr PageSize = scudo::getPageSizeCached();
2828

2929
template <typename Config> static scudo::Options getOptionsForConfig() {
30-
if (!scudo::systemSupportsMemoryTagging())
30+
if (!Config::getMaySupportMemoryTagging() ||
31+
!scudo::archSupportsMemoryTagging() ||
32+
!scudo::systemSupportsMemoryTagging())
3133
return {};
3234
scudo::AtomicOptions AO;
3335
AO.set(scudo::OptionBit::UseMemoryTagging);

compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ TEST_F(ScudoWrappersCppTest, ThreadedNew) {
187187
// TODO: Investigate why libc sometimes crashes with tag missmatch in
188188
// __pthread_clockjoin_ex.
189189
std::unique_ptr<scudo::ScopedDisableMemoryTagChecks> NoTags;
190-
if (!SCUDO_ANDROID && scudo::systemSupportsMemoryTagging())
190+
if (!SCUDO_ANDROID && scudo::archSupportsMemoryTagging() &&
191+
scudo::systemSupportsMemoryTagging())
191192
NoTags = std::make_unique<scudo::ScopedDisableMemoryTagChecks>();
192193

193194
Ready = false;

libc/fuzzing/__support/freelist_heap_fuzz.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ asm(R"(
2424
_end:
2525
.fill 1024
2626
__llvm_libc_heap_limit:
27-
)";
27+
)");
2828

2929
using LIBC_NAMESPACE::FreeListHeap;
3030
using LIBC_NAMESPACE::inline_memset;

libc/fuzzing/string/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ add_libc_fuzzer(
4040
DEPENDS
4141
libc.src.strings.bcmp
4242
)
43+
44+
add_libc_fuzzer(
45+
strlen_fuzz
46+
SRCS
47+
strlen_fuzz.cpp
48+
DEPENDS
49+
libc.src.string.strlen
50+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===-- strlen_fuzz.cpp ---------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// Fuzzing test for llvm-libc strlen implementation.
10+
///
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "src/string/strlen.h"
14+
#include <cstdint>
15+
#include <cstring>
16+
17+
// always null terminate the data
18+
extern "C" size_t LLVMFuzzerMutate(uint8_t *data, size_t size, size_t max_size);
19+
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t *data, size_t size,
20+
size_t max_size, unsigned int seed) {
21+
size = LLVMFuzzerMutate(data, size, max_size);
22+
data[size - 1] = '\0';
23+
return size;
24+
}
25+
26+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
27+
size_t ref = ::strlen(reinterpret_cast<const char *>(data));
28+
size_t impl = LIBC_NAMESPACE::strlen(reinterpret_cast<const char *>(data));
29+
if (ref != impl)
30+
__builtin_trap();
31+
return 0;
32+
}

libc/src/string/memory_utils/aarch64/inline_strlen.h

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_STRLEN_H
99
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_STRLEN_H
1010

11+
#include "src/__support/macros/properties/cpu_features.h"
12+
1113
#if defined(__ARM_NEON)
1214
#include "src/__support/CPP/bit.h" // countr_zero
13-
1415
#include <arm_neon.h>
1516
#include <stddef.h> // size_t
16-
1717
namespace LIBC_NAMESPACE_DECL {
18-
1918
namespace neon {
2019
[[maybe_unused]] LIBC_NO_SANITIZE_OOB_ACCESS LIBC_INLINE static size_t
2120
string_length(const char *src) {
@@ -45,9 +44,63 @@ string_length(const char *src) {
4544
}
4645
}
4746
} // namespace neon
47+
} // namespace LIBC_NAMESPACE_DECL
48+
#endif // __ARM_NEON
4849

49-
namespace string_length_impl = neon;
50+
#ifdef LIBC_TARGET_CPU_HAS_SVE
51+
#include "src/__support/macros/optimization.h"
52+
#include <arm_sve.h>
53+
namespace LIBC_NAMESPACE_DECL {
54+
namespace sve {
55+
[[maybe_unused]] LIBC_INLINE static size_t string_length(const char *src) {
56+
const uint8_t *ptr = reinterpret_cast<const uint8_t *>(src);
57+
// Initialize the first-fault register to all true
58+
svsetffr();
59+
const svbool_t all_true = svptrue_b8(); // all true predicate
60+
svbool_t cmp_zero;
61+
size_t len = 0;
5062

63+
for (;;) {
64+
// Read a vector's worth of bytes, stopping on first fault.
65+
svuint8_t data = svldff1_u8(all_true, &ptr[len]);
66+
svbool_t fault_mask = svrdffr_z(all_true);
67+
bool has_no_fault = svptest_last(all_true, fault_mask);
68+
if (LIBC_LIKELY(has_no_fault)) {
69+
// First fault did not fail: the whole vector is valid.
70+
// Avoid depending on the contents of FFR beyond the branch.
71+
len += svcntb(); // speculative increment
72+
cmp_zero = svcmpeq_n_u8(all_true, data, 0);
73+
bool has_no_zero = !svptest_any(all_true, cmp_zero);
74+
if (LIBC_LIKELY(has_no_zero))
75+
continue;
76+
len -= svcntb(); // undo speculative increment
77+
break;
78+
} else {
79+
// First fault failed: only some of the vector is valid.
80+
// Perform the comparison only on the valid bytes.
81+
cmp_zero = svcmpeq_n_u8(fault_mask, data, 0);
82+
bool has_zero = svptest_any(fault_mask, cmp_zero);
83+
if (LIBC_LIKELY(has_zero))
84+
break;
85+
svsetffr();
86+
len += svcntp_b8(all_true, fault_mask);
87+
continue;
88+
}
89+
}
90+
// Select the bytes before the first and count them.
91+
svbool_t before_zero = svbrkb_z(all_true, cmp_zero);
92+
len += svcntp_b8(all_true, before_zero);
93+
return len;
94+
}
95+
} // namespace sve
96+
} // namespace LIBC_NAMESPACE_DECL
97+
#endif // LIBC_TARGET_CPU_HAS_SVE
98+
99+
namespace LIBC_NAMESPACE_DECL {
100+
#ifdef LIBC_TARGET_CPU_HAS_SVE
101+
namespace string_length_impl = sve;
102+
#elif defined(__ARM_NEON)
103+
namespace string_length_impl = neon;
104+
#endif
51105
} // namespace LIBC_NAMESPACE_DECL
52-
#endif // __ARM_NEON
53106
#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_STRLEN_H

0 commit comments

Comments
 (0)