From e0cd57decb3aa9eb911b62306b8f8ac88fd97ffd Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Thu, 23 Jan 2025 13:00:39 -0500 Subject: [PATCH] [compiler-rt] Remove support and workarounds for Android 4 and older (#124056) --- compiler-rt/lib/asan/tests/asan_test.cpp | 6 +----- compiler-rt/lib/lsan/lsan_common_linux.cpp | 5 ----- .../lib/sanitizer_common/sanitizer_common.h | 1 - .../sanitizer_common/sanitizer_getauxval.h | 21 +++++++++---------- .../lib/sanitizer_common/sanitizer_linux.cpp | 11 +--------- .../sanitizer_linux_libcdep.cpp | 10 +-------- .../sanitizer_platform_limits_posix.cpp | 2 +- 7 files changed, 14 insertions(+), 42 deletions(-) diff --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp index 09d71569f89b..56377bde1c8d 100644 --- a/compiler-rt/lib/asan/tests/asan_test.cpp +++ b/compiler-rt/lib/asan/tests/asan_test.cpp @@ -1166,13 +1166,9 @@ TEST(AddressSanitizer, DISABLED_StressStackReuseAndExceptionsTest) { #if !defined(_WIN32) TEST(AddressSanitizer, MlockTest) { -#if !defined(__ANDROID__) || __ANDROID_API__ >= 17 EXPECT_EQ(0, mlockall(MCL_CURRENT)); -#endif - EXPECT_EQ(0, mlock((void*)0x12345, 0x5678)); -#if !defined(__ANDROID__) || __ANDROID_API__ >= 17 + EXPECT_EQ(0, mlock((void *)0x12345, 0x5678)); EXPECT_EQ(0, munlockall()); -#endif EXPECT_EQ(0, munlock((void*)0x987, 0x654)); } #endif diff --git a/compiler-rt/lib/lsan/lsan_common_linux.cpp b/compiler-rt/lib/lsan/lsan_common_linux.cpp index 7a0b2f038be0..6fd54bbea3c7 100644 --- a/compiler-rt/lib/lsan/lsan_common_linux.cpp +++ b/compiler-rt/lib/lsan/lsan_common_linux.cpp @@ -93,11 +93,6 @@ static int ProcessGlobalRegionsCallback(struct dl_phdr_info *info, size_t size, return 0; } -#if SANITIZER_ANDROID && __ANDROID_API__ < 21 -extern "C" __attribute__((weak)) int dl_iterate_phdr( - int (*)(struct dl_phdr_info *, size_t, void *), void *); -#endif - // Scans global variables for heap pointers. void ProcessGlobalRegions(Frontier *frontier) { if (!flags()->use_globals) return; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 0b5e68c5fd79..d9e7ded593fe 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -927,7 +927,6 @@ typedef void (*RangeIteratorCallback)(uptr begin, uptr end, void *arg); enum AndroidApiLevel { ANDROID_NOT_ANDROID = 0, - ANDROID_KITKAT = 19, ANDROID_LOLLIPOP_MR1 = 22, ANDROID_POST_LOLLIPOP = 23 }; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h b/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h index 38439e44f611..910590b627c2 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h @@ -21,22 +21,21 @@ #if SANITIZER_LINUX || SANITIZER_FUCHSIA -# if (__GLIBC_PREREQ(2, 16) || (SANITIZER_ANDROID && __ANDROID_API__ >= 21) || \ - SANITIZER_FUCHSIA) && \ - !SANITIZER_GO -# define SANITIZER_USE_GETAUXVAL 1 -# else -# define SANITIZER_USE_GETAUXVAL 0 -# endif +# if (__GLIBC_PREREQ(2, 16) || SANITIZER_ANDROID || SANITIZER_FUCHSIA) && \ + !SANITIZER_GO +# define SANITIZER_USE_GETAUXVAL 1 +# else +# define SANITIZER_USE_GETAUXVAL 0 +# endif -# if SANITIZER_USE_GETAUXVAL -# include -# else +# if SANITIZER_USE_GETAUXVAL +# include +# else // The weak getauxval definition allows to check for the function at runtime. // This is useful for Android, when compiled at a lower API level yet running // on a more recent platform that offers the function. extern "C" SANITIZER_WEAK_ATTRIBUTE unsigned long getauxval(unsigned long type); -# endif +# endif #elif SANITIZER_NETBSD diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 04b095dca904..997b95f343d4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -1849,11 +1849,6 @@ int internal_uname(struct utsname *buf) { # endif # if SANITIZER_ANDROID -# if __ANDROID_API__ < 21 -extern "C" __attribute__((weak)) int dl_iterate_phdr( - int (*)(struct dl_phdr_info *, size_t, void *), void *); -# endif - static int dl_iterate_phdr_test_cb(struct dl_phdr_info *info, size_t size, void *data) { // Any name starting with "lib" indicates a bug in L where library base names @@ -1869,9 +1864,7 @@ static int dl_iterate_phdr_test_cb(struct dl_phdr_info *info, size_t size, static atomic_uint32_t android_api_level; static AndroidApiLevel AndroidDetectApiLevelStatic() { -# if __ANDROID_API__ <= 19 - return ANDROID_KITKAT; -# elif __ANDROID_API__ <= 22 +# if __ANDROID_API__ <= 22 return ANDROID_LOLLIPOP_MR1; # else return ANDROID_POST_LOLLIPOP; @@ -1879,8 +1872,6 @@ static AndroidApiLevel AndroidDetectApiLevelStatic() { } static AndroidApiLevel AndroidDetectApiLevel() { - if (!&dl_iterate_phdr) - return ANDROID_KITKAT; // K or lower bool base_name_seen = false; dl_iterate_phdr(dl_iterate_phdr_test_cb, &base_name_seen); if (base_name_seen) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp index 62b1dc43dce1..e11eff13cd32 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -773,11 +773,6 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { return 0; } -# if SANITIZER_ANDROID && __ANDROID_API__ < 21 -extern "C" __attribute__((weak)) int dl_iterate_phdr( - int (*)(struct dl_phdr_info *, size_t, void *), void *); -# endif - static bool requiresProcmaps() { # if SANITIZER_ANDROID && __ANDROID_API__ <= 22 // Fall back to /proc/maps if dl_iterate_phdr is unavailable or broken. @@ -940,11 +935,8 @@ extern "C" SANITIZER_WEAK_ATTRIBUTE int __android_log_write(int prio, void WriteOneLineToSyslog(const char *s) { if (&async_safe_write_log) { async_safe_write_log(SANITIZER_ANDROID_LOG_INFO, GetProcessName(), s); - } else if (AndroidGetApiLevel() > ANDROID_KITKAT) { - syslog(LOG_INFO, "%s", s); } else { - CHECK(&__android_log_write); - __android_log_write(SANITIZER_ANDROID_LOG_INFO, nullptr, s); + syslog(LOG_INFO, "%s", s); } } 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 ddd67cb43524..a5311d266b0c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -1093,7 +1093,7 @@ CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len); CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level); CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type); -#if SANITIZER_LINUX && (__ANDROID_API__ >= 21 || __GLIBC_PREREQ (2, 14)) +# if SANITIZER_LINUX && (SANITIZER_ANDROID || __GLIBC_PREREQ(2, 14)) CHECK_TYPE_SIZE(mmsghdr); CHECK_SIZE_AND_OFFSET(mmsghdr, msg_hdr); CHECK_SIZE_AND_OFFSET(mmsghdr, msg_len);