Index: lib/sanitizer_common/sanitizer_linux.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux.cc +++ lib/sanitizer_common/sanitizer_linux.cc @@ -1727,9 +1727,15 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { #if defined(__arm__) ucontext_t *ucontext = (ucontext_t*)context; +# if SANITIZER_NETBSD + *pc = _UC_MACHINE_PC(ucontext); + *bp = _UC_MACHINE_SP(ucontext); + *sp = ucontext->uc_mcontext.__gregs[_REG_R11]; +# else *pc = ucontext->uc_mcontext.arm_pc; *bp = ucontext->uc_mcontext.arm_fp; *sp = ucontext->uc_mcontext.arm_sp; +# endif #elif defined(__aarch64__) ucontext_t *ucontext = (ucontext_t*)context; *pc = ucontext->uc_mcontext.pc; @@ -1737,17 +1743,23 @@ *sp = ucontext->uc_mcontext.sp; #elif defined(__hppa__) ucontext_t *ucontext = (ucontext_t*)context; +# if SANITIZER_NETBSD + *pc = _UC_MACHINE_PC(ucontext); + *sp = _UC_MACHINE_SP(ucontext); + *bp = ucontext->uc_mcontext.__gregs[3]; +# else *pc = ucontext->uc_mcontext.sc_iaoq[0]; /* GCC uses %r3 whenever a frame pointer is needed. */ *bp = ucontext->uc_mcontext.sc_gr[3]; *sp = ucontext->uc_mcontext.sc_gr[30]; +# endif #elif defined(__x86_64__) # if SANITIZER_FREEBSD ucontext_t *ucontext = (ucontext_t*)context; *pc = ucontext->uc_mcontext.mc_rip; *bp = ucontext->uc_mcontext.mc_rbp; *sp = ucontext->uc_mcontext.mc_rsp; -#elif SANITIZER_NETBSD +# elif SANITIZER_NETBSD ucontext_t *ucontext = (ucontext_t *)context; *pc = ucontext->uc_mcontext.__gregs[_REG_RIP]; *bp = ucontext->uc_mcontext.__gregs[_REG_RBP]; @@ -1764,7 +1776,7 @@ *pc = ucontext->uc_mcontext.mc_eip; *bp = ucontext->uc_mcontext.mc_ebp; *sp = ucontext->uc_mcontext.mc_esp; -#elif SANITIZER_NETBSD +# elif SANITIZER_NETBSD ucontext_t *ucontext = (ucontext_t *)context; *pc = ucontext->uc_mcontext.__gregs[_REG_EIP]; *bp = ucontext->uc_mcontext.__gregs[_REG_EBP]; @@ -1790,39 +1802,62 @@ # endif #elif defined(__powerpc__) || defined(__powerpc64__) ucontext_t *ucontext = (ucontext_t*)context; +# if SANITIZER_NETBSD + *pc = _UC_MACHINE_PC(ucontext); + *sp = _UC_MACHINE_SP(ucontext); + *bp = ucontext->uc_mcontext.__gregs[_REG_R31]; +# else *pc = ucontext->uc_mcontext.regs->nip; *sp = ucontext->uc_mcontext.regs->gpr[PT_R1]; // The powerpc{,64}-linux ABIs do not specify r31 as the frame // pointer, but GCC always uses r31 when we need a frame pointer. *bp = ucontext->uc_mcontext.regs->gpr[PT_R31]; +# endif #elif defined(__sparc__) ucontext_t *ucontext = (ucontext_t*)context; uptr *stk_ptr; -# if defined (__sparcv9) -# ifndef MC_PC -# define MC_PC REG_PC -# endif -# ifndef MC_O6 -# define MC_O6 REG_O6 -# endif -# ifdef SANITIZER_SOLARIS -# define mc_gregs gregs -# endif +# if SANITIZER_NETBSD + *pc = _UC_MACHINE_PC(ucontext); + *sp = _UC_MACHINE_SP(ucontext); +# if defined (__arch64__) + stk_ptr = (uptr *) (*sp + 2047); +# else + stk_ptr = (uptr *) *sp; +# endif + *bp = stk_ptr[15]; +# else +# if defined (__sparcv9) +# ifndef MC_PC +# define MC_PC REG_PC +# endif +# ifndef MC_O6 +# define MC_O6 REG_O6 +# endif +# ifdef SANITIZER_SOLARIS +# define mc_gregs gregs +# endif *pc = ucontext->uc_mcontext.mc_gregs[MC_PC]; *sp = ucontext->uc_mcontext.mc_gregs[MC_O6]; stk_ptr = (uptr *) (*sp + 2047); *bp = stk_ptr[15]; -# else +# else *pc = ucontext->uc_mcontext.gregs[REG_PC]; *sp = ucontext->uc_mcontext.gregs[REG_O6]; stk_ptr = (uptr *) *sp; *bp = stk_ptr[15]; +# endif # endif #elif defined(__mips__) ucontext_t *ucontext = (ucontext_t*)context; +# if SANITIZER_NETBSD + *pc = _UC_MACHINE_PC(ucontext); + *sp = _UC_MACHINE_SP(ucontext); + *bp = ucontext->uc_mcontext.__gregs[_REG_S8]; +# else *pc = ucontext->uc_mcontext.pc; *bp = ucontext->uc_mcontext.gregs[30]; *sp = ucontext->uc_mcontext.gregs[29]; +# endif #elif defined(__s390__) ucontext_t *ucontext = (ucontext_t*)context; # if defined(__s390x__) @@ -1832,6 +1867,26 @@ # endif *bp = ucontext->uc_mcontext.gregs[11]; *sp = ucontext->uc_mcontext.gregs[15]; +#elif defined(__alpha__) // SANITIZER_NETBSD + ucontext_t *ucontext = (ucontext_t*)context; + *pc = _UC_MACHINE_PC(ucontext); + *sp = _UC_MACHINE_SP(ucontext); + *bp = ucontext->uc_mcontext.__gregs[_REG_S6]; +#elif defined(__m68k__) || defined(__mc68010__) // SANITIZER_NETBSD + ucontext_t *ucontext = (ucontext_t*)context; + *pc = _UC_MACHINE_PC(ucontext); + *sp = _UC_MACHINE_SP(ucontext); + *bp = ucontext->uc_mcontext.__gregs[_REG_A6]; +#elif defined(__vax__) // SANITIZER_NETBSD + ucontext_t *ucontext = (ucontext_t*)context; + *pc = _UC_MACHINE_PC(ucontext); + *sp = _UC_MACHINE_SP(ucontext); + *bp = ucontext->uc_mcontext.__gregs[_REG_FP]; +#elif defined(__sh3__) // SANITIZER_NETBSD + ucontext_t *ucontext = (ucontext_t*)context; + *pc = _UC_MACHINE_PC(ucontext); + *sp = _UC_MACHINE_SP(ucontext); + *bp = ucontext->uc_mcontext.__gregs[_REG_R14]; #else # error "Unsupported arch" #endif Index: lib/ubsan/ubsan_platform.h =================================================================== --- lib/ubsan/ubsan_platform.h +++ lib/ubsan/ubsan_platform.h @@ -15,10 +15,12 @@ // Other platforms should be easy to add, and probably work as-is. #if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \ - defined(__NetBSD__)) && \ + defined(__NetBSD__) || (defined(__sun__) && defined(__svr4__))) && \ (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || \ defined(__aarch64__) || defined(__mips__) || defined(__powerpc64__) || \ - defined(__s390__)) || (defined(__sun__) && defined(__svr4__)) + defined(__s390__) || defined(__powerpc__) || defined(__hppa__) || \ + defined(__m68k__) || defined(__mc68010__) || defined(__sparc__) || \ + defined(__alpha__) || defined(__vax__) || defined(__sh3__)) # define CAN_SANITIZE_UB 1 #elif defined(_WIN32) || defined(__Fuchsia__) # define CAN_SANITIZE_UB 1