PL/Perl portability fix: absorb relevant -D switches from Perl.

The Perl documentation is very clear that stuff calling libperl should
be built with the compiler switches shown by Perl's $Config{ccflags}.
We'd been ignoring that up to now, and mostly getting away with it,
but recent Perl versions contain ABI compatibility cross-checks that
fail on some builds because of this omission.  In particular the
sizeof(PerlInterpreter) can come out different due to some fields being
added or removed; which means we have a live ABI hazard that we'd better
fix rather than continuing to sweep it under the rug.

However, it still seems like a bad idea to just absorb $Config{ccflags}
verbatim.  In some environments Perl was built with a different compiler
that doesn't even use the same switch syntax.  -D switch syntax is pretty
universal though, and absorbing Perl's -D switches really ought to be
enough to fix the problem.

Furthermore, Perl likes to inject stuff like -D_LARGEFILE_SOURCE and
-D_FILE_OFFSET_BITS=64 into $Config{ccflags}, which affect libc ABIs on
platforms where they're relevant.  Adopting those seems dangerous too.
It's unclear whether a build wherein Perl and Postgres have different ideas
of sizeof(off_t) etc would work, or whether anyone would care about making
it work.  But it's dead certain that having different stdio ABIs in
core Postgres and PL/Perl will not work; we've seen that movie before.
Therefore, let's also ignore -D switches for symbols beginning with
underscore.  The symbols that we actually need to import should be the ones
mentioned in perl.h's PL_bincompat_options stanza, and none of those start
with underscore, so this seems likely to work.  (If it turns out not to
work everywhere, we could consider intersecting the symbols mentioned in
PL_bincompat_options with the -D switches.  But that will be much more
complicated, so let's try this way first.)

This will need to be back-patched, but first let's see what the
buildfarm makes of it.

Ashutosh Sharma, some adjustments by me

Discussion: https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com
This commit is contained in:
Tom Lane 2017-07-28 14:25:28 -04:00
parent bebe174bb4
commit 3c163a7fc7
7 changed files with 71 additions and 4 deletions

View file

@ -49,6 +49,31 @@ AC_DEFUN([PGAC_CHECK_PERL_CONFIGS],
[m4_foreach([pgac_item], [$1], [PGAC_CHECK_PERL_CONFIG(pgac_item)])])
# PGAC_CHECK_PERL_EMBED_CCFLAGS
# -----------------------------
# We selectively extract stuff from $Config{ccflags}. We don't really need
# anything except -D switches, and other sorts of compiler switches can
# actively break things if Perl was compiled with a different compiler.
# Moreover, although Perl likes to put stuff like -D_LARGEFILE_SOURCE and
# -D_FILE_OFFSET_BITS=64 here, it would be fatal to try to compile PL/Perl
# 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.
# 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],
[AC_REQUIRE([PGAC_PATH_PERL])
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[^_]/)}']`
AC_SUBST(perl_embed_ccflags)dnl
AC_MSG_RESULT([$perl_embed_ccflags])
])# PGAC_CHECK_PERL_EMBED_CCFLAGS
# PGAC_CHECK_PERL_EMBED_LDFLAGS
# -----------------------------
# We are after Embed's ldopts, but without the subset mentioned in

13
configure vendored
View file

@ -668,6 +668,7 @@ python_version
python_majorversion
PYTHON
perl_embed_ldflags
perl_embed_ccflags
perl_useshrplib
perl_privlibexp
perl_archlibexp
@ -7767,6 +7768,18 @@ documentation for details. Use --without-perl to disable building
PL/Perl." "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLAGS recommended by Perl" >&5
$as_echo_n "checking for CFLAGS recommended by Perl... " >&6; }
perl_ccflags=`$PERL -MConfig -e 'print $Config{ccflags}'`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $perl_ccflags" >&5
$as_echo "$perl_ccflags" >&6; }
{ $as_echo "$as_me:${as_lineno-$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[^_]/)}'`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $perl_embed_ccflags" >&5
$as_echo "$perl_embed_ccflags" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for flags to link embedded Perl" >&5
$as_echo_n "checking for flags to link embedded Perl... " >&6; }
if test "$PORTNAME" = "win32" ; then

View file

@ -938,6 +938,7 @@ You might have to rebuild your Perl installation. Refer to the
documentation for details. Use --without-perl to disable building
PL/Perl.])
fi
PGAC_CHECK_PERL_EMBED_CCFLAGS
PGAC_CHECK_PERL_EMBED_LDFLAGS
fi

View file

@ -38,4 +38,4 @@ endif
# last, probably because it sometimes contains some header files with names
# that clash with some of ours, or with some that we include, notably on
# Windows.
override CPPFLAGS := $(CPPFLAGS) -I$(perl_archlibexp)/CORE
override CPPFLAGS := $(CPPFLAGS) $(perl_embed_ccflags) -I$(perl_archlibexp)/CORE

View file

@ -304,6 +304,7 @@ else
endif
perl_archlibexp = @perl_archlibexp@
perl_privlibexp = @perl_privlibexp@
perl_embed_ccflags = @perl_embed_ccflags@
perl_embed_ldflags = @perl_embed_ldflags@
# Miscellaneous

View file

@ -12,7 +12,11 @@ override CPPFLAGS += -DPLPERL_HAVE_UID_GID
override CPPFLAGS += -Wno-comment
endif
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) -I$(perl_archlibexp)/CORE
# Note: we need to make sure that the CORE directory is included last,
# probably because it sometimes contains some header files with names
# that clash with some of ours, or with some that we include, notably on
# Windows.
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) $(perl_embed_ccflags) -I$(perl_archlibexp)/CORE
rpathdir = $(perl_archlibexp)/CORE

View file

@ -517,7 +517,26 @@ sub mkvcbuild
my $plperl =
$solution->AddProject('plperl', 'dll', 'PLs', 'src/pl/plperl');
$plperl->AddIncludeDir($solution->{options}->{perl} . '/lib/CORE');
$plperl->AddDefine('PLPERL_HAVE_UID_GID');
# Add defines from Perl's ccflags; see PGAC_CHECK_PERL_EMBED_CCFLAGS
my @perl_embed_ccflags;
foreach my $f (split(" ",$Config{ccflags}))
{
if ($f =~ /^-D[^_]/)
{
$f =~ s/\-D//;
push(@perl_embed_ccflags, $f);
}
}
# XXX this probably is redundant now?
push(@perl_embed_ccflags, 'PLPERL_HAVE_UID_GID');
foreach my $f (@perl_embed_ccflags)
{
$plperl->AddDefine($f);
}
foreach my $xs ('SPI.xs', 'Util.xs')
{
(my $xsc = $xs) =~ s/\.xs/.c/;
@ -601,7 +620,11 @@ sub mkvcbuild
'hstore_plperl', 'contrib/hstore_plperl',
'plperl', 'src/pl/plperl',
'hstore', 'contrib/hstore');
$hstore_plperl->AddDefine('PLPERL_HAVE_UID_GID');
foreach my $f (@perl_embed_ccflags)
{
$hstore_plperl->AddDefine($f);
}
}
$mf =