From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78149 invoked by alias); 21 May 2016 16:37:10 -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 77543 invoked by uid 89); 21 May 2016 16:37:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=2016-05-21 X-HELO: one.firstfloor.org Received: from one.firstfloor.org (HELO one.firstfloor.org) (193.170.194.197) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 21 May 2016 16:37:00 +0000 Received: from firstfloor.org (63-225-80-217.ptld.qwest.net [63.225.80.217]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by one.firstfloor.org (Postfix) with ESMTPSA id 38C3E8717D; Sat, 21 May 2016 18:36:54 +0200 (CEST) Received: by firstfloor.org (Postfix, from userid 1000) id BC949A1D8B; Sat, 21 May 2016 09:36:32 -0700 (PDT) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH 2/5] Don't cause ICEs when auto profile file is not found with checking Date: Sat, 21 May 2016 16:37:00 -0000 Message-Id: <1463848586-19259-3-git-send-email-andi@firstfloor.org> In-Reply-To: <1463848586-19259-2-git-send-email-andi@firstfloor.org> References: <1463848586-19259-1-git-send-email-andi@firstfloor.org> <1463848586-19259-2-git-send-email-andi@firstfloor.org> X-SW-Source: 2016-05/txt/msg01717.txt.bz2 From: Andi Kleen Currently, on a checking enabled compiler when -fauto-profile does not find the profile feedback file it errors out with assertation failures. Add proper errors for this case. gcc/: 2016-05-21 Andi Kleen * auto-profile.c (read_profile): Replace asserts with errors when file does not exist. * gcov-io.c (gcov_read_words): Dito. --- gcc/auto-profile.c | 32 +++++++++++++++++++++++++------- gcc/gcov-io.c | 4 +++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c index cd82ab4..9e3fd02 100644 --- a/gcc/auto-profile.c +++ b/gcc/auto-profile.c @@ -884,16 +884,25 @@ static void read_profile (void) { if (gcov_open (auto_profile_file, 1) == 0) - error ("Cannot open profile file %s.", auto_profile_file); + { + error ("Cannot open profile file %s.", auto_profile_file); + return; + } if (gcov_read_unsigned () != GCOV_DATA_MAGIC) - error ("AutoFDO profile magic number does not mathch."); + { + error ("AutoFDO profile magic number does not mathch."); + return; + } /* Skip the version number. */ unsigned version = gcov_read_unsigned (); if (version != AUTO_PROFILE_VERSION) - error ("AutoFDO profile version %u does match %u.", - version, AUTO_PROFILE_VERSION); + { + error ("AutoFDO profile version %u does match %u.", + version, AUTO_PROFILE_VERSION); + return; + } /* Skip the empty integer. */ gcov_read_unsigned (); @@ -901,19 +910,28 @@ read_profile (void) /* string_table. */ afdo_string_table = new string_table (); if (!afdo_string_table->read()) - error ("Cannot read string table from %s.", auto_profile_file); + { + error ("Cannot read string table from %s.", auto_profile_file); + return; + } /* autofdo_source_profile. */ afdo_source_profile = autofdo_source_profile::create (); if (afdo_source_profile == NULL) - error ("Cannot read function profile from %s.", auto_profile_file); + { + error ("Cannot read function profile from %s.", auto_profile_file); + return; + } /* autofdo_module_profile. */ fake_read_autofdo_module_profile (); /* Read in the working set. */ if (gcov_read_unsigned () != GCOV_TAG_AFDO_WORKING_SET) - error ("Cannot read working set from %s.", auto_profile_file); + { + error ("Cannot read working set from %s.", auto_profile_file); + return; + } /* Skip the length of the section. */ gcov_read_unsigned (); diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c index 17fcae0..95ead22 100644 --- a/gcc/gcov-io.c +++ b/gcc/gcov-io.c @@ -493,7 +493,9 @@ gcov_read_words (unsigned words) const gcov_unsigned_t *result; unsigned excess = gcov_var.length - gcov_var.offset; - gcov_nonruntime_assert (gcov_var.mode > 0); + if (gcov_var.mode <= 0) + return NULL; + if (excess < words) { gcov_var.start += gcov_var.offset; -- 2.8.2