From patchwork Sat Jun 23 18:00:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 166774 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]) by ozlabs.org (Postfix) with SMTP id 4E8AAB6FAC for ; Sun, 24 Jun 2012 04:00:51 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1341079252; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=m9ifbRt9+kbB759IRsqh7obG9Us=; b=Nbmvg+2APF6zf0B NrkfT5hodGymPciKTJ10/88ZDg2c2T1frS32JUSljlV5T7MlHylonD29/+AEUoiz NBNmU1W0BTDpjnIHG3qqPO5Jzrt5gX8jfKyoHNQrlppJL9owUVhQgAMI49N4Nuhn lcpZ9v9jtPxkdjpWvNxMMEsGWar8= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ErmymxJU0BjS6mJBO8IBhCy5QK60tT3tLvHm52F4CzNzDOfCYHrrCakXEyEbL+ a0Y2DRV0wUeB/pt1Kj0+WQNUl5fkkEziydEwG/jIFYZ96w/FQUl5Aqu+MMJVT4XL 3uBIYGpD0xLm5dsoKfrSaK/Up/DmiWTzWHphR64/asw7w=; Received: (qmail 24762 invoked by alias); 23 Jun 2012 18:00:47 -0000 Received: (qmail 24752 invoked by uid 22791); 23 Jun 2012 18:00:46 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_CP, TW_HK X-Spam-Check-By: sourceware.org Received: from mail-ey0-f175.google.com (HELO mail-ey0-f175.google.com) (209.85.215.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 23 Jun 2012 18:00:33 +0000 Received: by eaal1 with SMTP id l1so894901eaa.20 for ; Sat, 23 Jun 2012 11:00:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:subject :content-type:x-gm-message-state; bh=vc5lcTF4JzBeo90JbyURtZrmS7+zem4VsVuZh+qLGvI=; b=PwUtPKTMo7RSs7LlQsKDyUY1Mh2KhyljYb8HLxBk1dkwyadwOdxntXCdQJ7hSBNWxR 2xK9gpxXIWouJ21kfVbqqgddXRcSHwl7psZYnprFAKBypHMw+LE/a0v80WkVhFxpu+aL P3nqbhM9kQvpGBCo7A41pfBL3J0drkh3hboPUYQR7M7lX/8mPY+Ad4CHFZ9dJYCRTsfH VVfuvnjz5xgIvASJLhpDNYesZDEDHJPKG0bhW6ggOMCvPb/fJ75/4agKRlndQL9Ot2T1 so7W2qOXV2ARE4G1qgp7Eydd2FzDx7rrKiBVm3sm7mHetsildfFQfz1FFJTc8GhrPpjn Ri0g== Received: by 10.14.95.205 with SMTP id p53mr1223191eef.89.1340474431444; Sat, 23 Jun 2012 11:00:31 -0700 (PDT) Received: by 10.14.95.205 with SMTP id p53mr1223183eef.89.1340474431249; Sat, 23 Jun 2012 11:00:31 -0700 (PDT) Received: from [192.168.44.108] (5ac3c8c3.bb.sky.com. [90.195.200.195]) by mx.google.com with ESMTPS id z5sm123133159eem.3.2012.06.23.11.00.29 (version=SSLv3 cipher=OTHER); Sat, 23 Jun 2012 11:00:30 -0700 (PDT) Message-ID: <4FE6043C.6020608@acm.org> Date: Sat, 23 Jun 2012 19:00:28 +0100 From: Nathan Sidwell User-Agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: GCC Patches , Xinliang David Li Subject: Coverage unlinking X-Gm-Message-State: ALoCoQkeBU+2LzN8ANA0CxbYSg7hvge7x2pEVnzqjy26n1zZM1UerkudspHff+DBrlj6rFHhWnedmtIj7jhaRaK3qNlNItWYMp82i5WpQwxCCTleAZ45h2vu+8yIHEr0y/kW/MPypxLPmiUgRhW2wlkkMFgAhau/sfPM/yhlsMaN2dXRM1W7QX4= X-IsSubscribed: yes 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 This patch changes the coverage unlinking to be less aggressive. As David pointed out, when experimenting with random optimization options along side -fuse-coverage and -frandom-seed, it is inconvenient for gcc to remove the coverage data file. The reason it was doing so, is because -frandom-seed prevents a unique stamp being placed in the coverage data to distinguish execution of the newly optimized program from execution of the older incarnation of it. libgcov would get confused and give errors about mismatched function checksums. This patch tweaks things. With -fuse-coverage we read in the coverage data file and its stamp. We can feed that stamp into the stamp to be used for the output coverage data, and hence effectively distinguish generations of coverage data even when -frandom-seed prevents randomness. We also don't need to delete the data file if we're not producing coverage data for the new compilation. Manual testing shows this patch is preventing deletion of the data file in the circumstances I understand David's using. David, care to try this patch out to see if it resolves your use case? The changes to tree.c merely extend the crc32 code to allow it to generate a crc from a 32-bit unsigned, in addition to the byte variant already present. testing on i686-pc-linux-gnu shows no regressions. nathan 2012-06-23 Nathan Sidwell * coverage.c (bbg_file_stamp): New. (read_counts_file): Merge incoming stamp with bbg_file_stamp. (build_info): Write bbg_file_stamp. (coverage_init): Initialize bbg_file_stamp. Read counts file before writing graph header. (coverage_finish): Don't unlink the data file if we can generate a unique file stamp. * tree.h (crc32_unsigned): Declare. * tree.c (crc32_unsigned_bits): New, broken out of ... (crc32_byte): ... here. Use it. (crc32_unsigned): New. Index: coverage.c =================================================================== --- coverage.c (revision 188900) +++ coverage.c (working copy) @@ -101,6 +101,9 @@ static GTY(()) tree gcov_fn_info_ptr_typ we're not writing to the notes file. */ static char *bbg_file_name; +/* File stamp for graph file. */ +static unsigned bbg_file_stamp; + /* Name of the count data file. */ static char *da_file_name; @@ -205,8 +208,9 @@ read_counts_file (void) return; } - /* Read and discard the stamp. */ - gcov_read_unsigned (); + /* Read the stamp, used for creating a generation count. */ + tag = gcov_read_unsigned (); + bbg_file_stamp = crc32_unsigned (bbg_file_stamp, tag); counts_hash = htab_create (10, htab_counts_entry_hash, htab_counts_entry_eq, @@ -905,7 +909,7 @@ build_info (tree info_type, tree fn_ary) /* stamp */ CONSTRUCTOR_APPEND_ELT (v1, info_fields, build_int_cstu (TREE_TYPE (info_fields), - local_tick)); + bbg_file_stamp)); info_fields = DECL_CHAIN (info_fields); /* Filename */ @@ -1101,6 +1105,11 @@ coverage_init (const char *filename) memcpy (da_file_name + prefix_len, filename, len); strcpy (da_file_name + prefix_len + len, GCOV_DATA_SUFFIX); + bbg_file_stamp = local_tick; + + if (flag_branch_probabilities) + read_counts_file (); + /* Name of bbg file. */ if (flag_test_coverage && !flag_compare_debug) { @@ -1117,12 +1126,9 @@ coverage_init (const char *filename) { gcov_write_unsigned (GCOV_NOTE_MAGIC); gcov_write_unsigned (GCOV_VERSION); - gcov_write_unsigned (local_tick); + gcov_write_unsigned (bbg_file_stamp); } } - - if (flag_branch_probabilities) - read_counts_file (); } /* Performs file-level cleanup. Close graph file, generate coverage @@ -1133,10 +1139,11 @@ coverage_finish (void) { if (bbg_file_name && gcov_close ()) unlink (bbg_file_name); - - if (!local_tick || local_tick == (unsigned)-1) - /* Only remove the da file, if we cannot stamp it. If we can - stamp it, libgcov will DTRT. */ + + if (!flag_branch_probabilities && flag_test_coverage + && (!local_tick || local_tick == (unsigned)-1)) + /* Only remove the da file, if we're emitting coverage code and + cannot uniquely stamp it. If we can stamp it, libgcov will DTRT. */ unlink (da_file_name); if (coverage_obj_init ()) Index: tree.c =================================================================== --- tree.c (revision 188900) +++ tree.c (working copy) @@ -8734,23 +8734,37 @@ dump_tree_statistics (void) /* Generate a crc32 of a byte. */ -unsigned -crc32_byte (unsigned chksum, char byte) +static unsigned +crc32_unsigned_bits (unsigned chksum, unsigned value, unsigned bits) { - unsigned value = (unsigned) byte << 24; - unsigned ix; + unsigned ix; - for (ix = 8; ix--; value <<= 1) - { - unsigned feedback; - - feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0; - chksum <<= 1; - chksum ^= feedback; - } + for (ix = bits; ix--; value <<= 1) + { + unsigned feedback; + + feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0; + chksum <<= 1; + chksum ^= feedback; + } return chksum; } +/* Generate a crc32 of a 32-bit unsigned. */ + +unsigned +crc32_unsigned (unsigned chksum, unsigned value) +{ + return crc32_unsigned_bits (chksum, value, 32); +} + +/* Generate a crc32 of a byte. */ + +unsigned +crc32_byte (unsigned chksum, char byte) +{ + return crc32_unsigned_bits (chksum, (unsigned) byte << 24, 8); +} /* Generate a crc32 of a string. */ Index: tree.h =================================================================== --- tree.h (revision 188900) +++ tree.h (working copy) @@ -5168,6 +5168,7 @@ inlined_function_outer_scope_p (const_tr /* In tree.c */ extern unsigned crc32_string (unsigned, const char *); extern unsigned crc32_byte (unsigned, char); +extern unsigned crc32_unsigned (unsigned, unsigned); extern void clean_symbol_name (char *); extern tree get_file_function_name (const char *); extern tree get_callee_fndecl (const_tree);