Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1886899

Browse files
committed
MSVC: Test whether 32-bit Perl needs -D_USE_32BIT_TIME_T.
Commits5a5c2fe andb5178c5 introduced support for modernMSVC-built, 32-bit Perl, but they broke use of MinGW-built, 32-bit Perldistributions like Strawberry Perl and modern ActivePerl. Perl has norobust means to report whether it expects a -D_USE_32BIT_TIME_T ABI, sotest this. Back-patch to 9.3 (all supported versions).The chief alternative was a heuristic of adding -D_USE_32BIT_TIME_T when$Config{gccversion} is nonempty. That banks on every gcc-built Perlusing the same ABI. gcc could change its default ABI the way MSVC oncedid, and one could build Perl with gcc and the non-default ABI.The GNU make build system could benefit from a similar test, withoutwhich it does not support MSVC-built Perl. For now, just add a comment.Most users taking the special step of building Perl with MSVC probablybuild PostgreSQL with MSVC.Discussion:https://postgr.es/m/20171130041441.GA3161526@rfd.leadboat.com
1 parent99aa36d commit1886899

File tree

2 files changed

+158
-41
lines changed

2 files changed

+158
-41
lines changed

‎config/perl.m4

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,23 @@ AC_DEFUN([PGAC_CHECK_PERL_CONFIGS],
5151

5252
# PGAC_CHECK_PERL_EMBED_CCFLAGS
5353
# -----------------------------
54-
# We selectively extract stuff from $Config{ccflags}. We don't really need
55-
# anything except -D switches, and other sorts of compiler switches can
56-
# actively break things if Perl was compiled with a different compiler.
57-
# Moreover, although Perl likes to put stuff like -D_LARGEFILE_SOURCE and
58-
# -D_FILE_OFFSET_BITS=64 here, it would be fatal to try to compile PL/Perl
59-
# to a different libc ABI than core Postgres uses. The available information
60-
# says that all the symbols that affect Perl's own ABI begin with letters,
61-
# so it should be sufficient to adopt -D switches for symbols not beginning
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.)
65-
# For debugging purposes, let's have the configure output report the raw
66-
# ccflags value as well as the set of flags we chose to adopt.
54+
# We selectively extract stuff from $Config{ccflags}. For debugging purposes,
55+
# let's have the configure output report the raw ccflags value as well as the
56+
# set of flags we chose to adopt. We don't really need anything except -D
57+
# switches, and other sorts of compiler switches can actively break things if
58+
# Perl was compiled with a different compiler. Moreover, although Perl likes
59+
# to put stuff like -D_LARGEFILE_SOURCE and -D_FILE_OFFSET_BITS=64 here, it
60+
# would be fatal to try to compile PL/Perl to a different libc ABI than core
61+
# Postgres uses. The available information says that most symbols that affect
62+
# Perl's own ABI begin with letters, so it's almost sufficient to adopt -D
63+
# switches for symbols not beginning with underscore. Some exceptions are the
64+
# Windows-specific -D_USE_32BIT_TIME_T and -D__MINGW_USE_VC2005_COMPAT; see
65+
# Mkvcbuild.pm for details. We absorb the former when Perl reports it. Perl
66+
# never reports the latter, and we don't attempt to deduce when it's needed.
67+
# Consequently, we don't support using MinGW to link to MSVC-built Perl. As
68+
# of 2017, all supported ActivePerl and Strawberry Perl are MinGW-built. If
69+
# that changes or an MSVC-built Perl distribution becomes prominent, we can
70+
# revisit this limitation.
6771
AC_DEFUN([PGAC_CHECK_PERL_EMBED_CCFLAGS],
6872
[AC_REQUIRE([PGAC_PATH_PERL])
6973
AC_MSG_CHECKING([for CFLAGS recommended by Perl])

‎src/tools/msvc/Mkvcbuild.pm

Lines changed: 141 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ my $libpgport;
2828
my$libpgcommon;
2929
my$postgres;
3030
my$libpq;
31+
my@unlink_on_exit;
3132

3233
my$contrib_defines = {'refint'=>'REFINT_VERBOSE' };
3334
my@contrib_uselibpq =
@@ -140,34 +141,154 @@ sub mkvcbuild
140141
my$plperl =
141142
$solution->AddProject('plperl','dll','PLs','src\pl\plperl');
142143
$plperl->AddIncludeDir($solution->{options}->{perl} .'/lib/CORE');
144+
$plperl->AddReference($postgres);
145+
146+
my$perl_path =$solution->{options}->{perl} .'\lib\CORE\*perl*';
147+
148+
# ActivePerl 5.16 provided perl516.lib; 5.18 provided libperl518.a
149+
my@perl_libs =
150+
grep {/perl\d+\.lib$|libperl\d+\.a$/ }glob($perl_path);
151+
if (@perl_libs == 1)
152+
{
153+
$plperl->AddLibrary($perl_libs[0]);
154+
}
155+
else
156+
{
157+
die
158+
"could not identify perl library version matching pattern$perl_path\n";
159+
}
143160

144161
# Add defines from Perl's ccflags; see PGAC_CHECK_PERL_EMBED_CCFLAGS
145162
my@perl_embed_ccflags;
146163
foreachmy$f (split("",$Config{ccflags}))
147164
{
148-
if ($f =~/^-D[^_]/ ||
149-
$f =~/^-D_USE_32BIT_TIME_T/)
165+
if ($f =~/^-D[^_]/)
150166
{
151167
$f =~s/\-D//;
152168
push(@perl_embed_ccflags,$f);
153169
}
154170
}
155171

156-
# Perl versions before 5.13.4 don't provide -D_USE_32BIT_TIME_T
157-
# regardless of how they were built. On 32-bit Windows, assume
158-
# such a version was built with a pre-MSVC-2005 compiler, and
159-
# define the symbol anyway, so that we are compatible if we're
160-
# being built with a later MSVC version.
161-
push(@perl_embed_ccflags,'_USE_32BIT_TIME_T')
162-
if$solution->{platform}eq'Win32'
163-
&&$Config{PERL_REVISION} == 5
164-
&& ($Config{PERL_VERSION} < 13
165-
|| ($Config{PERL_VERSION} == 13
166-
&&$Config{PERL_SUBVERSION} < 4));
167-
168-
# Also, a hack to prevent duplicate definitions of uid_t/gid_t
172+
# hack to prevent duplicate definitions of uid_t/gid_t
169173
push(@perl_embed_ccflags,'PLPERL_HAVE_UID_GID');
170174

175+
# Windows offers several 32-bit ABIs. Perl is sensitive to
176+
# sizeof(time_t), one of the ABI dimensions. To get 32-bit time_t,
177+
# use "cl -D_USE_32BIT_TIME_T" or plain "gcc". For 64-bit time_t, use
178+
# "gcc -D__MINGW_USE_VC2005_COMPAT" or plain "cl". Before MSVC 2005,
179+
# plain "cl" chose 32-bit time_t. PostgreSQL doesn't support building
180+
# with pre-MSVC-2005 compilers, but it does support linking to Perl
181+
# built with such a compiler. MSVC-built Perl 5.13.4 and later report
182+
# -D_USE_32BIT_TIME_T in $Config{ccflags} if applicable, but
183+
# MinGW-built Perl never reports -D_USE_32BIT_TIME_T despite typically
184+
# needing it. Ignore the $Config{ccflags} opinion about
185+
# -D_USE_32BIT_TIME_T, and use a runtime test to deduce the ABI Perl
186+
# expects. Specifically, test use of PL_modglobal, which maps to a
187+
# PerlInterpreter field whose position depends on sizeof(time_t).
188+
if ($solution->{platform}eq'Win32')
189+
{
190+
my$source_file ='conftest.c';
191+
my$obj ='conftest.obj';
192+
my$exe ='conftest.exe';
193+
my@conftest = ($source_file,$obj,$exe);
194+
push@unlink_on_exit,@conftest;
195+
unlink$source_file;
196+
openmy$o,'>',$source_file
197+
|| croak"Could not write to$source_file";
198+
print$o'
199+
/* compare to plperl.h */
200+
#define __inline__ __inline
201+
#define PERL_NO_GET_CONTEXT
202+
#include <EXTERN.h>
203+
#include <perl.h>
204+
205+
int
206+
main(int argc, char **argv)
207+
{
208+
intdummy_argc = 1;
209+
char *dummy_argv[1] = {""};
210+
char *dummy_env[1] = {NULL};
211+
static PerlInterpreter *interp;
212+
213+
PERL_SYS_INIT3(&dummy_argc, (char ***) &dummy_argv,
214+
(char ***) &dummy_env);
215+
interp = perl_alloc();
216+
perl_construct(interp);
217+
{
218+
dTHX;
219+
const charkey[] = "dummy";
220+
221+
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
222+
hv_store(PL_modglobal, key, sizeof(key) - 1, newSViv(1), 0);
223+
return hv_fetch(PL_modglobal, key, sizeof(key) - 1, 0) == NULL;
224+
}
225+
}
226+
';
227+
close$o;
228+
229+
# Build $source_file with a given #define, and return a true value
230+
# if a run of the resulting binary exits successfully.
231+
my$try_define =sub {
232+
my$define =shift;
233+
234+
unlink$obj,$exe;
235+
my@cmd = (
236+
'cl',
237+
'-I' .$solution->{options}->{perl} .'/lib/CORE',
238+
(map {"-D$_" }@perl_embed_ccflags,$define || ()),
239+
$source_file,
240+
'/link',
241+
$perl_libs[0]);
242+
my$compile_output =`@cmd 2>&1`;
243+
-f$exe ||die"Failed to build Perl test:\n$compile_output";
244+
245+
{
246+
247+
# Some builds exhibit runtime failure through Perl warning
248+
# 'Can't spawn "conftest.exe"'; supress that.
249+
no warnings;
250+
251+
# Disable error dialog boxes like we do in the postmaster.
252+
# Here, we run code that triggers relevant errors.
253+
use Win32API::Fileqw(SetErrorMode :SEM_);
254+
my$oldmode = SetErrorMode(
255+
SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
256+
system(".\\$exe");
257+
SetErrorMode($oldmode);
258+
}
259+
260+
return !($? >> 8);
261+
};
262+
263+
my$define_32bit_time ='_USE_32BIT_TIME_T';
264+
my$ok_now =$try_define->(undef);
265+
my$ok_32bit =$try_define->($define_32bit_time);
266+
unlink@conftest;
267+
if (!$ok_now && !$ok_32bit)
268+
{
269+
270+
# Unsupported configuration. Since we used %Config from the
271+
# Perl running the build scripts, this is expected if
272+
# attempting to link with some other Perl.
273+
die"Perl test fails with or without -D$define_32bit_time";
274+
}
275+
elsif ($ok_now &&$ok_32bit)
276+
{
277+
278+
# Resulting build may work, but it's especially important to
279+
# verify with "vcregress plcheck". A refined test may avoid
280+
# this outcome.
281+
warn"Perl test passes with or without -D$define_32bit_time";
282+
}
283+
elsif ($ok_32bit)
284+
{
285+
push(@perl_embed_ccflags,$define_32bit_time);
286+
}# else $ok_now, hence no flag required
287+
}
288+
289+
print"CFLAGS recommended by Perl:$Config{ccflags}\n";
290+
print"CFLAGS to compile embedded Perl:",
291+
(join'',map {"-D$_" }@perl_embed_ccflags),"\n";
171292
foreachmy$f (@perl_embed_ccflags)
172293
{
173294
$plperl->AddDefine($f);
@@ -237,19 +358,6 @@ sub mkvcbuild
237358
die'Failed to create plperl_opmask.h' ."\n";
238359
}
239360
}
240-
$plperl->AddReference($postgres);
241-
my$perl_path =$solution->{options}->{perl} .'\lib\CORE\*perl*';
242-
# ActivePerl 5.16 provided perl516.lib; 5.18 provided libperl518.a
243-
my@perl_libs =
244-
grep {/perl\d+\.lib$|libperl\d+\.a$/ }glob($perl_path);
245-
if (@perl_libs == 1)
246-
{
247-
$plperl->AddLibrary($perl_libs[0]);
248-
}
249-
else
250-
{
251-
die"could not identify perl library version";
252-
}
253361
}
254362

255363
if ($solution->{options}->{python})
@@ -839,4 +947,9 @@ sub AdjustContribProj
839947
}
840948
}
841949

950+
END
951+
{
952+
unlink@unlink_on_exit;
953+
}
954+
842955
1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp