[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RFC: dpkg patch to using -ffile-prefix-map



With gcc 8 being the default compiler in debian now, we should be able
to use -ffile-prefix-map, which should handle *some* of the cases that
BUILD_PATH_PREFIX_MAP is intended to solve. It definitely won't help
with things that embed the gcc commandline into arguments.

But since we've been unable to convince gcc on the merits of
BUILD_PATH_PREFIX_MAP using an environment variable, rebasing the gcc
patches to support it takes a lot of effort, perhaps we should explore
other options.

I've got a dpkg patch which makes use of -ffile-prefix-map. I haven't
found a good test case yet... package that fails to build reproducibly
due to using __FILE__, __BASE_FILE__, or __builtin_FILE() and builds
fast enough that it's easy to test (holger suggested trying "dtkwm", but
I haven't had a chance to try yet). Figured I'd at least publish my
patch to get some review and/or testers.

The patch largely just copy-and-pastes the -fdebug-prefix-map code,
though arguably could obsolete it entirely, since -ffile-prefix-map
effectivly sets both -fdebug-prefix-map and -fmacro-prefix-map. But
having the two features independently allows enabling or disabling one
or the other easily for now.

If nothing else, carrying a patch on dpkg builds *much* faster than gcc,
and rebasing it periodically will be a lot less effort. Though if it
works, hopefully we can get it into dpkg directly.

Thanks!


live well,
  vagrant

commit a500874714fc8f7865d897653d8a33ab3ce7d7ff
Author: Vagrant Cascadian <vagrant@debian.org>
Date:   Thu Jul 26 16:49:28 2018 +0800

    Add support for -ffile-prefix-map, which enables both
    -fdebug-prefix-map and -fmacro-prefix-map to also support common path
    related macros.

diff --git a/scripts/Dpkg/Vendor/Debian.pm b/scripts/Dpkg/Vendor/Debian.pm
index 1e8f24397..315d8b9b8 100644
--- a/scripts/Dpkg/Vendor/Debian.pm
+++ b/scripts/Dpkg/Vendor/Debian.pm
@@ -101,6 +101,7 @@ sub _add_build_flags {
         reproducible => {
             timeless => 1,
             fixdebugpath => 1,
+            fixfilepath => 1,
         },
         sanitize => {
             address => 0,
@@ -218,6 +219,20 @@ sub _add_build_flags {
         }
     }
 
+    # Mask features that might have an unsafe usage.
+    if ($use_feature{reproducible}{fixfilepath}) {
+        require Cwd;
+
+        $build_path = $ENV{DEB_BUILD_PATH} || Cwd::cwd();
+
+        # If we have any unsafe character in the path, disable the flag,
+        # so that we do not need to worry about escaping the characters
+        # on output.
+        if ($build_path =~ m/[^-+:.0-9a-zA-Z~\/_]/) {
+            $use_feature{reproducible}{fixfilepath} = 0;
+        }
+    }
+
     # Warn when the __TIME__, __DATE__ and __TIMESTAMP__ macros are used.
     if ($use_feature{reproducible}{timeless}) {
        $flags->append('CPPFLAGS', '-Wdate-time');
@@ -235,6 +250,19 @@ sub _add_build_flags {
         $flags->append('GCJFLAGS', $map);
     }
 
+    # Avoid storing the build path in the debug symbols and binaries
+    # when the  __FILE__, __BASE_FILE__, and __builtin_FILE() macros are used.
+    if ($use_feature{reproducible}{fixfilepath}) {
+        my $map = '-ffile-prefix-map=' . $build_path . '=.';
+        $flags->append('CFLAGS', $map);
+        $flags->append('CXXFLAGS', $map);
+        $flags->append('OBJCFLAGS', $map);
+        $flags->append('OBJCXXFLAGS', $map);
+        $flags->append('FFLAGS', $map);
+        $flags->append('FCFLAGS', $map);
+        $flags->append('GCJFLAGS', $map);
+    }
+
     ## Area: sanitize
 
     # Handle logical feature interactions.

Attachment: signature.asc
Description: PGP signature


Reply to: