head 1.5; access; symbols netbsd-11-0-RC4:1.4 netbsd-11-0-RC3:1.4 netbsd-11-0-RC2:1.4 netbsd-11-0-RC1:1.4 gcc-14-3-0:1.1.1.2 perseant-exfatfs-base-20250801:1.4 netbsd-11:1.4.0.4 netbsd-11-base:1.4 gcc-12-5-0:1.1.1.1 perseant-exfatfs-base-20240630:1.4 gcc-12-4-0:1.1.1.1 perseant-exfatfs:1.4.0.2 perseant-exfatfs-base:1.4 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.5 date 2025.09.14.00.08.58; author mrg; state Exp; branches; next 1.4; commitid x9D5QEnvbeMI4CaG; 1.4 date 2023.08.04.07.40.05; author mrg; state Exp; branches; next 1.3; commitid eYDwr3Sks18VnrzE; 1.3 date 2023.07.31.01.44.57; author mrg; state Exp; branches; next 1.2; commitid q79F5Opf0FLsyTyE; 1.2 date 2021.04.11.23.54.28; 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.5 log @merge GCC 14.3.0. @ text @//===-- sanitizer_unwind_linux_libcdep.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 contains the unwind.h-based (aka "slow") stack unwinding routines // available to the tools on Linux, Android, NetBSD, FreeBSD, and Solaris. //===----------------------------------------------------------------------===// #include "sanitizer_platform.h" #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \ SANITIZER_SOLARIS #include "sanitizer_common.h" #include "sanitizer_stacktrace.h" #if SANITIZER_ANDROID #include // for dlopen() #endif #if SANITIZER_FREEBSD #define _GNU_SOURCE // to declare _Unwind_Backtrace() from #endif #include namespace __sanitizer { namespace { //---------------------------- UnwindSlow -------------------------------------- typedef struct { uptr absolute_pc; uptr stack_top; uptr stack_size; } backtrace_frame_t; extern "C" { typedef void *(*acquire_my_map_info_list_func)(); typedef void (*release_my_map_info_list_func)(void *map); typedef sptr (*unwind_backtrace_signal_arch_func)( void *siginfo, void *sigcontext, void *map_info_list, backtrace_frame_t *backtrace, uptr ignore_depth, uptr max_depth); acquire_my_map_info_list_func acquire_my_map_info_list; release_my_map_info_list_func release_my_map_info_list; unwind_backtrace_signal_arch_func unwind_backtrace_signal_arch; } // extern "C" #if defined(__arm__) && !SANITIZER_NETBSD // NetBSD uses dwarf EH #define UNWIND_STOP _URC_END_OF_STACK #define UNWIND_CONTINUE _URC_NO_REASON #else #define UNWIND_STOP _URC_NORMAL_STOP #define UNWIND_CONTINUE _URC_NO_REASON #endif uptr Unwind_GetIP(struct _Unwind_Context *ctx) { #if defined(__arm__) && !SANITIZER_APPLE && !SANITIZER_NETBSD uptr val; _Unwind_VRS_Result res = _Unwind_VRS_Get(ctx, _UVRSC_CORE, 15 /* r15 = PC */, _UVRSD_UINT32, &val); CHECK(res == _UVRSR_OK && "_Unwind_VRS_Get failed"); // Clear the Thumb bit. return val & ~(uptr)1; #else return (uptr)_Unwind_GetIP(ctx); #endif } struct UnwindTraceArg { BufferedStackTrace *stack; u32 max_depth; }; _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) { UnwindTraceArg *arg = (UnwindTraceArg*)param; CHECK_LT(arg->stack->size, arg->max_depth); uptr pc = Unwind_GetIP(ctx); const uptr kPageSize = GetPageSizeCached(); // Let's assume that any pointer in the 0th page (i.e. <0x1000 on i386 and // x86_64) is invalid and stop unwinding here. If we're adding support for // a platform where this isn't true, we need to reconsider this check. if (pc < kPageSize) return UNWIND_STOP; arg->stack->trace_buffer[arg->stack->size++] = pc; if (arg->stack->size == arg->max_depth) return UNWIND_STOP; return UNWIND_CONTINUE; } } // namespace #if SANITIZER_ANDROID void SanitizerInitializeUnwinder() { if (AndroidGetApiLevel() >= ANDROID_LOLLIPOP_MR1) return; // Pre-lollipop Android can not unwind through signal handler frames with // libgcc unwinder, but it has a libcorkscrew.so library with the necessary // workarounds. void *p = dlopen("libcorkscrew.so", RTLD_LAZY); if (!p) { VReport(1, "Failed to open libcorkscrew.so. You may see broken stack traces " "in SEGV reports."); return; } acquire_my_map_info_list = (acquire_my_map_info_list_func)(uptr)dlsym(p, "acquire_my_map_info_list"); release_my_map_info_list = (release_my_map_info_list_func)(uptr)dlsym(p, "release_my_map_info_list"); unwind_backtrace_signal_arch = (unwind_backtrace_signal_arch_func)(uptr)dlsym( p, "unwind_backtrace_signal_arch"); if (!acquire_my_map_info_list || !release_my_map_info_list || !unwind_backtrace_signal_arch) { VReport(1, "Failed to find one of the required symbols in libcorkscrew.so. " "You may see broken stack traces in SEGV reports."); acquire_my_map_info_list = 0; unwind_backtrace_signal_arch = 0; release_my_map_info_list = 0; } } #endif void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) { CHECK_GE(max_depth, 2); size = 0; UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)}; _Unwind_Backtrace(Unwind_Trace, &arg); // We need to pop a few frames so that pc is on top. uptr to_pop = LocatePcInTrace(pc); // trace_buffer[0] belongs to the current function so we always pop it, // unless there is only 1 frame in the stack trace (1 frame is always better // than 0!). // 1-frame stacks don't normally happen, but this depends on the actual // unwinder implementation (libgcc, libunwind, etc) which is outside of our // control. if (to_pop == 0 && size > 1) to_pop = 1; PopStackFrames(to_pop); trace_buffer[0] = pc; } void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) { CHECK(context); CHECK_GE(max_depth, 2); if (!unwind_backtrace_signal_arch) { UnwindSlow(pc, max_depth); return; } void *map = acquire_my_map_info_list(); CHECK(map); InternalMmapVector frames(kStackTraceMax); // siginfo argument appears to be unused. sptr res = unwind_backtrace_signal_arch(/* siginfo */ 0, context, map, frames.data(), /* ignore_depth */ 0, max_depth); release_my_map_info_list(map); if (res < 0) return; CHECK_LE((uptr)res, kStackTraceMax); size = 0; // +2 compensate for libcorkscrew unwinder returning addresses of call // instructions instead of raw return addresses. for (sptr i = 0; i < res; ++i) trace_buffer[size++] = frames[i].absolute_pc + 2; } } // namespace __sanitizer #endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || // SANITIZER_SOLARIS @ 1.4 log @make sanitizers build for some more platforms m68k (but not m68000), riscv{32,64}, and arm32. @ text @d61 1 a61 1 #if defined(__arm__) && !SANITIZER_MAC && !SANITIZER_NETBSD a141 5 #if defined(__GNUC__) && defined(__sparc__) // __builtin_return_address returns the address of the call instruction // on the SPARC and not the return address, so we need to compensate. trace_buffer[0] = GetNextInstructionPc(pc); #else a142 1 #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 @d61 1 a61 1 #if defined(__arm__) && !SANITIZER_MAC @ 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 @d61 1 a61 1 #if defined(__arm__) && !SANITIZER_APPLE d142 5 d148 1 @