Package: src:dpkg
Version: 1.19.7
Tags: patch
Please add an optimization area (opt, optimization) for extra optimizations like
lto (link time optimization) and pgo (profile guided optimization).
lto can be directly translated into compiler flags, as seen in the attached
patch, assuming that no lto across package boundaries is done (ensured by the
debhelper patch in #939656). The patch assumes that just nolto can be used to
disable lto until an area is introduced in dpkg.
Some upstream packages also provide build support for lto builds, so for these
an option should be given to disable the addition to the compiler flags (like
the nolto in the proposed patch).
pgo doesn't directly translate into compiler flags, but almost always requires
upstream support in the build system. pgo usually is enabled by some configure
options which are specific to the upstream build. pgo usually requires running
a profiling task, so this optimization probably should be disabled for cross
builds, otoh, the cross build then is different to the native build (although it
should create a functional identical package).
diff -Nru dpkg-1.19.7/debian/changelog dpkg-1.19.7.1/debian/changelog
--- dpkg-1.19.7/debian/changelog 2019-06-03 23:22:35.000000000 +0200
+++ dpkg-1.19.7.1/debian/changelog 2019-09-17 11:54:05.000000000 +0200
@@ -1,3 +1,10 @@
+dpkg (1.19.7.1) UNRELEASED; urgency=medium
+
+ * Non-maintainer upload.
+ * dpkg-buildflags: Turn on LTO by default.
+
+ -- Matthias Klose <[email protected]> Tue, 17 Sep 2019 11:54:05 +0200
+
dpkg (1.19.7) unstable; urgency=medium
[ Guillem Jover ]
diff -Nru dpkg-1.19.7/scripts/Dpkg/Vendor/Debian.pm dpkg-1.19.7.1/scripts/Dpkg/Vendor/Debian.pm
--- dpkg-1.19.7/scripts/Dpkg/Vendor/Debian.pm 2019-04-19 04:14:13.000000000 +0200
+++ dpkg-1.19.7.1/scripts/Dpkg/Vendor/Debian.pm 2019-09-17 11:54:05.000000000 +0200
@@ -158,8 +158,11 @@
my $default_flags;
if ($opts_build->has('noopt')) {
$default_flags = '-g -O0';
- } else {
+ } elsif ($opts_build->has('nolto') or $opts_maint->has('nolto')) {
$default_flags = '-g -O2';
+ $flags->append('LDFLAGS', '-fno-lto');
+ } else {
+ $default_flags = '-g -O2 -flto=auto -ffat-lto-objects';
}
$flags->append('CFLAGS', $default_flags);
$flags->append('CXXFLAGS', $default_flags);