From patchwork Tue Feb 4 13:00:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1233330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518876-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=rOZwCjps; dkim-atps=neutral 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 48BlDz2MBjzB3ww for ; Wed, 5 Feb 2020 00:01:05 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=eaeVC/0dXzjjyACoy1Ql424PMaYWZSPSjGPdn2UYLH5a2Bou5F KrugXxJxOPxlk5M2i7W9W1hLOD1TS2QUbglanfnaVWPH0BHtpan6MFh+kc7pN3KZ dntbUcxWwszU1xXUCCiuoCWrLCVvHmQ/F4PBev+zCQo+p/y3SmOtx9W7w= 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 :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=dGZdWgpUCUvavFv2/Lq8qayJ4p8=; b=rOZwCjpsO6o/1hL0LNok Js7y6I3dyvEbVGKtKwOz5yFzTo9kDd6AJ+9NutaCs/nemb3vbfHt6pD5R3HcYZFh PkSuhks6BA9o3Os2waxEshXOJofV4zOQuiQ2soDtJ2hKwTVSPLmkNJ5RRSW3n9aA amz7SUw108gx+XF4PIcRxsA= Received: (qmail 55061 invoked by alias); 4 Feb 2020 13:00:56 -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 55023 invoked by uid 89); 4 Feb 2020 13:00:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=2187, 2878, 2286, HX-Languages-Length:4714 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Feb 2020 13:00:48 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 60EFBB198; Tue, 4 Feb 2020 13:00:46 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] Rework GCOV_PREFIX_STRIP env variable. To: gcc-patches@gcc.gnu.org Cc: Jan Hubicka Message-ID: Date: Tue, 4 Feb 2020 14:00:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi. The patch addresses https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93401#c9 where we currently support mechanism for cross compilation: GCC manual: 10.5 Data File Relocation to Support Cross-Profiling That's very much the same what Honza needs for Firefox, where profile-gen run happens in a different location than profile-use run. However, I see current meaning of GCOV_PREFIX_STRIP a bit difficult to use. That's why I suggest to rename it to GCOV_PREFIX_STRIP_COMPONENTS and use GCOV_PREFIX_STRIP for real strip prefix. Thoughts? Martin gcc/ChangeLog: 2020-02-04 Martin Liska PR gcov-profile/93401 * doc/gcov.texi: Document new behaviour of GCOV_PREFIX_STRIP and introduce GCOV_PREFIX_STRIP_COMPONENTS. libgcc/ChangeLog: 2020-02-04 Martin Liska PR gcov-profile/93401 * libgcov-driver-system.c (allocate_filename_struct): Parse also GCOV_PREFIX_STRIP_COMPONENTS. (gcov_exit_open_gcda_file): Handle new meaning of GCOV_PREFIX_STRIP and GCOV_PREFIX_STRIP_COMPONENTS. * libgcov-driver.c (struct gcov_filename): New field. --- gcc/doc/gcov.texi | 17 +++++++++++------ libgcc/libgcov-driver-system.c | 7 +++++-- libgcc/libgcov-driver.c | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi index 61250c9407e..154c7eb965a 100644 --- a/gcc/doc/gcov.texi +++ b/gcc/doc/gcov.texi @@ -951,11 +951,16 @@ in the object file. Prefix can be absolute, or relative. The default is no prefix. @item -GCOV_PREFIX_STRIP indicates the how many initial directory names to strip off -the hardwired absolute paths. Default value is 0. +GCOV_PREFIX_STRIP_COMPONENTS indicates the how many initial directory names +to strip off the hardwired absolute paths. Default value is 0. -@emph{Note:} If GCOV_PREFIX_STRIP is set without GCOV_PREFIX is undefined, - then a relative path is made out of the hardwired absolute paths. +@item +GCOV_PREFIX_STRIP indicates path prefix to strip off +the hardwired absolute paths. + +@emph{Note:} If GCOV_PREFIX_STRIP_COMPONENTS (or GCOV_PREFIX_STRIP) +is set without GCOV_PREFIX, then a relative path is made +out of the hardwired absolute paths. @end itemize For example, if the object file @file{/user/build/foo.o} was built with @@ -963,8 +968,8 @@ For example, if the object file @file{/user/build/foo.o} was built with @file{/user/build/foo.gcda} when running on the target system. This will fail if the corresponding directory does not exist and it is unable to create it. This can be overcome by, for example, setting the environment as -@samp{GCOV_PREFIX=/target/run} and @samp{GCOV_PREFIX_STRIP=1}. Such a -setting will name the data file @file{/target/run/build/foo.gcda}. +@samp{GCOV_PREFIX=/target/run} and @samp{GCOV_PREFIX_STRIP_COMPONENTS=1}. +Such a setting will name the data file @file{/target/run/build/foo.gcda}. You must move the data files to the expected directory tree in order to use them for profile directed optimizations (@option{-fprofile-use}), or to diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 031f057e318..c17ce72b4b6 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -218,7 +218,7 @@ allocate_filename_struct (struct gcov_filename *gf) { /* Check if the level of dirs to strip off specified. */ - char *tmp = getenv("GCOV_PREFIX_STRIP"); + char *tmp = getenv ("GCOV_PREFIX_STRIP_COMPONENTS"); if (tmp) { strip = atoi (tmp); @@ -228,6 +228,7 @@ allocate_filename_struct (struct gcov_filename *gf) } } gf->strip = strip; + gf->strip_prefix = getenv ("GCOV_PREFIX_STRIP"); /* Get file name relocation prefix. Non-absolute values are ignored. */ gcov_prefix = getenv("GCOV_PREFIX"); @@ -239,7 +240,7 @@ allocate_filename_struct (struct gcov_filename *gf) /* If no prefix was specified and a prefix stip, then we assume relative. */ - if (!prefix_length && gf->strip) + if (!prefix_length && (gf->strip || gf->strip_prefix)) { gcov_prefix = "."; prefix_length = 1; @@ -286,6 +287,8 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, level--; } } + else if (gf->strip_prefix && strstr (fname, gf->strip_prefix) == fname) + fname += strlen (gf->strip_prefix); /* Update complete filename with stripped original. */ if (gf->prefix) diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index fb320738e1e..15c2009f8fc 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -76,6 +76,7 @@ struct gcov_filename { char *filename; /* filename buffer */ int strip; /* leading chars to strip from filename */ + char *strip_prefix; /* leading path prefix that should be stripped */ char *prefix; /* prefix string */ };