Re: pl/perl extension fails on Windows
Ashutosh Sharma <ashu.coek88@gmail.com>
From: Ashutosh Sharma <ashu.coek88@gmail.com>
To: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Cc: Dave Page <dpage@pgadmin.org>, Tom Lane <tgl@sss.pgh.pa.us>, Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2017-07-13T12:08:37Z
Lists: pgsql-hackers
On Thu, Jul 13, 2017 at 12:01 AM, Andrew Dunstan
<andrew.dunstan@2ndquadrant.com> wrote:
> On 07/12/2017 11:49 AM, Dave Page wrote:
>>
>>
>> Well crake is a Fedora box - and we have no problems on Linux, only on
>> Windows.
>>
>>
>
>
> Yeah, I have this on one of my Windows boxes, and haven't had time to
> get to the bottom of it yet ;-(
>
I could also see this problem in my Windows machine and I have spent
some time to analyse it. Here are my findings:
The stacktrace where the crash happens is:
perl524.dll!Perl_xs_handshake(const unsigned long key, void
*v_my_perl, const char * file, ...) Line 5569 C
plperl.dll!boot_PostgreSQL__InServer__Util(interpreter * my_perl, cv
* cv) Line 490 + 0x22 bytes C
perl524.dll!Perl_pp_entersub(interpreter * my_perl) Line 3987 + 0xc bytes C
perl524.dll!Perl_runops_standard(interpreter * my_perl) Line 41 + 0x6 bytes C
perl524.dll!S_run_body(interpreter * my_perl, long oldscope) Line 2485 C
perl524.dll!perl_run(interpreter * my_perl) Line 2406 + 0xc bytes C
plperl.dll!plperl_init_interp() Line 829 + 0xb bytes C
plperl.dll!_PG_init() Line 470 + 0x5 bytes C
I couldn't get much out of above bt, but, one thing i could notice is
that the input key passed to 'Perl_xs_handshake()' function is not
matching with the key being generated inside 'Perl_xs_handshake()',
hence, the handshaking is failing.
Please have a look into the following code snippet from 'perl 5.24'
and 'Util.c' file in plperl respectively,
Perl-5.24:
=======
got = INT2PTR(void*, (UV)(key & HSm_KEY_MATCH));
need = (void *)(HS_KEY(FALSE, FALSE, "", "") & HSm_KEY_MATCH);
if (UNLIKELY(got != need))
goto bad_handshake;
Util.c in plperl:
==========
485 XS_EXTERNAL(boot_PostgreSQL__InServer__Util)
486 {
487 #if PERL_VERSION_LE(5, 21, 5)
488 dVAR; dXSARGS;
489 #else
490 dVAR; dXSBOOTARGSAPIVERCHK;
Actually the macro 'dXSBOOTARGSAPIVERCHK' in line #490 gets expanded to,
#define XS_APIVERSION_SETXSUBFN_POPMARK_BOOTCHECK
\
Perl_xs_handshake(HS_KEY(TRUE, TRUE, "v" PERL_API_VERSION_STRING,
""), \
HS_CXT, __FILE__, "v" PERL_API_VERSION_STRING)
And the point to be noted is, the way, the key is being generated in
above macro and in Perl_xs_handshake(). As shown above,
'XS_APIVERSION_SETXSUBFN_POPMARK_BOOTCHECK' macro passes
'PERL_API_VERSION_STRING' as input to HS_KEY() to generate the key and
this key is passed to Perl_xs_handshake function whereas inside
Perl_xs_handshake(), there is no such version string being used to
generate the key. Hence, the key mismatch is seen thereby resulting in
a bad_handshake error.
After doing some study, I could understand that Util.c is generated
from Util.xs by xsubpp compiler at build time. This is being done in
Mkvcbuild.pm file in postgres. If I manually replace
'dXSBOOTARGSAPIVERCHK' macro with 'dXSBOOTARGSNOVERCHK' macro in
src/pl/plperl/Util.c, the things work fine. The diff is as follows,
XS_EXTERNAL(boot_PostgreSQL__InServer__Util)
{
#if PERL_VERSION_LE(5, 21, 5)
dVAR; dXSARGS;
#else
- dVAR; dXSBOOTARGSAPIVERCHK;
+ dVAR; dXSBOOTARGSNOVERCHK;
I need to further investigate, but let me know if you have any ideas.
>
> Latest versions of ActivePerl don't ship with library descriptor files,
> either, which is unpleasant.
>
I too had similar observation and surprisingly, I am seeing
'libperl*.a' file instead of 'perl*.lib' file in most of the
ActiverPerl versions for Windows.
--
With Regards,
Ashutosh Sharma
EnterpriseDB:http://www.enterprisedb.com
Commits
-
MSVC: Test whether 32-bit Perl needs -D_USE_32BIT_TIME_T.
- 1886899420ce 9.3.21 landed
- aed8d41af628 9.4.16 landed
- 1c1a572d055f 9.5.11 landed
- 140fa2fbad94 9.6.7 landed
- 9b5c99790e83 10.2 landed
- 65a00f30352a 11.0 landed
-
Further tweaks to compiler flags for PL/Perl on Windows.
- f7e4783ddbef 9.2.23 landed
- bc4404405f21 9.3.19 landed
- 4f862351d20b 9.4.14 landed
- bff216d8789f 9.5.9 landed
- c343314882f1 9.6.5 landed
- 1d7a479d22f6 10.0 landed
- b5178c5d08ca 11.0 landed
-
Absorb -D_USE_32BIT_TIME_T switch from Perl, if relevant.
- e3335ec0b6a6 9.2.23 landed
- 5a5c2feca3fd 10.0 landed
- 3883be3eae97 9.6.5 landed
- 25169b948e13 9.3.19 landed
- 1621a75531c8 9.5.9 landed
- 01de7ea85378 9.4.14 landed
-
PL/Perl portability fix: absorb relevant -D switches from Perl.
- df52739ce3e7 9.5.8 landed
- 9cbdc689418b 9.4.13 landed
- 456c7dff2af1 9.2.22 landed
- 1e58c503ec46 9.6.4 landed
- 0d8f015e7726 9.3.18 landed
- 3c163a7fc76d 10.0 landed
-
PL/Perl portability fix: avoid including XSUB.h in plperl.c.
- d48180ec812d 9.4.13 landed
- b92f17277eb9 9.3.18 landed
- b4b958251fbf 9.2.22 landed
- 99eea89dbe31 9.5.8 landed
- 30a5c8bfbd7b 9.6.4 landed
- bebe174bb446 10.0 landed