From 829ed78471828ce9eaefd59a9d9c0cb4de1699dc Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Fri, 14 Mar 2025 13:37:39 -0400 Subject: [PATCH 01/18] [sanitizer_common] recognize AIX --- .../sanitizer_allocator_internal.h | 5 ++ .../sanitizer_allocator_primary32.h | 1 + .../sanitizer_common/sanitizer_atomic_clang.h | 16 ++++ .../sanitizer_common_libcdep.cpp | 7 +- .../lib/sanitizer_common/sanitizer_errno.h | 2 + .../lib/sanitizer_common/sanitizer_flags.inc | 3 + .../lib/sanitizer_common/sanitizer_platform.h | 17 +++- .../sanitizer_platform_limits_posix.cpp | 40 +++++++-- .../sanitizer_platform_limits_posix.h | 82 ++++++++++++++++--- .../lib/sanitizer_common/sanitizer_posix.cpp | 2 +- 10 files changed, 156 insertions(+), 19 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h index 62523c7ae187c..e5b912d70e61e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h @@ -23,7 +23,12 @@ namespace __sanitizer { typedef CompactSizeClassMap InternalSizeClassMap; struct AP32 { +// For AIX 64-bit, the mmap begin is at address 0x0a00000000000000ULL. +#if SANITIZER_AIX && SANITIZER_WORDSIZE == 64 + static const uptr kSpaceBeg = 0x0a00000000000000ULL; +#else static const uptr kSpaceBeg = 0; +#endif static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; static const uptr kMetadataSize = 0; typedef InternalSizeClassMap SizeClassMap; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h index 602b197c42ae3..0faf9b3c151a4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h @@ -288,6 +288,7 @@ class SizeClassAllocator32 { uptr ComputeRegionId(uptr mem) const { if (SANITIZER_SIGN_EXTENDED_ADDRESSES) mem &= (kSpaceSize - 1); + mem -= kSpaceBeg; const uptr res = mem >> kRegionSizeLog; CHECK_LT(res, kNumPossibleRegions); return res; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h index 1414092e38d7e..db4805468c2d5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h @@ -14,6 +14,18 @@ #ifndef SANITIZER_ATOMIC_CLANG_H #define SANITIZER_ATOMIC_CLANG_H +// Helper to suppress warnings related to 8-byte atomic accesses when the target +// is 32-bit AIX (where such accesses use libatomic). +#if defined(_AIX) && !defined(__powerpc64__) && defined(__clang__) +#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Watomic-alignment\"") +#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END _Pragma("clang diagnostic pop") +#else +#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN +#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END +#endif + namespace __sanitizer { // We use the compiler builtin atomic operations for loads and stores, which @@ -35,6 +47,8 @@ inline void proc_yield(int cnt) { #endif } +SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN + template inline typename T::Type atomic_load(const volatile T *a, memory_order mo) { DCHECK(mo == memory_order_relaxed || mo == memory_order_consume || @@ -92,6 +106,8 @@ inline bool atomic_compare_exchange_weak(volatile T *a, typename T::Type *cmp, return atomic_compare_exchange_strong(a, cmp, xchg, mo); } +SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END + } // namespace __sanitizer #undef ATOMIC_ORDER diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp index f275e81ff0416..a770c8cf656b3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp @@ -169,7 +169,12 @@ void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name, : !MmapFixedNoReserve(beg, size, name)) { Report( "ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. " - "Perhaps you're using ulimit -v or ulimit -d\n", + "Perhaps you're using ulimit -v " +#if SANITIZER_AIX && SANITIZER_WORDSIZE == 32 + "or using large address-space model for 32-bit XCOFF by using ldedit " + "or setting LDR_CNTRL=MAXDATA or compiling the binary with -bmaxdata " +#endif + "\n", size); Die(); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_errno.h b/compiler-rt/lib/sanitizer_common/sanitizer_errno.h index 76919da57d942..0d2a9307cde6f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_errno.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_errno.h @@ -31,6 +31,8 @@ # define __errno_location _errno #elif SANITIZER_HAIKU # define __errno_location _errnop +#elif SANITIZER_AIX +# define __errno_location _Errno #endif extern "C" int *__errno_location(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc index c1e3530618c20..a6c760b2387fb 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc @@ -269,6 +269,9 @@ COMMON_FLAG(bool, detect_write_exec, false, COMMON_FLAG(bool, test_only_emulate_no_memorymap, false, "TEST ONLY fail to read memory mappings to emulate sanitized " "\"init\"") +COMMON_FLAG(bool, enable_unmalloced_free_check, !SANITIZER_AIX, + "if true, FreeNotMalloced error will be reported. Only disable " + "this error detecting on AIX by default for now.") // With static linking, dladdr((void*)pthread_join) or similar will return the // path to the main program. This flag will replace dlopen(
// with dlopen(NULL,...), which is the correct way to get a handle to the main diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h index 9f5f41cd85514..982011eedd75a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h @@ -14,7 +14,8 @@ #if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ !defined(__APPLE__) && !defined(_WIN32) && !defined(__Fuchsia__) && \ - !(defined(__sun__) && defined(__svr4__)) && !defined(__HAIKU__) + !(defined(__sun__) && defined(__svr4__)) && !defined(__HAIKU__) && \ + !defined(_AIX) # error "This operating system is not supported" #endif @@ -31,6 +32,12 @@ # define SANITIZER_LINUX 0 #endif +#if defined(_AIX) +# define SANITIZER_AIX 1 +#else +# define SANITIZER_AIX 0 +#endif + #if defined(__GLIBC__) # define SANITIZER_GLIBC 1 #else @@ -144,7 +151,11 @@ #define SANITIZER_POSIX \ (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_APPLE || \ +<<<<<<< HEAD SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_HAIKU) +======= + SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_AIX) +>>>>>>> d8273ed5690f ([sanitizer_common] recognize AIX) #if __LP64__ || defined(_WIN64) # define SANITIZER_WORDSIZE 64 @@ -398,7 +409,9 @@ // (ie. same as double) to 128-bit long double. On those, glibc symbols // involving long doubles come in two versions, and we need to pass the // correct one to dlvsym when intercepting them. -#if SANITIZER_LINUX && (SANITIZER_S390 || SANITIZER_PPC32 || SANITIZER_PPC64V1) +#if SANITIZER_LINUX && \ + (SANITIZER_S390 || (SANITIZER_PPC32 && !SANITIZER_AIX) || \ + SANITIZER_PPC64V1) # define SANITIZER_NLDBL_VERSION "GLIBC_2.4" #endif diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp index b4d87ab6228e5..87bada2d5fef2 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -24,7 +24,7 @@ // Must go after undef _FILE_OFFSET_BITS. #include "sanitizer_platform.h" -#if SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU +#if SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX // Must go after undef _FILE_OFFSET_BITS. #include "sanitizer_glibc_version.h" @@ -61,7 +61,7 @@ #endif #if !SANITIZER_ANDROID -#if !SANITIZER_HAIKU +#if !SANITIZER_HAIKU && !SANITIZER_AIX #include #endif #include @@ -112,7 +112,11 @@ typedef struct user_fpregs elf_fpregset_t; #endif #if !SANITIZER_ANDROID +#if !SANITIZER_AIX #include +#else +#include +#endif #if !SANITIZER_HAIKU #include #include @@ -177,6 +181,17 @@ typedef struct user_fpregs elf_fpregset_t; #include #endif +#if SANITIZER_AIX +#include +#include +#include +#include +#include +#if HAVE_RPC_XDR_H +#include +#endif +#endif + #if SANITIZER_HAIKU #include #include @@ -563,6 +578,19 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); unsigned IOCTL_FIONBIO = FIONBIO; #if !SANITIZER_HAIKU unsigned IOCTL_FIOASYNC = FIOASYNC; + unsigned IOCTL_FIONBIO = FIONBIO; + unsigned IOCTL_FIOSETOWN = FIOSETOWN; + unsigned IOCTL_SIOCSPGRP = SIOCSPGRP; + unsigned IOCTL_TIOCCONS = TIOCCONS; + unsigned IOCTL_TIOCMBIC = TIOCMBIC; + unsigned IOCTL_TIOCMBIS = TIOCMBIS; + unsigned IOCTL_TIOCMSET = TIOCMSET; + unsigned IOCTL_TIOCPKT = TIOCPKT; + unsigned IOCTL_TIOCSETD = TIOCSETD; + unsigned IOCTL_TIOCSPGRP = TIOCSPGRP; + unsigned IOCTL_TIOCSTI = TIOCSTI; + unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ; +#endif unsigned IOCTL_FIOCLEX = FIOCLEX; unsigned IOCTL_FIOGETOWN = FIOGETOWN; unsigned IOCTL_FIONCLEX = FIONCLEX; @@ -601,8 +629,6 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); unsigned IOCTL_TIOCEXCL = TIOCEXCL; unsigned IOCTL_TIOCGPGRP = TIOCGPGRP; unsigned IOCTL_TIOCGWINSZ = TIOCGWINSZ; - unsigned IOCTL_TIOCMBIC = TIOCMBIC; - unsigned IOCTL_TIOCMBIS = TIOCMBIS; unsigned IOCTL_TIOCMGET = TIOCMGET; unsigned IOCTL_TIOCMSET = TIOCMSET; unsigned IOCTL_TIOCNXCL = TIOCNXCL; @@ -1118,6 +1144,8 @@ COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent)); CHECK_SIZE_AND_OFFSET(dirent, d_ino); #if SANITIZER_APPLE CHECK_SIZE_AND_OFFSET(dirent, d_seekoff); +#elif SANITIZER_AIX +CHECK_SIZE_AND_OFFSET(dirent, d_offset); #elif SANITIZER_FREEBSD || SANITIZER_HAIKU // There is no 'd_off' field on FreeBSD. #else @@ -1208,8 +1236,10 @@ CHECK_SIZE_AND_OFFSET(tm, tm_year); CHECK_SIZE_AND_OFFSET(tm, tm_wday); CHECK_SIZE_AND_OFFSET(tm, tm_yday); CHECK_SIZE_AND_OFFSET(tm, tm_isdst); +#if !SANITIZER_AIX CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff); CHECK_SIZE_AND_OFFSET(tm, tm_zone); +#endif #if SANITIZER_LINUX CHECK_TYPE_SIZE(mntent); @@ -1261,7 +1291,7 @@ CHECK_TYPE_SIZE(clock_t); CHECK_TYPE_SIZE(clockid_t); #endif -#if !SANITIZER_ANDROID && !SANITIZER_HAIKU +#if !SANITIZER_ANDROID && !SANITIZER_HAIKU && !SANITIZER_AIX CHECK_TYPE_SIZE(ifaddrs); CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next); CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h index 348bb4f27aec3..bcb7823aeeed4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -14,7 +14,7 @@ #ifndef SANITIZER_PLATFORM_LIMITS_POSIX_H #define SANITIZER_PLATFORM_LIMITS_POSIX_H -#if SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU +#if SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX #include "sanitizer_internal_defs.h" #include "sanitizer_platform.h" @@ -29,7 +29,7 @@ #define SANITIZER_HAS_STAT64 0 #define SANITIZER_HAS_STATFS64 0 #endif -#elif SANITIZER_GLIBC || SANITIZER_ANDROID +#elif SANITIZER_GLIBC || SANITIZER_ANDROID || SANITIZER_AIX #define SANITIZER_HAS_STAT64 1 #define SANITIZER_HAS_STATFS64 1 #endif @@ -319,7 +319,7 @@ struct __sanitizer_iovec { usize iov_len; }; -#if !SANITIZER_ANDROID +#if !SANITIZER_ANDROID && !SANITIZER_AIX struct __sanitizer_ifaddrs { struct __sanitizer_ifaddrs *ifa_next; char *ifa_name; @@ -341,7 +341,7 @@ typedef unsigned long __sanitizer_pthread_key_t; typedef unsigned __sanitizer_pthread_key_t; #endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_AIX struct __sanitizer_XDR { int x_op; @@ -436,12 +436,14 @@ struct __sanitizer_tm { int tm_wday; int tm_yday; int tm_isdst; +#if !SANITIZER_AIX #if SANITIZER_HAIKU int tm_gmtoff; #else long int tm_gmtoff; #endif const char *tm_zone; +#endif }; #if SANITIZER_LINUX @@ -485,11 +487,19 @@ struct __sanitizer_msghdr { struct __sanitizer_iovec *msg_iov; uptr msg_iovlen; void *msg_control; +#if !SANITIZER_AIX uptr msg_controllen; +#else + unsigned msg_controllen; +#endif int msg_flags; }; struct __sanitizer_cmsghdr { +#if !SANITIZER_AIX uptr cmsg_len; +#else + unsigned cmsg_len; +#endif int cmsg_level; int cmsg_type; }; @@ -528,8 +538,13 @@ struct __sanitizer_dirent { }; # else struct __sanitizer_dirent { +#if SANITIZER_AIX + uptr d_offset; + uptr d_ino; +#else uptr d_ino; uptr d_off; +#endif unsigned short d_reclen; // more fields that we don't care about }; @@ -547,6 +562,9 @@ extern unsigned struct_sock_fprog_sz; #if SANITIZER_HAIKU typedef int __sanitizer_clock_t; +#if SANITIZER_AIX +typedef int __sanitizer_clock_t; +typedef int __sanitizer_clockid_t; #elif defined(__x86_64__) && !defined(_LP64) typedef long long __sanitizer_clock_t; #else @@ -609,6 +627,14 @@ struct __sanitizer_sigset_t { // The size is determined by looking at sizeof of real sigset_t on linux. uptr val[128 / sizeof(uptr)]; }; +#elif SANITIZER_AIX +struct __sanitizer_sigset_t { +#if SANITIZER_WORDSIZE == 64 + uptr val[4]; +#else + uptr val[2]; +#endif +}; #endif struct __sanitizer_siginfo_pad { @@ -799,8 +825,12 @@ struct __sanitizer_addrinfo { int ai_family; int ai_socktype; int ai_protocol; -#if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_HAIKU +#if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX +#if SANITIZER_AIX // AIX ai_addrlen type is size_t + uptr ai_addrlen; +#else unsigned ai_addrlen; +#endif char *ai_canonname; void *ai_addr; #else // LINUX @@ -809,6 +839,9 @@ struct __sanitizer_addrinfo { char *ai_canonname; #endif struct __sanitizer_addrinfo *ai_next; +#if SANITIZER_AIX + int ai_eflags; +#endif }; struct __sanitizer_hostent { @@ -825,7 +858,7 @@ struct __sanitizer_pollfd { short revents; }; -#if SANITIZER_ANDROID || SANITIZER_APPLE +#if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_AIX typedef unsigned __sanitizer_nfds_t; #else typedef unsigned long __sanitizer_nfds_t; @@ -863,6 +896,10 @@ struct __sanitizer_wordexp_t { uptr we_wordc; char **we_wordv; uptr we_offs; +#if SANITIZER_AIX + int we_sflags; + uptr we_soffs; +#endif }; #if SANITIZER_LINUX && !SANITIZER_ANDROID @@ -1122,12 +1159,39 @@ extern unsigned fpos_t_sz; // when it can not be determined without including any system headers. extern const unsigned IOCTL_NOT_PRESENT; +#if SANITIZER_AIX +extern uptr IOCTL_FIOASYNC; +extern uptr IOCTL_FIONBIO; +extern uptr IOCTL_FIOSETOWN; +extern uptr IOCTL_SIOCSPGRP; +extern uptr IOCTL_TIOCCONS; +extern uptr IOCTL_TIOCMBIC; +extern uptr IOCTL_TIOCMBIS; +extern uptr IOCTL_TIOCMSET; +extern uptr IOCTL_TIOCPKT; +extern uptr IOCTL_TIOCSETD; +extern uptr IOCTL_TIOCSPGRP; +extern uptr IOCTL_TIOCSTI; +extern uptr IOCTL_TIOCSWINSZ; +#else extern unsigned IOCTL_FIOASYNC; +extern unsigned IOCTL_FIONBIO; +extern unsigned IOCTL_FIOSETOWN; +extern unsigned IOCTL_SIOCSPGRP; +extern unsigned IOCTL_TIOCCONS; +extern unsigned IOCTL_TIOCMBIC; +extern unsigned IOCTL_TIOCMBIS; +extern unsigned IOCTL_TIOCMSET; +extern unsigned IOCTL_TIOCPKT; +extern unsigned IOCTL_TIOCSETD; +extern unsigned IOCTL_TIOCSPGRP; +extern unsigned IOCTL_TIOCSTI; +extern unsigned IOCTL_TIOCSWINSZ; +#endif + extern unsigned IOCTL_FIOCLEX; extern unsigned IOCTL_FIOGETOWN; -extern unsigned IOCTL_FIONBIO; extern unsigned IOCTL_FIONCLEX; -extern unsigned IOCTL_FIOSETOWN; extern unsigned IOCTL_SIOCADDMULTI; extern unsigned IOCTL_SIOCATMARK; extern unsigned IOCTL_SIOCDELMULTI; @@ -1159,8 +1223,6 @@ extern unsigned IOCTL_TIOCSTI; extern unsigned IOCTL_TIOCEXCL; extern unsigned IOCTL_TIOCGPGRP; extern unsigned IOCTL_TIOCGWINSZ; -extern unsigned IOCTL_TIOCMBIC; -extern unsigned IOCTL_TIOCMBIS; extern unsigned IOCTL_TIOCMGET; extern unsigned IOCTL_TIOCMSET; extern unsigned IOCTL_TIOCNXCL; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp index 69af6465a62c2..44c40036babb2 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp @@ -27,7 +27,7 @@ #include #include -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_AIX // The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before // that, it was never implemented. So just define it to zero. #undef MAP_NORESERVE From 075dd32ebd49e5403a02acc5da545eb4db0b72a5 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Tue, 1 Apr 2025 10:09:50 -0400 Subject: [PATCH 02/18] Fix formatting --- .../sanitizer_common/sanitizer_atomic_clang.h | 12 +-- .../sanitizer_common_libcdep.cpp | 4 +- .../sanitizer_platform_limits_posix.cpp | 37 +++---- .../sanitizer_platform_limits_posix.h | 96 +++++++++---------- .../lib/sanitizer_common/sanitizer_posix.cpp | 2 +- 5 files changed, 76 insertions(+), 75 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h index db4805468c2d5..b357345ec7854 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h @@ -17,13 +17,13 @@ // Helper to suppress warnings related to 8-byte atomic accesses when the target // is 32-bit AIX (where such accesses use libatomic). #if defined(_AIX) && !defined(__powerpc64__) && defined(__clang__) -#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Watomic-alignment\"") -#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END _Pragma("clang diagnostic pop") +# define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Watomic-alignment\"") +# define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END _Pragma("clang diagnostic pop") #else -#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN -#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END +# define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN +# define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END #endif namespace __sanitizer { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp index a770c8cf656b3..aa30fd9b5dd96 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp @@ -170,10 +170,10 @@ void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name, Report( "ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. " "Perhaps you're using ulimit -v " -#if SANITIZER_AIX && SANITIZER_WORDSIZE == 32 +# if SANITIZER_AIX && SANITIZER_WORDSIZE == 32 "or using large address-space model for 32-bit XCOFF by using ldedit " "or setting LDR_CNTRL=MAXDATA or compiling the binary with -bmaxdata " -#endif +# endif "\n", size); Die(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp index 87bada2d5fef2..1c54b7c0f152c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -61,7 +61,7 @@ #endif #if !SANITIZER_ANDROID -#if !SANITIZER_HAIKU && !SANITIZER_AIX +#if !SANITIZER_AIX && !SANITIZER_HAIKU #include #endif #include @@ -181,16 +181,16 @@ typedef struct user_fpregs elf_fpregset_t; #include #endif -#if SANITIZER_AIX -#include -#include -#include -#include -#include -#if HAVE_RPC_XDR_H -#include -#endif -#endif +# if SANITIZER_AIX +# include +# include +# include +# include +# include +# if HAVE_RPC_XDR_H +# include +# endif +# endif #if SANITIZER_HAIKU #include @@ -590,7 +590,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); unsigned IOCTL_TIOCSPGRP = TIOCSPGRP; unsigned IOCTL_TIOCSTI = TIOCSTI; unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ; -#endif +# endif unsigned IOCTL_FIOCLEX = FIOCLEX; unsigned IOCTL_FIOGETOWN = FIOGETOWN; unsigned IOCTL_FIONCLEX = FIONCLEX; @@ -637,6 +637,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); unsigned IOCTL_TIOCSPGRP = TIOCSPGRP; unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ; #if SANITIZER_LINUX && !SANITIZER_ANDROID + unsigned IOCTL_SIOCGETSGCNT = SIOCGETSGCNT; unsigned IOCTL_SIOCGETVIFCNT = SIOCGETVIFCNT; #endif @@ -1144,13 +1145,13 @@ COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent)); CHECK_SIZE_AND_OFFSET(dirent, d_ino); #if SANITIZER_APPLE CHECK_SIZE_AND_OFFSET(dirent, d_seekoff); -#elif SANITIZER_AIX +# elif SANITIZER_AIX CHECK_SIZE_AND_OFFSET(dirent, d_offset); #elif SANITIZER_FREEBSD || SANITIZER_HAIKU // There is no 'd_off' field on FreeBSD. -#else +# else CHECK_SIZE_AND_OFFSET(dirent, d_off); -#endif +# endif CHECK_SIZE_AND_OFFSET(dirent, d_reclen); #if SANITIZER_GLIBC @@ -1236,12 +1237,12 @@ CHECK_SIZE_AND_OFFSET(tm, tm_year); CHECK_SIZE_AND_OFFSET(tm, tm_wday); CHECK_SIZE_AND_OFFSET(tm, tm_yday); CHECK_SIZE_AND_OFFSET(tm, tm_isdst); -#if !SANITIZER_AIX +# if !SANITIZER_AIX CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff); CHECK_SIZE_AND_OFFSET(tm, tm_zone); -#endif +# endif -#if SANITIZER_LINUX +# if SANITIZER_LINUX CHECK_TYPE_SIZE(mntent); CHECK_SIZE_AND_OFFSET(mntent, mnt_fsname); CHECK_SIZE_AND_OFFSET(mntent, mnt_dir); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h index bcb7823aeeed4..eaca02ca51111 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -16,25 +16,25 @@ #if SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX -#include "sanitizer_internal_defs.h" -#include "sanitizer_platform.h" -#include "sanitizer_mallinfo.h" - -#if SANITIZER_APPLE -#include -#if !__DARWIN_ONLY_64_BIT_INO_T -#define SANITIZER_HAS_STAT64 1 -#define SANITIZER_HAS_STATFS64 1 -#else -#define SANITIZER_HAS_STAT64 0 -#define SANITIZER_HAS_STATFS64 0 -#endif -#elif SANITIZER_GLIBC || SANITIZER_ANDROID || SANITIZER_AIX -#define SANITIZER_HAS_STAT64 1 -#define SANITIZER_HAS_STATFS64 1 -#endif +# include "sanitizer_internal_defs.h" +# include "sanitizer_platform.h" +# include "sanitizer_mallinfo.h" + +# if SANITIZER_APPLE +# include +# if !__DARWIN_ONLY_64_BIT_INO_T +# define SANITIZER_HAS_STAT64 1 +# define SANITIZER_HAS_STATFS64 1 +# else +# define SANITIZER_HAS_STAT64 0 +# define SANITIZER_HAS_STATFS64 0 +# endif +# elif SANITIZER_GLIBC || SANITIZER_ANDROID || SANITIZER_AIX +# define SANITIZER_HAS_STAT64 1 +# define SANITIZER_HAS_STATFS64 1 +# endif -#if defined(__sparc__) +# if defined(__sparc__) // FIXME: This can't be included from tsan which does not support sparc yet. #include "sanitizer_glibc_version.h" #endif @@ -319,7 +319,7 @@ struct __sanitizer_iovec { usize iov_len; }; -#if !SANITIZER_ANDROID && !SANITIZER_AIX +# if !SANITIZER_ANDROID && !SANITIZER_AIX struct __sanitizer_ifaddrs { struct __sanitizer_ifaddrs *ifa_next; char *ifa_name; @@ -341,7 +341,7 @@ typedef unsigned long __sanitizer_pthread_key_t; typedef unsigned __sanitizer_pthread_key_t; #endif -#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_AIX +# if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_AIX struct __sanitizer_XDR { int x_op; @@ -443,7 +443,7 @@ struct __sanitizer_tm { long int tm_gmtoff; #endif const char *tm_zone; -#endif +# endif }; #if SANITIZER_LINUX @@ -487,19 +487,19 @@ struct __sanitizer_msghdr { struct __sanitizer_iovec *msg_iov; uptr msg_iovlen; void *msg_control; -#if !SANITIZER_AIX +# if !SANITIZER_AIX uptr msg_controllen; -#else +# else unsigned msg_controllen; -#endif +# endif int msg_flags; }; struct __sanitizer_cmsghdr { -#if !SANITIZER_AIX +# if !SANITIZER_AIX uptr cmsg_len; -#else +# else unsigned cmsg_len; -#endif +# endif int cmsg_level; int cmsg_type; }; @@ -538,13 +538,13 @@ struct __sanitizer_dirent { }; # else struct __sanitizer_dirent { -#if SANITIZER_AIX +# if SANITIZER_AIX uptr d_offset; uptr d_ino; -#else +# else uptr d_ino; uptr d_off; -#endif +# endif unsigned short d_reclen; // more fields that we don't care about }; @@ -565,11 +565,11 @@ typedef int __sanitizer_clock_t; #if SANITIZER_AIX typedef int __sanitizer_clock_t; typedef int __sanitizer_clockid_t; -#elif defined(__x86_64__) && !defined(_LP64) +# elif defined(__x86_64__) && !defined(_LP64) typedef long long __sanitizer_clock_t; -#else +# else typedef long __sanitizer_clock_t; -#endif +# endif #if SANITIZER_LINUX || SANITIZER_HAIKU typedef int __sanitizer_clockid_t; @@ -627,15 +627,15 @@ struct __sanitizer_sigset_t { // The size is determined by looking at sizeof of real sigset_t on linux. uptr val[128 / sizeof(uptr)]; }; -#elif SANITIZER_AIX +# elif SANITIZER_AIX struct __sanitizer_sigset_t { -#if SANITIZER_WORDSIZE == 64 +# if SANITIZER_WORDSIZE == 64 uptr val[4]; -#else +# else uptr val[2]; -#endif +# endif }; -#endif +# endif struct __sanitizer_siginfo_pad { #if SANITIZER_X32 @@ -828,9 +828,9 @@ struct __sanitizer_addrinfo { #if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX #if SANITIZER_AIX // AIX ai_addrlen type is size_t uptr ai_addrlen; -#else +# else unsigned ai_addrlen; -#endif +# endif char *ai_canonname; void *ai_addr; #else // LINUX @@ -839,9 +839,9 @@ struct __sanitizer_addrinfo { char *ai_canonname; #endif struct __sanitizer_addrinfo *ai_next; -#if SANITIZER_AIX +# if SANITIZER_AIX int ai_eflags; -#endif +# endif }; struct __sanitizer_hostent { @@ -858,7 +858,7 @@ struct __sanitizer_pollfd { short revents; }; -#if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_AIX +# if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_AIX typedef unsigned __sanitizer_nfds_t; #else typedef unsigned long __sanitizer_nfds_t; @@ -896,10 +896,10 @@ struct __sanitizer_wordexp_t { uptr we_wordc; char **we_wordv; uptr we_offs; -#if SANITIZER_AIX +# if SANITIZER_AIX int we_sflags; uptr we_soffs; -#endif +# endif }; #if SANITIZER_LINUX && !SANITIZER_ANDROID @@ -1159,7 +1159,7 @@ extern unsigned fpos_t_sz; // when it can not be determined without including any system headers. extern const unsigned IOCTL_NOT_PRESENT; -#if SANITIZER_AIX +# if SANITIZER_AIX extern uptr IOCTL_FIOASYNC; extern uptr IOCTL_FIONBIO; extern uptr IOCTL_FIOSETOWN; @@ -1173,7 +1173,7 @@ extern uptr IOCTL_TIOCSETD; extern uptr IOCTL_TIOCSPGRP; extern uptr IOCTL_TIOCSTI; extern uptr IOCTL_TIOCSWINSZ; -#else +# else extern unsigned IOCTL_FIOASYNC; extern unsigned IOCTL_FIONBIO; extern unsigned IOCTL_FIOSETOWN; @@ -1187,7 +1187,7 @@ extern unsigned IOCTL_TIOCSETD; extern unsigned IOCTL_TIOCSPGRP; extern unsigned IOCTL_TIOCSTI; extern unsigned IOCTL_TIOCSWINSZ; -#endif +# endif extern unsigned IOCTL_FIOCLEX; extern unsigned IOCTL_FIOGETOWN; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp index 44c40036babb2..b25ec8a66f64a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp @@ -27,7 +27,7 @@ #include #include -#if SANITIZER_FREEBSD || SANITIZER_AIX +# if SANITIZER_FREEBSD || SANITIZER_AIX // The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before // that, it was never implemented. So just define it to zero. #undef MAP_NORESERVE From 50405237e22140c0c5d891e66b25939c49f061c0 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Tue, 1 Apr 2025 10:18:13 -0400 Subject: [PATCH 03/18] Fix formatting 2 --- .../lib/sanitizer_common/sanitizer_platform_limits_posix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h index eaca02ca51111..f7913b7e39171 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -17,8 +17,8 @@ #if SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX # include "sanitizer_internal_defs.h" -# include "sanitizer_platform.h" # include "sanitizer_mallinfo.h" +# include "sanitizer_platform.h" # if SANITIZER_APPLE # include From d994b0a302cab10a50bae18063cb5624d3376f46 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Tue, 22 Apr 2025 11:24:13 -0400 Subject: [PATCH 04/18] Add general asan part --- compiler-rt/cmake/Modules/AddCompilerRT.cmake | 17 +++ compiler-rt/lib/asan/CMakeLists.txt | 11 ++ .../lib/asan/asan.link_with_main_exec.txt | 115 ++++++++++++++++++ compiler-rt/lib/asan/asan_aix.cpp | 44 +++++++ compiler-rt/lib/asan/asan_allocator.cpp | 6 +- .../lib/asan/asan_cxx.link_with_main_exec.txt | 21 ++++ compiler-rt/lib/asan/asan_posix.cpp | 7 +- .../lib/asan/scripts/asan_symbolize.py | 3 +- 8 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 compiler-rt/lib/asan/asan.link_with_main_exec.txt create mode 100644 compiler-rt/lib/asan/asan_aix.cpp create mode 100644 compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index d346b0ec01b03..d29ee07ccbdfe 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -582,6 +582,23 @@ macro(add_compiler_rt_script name) DESTINATION ${COMPILER_RT_INSTALL_BINARY_DIR}) endmacro(add_compiler_rt_script src name) +macro(add_compiler_rt_cfg target_name file_name component) + set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}") + get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir) + set(dst_file "${output_dir}/${file_name}") + add_custom_command(OUTPUT ${dst_file} + DEPENDS ${src_file} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file} + COMMENT "Copying ${file_name}...") + add_custom_target(${target_name} DEPENDS ${dst_file}) + install(FILES ${file_name} + DESTINATION ${COMPILER_RT_INSTALL_LIBRARY_DIR} + COMPONENT ${component}) + add_dependencies(${component} ${target_name}) + + set_target_properties(${target_name} PROPERTIES FOLDER "Compiler-RT Misc") +endmacro() + # Builds custom version of libc++ and installs it in . # Can be used to build sanitized versions of libc++ for running unit tests. # add_custom_libcxx( diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt index e2f39f224df9c..1ccf3fd3fb8c7 100644 --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -1,6 +1,7 @@ # Build for the AddressSanitizer runtime support library. set(ASAN_SOURCES + asan_aix.cpp asan_allocator.cpp asan_activation.cpp asan_debugging.cpp @@ -281,6 +282,8 @@ else() PARENT_TARGET asan) endif() + # On AIX, we only need the static libraries. + if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") foreach(arch ${ASAN_SUPPORTED_ARCH}) if (COMPILER_RT_HAS_VERSION_SCRIPT) if(WIN32) @@ -382,10 +385,18 @@ else() endif() endif() endforeach() + endif() endif() add_compiler_rt_resource_file(asan_ignorelist asan_ignorelist.txt asan) +On AIX, we need to put asan.link_with_main_exec.txt and asan_cxx.link_with_main_exec.txt +# to the build and install dir. +if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") + add_compiler_rt_cfg(asan_symbols asan.link_with_main_exec.txt asan) + add_compiler_rt_cfg(asan_cxx_symbols asan_cxx.link_with_main_exec.txt asan) +endif() + add_subdirectory(scripts) if(COMPILER_RT_INCLUDE_TESTS) diff --git a/compiler-rt/lib/asan/asan.link_with_main_exec.txt b/compiler-rt/lib/asan/asan.link_with_main_exec.txt new file mode 100644 index 0000000000000..5efc48c262369 --- /dev/null +++ b/compiler-rt/lib/asan/asan.link_with_main_exec.txt @@ -0,0 +1,115 @@ +#! . +__asan_report_load_n +__asan_loadN +__asan_report_load1 +__asan_load1 +__asan_report_load2 +__asan_load2 +__asan_report_load4 +__asan_load4 +__asan_report_load8 +__asan_load8 +__asan_report_load16 +__asan_load16 +__asan_report_store_n +__asan_storeN +__asan_report_store1 +__asan_store1 +__asan_report_store2 +__asan_store2 +__asan_report_store4 +__asan_store4 +__asan_report_store8 +__asan_store8 +__asan_report_store16 +__asan_store16 +__asan_report_exp_load_n +__asan_exp_loadN +__asan_report_exp_load1 +__asan_exp_load1 +__asan_report_exp_load2 +__asan_exp_load2 +__asan_report_exp_load4 +__asan_exp_load4 +__asan_report_exp_load8 +__asan_exp_load8 +__asan_report_exp_load16 +__asan_exp_load16 +__asan_report_exp_store_n +__asan_exp_storeN +__asan_report_exp_store1 +__asan_exp_store1 +__asan_report_exp_store2 +__asan_exp_store2 +__asan_report_exp_store4 +__asan_exp_store4 +__asan_report_exp_store8 +__asan_exp_store8 +__asan_report_exp_store16 +__asan_exp_store16 +__asan_memmove +__asan_memcpy +__asan_memset +__asan_handle_no_return +__sanitizer_ptr_cmp +__sanitizer_ptr_sub +__asan_before_dynamic_init +__asan_after_dynamic_init +__asan_register_globals +__asan_unregister_globals +__asan_register_image_globals +__asan_unregister_image_globals +__asan_register_elf_globals +__asan_unregister_elf_globals +__asan_init +__asan_version_mismatch_check_v8 +__asan_stack_malloc_0 +__asan_stack_malloc_1 +__asan_stack_malloc_2 +__asan_stack_malloc_3 +__asan_stack_malloc_4 +__asan_stack_malloc_5 +__asan_stack_malloc_6 +__asan_stack_malloc_7 +__asan_stack_malloc_8 +__asan_stack_malloc_9 +__asan_stack_malloc_10 +__asan_stack_malloc_always_0 +__asan_stack_malloc_always_1 +__asan_stack_malloc_always_2 +__asan_stack_malloc_always_3 +__asan_stack_malloc_always_4 +__asan_stack_malloc_always_5 +__asan_stack_malloc_always_6 +__asan_stack_malloc_always_7 +__asan_stack_malloc_always_8 +__asan_stack_malloc_always_9 +__asan_stack_malloc_always_10 +__asan_stack_free_0 +__asan_stack_free_1 +__asan_stack_free_2 +__asan_stack_free_3 +__asan_stack_free_4 +__asan_stack_free_5 +__asan_stack_free_6 +__asan_stack_free_7 +__asan_stack_free_8 +__asan_stack_free_9 +__asan_stack_free_10 +__asan_set_shadow_00 +__asan_set_shadow_01 +__asan_set_shadow_02 +__asan_set_shadow_03 +__asan_set_shadow_04 +__asan_set_shadow_05 +__asan_set_shadow_06 +__asan_set_shadow_07 +__asan_set_shadow_f1 +__asan_set_shadow_f2 +__asan_set_shadow_f3 +__asan_set_shadow_f5 +__asan_set_shadow_f8 +__asan_poison_stack_memory +__asan_unpoison_stack_memory +__asan_option_detect_stack_use_after_return +__asan_shadow_memory_dynamic_address diff --git a/compiler-rt/lib/asan/asan_aix.cpp b/compiler-rt/lib/asan/asan_aix.cpp new file mode 100644 index 0000000000000..d1a8a5ac8e59d --- /dev/null +++ b/compiler-rt/lib/asan/asan_aix.cpp @@ -0,0 +1,44 @@ +//===-- asan_aix.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// AIX-specific details. +//===----------------------------------------------------------------------===// + +#include "sanitizer_common/sanitizer_platform.h" + +#if SANITIZER_AIX +# include "asan_mapping.h" +# include "sanitizer_common/sanitizer_internal_defs.h" + +namespace __asan { + +void AsanCheckIncompatibleRT() {} + +void AsanCheckDynamicRTPrereqs() {} + +void InitializePlatformExceptionHandlers() {} + +void *AsanDoesNotSupportStaticLinkage() { return 0; } + +void InitializePlatformInterceptors() {} +void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {} + +uptr FindDynamicShadowStart() { + UNREACHABLE("AIX does not use dynamic shadow offset!"); + return 0; +} + +void FlushUnneededASanShadowMemory(uptr p, uptr size) { + ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size)); +} + +} // namespace __asan + +#endif // SANITIZER_AIX diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp index 3a55c2af65653..8a56132bf946a 100644 --- a/compiler-rt/lib/asan/asan_allocator.cpp +++ b/compiler-rt/lib/asan/asan_allocator.cpp @@ -797,8 +797,10 @@ struct Allocator { void ReportInvalidFree(void *ptr, u8 chunk_state, BufferedStackTrace *stack) { if (chunk_state == CHUNK_QUARANTINE) ReportDoubleFree((uptr)ptr, stack); - else - ReportFreeNotMalloced((uptr)ptr, stack); + else { + if (common_flags()->enable_unmalloced_free_check) + ReportFreeNotMalloced((uptr)ptr, stack); + } } void CommitBack(AsanThreadLocalMallocStorage *ms, BufferedStackTrace *stack) { diff --git a/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt b/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt new file mode 100644 index 0000000000000..7387f8173e859 --- /dev/null +++ b/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt @@ -0,0 +1,21 @@ +#! . +_ZdaPv +_ZdaPvRKSt9nothrow_t +_ZdaPvSt11align_val_t +_ZdaPvSt11align_val_tRKSt9nothrow_t +_ZdaPvm +_ZdaPvmSt11align_val_t +_ZdlPv +_ZdlPvRKSt9nothrow_t +_ZdlPvSt11align_val_t +_ZdlPvSt11align_val_tRKSt9nothrow_t +_ZdlPvm +_ZdlPvmSt11align_val_t +_Znam +_ZnamRKSt9nothrow_t +_ZnamSt11align_val_t +_ZnamSt11align_val_tRKSt9nothrow_t +_Znwm +_ZnwmRKSt9nothrow_t +_ZnwmSt11align_val_t +_ZnwmSt11align_val_tRKSt9nothrow_t diff --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp index fb66c871ea8a5..43a5cef27ea35 100644 --- a/compiler-rt/lib/asan/asan_posix.cpp +++ b/compiler-rt/lib/asan/asan_posix.cpp @@ -14,7 +14,11 @@ #include "sanitizer_common/sanitizer_platform.h" #if SANITIZER_POSIX +// tid_t is also defined in AIX header /usr/include/sys/types.h which is +// included by system pthread.h +# define tid_t tid_t_temp # include +# undef tid_t # include # include # include @@ -180,7 +184,8 @@ static void AfterFork(bool fork_child) { void InstallAtForkHandler() { # if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE || \ - (SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU + (SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU || \ + SANITIZER_AIX // While other Linux targets use clone in internal_fork which doesn't // trigger pthread_atfork handlers, Linux/sparc64 uses __fork, causing a // hang. diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py index 058a1614b55e6..466173336d8b1 100755 --- a/compiler-rt/lib/asan/scripts/asan_symbolize.py +++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py @@ -59,6 +59,7 @@ def is_valid_arch(s): "armv7s", "armv7k", "arm64", + "powerpc", "powerpc64", "powerpc64le", "s390x", @@ -449,7 +450,7 @@ def __init__(self, plugin_proxy=None, dsym_hint_producer=None): # E.g. in Chrome several binaries may share a single .dSYM. self.dsym_hint_producer = dsym_hint_producer self.system = os.uname()[0] - if self.system not in ["Linux", "Darwin", "FreeBSD", "NetBSD", "SunOS"]: + if self.system not in ["Linux", "Darwin", "FreeBSD", "NetBSD", "SunOS", "AIX"]: raise Exception("Unknown system") self.llvm_symbolizers = {} self.last_llvm_symbolizer = None From 6bc803eae1f857cf8178aeab101213fc4f85dd2e Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Thu, 24 Apr 2025 11:03:22 -0400 Subject: [PATCH 05/18] Fix xdr.h path --- compiler-rt/cmake/base-config-ix.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake index d92bc0e71fa1a..953fa3983ecfc 100644 --- a/compiler-rt/cmake/base-config-ix.cmake +++ b/compiler-rt/cmake/base-config-ix.cmake @@ -14,7 +14,11 @@ include(CompilerRTDarwinUtils) check_include_file(unwind.h HAVE_UNWIND_H) # Used by sanitizer_common and tests. -check_include_file(rpc/xdr.h HAVE_RPC_XDR_H) +if (${CMAKE_SYSTEM_NAME} MATCHES AIX) + check_include_file(tirpc/rpc/xdr.h HAVE_RPC_XDR_H) +else() + check_include_file(rpc/xdr.h HAVE_RPC_XDR_H) +endif() if (NOT HAVE_RPC_XDR_H) set(HAVE_RPC_XDR_H 0) endif() From ada3b70170ed3cf2ff01b9c525ce3c3adba2c638 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Sun, 27 Apr 2025 13:19:06 -0400 Subject: [PATCH 06/18] Fix merge resolution --- .../lib/sanitizer_common/sanitizer_platform.h | 6 +-- .../sanitizer_platform_limits_posix.cpp | 53 ++++++++++--------- .../sanitizer_platform_limits_posix.h | 24 ++++----- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h index 982011eedd75a..3916721654a44 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h @@ -151,11 +151,7 @@ #define SANITIZER_POSIX \ (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_APPLE || \ -<<<<<<< HEAD - SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_HAIKU) -======= - SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_AIX) ->>>>>>> d8273ed5690f ([sanitizer_common] recognize AIX) + SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_HAIKU || SANITIZER_AIX) #if __LP64__ || defined(_WIN64) # define SANITIZER_WORDSIZE 64 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp index 1c54b7c0f152c..61d7549e94e7b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -575,26 +575,44 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); const unsigned IOCTL_NOT_PRESENT = 0; + // On AIX, some variables are unsigned long types. +#if SANITIZER_AIX + uptr IOCTL_FIOASYNC = FIOASYNC; + uptr IOCTL_FIONBIO = FIONBIO; + uptr IOCTL_FIOSETOWN = FIOSETOWN; + uptr IOCTL_SIOCSPGRP = SIOCSPGRP; + uptr IOCTL_TIOCCONS = TIOCCONS; + uptr IOCTL_TIOCMBIC = TIOCMBIC; + uptr IOCTL_TIOCMBIS = TIOCMBIS; + uptr IOCTL_TIOCMSET = TIOCMSET; + uptr IOCTL_TIOCPKT = TIOCPKT; + uptr IOCTL_TIOCSETD = TIOCSETD; + uptr IOCTL_TIOCSPGRP = TIOCSPGRP; + uptr IOCTL_TIOCSTI = TIOCSTI; + uptr IOCTL_TIOCSWINSZ = TIOCSWINSZ; +#else unsigned IOCTL_FIONBIO = FIONBIO; #if !SANITIZER_HAIKU unsigned IOCTL_FIOASYNC = FIOASYNC; - unsigned IOCTL_FIONBIO = FIONBIO; unsigned IOCTL_FIOSETOWN = FIOSETOWN; - unsigned IOCTL_SIOCSPGRP = SIOCSPGRP; unsigned IOCTL_TIOCCONS = TIOCCONS; - unsigned IOCTL_TIOCMBIC = TIOCMBIC; - unsigned IOCTL_TIOCMBIS = TIOCMBIS; - unsigned IOCTL_TIOCMSET = TIOCMSET; unsigned IOCTL_TIOCPKT = TIOCPKT; unsigned IOCTL_TIOCSETD = TIOCSETD; - unsigned IOCTL_TIOCSPGRP = TIOCSPGRP; unsigned IOCTL_TIOCSTI = TIOCSTI; +#endif + unsigned IOCTL_SIOCSPGRP = SIOCSPGRP; + unsigned IOCTL_TIOCMBIC = TIOCMBIC; + unsigned IOCTL_TIOCMBIS = TIOCMBIS; unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ; -# endif + unsigned IOCTL_TIOCMSET = TIOCMSET; + unsigned IOCTL_TIOCSPGRP = TIOCSPGRP; +#endif +#if !SANITIZER_HAIKU unsigned IOCTL_FIOCLEX = FIOCLEX; unsigned IOCTL_FIOGETOWN = FIOGETOWN; unsigned IOCTL_FIONCLEX = FIONCLEX; - unsigned IOCTL_FIOSETOWN = FIOSETOWN; + unsigned IOCTL_TIOCGETD = TIOCGETD; + unsigned IOCTL_TIOCNOTTY = TIOCNOTTY; #endif unsigned IOCTL_SIOCADDMULTI = SIOCADDMULTI; unsigned IOCTL_SIOCATMARK = SIOCATMARK; @@ -615,29 +633,17 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); unsigned IOCTL_SIOCSIFMETRIC = SIOCSIFMETRIC; unsigned IOCTL_SIOCSIFMTU = SIOCSIFMTU; unsigned IOCTL_SIOCSIFNETMASK = SIOCSIFNETMASK; - unsigned IOCTL_SIOCSPGRP = SIOCSPGRP; - -#if !SANITIZER_HAIKU - unsigned IOCTL_TIOCCONS = TIOCCONS; - unsigned IOCTL_TIOCGETD = TIOCGETD; - unsigned IOCTL_TIOCNOTTY = TIOCNOTTY; - unsigned IOCTL_TIOCPKT = TIOCPKT; - unsigned IOCTL_TIOCSETD = TIOCSETD; - unsigned IOCTL_TIOCSTI = TIOCSTI; -#endif unsigned IOCTL_TIOCEXCL = TIOCEXCL; unsigned IOCTL_TIOCGPGRP = TIOCGPGRP; unsigned IOCTL_TIOCGWINSZ = TIOCGWINSZ; unsigned IOCTL_TIOCMGET = TIOCMGET; - unsigned IOCTL_TIOCMSET = TIOCMSET; unsigned IOCTL_TIOCNXCL = TIOCNXCL; unsigned IOCTL_TIOCOUTQ = TIOCOUTQ; +#if !SANITIZER_AIX unsigned IOCTL_TIOCSCTTY = TIOCSCTTY; - unsigned IOCTL_TIOCSPGRP = TIOCSPGRP; - unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ; +#endif #if SANITIZER_LINUX && !SANITIZER_ANDROID - unsigned IOCTL_SIOCGETSGCNT = SIOCGETSGCNT; unsigned IOCTL_SIOCGETVIFCNT = SIOCGETVIFCNT; #endif @@ -1033,8 +1039,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); const int si_SEGV_MAPERR = SEGV_MAPERR; const int si_SEGV_ACCERR = SEGV_ACCERR; -} // namespace __sanitizer - +} // namespace __sanitizer using namespace __sanitizer; COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t)); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h index f7913b7e39171..98466398f8da6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -1159,7 +1159,7 @@ extern unsigned fpos_t_sz; // when it can not be determined without including any system headers. extern const unsigned IOCTL_NOT_PRESENT; -# if SANITIZER_AIX +#if SANITIZER_AIX extern uptr IOCTL_FIOASYNC; extern uptr IOCTL_FIONBIO; extern uptr IOCTL_FIOSETOWN; @@ -1173,21 +1173,23 @@ extern uptr IOCTL_TIOCSETD; extern uptr IOCTL_TIOCSPGRP; extern uptr IOCTL_TIOCSTI; extern uptr IOCTL_TIOCSWINSZ; -# else +#else extern unsigned IOCTL_FIOASYNC; extern unsigned IOCTL_FIONBIO; extern unsigned IOCTL_FIOSETOWN; extern unsigned IOCTL_SIOCSPGRP; -extern unsigned IOCTL_TIOCCONS; extern unsigned IOCTL_TIOCMBIC; extern unsigned IOCTL_TIOCMBIS; extern unsigned IOCTL_TIOCMSET; +extern unsigned IOCTL_TIOCSPGRP; +extern unsigned IOCTL_TIOCSWINSZ; +#if !SANITIZER_HAIKU +extern unsigned IOCTL_TIOCCONS; extern unsigned IOCTL_TIOCPKT; extern unsigned IOCTL_TIOCSETD; -extern unsigned IOCTL_TIOCSPGRP; extern unsigned IOCTL_TIOCSTI; -extern unsigned IOCTL_TIOCSWINSZ; -# endif +#endif +#endif extern unsigned IOCTL_FIOCLEX; extern unsigned IOCTL_FIOGETOWN; @@ -1211,25 +1213,19 @@ extern unsigned IOCTL_SIOCSIFFLAGS; extern unsigned IOCTL_SIOCSIFMETRIC; extern unsigned IOCTL_SIOCSIFMTU; extern unsigned IOCTL_SIOCSIFNETMASK; -extern unsigned IOCTL_SIOCSPGRP; #if !SANITIZER_HAIKU -extern unsigned IOCTL_TIOCCONS; extern unsigned IOCTL_TIOCGETD; extern unsigned IOCTL_TIOCNOTTY; -extern unsigned IOCTL_TIOCPKT; -extern unsigned IOCTL_TIOCSETD; -extern unsigned IOCTL_TIOCSTI; #endif extern unsigned IOCTL_TIOCEXCL; extern unsigned IOCTL_TIOCGPGRP; extern unsigned IOCTL_TIOCGWINSZ; extern unsigned IOCTL_TIOCMGET; -extern unsigned IOCTL_TIOCMSET; extern unsigned IOCTL_TIOCNXCL; extern unsigned IOCTL_TIOCOUTQ; +#if !SANITIZER_AIX extern unsigned IOCTL_TIOCSCTTY; -extern unsigned IOCTL_TIOCSPGRP; -extern unsigned IOCTL_TIOCSWINSZ; +#endif #if SANITIZER_LINUX && !SANITIZER_ANDROID extern unsigned IOCTL_SIOCGETSGCNT; extern unsigned IOCTL_SIOCGETVIFCNT; From 8641fca344af7f05871a70bc8230898128acf5b1 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Sun, 27 Apr 2025 22:37:37 -0400 Subject: [PATCH 07/18] Add missing # --- compiler-rt/lib/asan/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt index 1ccf3fd3fb8c7..3a8043fbb9adb 100644 --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -390,7 +390,7 @@ endif() add_compiler_rt_resource_file(asan_ignorelist asan_ignorelist.txt asan) -On AIX, we need to put asan.link_with_main_exec.txt and asan_cxx.link_with_main_exec.txt +# On AIX, we need to put asan.link_with_main_exec.txt and asan_cxx.link_with_main_exec.txt # to the build and install dir. if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") add_compiler_rt_cfg(asan_symbols asan.link_with_main_exec.txt asan) From 35db4098a6200d247106041f027e68e8a60afd2c Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Sun, 27 Apr 2025 23:48:51 -0400 Subject: [PATCH 08/18] Resolve build fail --- .../lib/sanitizer_common/sanitizer_platform_limits_posix.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h index 98466398f8da6..956d679662766 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -560,9 +560,9 @@ struct __sanitizer_dirent64 { extern unsigned struct_sock_fprog_sz; #endif -#if SANITIZER_HAIKU +# if SANITIZER_HAIKU typedef int __sanitizer_clock_t; -#if SANITIZER_AIX +# elif SANITIZER_AIX typedef int __sanitizer_clock_t; typedef int __sanitizer_clockid_t; # elif defined(__x86_64__) && !defined(_LP64) @@ -1625,6 +1625,6 @@ extern const int si_SEGV_ACCERR; typedef void *__sanitizer_timer_t; # endif -#endif // SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU +#endif // SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX #endif From f5ce2a73b9684474d6b5a58690747e558e130431 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Mon, 28 Apr 2025 10:21:37 -0400 Subject: [PATCH 09/18] Add TryReExecWithoutASLR stub --- compiler-rt/lib/asan/asan_aix.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler-rt/lib/asan/asan_aix.cpp b/compiler-rt/lib/asan/asan_aix.cpp index d1a8a5ac8e59d..6131e425d6950 100644 --- a/compiler-rt/lib/asan/asan_aix.cpp +++ b/compiler-rt/lib/asan/asan_aix.cpp @@ -19,6 +19,10 @@ namespace __asan { +void TryReExecWithoutASLR() { + // Allowed to fail and do nothing. + } + void AsanCheckIncompatibleRT() {} void AsanCheckDynamicRTPrereqs() {} From 12653e19bafcad8655ba4f4f89f97c6fb571fd83 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Tue, 29 Apr 2025 09:57:32 -0400 Subject: [PATCH 10/18] enable_unmalloced_free_check --- compiler-rt/lib/asan/asan_allocator.cpp | 6 ++---- compiler-rt/lib/sanitizer_common/sanitizer_flags.inc | 3 --- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp index 8a56132bf946a..3a55c2af65653 100644 --- a/compiler-rt/lib/asan/asan_allocator.cpp +++ b/compiler-rt/lib/asan/asan_allocator.cpp @@ -797,10 +797,8 @@ struct Allocator { void ReportInvalidFree(void *ptr, u8 chunk_state, BufferedStackTrace *stack) { if (chunk_state == CHUNK_QUARANTINE) ReportDoubleFree((uptr)ptr, stack); - else { - if (common_flags()->enable_unmalloced_free_check) - ReportFreeNotMalloced((uptr)ptr, stack); - } + else + ReportFreeNotMalloced((uptr)ptr, stack); } void CommitBack(AsanThreadLocalMallocStorage *ms, BufferedStackTrace *stack) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc index a6c760b2387fb..c1e3530618c20 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc @@ -269,9 +269,6 @@ COMMON_FLAG(bool, detect_write_exec, false, COMMON_FLAG(bool, test_only_emulate_no_memorymap, false, "TEST ONLY fail to read memory mappings to emulate sanitized " "\"init\"") -COMMON_FLAG(bool, enable_unmalloced_free_check, !SANITIZER_AIX, - "if true, FreeNotMalloced error will be reported. Only disable " - "this error detecting on AIX by default for now.") // With static linking, dladdr((void*)pthread_join) or similar will return the // path to the main program. This flag will replace dlopen(
// with dlopen(NULL,...), which is the correct way to get a handle to the main From 26bf8fe8d135543d171571ba7dd42a7d828a5272 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Tue, 29 Apr 2025 11:25:00 -0400 Subject: [PATCH 11/18] Fix formatting --- compiler-rt/lib/asan/scripts/asan_symbolize.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py index 466173336d8b1..7cff87b6c9bc9 100755 --- a/compiler-rt/lib/asan/scripts/asan_symbolize.py +++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py @@ -450,7 +450,14 @@ def __init__(self, plugin_proxy=None, dsym_hint_producer=None): # E.g. in Chrome several binaries may share a single .dSYM. self.dsym_hint_producer = dsym_hint_producer self.system = os.uname()[0] - if self.system not in ["Linux", "Darwin", "FreeBSD", "NetBSD", "SunOS", "AIX"]: + if self.system not in [ + "Linux", + "Darwin", + "FreeBSD", + "NetBSD", + "SunOS", + "AIX", + ]: raise Exception("Unknown system") self.llvm_symbolizers = {} self.last_llvm_symbolizer = None From cc252b9d0097e541a6d38c12ff7217f026fbb846 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Tue, 29 Apr 2025 11:42:04 -0400 Subject: [PATCH 12/18] Fix formatting --- compiler-rt/lib/asan/asan_aix.cpp | 4 +- compiler-rt/lib/asan/asan_posix.cpp | 3 +- .../sanitizer_platform_limits_posix.cpp | 62 +++++++++---------- .../sanitizer_platform_limits_posix.h | 33 +++++----- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/compiler-rt/lib/asan/asan_aix.cpp b/compiler-rt/lib/asan/asan_aix.cpp index 6131e425d6950..24edc5cf90228 100644 --- a/compiler-rt/lib/asan/asan_aix.cpp +++ b/compiler-rt/lib/asan/asan_aix.cpp @@ -20,8 +20,8 @@ namespace __asan { void TryReExecWithoutASLR() { - // Allowed to fail and do nothing. - } + // Allowed to fail and do nothing. +} void AsanCheckIncompatibleRT() {} diff --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp index 43a5cef27ea35..c2f85099a3e36 100644 --- a/compiler-rt/lib/asan/asan_posix.cpp +++ b/compiler-rt/lib/asan/asan_posix.cpp @@ -184,8 +184,7 @@ static void AfterFork(bool fork_child) { void InstallAtForkHandler() { # if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE || \ - (SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU || \ - SANITIZER_AIX + (SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU || SANITIZER_AIX // While other Linux targets use clone in internal_fork which doesn't // trigger pthread_atfork handlers, Linux/sparc64 uses __fork, causing a // hang. diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp index 61d7549e94e7b..9cbe4c8dac6be 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -61,11 +61,11 @@ #endif #if !SANITIZER_ANDROID -#if !SANITIZER_AIX && !SANITIZER_HAIKU -#include -#endif -#include -#include +# if !SANITIZER_AIX && !SANITIZER_HAIKU +# include +# endif +# include +# include #endif #if SANITIZER_LINUX @@ -112,15 +112,15 @@ typedef struct user_fpregs elf_fpregset_t; #endif #if !SANITIZER_ANDROID -#if !SANITIZER_AIX -#include -#else -#include -#endif -#if !SANITIZER_HAIKU -#include -#include -#endif +# if !SANITIZER_AIX +# include +# else +# include +# endif +# if !SANITIZER_HAIKU +# include +# include +# endif #endif #if SANITIZER_LINUX @@ -192,10 +192,10 @@ typedef struct user_fpregs elf_fpregset_t; # endif # endif -#if SANITIZER_HAIKU -#include -#include -#endif +# if SANITIZER_HAIKU +# include +# include +# endif // Include these after system headers to avoid name clashes and ambiguities. # include "sanitizer_common.h" @@ -576,7 +576,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); const unsigned IOCTL_NOT_PRESENT = 0; // On AIX, some variables are unsigned long types. -#if SANITIZER_AIX +# if SANITIZER_AIX uptr IOCTL_FIOASYNC = FIOASYNC; uptr IOCTL_FIONBIO = FIONBIO; uptr IOCTL_FIOSETOWN = FIOSETOWN; @@ -590,30 +590,30 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); uptr IOCTL_TIOCSPGRP = TIOCSPGRP; uptr IOCTL_TIOCSTI = TIOCSTI; uptr IOCTL_TIOCSWINSZ = TIOCSWINSZ; -#else +# else unsigned IOCTL_FIONBIO = FIONBIO; -#if !SANITIZER_HAIKU +# if !SANITIZER_HAIKU unsigned IOCTL_FIOASYNC = FIOASYNC; unsigned IOCTL_FIOSETOWN = FIOSETOWN; unsigned IOCTL_TIOCCONS = TIOCCONS; unsigned IOCTL_TIOCPKT = TIOCPKT; unsigned IOCTL_TIOCSETD = TIOCSETD; unsigned IOCTL_TIOCSTI = TIOCSTI; -#endif +# endif unsigned IOCTL_SIOCSPGRP = SIOCSPGRP; unsigned IOCTL_TIOCMBIC = TIOCMBIC; unsigned IOCTL_TIOCMBIS = TIOCMBIS; unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ; unsigned IOCTL_TIOCMSET = TIOCMSET; unsigned IOCTL_TIOCSPGRP = TIOCSPGRP; -#endif -#if !SANITIZER_HAIKU +# endif +# if !SANITIZER_HAIKU unsigned IOCTL_FIOCLEX = FIOCLEX; unsigned IOCTL_FIOGETOWN = FIOGETOWN; unsigned IOCTL_FIONCLEX = FIONCLEX; unsigned IOCTL_TIOCGETD = TIOCGETD; unsigned IOCTL_TIOCNOTTY = TIOCNOTTY; -#endif +# endif unsigned IOCTL_SIOCADDMULTI = SIOCADDMULTI; unsigned IOCTL_SIOCATMARK = SIOCATMARK; unsigned IOCTL_SIOCDELMULTI = SIOCDELMULTI; @@ -640,10 +640,10 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); unsigned IOCTL_TIOCMGET = TIOCMGET; unsigned IOCTL_TIOCNXCL = TIOCNXCL; unsigned IOCTL_TIOCOUTQ = TIOCOUTQ; -#if !SANITIZER_AIX +# if !SANITIZER_AIX unsigned IOCTL_TIOCSCTTY = TIOCSCTTY; -#endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID +# endif +# if SANITIZER_LINUX && !SANITIZER_ANDROID unsigned IOCTL_SIOCGETSGCNT = SIOCGETSGCNT; unsigned IOCTL_SIOCGETVIFCNT = SIOCGETVIFCNT; #endif @@ -1039,7 +1039,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); const int si_SEGV_MAPERR = SEGV_MAPERR; const int si_SEGV_ACCERR = SEGV_ACCERR; -} // namespace __sanitizer + } // namespace __sanitizer using namespace __sanitizer; COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t)); @@ -1152,7 +1152,7 @@ CHECK_SIZE_AND_OFFSET(dirent, d_ino); CHECK_SIZE_AND_OFFSET(dirent, d_seekoff); # elif SANITIZER_AIX CHECK_SIZE_AND_OFFSET(dirent, d_offset); -#elif SANITIZER_FREEBSD || SANITIZER_HAIKU +# elif SANITIZER_FREEBSD || SANITIZER_HAIKU // There is no 'd_off' field on FreeBSD. # else CHECK_SIZE_AND_OFFSET(dirent, d_off); @@ -1297,7 +1297,7 @@ CHECK_TYPE_SIZE(clock_t); CHECK_TYPE_SIZE(clockid_t); #endif -#if !SANITIZER_ANDROID && !SANITIZER_HAIKU && !SANITIZER_AIX +# if !SANITIZER_ANDROID && !SANITIZER_HAIKU && !SANITIZER_AIX CHECK_TYPE_SIZE(ifaddrs); CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next); CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h index 956d679662766..67d3865473e6a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -436,8 +436,8 @@ struct __sanitizer_tm { int tm_wday; int tm_yday; int tm_isdst; -#if !SANITIZER_AIX -#if SANITIZER_HAIKU +# if !SANITIZER_AIX +# if SANITIZER_HAIKU int tm_gmtoff; #else long int tm_gmtoff; @@ -571,7 +571,7 @@ typedef long long __sanitizer_clock_t; typedef long __sanitizer_clock_t; # endif -#if SANITIZER_LINUX || SANITIZER_HAIKU +# if SANITIZER_LINUX || SANITIZER_HAIKU typedef int __sanitizer_clockid_t; typedef unsigned long long __sanitizer_eventfd_t; #endif @@ -825,8 +825,8 @@ struct __sanitizer_addrinfo { int ai_family; int ai_socktype; int ai_protocol; -#if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX -#if SANITIZER_AIX // AIX ai_addrlen type is size_t +# if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX +# if SANITIZER_AIX // AIX ai_addrlen type is size_t uptr ai_addrlen; # else unsigned ai_addrlen; @@ -1159,7 +1159,7 @@ extern unsigned fpos_t_sz; // when it can not be determined without including any system headers. extern const unsigned IOCTL_NOT_PRESENT; -#if SANITIZER_AIX +# if SANITIZER_AIX extern uptr IOCTL_FIOASYNC; extern uptr IOCTL_FIONBIO; extern uptr IOCTL_FIOSETOWN; @@ -1173,7 +1173,7 @@ extern uptr IOCTL_TIOCSETD; extern uptr IOCTL_TIOCSPGRP; extern uptr IOCTL_TIOCSTI; extern uptr IOCTL_TIOCSWINSZ; -#else +# else extern unsigned IOCTL_FIOASYNC; extern unsigned IOCTL_FIONBIO; extern unsigned IOCTL_FIOSETOWN; @@ -1183,13 +1183,13 @@ extern unsigned IOCTL_TIOCMBIS; extern unsigned IOCTL_TIOCMSET; extern unsigned IOCTL_TIOCSPGRP; extern unsigned IOCTL_TIOCSWINSZ; -#if !SANITIZER_HAIKU +# if !SANITIZER_HAIKU extern unsigned IOCTL_TIOCCONS; extern unsigned IOCTL_TIOCPKT; extern unsigned IOCTL_TIOCSETD; extern unsigned IOCTL_TIOCSTI; -#endif -#endif +# endif +# endif extern unsigned IOCTL_FIOCLEX; extern unsigned IOCTL_FIOGETOWN; @@ -1213,20 +1213,20 @@ extern unsigned IOCTL_SIOCSIFFLAGS; extern unsigned IOCTL_SIOCSIFMETRIC; extern unsigned IOCTL_SIOCSIFMTU; extern unsigned IOCTL_SIOCSIFNETMASK; -#if !SANITIZER_HAIKU +# if !SANITIZER_HAIKU extern unsigned IOCTL_TIOCGETD; extern unsigned IOCTL_TIOCNOTTY; -#endif +# endif extern unsigned IOCTL_TIOCEXCL; extern unsigned IOCTL_TIOCGPGRP; extern unsigned IOCTL_TIOCGWINSZ; extern unsigned IOCTL_TIOCMGET; extern unsigned IOCTL_TIOCNXCL; extern unsigned IOCTL_TIOCOUTQ; -#if !SANITIZER_AIX +# if !SANITIZER_AIX extern unsigned IOCTL_TIOCSCTTY; -#endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID +# endif +# if SANITIZER_LINUX && !SANITIZER_ANDROID extern unsigned IOCTL_SIOCGETSGCNT; extern unsigned IOCTL_SIOCGETVIFCNT; #endif @@ -1625,6 +1625,7 @@ extern const int si_SEGV_ACCERR; typedef void *__sanitizer_timer_t; # endif -#endif // SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU || SANITIZER_AIX +#endif // SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_HAIKU || + // SANITIZER_AIX #endif From b42ddffae3e41fa3b2a6a73cfede438ed56ef5a5 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Tue, 29 Apr 2025 11:49:47 -0400 Subject: [PATCH 13/18] Fix formatting.. --- .../lib/sanitizer_common/sanitizer_platform_limits_posix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp index 9cbe4c8dac6be..f5cf57d5c9689 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -193,8 +193,8 @@ typedef struct user_fpregs elf_fpregset_t; # endif # if SANITIZER_HAIKU -# include # include +# include # endif // Include these after system headers to avoid name clashes and ambiguities. From d9b56c006b56968a8bc50dfc6f5bbcdd066e714b Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Wed, 30 Apr 2025 11:20:58 -0400 Subject: [PATCH 14/18] Move code from other PR --- .../sanitizer_symbolizer_libcdep.cpp | 3 +++ .../sanitizer_default_arch/llvm-symbolizer | 7 +++++++ .../symbolizer_default_arch_ppc64.cpp | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100755 compiler-rt/test/sanitizer_common/TestCases/Inputs/sanitizer_default_arch/llvm-symbolizer create mode 100644 compiler-rt/test/sanitizer_common/TestCases/symbolizer_default_arch_ppc64.cpp diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp index 565701c85d978..6492e8ebe73ad 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp @@ -282,6 +282,9 @@ class LLVMSymbolizerProcess final : public SymbolizerProcess { const char *const kSymbolizerArch = "--default-arch=powerpc64"; # elif defined(__powerpc64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ const char *const kSymbolizerArch = "--default-arch=powerpc64le"; +# elif defined(__powerpc__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + // Must check __powerpc__ after __powerpc64__ because both can be set. + const char *const kSymbolizerArch = "--default-arch=powerpc"; # elif defined(__s390x__) const char *const kSymbolizerArch = "--default-arch=s390x"; # elif defined(__s390__) diff --git a/compiler-rt/test/sanitizer_common/TestCases/Inputs/sanitizer_default_arch/llvm-symbolizer b/compiler-rt/test/sanitizer_common/TestCases/Inputs/sanitizer_default_arch/llvm-symbolizer new file mode 100755 index 0000000000000..4a3d68a43ad7d --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/Inputs/sanitizer_default_arch/llvm-symbolizer @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +# Assisted by watsonx Code Assistant +import json +import sys +print(json.dumps(sys.argv[1:]), file=sys.stderr) +print("main\n??:0:0\n") diff --git a/compiler-rt/test/sanitizer_common/TestCases/symbolizer_default_arch_ppc64.cpp b/compiler-rt/test/sanitizer_common/TestCases/symbolizer_default_arch_ppc64.cpp new file mode 100644 index 0000000000000..714bcd5332821 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/symbolizer_default_arch_ppc64.cpp @@ -0,0 +1,18 @@ +// REQUIRES: powerpc64-target-arch + +// RUN: %clangxx -O0 %s -o %t +// RUN: %env_tool_opts=external_symbolizer_path=%p/Inputs/sanitizer_default_arch/llvm-symbolizer \ +// RUN: %run %t 2>&1 | FileCheck %s + +#include + +static void Symbolize() { + char buffer[100]; + __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", buffer, + sizeof(buffer)); +} + +int main() { + // CHECK: "--default-arch=powerpc64" + Symbolize(); +} From 9603601b0688d0fc70a893bf7ad7a6e4c6676886 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Thu, 8 May 2025 14:26:25 -0400 Subject: [PATCH 15/18] Move code to new PR --- .../sanitizer_symbolizer_libcdep.cpp | 3 --- .../sanitizer_default_arch/llvm-symbolizer | 7 ------- .../symbolizer_default_arch_ppc64.cpp | 18 ------------------ 3 files changed, 28 deletions(-) delete mode 100755 compiler-rt/test/sanitizer_common/TestCases/Inputs/sanitizer_default_arch/llvm-symbolizer delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/symbolizer_default_arch_ppc64.cpp diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp index 6492e8ebe73ad..565701c85d978 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp @@ -282,9 +282,6 @@ class LLVMSymbolizerProcess final : public SymbolizerProcess { const char *const kSymbolizerArch = "--default-arch=powerpc64"; # elif defined(__powerpc64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ const char *const kSymbolizerArch = "--default-arch=powerpc64le"; -# elif defined(__powerpc__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - // Must check __powerpc__ after __powerpc64__ because both can be set. - const char *const kSymbolizerArch = "--default-arch=powerpc"; # elif defined(__s390x__) const char *const kSymbolizerArch = "--default-arch=s390x"; # elif defined(__s390__) diff --git a/compiler-rt/test/sanitizer_common/TestCases/Inputs/sanitizer_default_arch/llvm-symbolizer b/compiler-rt/test/sanitizer_common/TestCases/Inputs/sanitizer_default_arch/llvm-symbolizer deleted file mode 100755 index 4a3d68a43ad7d..0000000000000 --- a/compiler-rt/test/sanitizer_common/TestCases/Inputs/sanitizer_default_arch/llvm-symbolizer +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python3 - -# Assisted by watsonx Code Assistant -import json -import sys -print(json.dumps(sys.argv[1:]), file=sys.stderr) -print("main\n??:0:0\n") diff --git a/compiler-rt/test/sanitizer_common/TestCases/symbolizer_default_arch_ppc64.cpp b/compiler-rt/test/sanitizer_common/TestCases/symbolizer_default_arch_ppc64.cpp deleted file mode 100644 index 714bcd5332821..0000000000000 --- a/compiler-rt/test/sanitizer_common/TestCases/symbolizer_default_arch_ppc64.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// REQUIRES: powerpc64-target-arch - -// RUN: %clangxx -O0 %s -o %t -// RUN: %env_tool_opts=external_symbolizer_path=%p/Inputs/sanitizer_default_arch/llvm-symbolizer \ -// RUN: %run %t 2>&1 | FileCheck %s - -#include - -static void Symbolize() { - char buffer[100]; - __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", buffer, - sizeof(buffer)); -} - -int main() { - // CHECK: "--default-arch=powerpc64" - Symbolize(); -} From 20074e396eef499031f97d35d43da80fd871fe25 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Mon, 12 May 2025 14:45:08 -0400 Subject: [PATCH 16/18] Move code --- compiler-rt/cmake/Modules/AddCompilerRT.cmake | 17 --- compiler-rt/lib/asan/CMakeLists.txt | 11 -- .../lib/asan/asan.link_with_main_exec.txt | 115 ------------------ compiler-rt/lib/asan/asan_aix.cpp | 48 -------- .../lib/asan/asan_cxx.link_with_main_exec.txt | 21 ---- compiler-rt/lib/asan/asan_posix.cpp | 6 +- .../lib/asan/scripts/asan_symbolize.py | 10 +- .../sanitizer_allocator_internal.h | 5 - .../sanitizer_allocator_primary32.h | 1 - .../sanitizer_common_libcdep.cpp | 7 +- 10 files changed, 3 insertions(+), 238 deletions(-) delete mode 100644 compiler-rt/lib/asan/asan.link_with_main_exec.txt delete mode 100644 compiler-rt/lib/asan/asan_aix.cpp delete mode 100644 compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index d29ee07ccbdfe..d346b0ec01b03 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -582,23 +582,6 @@ macro(add_compiler_rt_script name) DESTINATION ${COMPILER_RT_INSTALL_BINARY_DIR}) endmacro(add_compiler_rt_script src name) -macro(add_compiler_rt_cfg target_name file_name component) - set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}") - get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir) - set(dst_file "${output_dir}/${file_name}") - add_custom_command(OUTPUT ${dst_file} - DEPENDS ${src_file} - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file} - COMMENT "Copying ${file_name}...") - add_custom_target(${target_name} DEPENDS ${dst_file}) - install(FILES ${file_name} - DESTINATION ${COMPILER_RT_INSTALL_LIBRARY_DIR} - COMPONENT ${component}) - add_dependencies(${component} ${target_name}) - - set_target_properties(${target_name} PROPERTIES FOLDER "Compiler-RT Misc") -endmacro() - # Builds custom version of libc++ and installs it in . # Can be used to build sanitized versions of libc++ for running unit tests. # add_custom_libcxx( diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt index 3a8043fbb9adb..e2f39f224df9c 100644 --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -1,7 +1,6 @@ # Build for the AddressSanitizer runtime support library. set(ASAN_SOURCES - asan_aix.cpp asan_allocator.cpp asan_activation.cpp asan_debugging.cpp @@ -282,8 +281,6 @@ else() PARENT_TARGET asan) endif() - # On AIX, we only need the static libraries. - if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") foreach(arch ${ASAN_SUPPORTED_ARCH}) if (COMPILER_RT_HAS_VERSION_SCRIPT) if(WIN32) @@ -385,18 +382,10 @@ else() endif() endif() endforeach() - endif() endif() add_compiler_rt_resource_file(asan_ignorelist asan_ignorelist.txt asan) -# On AIX, we need to put asan.link_with_main_exec.txt and asan_cxx.link_with_main_exec.txt -# to the build and install dir. -if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") - add_compiler_rt_cfg(asan_symbols asan.link_with_main_exec.txt asan) - add_compiler_rt_cfg(asan_cxx_symbols asan_cxx.link_with_main_exec.txt asan) -endif() - add_subdirectory(scripts) if(COMPILER_RT_INCLUDE_TESTS) diff --git a/compiler-rt/lib/asan/asan.link_with_main_exec.txt b/compiler-rt/lib/asan/asan.link_with_main_exec.txt deleted file mode 100644 index 5efc48c262369..0000000000000 --- a/compiler-rt/lib/asan/asan.link_with_main_exec.txt +++ /dev/null @@ -1,115 +0,0 @@ -#! . -__asan_report_load_n -__asan_loadN -__asan_report_load1 -__asan_load1 -__asan_report_load2 -__asan_load2 -__asan_report_load4 -__asan_load4 -__asan_report_load8 -__asan_load8 -__asan_report_load16 -__asan_load16 -__asan_report_store_n -__asan_storeN -__asan_report_store1 -__asan_store1 -__asan_report_store2 -__asan_store2 -__asan_report_store4 -__asan_store4 -__asan_report_store8 -__asan_store8 -__asan_report_store16 -__asan_store16 -__asan_report_exp_load_n -__asan_exp_loadN -__asan_report_exp_load1 -__asan_exp_load1 -__asan_report_exp_load2 -__asan_exp_load2 -__asan_report_exp_load4 -__asan_exp_load4 -__asan_report_exp_load8 -__asan_exp_load8 -__asan_report_exp_load16 -__asan_exp_load16 -__asan_report_exp_store_n -__asan_exp_storeN -__asan_report_exp_store1 -__asan_exp_store1 -__asan_report_exp_store2 -__asan_exp_store2 -__asan_report_exp_store4 -__asan_exp_store4 -__asan_report_exp_store8 -__asan_exp_store8 -__asan_report_exp_store16 -__asan_exp_store16 -__asan_memmove -__asan_memcpy -__asan_memset -__asan_handle_no_return -__sanitizer_ptr_cmp -__sanitizer_ptr_sub -__asan_before_dynamic_init -__asan_after_dynamic_init -__asan_register_globals -__asan_unregister_globals -__asan_register_image_globals -__asan_unregister_image_globals -__asan_register_elf_globals -__asan_unregister_elf_globals -__asan_init -__asan_version_mismatch_check_v8 -__asan_stack_malloc_0 -__asan_stack_malloc_1 -__asan_stack_malloc_2 -__asan_stack_malloc_3 -__asan_stack_malloc_4 -__asan_stack_malloc_5 -__asan_stack_malloc_6 -__asan_stack_malloc_7 -__asan_stack_malloc_8 -__asan_stack_malloc_9 -__asan_stack_malloc_10 -__asan_stack_malloc_always_0 -__asan_stack_malloc_always_1 -__asan_stack_malloc_always_2 -__asan_stack_malloc_always_3 -__asan_stack_malloc_always_4 -__asan_stack_malloc_always_5 -__asan_stack_malloc_always_6 -__asan_stack_malloc_always_7 -__asan_stack_malloc_always_8 -__asan_stack_malloc_always_9 -__asan_stack_malloc_always_10 -__asan_stack_free_0 -__asan_stack_free_1 -__asan_stack_free_2 -__asan_stack_free_3 -__asan_stack_free_4 -__asan_stack_free_5 -__asan_stack_free_6 -__asan_stack_free_7 -__asan_stack_free_8 -__asan_stack_free_9 -__asan_stack_free_10 -__asan_set_shadow_00 -__asan_set_shadow_01 -__asan_set_shadow_02 -__asan_set_shadow_03 -__asan_set_shadow_04 -__asan_set_shadow_05 -__asan_set_shadow_06 -__asan_set_shadow_07 -__asan_set_shadow_f1 -__asan_set_shadow_f2 -__asan_set_shadow_f3 -__asan_set_shadow_f5 -__asan_set_shadow_f8 -__asan_poison_stack_memory -__asan_unpoison_stack_memory -__asan_option_detect_stack_use_after_return -__asan_shadow_memory_dynamic_address diff --git a/compiler-rt/lib/asan/asan_aix.cpp b/compiler-rt/lib/asan/asan_aix.cpp deleted file mode 100644 index 24edc5cf90228..0000000000000 --- a/compiler-rt/lib/asan/asan_aix.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//===-- asan_aix.cpp ------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file is a part of AddressSanitizer, an address sanity checker. -// -// AIX-specific details. -//===----------------------------------------------------------------------===// - -#include "sanitizer_common/sanitizer_platform.h" - -#if SANITIZER_AIX -# include "asan_mapping.h" -# include "sanitizer_common/sanitizer_internal_defs.h" - -namespace __asan { - -void TryReExecWithoutASLR() { - // Allowed to fail and do nothing. -} - -void AsanCheckIncompatibleRT() {} - -void AsanCheckDynamicRTPrereqs() {} - -void InitializePlatformExceptionHandlers() {} - -void *AsanDoesNotSupportStaticLinkage() { return 0; } - -void InitializePlatformInterceptors() {} -void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {} - -uptr FindDynamicShadowStart() { - UNREACHABLE("AIX does not use dynamic shadow offset!"); - return 0; -} - -void FlushUnneededASanShadowMemory(uptr p, uptr size) { - ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size)); -} - -} // namespace __asan - -#endif // SANITIZER_AIX diff --git a/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt b/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt deleted file mode 100644 index 7387f8173e859..0000000000000 --- a/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt +++ /dev/null @@ -1,21 +0,0 @@ -#! . -_ZdaPv -_ZdaPvRKSt9nothrow_t -_ZdaPvSt11align_val_t -_ZdaPvSt11align_val_tRKSt9nothrow_t -_ZdaPvm -_ZdaPvmSt11align_val_t -_ZdlPv -_ZdlPvRKSt9nothrow_t -_ZdlPvSt11align_val_t -_ZdlPvSt11align_val_tRKSt9nothrow_t -_ZdlPvm -_ZdlPvmSt11align_val_t -_Znam -_ZnamRKSt9nothrow_t -_ZnamSt11align_val_t -_ZnamSt11align_val_tRKSt9nothrow_t -_Znwm -_ZnwmRKSt9nothrow_t -_ZnwmSt11align_val_t -_ZnwmSt11align_val_tRKSt9nothrow_t diff --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp index c2f85099a3e36..fb66c871ea8a5 100644 --- a/compiler-rt/lib/asan/asan_posix.cpp +++ b/compiler-rt/lib/asan/asan_posix.cpp @@ -14,11 +14,7 @@ #include "sanitizer_common/sanitizer_platform.h" #if SANITIZER_POSIX -// tid_t is also defined in AIX header /usr/include/sys/types.h which is -// included by system pthread.h -# define tid_t tid_t_temp # include -# undef tid_t # include # include # include @@ -184,7 +180,7 @@ static void AfterFork(bool fork_child) { void InstallAtForkHandler() { # if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE || \ - (SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU || SANITIZER_AIX + (SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU // While other Linux targets use clone in internal_fork which doesn't // trigger pthread_atfork handlers, Linux/sparc64 uses __fork, causing a // hang. diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py index 7cff87b6c9bc9..058a1614b55e6 100755 --- a/compiler-rt/lib/asan/scripts/asan_symbolize.py +++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py @@ -59,7 +59,6 @@ def is_valid_arch(s): "armv7s", "armv7k", "arm64", - "powerpc", "powerpc64", "powerpc64le", "s390x", @@ -450,14 +449,7 @@ def __init__(self, plugin_proxy=None, dsym_hint_producer=None): # E.g. in Chrome several binaries may share a single .dSYM. self.dsym_hint_producer = dsym_hint_producer self.system = os.uname()[0] - if self.system not in [ - "Linux", - "Darwin", - "FreeBSD", - "NetBSD", - "SunOS", - "AIX", - ]: + if self.system not in ["Linux", "Darwin", "FreeBSD", "NetBSD", "SunOS"]: raise Exception("Unknown system") self.llvm_symbolizers = {} self.last_llvm_symbolizer = None diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h index e5b912d70e61e..62523c7ae187c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h @@ -23,12 +23,7 @@ namespace __sanitizer { typedef CompactSizeClassMap InternalSizeClassMap; struct AP32 { -// For AIX 64-bit, the mmap begin is at address 0x0a00000000000000ULL. -#if SANITIZER_AIX && SANITIZER_WORDSIZE == 64 - static const uptr kSpaceBeg = 0x0a00000000000000ULL; -#else static const uptr kSpaceBeg = 0; -#endif static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; static const uptr kMetadataSize = 0; typedef InternalSizeClassMap SizeClassMap; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h index 0faf9b3c151a4..602b197c42ae3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h @@ -288,7 +288,6 @@ class SizeClassAllocator32 { uptr ComputeRegionId(uptr mem) const { if (SANITIZER_SIGN_EXTENDED_ADDRESSES) mem &= (kSpaceSize - 1); - mem -= kSpaceBeg; const uptr res = mem >> kRegionSizeLog; CHECK_LT(res, kNumPossibleRegions); return res; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp index aa30fd9b5dd96..f275e81ff0416 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp @@ -169,12 +169,7 @@ void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name, : !MmapFixedNoReserve(beg, size, name)) { Report( "ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. " - "Perhaps you're using ulimit -v " -# if SANITIZER_AIX && SANITIZER_WORDSIZE == 32 - "or using large address-space model for 32-bit XCOFF by using ldedit " - "or setting LDR_CNTRL=MAXDATA or compiling the binary with -bmaxdata " -# endif - "\n", + "Perhaps you're using ulimit -v or ulimit -d\n", size); Die(); } From af8e7740a286d3a94b2c1365b70ba01f4bd9b8f2 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Mon, 12 May 2025 22:17:04 -0400 Subject: [PATCH 17/18] Trigger PR refresh From d797a87b655819b6829718f038984daf679801d2 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Mon, 12 May 2025 22:17:54 -0400 Subject: [PATCH 18/18] Move code to new PR --- .../sanitizer_common/sanitizer_atomic_clang.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h index b357345ec7854..1414092e38d7e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h @@ -14,18 +14,6 @@ #ifndef SANITIZER_ATOMIC_CLANG_H #define SANITIZER_ATOMIC_CLANG_H -// Helper to suppress warnings related to 8-byte atomic accesses when the target -// is 32-bit AIX (where such accesses use libatomic). -#if defined(_AIX) && !defined(__powerpc64__) && defined(__clang__) -# define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Watomic-alignment\"") -# define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END _Pragma("clang diagnostic pop") -#else -# define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN -# define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END -#endif - namespace __sanitizer { // We use the compiler builtin atomic operations for loads and stores, which @@ -47,8 +35,6 @@ inline void proc_yield(int cnt) { #endif } -SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN - template inline typename T::Type atomic_load(const volatile T *a, memory_order mo) { DCHECK(mo == memory_order_relaxed || mo == memory_order_consume || @@ -106,8 +92,6 @@ inline bool atomic_compare_exchange_weak(volatile T *a, typename T::Type *cmp, return atomic_compare_exchange_strong(a, cmp, xchg, mo); } -SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END - } // namespace __sanitizer #undef ATOMIC_ORDER