Absorb -D_USE_32BIT_TIME_T switch from Perl, if relevant.
authorTom Lane <[email protected]>
Mon, 14 Aug 2017 15:48:59 +0000 (11:48 -0400)
committerTom Lane <[email protected]>
Mon, 14 Aug 2017 15:48:59 +0000 (11:48 -0400)
Commit 3c163a7fc's original choice to ignore all #define symbols whose
names begin with underscore turns out to be too simplistic.  On Windows,
some Perl installations are built with -D_USE_32BIT_TIME_T, and we must
absorb that or we get the wrong result for sizeof(PerlInterpreter).

This effectively re-reverts commit ef58b87df, which injected that symbol
in a hacky way, making it apply to all of Postgres not just PL/Perl.
More significantly, it did so on *all* 32-bit Windows builds, even when
the Perl build to be used did not select this option; so that it fails
to work properly with some newer Perl builds.

By making this change, we would be introducing an ABI break in 32-bit
Windows builds; but fortunately we have not used type time_t in any
exported Postgres APIs in a long time.  So it should be OK, both for
PL/Perl itself and for third-party extensions, if an extension library
is built with a different _USE_32BIT_TIME_T setting than the core code.

Patch by me, based on research by Ashutosh Sharma and Robert Haas.
Back-patch to all supported branches, as commit 3c163a7fc was.

Discussion: https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com

config/perl.m4
configure
src/tools/msvc/MSBuildProject.pm
src/tools/msvc/Mkvcbuild.pm
src/tools/msvc/VCBuildProject.pm

index a88ce73941bcc348a65587f10f5e4a4d256d9577..f07e34b0950bc23485d2d0fba9e1dff3dad4dda1 100644 (file)
@@ -58,7 +58,9 @@ AC_DEFUN([PGAC_CHECK_PERL_CONFIGS],
 # to a different libc ABI than core Postgres uses.  The available information
 # says that all the symbols that affect Perl's own ABI begin with letters,
 # so it should be sufficient to adopt -D switches for symbols not beginning
-# with underscore.
+# with underscore.  An exception is that we need to let through
+# -D_USE_32BIT_TIME_T if it's present.  (We probably could restrict that to
+# only get through on Windows, but for the moment we let it through always.)
 # For debugging purposes, let's have the configure output report the raw
 # ccflags value as well as the set of flags we chose to adopt.
 AC_DEFUN([PGAC_CHECK_PERL_EMBED_CCFLAGS],
@@ -67,7 +69,7 @@ AC_MSG_CHECKING([for CFLAGS recommended by Perl])
 perl_ccflags=`$PERL -MConfig -e ['print $Config{ccflags}']`
 AC_MSG_RESULT([$perl_ccflags])
 AC_MSG_CHECKING([for CFLAGS to compile embedded Perl])
-perl_embed_ccflags=`$PERL -MConfig -e ['foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/)}']`
+perl_embed_ccflags=`$PERL -MConfig -e ['foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/ || $f =~ /^-D_USE_32BIT_TIME_T/)}']`
 AC_SUBST(perl_embed_ccflags)dnl
 AC_MSG_RESULT([$perl_embed_ccflags])
 ])# PGAC_CHECK_PERL_EMBED_CCFLAGS
index a2b84bf61c7e091819d139f2abf39ffd6ae1b8ba..5a7e4e0009235621e3bab565a1ea8dadaa6489b5 100755 (executable)
--- a/configure
+++ b/configure
@@ -7326,7 +7326,7 @@ perl_ccflags=`$PERL -MConfig -e 'print $Config{ccflags}'`
 $as_echo "$perl_ccflags" >&6; }
 { $as_echo "$as_me:$LINENO: checking for CFLAGS to compile embedded Perl" >&5
 $as_echo_n "checking for CFLAGS to compile embedded Perl... " >&6; }
-perl_embed_ccflags=`$PERL -MConfig -e 'foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/)}'`
+perl_embed_ccflags=`$PERL -MConfig -e 'foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/ || $f =~ /^-D_USE_32BIT_TIME_T/)}'`
 { $as_echo "$as_me:$LINENO: result: $perl_embed_ccflags" >&5
 $as_echo "$perl_embed_ccflags" >&6; }
 
index dc2e3659f3445425aa15846f68f6b1625503165c..4863ee9c5f6000258127624303a3ef5983e0c399 100644 (file)
@@ -62,21 +62,16 @@ EOF
   </PropertyGroup>
 EOF
 
-   # We have to use this flag on 32 bit targets because the 32bit perls
-   # are built with it and sometimes crash if we don't.
-   my $use_32bit_time_t = 
-     $self->{platform} eq 'Win32' ? '_USE_32BIT_TIME_T;' : '';
-
    $self->WriteItemDefinitionGroup(
        $f, 'Debug',
-       {   defs    => "_DEBUG;DEBUG=1;$use_32bit_time_t",
+       {   defs    => "_DEBUG;DEBUG=1",
            opt     => 'Disabled',
            strpool => 'false',
            runtime => 'MultiThreadedDebugDLL' });
    $self->WriteItemDefinitionGroup(
        $f,
        'Release',
-       {   defs    => "$use_32bit_time_t",
+       {   defs    => "",
            opt     => 'Full',
            strpool => 'true',
            runtime => 'MultiThreadedDLL' });
index 7a2c0d14e9174923ba1776bd0129401dc4e9575e..7954773c0520a1e4e59e33f28bc64cbfc7d3aaf9 100644 (file)
@@ -121,14 +121,15 @@ sub mkvcbuild
        my @perl_embed_ccflags;
        foreach my $f (split(" ",$Config{ccflags}))
        {
-           if ($f =~ /^-D[^_]/)
+           if ($f =~ /^-D[^_]/ ||
+               $f =~ /^-D_USE_32BIT_TIME_T/)
            {
                $f =~ s/\-D//;
                push(@perl_embed_ccflags, $f);
            }
        }
 
-       # XXX this probably is redundant now?
+       # Also, a hack to prevent duplicate definitions of uid_t/gid_t
        push(@perl_embed_ccflags, 'PLPERL_HAVE_UID_GID');
 
        foreach my $f (@perl_embed_ccflags)
index 6d04a6b239bd4c9c282f2ffad165cf696615f0df..f4059872ac6aa9dbbd027b008dfcfe50b18b4f61 100644 (file)
@@ -33,15 +33,9 @@ sub WriteHeader
  <Configurations>
 EOF
 
-   # We have to use this flag on 32 bit targets because the 32bit perls
-   # are built with it and sometimes crash if we don't.
-   my $use_32bit_time_t = 
-     $self->{platform} eq 'Win32' ? '_USE_32BIT_TIME_T;' : '';
-
-
    $self->WriteConfiguration(
        $f, 'Debug',
-       {   defs     => "_DEBUG;DEBUG=1;$use_32bit_time_t",
+       {   defs     => "_DEBUG;DEBUG=1",
            wholeopt => 0,
            opt      => 0,
            strpool  => 'false',
@@ -49,7 +43,7 @@ EOF
    $self->WriteConfiguration(
        $f,
        'Release',
-       {   defs     => "$use_32bit_time_t",
+       {   defs     => "",
            wholeopt => 0,
            opt      => 3,
            strpool  => 'true',