public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ximin Luo <infinity0@pwned.gg>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Ximin Luo <infinity0@pwned.gg>
Subject: [PATCH 3/3] When remapping paths, only match whole path components
Date: Fri, 21 Jul 2017 16:16:00 -0000	[thread overview]
Message-ID: <20170721161538.7508-4-infinity0@pwned.gg> (raw)
In-Reply-To: <20170721161538.7508-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 therefore it is easier
for users to figure out how to set the mapping appropriately.  Therefore, I
believe it is better as a standardised algorithm that other build tools might
like to adopt, and so in our BUILD_PATH_PREFIX_MAP specification we recommend
this algorithm - though we allow others, and explicitly mention GCC's current
algorithm.  But it would be good for GCC to adopt this newer and cleaner one.

(The original idea came from discussions with rustc developers on this topic.)

This does technically break backwards-compatibility, but I was under the
impression that this option was not seen as such a critical feature, that this
would be too important.  Nevertheless, this part is totally independent from
the other patches and may be included or excluded as GCC maintainers desire.

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
----------

libiberty/ChangeLog:

2017-07-21  Ximin Luo  <infinity0@pwned.gg>

	* prefix-map.c: When remapping paths, only match whole path components.

Index: gcc-8-20170716/libiberty/prefix-map.c
===================================================================
--- gcc-8-20170716.orig/libiberty/prefix-map.c
+++ gcc-8-20170716/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;
 }

  parent reply	other threads:[~2017-07-21 16:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21 16:16 [PING^4][PATCH v2] Generate reproducible output independently of the build-path Ximin Luo
2017-07-21 16:16 ` [PATCH 2/3] Use BUILD_PATH_PREFIX_MAP envvar to transform __FILE__ Ximin Luo
2017-07-21 16:16 ` [PATCH 1/3] Use BUILD_PATH_PREFIX_MAP envvar for debug-prefix-map Ximin Luo
2017-08-02 19:19   ` Jeff Law
2017-07-21 16:16 ` Ximin Luo [this message]
2017-08-02 19:09 ` [PING^4][PATCH v2] Generate reproducible output independently of the build-path Jeff Law
2017-08-03  2:06   ` Ximin Luo
2017-08-03  4:49     ` Yury Gribov
2017-08-03 11:46       ` Ximin Luo
2017-08-04  8:40         ` Yury Gribov
2017-08-10 21:29           ` Ximin Luo
2017-08-03 15:57       ` Jeff Law
2017-08-03 16:05     ` Jeff Law
2017-08-03 17:02       ` Ximin Luo
2017-08-04 12:32       ` Matthias Klose
2017-08-04 13:05         ` Jakub Jelinek
2017-08-10 21:15           ` Ximin Luo
2017-08-04 16:05         ` Yury Gribov
2017-08-10 20:55           ` Ximin Luo
2017-08-11  2:53             ` Joseph Myers
  -- strict thread matches above, loose matches on Subject: below --
2017-04-11 11:35 [PATCH " Ximin Luo
2017-04-11 11:35 ` [PATCH 3/3] When remapping paths, only match whole path components Ximin Luo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170721161538.7508-4-infinity0@pwned.gg \
    --to=infinity0@pwned.gg \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).