From patchwork Tue Oct 29 12:13:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 286822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id ABFC12C0342 for ; Tue, 29 Oct 2013 23:14:11 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=t6+Yigb7uF8nHiuJ0 H2VfhKws64s9KgzUd5xxI9zXkwix6kheSs+p1Rmo4Yr8W0W4z3byN8SPJA1r+Tkl GLWQBfHAY4wv0oBaKGdrtr2zDEq9D/lLDNTfMUy6iTbrwgyMaiLklxN/lnRNwOeB C7SldClUAl5GK0RjKKrCVCJlmc= 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:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=JXpnadtQgo31CVCIogbalRx 4Nco=; b=lkaXxSOpLgaerHdv/tYToFipLl5QJ042Nu1xl/n2swoA95NbOeeSysU J8JLTjYC6MpJC5KMqAj5S9nVhpI+GerSICc4Ng9bMsrbKYIsliXWFX/qeB3QhzDz nsgMA9SSOwdFU/hPnJVfKyUL5PZlZ7U7WVHnLoKGu+sOCydCfUBs= Received: (qmail 10155 invoked by alias); 29 Oct 2013 12:14:04 -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 10119 invoked by uid 89); 29 Oct 2013 12:14:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Oct 2013 12:14:00 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9TCDwuY001685 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 29 Oct 2013 08:13:59 -0400 Received: from tucnak.zalov.cz (vpn1-7-226.ams2.redhat.com [10.36.7.226]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r9TCDuDC007424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 29 Oct 2013 08:13:58 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id r9TCDuG0019246; Tue, 29 Oct 2013 13:13:56 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id r9TCDtcb019245; Tue, 29 Oct 2013 13:13:55 +0100 Date: Tue, 29 Oct 2013 13:13:55 +0100 From: Jakub Jelinek To: Konstantin Serebryany Cc: GCC Patches , Dodji Seketeli , Dmitry Vyukov Subject: Re: libsanitizer merge from upstream r191666 Message-ID: <20131029121355.GY30970@tucnak.zalov.cz> Reply-To: Jakub Jelinek References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes > On Wed, Oct 2, 2013 at 12:51 PM, Konstantin Serebryany > > 2013-10-XX Kostya Serebryany > > > > * g++.dg/asan/asan_test.cc: Update the test > > to match the fresh asan run-time. > > * c-c++-common/asan/stack-overflow-1.c: Ditto. > > > > =========== gcc/ChangeLog > > > > 2013-10-XX Kostya Serebryany > > > > * asan.c: Update to match the changed asan API. > > (asan_emit_stack_protection): update the string stored in the > > stack red zone to match new API. Store the PC of the current > > function in the red zone. > > (asan_global_struct): update the __asan_global definition to match > > the new API. > > (asan_add_global): Ditto. > > * sanitizer.def: rename __asan_init_v1 to __asan_init_v3 The "Update to match the changed asan API." should either be dropped, or come on a line before the * asan.c (asan_emit_stack_protection): line. All descriptions should start with capital letters, end with ., two spaces after . if followed by another sentence. Besides that, here is (completely untested) attempt to give you the pc of the first instruction of the function and two minor changes (pp_string (something, "") is useless and in two spots I've noticed you didn't add space before ( in function call). Finally, if the new libasan is ABI incompatible with the old one, which seems it is, then libsanitizer/asan/libtool-version (and perhaps also libsanitizer/tsan/libtool-version, haven't looked if that one is ABI compatible or not) needs to be bumped (to 1:0:0 ?). Jakub --- gcc/asan.c.jj 2013-10-29 11:58:30.000000000 +0100 +++ gcc/asan.c 2013-10-29 13:04:07.709667677 +0100 @@ -921,6 +921,15 @@ asan_clear_shadow (rtx shadow_mem, HOST_ add_int_reg_note (jump, REG_BR_PROB, REG_BR_PROB_BASE * 80 / 100); } +void +asan_function_start (void) +{ + section *fnsec = function_section (current_function_decl); + switch_to_section (fnsec); + ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LASANPC", + current_function_funcdef_no); +} + /* Insert code to protect stack vars. The prologue sequence should be emitted directly, epilogue sequence returned. BASE is the register holding the stack base, against which OFFSETS array offsets are relative to, OFFSETS @@ -936,12 +945,13 @@ asan_emit_stack_protection (rtx base, HO int length) { rtx shadow_base, shadow_mem, ret, mem; + char buf[30]; unsigned char shadow_bytes[4]; HOST_WIDE_INT base_offset = offsets[length - 1], offset, prev_offset; HOST_WIDE_INT last_offset, last_size; int l; unsigned char cur_shadow_byte = ASAN_STACK_MAGIC_LEFT; - tree str_cst; + tree str_cst, decl; if (shadow_ptr_types[0] == NULL_TREE) asan_init_shadow_ptr_types (); @@ -949,7 +959,6 @@ asan_emit_stack_protection (rtx base, HO /* First of all, prepare the description string. */ pretty_printer asan_pp; - pp_string (&asan_pp, ""); pp_decimal_int (&asan_pp, length / 2 - 1); pp_space (&asan_pp); for (l = length - 2; l; l -= 2) @@ -980,7 +989,17 @@ asan_emit_stack_protection (rtx base, HO mem = adjust_address (mem, VOIDmode, GET_MODE_SIZE (ptr_mode)); emit_move_insn (mem, expand_normal (str_cst)); mem = adjust_address (mem, VOIDmode, GET_MODE_SIZE (ptr_mode)); - emit_move_insn (mem, expand_normal (str_cst)); // FIXME: should be cur_pc. + ASM_GENERATE_INTERNAL_LABEL (buf, "LASANPC", current_function_funcdef_no); + decl = build_decl (DECL_SOURCE_LOCATION (current_function_decl), + VAR_DECL, get_identifier (buf), char_type_node); + TREE_ADDRESSABLE (decl) = 1; + TREE_READONLY (decl) = 1; + DECL_ARTIFICIAL (decl) = 1; + DECL_IGNORED_P (decl) = 1; + TREE_STATIC (decl) = 1; + TREE_PUBLIC (decl) = 0; + TREE_USED (decl) = 1; + emit_move_insn (mem, expand_normal (build_fold_addr_expr (decl))); shadow_base = expand_binop (Pmode, lshr_optab, base, GEN_INT (ASAN_SHADOW_SHIFT), NULL_RTX, 1, OPTAB_DIRECT); @@ -1979,8 +1998,8 @@ asan_add_global (tree decl, tree type, v pp_string (&asan_pp, ""); str_cst = asan_pp_string (&asan_pp); - pp_string(&module_name_pp, main_input_filename); - module_name_cst = asan_pp_string(&module_name_pp); + pp_string (&module_name_pp, main_input_filename); + module_name_cst = asan_pp_string (&module_name_pp); if (asan_needs_local_alias (decl)) { --- gcc/asan.h.jj 2013-01-11 09:02:50.000000000 +0100 +++ gcc/asan.h 2013-10-29 12:37:54.190798947 +0100 @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. #ifndef TREE_ASAN #define TREE_ASAN +extern void asan_function_start (void); extern void asan_finish_file (void); extern rtx asan_emit_stack_protection (rtx, HOST_WIDE_INT *, tree *, int); extern bool asan_protect_global (tree); --- gcc/final.c.jj 2013-10-23 14:43:12.000000000 +0200 +++ gcc/final.c 2013-10-29 12:49:33.609176613 +0100 @@ -78,6 +78,7 @@ along with GCC; see the file COPYING3. #include "cfgloop.h" #include "params.h" #include "tree-pretty-print.h" /* for dump_function_header */ +#include "asan.h" #ifdef XCOFF_DEBUGGING_INFO #include "xcoffout.h" /* Needed for external data @@ -1738,6 +1739,9 @@ final_start_function (rtx first, FILE *f high_block_linenum = high_function_linenum = last_linenum; + if (flag_sanitize & SANITIZE_ADDRESS) + asan_function_start (); + if (!DECL_IGNORED_P (current_function_decl)) debug_hooks->begin_prologue (last_linenum, last_filename);