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=1f0ebe1945724fd57fd3984af0031ce9bf55b524

commit 1f0ebe1945724fd57fd3984af0031ce9bf55b524
Author: Guillem Jover <[email protected]>
AuthorDate: Tue Feb 27 04:19:53 2024 +0100

    Dpkg::Vendor::Debian: Enable time64 feature by default except on <some>-i386
    
    On Debian the plan is to switch all architectures to default to time64,
    except for i386 (which is left to use time32 for backwards binary
    compatibility reasons), and hurd-i386 and kfreebsd-i386 (which do not
    have time64 support).
    
    In addition, the default compiler (gcc) also emits the necessary
    pre-processor flags on armel, armhf, hppa, m68k, mips, mipsel, powerpc
    and sh4, so for those if the user has explicitly requested abi=-time64
    we need to emit options to unset the macros.
    
    If the user explicitly requests abi=+time64, then it will be enabled
    everywhere (except for hurd-i386 and kfreebsd-i386 where the kernel does
    not support it), so that it can be requested explicitly on packages that
    want or need to be time64 aware regardless of the default exception, and
    so that we do not break any ABI with packages that might have already
    opted in.
    
    Based-on-patch-by: Steve Langasek <[email protected]>
    Closes: #1037136
---
 man/dpkg-buildflags.pod       |  26 +++++++++--
 scripts/Dpkg/Vendor/Debian.pm |  35 +++++++++++++-
 scripts/t/Dpkg_BuildFlags.t   | 105 +++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 161 insertions(+), 5 deletions(-)

diff --git a/man/dpkg-buildflags.pod b/man/dpkg-buildflags.pod
index bed746d5b..b661e3562 100644
--- a/man/dpkg-buildflags.pod
+++ b/man/dpkg-buildflags.pod
@@ -465,11 +465,31 @@ feature in the B<future> feature area.
 
 =item B<time64>
 
-This setting (since dpkg 1.22.0; disabled by default) enables 64-bit time_t
-support on 32-bit architectures where their ABI does not include it by
-default, by adding B<-D_TIME_BITS=64> to B<CPPFLAGS>.
+This setting (since dpkg 1.22.0; enabled by default except for i386,
+hurd-i386 and kfreebsd-i386 since dpkg 1.22.5) enables 64-bit time_t support
+on 32-bit architectures where their ABI does not include it by default,
+by adding B<-D_TIME_BITS=64> to B<CPPFLAGS>.
 This setting automatically enables the B<lfs> feature as it requires it.
 
+If the setting is enabled explicitly then it gets enabled on all
+architectures including i386 but not hurd-i386 nor kfreebsd-i386
+(where the kernel does not have time64 interfaces),
+ignoring the binary backwards compatibility default.
+
+It is also enabled by default by gcc on the
+armel,
+armhf,
+hppa,
+m68k,
+mips,
+mipsel,
+powerpc
+and
+sh4
+Debian architectures,
+where disabling the feature will add instead
+B<-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS -U_TIME_BITS> to B<CPPFLAGS>.
+
 =back
 
 =head2 future
diff --git a/scripts/Dpkg/Vendor/Debian.pm b/scripts/Dpkg/Vendor/Debian.pm
index 0dbf539fd..3e5f0faec 100644
--- a/scripts/Dpkg/Vendor/Debian.pm
+++ b/scripts/Dpkg/Vendor/Debian.pm
@@ -113,7 +113,8 @@ sub set_build_features {
             # XXX: This is set to undef so that we can handle the alias from
             # the future feature area.
             lfs => undef,
-            time64 => 0,
+            # XXX: This is set to undef to handle mask on the default setting.
+            time64 => undef,
         },
         qa => {
             bug => 0,
@@ -270,6 +271,29 @@ sub set_build_features {
 
     ## Area: abi
 
+    if (any { $arch eq $_ } qw(hurd-i386 kfreebsd-i386)) {
+        # Mask time64 on hurd-i386 and kfreebsd-i386, as their kernel lacks
+        # support for that arch and it will not be implemented.
+        $use_feature{abi}{time64} = 0;
+    } elsif (not defined $use_feature{abi}{time64}) {
+        # If the user has not requested a specific setting, by default only
+        # enable time64 everywhere except for i386, where we preserve it for
+        # binary backwards compatibility.
+        if ($arch eq 'i386') {
+            $use_feature{abi}{time64} = 0;
+        } else {
+            $use_feature{abi}{time64} = 1;
+        }
+    }
+
+    # In Debian gcc enables time64 (and lfs) for the following architectures
+    # by injecting pre-processor flags, though the libc ABI has not changed.
+    if (any { $arch eq $_ } qw(armel armhf hppa m68k mips mipsel powerpc sh4)) 
{
+        $flags->set_option_value('cc-abi-time64', 1);
+    } else {
+        $flags->set_option_value('cc-abi-time64', 0);
+    }
+
     if ($use_feature{abi}{time64} && ! $builtin_feature{abi}{time64}) {
         # On glibc 64-bit time_t support requires LFS.
         $use_feature{abi}{lfs} = 1 if $libc eq 'gnu';
@@ -425,13 +449,22 @@ sub add_build_flags {
     ## Area: abi
 
     my %abi_builtins = $flags->get_builtins('abi');
+    my $cc_abi_time64 = $flags->get_option_value('cc-abi-time64');
+
     if ($flags->use_feature('abi', 'lfs') && ! $abi_builtins{lfs}) {
         $flags->append('CPPFLAGS',
                        '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+    } elsif (! $flags->use_feature('abi', 'lfs') &&
+             ! $abi_builtins{lfs} && $cc_abi_time64) {
+        $flags->append('CPPFLAGS',
+                       '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
     }
 
     if ($flags->use_feature('abi', 'time64') && ! $abi_builtins{time64}) {
         $flags->append('CPPFLAGS', '-D_TIME_BITS=64');
+    } elsif (! $flags->use_feature('abi', 'time64') &&
+             ! $abi_builtins{time64} && $cc_abi_time64) {
+        $flags->append('CPPFLAGS', '-U_TIME_BITS');
     }
 
     ## Area: qa
diff --git a/scripts/t/Dpkg_BuildFlags.t b/scripts/t/Dpkg_BuildFlags.t
index 530871c8a..b1c6d29f4 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 => 40;
+use Test::More tests => 88;
 
 BEGIN {
     $ENV{DEB_BUILD_ARCH} = 'amd64';
@@ -171,4 +171,107 @@ $ENV{DEB_BUILD_MAINT_OPTIONS} = 'future=+lfs abi=-lfs';
 $bf = Dpkg::BuildFlags->new();
 test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
 
+# Test time64 abi features, for a 64-bit system, a 32-bit system with time64
+# and a 32-bit system with time32.
+
+# 32-bit system with time32, time64 not enabled by default.
+$ENV{DEB_BUILD_ARCH} = 'i386';
+$ENV{DEB_HOST_ARCH} = 'i386';
+
+undef $ENV{DEB_BUILD_MAINT_OPTIONS};
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'abi=+time64';
+$bf = Dpkg::BuildFlags->new();
+test_has_flag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_flag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'abi=-time64';
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+# 32-bit system with time32 and no time64.
+$ENV{DEB_BUILD_ARCH} = 'hurd-i386';
+$ENV{DEB_HOST_ARCH} = 'hurd-i386';
+
+undef $ENV{DEB_BUILD_MAINT_OPTIONS};
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'abi=+time64';
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'abi=-time64';
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+# 32-bit system with time32, time64 enabled by default.
+$ENV{DEB_BUILD_ARCH} = 'armhf';
+$ENV{DEB_HOST_ARCH} = 'armhf';
+
+undef $ENV{DEB_BUILD_MAINT_OPTIONS};
+$bf = Dpkg::BuildFlags->new();
+test_has_flag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_flag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'abi=+time64';
+$bf = Dpkg::BuildFlags->new();
+test_has_flag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_flag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'abi=-time64';
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_flag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_flag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+# 64-bit system with built-in time64.
+$ENV{DEB_BUILD_ARCH} = 'amd64';
+$ENV{DEB_HOST_ARCH} = 'amd64';
+
+undef $ENV{DEB_BUILD_MAINT_OPTIONS};
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'abi=+time64';
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'abi=-time64';
+$bf = Dpkg::BuildFlags->new();
+test_has_noflag($bf, 'CPPFLAGS', '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS');
+test_has_noflag($bf, 'CPPFLAGS', '-D_TIME_BITS=64');
+test_has_noflag($bf, 'CPPFLAGS', '-U_TIME_BITS');
+
 # TODO: Add more test cases.

-- 
Dpkg.Org's dpkg

Reply via email to