From nobody Tue May 17 19:47:01 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 9F56B1ADA498; Tue, 17 May 2022 19:47:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4L2mps4368z4VFc; Tue, 17 May 2022 19:47:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652816821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WWlhT5gBeR8IqkuEIx6pqlDtVKlo1HLG1USw68DR4iU=; b=roZiAxtnroKDcETt4m/jflGqEpDoutDipEIv2PvnIaWSJ9SK9j34FNlkPrYSc5MrHofdah J/srh4omLuqDUqwn7FxIIGVGz3iX8tVqp6X4j2JU9oL6Okv0AvKlA2dm2p4LPVdA9BQ81m m5/onG4QSwSW/cGqibnuB707T8XoKkA6MpVXGkFXQE2HOZ3zfOMiL9qNChp9JRDoNGOfS1 pVsL/O3XxUudzdwjQg5n6MLBe79AT1BdsoZYO3V7m+ZeHF+j9kma/EKlZzGAcGYv/bKx9M 3c1sQQU21XGc6QqcFQwBlu5D4YmW8R06fhCjE/foFBgGmZLZb8ucwGNY+9II3Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6B90C1AEFE; Tue, 17 May 2022 19:47:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 24HJl1Ta000803; Tue, 17 May 2022 19:47:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24HJl1eL000802; Tue, 17 May 2022 19:47:01 GMT (envelope-from git) Date: Tue, 17 May 2022 19:47:01 GMT Message-Id: <202205171947.24HJl1eL000802@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Kubaj Subject: git: f5024381ac16 - main - powerpc: enable supported sanitizers on powerpc64* List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pkubaj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f5024381ac16ba43d37a8bd32d54c27f6a6afa66 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652816821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WWlhT5gBeR8IqkuEIx6pqlDtVKlo1HLG1USw68DR4iU=; b=RyTxIS7w3VeQf9gWAa75YzMW+DUgILCc/206LeXPnYdlTtlOtb5yjgpZYTy4X4YDYumQUG f1X4dQme2vvpBL9GBewHswG97PGCi0nHHRBqXDRDcM77l3tIxGHFjblcpxdnkJfeHl/Qyn w6cbPoRQdAjNYkRRdyuoD5MzHMwkPTbdGr8juH1fTN8HamIV1ju5EFD6perJ5xhi5VSj5e ASJ/HdwtR+StoJYcBadAyvmnn3t00R6z8UUlZLrjguyFp2DEB8fWpLwNb4okA7gEbhJPEH 1CqQmB8NuGO1FR5fcZdr/yCXpziIqSCj92BBDMvt1fglxjwjj6WFQFbP2a7TZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652816821; a=rsa-sha256; cv=none; b=ModU568VvqDMNDiCHwLOhXk1coLmFwULepSeRfFPK48bJedTVqoOvuFnQyyr7g7Uhst12r VYp8+BS7aca+VUSx/p4GenxS6SPKoc3Hjd6vzQU+hAgxirR4VQOMaKOZW10+mr+r9tPwUP Z7M73X+fwLSsn3nBQkYBH4YpjCBc/ODs9tmGz65NP7x16l0Yl/r2EYDk3XOAeOW8pshlTg +3Bj8/BOFtrfV+2BpT7qf6G2gpmb0psA+As8VYUg0oeA81pXLP0e3nRQ9CxV45Nwli1fYp BJ11lKLdlE1IXzzL3pNxLZTjlk49peXG5RXBuf3lGkJEfYG8QVyqF1ofBDoCGA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pkubaj (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=f5024381ac16ba43d37a8bd32d54c27f6a6afa66 commit f5024381ac16ba43d37a8bd32d54c27f6a6afa66 Author: Piotr Kubaj AuthorDate: 2022-05-17 06:39:29 +0000 Commit: Piotr Kubaj CommitDate: 2022-05-17 19:46:53 +0000 powerpc: enable supported sanitizers on powerpc64* 1. Merge LLVM's 315d792130258a9b7250494be8d002ebb427b08f, adding support for FreeBSD/powerpc64*. 2. Add sanitizer list to lib/libclang_rt/Makefile, taken from the list of libraries that llvm-devel port builds. 3. powerpc64le supports the same sanitizers that powerpc64, but powerpc64le also supports xray* sanitizers. 4. lib/libclang_rt/xray/Makefile hardcodes amd64-specific files, so that needs to be conditionalized. 5. Sanitizers are not enabled for powerpc, because powerpc supports only builtins and profile. Reviewed by: dim Differential Revision: https://reviews.freebsd.org/D35228 Relnotes: yes MFC after: 3 days --- .../lib/sanitizer_common/sanitizer_linux.cpp | 34 +++++++++++++--------- .../compiler-rt/lib/xray/xray_powerpc64.inc | 15 ++++++++++ lib/libclang_rt/Makefile | 25 ++++++++++++++++ lib/libclang_rt/xray/Makefile | 11 ++++++- 4 files changed, 71 insertions(+), 14 deletions(-) diff --git a/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 9f8cc5e6f4c3..778a79b1dfa3 100644 --- a/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2080,12 +2080,19 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { *sp = ucontext->uc_mcontext.gregs[REG_UESP]; # endif #elif defined(__powerpc__) || defined(__powerpc64__) +# if SANITIZER_FREEBSD + ucontext_t *ucontext = (ucontext_t *)context; + *pc = ucontext->uc_mcontext.mc_srr0; + *sp = ucontext->uc_mcontext.mc_frame[1]; + *bp = ucontext->uc_mcontext.mc_frame[31]; +# else ucontext_t *ucontext = (ucontext_t*)context; *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__) #if defined(__arch64__) || defined(__sparcv9) #define STACK_BIAS 2047 @@ -2174,17 +2181,6 @@ void CheckASLR() { GetArgv()[0]); Die(); } -#elif SANITIZER_PPC64V2 - // Disable ASLR for Linux PPC64LE. - int old_personality = personality(0xffffffff); - if (old_personality != -1 && (old_personality & ADDR_NO_RANDOMIZE) == 0) { - VReport(1, "WARNING: Program is being run with address space layout " - "randomization (ASLR) enabled which prevents the thread and " - "memory sanitizers from working on powerpc64le.\n" - "ASLR will be disabled and the program re-executed.\n"); - CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1); - ReExec(); - } #elif SANITIZER_FREEBSD int aslr_status; if (UNLIKELY(procctl(P_PID, 0, PROC_ASLR_STATUS, &aslr_status) == -1)) { @@ -2201,6 +2197,18 @@ void CheckASLR() { CHECK_NE(procctl(P_PID, 0, PROC_ASLR_CTL, &aslr_ctl), -1); ReExec(); } +# elif SANITIZER_PPC64V2 + // Disable ASLR for Linux PPC64LE. + int old_personality = personality(0xffffffff); + if (old_personality != -1 && (old_personality & ADDR_NO_RANDOMIZE) == 0) { + VReport(1, + "WARNING: Program is being run with address space layout " + "randomization (ASLR) enabled which prevents the thread and " + "memory sanitizers from working on powerpc64le.\n" + "ASLR will be disabled and the program re-executed.\n"); + CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1); + ReExec(); + } #else // Do nothing #endif @@ -2225,9 +2233,9 @@ void CheckMPROTECT() { Printf("This sanitizer is not compatible with enabled MPROTECT\n"); Die(); } -#else +# else // Do nothing -#endif +# endif } void CheckNoDeepBind(const char *filename, int flag) { diff --git a/contrib/llvm-project/compiler-rt/lib/xray/xray_powerpc64.inc b/contrib/llvm-project/compiler-rt/lib/xray/xray_powerpc64.inc index e4e16d5b28e0..7e872b5b42e6 100644 --- a/contrib/llvm-project/compiler-rt/lib/xray/xray_powerpc64.inc +++ b/contrib/llvm-project/compiler-rt/lib/xray/xray_powerpc64.inc @@ -12,7 +12,22 @@ #include #include +#ifdef __linux__ #include +#elif defined(__FreeBSD__) +#include +#include + +#define __ppc_get_timebase __builtin_ppc_get_timebase + +uint64_t __ppc_get_timebase_freq (void) +{ + uint64_t tb_freq = 0; + size_t length = sizeof(tb_freq); + sysctlbyname("kern.timecounter.tc.timebase.frequency", &tb_freq, &length, nullptr, 0); + return tb_freq; +} +#endif #include "xray_defs.h" diff --git a/lib/libclang_rt/Makefile b/lib/libclang_rt/Makefile index 0f9a123b0fba..6c6aa2af2a5f 100644 --- a/lib/libclang_rt/Makefile +++ b/lib/libclang_rt/Makefile @@ -32,6 +32,31 @@ SUBDIR+= xray-fdr SUBDIR+= xray-profiling .endif # amd64 +.if ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "powerpc64le" +SUBDIR+= include +SUBDIR+= asan +SUBDIR+= asan-preinit +SUBDIR+= asan_cxx +SUBDIR+= asan_dynamic +SUBDIR+= asan_static +SUBDIR+= msan +SUBDIR+= msan_cxx +SUBDIR+= stats +SUBDIR+= stats_client +SUBDIR+= tsan +SUBDIR+= tsan_cxx +SUBDIR+= ubsan_minimal +SUBDIR+= ubsan_standalone +SUBDIR+= ubsan_standalone_cxx +.endif # powerpc64 || powerpc64le + +.if ${MACHINE_ARCH} == "powerpc64le" +SUBDIR+= xray +SUBDIR+= xray-basic +SUBDIR+= xray-fdr +SUBDIR+= xray-profiling +.endif # powerpc64le + .if ${MACHINE_CPUARCH} == "riscv" SUBDIR+= include SUBDIR+= asan diff --git a/lib/libclang_rt/xray/Makefile b/lib/libclang_rt/xray/Makefile index ce2d725710e8..252c42211837 100644 --- a/lib/libclang_rt/xray/Makefile +++ b/lib/libclang_rt/xray/Makefile @@ -37,9 +37,18 @@ SRCS+= xray/xray_flags.cpp SRCS+= xray/xray_init.cpp SRCS+= xray/xray_interface.cpp SRCS+= xray/xray_log_interface.cpp -SRCS+= xray/xray_trampoline_x86_64.S SRCS+= xray/xray_utils.cpp + +.if ${MACHINE_CPUARCH} == amd64 +SRCS+= xray/xray_trampoline_x86_64.S SRCS+= xray/xray_x86_64.cpp +.endif # amd64 + +.if ${MACHINE_ARCH} == powerpc64le +SRCS+= xray/xray_powerpc64.cpp +SRCS+= xray/xray_trampoline_powerpc64.cpp +SRCS+= xray/xray_trampoline_powerpc64_asm.S +.endif # powerpc64le .PATH: ${CRTSRC}/include/xray INCSDIR= ${CLANGDIR}/include/xray