Skip to content

Commit 3883be3

Browse files
committed
Absorb -D_USE_32BIT_TIME_T switch from Perl, if relevant.
Commit 3c163a7'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 ef58b87, 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 3c163a7 was. Discussion: https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com
1 parent a64b5a9 commit 3883be3

File tree

5 files changed

+12
-20
lines changed

5 files changed

+12
-20
lines changed

config/perl.m4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ AC_DEFUN([PGAC_CHECK_PERL_CONFIGS],
5959
# to a different libc ABI than core Postgres uses. The available information
6060
# says that all the symbols that affect Perl's own ABI begin with letters,
6161
# so it should be sufficient to adopt -D switches for symbols not beginning
62-
# with underscore.
62+
# with underscore. An exception is that we need to let through
63+
# -D_USE_32BIT_TIME_T if it's present. (We probably could restrict that to
64+
# only get through on Windows, but for the moment we let it through always.)
6365
# For debugging purposes, let's have the configure output report the raw
6466
# ccflags value as well as the set of flags we chose to adopt.
6567
AC_DEFUN([PGAC_CHECK_PERL_EMBED_CCFLAGS],
@@ -68,7 +70,7 @@ AC_MSG_CHECKING([for CFLAGS recommended by Perl])
6870
perl_ccflags=`$PERL -MConfig -e ['print $Config{ccflags}']`
6971
AC_MSG_RESULT([$perl_ccflags])
7072
AC_MSG_CHECKING([for CFLAGS to compile embedded Perl])
71-
perl_embed_ccflags=`$PERL -MConfig -e ['foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/)}']`
73+
perl_embed_ccflags=`$PERL -MConfig -e ['foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/ || $f =~ /^-D_USE_32BIT_TIME_T/)}']`
7274
AC_SUBST(perl_embed_ccflags)dnl
7375
AC_MSG_RESULT([$perl_embed_ccflags])
7476
])# PGAC_CHECK_PERL_EMBED_CCFLAGS

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7519,7 +7519,7 @@ perl_ccflags=`$PERL -MConfig -e 'print $Config{ccflags}'`
75197519
$as_echo "$perl_ccflags" >&6; }
75207520
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLAGS to compile embedded Perl" >&5
75217521
$as_echo_n "checking for CFLAGS to compile embedded Perl... " >&6; }
7522-
perl_embed_ccflags=`$PERL -MConfig -e 'foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/)}'`
7522+
perl_embed_ccflags=`$PERL -MConfig -e 'foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/ || $f =~ /^-D_USE_32BIT_TIME_T/)}'`
75237523
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $perl_embed_ccflags" >&5
75247524
$as_echo "$perl_embed_ccflags" >&6; }
75257525

src/tools/msvc/MSBuildProject.pm

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,16 @@ EOF
6363
</PropertyGroup>
6464
EOF
6565

66-
# We have to use this flag on 32 bit targets because the 32bit perls
67-
# are built with it and sometimes crash if we don't.
68-
my $use_32bit_time_t =
69-
$self->{platform} eq 'Win32' ? '_USE_32BIT_TIME_T;' : '';
70-
7166
$self->WriteItemDefinitionGroup(
7267
$f, 'Debug',
73-
{ defs => "_DEBUG;DEBUG=1;$use_32bit_time_t",
68+
{ defs => "_DEBUG;DEBUG=1",
7469
opt => 'Disabled',
7570
strpool => 'false',
7671
runtime => 'MultiThreadedDebugDLL' });
7772
$self->WriteItemDefinitionGroup(
7873
$f,
7974
'Release',
80-
{ defs => "$use_32bit_time_t",
75+
{ defs => "",
8176
opt => 'Full',
8277
strpool => 'true',
8378
runtime => 'MultiThreadedDLL' });

src/tools/msvc/Mkvcbuild.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,15 @@ sub mkvcbuild
521521
my @perl_embed_ccflags;
522522
foreach my $f (split(" ",$Config{ccflags}))
523523
{
524-
if ($f =~ /^-D[^_]/)
524+
if ($f =~ /^-D[^_]/ ||
525+
$f =~ /^-D_USE_32BIT_TIME_T/)
525526
{
526527
$f =~ s/\-D//;
527528
push(@perl_embed_ccflags, $f);
528529
}
529530
}
530531

531-
# XXX this probably is redundant now?
532+
# Also, a hack to prevent duplicate definitions of uid_t/gid_t
532533
push(@perl_embed_ccflags, 'PLPERL_HAVE_UID_GID');
533534

534535
foreach my $f (@perl_embed_ccflags)

src/tools/msvc/VCBuildProject.pm

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,17 @@ sub WriteHeader
3333
<Configurations>
3434
EOF
3535

36-
# We have to use this flag on 32 bit targets because the 32bit perls
37-
# are built with it and sometimes crash if we don't.
38-
my $use_32bit_time_t =
39-
$self->{platform} eq 'Win32' ? '_USE_32BIT_TIME_T;' : '';
40-
41-
4236
$self->WriteConfiguration(
4337
$f, 'Debug',
44-
{ defs => "_DEBUG;DEBUG=1;$use_32bit_time_t",
38+
{ defs => "_DEBUG;DEBUG=1",
4539
wholeopt => 0,
4640
opt => 0,
4741
strpool => 'false',
4842
runtime => 3 });
4943
$self->WriteConfiguration(
5044
$f,
5145
'Release',
52-
{ defs => "$use_32bit_time_t",
46+
{ defs => "",
5347
wholeopt => 0,
5448
opt => 3,
5549
strpool => 'true',

0 commit comments

Comments
 (0)