Skip to content

Commit 1444a93

Browse files
authored
Update compiler-rt to LLVM 19.1.4 (#22937)
All changes are upstream changes except for a few unused variable warning fixes and code size rebaselines. This PR was created by running https://github.com/emscripten-core/emscripten/blob/main/system/lib/update_compiler_rt.py script.
1 parent 74d95fb commit 1444a93

File tree

115 files changed

+1190
-986
lines changed

Some content is hidden

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

115 files changed

+1190
-986
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.75 (in development)
2222
-----------------------
23+
- compiler-rt was updated to LLVM 19.1.4. (#22937)
2324
- The Wasm nontrapping-fptoint feature has been enabled by default. clang will
2425
generate nontrapping (saturating) float-to-int conversion instructions for
2526
C typecasts. This should have no effect on programs that do not have

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,20 @@ size_t SANITIZER_CDECL __sanitizer_get_free_bytes(void);
6262
size_t SANITIZER_CDECL __sanitizer_get_unmapped_bytes(void);
6363

6464
/* Malloc hooks that may be optionally provided by user.
65-
__sanitizer_malloc_hook(ptr, size) is called immediately after
66-
allocation of "size" bytes, which returned "ptr".
67-
__sanitizer_free_hook(ptr) is called immediately before
68-
deallocation of "ptr". */
65+
- __sanitizer_malloc_hook(ptr, size) is called immediately after allocation
66+
of "size" bytes, which returned "ptr".
67+
- __sanitizer_free_hook(ptr) is called immediately before deallocation of
68+
"ptr".
69+
- __sanitizer_ignore_free_hook(ptr) is called immediately before deallocation
70+
of "ptr", and if it returns a non-zero value, the deallocation of "ptr"
71+
will not take place. This allows software to make free a no-op until it
72+
calls free() again in the same pointer at a later time. Hint: read this as
73+
"ignore the free" rather than "ignore the hook".
74+
*/
6975
void SANITIZER_CDECL __sanitizer_malloc_hook(const volatile void *ptr,
7076
size_t size);
7177
void SANITIZER_CDECL __sanitizer_free_hook(const volatile void *ptr);
78+
int SANITIZER_CDECL __sanitizer_ignore_free_hook(const volatile void *ptr);
7279

7380
/* Installs a pair of hooks for malloc/free.
7481
Several (currently, 5) hook pairs may be installed, they are executed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,15 @@
18561856
__sanitizer_syscall_pre_impl_sigaltstack((long)ss, (long)oss)
18571857
#define __sanitizer_syscall_post_sigaltstack(res, ss, oss) \
18581858
__sanitizer_syscall_post_impl_sigaltstack(res, (long)ss, (long)oss)
1859+
#define __sanitizer_syscall_pre_futex(uaddr, futex_op, val, timeout, uaddr2, \
1860+
val3) \
1861+
__sanitizer_syscall_pre_impl_futex((long)uaddr, (long)futex_op, (long)val, \
1862+
(long)timeout, (long)uaddr2, (long)val3)
1863+
#define __sanitizer_syscall_post_futex(res, uaddr, futex_op, val, timeout, \
1864+
uaddr2, val3) \
1865+
__sanitizer_syscall_post_impl_futex(res, (long)uaddr, (long)futex_op, \
1866+
(long)val, (long)timeout, (long)uaddr2, \
1867+
(long)val3)
18591868

18601869
// And now a few syscalls we don't handle yet.
18611870
#define __sanitizer_syscall_pre_afs_syscall(...)
@@ -1875,7 +1884,6 @@
18751884
#define __sanitizer_syscall_pre_fchown32(...)
18761885
#define __sanitizer_syscall_pre_ftime(...)
18771886
#define __sanitizer_syscall_pre_ftruncate64(...)
1878-
#define __sanitizer_syscall_pre_futex(...)
18791887
#define __sanitizer_syscall_pre_getegid32(...)
18801888
#define __sanitizer_syscall_pre_geteuid32(...)
18811889
#define __sanitizer_syscall_pre_getgid32(...)
@@ -1954,7 +1962,6 @@
19541962
#define __sanitizer_syscall_post_fchown32(res, ...)
19551963
#define __sanitizer_syscall_post_ftime(res, ...)
19561964
#define __sanitizer_syscall_post_ftruncate64(res, ...)
1957-
#define __sanitizer_syscall_post_futex(res, ...)
19581965
#define __sanitizer_syscall_post_getegid32(res, ...)
19591966
#define __sanitizer_syscall_post_geteuid32(res, ...)
19601967
#define __sanitizer_syscall_post_getgid32(res, ...)
@@ -3093,6 +3100,11 @@ void __sanitizer_syscall_post_impl_rt_sigaction(long res, long signum, long act,
30933100
long oldact, long sz);
30943101
void __sanitizer_syscall_pre_impl_sigaltstack(long ss, long oss);
30953102
void __sanitizer_syscall_post_impl_sigaltstack(long res, long ss, long oss);
3103+
void __sanitizer_syscall_pre_impl_futex(long uaddr, long futex_op, long val,
3104+
long timeout, long uaddr2, long val3);
3105+
void __sanitizer_syscall_post_impl_futex(long res, long uaddr, long futex_op,
3106+
long val, long timeout, long uaddr2,
3107+
long val3);
30963108
#ifdef __cplusplus
30973109
} // extern "C"
30983110
#endif
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===-- sanitizer/nsan_interface.h ------------------------------*- C++ -*-===//
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+
// Public interface for nsan.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
#ifndef SANITIZER_NSAN_INTERFACE_H
13+
#define SANITIZER_NSAN_INTERFACE_H
14+
15+
#include <sanitizer/common_interface_defs.h>
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
/// User-provided default option settings.
22+
///
23+
/// You can provide your own implementation of this function to return a string
24+
/// containing NSan runtime options (for example,
25+
/// <c>verbosity=1:halt_on_error=0</c>).
26+
///
27+
/// \returns Default options string.
28+
const char *__nsan_default_options(void);
29+
30+
// Dumps nsan shadow data for a block of `size_bytes` bytes of application
31+
// memory at location `addr`.
32+
//
33+
// Each line contains application address, shadow types, then values.
34+
// Unknown types are shown as `__`, while known values are shown as
35+
// `f`, `d`, `l` for float, double, and long double respectively. Position is
36+
// shown as a single hex digit. The shadow value itself appears on the line that
37+
// contains the first byte of the value.
38+
// FIXME: Show both shadow and application value.
39+
//
40+
// Example: `__nsan_dump_shadow_mem(addr, 32, 8, 0)` might print:
41+
//
42+
// 0x0add7359: __ f0 f1 f2 f3 __ __ __ (42.000)
43+
// 0x0add7361: __ d1 d2 d3 d4 d5 d6 d7
44+
// 0x0add7369: d8 f0 f1 f2 f3 __ __ f2 (-1.000) (12.5)
45+
// 0x0add7371: f3 __ __ __ __ __ __ __
46+
//
47+
// This means that there is:
48+
// - a shadow double for the float at address 0x0add7360, with value 42;
49+
// - a shadow float128 for the double at address 0x0add7362, with value -1;
50+
// - a shadow double for the float at address 0x0add736a, with value 12.5;
51+
// There was also a shadow double for the float at address 0x0add736e, but bytes
52+
// f0 and f1 were overwritten by one or several stores, so that the shadow value
53+
// is no longer valid.
54+
// The argument `reserved` can be any value. Its true value is provided by the
55+
// instrumentation.
56+
void __nsan_dump_shadow_mem(const char *addr, size_t size_bytes,
57+
size_t bytes_per_line, size_t reserved);
58+
59+
// Explicitly dumps a value.
60+
// FIXME: vector versions ?
61+
void __nsan_dump_float(float value);
62+
void __nsan_dump_double(double value);
63+
void __nsan_dump_longdouble(long double value);
64+
65+
// Explicitly checks a value.
66+
// FIXME: vector versions ?
67+
void __nsan_check_float(float value);
68+
void __nsan_check_double(double value);
69+
void __nsan_check_longdouble(long double value);
70+
71+
#ifdef __cplusplus
72+
} // extern "C"
73+
#endif
74+
75+
#endif // SANITIZER_NSAN_INTERFACE_H

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,15 @@ struct Allocator {
717717
return;
718718
}
719719

720-
RunFreeHooks(ptr);
720+
if (RunFreeHooks(ptr)) {
721+
// Someone used __sanitizer_ignore_free_hook() and decided that they
722+
// didn't want the memory to __sanitizer_ignore_free_hook freed right now.
723+
// When they call free() on this pointer again at a later time, we should
724+
// ignore the alloc-type mismatch and allow them to deallocate the pointer
725+
// through free(), rather than the initial alloc type.
726+
m->alloc_type = FROM_MALLOC;
727+
return;
728+
}
721729

722730
// Must mark the chunk as quarantined before any changes to its metadata.
723731
// Do not quarantine given chunk if we failed to set CHUNK_QUARANTINE flag.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr,
245245
InternalScopedString str;
246246
str.AppendF(" [%zd, %zd)", var.beg, var_end);
247247
// Render variable name.
248-
str.AppendF(" '");
248+
str.Append(" '");
249249
for (uptr i = 0; i < var.name_len; ++i) {
250250
str.AppendF("%c", var.name_pos[i]);
251251
}
252-
str.AppendF("'");
252+
str.Append("'");
253253
if (var.line > 0) {
254254
str.AppendF(" (line %zd)", var.line);
255255
}
@@ -260,7 +260,7 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr,
260260
str.AppendF("%s <== Memory access at offset %zd %s this variable%s\n",
261261
d.Location(), addr, pos_descr, d.Default());
262262
} else {
263-
str.AppendF("\n");
263+
str.Append("\n");
264264
}
265265
Printf("%s", str.data());
266266
}
@@ -292,7 +292,7 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
292292
str.AppendF(" global variable '%s' defined in '",
293293
MaybeDemangleGlobalName(g.name));
294294
PrintGlobalLocation(&str, g, /*print_module_name=*/false);
295-
str.AppendF("' (0x%zx) of size %zu\n", g.beg, g.size);
295+
str.AppendF("' (%p) of size %zu\n", (void *)g.beg, g.size);
296296
str.Append(d.Default());
297297
PrintGlobalNameIfASCII(&str, g);
298298
Printf("%s", str.data());

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ void AsanCheckDynamicRTPrereqs() {}
5757
void AsanCheckIncompatibleRT() {}
5858
void InitializeAsanInterceptors() {}
5959

60-
void *AsanDoesNotSupportStaticLinkage() { return nullptr; }
61-
6260
void InitializePlatformExceptionHandlers() {}
6361
void AsanOnDeadlySignal(int signo, void *siginfo, void *context) {
6462
UNIMPLEMENTED();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ void __asan_unregister_image_globals(uptr *flag) {
345345
}
346346

347347
void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
348-
if (*flag) return;
349-
if (!start) return;
348+
if (*flag || start == stop)
349+
return;
350350
CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
351351
__asan_global *globals_start = (__asan_global*)start;
352352
__asan_global *globals_stop = (__asan_global*)stop;
@@ -355,8 +355,8 @@ void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
355355
}
356356

357357
void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop) {
358-
if (!*flag) return;
359-
if (!start) return;
358+
if (!*flag || start == stop)
359+
return;
360360
CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
361361
__asan_global *globals_start = (__asan_global*)start;
362362
__asan_global *globals_stop = (__asan_global*)stop;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ namespace __asan {
1717

1818
#pragma section(".ASAN$GA", read, write)
1919
#pragma section(".ASAN$GZ", read, write)
20-
extern "C" __declspec(allocate(".ASAN$GA"))
21-
ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_start = {};
22-
extern "C" __declspec(allocate(".ASAN$GZ"))
23-
ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_end = {};
20+
extern "C" alignas(sizeof(__asan_global))
21+
__declspec(allocate(".ASAN$GA")) __asan_global __asan_globals_start = {};
22+
extern "C" alignas(sizeof(__asan_global))
23+
__declspec(allocate(".ASAN$GZ")) __asan_global __asan_globals_end = {};
2424
#pragma comment(linker, "/merge:.ASAN=.data")
2525

2626
static void call_on_globals(void (*hook)(__asan_global *, uptr)) {

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

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ INTERCEPTOR(int, pthread_timedjoin_np, void *thread, void **ret,
333333
}
334334
# endif
335335

336-
DEFINE_REAL_PTHREAD_FUNCTIONS
336+
DEFINE_INTERNAL_PTHREAD_FUNCTIONS
337337
#endif // ASAN_INTERCEPT_PTHREAD_CREATE
338338

339339
#if ASAN_INTERCEPT_SWAPCONTEXT
@@ -352,8 +352,16 @@ static void ClearShadowMemoryForContextStack(uptr stack, uptr ssize) {
352352
PoisonShadow(bottom, ssize, 0);
353353
}
354354

355+
// Since Solaris 10/SPARC, ucp->uc_stack.ss_sp refers to the stack base address
356+
// as on other targets. For binary compatibility, the new version uses a
357+
// different external name, so we intercept that.
358+
# if SANITIZER_SOLARIS && defined(__sparc__)
359+
INTERCEPTOR(void, __makecontext_v2, struct ucontext_t *ucp, void (*func)(),
360+
int argc, ...) {
361+
# else
355362
INTERCEPTOR(void, makecontext, struct ucontext_t *ucp, void (*func)(), int argc,
356363
...) {
364+
# endif
357365
va_list ap;
358366
uptr args[64];
359367
// We don't know a better way to forward ... into REAL function. We can
@@ -373,7 +381,11 @@ INTERCEPTOR(void, makecontext, struct ucontext_t *ucp, void (*func)(), int argc,
373381
ENUMERATE_ARRAY_16(0), ENUMERATE_ARRAY_16(16), ENUMERATE_ARRAY_16(32), \
374382
ENUMERATE_ARRAY_16(48)
375383

384+
# if SANITIZER_SOLARIS && defined(__sparc__)
385+
REAL(__makecontext_v2)
386+
# else
376387
REAL(makecontext)
388+
# endif
377389
((struct ucontext_t *)ucp, func, argc, ENUMERATE_ARRAY_64());
378390

379391
# undef ENUMERATE_ARRAY_4
@@ -558,6 +570,17 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) {
558570
return REAL(strcpy)(to, from);
559571
}
560572

573+
// Windows doesn't always define the strdup identifier,
574+
// and when it does it's a macro defined to either _strdup
575+
// or _strdup_dbg, _strdup_dbg ends up calling _strdup, so
576+
// we want to intercept that. push/pop_macro are used to avoid problems
577+
// if this file ends up including <string.h> in the future.
578+
# if SANITIZER_WINDOWS
579+
# pragma push_macro("strdup")
580+
# undef strdup
581+
# define strdup _strdup
582+
# endif
583+
561584
INTERCEPTOR(char*, strdup, const char *s) {
562585
void *ctx;
563586
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
@@ -575,7 +598,7 @@ INTERCEPTOR(char*, strdup, const char *s) {
575598
return reinterpret_cast<char*>(new_mem);
576599
}
577600

578-
#if ASAN_INTERCEPT___STRDUP
601+
# if ASAN_INTERCEPT___STRDUP
579602
INTERCEPTOR(char*, __strdup, const char *s) {
580603
void *ctx;
581604
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
@@ -724,7 +747,7 @@ INTERCEPTOR(int, atexit, void (*func)()) {
724747
extern "C" {
725748
extern int _pthread_atfork(void (*prepare)(), void (*parent)(),
726749
void (*child)());
727-
};
750+
}
728751

729752
INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(),
730753
void (*child)()) {
@@ -738,8 +761,8 @@ INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(),
738761
#endif
739762

740763
#if ASAN_INTERCEPT_VFORK
741-
DEFINE_REAL(int, vfork)
742-
DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(int, vfork)
764+
DEFINE_REAL(int, vfork,)
765+
DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(int, vfork,)
743766
#endif
744767

745768
// ---------------------- InitializeAsanInterceptors ---------------- {{{1
@@ -758,7 +781,7 @@ void InitializeAsanInterceptors() {
758781
ASAN_INTERCEPT_FUNC(strncat);
759782
ASAN_INTERCEPT_FUNC(strncpy);
760783
ASAN_INTERCEPT_FUNC(strdup);
761-
#if ASAN_INTERCEPT___STRDUP
784+
# if ASAN_INTERCEPT___STRDUP
762785
ASAN_INTERCEPT_FUNC(__strdup);
763786
#endif
764787
#if ASAN_INTERCEPT_INDEX && ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
@@ -780,7 +803,12 @@ void InitializeAsanInterceptors() {
780803

781804
# if ASAN_INTERCEPT_SWAPCONTEXT
782805
ASAN_INTERCEPT_FUNC(swapcontext);
806+
// See the makecontext interceptor above for an explanation.
807+
# if SANITIZER_SOLARIS && defined(__sparc__)
808+
ASAN_INTERCEPT_FUNC(__makecontext_v2);
809+
# else
783810
ASAN_INTERCEPT_FUNC(makecontext);
811+
# endif
784812
# endif
785813
# if ASAN_INTERCEPT__LONGJMP
786814
ASAN_INTERCEPT_FUNC(_longjmp);
@@ -849,6 +877,10 @@ void InitializeAsanInterceptors() {
849877
VReport(1, "AddressSanitizer: libc interceptors initialized\n");
850878
}
851879

880+
# if SANITIZER_WINDOWS
881+
# pragma pop_macro("strdup")
882+
# endif
883+
852884
} // namespace __asan
853885

854886
#endif // !SANITIZER_FUCHSIA && !SANITIZER_RTEMS && !SANITIZER_EMSCRIPTEN

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ void ReplaceSystemMalloc();
8080

8181
// asan_linux.cpp / asan_mac.cpp / asan_win.cpp
8282
uptr FindDynamicShadowStart();
83-
void *AsanDoesNotSupportStaticLinkage();
8483
void AsanCheckDynamicRTPrereqs();
8584
void AsanCheckIncompatibleRT();
8685

0 commit comments

Comments
 (0)