Skip to content

Commit

Permalink
Update compiler-rt to LLVM 19.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
aheejin committed Nov 15, 2024
1 parent 4a4e165 commit 5debfcc
Show file tree
Hide file tree
Showing 101 changed files with 1,046 additions and 961 deletions.
15 changes: 11 additions & 4 deletions system/lib/compiler-rt/include/sanitizer/allocator_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,20 @@ size_t SANITIZER_CDECL __sanitizer_get_free_bytes(void);
size_t SANITIZER_CDECL __sanitizer_get_unmapped_bytes(void);

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

/* Installs a pair of hooks for malloc/free.
Several (currently, 5) hook pairs may be installed, they are executed
Expand Down
16 changes: 14 additions & 2 deletions system/lib/compiler-rt/include/sanitizer/linux_syscall_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,15 @@
__sanitizer_syscall_pre_impl_sigaltstack((long)ss, (long)oss)
#define __sanitizer_syscall_post_sigaltstack(res, ss, oss) \
__sanitizer_syscall_post_impl_sigaltstack(res, (long)ss, (long)oss)
#define __sanitizer_syscall_pre_futex(uaddr, futex_op, val, timeout, uaddr2, \
val3) \
__sanitizer_syscall_pre_impl_futex((long)uaddr, (long)futex_op, (long)val, \
(long)timeout, (long)uaddr2, (long)val3)
#define __sanitizer_syscall_post_futex(res, uaddr, futex_op, val, timeout, \
uaddr2, val3) \
__sanitizer_syscall_post_impl_futex(res, (long)uaddr, (long)futex_op, \
(long)val, (long)timeout, (long)uaddr2, \
(long)val3)

// And now a few syscalls we don't handle yet.
#define __sanitizer_syscall_pre_afs_syscall(...)
Expand All @@ -1875,7 +1884,6 @@
#define __sanitizer_syscall_pre_fchown32(...)
#define __sanitizer_syscall_pre_ftime(...)
#define __sanitizer_syscall_pre_ftruncate64(...)
#define __sanitizer_syscall_pre_futex(...)
#define __sanitizer_syscall_pre_getegid32(...)
#define __sanitizer_syscall_pre_geteuid32(...)
#define __sanitizer_syscall_pre_getgid32(...)
Expand Down Expand Up @@ -1954,7 +1962,6 @@
#define __sanitizer_syscall_post_fchown32(res, ...)
#define __sanitizer_syscall_post_ftime(res, ...)
#define __sanitizer_syscall_post_ftruncate64(res, ...)
#define __sanitizer_syscall_post_futex(res, ...)
#define __sanitizer_syscall_post_getegid32(res, ...)
#define __sanitizer_syscall_post_geteuid32(res, ...)
#define __sanitizer_syscall_post_getgid32(res, ...)
Expand Down Expand Up @@ -3093,6 +3100,11 @@ void __sanitizer_syscall_post_impl_rt_sigaction(long res, long signum, long act,
long oldact, long sz);
void __sanitizer_syscall_pre_impl_sigaltstack(long ss, long oss);
void __sanitizer_syscall_post_impl_sigaltstack(long res, long ss, long oss);
void __sanitizer_syscall_pre_impl_futex(long uaddr, long futex_op, long val,
long timeout, long uaddr2, long val3);
void __sanitizer_syscall_post_impl_futex(long res, long uaddr, long futex_op,
long val, long timeout, long uaddr2,
long val3);
#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
10 changes: 9 additions & 1 deletion system/lib/compiler-rt/lib/asan/asan_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,15 @@ struct Allocator {
return;
}

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

// Must mark the chunk as quarantined before any changes to its metadata.
// Do not quarantine given chunk if we failed to set CHUNK_QUARANTINE flag.
Expand Down
8 changes: 4 additions & 4 deletions system/lib/compiler-rt/lib/asan/asan_descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr,
InternalScopedString str;
str.AppendF(" [%zd, %zd)", var.beg, var_end);
// Render variable name.
str.AppendF(" '");
str.Append(" '");
for (uptr i = 0; i < var.name_len; ++i) {
str.AppendF("%c", var.name_pos[i]);
}
str.AppendF("'");
str.Append("'");
if (var.line > 0) {
str.AppendF(" (line %zd)", var.line);
}
Expand All @@ -260,7 +260,7 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr,
str.AppendF("%s <== Memory access at offset %zd %s this variable%s\n",
d.Location(), addr, pos_descr, d.Default());
} else {
str.AppendF("\n");
str.Append("\n");
}
Printf("%s", str.data());
}
Expand Down Expand Up @@ -292,7 +292,7 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
str.AppendF(" global variable '%s' defined in '",
MaybeDemangleGlobalName(g.name));
PrintGlobalLocation(&str, g, /*print_module_name=*/false);
str.AppendF("' (0x%zx) of size %zu\n", g.beg, g.size);
str.AppendF("' (%p) of size %zu\n", (void *)g.beg, g.size);
str.Append(d.Default());
PrintGlobalNameIfASCII(&str, g);
Printf("%s", str.data());
Expand Down
2 changes: 0 additions & 2 deletions system/lib/compiler-rt/lib/asan/asan_fuchsia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ void AsanCheckDynamicRTPrereqs() {}
void AsanCheckIncompatibleRT() {}
void InitializeAsanInterceptors() {}

void *AsanDoesNotSupportStaticLinkage() { return nullptr; }

void InitializePlatformExceptionHandlers() {}
void AsanOnDeadlySignal(int signo, void *siginfo, void *context) {
UNIMPLEMENTED();
Expand Down
8 changes: 4 additions & 4 deletions system/lib/compiler-rt/lib/asan/asan_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ void __asan_unregister_image_globals(uptr *flag) {
}

void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
if (*flag) return;
if (!start) return;
if (*flag || start == stop)
return;
CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
__asan_global *globals_start = (__asan_global*)start;
__asan_global *globals_stop = (__asan_global*)stop;
Expand All @@ -355,8 +355,8 @@ void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
}

void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop) {
if (!*flag) return;
if (!start) return;
if (!*flag || start == stop)
return;
CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
__asan_global *globals_start = (__asan_global*)start;
__asan_global *globals_stop = (__asan_global*)stop;
Expand Down
8 changes: 4 additions & 4 deletions system/lib/compiler-rt/lib/asan/asan_globals_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace __asan {

#pragma section(".ASAN$GA", read, write)
#pragma section(".ASAN$GZ", read, write)
extern "C" __declspec(allocate(".ASAN$GA"))
ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_start = {};
extern "C" __declspec(allocate(".ASAN$GZ"))
ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_end = {};
extern "C" alignas(sizeof(__asan_global))
__declspec(allocate(".ASAN$GA")) __asan_global __asan_globals_start = {};
extern "C" alignas(sizeof(__asan_global))
__declspec(allocate(".ASAN$GZ")) __asan_global __asan_globals_end = {};
#pragma comment(linker, "/merge:.ASAN=.data")

static void call_on_globals(void (*hook)(__asan_global *, uptr)) {
Expand Down
44 changes: 38 additions & 6 deletions system/lib/compiler-rt/lib/asan/asan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ INTERCEPTOR(int, pthread_timedjoin_np, void *thread, void **ret,
}
# endif

DEFINE_REAL_PTHREAD_FUNCTIONS
DEFINE_INTERNAL_PTHREAD_FUNCTIONS
#endif // ASAN_INTERCEPT_PTHREAD_CREATE

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

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

# if SANITIZER_SOLARIS && defined(__sparc__)
REAL(__makecontext_v2)
# else
REAL(makecontext)
# endif
((struct ucontext_t *)ucp, func, argc, ENUMERATE_ARRAY_64());

# undef ENUMERATE_ARRAY_4
Expand Down Expand Up @@ -558,6 +570,17 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) {
return REAL(strcpy)(to, from);
}

// Windows doesn't always define the strdup identifier,
// and when it does it's a macro defined to either _strdup
// or _strdup_dbg, _strdup_dbg ends up calling _strdup, so
// we want to intercept that. push/pop_macro are used to avoid problems
// if this file ends up including <string.h> in the future.
# if SANITIZER_WINDOWS
# pragma push_macro("strdup")
# undef strdup
# define strdup _strdup
# endif

INTERCEPTOR(char*, strdup, const char *s) {
void *ctx;
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
Expand All @@ -575,7 +598,7 @@ INTERCEPTOR(char*, strdup, const char *s) {
return reinterpret_cast<char*>(new_mem);
}

#if ASAN_INTERCEPT___STRDUP
# if ASAN_INTERCEPT___STRDUP
INTERCEPTOR(char*, __strdup, const char *s) {
void *ctx;
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
Expand Down Expand Up @@ -724,7 +747,7 @@ INTERCEPTOR(int, atexit, void (*func)()) {
extern "C" {
extern int _pthread_atfork(void (*prepare)(), void (*parent)(),
void (*child)());
};
}

INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(),
void (*child)()) {
Expand All @@ -738,8 +761,8 @@ INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(),
#endif

#if ASAN_INTERCEPT_VFORK
DEFINE_REAL(int, vfork)
DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(int, vfork)
DEFINE_REAL(int, vfork,)
DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(int, vfork,)
#endif

// ---------------------- InitializeAsanInterceptors ---------------- {{{1
Expand All @@ -758,7 +781,7 @@ void InitializeAsanInterceptors() {
ASAN_INTERCEPT_FUNC(strncat);
ASAN_INTERCEPT_FUNC(strncpy);
ASAN_INTERCEPT_FUNC(strdup);
#if ASAN_INTERCEPT___STRDUP
# if ASAN_INTERCEPT___STRDUP
ASAN_INTERCEPT_FUNC(__strdup);
#endif
#if ASAN_INTERCEPT_INDEX && ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
Expand All @@ -780,7 +803,12 @@ void InitializeAsanInterceptors() {

# if ASAN_INTERCEPT_SWAPCONTEXT
ASAN_INTERCEPT_FUNC(swapcontext);
// See the makecontext interceptor above for an explanation.
# if SANITIZER_SOLARIS && defined(__sparc__)
ASAN_INTERCEPT_FUNC(__makecontext_v2);
# else
ASAN_INTERCEPT_FUNC(makecontext);
# endif
# endif
# if ASAN_INTERCEPT__LONGJMP
ASAN_INTERCEPT_FUNC(_longjmp);
Expand Down Expand Up @@ -849,6 +877,10 @@ void InitializeAsanInterceptors() {
VReport(1, "AddressSanitizer: libc interceptors initialized\n");
}

# if SANITIZER_WINDOWS
# pragma pop_macro("strdup")
# endif

} // namespace __asan

#endif // !SANITIZER_FUCHSIA && !SANITIZER_RTEMS && !SANITIZER_EMSCRIPTEN
1 change: 0 additions & 1 deletion system/lib/compiler-rt/lib/asan/asan_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void ReplaceSystemMalloc();

// asan_linux.cpp / asan_mac.cpp / asan_win.cpp
uptr FindDynamicShadowStart();
void *AsanDoesNotSupportStaticLinkage();
void AsanCheckDynamicRTPrereqs();
void AsanCheckIncompatibleRT();

Expand Down
11 changes: 2 additions & 9 deletions system/lib/compiler-rt/lib/asan/asan_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@

# if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS
# include <ucontext.h>
extern "C" void *_DYNAMIC;
# elif SANITIZER_NETBSD
# include <link_elf.h>
# include <ucontext.h>
extern Elf_Dyn _DYNAMIC;
# else
# include <link.h>
# include <sys/ucontext.h>
extern ElfW(Dyn) _DYNAMIC[];
# endif

typedef enum {
Expand All @@ -76,11 +73,6 @@ void InitializePlatformInterceptors() {}
void InitializePlatformExceptionHandlers() {}
bool IsSystemHeapAddress(uptr addr) { return false; }

void *AsanDoesNotSupportStaticLinkage() {
// This will fail to link with -static.
return &_DYNAMIC;
}

# if ASAN_PREMAP_SHADOW
uptr FindPremappedShadowStart(uptr shadow_size_bytes) {
uptr granularity = GetMmapGranularity();
Expand All @@ -101,7 +93,8 @@ uptr FindDynamicShadowStart() {
# endif

return MapDynamicShadow(shadow_size_bytes, ASAN_SHADOW_SCALE,
/*min_shadow_base_alignment*/ 0, kHighMemEnd);
/*min_shadow_base_alignment*/ 0, kHighMemEnd,
GetMmapGranularity());
}

void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {
Expand Down
8 changes: 2 additions & 6 deletions system/lib/compiler-rt/lib/asan/asan_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ void InitializePlatformInterceptors() {}
void InitializePlatformExceptionHandlers() {}
bool IsSystemHeapAddress (uptr addr) { return false; }

// No-op. Mac does not support static linkage anyway.
void *AsanDoesNotSupportStaticLinkage() {
return 0;
}

uptr FindDynamicShadowStart() {
return MapDynamicShadow(MemToShadowSize(kHighMemEnd), ASAN_SHADOW_SCALE,
/*min_shadow_base_alignment*/ 0, kHighMemEnd);
/*min_shadow_base_alignment*/ 0, kHighMemEnd,
GetMmapGranularity());
}

// No-op. Mac does not support static linkage anyway.
Expand Down
4 changes: 2 additions & 2 deletions system/lib/compiler-rt/lib/asan/asan_malloc_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ struct MallocDebugL {
void* (*valloc)(uptr size);
};

ALIGNED(32) const MallocDebugK asan_malloc_dispatch_k = {
alignas(32) const MallocDebugK asan_malloc_dispatch_k = {
WRAP(malloc), WRAP(free), WRAP(calloc),
WRAP(realloc), WRAP(memalign), WRAP(malloc_usable_size)};

ALIGNED(32) const MallocDebugL asan_malloc_dispatch_l = {
alignas(32) const MallocDebugL asan_malloc_dispatch_l = {
WRAP(calloc), WRAP(free), WRAP(mallinfo),
WRAP(malloc), WRAP(malloc_usable_size), WRAP(memalign),
WRAP(posix_memalign), WRAP(pvalloc), WRAP(realloc),
Expand Down
7 changes: 5 additions & 2 deletions system/lib/compiler-rt/lib/asan/asan_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@
// || `[0x2000000000, 0x23ffffffff]` || LowShadow ||
// || `[0x0000000000, 0x1fffffffff]` || LowMem ||
//
// Default Linux/RISCV64 Sv39 mapping:
// Default Linux/RISCV64 Sv39 mapping with SHADOW_OFFSET == 0xd55550000;
// (the exact location of SHADOW_OFFSET may vary depending the dynamic probing
// by FindDynamicShadowStart).
//
// || `[0x1555550000, 0x3fffffffff]` || HighMem ||
// || `[0x0fffffa000, 0x1555555fff]` || HighShadow ||
// || `[0x0effffa000, 0x0fffff9fff]` || ShadowGap ||
Expand Down Expand Up @@ -186,7 +189,7 @@
# elif SANITIZER_FREEBSD && defined(__aarch64__)
# define ASAN_SHADOW_OFFSET_CONST 0x0000800000000000
# elif SANITIZER_RISCV64
# define ASAN_SHADOW_OFFSET_CONST 0x0000000d55550000
# define ASAN_SHADOW_OFFSET_DYNAMIC
# elif defined(__aarch64__)
# define ASAN_SHADOW_OFFSET_CONST 0x0000001000000000
# elif defined(__powerpc64__)
Expand Down
10 changes: 4 additions & 6 deletions system/lib/compiler-rt/lib/asan/asan_preinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
using namespace __asan;

#if SANITIZER_CAN_USE_PREINIT_ARRAY
// The symbol is called __local_asan_preinit, because it's not intended to be
// exported.
// This code linked into the main executable when -fsanitize=address is in
// the link flags. It can only use exported interface functions.
__attribute__((section(".preinit_array"), used))
void (*__local_asan_preinit)(void) = __asan_init;
// This section is linked into the main executable when -fsanitize=address is
// specified to perform initialization at a very early stage.
__attribute__((section(".preinit_array"), used)) static auto preinit =
__asan_init;
#endif
Loading

0 comments on commit 5debfcc

Please sign in to comment.