From patchwork Tue Apr 11 11:34:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ximin Luo X-Patchwork-Id: 749425 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 3w2Q2x4rRGz9sNS for ; Tue, 11 Apr 2017 21:35:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CFhPCjhu"; 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:in-reply-to:references; q=dns; s= default; b=wF0dSolxFMejjNotp64Oj+iHjasaG5NplK40dcrQrvNXVbEt8W0yr XQPJBb1pQm4nWjyEvLasERmjOkhbqtNqJfzKOSk5dU9uY/s9J/iHG773LtupixWE uhWvWvMe4CRXRwFX4OdvHOG/AZ1EQ2zs9ohc0mx28TaKgPM2/IzSfQ= 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:in-reply-to:references; s= default; bh=QMPpMYEhoO08OMjcV8b5PW0YL4A=; b=CFhPCjhuUeHB1ElSGjAO T4/Uie64TZBSwLyzWRunZdwh6n2h7TeF6Q7ozN0eIOxejINS/V0tF0CkWAD7fOkx EmtAlgcncLbt3xpHGbrmAaYJd/nHEVj7v6Y7LXnZHv3D/5OP+/QevSH82tbaWQD4 BhbrUXwW2k7/VMd1yPYEXDM= Received: (qmail 113223 invoked by alias); 11 Apr 2017 11:35:07 -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 112372 invoked by uid 89); 11 Apr 2017 11:35:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-14.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=luo, Luo, ir, dots X-HELO: mail.headstrong.de Received: from mail.headstrong.de (HELO mail.headstrong.de) (81.7.4.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Apr 2017 11:35:02 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.headstrong.de (Postfix) with ESMTP id 038971C00637; Tue, 11 Apr 2017 13:35:01 +0200 (CEST) Authentication-Results: mail.headstrong.de (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=headstrong.de Received: from mail.headstrong.de ([127.0.0.1]) by localhost (mail.headstrong.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7mXVk_5ZdhoR; Tue, 11 Apr 2017 13:34:58 +0200 (CEST) Received: from infinity0 by pdeb1.fritz.box with local (Exim 4.88) (envelope-from ) id 1cxu4Y-00046i-5J; Tue, 11 Apr 2017 13:34:58 +0200 From: Ximin Luo To: GCC Patches Cc: Ximin Luo Subject: [PATCH 3/3] When remapping paths, only match whole path components Date: Tue, 11 Apr 2017 13:34:46 +0200 Message-Id: <20170411113446.15683-4-infinity0@pwned.gg> In-Reply-To: <20170411113446.15683-1-infinity0@pwned.gg> References: <20170411113446.15683-1-infinity0@pwned.gg> Change the remapping algorithm so that each old_prefix only matches paths that have old_prefix as a whole path component prefix. (A whole path component is a part of a path that begins and ends at a directory separator or at either end of the path string.) This remapping algorithm is more predictable than the old algorithm, because there is no chance of mappings for one directory interfering with mappings for other directories. It contains less corner cases and is therefore nicer for clients to use. For these reasons, in our BUILD_PATH_PREFIX_MAP specification we recommend this algorithm, and it would be good for GCC to follow suit. This does technically break backwards compatibility but I don't think anyone would be reasonably depending on the corner cases of the previous algorithm, which are surprising and counterintuitive. Acknowledgements ---------------- Discussions with Michael Woerister and other members of the Rust compiler team on Github, and discussions with Daniel Shahaf on the rb-general@ mailing list on lists.reproducible-builds.org. ChangeLogs ---------- gcc/ChangeLog: 2017-04-09 Ximin Luo * doc/invoke.texi (Environment Variables): Document form and behaviour of BUILD_PATH_PREFIX_MAP. libiberty/ChangeLog: 2017-04-09 Ximin Luo * prefix-map.c: When remapping paths, only match whole path components. Index: gcc-7-20170409/gcc/doc/invoke.texi =================================================================== --- gcc-7-20170409.orig/gcc/doc/invoke.texi +++ gcc-7-20170409/gcc/doc/invoke.texi @@ -26637,6 +26637,26 @@ Recognize EUCJP characters. If @env{LANG} is not defined, or if it has some other value, then the compiler uses @code{mblen} and @code{mbtowc} as defined by the default locale to recognize and translate multibyte characters. + +@item BUILD_PATH_PREFIX_MAP +@findex BUILD_PATH_PREFIX_MAP +If this variable is set, it specifies an ordered map used to transform +filepaths output in debugging symbols and expansions of the @code{__FILE__} +macro. This may be used to achieve fully reproducible output. In the context +of running GCC within a higher-level build tool, it is typically more reliable +than setting command line arguments such as @option{-fdebug-prefix-map} or +common environment variables such as @env{CFLAGS}, since the build tool may +save these latter values into other output outside of GCC's control. + +The value is of the form +@samp{@var{dst@r{[0]}}=@var{src@r{[0]}}:@var{dst@r{[1]}}=@var{src@r{[1]}}@r{@dots{}}}. +If any @var{dst@r{[}i@r{]}} or @var{src@r{[}i@r{]}} contains @code{%}, @code{=} +or @code{:} characters, they must be replaced with @code{%#}, @code{%+}, and +@code{%.} respectively. + +Whenever GCC emits a filepath that starts with a whole path component matching +@var{src@r{[}i@r{]}} for some @var{i}, with rightmost @var{i} taking priority, +the matching part is replaced with @var{dst@r{[}i@r{]}} in the final output. @end table @noindent Index: gcc-7-20170409/libiberty/prefix-map.c =================================================================== --- gcc-7-20170409.orig/libiberty/prefix-map.c +++ gcc-7-20170409/libiberty/prefix-map.c @@ -87,12 +87,22 @@ struct prefix_map * prefix_map_find (struct prefix_map *map, const char *old_name, const char **suffix, size_t *suf_len) { + size_t len; + for (; map; map = map->next) - if (filename_ncmp (old_name, map->old_prefix, map->old_len) == 0) - { - *suf_len = strlen (*suffix = old_name + map->old_len); - break; - } + { + len = map->old_len; + /* Ignore trailing path separators at the end of old_prefix */ + while (len > 0 && IS_DIR_SEPARATOR (map->old_prefix[len-1])) len--; + /* Check if old_name matches old_prefix at a path component boundary */ + if (! filename_ncmp (old_name, map->old_prefix, len) + && (IS_DIR_SEPARATOR (old_name[len]) + || old_name[len] == '\0')) + { + *suf_len = strlen (*suffix = old_name + len); + break; + } + } return map; }