From patchwork Thu Jul 30 12:30:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: joshua X-Patchwork-Id: 1338800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=DWewYK93; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BHVBc3j57z9sSd for ; Thu, 30 Jul 2020 22:31:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D9DE386F836; Thu, 30 Jul 2020 12:31:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D9DE386F836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596112262; bh=/CWv4urCv1nSiqYHbJq/mtgCpgabmPcV/8ALwh2vSpo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DWewYK93AW3zsqeyxUbw6XOUKZGuP9TeJsimOHtEoF292VrEtw2WutBhjmhhBF1o4 G3mwMSfVmC4FiveRILvM4Lm7LH4yFVtUpL8aXvzFKflt3Pi/dY1/qhifcD8nAw1Sxg jfj/na/Eqa13cZqGxQOJ16NY7XmMmLPkh9/vMCE4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by sourceware.org (Postfix) with ESMTPS id 55C173857C61 for ; Thu, 30 Jul 2020 12:30:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 55C173857C61 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R391e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e01358; MF=cooper.joshua@linux.alibaba.com; NM=1; PH=DS; RN=2; SR=0; TI=SMTPD_---0U4EziBN_1596112230; Received: from localhost(mailfrom:cooper.joshua@linux.alibaba.com fp:SMTPD_---0U4EziBN_1596112230) by smtp.aliyun-inc.com(127.0.0.1); Thu, 30 Jul 2020 20:30:39 +0800 To: gcc Subject: [RISC-V] Add support for AddressSanitizer on RISC-V GCC Date: Thu, 30 Jul 2020 20:30:06 +0800 Message-Id: <20200730123006.104-1-cooper.joshua@linux.alibaba.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-19.1 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joshua via Gcc-patches From: joshua Reply-To: Joshua Cc: "cooper . joshua" Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" From: cooper.joshua gcc/ * config/riscv/riscv.c (asan_shadow_offset): Implement the offset of asan shadow memory for risc-v. (asan_shadow_offset): new macro definition. libsanitizer/ * sanitizer_common/sanitizer_common.h (ModuleArch): New enumerator. (ModuleArchToString): New architecture option. * sanitizer_common/sanitizer_platform.h: New macro definition. * sanitizer_common/sanitizer_symbolizer_libcdep.cpp (GetArgV): New architecture option. --- gcc/config/riscv/riscv.c | 11 +++++++++++ libsanitizer/sanitizer_common/sanitizer_common.h | 5 ++++- libsanitizer/sanitizer_common/sanitizer_platform.h | 6 ++++++ .../sanitizer_common/sanitizer_symbolizer_libcdep.cpp | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index bfb3885..05669c2 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -5245,6 +5245,14 @@ riscv_gpr_save_operation_p (rtx op)linux.alibaba return true; } +/* Implement TARGET_ASAN_SHADOW_OFFSET. */ + +static unsigned HOST_WIDE_INT +riscv_asan_shadow_offset (void) +{ + return HOST_WIDE_INT_UC (0x10000000); +} + /* Initialize the GCC target structure. */ #undef TARGET_ASM_ALIGNED_HI_OP #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t" @@ -5428,6 +5436,9 @@ riscv_gpr_save_operation_p (rtx op) #undef TARGET_NEW_ADDRESS_PROFITABLE_P #define TARGET_NEW_ADDRESS_PROFITABLE_P riscv_new_address_profitable_p +#undef TARGET_ASAN_SHADOW_OFFSET +#define TARGET_ASAN_SHADOW_OFFSET riscv_asan_shadow_offset + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-riscv.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_common.h b/libsanitizer/sanitizer_common/sanitizer_common.h index ac16e0e..ea7dff7 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common.h +++ b/libsanitizer/sanitizer_common/sanitizer_common.h @@ -649,7 +649,8 @@ enum ModuleArch { kModuleArchARMV7, kModuleArchARMV7S, kModuleArchARMV7K, - kModuleArchARM64 + kModuleArchARM64, + kModuleArchRISCV }; // Opens the file 'file_name" and reads up to 'max_len' bytes. @@ -693,6 +694,8 @@ inline const char *ModuleArchToString(ModuleArch arch) { return "armv7k"; case kModuleArchARM64: return "arm64"; + case kModuleArchRISCV: + return "riscv"; } CHECK(0 && "Invalid module arch"); return ""; diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/sanitizer_common/sanitizer_platform.h index c68bfa2..bf52490 100644 --- a/libsanitizer/sanitizer_common/sanitizer_platform.h +++ b/libsanitizer/sanitizer_common/sanitizer_platform.h @@ -126,6 +126,12 @@ # define FIRST_32_SECOND_64(a, b) (a) #endif +#if defined(__riscv__) +# define SANITIZER_RISCV 1 +#else +# define SANITIZER_RISCV 0 +#endif + #if defined(__x86_64__) && !defined(_LP64) # define SANITIZER_X32 1 #else diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libcdep.cpp index 490c6fe..408f57d 100644 --- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libcdep.cpp @@ -270,6 +270,8 @@ class LLVMSymbolizerProcess : public SymbolizerProcess { const char* const kSymbolizerArch = "--default-arch=s390x"; #elif defined(__s390__) const char* const kSymbolizerArch = "--default-arch=s390"; +#elif defined(__riscv__) + const char* const kSymbolizerArch = "--default-arch=riscv"; #else const char* const kSymbolizerArch = "--default-arch=unknown"; #endif