From patchwork Wed Sep 10 17:24:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teresa Johnson X-Patchwork-Id: 387907 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C6371400DD for ; Thu, 11 Sep 2014 03:25:03 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=Ee1hu6VCZw7NApH+F/iLqdKJymNQGuKcGtW5TQZ0WE7igG aG9ElqyaP4d5dCB01/H/BX7ewAXwTrTI3dlceeO6DTpmtZvViNkOzo5WCuG4RQa/ xEoCN9cdTynQDxH0yKzkdIFosVLhh8Z0Qpu9ceOKcEoMb/BPOFe3geaomwruk= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=CfWtYyM2ShMKgGnjSqMgPDT55fQ=; b=e8CHBxOpUjj6q85DXGui Hs/29mOQ9QxaDfZsfo41zn+5yDa8QFEp/o6g27C6RfVw8mkaV3DkfSQ4kn0YSHXg EWivl59C5ROfsDb2PJ8IheKfz+i4xx39bYMkYp+V3PFKSQLCBIvqoWAx/7thG702 B+wejNS3YRGiLuVDM96i5DM= Received: (qmail 12898 invoked by alias); 10 Sep 2014 17:24:33 -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 12840 invoked by uid 89); 10 Sep 2014 17:24:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qg0-f48.google.com Received: from mail-qg0-f48.google.com (HELO mail-qg0-f48.google.com) (209.85.192.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 10 Sep 2014 17:24:31 +0000 Received: by mail-qg0-f48.google.com with SMTP id q108so2297201qgd.7 for ; Wed, 10 Sep 2014 10:24:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=WVHo5TXEuWvYlNW5FdgOE5jl/xdbww0T9BCoQv2lUJU=; b=V04AN5OuSfpiYJLrDK9NZEEWYVfhXIkbriyQU8Zj1Gh80ITon1K/F947Hi3Bc1svUd wSFaSaoQScNXOCncpZS/L50LHRQZgMYVFd9//OjpQ7qdfSrmnOkclDUhHzrPMAHDgDmP uV9aaA1vmclLx5k+se5BBKxJ/bHT3utjdD7I4YLDzRGzP0jo4gh/R6rEV76IlK/p6+Dy C+SwdeTCI0dnaP7dDrMLkGpUh1bg79c45W8IMFo2QyiEtjELo6rnSkeXGwMjVVd7ibMG NrzLIImn4KpFpfPnNgacYQLdEeoQqKcjG811/jQdYGKCg5L0AcVCPf3OilmCd0I/7pKV IaTQ== X-Gm-Message-State: ALoCoQmGWROFmB9P/69uKXs8gmyno7pNS3/9OOlk4SxMvOneXPFXnS9AdEBdtQneQxgG24H0/W4s MIME-Version: 1.0 X-Received: by 10.229.131.5 with SMTP id v5mr61816557qcs.21.1410369868729; Wed, 10 Sep 2014 10:24:28 -0700 (PDT) Received: by 10.229.126.201 with HTTP; Wed, 10 Sep 2014 10:24:28 -0700 (PDT) Date: Wed, 10 Sep 2014 10:24:28 -0700 Message-ID: Subject: [GOOGLE] Fix gcda build info support From: Teresa Johnson To: "gcc-patches@gcc.gnu.org" , David Li X-IsSubscribed: yes While porting recent support for a build info section in the gcda from google/4_8 to 4_9 and doing manual testing, I discovered that it does not interact well with the COMDAT fixup handling. This patch fixes the issue, and adds a test case that exposes the problem without the fix. Here is the google/4_8 patch - I plan to commit there first then port it along with the original build info patch to 4_9. Passes regression tests - ok for google branches? Thanks, Teresa 2014-09-10 Teresa Johnson libgcc: * libgcov-driver.c (gcov_scan_to_function_data): Rename from gcov_scan_summary_end, scan past BUILD_INFO section. (gcov_dump_module_info): Rename gcov_scan_summary_end to gcov_scan_to_function_data. gcc/testsuite: * g++.dg/tree-prof/lipo/buildinfo.txt: Input for -fprofile-generate-buildinfo option. * g++.dg/tree-prof/lipo/comdat_fixup_0.C: New test. * g++.dg/tree-prof/lipo/comdat_fixup_1.C: Ditto. * g++.dg/tree-prof/lipo/comdat_fixup_2.C: Ditto. * g++.dg/tree-prof/lipo/comdat_fixup.h: Ditto. * lib/profopt.exp: Declare srcdir for use in test options. Index: libgcc/libgcov-driver.c =================================================================== --- libgcc/libgcov-driver.c (revision 214976) +++ libgcc/libgcov-driver.c (working copy) @@ -428,13 +428,15 @@ struct gcov_filename_aux{ #include "libgcov-driver-system.c" /* Scan through the current open gcda file corresponding to GI_PTR - to locate the end position of the last summary, returned in - SUMMARY_END_POS_P. Return 0 on success, -1 on error. */ + to locate the end position just before function data should be rewritten, + returned in SUMMARY_END_POS_P. E.g. scan past the last summary and other + sections that won't be rewritten, like the build info. Return 0 on success, + -1 on error. */ static int -gcov_scan_summary_end (struct gcov_info *gi_ptr, - gcov_position_t *summary_end_pos_p) +gcov_scan_to_function_data (struct gcov_info *gi_ptr, + gcov_position_t *summary_end_pos_p) { - gcov_unsigned_t tag, version, stamp; + gcov_unsigned_t tag, version, stamp, i, length; tag = gcov_read_unsigned (); if (tag != GCOV_DATA_MAGIC) { @@ -467,6 +469,28 @@ static int return -1; } + /* If there is a build info section, scan past it as well. */ + if (tag == GCOV_TAG_BUILD_INFO) + { + length = gcov_read_unsigned (); + gcov_unsigned_t num_strings = 0; + char **build_info_strings = gcov_read_build_info (length, &num_strings); + if (!build_info_strings) + { + gcov_error ("profiling:%s:Error reading build info\n", gi_filename); + return -1; + } + + for (i = 0; i < num_strings; i++) + free (build_info_strings[i]); + free (build_info_strings); + + *summary_end_pos_p = gcov_position (); + tag = gcov_read_unsigned (); + } + /* The next section should be the function counters. */ + gcc_assert (tag == GCOV_TAG_FUNCTION); + return 0; } @@ -1031,10 +1055,10 @@ gcov_dump_module_info (struct gcov_filename_aux *g if (changed) { - /* Scan file to find the end of the summary section, which is + /* Scan file to find the start of the function section, which is where we will start re-writing the counters. */ gcov_position_t summary_end_pos; - if (gcov_scan_summary_end (gi_ptr, &summary_end_pos) == -1) + if (gcov_scan_to_function_data (gi_ptr, &summary_end_pos) == -1) gcov_error ("profiling:%s:Error scanning summaries\n", gi_filename); else Index: gcc/testsuite/g++.dg/tree-prof/lipo/buildinfo.txt =================================================================== --- gcc/testsuite/g++.dg/tree-prof/lipo/buildinfo.txt (revision 0) +++ gcc/testsuite/g++.dg/tree-prof/lipo/buildinfo.txt (revision 0) @@ -0,0 +1 @@ +Test -fprofile-generate-buildinfo option Index: gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_0.C =================================================================== --- gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_0.C (revision 0) +++ gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_0.C (revision 0) @@ -0,0 +1,9 @@ +/* { dg-options "-O2 -fno-inline -fprofile-generate-buildinfo=$srcdir/g++.dg/tree-prof/lipo/buildinfo.txt" } */ +#include + +extern int foo1(int x); +extern int foo2(int x); +int main() +{ + printf ("Result = %d\n", foo1(1) + foo2(1)); +} Index: gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_1.C =================================================================== --- gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_1.C (revision 0) +++ gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_1.C (revision 0) @@ -0,0 +1,7 @@ +/* { dg-options "-O2 -fno-inline" } */ +#include "comdat_fixup.h" +int foo1(int x) +{ + Foo f; + return f.foo(x); +} Index: gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_2.C =================================================================== --- gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_2.C (revision 0) +++ gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup_2.C (revision 0) @@ -0,0 +1,7 @@ +/* { dg-options "-O2 -fno-inline" } */ +#include "comdat_fixup.h" +int foo2(int x) +{ + Foo f; + return f.foo(x); +} Index: gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup.h =================================================================== --- gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup.h (revision 0) +++ gcc/testsuite/g++.dg/tree-prof/lipo/comdat_fixup.h (revision 0) @@ -0,0 +1,5 @@ +class Foo +{ + public: + int foo(int x) { return x; } +}; Index: gcc/testsuite/lib/profopt.exp =================================================================== --- gcc/testsuite/lib/profopt.exp (revision 214976) +++ gcc/testsuite/lib/profopt.exp (working copy) @@ -169,6 +169,8 @@ proc profopt-final-code { which final_code name } # SRC is the full pathname of the testcase. # proc profopt-get-options { src } { + global srcdir + # dg-options sets a variable called dg-extra-tool-flags. set dg-extra-tool-flags ""