From patchwork Tue Nov 6 10:12:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 993566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489135-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=CeBiTec.Uni-Bielefeld.DE Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="sYgGNvA9"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42q52K1DzCz9sBZ for ; Tue, 6 Nov 2018 21:12:23 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=fcxkOE0JM/UTIxTiL5dRUhKMj1alZPrjgwkUdEZ9TJUhc3Y4TQ GJu4BOQeX67i/0rspotopDhY8Yx28l9IoEArxQMVFgXAqUe1DD+KziUSImUiXNvt lIswMqh0inVCMQFDfJHDgN6ad8fUo3AlBQWVoe2GEpzLlf8OKuZfwqlpk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=X/S3oUlsXFQDQ0MAyY6Kt/r6g4w=; b=sYgGNvA9pRuB3BaD8KgI P5Ta+GnTRULLE5+Coej/+0Er+Dp/GHsTp8o1NJoIzELgPvn9W8GQoDVpKgN/KIRt GyKsugbDEvYibkgwUiitCTHgcoC07NWJCDyAQ3mddZ5zZAmbo0q6PelYp/6lLF5Y TcaI0eyqKuHD4DlvFYc24tw= Received: (qmail 670 invoked by alias); 6 Nov 2018 10:12:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 655 invoked by uid 89); 6 Nov 2018 10:12:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=inclination X-HELO: smtp.CeBiTec.Uni-Bielefeld.DE Received: from smtp.CeBiTec.Uni-Bielefeld.DE (HELO smtp.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Nov 2018 10:12:12 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id D8EE035F; Tue, 6 Nov 2018 11:12:07 +0100 (CET) Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id VBZpTXsDMSyo; Tue, 6 Nov 2018 11:12:02 +0100 (CET) Received: from lokon.CeBiTec.Uni-Bielefeld.DE (lokon.CeBiTec.Uni-Bielefeld.DE [129.70.161.152]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id F3EE935E; Tue, 6 Nov 2018 11:12:01 +0100 (CET) Received: (from ro@localhost) by lokon.CeBiTec.Uni-Bielefeld.DE (8.15.2+Sun/8.15.2/Submit) id wA6AC0IM010109; Tue, 6 Nov 2018 11:12:00 +0100 (MET) From: Rainer Orth To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou , Jakub Jelinek Subject: [libsanitizer] Enable libsanitizer on Solaris (PR sanitizer/80953) Date: Tue, 06 Nov 2018 11:12:00 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes Now that the Solaris sanitizer port (asan and ubsan only for now) has been upstream for a while and some last issues fixed, I'd finally like to enable the sanitizers on both sparc and x86. The asan port is 32-bit only for now (on sparc because 64-bit Solaris/SPARC uses the full address space with a large virtual address hole in the middle whose exact location is machine-dependent and not easily determined at runtime; on x86 the situation was the same before Solaris 11.4). The patch itself is pretty trivial, mostly duplicating what Linux does. The only parts I need approval for are * The SPARC implementation of TARGET_ASAN_SHADOW_OFFSET, so far only tested on 32-bit Solaris/SPARC. * The change to c-c++-common/asan/alloca_loop_unpoisoning.c is necessary since Solaris doesn't have an alloca prototype by default: FAIL: c-c++-common/asan/alloca_loop_unpoisoning.c -O0 (test for excess errors) WARNING: c-c++-common/asan/alloca_loop_unpoisoning.c -O0 compilation failed to produce executable Excess errors: /vol/gcc/src/hg/trunk/solaris-asan/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c:19:3: warning: implicit declaration of function 'alloca' [-Wimplicit-function-declaration] /vol/gcc/src/hg/trunk/solaris-asan/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c:19:3: warning: incompatible implicit declaration of built-in function 'alloca' This isn't an issue on Linux where glibc includes which defines alloca as __builtin_alloca. * I'm only enabling libsanitizer on Solaris 11 right now: on Solaris 10 there are a couple of libsanitizer compilation failures and I don't know if I have much time or inclination to fix them only to rip the changes out again in GCC 10. Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11. x86 testsuite results are decent with only c-c++-common/asan/swapcontext-test-1.c failing and g++.dg/asan/default-options-1.C failing on Solaris 11.4+ (11.3 is fine; I suspect this is just another instance of PR c++/52477). On sparc there are quite some more which I intend to investigate subsequently. Ok for mainline? Rainer # HG changeset patch # Parent 7a0019c2c3d32fe0c18f4708f0099e2816f05fa6 Enable libsanitizer on Solaris (PR sanitizer/80953) diff --git a/gcc/config/i386/sol2.h b/gcc/config/i386/sol2.h --- a/gcc/config/i386/sol2.h +++ b/gcc/config/i386/sol2.h @@ -54,6 +54,9 @@ along with GCC; see the file COPYING3. #undef CPP_SPEC #define CPP_SPEC "%(cpp_subtarget)" +#undef CC1_SPEC +#define CC1_SPEC "%(cc1_cpu) " ASAN_CC1_SPEC + /* GNU as understands --32 and --64, but the native Solaris assembler requires -xarch=generic or -xarch=generic64 instead. */ #ifdef USE_GAS @@ -241,6 +244,10 @@ along with GCC; see the file COPYING3. #define LARGECOMM_SECTION_ASM_OP "\t.lbcomm\t" #endif +/* -fsanitize=address is currently only supported for 32-bit. */ +#define ASAN_REJECT_SPEC \ + DEF_ARCH64_SPEC("%e:-fsanitize=address is not supported in this configuration") + #define USE_IX86_FRAME_POINTER 1 #define USE_X86_64_FRAME_POINTER 1 diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h --- a/gcc/config/sol2.h +++ b/gcc/config/sol2.h @@ -138,6 +138,9 @@ along with GCC; see the file COPYING3. #define DEF_ARCH64_SPEC(__str) "%{!m32:" __str "}" #endif +/* Solaris needs -fasynchronous-unwind-tables to generate unwind info. */ +#define ASAN_CC1_SPEC "%{%:sanitize(address):-fasynchronous-unwind-tables}" + /* It's safe to pass -s always, even if -g is not used. Those options are handled by both Sun as and GNU as. */ #define ASM_SPEC_BASE \ @@ -231,6 +234,36 @@ along with GCC; see the file COPYING3. #define ENDFILE_VTV_SPEC "" #endif /* !ENABLE_VTABLE_VERIFY */ +/* Link -lasan early on the command line. For -static-libasan, don't link + it for -shared link, the executable should be compiled with -static-libasan + in that case, and for executable link with --{,no-}whole-archive around + it to force everything into the executable. */ + +#ifndef USE_GNU_LD +#define LD_WHOLE_ARCHIVE_OPTION "-z allextract" +#define LD_NO_WHOLE_ARCHIVE_OPTION "-z defaultextract" +#else +#define LD_WHOLE_ARCHIVE_OPTION "--whole-archive" +#define LD_NO_WHOLE_ARCHIVE_OPTION "--no-whole-archive" +#endif + +/* Allow rejecting -fsanitize=address, e.g. for specific multilibs. */ +#ifndef ASAN_REJECT_SPEC +#define ASAN_REJECT_SPEC "" +#endif + +#define LIBASAN_EARLY_SPEC ASAN_REJECT_SPEC \ + " %{!shared:libasan_preinit%O%s} \ + %{static-libasan:%{!shared: -Bstatic "\ + LD_WHOLE_ARCHIVE_OPTION " -lasan " LD_NO_WHOLE_ARCHIVE_OPTION \ + "-Bdynamic}}%{!static-libasan:-lasan}" + +/* Error out on -fsanitize=thread|leak. */ +#define LIBTSAN_EARLY_SPEC "\ + %e:-fsanitize=thread is not supported in this configuration" +#define LIBLSAN_EARLY_SPEC "\ + %e:-fsanitize=leak is not supported in this configuration" + /* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us. */ #undef STARTFILE_SPEC #ifdef HAVE_SOLARIS_CRTS diff --git a/gcc/config/sparc/sol2.h b/gcc/config/sparc/sol2.h --- a/gcc/config/sparc/sol2.h +++ b/gcc/config/sparc/sol2.h @@ -237,7 +237,7 @@ extern const char *host_detect_local_cpu %{m64:%{m32:%emay not use both -m32 and -m64}} \ %{m64:-mptr64 -mstack-bias -mno-v8plus \ %{!mcpu*:-%{!mv8plus:mcpu=v9}}} \ -" +" ASAN_CC1_SPEC #else #define CC1_SPEC "\ %{m32:%{m64:%emay not use both -m32 and -m64}} \ @@ -245,7 +245,7 @@ extern const char *host_detect_local_cpu %{!mcpu*:%{!mv8plus:-mcpu=v9}}} \ %{mv8plus:-m32 -mptr32 -mno-stack-bias \ %{!mcpu*:-mcpu=v9}} \ -" +" ASAN_CC1_SPEC #endif /* Support for a compile-time default CPU, et cetera. The rules are: @@ -322,6 +322,9 @@ extern const char *host_detect_local_cpu #define ENDFILE_ARCH_SPEC "" +/* -fsanitize=address is currently only supported for 32-bit. */ +#define ASAN_REJECT_SPEC \ + DEF_ARCH64_SPEC("%e:-fsanitize=address is not supported in this configuration") /* Register the Solaris-specific #pragma directives. */ diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c --- a/gcc/config/sparc/sparc.c +++ b/gcc/config/sparc/sparc.c @@ -674,6 +674,7 @@ static unsigned int sparc_function_arg_b const_tree); static int sparc_arg_partial_bytes (cumulative_args_t, machine_mode, tree, bool); +static unsigned HOST_WIDE_INT sparc_asan_shadow_offset (void); static void sparc_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED; static void sparc_file_end (void); static bool sparc_frame_pointer_required (void); @@ -839,6 +840,9 @@ char sparc_hard_reg_printed[8]; #undef TARGET_STRICT_ARGUMENT_NAMING #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming +#undef TARGET_ASAN_SHADOW_OFFSET +#define TARGET_ASAN_SHADOW_OFFSET sparc_asan_shadow_offset + #undef TARGET_EXPAND_BUILTIN_VA_START #define TARGET_EXPAND_BUILTIN_VA_START sparc_va_start #undef TARGET_GIMPLIFY_VA_ARG_EXPR @@ -12490,7 +12494,15 @@ sparc_init_machine_status (void) { return ggc_cleared_alloc (); } - + +/* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */ + +static unsigned HOST_WIDE_INT +sparc_asan_shadow_offset (void) +{ + return TARGET_ARCH64 ? HOST_WIDE_INT_C (0x7fff8000) : (HOST_WIDE_INT_1 << 29); +} + /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL. We need to emit DTP-relative relocations. */ diff --git a/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c b/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c --- a/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c +++ b/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c @@ -1,4 +1,5 @@ /* { dg-do run } */ +/* { dg-require-effective-target alloca } */ /* This testcase checks that allocas and VLAs inside loop are correctly unpoisoned. */ @@ -16,7 +17,7 @@ volatile int thirty_two = 32; top = &x; volatile char array[len]; assert(!((uintptr_t) array & 31L)); - alloca(len); + __builtin_alloca(len); for (int i = 0; i < thirty_two; ++i) { char array[i]; bot = array; diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt --- a/libsanitizer/configure.tgt +++ b/libsanitizer/configure.tgt @@ -43,6 +43,8 @@ case "${target}" in ;; s390*-*-linux*) ;; + sparc*-*-solaris2.11*) + ;; arm*-*-linux*) ;; mips*64*-*-linux*) @@ -68,6 +70,8 @@ case "${target}" in esac TSAN_SUPPORTED=no ;; + x86_64-*-solaris2.11* | i?86-*-solaris2.11*) + ;; *) UNSUPPORTED=1 ;;