This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=df7627acfadca528e52147cc777fa01b2ed802b4

commit df7627acfadca528e52147cc777fa01b2ed802b4
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Dec 10 19:44:20 2022 +0100

    Dpkg::Vendor::Ubuntu: Handle LTO by default using new feature overrides
---
 scripts/Dpkg/Vendor/Ubuntu.pm      |  6 ++++++
 scripts/t/Dpkg_BuildFlags_Ubuntu.t | 13 ++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/scripts/Dpkg/Vendor/Ubuntu.pm b/scripts/Dpkg/Vendor/Ubuntu.pm
index 228e5a429..df42580e2 100644
--- a/scripts/Dpkg/Vendor/Ubuntu.pm
+++ b/scripts/Dpkg/Vendor/Ubuntu.pm
@@ -24,6 +24,8 @@ use warnings;
 
 our $VERSION = '0.01';
 
+use List::Util qw(any);
+
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
 use Dpkg::Control::Types;
@@ -115,6 +117,10 @@ sub set_build_features {
     require Dpkg::Arch;
     my $arch = Dpkg::Arch::get_host_arch();
 
+    if (any { $_ eq $arch } qw(amd64 arm64 ppc64el s390x)) {
+        $flags->set_feature('optimize', 'lto', 1);
+    }
+
     if ($arch eq 'ppc64el' && $flags->get_option_value('optimize-level') != 0) 
{
         $flags->set_option_value('optimize-level', 3);
     }
diff --git a/scripts/t/Dpkg_BuildFlags_Ubuntu.t 
b/scripts/t/Dpkg_BuildFlags_Ubuntu.t
index 3cfdb268f..193e49269 100644
--- a/scripts/t/Dpkg_BuildFlags_Ubuntu.t
+++ b/scripts/t/Dpkg_BuildFlags_Ubuntu.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16;
+use Test::More tests => 18;
 
 BEGIN {
     use_ok('Dpkg::BuildFlags');
@@ -33,6 +33,15 @@ sub test_optflag
     }
 }
 
+sub test_ltoflag
+{
+    my $bf = shift;
+
+    # Test the LTO flags enabled by default on some arches.
+    ok($bf->get('LDFLAGS') =~ m/-flto=auto -ffat-lto-objects/,
+        "LDFLAGS contains LTO flags on $ENV{DEB_HOST_ARCH}");
+}
+
 my $bf;
 
 # Force loading the Dpkg::Vendor::Ubuntu module.
@@ -43,6 +52,7 @@ $ENV{DEB_HOST_ARCH} = 'amd64';
 $bf = Dpkg::BuildFlags->new();
 
 test_optflag($bf, '-O2');
+test_ltoflag($bf);
 
 # Test the overlaid Ubuntu-specific linker flag.
 ok($bf->get('LDFLAGS') =~ m/-Wl,-Bsymbolic-functions/,
@@ -53,5 +63,6 @@ $ENV{DEB_HOST_ARCH} = 'ppc64el';
 $bf = Dpkg::BuildFlags->new();
 
 test_optflag($bf, '-O3');
+test_ltoflag($bf);
 
 1;

-- 
Dpkg.Org's dpkg

Reply via email to