Skip to content

Commit 3f7cc14

Browse files
authored
Update compiler-rt to llvm 16 (#19506)
1 parent ffbc85a commit 3f7cc14

File tree

77 files changed

+2008
-744
lines changed

Some content is hidden

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

77 files changed

+2008
-744
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ See docs/process.md for more on how version tagging works.
2323
- A new setting (`CHECK_NULL_WRITES`) was added to disabled the checking of
2424
address zero that is normally done when `STACK_OVERFLOW_CHECK` is enabled.
2525
(#19487)
26+
- compiler-rt updated to LLVM 16. (#19506)
2627

2728
3.1.40 - 05/30/23
2829
-----------------

system/lib/compiler-rt/include/sanitizer/common_interface_defs.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,40 @@ void __sanitizer_annotate_contiguous_container(const void *beg,
159159
const void *old_mid,
160160
const void *new_mid);
161161

162+
/// Similar to <c>__sanitizer_annotate_contiguous_container</c>.
163+
///
164+
/// Annotates the current state of a contiguous container memory,
165+
/// such as <c>std::deque</c>'s single chunk, when the boundries are moved.
166+
///
167+
/// A contiguous chunk is a chunk that keeps all of its elements
168+
/// in a contiguous region of memory. The container owns the region of memory
169+
/// <c>[storage_beg, storage_end)</c>; the memory <c>[container_beg,
170+
/// container_end)</c> is used to store the current elements, and the memory
171+
/// <c>[storage_beg, container_beg), [container_end, storage_end)</c> is
172+
/// reserved for future elements (<c>storage_beg <= container_beg <=
173+
/// container_end <= storage_end</c>). For example, in <c> std::deque </c>:
174+
/// - chunk with a frist deques element will have container_beg equal to address
175+
/// of the first element.
176+
/// - in every next chunk with elements, true is <c> container_beg ==
177+
/// storage_beg </c>.
178+
///
179+
/// Argument requirements:
180+
/// During unpoisoning memory of empty container (before first element is
181+
/// added):
182+
/// - old_container_beg_p == old_container_end_p
183+
/// During poisoning after last element was removed:
184+
/// - new_container_beg_p == new_container_end_p
185+
/// \param storage_beg Beginning of memory region.
186+
/// \param storage_end End of memory region.
187+
/// \param old_container_beg Old beginning of used region.
188+
/// \param old_container_end End of used region.
189+
/// \param new_container_beg New beginning of used region.
190+
/// \param new_container_end New end of used region.
191+
void __sanitizer_annotate_double_ended_contiguous_container(
192+
const void *storage_beg, const void *storage_end,
193+
const void *old_container_beg, const void *old_container_end,
194+
const void *new_container_beg, const void *new_container_end);
195+
162196
/// Returns true if the contiguous container <c>[beg, end)</c> is properly
163197
/// poisoned.
164198
///
@@ -178,6 +212,31 @@ void __sanitizer_annotate_contiguous_container(const void *beg,
178212
int __sanitizer_verify_contiguous_container(const void *beg, const void *mid,
179213
const void *end);
180214

215+
/// Returns true if the double ended contiguous
216+
/// container <c>[storage_beg, storage_end)</c> is properly poisoned.
217+
///
218+
/// Proper poisoning could occur, for example, with
219+
/// <c>__sanitizer_annotate_double_ended_contiguous_container</c>), that is, if
220+
/// <c>[storage_beg, container_beg)</c> is not addressable, <c>[container_beg,
221+
/// container_end)</c> is addressable and <c>[container_end, end)</c> is
222+
/// unaddressable. Full verification requires O (<c>storage_end -
223+
/// storage_beg</c>) time; this function tries to avoid such complexity by
224+
/// touching only parts of the container around <c><i>storage_beg</i></c>,
225+
/// <c><i>container_beg</i></c>, <c><i>container_end</i></c>, and
226+
/// <c><i>storage_end</i></c>.
227+
///
228+
/// \param storage_beg Beginning of memory region.
229+
/// \param container_beg Beginning of used region.
230+
/// \param container_end End of used region.
231+
/// \param storage_end End of memory region.
232+
///
233+
/// \returns True if the double-ended contiguous container <c>[storage_beg,
234+
/// container_beg, container_end, end)</c> is properly poisoned - only
235+
/// [container_beg; container_end) is addressable.
236+
int __sanitizer_verify_double_ended_contiguous_container(
237+
const void *storage_beg, const void *container_beg,
238+
const void *container_end, const void *storage_end);
239+
181240
/// Similar to <c>__sanitizer_verify_contiguous_container()</c> but also
182241
/// returns the address of the first improperly poisoned byte.
183242
///
@@ -192,6 +251,20 @@ const void *__sanitizer_contiguous_container_find_bad_address(const void *beg,
192251
const void *mid,
193252
const void *end);
194253

254+
/// returns the address of the first improperly poisoned byte.
255+
///
256+
/// Returns NULL if the area is poisoned properly.
257+
///
258+
/// \param storage_beg Beginning of memory region.
259+
/// \param container_beg Beginning of used region.
260+
/// \param container_end End of used region.
261+
/// \param storage_end End of memory region.
262+
///
263+
/// \returns The bad address or NULL.
264+
const void *__sanitizer_double_ended_contiguous_container_find_bad_address(
265+
const void *storage_beg, const void *container_beg,
266+
const void *container_end, const void *storage_end);
267+
195268
/// Prints the stack trace leading to this call (useful for calling from the
196269
/// debugger).
197270
void __sanitizer_print_stack_trace(void);

system/lib/compiler-rt/include/sanitizer/dfsan_interface.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ typedef void (*dfsan_write_callback_t)(int fd, const void *buf, size_t count);
3131
typedef void (*dfsan_conditional_callback_t)(dfsan_label label,
3232
dfsan_origin origin);
3333

34+
/// Signature of the callback argument to dfsan_set_reaches_function_callback().
35+
/// The description is intended to hold the name of the variable.
36+
typedef void (*dfsan_reaches_function_callback_t)(dfsan_label label,
37+
dfsan_origin origin,
38+
const char *file,
39+
unsigned int line,
40+
const char *function);
41+
3442
/// Computes the union of \c l1 and \c l2, resulting in a union label.
3543
dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
3644

@@ -91,6 +99,18 @@ void dfsan_set_conditional_callback(dfsan_conditional_callback_t callback);
9199
/// This function returns all label bits seen in signal handler conditions.
92100
dfsan_label dfsan_get_labels_in_signal_conditional();
93101

102+
/// Sets a callback to be invoked when tainted data reaches a function.
103+
/// This could occur at function entry, or at a load instruction.
104+
/// These callbacks will only be added if -dfsan-reaches-function-callbacks=1.
105+
void dfsan_set_reaches_function_callback(
106+
dfsan_reaches_function_callback_t callback);
107+
108+
/// Making callbacks that handle signals well is tricky, so when
109+
/// -dfsan-reaches-function-callbacks=true, functions reached in signal
110+
/// handlers will add the labels they see into a global (bitwise-or together).
111+
/// This function returns all label bits seen during signal handlers.
112+
dfsan_label dfsan_get_labels_in_signal_reaches_function();
113+
94114
/// Interceptor hooks.
95115
/// Whenever a dfsan's custom function is called the corresponding
96116
/// hook is called it non-zero. The hooks should be defined by the user.

system/lib/compiler-rt/include/sanitizer/msan_interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ extern "C" {
9292

9393
/* Tell MSan about newly destroyed memory. Mark memory as uninitialized. */
9494
void __sanitizer_dtor_callback(const volatile void* data, size_t size);
95+
void __sanitizer_dtor_callback_fields(const volatile void *data, size_t size);
96+
void __sanitizer_dtor_callback_vptr(const volatile void *data);
9597

9698
/* This function may be optionally provided by user and should return
9799
a string containing Msan runtime options. See msan_flags.h for details. */

system/lib/compiler-rt/lib/asan/asan_allocator.cpp

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ struct Allocator {
803803
sptr offset = 0;
804804
if (!m1 || AsanChunkView(m1).AddrIsAtLeft(addr, 1, &offset)) {
805805
// The address is in the chunk's left redzone, so maybe it is actually
806-
// a right buffer overflow from the other chunk to the left.
807-
// Search a bit to the left to see if there is another chunk.
806+
// a right buffer overflow from the other chunk before.
807+
// Search a bit before to see if there is another chunk.
808808
AsanChunk *m2 = nullptr;
809809
for (uptr l = 1; l < GetPageSizeCached(); l++) {
810810
m2 = GetAsanChunkByAddr(addr - l);
@@ -1094,6 +1094,8 @@ uptr PointsIntoChunk(void *p) {
10941094
}
10951095

10961096
uptr GetUserBegin(uptr chunk) {
1097+
// FIXME: All usecases provide chunk address, GetAsanChunkByAddrFastLocked is
1098+
// not needed.
10971099
__asan::AsanChunk *m = __asan::instance.GetAsanChunkByAddrFastLocked(chunk);
10981100
return m ? m->Beg() : 0;
10991101
}
@@ -1153,33 +1155,6 @@ IgnoreObjectResult IgnoreObjectLocked(const void *p) {
11531155
return kIgnoreObjectSuccess;
11541156
}
11551157

1156-
void GetAdditionalThreadContextPtrs(ThreadContextBase *tctx, void *ptrs) {
1157-
// Look for the arg pointer of threads that have been created or are running.
1158-
// This is necessary to prevent false positive leaks due to the AsanThread
1159-
// holding the only live reference to a heap object. This can happen because
1160-
// the `pthread_create()` interceptor doesn't wait for the child thread to
1161-
// start before returning and thus loosing the the only live reference to the
1162-
// heap object on the stack.
1163-
1164-
__asan::AsanThreadContext *atctx =
1165-
reinterpret_cast<__asan::AsanThreadContext *>(tctx);
1166-
__asan::AsanThread *asan_thread = atctx->thread;
1167-
1168-
// Note ThreadStatusRunning is required because there is a small window where
1169-
// the thread status switches to `ThreadStatusRunning` but the `arg` pointer
1170-
// still isn't on the stack yet.
1171-
if (atctx->status != ThreadStatusCreated &&
1172-
atctx->status != ThreadStatusRunning)
1173-
return;
1174-
1175-
uptr thread_arg = reinterpret_cast<uptr>(asan_thread->get_arg());
1176-
if (!thread_arg)
1177-
return;
1178-
1179-
auto ptrsVec = reinterpret_cast<InternalMmapVector<uptr> *>(ptrs);
1180-
ptrsVec->push_back(thread_arg);
1181-
}
1182-
11831158
} // namespace __lsan
11841159

11851160
// ---------------------- Interface ---------------- {{{1

system/lib/compiler-rt/lib/asan/asan_allocator.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ typedef VeryCompactSizeClassMap SizeClassMap;
135135
const uptr kAllocatorSpace = ~(uptr)0;
136136
const uptr kAllocatorSize = 0x2000000000ULL; // 128G.
137137
typedef VeryDenseSizeClassMap SizeClassMap;
138-
# elif defined(__aarch64__)
139-
// AArch64/SANITIZER_CAN_USE_ALLOCATOR64 is only for 42-bit VMA
140-
// so no need to different values for different VMA.
141-
const uptr kAllocatorSpace = 0x10000000000ULL;
142-
const uptr kAllocatorSize = 0x10000000000ULL; // 3T.
143-
typedef DefaultSizeClassMap SizeClassMap;
144138
#elif defined(__sparc__)
145139
const uptr kAllocatorSpace = ~(uptr)0;
146140
const uptr kAllocatorSize = 0x20000000000ULL; // 2T.

system/lib/compiler-rt/lib/asan/asan_descriptions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ static void PrintHeapChunkAccess(uptr addr, const ChunkAccess &descr) {
129129
str.append("%s", d.Location());
130130
switch (descr.access_type) {
131131
case kAccessTypeLeft:
132-
str.append("%p is located %zd bytes to the left of",
132+
str.append("%p is located %zd bytes before",
133133
(void *)descr.bad_addr, descr.offset);
134134
break;
135135
case kAccessTypeRight:
136-
str.append("%p is located %zd bytes to the right of",
136+
str.append("%p is located %zd bytes after",
137137
(void *)descr.bad_addr, descr.offset);
138138
break;
139139
case kAccessTypeInside:
@@ -279,17 +279,17 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
279279
Decorator d;
280280
str.append("%s", d.Location());
281281
if (addr < g.beg) {
282-
str.append("%p is located %zd bytes to the left", (void *)addr,
282+
str.append("%p is located %zd bytes before", (void *)addr,
283283
g.beg - addr);
284284
} else if (addr + access_size > g.beg + g.size) {
285285
if (addr < g.beg + g.size) addr = g.beg + g.size;
286-
str.append("%p is located %zd bytes to the right", (void *)addr,
286+
str.append("%p is located %zd bytes after", (void *)addr,
287287
addr - (g.beg + g.size));
288288
} else {
289289
// Can it happen?
290-
str.append("%p is located %zd bytes inside", (void *)addr, addr - g.beg);
290+
str.append("%p is located %zd bytes inside of", (void *)addr, addr - g.beg);
291291
}
292-
str.append(" of global variable '%s' defined in '",
292+
str.append(" global variable '%s' defined in '",
293293
MaybeDemangleGlobalName(g.name));
294294
PrintGlobalLocation(&str, g);
295295
str.append("' (0x%zx) of size %zu\n", g.beg, g.size);

system/lib/compiler-rt/lib/asan/asan_errors.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,26 @@ void ErrorBadParamsToAnnotateContiguousContainer::Print() {
334334
ReportErrorSummary(scariness.GetDescription(), stack);
335335
}
336336

337+
void ErrorBadParamsToAnnotateDoubleEndedContiguousContainer::Print() {
338+
Report(
339+
"ERROR: AddressSanitizer: bad parameters to "
340+
"__sanitizer_annotate_double_ended_contiguous_container:\n"
341+
" storage_beg : %p\n"
342+
" storage_end : %p\n"
343+
" old_container_beg : %p\n"
344+
" old_container_end : %p\n"
345+
" new_container_beg : %p\n"
346+
" new_container_end : %p\n",
347+
(void *)storage_beg, (void *)storage_end, (void *)old_container_beg,
348+
(void *)old_container_end, (void *)new_container_beg,
349+
(void *)new_container_end);
350+
uptr granularity = ASAN_SHADOW_GRANULARITY;
351+
if (!IsAligned(storage_beg, granularity))
352+
Report("ERROR: storage_beg is not aligned by %zu\n", granularity);
353+
stack->Print();
354+
ReportErrorSummary(scariness.GetDescription(), stack);
355+
}
356+
337357
void ErrorODRViolation::Print() {
338358
Decorator d;
339359
Printf("%s", d.Error());
@@ -550,7 +570,8 @@ static void PrintShadowBytes(InternalScopedString *str, const char *before,
550570
u8 *bytes, u8 *guilty, uptr n) {
551571
Decorator d;
552572
if (before)
553-
str->append("%s%p:", before, (void *)bytes);
573+
str->append("%s%p:", before,
574+
(void *)ShadowToMem(reinterpret_cast<uptr>(bytes)));
554575
for (uptr i = 0; i < n; i++) {
555576
u8 *p = bytes + i;
556577
const char *before =

system/lib/compiler-rt/lib/asan/asan_errors.h

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,28 @@ struct ErrorBadParamsToAnnotateContiguousContainer : ErrorBase {
331331
void Print();
332332
};
333333

334+
struct ErrorBadParamsToAnnotateDoubleEndedContiguousContainer : ErrorBase {
335+
const BufferedStackTrace *stack;
336+
uptr storage_beg, storage_end, old_container_beg, old_container_end,
337+
new_container_beg, new_container_end;
338+
339+
ErrorBadParamsToAnnotateDoubleEndedContiguousContainer() = default; // (*)
340+
ErrorBadParamsToAnnotateDoubleEndedContiguousContainer(
341+
u32 tid, BufferedStackTrace *stack_, uptr storage_beg_, uptr storage_end_,
342+
uptr old_container_beg_, uptr old_container_end_, uptr new_container_beg_,
343+
uptr new_container_end_)
344+
: ErrorBase(tid, 10,
345+
"bad-__sanitizer_annotate_double_ended_contiguous_container"),
346+
stack(stack_),
347+
storage_beg(storage_beg_),
348+
storage_end(storage_end_),
349+
old_container_beg(old_container_beg_),
350+
old_container_end(old_container_end_),
351+
new_container_beg(new_container_beg_),
352+
new_container_end(new_container_end_) {}
353+
void Print();
354+
};
355+
334356
struct ErrorODRViolation : ErrorBase {
335357
__asan_global global1, global2;
336358
u32 stack_id1, stack_id2;
@@ -378,28 +400,29 @@ struct ErrorGeneric : ErrorBase {
378400
};
379401

380402
// clang-format off
381-
#define ASAN_FOR_EACH_ERROR_KIND(macro) \
382-
macro(DeadlySignal) \
383-
macro(DoubleFree) \
384-
macro(NewDeleteTypeMismatch) \
385-
macro(FreeNotMalloced) \
386-
macro(AllocTypeMismatch) \
387-
macro(MallocUsableSizeNotOwned) \
388-
macro(SanitizerGetAllocatedSizeNotOwned) \
389-
macro(CallocOverflow) \
390-
macro(ReallocArrayOverflow) \
391-
macro(PvallocOverflow) \
392-
macro(InvalidAllocationAlignment) \
393-
macro(InvalidAlignedAllocAlignment) \
394-
macro(InvalidPosixMemalignAlignment) \
395-
macro(AllocationSizeTooBig) \
396-
macro(RssLimitExceeded) \
397-
macro(OutOfMemory) \
398-
macro(StringFunctionMemoryRangesOverlap) \
399-
macro(StringFunctionSizeOverflow) \
400-
macro(BadParamsToAnnotateContiguousContainer) \
401-
macro(ODRViolation) \
402-
macro(InvalidPointerPair) \
403+
#define ASAN_FOR_EACH_ERROR_KIND(macro) \
404+
macro(DeadlySignal) \
405+
macro(DoubleFree) \
406+
macro(NewDeleteTypeMismatch) \
407+
macro(FreeNotMalloced) \
408+
macro(AllocTypeMismatch) \
409+
macro(MallocUsableSizeNotOwned) \
410+
macro(SanitizerGetAllocatedSizeNotOwned) \
411+
macro(CallocOverflow) \
412+
macro(ReallocArrayOverflow) \
413+
macro(PvallocOverflow) \
414+
macro(InvalidAllocationAlignment) \
415+
macro(InvalidAlignedAllocAlignment) \
416+
macro(InvalidPosixMemalignAlignment) \
417+
macro(AllocationSizeTooBig) \
418+
macro(RssLimitExceeded) \
419+
macro(OutOfMemory) \
420+
macro(StringFunctionMemoryRangesOverlap) \
421+
macro(StringFunctionSizeOverflow) \
422+
macro(BadParamsToAnnotateContiguousContainer) \
423+
macro(BadParamsToAnnotateDoubleEndedContiguousContainer) \
424+
macro(ODRViolation) \
425+
macro(InvalidPointerPair) \
403426
macro(Generic)
404427
// clang-format on
405428

0 commit comments

Comments
 (0)