From patchwork Fri Apr 28 17:41:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 756508 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 3wF1NR3gx9z9s7w for ; Sat, 29 Apr 2017 03:42:14 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="BY98Vr1E"; 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:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; q=dns; s=default; b=lR44eqq+RQYu3yv8 895AUhsqDovDac1JUMkP/zZmk6fJPzPgP85QJ1nfpWHAUmEBejSjwzvVCS8Hlilz 5otL/SX2nPMXtalzjuUAdK55UTXEzhdhztMvjbx53VkyfXi13VlqY8IiTwlnism8 eTRmfgJ0fOe7J6ZO0MsX/AntrCQ= 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:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; s=default; bh=+1mx7QmQTjwO8l80E4Fl94 ScyaA=; b=BY98Vr1EPDcvOM4hWxv7R61XC1Xgk7bTpCy/DgA0ABdL4WTEZDCCuj OSbMmrabRV30+yMpalBbcyBqtBvS97XuPF8ccMatdGdzQt+NTLO1YWy8NAetczNr gmt/09yG3ogPEbvLI2MQGntxts5Ikix1+QjI8rYxNecJlWS3/rkjk= Received: (qmail 18073 invoked by alias); 28 Apr 2017 17:42:03 -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 18059 invoked by uid 89); 28 Apr 2017 17:42:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.6 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=Hx-spam-relays-external:sk:HE1EUR0, closely, H*RU:sk:HE1EUR0, H*r:sk:HE1EUR0 X-HELO: EUR01-DB5-obe.outbound.protection.outlook.com Received: from mail-oln040092064074.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (40.92.64.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Apr 2017 17:42:00 +0000 Received: from HE1EUR01FT042.eop-EUR01.prod.protection.outlook.com (10.152.0.54) by HE1EUR01HT060.eop-EUR01.prod.protection.outlook.com (10.152.1.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1047.9; Fri, 28 Apr 2017 17:41:59 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com (10.152.0.54) by HE1EUR01FT042.mail.protection.outlook.com (10.152.0.228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1047.9 via Frontend Transport; Fri, 28 Apr 2017 17:41:59 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com ([fe80::40a0:2642:4335:50ed]) by AM4PR0701MB2162.eurprd07.prod.outlook.com ([fe80::40a0:2642:4335:50ed%19]) with mapi id 15.01.1075.002; Fri, 28 Apr 2017 17:41:59 +0000 From: Bernd Edlinger To: Joseph Myers CC: "gcc-patches@gcc.gnu.org" , Nathan Sidwell , Jan Hubicka Subject: [PING] [PATCH] Force use of absolute path names for gcov Date: Fri, 28 Apr 2017 17:41:59 +0000 Message-ID: References: In-Reply-To: authentication-results: codesourcery.com; dkim=none (message not signed) header.d=none; codesourcery.com; dmarc=none action=none header.from=hotmail.de; x-incomingtopheadermarker: OriginalChecksum:3ABD49224C7B556A1F1635D44C44CB200EAD0119B5BBE4B4398329C5F5DB0D0F; UpperCasedChecksum:261FEF5E039F2B592A7662C5D0D5ADB92ABDF36FFD982939B87EFCB29A00B964; SizeAsReceived:8458; Count:43 x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1EUR01HT060; 5:9L8h9+eO5SGJ5gXZkzwkz194iaCvwCXJLhKcIMttlHq65KI5JRuXXiaHJIB8Ml6PwjCqCpxak46DrHVKbg1rhoVAjYWnTK/fPswoxgSfjHpgG7Nd/QXCo7ffavvbqvv4uD96sHacvUx+aL3MtN0cNw==; 24:ybNcYG17F4kwXxdQmYx3Tkk5hfWjrqtWhXbxEd9diTVFLNKP2RfPEiAzsT/o4eSJRLigWZmQpqj3QN2gNvoWopECeXnT/61x7mEE+tdOxoU=; 7:0ijvUTkZ2G/NNfdFw4ykTsCpcoXAgrtJJYOMS9NDXlb3/IWyUjRvvU5Vy28mOxNUS4viIf6dJONkDMjl8pHkUohetwVwBAjljH1mXzrLLyzBO7wAy2V1cSJ++scshA33bOwpUMDFctdw3dyQSu5G/xVRu8tdd6+L0THr78EQ5y2QQpwmsbunRmpix8LnhZTRNjx9uYLwfCRdJYO8W2+1XlwGBwDEzu8lcg/88YkrmFbJTIFiaamgP/glDx9S9TNiSX8T1wqbCqMd3DMYSV5ao7IA3pgPdppkKwVx8nZw8mKvkP3sBv72yOW4Qs+0bYe5 x-incomingheadercount: 43 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:HE1EUR01HT060; H:AM4PR0701MB2162.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: d05c4d74-0617-4f86-07c2-08d48e5ddea1 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(201702181274)(2017031322274)(1601125374)(1603101448)(1701031045); SRVR:HE1EUR01HT060; x-ms-exchange-slblob-mailprops: 79Jo46q8hhAt+fDCftx/QfcS1Z0rvxoEUhNEunXRkX3PYgSCDWa+YlvZ+/yPA3PPYJkRyBZE8ykXG1WA0kOL0ZpXw6s2LxFPGPw/Vy0Z39NSSYkz79DS1X0WxXZ8PPlrMhIHnKyDP42rKPETtZ+sKvz+nBwFyF4//plijQSnXZNtHh9Wn3MEppWOZp88SEyaxHiFnEtFy/+apMwoJCKstjCn2QanQHWmh5YvxBW/7EGz7ZXgDy/2GOYsdLVljqGR3a48Xqt7x3AqL3jZnUgOEQWTyxECsGNQ0a2GbBgaBznBBUtoT2O6XFPKy0PgoqviDXWaZot1q5ltEmA2qYP8VqoT3DX0kCBRfTp3wEsIc21H7cLzhZrE7E47jUpLbqbS5mwhMReNceQazXilgF1cxPnReYEJCxwiDLwAsz6b+VwSnW5MaF6Nooam3Hvr9TtXa/p51m2t5dRj2fXHf/bccfByudRY8wH98HEhCYQ/qNbDQpgN2GoH2Hf42u7cE5DkRuncEwDHwNe9imnThDd9nU5EnckkVhLl3xRdIcDkgI8Ius0iRdUC4AJO1gxOsAWlcdsNLYiPWTvQ5PQlq7Fgbe4hNI8+Vz4cTWQh0gnoPcI0d3DmlGiYJboZW88XfC8cJUmf4ATAosCoPkd1FUpcG6ayKC3g7DemJIW8Ki2ESaxBJLItIn42X89jtHdwMXJU x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:HE1EUR01HT060; BCL:0; PCL:0; RULEID:; SRVR:HE1EUR01HT060; x-forefront-prvs: 029174C036 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2017 17:41:59.5489 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR01HT060 Ping... I attached a rebased patch file, with the doc changes and merge conflicts with trunk of today fixed, but otherwise identical. Thanks Bernd. On 04/21/17 22:26, Bernd Edlinger wrote: > > > On 04/21/17 21:50, Joseph Myers wrote: >> On Fri, 21 Apr 2017, Bernd Edlinger wrote: >> >>> 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. >> >> I don't see any actual documentation of this option in the patch (you add >> it to the summary list of options, and mention it in text under the >> documentation of --coverage, but don't have any actual @item >> -fprofile-abs-path / @opindex fprofile-abs-path paragraph with text >> describing what the option does). >> > > Ah yes, thanks. > > So I'll add one more sentence to invoke.texi: > > @@ -10696,6 +10713,12 @@ > generate test coverage data. Coverage data matches the source files > more closely if you do not optimize. > > +@item -fprofile-abs-path > +@opindex fprofile-abs-path > +Automatically convert relative source file names to absolute path names > +in the @file{.gcno} files. This allows @command{gcov} to find the correct > +sources in projects with multiple directories. > + > @item -fprofile-dir=@var{path} > @opindex fprofile-dir > > > > > 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). @@ -10696,6 +10713,12 @@ generate test coverage data. Coverage data matches the source files more closely if you do not optimize. +@item -fprofile-abs-path +@opindex fprofile-abs-path +Automatically convert relative source file names to absolute path names +in the @file{.gcno} files. This allows @command{gcov} to find the correct +sources in projects with multiple directories. + @item -fprofile-dir=@var{path} @opindex fprofile-dir 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 } } */