From patchwork Tue Dec 13 08:51:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 87808 Delivered-To: patch@linaro.org Received: by 10.182.112.6 with SMTP id im6csp2089314obb; Tue, 13 Dec 2016 00:51:43 -0800 (PST) X-Received: by 10.84.217.149 with SMTP id p21mr166553352pli.121.1481619103934; Tue, 13 Dec 2016 00:51:43 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b1si47254023pgn.86.2016.12.13.00.51.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 00:51:43 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444247-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444247-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444247-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=S9qez5MgrzJ3X0n8oZ0CoyZBDuYeOmmcuGgxIRhrdNpKGA4qrU a2Vm8QJxlCvAEwHGbm8CDlGK+7OrKZgR+oR6Z/KNAU1YU2k1SAz4ru3z0kOuuVso XkPgjVgL3+NThPPjDHpwg1TRTk88MgFMMogBv6C/2OZrNq1+F8GMDvblU= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=DylIk5NFQ5AdRevL5AfHru1EBdY=; b=chRvRtbjZG4IXVe8xMj1 97N9c/0rqdnkf9XoyYyQ4gSKziVFq+Imd8uCwiiZw17ewn7Z3I/RtmXgJ37eHVIJ i+0jvCjD5ml568AWJePwbKvImHOn4Tj6Z8Ur8UHnEJQrKl925eCSC36oMGJhoKMZ rI3IS3RN4GJWi2/yAaunGYM= Received: (qmail 103183 invoked by alias); 13 Dec 2016 08:51:29 -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 103146 invoked by uid 89); 13 Dec 2016 08:51:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=D*suse.cz, U*mliska, mliska@suse.cz, mliskasusecz X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Dec 2016 08:51:16 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0CBF1AAB9; Tue, 13 Dec 2016 08:51:14 +0000 (UTC) To: GCC Patches Cc: Jakub Jelinek From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Add pretty printer for ASAN_MARK and add a helper fn Message-ID: <886f68be-375d-1585-73be-604410ee7fbc@suse.cz> Date: Tue, 13 Dec 2016 09:51:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 X-IsSubscribed: yes It would be easier to read ASAN_MARK (UNPOISON, &a, 4); instead of ASAN_MARK (2, &a, 4); Apart from that new helper function asan_mark_p is added. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin >From ff843db17ba284d2e99bab567d76d4b779f9f1d6 Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 9 Dec 2016 16:24:16 +0100 Subject: [PATCH 1/2] Add pretty printer for ASAN_MARK and add a helper fn gcc/ChangeLog: 2016-12-09 Martin Liska * asan.c (asan_mark_poison_p): Remove. (asan_mark_p): New function. (transform_statements): Use the function. (asan_expand_mark_ifn): Do not use masked enum. * asan.h (enum asan_mark_flags): Declare it via a macro. * gimple-pretty-print.c (dump_gimple_call_args): Dump first argument of ASAN_MARK. * gimplify.c (build_asan_poison_call_expr): Use new enum values. (asan_poison_variable): Likewise. gcc/testsuite/ChangeLog: 2016-12-12 Martin Liska * gcc.dg/asan/use-after-scope-goto-1.c: Update first argument of scanned pattern ASAN_MARK. * gcc.dg/asan/use-after-scope-goto-2.c: Likewise. * gcc.dg/asan/use-after-scope-switch-1.c: Likewise. * gcc.dg/asan/use-after-scope-switch-2.c: Likewise. * gcc.dg/asan/use-after-scope-switch-3.c: Likewise. --- gcc/asan.c | 28 ++++++++++------------ gcc/asan.h | 11 ++++++--- gcc/gimple-pretty-print.c | 9 +++++++ gcc/gimple.c | 2 +- gcc/gimplify.c | 4 ++-- gcc/testsuite/gcc.dg/asan/use-after-scope-goto-1.c | 6 ++--- gcc/testsuite/gcc.dg/asan/use-after-scope-goto-2.c | 2 +- .../gcc.dg/asan/use-after-scope-switch-1.c | 4 ++-- .../gcc.dg/asan/use-after-scope-switch-2.c | 12 +++++----- .../gcc.dg/asan/use-after-scope-switch-3.c | 4 ++-- 10 files changed, 47 insertions(+), 35 deletions(-) diff --git a/gcc/asan.c b/gcc/asan.c index 5af95472db9..e297784270d 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -245,15 +245,6 @@ static unsigned HOST_WIDE_INT asan_shadow_offset_value; static bool asan_shadow_offset_computed; static vec sanitized_sections; -/* Return true if STMT is ASAN_MARK poisoning internal function call. */ -static inline bool -asan_mark_poison_p (gimple *stmt) -{ - return (gimple_call_internal_p (stmt, IFN_ASAN_MARK) - && tree_to_uhwi (gimple_call_arg (stmt, 0)) == ASAN_MARK_CLOBBER); - -} - /* Set of variable declarations that are going to be guarded by use-after-scope sanitizer. */ @@ -304,6 +295,13 @@ set_sanitized_sections (const char *sections) } bool +asan_mark_p (gimple *stmt, enum asan_mark_flags flag) +{ + return (gimple_call_internal_p (stmt, IFN_ASAN_MARK) + && tree_to_uhwi (gimple_call_arg (stmt, 0)) == flag); +} + +bool asan_sanitize_stack_p (void) { return ((flag_sanitize & SANITIZE_ADDRESS) @@ -2222,7 +2220,8 @@ transform_statements (void) miss some instrumentation opportunities. Do the same for a ASAN_MARK poisoning internal function. */ if (is_gimple_call (s) - && (!nonfreeing_call_p (s) || asan_mark_poison_p (s))) + && (!nonfreeing_call_p (s) + || asan_mark_p (s, ASAN_MARK_POISON))) empty_mem_ref_hash_table (); gsi_next (&i); @@ -2777,9 +2776,8 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter) { gimple *g = gsi_stmt (*iter); location_t loc = gimple_location (g); - HOST_WIDE_INT flags = tree_to_shwi (gimple_call_arg (g, 0)); - gcc_assert (flags < ASAN_MARK_LAST); - bool is_clobber = (flags & ASAN_MARK_CLOBBER) != 0; + HOST_WIDE_INT flag = tree_to_shwi (gimple_call_arg (g, 0)); + bool is_poison = ((asan_mark_flags)flag) == ASAN_MARK_POISON; tree base = gimple_call_arg (g, 1); gcc_checking_assert (TREE_CODE (base) == ADDR_EXPR); @@ -2827,7 +2825,7 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter) if (s > size_in_bytes) last_chunk_size = ASAN_SHADOW_GRANULARITY - (s - size_in_bytes); - asan_store_shadow_bytes (iter, loc, shadow, offset, is_clobber, + asan_store_shadow_bytes (iter, loc, shadow, offset, is_poison, size, last_chunk_size); offset += size; } @@ -2840,7 +2838,7 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter) gsi_insert_before (iter, g, GSI_SAME_STMT); tree sz_arg = gimple_assign_lhs (g); - tree fun = builtin_decl_implicit (is_clobber ? BUILT_IN_ASAN_CLOBBER_N + tree fun = builtin_decl_implicit (is_poison ? BUILT_IN_ASAN_CLOBBER_N : BUILT_IN_ASAN_UNCLOBBER_N); g = gimple_build_call (fun, 2, base_addr, sz_arg); gimple_set_location (g, loc); diff --git a/gcc/asan.h b/gcc/asan.h index 9cf5904618b..355a350bfeb 100644 --- a/gcc/asan.h +++ b/gcc/asan.h @@ -75,13 +75,18 @@ enum asan_check_flags }; /* Flags for Asan check builtins. */ +#define IFN_ASAN_MARK_FLAGS DEF(POISON), DEF(UNPOISON) + enum asan_mark_flags { - ASAN_MARK_CLOBBER = 1 << 0, - ASAN_MARK_UNCLOBBER = 1 << 1, - ASAN_MARK_LAST = 1 << 2 +#define DEF(X) ASAN_MARK_##X + IFN_ASAN_MARK_FLAGS +#undef DEF }; +/* Return true if STMT is ASAN_MARK with FLAG as first argument. */ +extern bool asan_mark_p (gimple *stmt, enum asan_mark_flags flag); + /* Return the size of padding needed to insert after a protected decl of SIZE. */ diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index b5e866d36fa..1bd4cde03cf 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see #include "value-prof.h" #include "trans-mem.h" #include "cfganal.h" +#include "asan.h" #define INDENT(SPACE) \ do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0) @@ -644,6 +645,14 @@ dump_gimple_call_args (pretty_printer *buffer, gcall *gs, int flags) limit = ARRAY_SIZE (reduction_args); break; + case IFN_ASAN_MARK: +#define DEF(X) #X + static const char *const asan_mark_args[] = {IFN_ASAN_MARK_FLAGS}; +#undef DEF + enums = asan_mark_args; + limit = ARRAY_SIZE (asan_mark_args); + break; + default: break; } diff --git a/gcc/gimple.c b/gcc/gimple.c index 0a3dc72ea21..23e59c2f123 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -2631,7 +2631,7 @@ nonfreeing_call_p (gimple *call) case IFN_ABNORMAL_DISPATCHER: return true; case IFN_ASAN_MARK: - return tree_to_uhwi (gimple_call_arg (call, 0)) == ASAN_MARK_UNCLOBBER; + return tree_to_uhwi (gimple_call_arg (call, 0)) == ASAN_MARK_UNPOISON; default: if (gimple_call_flags (call) & ECF_LEAF) return true; diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 8611060aea6..ce8847a20a0 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1109,7 +1109,7 @@ build_asan_poison_call_expr (tree decl) return build_call_expr_internal_loc (UNKNOWN_LOCATION, IFN_ASAN_MARK, void_type_node, 3, build_int_cst (integer_type_node, - ASAN_MARK_CLOBBER), + ASAN_MARK_POISON), base, unit_size); } @@ -1138,7 +1138,7 @@ asan_poison_variable (tree decl, bool poison, gimple_stmt_iterator *it, if (DECL_ALIGN_UNIT (decl) <= ASAN_SHADOW_GRANULARITY) SET_DECL_ALIGN (decl, BITS_PER_UNIT * ASAN_SHADOW_GRANULARITY); - HOST_WIDE_INT flags = poison ? ASAN_MARK_CLOBBER : ASAN_MARK_UNCLOBBER; + HOST_WIDE_INT flags = poison ? ASAN_MARK_POISON : ASAN_MARK_UNPOISON; gimple *g = gimple_build_call_internal (IFN_ASAN_MARK, 3, diff --git a/gcc/testsuite/gcc.dg/asan/use-after-scope-goto-1.c b/gcc/testsuite/gcc.dg/asan/use-after-scope-goto-1.c index c47a5e8db02..c1538e4e29b 100644 --- a/gcc/testsuite/gcc.dg/asan/use-after-scope-goto-1.c +++ b/gcc/testsuite/gcc.dg/asan/use-after-scope-goto-1.c @@ -42,6 +42,6 @@ int main(int argc, char **argv) return 0; } -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, 4\\);" 2 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &c, 4\\);" 2 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &e, 4\\);" 2 "asan0" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, 4\\);" 2 "asan0" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &c, 4\\);" 2 "asan0" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &e, 4\\);" 2 "asan0" } } */ diff --git a/gcc/testsuite/gcc.dg/asan/use-after-scope-goto-2.c b/gcc/testsuite/gcc.dg/asan/use-after-scope-goto-2.c index 73ef4e0eb1e..7c396141d9b 100644 --- a/gcc/testsuite/gcc.dg/asan/use-after-scope-goto-2.c +++ b/gcc/testsuite/gcc.dg/asan/use-after-scope-goto-2.c @@ -22,4 +22,4 @@ int main(int argc, char **argv) return 0; } -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, 4\\);" 1 "asan0" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, 4\\);" 1 "asan0" } } */ diff --git a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-1.c b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-1.c index a8342686d4e..d4d753936bb 100644 --- a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-1.c +++ b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-1.c @@ -21,5 +21,5 @@ main (int argc, char **argv) return 0; } -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, \[0-9\]\\);" 2 "gimple" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &a, \[0-9\]\\);" 1 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, \[0-9\]\\);" 2 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &a, \[0-9\]\\);" 1 "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-2.c b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-2.c index 8aeca5a3b7a..5a5ea375e18 100644 --- a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-2.c +++ b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-2.c @@ -25,9 +25,9 @@ main (int argc, char **argv) return 0; } -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, \[0-9\]\\);" 2 "gimple" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &b, \[0-9\]\\);" 2 "gimple" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &c, \[0-9\]\\);" 2 "gimple" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &a, \[0-9\]\\);" 1 "gimple" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &b, \[0-9\]\\);" 1 "gimple" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &c, \[0-9\]\\);" 1 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, \[0-9\]\\);" 2 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &b, \[0-9\]\\);" 2 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &c, \[0-9\]\\);" 2 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &a, \[0-9\]\\);" 1 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &b, \[0-9\]\\);" 1 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &c, \[0-9\]\\);" 1 "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-3.c b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-3.c index 828cb7c3b2a..f361591351b 100644 --- a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-3.c +++ b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-3.c @@ -32,5 +32,5 @@ main (int argc, char **argv) return 0; } -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, \[0-9\]\\);" 4 "gimple" } } */ -/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &a, \[0-9\]\\);" 1 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, \[0-9\]\\);" 4 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &a, \[0-9\]\\);" 1 "gimple" } } */ -- 2.11.0