public inbox for
 help / color / mirror / Atom feed
From: Richard Purdie <>
Cc: Khem Raj <>
Subject: Reproducible builds - supporting relative paths in *-prefix-map
Date: Mon, 15 Aug 2022 12:13:28 +0100	[thread overview]
Message-ID: <> (raw)


I'm wondering if we'd be able to improve path handling in the -f*-
prefix-map compiler options to cover relative paths?

Currently it works well for absolute paths but if a file uses a
relative path or a path with a symlink in, or a non-absolute path, it
will miss those cases. For relative paths in particular it is
problematic as you can't easily construct a compiler commandline that
would cover all relative path options.

At first glance this is relatively straight forward, for example:

Index: gcc-12.1.0/gcc/
--- gcc-12.1.0.orig/gcc/
+++ gcc-12.1.0/gcc/
@@ -70,19 +70,25 @@ remap_filename (file_prefix_map *maps, c
   file_prefix_map *map;
   char *s;
   const char *name;
+  char *realname;
   size_t name_len;
+  realname = lrealpath (filename);
   for (map = maps; map; map = map->next)
-    if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0)
+    if (filename_ncmp (realname, map->old_prefix, map->old_len) == 0)
-  if (!map)
+  if (!map) {
+    free (realname);
     return filename;
-  name = filename + map->old_len;
+  }
+  name = realname + map->old_len;
   name_len = strlen (name) + 1;
   s = (char *) ggc_alloc_atomic (name_len + map->new_len);
   memcpy (s, map->new_prefix, map->new_len);
   memcpy (s + map->new_len, name, name_len);
+  free (realname);
   return s;
which address a realpath() call into the prefix mapping code. I did
experiment with this and found it breaks compiling ruby and xen-tools
which both have code which does:

#include __FILE__

It may be possible to make the remapping conditional of not being
directly in a #include statement but I didn't find the gcc code
responsible for that as yet. I also noticed some valgrind tests fails
after it, I've not looked into why that would be yet.

I wanted to ask if there would be any interest in adding support for
something like this? I suspect the include/__FILE__ issue is probably a
latent bug anyway. If anyone has any pointers to the code I could
improve my patch with I'm also happy to have them!

In case it helps, my background on what I'm working on and why we'd
find this useful follows: 

I work on Yocto Project which cross compiles complete software stacks,
we use gcc heavily and the resulting builds are all around us. We care
deeply about build reproducibility.

With autotools, we long ago realised that we were best off separating
the source and the build output where we could and to do it we used
relative paths, which removed a lot of problematic hardcoded paths in
our output.

More recently we've been using -fdebug-prefix-map and -fmacro-prefix-
map (we need both since some of binutils doesn't seem to support the
combined version yet). We use the debug information (split separately)
to support on target debugging but where relative paths were used, we
miss information as the remapping either doesn't happen correctly or is
mangled. We'd like to fix our debug output but we're finding that hard
without relative path support for *prefix-map.



             reply	other threads:[~2022-08-15 11:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 11:13 Richard Purdie [this message]
2022-08-15 14:26 ` Richard Purdie
2022-08-15 14:36   ` David Edelsohn
2022-08-15 17:15 ` Joseph Myers
2022-08-15 19:51   ` Richard Purdie
2022-08-15 19:55 ` Mark Wielaard
2022-08-15 20:29   ` Richard Purdie
2022-08-17 11:23     ` Mark Wielaard
2022-08-17 18:06       ` Richard Purdie

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:

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

  git send-email \ \ \ \ \

* 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).