From patchwork Fri Apr 21 18:36:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 753526 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 3w8kwf6nKNz9s2x for ; Sat, 22 Apr 2017 04:36:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="x3+v5FwM"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type:mime-version; q=dns; s= default; b=AE5w0B1ALjh8UjJ3Ehp/7tarJMgyVt24z8yIywPl+DsKslP7xqcxT TC2YEVhOJMw+mpmfOhVVSAh9Ep1RZVk9lwLYI3SHzOJvZIfVJEEPUYFVBtl16UV8 b6ozZvNBxqEfRb2zYHM481cA3mLN0EyoI7mznbKgHLq1IV/gSdJebg= 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:from :to:subject:date:message-id:content-type:mime-version; s= default; bh=MWFvbdcrZA/WJwROHrLRgLNtTkU=; b=x3+v5FwMKaTEbE6MNjoq /752fLP63j1MjWv9JBpas9djuefQSn50zD32abDv5X+k2OTXZPsLGVJWKNHYVnqn +4xkFgiHqojx5LiQ46y3IZNdXAil5SKwjZrrPED0FnyyZ2EUsJUw/Ykj2nrpoNu5 bfUTpQnR/DM6HgIhsqAJXFY= Received: (qmail 48940 invoked by alias); 21 Apr 2017 18:36:37 -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 48911 invoked by uid 89); 21 Apr 2017 18:36:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-14.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=3536, TAG, basics, H*c:sk:HHHPRHH X-HELO: EUR02-HE1-obe.outbound.protection.outlook.com Received: from mail-oln040092068060.outbound.protection.outlook.com (HELO EUR02-HE1-obe.outbound.protection.outlook.com) (40.92.68.60) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Apr 2017 18:36:33 +0000 Received: from VE1EUR02FT006.eop-EUR02.prod.protection.outlook.com (10.152.12.53) by VE1EUR02HT044.eop-EUR02.prod.protection.outlook.com (10.152.13.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1019.14; Fri, 21 Apr 2017 18:36:22 +0000 Received: from HE1PR0701MB2169.eurprd07.prod.outlook.com (10.152.12.58) by VE1EUR02FT006.mail.protection.outlook.com (10.152.12.221) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.14 via Frontend Transport; Fri, 21 Apr 2017 18:36:22 +0000 Received: from HE1PR0701MB2169.eurprd07.prod.outlook.com ([10.168.36.18]) by HE1PR0701MB2169.eurprd07.prod.outlook.com ([10.168.36.18]) with mapi id 15.01.1061.005; Fri, 21 Apr 2017 18:36:22 +0000 From: Bernd Edlinger To: "gcc-patches@gcc.gnu.org" , Nathan Sidwell , Jan Hubicka Subject: [PATCH] Force use of absolute path names for gcov Date: Fri, 21 Apr 2017 18:36:22 +0000 Message-ID: authentication-results: gcc.gnu.org; dkim=none (message not signed) header.d=none; gcc.gnu.org; dmarc=none action=none header.from=hotmail.de; x-incomingtopheadermarker: OriginalChecksum:A4C8242A9D2BDA14ECCA9EDE6F9FF3DB4578296F609694020EB25A5C6B1FE91E; UpperCasedChecksum:9A6E0347AA93001AB5B34356C89E056DEEEB8BAEA761A51920E9CB306EF90854; SizeAsReceived:7856; Count:37 x-ms-exchange-messagesentrepresentingtype: 1 x-microsoft-exchange-diagnostics: 1; VE1EUR02HT044; 5:9htBvnOtgpNuXTgfixPi9Vzr0OMel1dmHFGN1WDnkYt75ef/WNxd1MjvuKJ0FPfVocef2LF04UOx09AGopPBca+hPScURf3g7lvyz78RX3BoqgcqPmC1hQOnfyHs3NXs8OWrP4PsdsxZETzqQMIY4Q==; 24:da5Olqk5XM3MDzQwfKQA3tQ1S9gLfUpKLm3lqGdkkUI+D2fXBEJU9CvOVfWKzgHEBHBKfYzrzPvy6s0/uoKolGRnwdk5Ptp4piE4YBpANyY=; 7:jofIEbNZ8myumVkmwhoopLIrYUOZr29Ku48wBpOCUg62KBHBp944gwWBeszMngfrCj/YliWTphe//tBakY1nWIaSpjSjOVWqMwfnKdkgRr7SXjS3oJoNaTC3W5Vq9Jv38+Gdy5kfd8u0TcmpiJXCQqzmHbntcT6pr+9Qqlb69zL8R9ZGly/Ps8lyoYDmEzWPsARa+NtPv8dtV1wwgT77jvTAPqyoxG9REOx0We/IqBjj5Z34fix83aRuMGiI1Ykynb7GDiiu6Ou1NsiUX+zNk/wn8snOyCS3WZ7HJB3kGqKSWulDhSsPOTCt+aHklyj3 x-incomingheadercount: 37 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:VE1EUR02HT044; H:HE1PR0701MB2169.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: 2f2b206f-f9d2-413e-6866-08d488e54e13 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322274)(1603101448)(1601125374)(1701031045); SRVR:VE1EUR02HT044; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:VE1EUR02HT044; BCL:0; PCL:0; RULEID:; SRVR:VE1EUR02HT044; x-forefront-prvs: 02843AA9E0 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Apr 2017 18:36:22.0318 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR02HT044 Hi! If gcov is used in projects where gcc is invoked in different directories, it may happen that the same source is compiled with different relative names, and the gcov tool is thus unable to find out, if it is the same source file or not, or to dump the source at all, which is a limitation of the gcov tool. So I would like to add a -fprofile-abs-path option that forces absolute path names in gcno files, which allows gcov to get the true canonicalized source name. Bootstrapped and reg-tested on x86_64-pc-linux-gnu. Is it OK for trunk? Thanks Bernd. Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 246571) +++ gcc/common.opt (working copy) @@ -1965,6 +1965,10 @@ fprofile Common Report Var(profile_flag) Enable basic program profiling code. +fprofile-abs-path +Common Report Var(profile_abs_path_flag) +Generate absolute source path names for gcov. + fprofile-arcs Common Report Var(profile_arc_flag) Insert arc-based program profiling code. Index: gcc/coverage.c =================================================================== --- gcc/coverage.c (revision 246571) +++ gcc/coverage.c (working copy) @@ -663,7 +663,7 @@ coverage_begin_function (unsigned lineno_checksum, gcov_write_unsigned (cfg_checksum); gcov_write_string (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl))); - gcov_write_string (xloc.file); + gcov_write_filename (xloc.file); gcov_write_unsigned (xloc.line); gcov_write_length (offset); Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 246571) +++ gcc/doc/invoke.texi (working copy) @@ -441,6 +441,7 @@ Objective-C and Objective-C++ Dialects}. @item Program Instrumentation Options @xref{Instrumentation Options,,Program Instrumentation Options}. @gccoptlist{-p -pg -fprofile-arcs --coverage -ftest-coverage @gol +-fprofile-abs-path @gol -fprofile-dir=@var{path} -fprofile-generate -fprofile-generate=@var{path} @gol -fsanitize=@var{style} -fsanitize-recover -fsanitize-recover=@var{style} @gol -fasan-shadow-offset=@var{number} -fsanitize-sections=@var{s1},@var{s2},... @gol @@ -10639,6 +10640,12 @@ additional @option{-ftest-coverage} option. You d every source file in a program. @item +Compile the source files additionally with @option{-fprofile-abs-path} +to create absolute path names in the @file{.gcno} files. This allows +@command{gcov} to find the correct sources in projects with multiple +directories. + +@item Link your object files with @option{-lgcov} or @option{-fprofile-arcs} (the latter implies the former). Index: gcc/gcov-io.c =================================================================== --- gcc/gcov-io.c (revision 246571) +++ gcc/gcov-io.c (working copy) @@ -353,6 +353,37 @@ gcov_write_string (const char *string) #endif #if !IN_LIBGCOV +/* Write FILENAME to coverage file. Sets error flag on file + error, overflow flag on overflow */ + +GCOV_LINKAGE void +gcov_write_filename (const char *filename) +{ + char buf[1024]; + size_t len; + + if (profile_abs_path_flag && filename && filename[0] + && !(IS_DIR_SEPARATOR (filename[0]) +#if HAVE_DOS_BASED_FILE_SYSTEM + || filename[1] == ':' +#endif + ) + && (len = strlen (filename)) < sizeof (buf) - 1) + { + if (getcwd (buf, sizeof (buf) - len - 1) != NULL) + { + if (buf[0] && !IS_DIR_SEPARATOR (buf[strlen (buf) - 1])) + strcat (buf, "/"); + strcat (buf, filename); + filename = buf; + } + } + + return gcov_write_string (filename); +} +#endif + +#if !IN_LIBGCOV /* Write a tag TAG and reserve space for the record length. Return a value to be used for gcov_write_length. */ Index: gcc/gcov-io.h =================================================================== --- gcc/gcov-io.h (revision 246571) +++ gcc/gcov-io.h (working copy) @@ -388,6 +388,7 @@ GCOV_LINKAGE void gcov_write_unsigned (gcov_unsign /* Available only in compiler */ GCOV_LINKAGE unsigned gcov_histo_index (gcov_type value); GCOV_LINKAGE void gcov_write_string (const char *); +GCOV_LINKAGE void gcov_write_filename (const char *); GCOV_LINKAGE gcov_position_t gcov_write_tag (gcov_unsigned_t); GCOV_LINKAGE void gcov_write_length (gcov_position_t /*position*/); #endif Index: gcc/profile.c =================================================================== --- gcc/profile.c (revision 246571) +++ gcc/profile.c (working copy) @@ -956,7 +956,7 @@ output_location (char const *file_name, int line, { prev_file_name = file_name; gcov_write_unsigned (0); - gcov_write_string (prev_file_name); + gcov_write_filename (prev_file_name); } if (line_differs) { Index: gcc/testsuite/gcc.misc-tests/gcov-1a.c =================================================================== --- gcc/testsuite/gcc.misc-tests/gcov-1a.c (revision 0) +++ gcc/testsuite/gcc.misc-tests/gcov-1a.c (working copy) @@ -0,0 +1,20 @@ +/* Test Gcov basics. */ + +/* { dg-options "-fprofile-arcs -ftest-coverage -fprofile-abs-path" } */ +/* { dg-do run { target native } } */ + +void noop () +{ +} + +int main () +{ + int i; + + for (i = 0; i < 10; i++) /* count(11) */ + noop (); /* count(10) */ + + return 0; /* count(1) */ +} + +/* { dg-final { run-gcov gcov-1a.c } } */