From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32203 invoked by alias); 3 Oct 2013 15:01:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 32194 invoked by uid 89); 3 Oct 2013 15:01:59 -0000 Received: from eu1sys200aog113.obsmtp.com (HELO eu1sys200aog113.obsmtp.com) (207.126.144.135) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) SMTP; Thu, 03 Oct 2013 15:01:59 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.3.2 X-HELO: eu1sys200aog113.obsmtp.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob113.postini.com ([207.126.147.11]) with SMTP ID DSNKUk2G4tjlZS+cVb5uoyWkvnbMjHhQjJZj@postini.com; Thu, 03 Oct 2013 15:01:58 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4F0FC1D7 for ; Thu, 3 Oct 2013 15:01:31 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas2.st.com [10.75.90.16]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1C24254E0 for ; Thu, 3 Oct 2013 14:48:44 +0000 (GMT) Received: from [164.129.122.168] (164.129.122.168) by webmail-eu.st.com (10.75.90.13) with Microsoft SMTP Server (TLS) id 8.3.297.1; Thu, 3 Oct 2013 17:01:52 +0200 Message-ID: <524D86DF.2070306@st.com> Date: Thu, 03 Oct 2013 15:01:00 -0000 From: Laurent Alfonsi User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" Subject: [PATCH] fix PR58602 (.gcno files not truncated at gcov_close) Content-Type: multipart/mixed; boundary="------------060808020009030709020101" X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00254.txt.bz2 --------------060808020009030709020101 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 737 Hi All, We have discovered a bug on gcno file generation registred as PR58602. When the .gcno graph file is opened for generating the coverage graph information, the mode used is w+ as this code is shared with updating tools such as libgcov. Thus, when GCC outputs .gcno files, it may leave garbage at the end of the file if the file already exists when opening it. This has been trackeddown from a kernel issue on lcov: http://sourceforge.net/p/ltp/mailman/message/31141937/ This following patch fixes the function gcov_open() such that the .gcno file is opened with truncation when gcc asks for creating a new file (mode<0). Regression test x86-64 are ok with this patch. Is it ok to commit in trunk ? Thanks Laurent --------------060808020009030709020101 Content-Type: text/x-patch; name="pr58602.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pr58602.patch" Content-length: 694 diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c index 5a21c1f..342877d 100644 --- a/gcc/gcov-io.c +++ b/gcc/gcov-io.c @@ -94,9 +94,15 @@ gcov_open (const char *name, int mode) /* pass mode (ignored) for compatibility */ fd = open (name, O_RDONLY, S_IRUSR | S_IWUSR); } - else + else if (mode < 0) + { + /* Write mode - acquire a write-lock. */ + s_flock.l_type = F_WRLCK; + fd = open (name, O_RDWR | O_CREAT | O_TRUNC, 0666); + } + else /* mode == 0 */ { - /* Write mode - acquire a write-lock. */ + /* Read-Write mode - acquire a write-lock. */ s_flock.l_type = F_WRLCK; fd = open (name, O_RDWR | O_CREAT, 0666); } --------------060808020009030709020101--