head 1.4; access; symbols netbsd-11-0-RC4:1.3 netbsd-11-0-RC3:1.3 netbsd-11-0-RC2:1.3 netbsd-11-0-RC1:1.3 gcc-14-3-0:1.1.1.2 perseant-exfatfs-base-20250801:1.3 netbsd-11:1.3.0.4 netbsd-11-base:1.3 gcc-12-5-0:1.1.1.1 perseant-exfatfs-base-20240630:1.3 gcc-12-4-0:1.1.1.1 perseant-exfatfs:1.3.0.2 perseant-exfatfs-base:1.3 gcc-12-3-0:1.1.1.1 gcc-10-5-0:1.1.1.1 gcc-10-4-0:1.1.1.1 cjep_sun2x:1.2.0.4 cjep_sun2x-base:1.2 cjep_staticlib_x-base1:1.2 cjep_staticlib_x:1.2.0.2 cjep_staticlib_x-base:1.2 gcc-10-3-0:1.1.1.1 FSF:1.1.1; locks; strict; comment @// @; 1.4 date 2025.09.14.00.08.54; author mrg; state Exp; branches; next 1.3; commitid x9D5QEnvbeMI4CaG; 1.3 date 2023.07.31.01.44.54; author mrg; state Exp; branches; next 1.2; commitid q79F5Opf0FLsyTyE; 1.2 date 2021.04.11.23.54.25; author mrg; state dead; branches; next 1.1; commitid wJn7ggfUTEMOWVOC; 1.1 date 2021.04.10.22.09.22; author mrg; state Exp; branches 1.1.1.1; next ; commitid eC4g0MRpqTvEkNOC; 1.1.1.1 date 2021.04.10.22.09.22; author mrg; state Exp; branches; next 1.1.1.2; commitid eC4g0MRpqTvEkNOC; 1.1.1.2 date 2025.09.13.23.45.04; author mrg; state Exp; branches; next ; commitid KwhwN4krNWa6XBaG; desc @@ 1.4 log @merge GCC 14.3.0. @ text @//===-- asan_malloc_mac.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. // // Mac-specific malloc interception. //===----------------------------------------------------------------------===// #include "sanitizer_common/sanitizer_platform.h" #if SANITIZER_APPLE #include "asan_interceptors.h" #include "asan_report.h" #include "asan_stack.h" #include "asan_stats.h" #include "lsan/lsan_common.h" using namespace __asan; #define COMMON_MALLOC_ZONE_NAME "asan" #define COMMON_MALLOC_ENTER() ENSURE_ASAN_INITED() # define COMMON_MALLOC_SANITIZER_INITIALIZED AsanInited() # define COMMON_MALLOC_FORCE_LOCK() asan_mz_force_lock() # define COMMON_MALLOC_FORCE_UNLOCK() asan_mz_force_unlock() # define COMMON_MALLOC_MEMALIGN(alignment, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_memalign(alignment, size, &stack, FROM_MALLOC) # define COMMON_MALLOC_MALLOC(size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_malloc(size, &stack) # define COMMON_MALLOC_REALLOC(ptr, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_realloc(ptr, size, &stack); # define COMMON_MALLOC_CALLOC(count, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_calloc(count, size, &stack); # define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \ GET_STACK_TRACE_MALLOC; \ int res = asan_posix_memalign(memptr, alignment, size, &stack); # define COMMON_MALLOC_VALLOC(size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_memalign(GetPageSizeCached(), size, &stack, FROM_MALLOC); # define COMMON_MALLOC_FREE(ptr) \ GET_STACK_TRACE_FREE; \ asan_free(ptr, &stack, FROM_MALLOC); # define COMMON_MALLOC_SIZE(ptr) uptr size = asan_mz_size(ptr); # define COMMON_MALLOC_FILL_STATS(zone, stats) \ AsanMallocStats malloc_stats; \ FillMallocStatistics(&malloc_stats); \ CHECK(sizeof(malloc_statistics_t) == sizeof(AsanMallocStats)); \ internal_memcpy(stats, &malloc_stats, sizeof(malloc_statistics_t)); # define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \ GET_STACK_TRACE_FREE; \ ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack); # define COMMON_MALLOC_NAMESPACE __asan # define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0 # define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 1 # include "sanitizer_common/sanitizer_malloc_mac.inc" namespace COMMON_MALLOC_NAMESPACE { bool HandleDlopenInit() { static_assert(SANITIZER_SUPPORTS_INIT_FOR_DLOPEN, "Expected SANITIZER_SUPPORTS_INIT_FOR_DLOPEN to be true"); // We have no reliable way of knowing how we are being loaded // so make it a requirement on Apple platforms to set this environment // variable to indicate that we want to perform initialization via // dlopen(). auto init_str = GetEnv("APPLE_ASAN_INIT_FOR_DLOPEN"); if (!init_str) return false; if (internal_strncmp(init_str, "1", 1) != 0) return false; // When we are loaded via `dlopen()` path we still initialize the malloc zone // so Symbolication clients (e.g. `leaks`) that load the ASan allocator can // find an initialized malloc zone. InitMallocZoneFields(); return true; } } // namespace COMMON_MALLOC_NAMESPACE namespace { void mi_extra_init(sanitizer_malloc_introspection_t *mi) { uptr last_byte_plus_one = 0; mi->allocator_ptr = 0; // Range is [begin_ptr, end_ptr) __lsan::GetAllocatorGlobalRange(&(mi->allocator_ptr), &last_byte_plus_one); CHECK_NE(mi->allocator_ptr, 0); CHECK_GT(last_byte_plus_one, mi->allocator_ptr); mi->allocator_size = last_byte_plus_one - (mi->allocator_ptr); CHECK_GT(mi->allocator_size, 0); } } // namespace #endif @ 1.3 log @make this actually be GCC 12.3.0's libsanitizer. the libsanitizer we used with GCC 9 and GCC 10 was significantly ahead of the GCC 9 and GCC 10 provided versions. @ text @d15 1 a15 1 #if SANITIZER_MAC d26 36 a61 37 #define COMMON_MALLOC_SANITIZER_INITIALIZED asan_inited #define COMMON_MALLOC_FORCE_LOCK() asan_mz_force_lock() #define COMMON_MALLOC_FORCE_UNLOCK() asan_mz_force_unlock() #define COMMON_MALLOC_MEMALIGN(alignment, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_memalign(alignment, size, &stack, FROM_MALLOC) #define COMMON_MALLOC_MALLOC(size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_malloc(size, &stack) #define COMMON_MALLOC_REALLOC(ptr, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_realloc(ptr, size, &stack); #define COMMON_MALLOC_CALLOC(count, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_calloc(count, size, &stack); #define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \ GET_STACK_TRACE_MALLOC; \ int res = asan_posix_memalign(memptr, alignment, size, &stack); #define COMMON_MALLOC_VALLOC(size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_memalign(GetPageSizeCached(), size, &stack, FROM_MALLOC); #define COMMON_MALLOC_FREE(ptr) \ GET_STACK_TRACE_FREE; \ asan_free(ptr, &stack, FROM_MALLOC); #define COMMON_MALLOC_SIZE(ptr) \ uptr size = asan_mz_size(ptr); #define COMMON_MALLOC_FILL_STATS(zone, stats) \ AsanMallocStats malloc_stats; \ FillMallocStatistics(&malloc_stats); \ CHECK(sizeof(malloc_statistics_t) == sizeof(AsanMallocStats)); \ internal_memcpy(stats, &malloc_stats, sizeof(malloc_statistics_t)); #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \ GET_STACK_TRACE_FREE; \ ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack); #define COMMON_MALLOC_NAMESPACE __asan #define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0 #define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 1 d63 1 a63 1 #include "sanitizer_common/sanitizer_malloc_mac.inc" @ 1.2 log @revert sanitizer back to the version we were using with GCC 9, since that one was already newer than the GCC 10 version. @ text @@ 1.1 log @Initial revision @ text @@ 1.1.1.1 log @initial import of GCC 10.3.0. main changes include: caveats: - ABI issue between c++14 and c++17 fixed - profile mode is removed from libstdc++ - -fno-common is now the default new features: - new flags -fallocation-dce, -fprofile-partial-training, -fprofile-reproducible, -fprofile-prefix-path, and -fanalyzer - many new compile and link time optimisations - enhanced drive optimisations - openacc 2.6 support - openmp 5.0 features - new warnings: -Wstring-compare and -Wzero-length-bounds - extended warnings: -Warray-bounds, -Wformat-overflow, -Wrestrict, -Wreturn-local-addr, -Wstringop-overflow, -Warith-conversion, -Wmismatched-tags, and -Wredundant-tags - some likely C2X features implemented - more C++20 implemented - many new arm & intel CPUs known hundreds of reported bugs are fixed. full list of changes can be found at: https://gcc.gnu.org/gcc-10/changes.html @ text @@ 1.1.1.2 log @initial import of GCC 14.3.0. major changes in GCC 13: - improved sanitizer - zstd debug info compression - LTO improvements - SARIF based diagnostic support - new warnings: -Wxor-used-as-pow, -Wenum-int-mismatch, -Wself-move, -Wdangling-reference - many new -Wanalyzer* specific warnings - enhanced warnings: -Wpessimizing-move, -Wredundant-move - new attributes to mark file descriptors, c++23 "assume" - several C23 features added - several C++23 features added - many new features for Arm, x86, RISC-V major changes in GCC 14: - more strict C99 or newer support - ia64* marked deprecated (but seemingly still in GCC 15.) - several new hardening features - support for "hardbool", which can have user supplied values of true/false - explicit support for stack scrubbing upon function exit - better auto-vectorisation support - added clang-compatible __has_feature and __has_extension - more C23, including -std=c23 - several C++26 features added - better diagnostics in C++ templates - new warnings: -Wnrvo, Welaborated-enum-base - many new features for Arm, x86, RISC-V - possible ABI breaking change for SPARC64 and small structures with arrays of floats. @ text @d15 1 a15 1 #if SANITIZER_APPLE d26 37 a62 36 # define COMMON_MALLOC_SANITIZER_INITIALIZED AsanInited() # define COMMON_MALLOC_FORCE_LOCK() asan_mz_force_lock() # define COMMON_MALLOC_FORCE_UNLOCK() asan_mz_force_unlock() # define COMMON_MALLOC_MEMALIGN(alignment, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_memalign(alignment, size, &stack, FROM_MALLOC) # define COMMON_MALLOC_MALLOC(size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_malloc(size, &stack) # define COMMON_MALLOC_REALLOC(ptr, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_realloc(ptr, size, &stack); # define COMMON_MALLOC_CALLOC(count, size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_calloc(count, size, &stack); # define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \ GET_STACK_TRACE_MALLOC; \ int res = asan_posix_memalign(memptr, alignment, size, &stack); # define COMMON_MALLOC_VALLOC(size) \ GET_STACK_TRACE_MALLOC; \ void *p = asan_memalign(GetPageSizeCached(), size, &stack, FROM_MALLOC); # define COMMON_MALLOC_FREE(ptr) \ GET_STACK_TRACE_FREE; \ asan_free(ptr, &stack, FROM_MALLOC); # define COMMON_MALLOC_SIZE(ptr) uptr size = asan_mz_size(ptr); # define COMMON_MALLOC_FILL_STATS(zone, stats) \ AsanMallocStats malloc_stats; \ FillMallocStatistics(&malloc_stats); \ CHECK(sizeof(malloc_statistics_t) == sizeof(AsanMallocStats)); \ internal_memcpy(stats, &malloc_stats, sizeof(malloc_statistics_t)); # define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \ GET_STACK_TRACE_FREE; \ ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack); # define COMMON_MALLOC_NAMESPACE __asan # define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0 # define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 1 d64 1 a64 1 # include "sanitizer_common/sanitizer_malloc_mac.inc" @