diff --git a/man/dpkg-buildflags.pod b/man/dpkg-buildflags.pod index adf496f1d4a9487a770209b36964711a37e39425..8af1d221ba508bb995cd8efa80afe9cf4592b8c8 100644 --- a/man/dpkg-buildflags.pod +++ b/man/dpkg-buildflags.pod @@ -354,6 +354,24 @@ B<LDFLAGS> set to B<-Wl,-z,deb-canary->I<random-id>. =back +=head2 optimize + +Several compile-time options (detailed below) can be used to help optimize +a resulting binary (since dpkg 1.21.0). +B<Note>: enabling B<all> these options can result in unreproducible binary +artifacts. + +=over + +=item lto + +This setting (since dpkg 1.21.0; disabled by default) enables +Link Time Optimization by adding B<-flto=auto -ffat-lto-objects> to +B<CFLAGS>, B<CXXFLAGS>, B<OBJCFLAGS>, B<OBJCXXFLAGS>, B<GCJFLAGS>, +B<FFLAGS>, B<FCFLAGS> and B<LDFLAGS>. + +=back + =head2 sanitize Several compile-time options (detailed below) can be used to help sanitize diff --git a/scripts/Dpkg/Vendor/Debian.pm b/scripts/Dpkg/Vendor/Debian.pm index 7e1c0b1f15a82893db1b4b08de54dc2a61cbd81b..6b3e1dd4ac1f29b6022afeb30ce87f87f3d1c2bc 100644 --- a/scripts/Dpkg/Vendor/Debian.pm +++ b/scripts/Dpkg/Vendor/Debian.pm @@ -108,6 +108,9 @@ sub _add_build_flags { fixfilepath => 1, fixdebugpath => 1, }, + optimize => { + lto => 0, + }, sanitize => { address => 0, thread => 0, @@ -268,6 +271,13 @@ sub _add_build_flags { $flags->append($_, $map) foreach @compile_flags; } + ## Area: optimize + + if ($use_feature{optimize}{lto}) { + my $flag = '-flto=auto -ffat-lto-objects'; + $flags->append($_, $flag) foreach (@compile_flags, 'LDFLAGS'); + } + ## Area: sanitize # Handle logical feature interactions. diff --git a/scripts/t/Dpkg_BuildFlags.t b/scripts/t/Dpkg_BuildFlags.t index 9faf19146de394f403596f21d00c24160cdfa00a..d2d3d7aee56c298bb74c0104f1817e28c29c9d28 100644 --- a/scripts/t/Dpkg_BuildFlags.t +++ b/scripts/t/Dpkg_BuildFlags.t @@ -16,7 +16,7 @@ use strict; use warnings; -use Test::More tests => 26; +use Test::More tests => 28; BEGIN { $ENV{DEB_BUILD_ARCH} = 'amd64'; @@ -71,6 +71,9 @@ my %known_features = ( fixfilepath timeless ) ], + optimize => [ qw( + lto + ) ], sanitize => [ qw( address leak