Hi, On 2021-10-04 14:38:16 -0700, Andres Freund wrote: > 3) When building against strawberry perl 5.32.1.1 I see errors when loading > plperl
The error is: loadable library and perl binaries are mismatched (got handshake key 0000000012800080, needed 0000000012900080) A bunch of research led me to believe this is because the struct sizes of PerlInterpreter differ between perl being compiled and us embedding perl. After a lot of headscratching [1], I got a struct layout of both a gcc compiled (just a test.c including the relevant headers) and and the msvc compiled plperl.dll. And indeed they differ: msvc: +0x42d Iin_utf8_COLLATE_locale : Bool +0x42e Iin_utf8_turkic_locale : Bool +0x42f Ilocale_utf8ness : [256] Char +0x530 Iwarn_locale : Ptr64 sv +0x538 Icolors : [6] Ptr64 Char +0x568 Ipeepp : Ptr64 void .. +0x1278 IPrivate_Use : Ptr64 sv gcc: /* 0x042d | 0x0001 */ _Bool Iin_utf8_COLLATE_locale; /* 0x042e | 0x0001 */ _Bool Iin_utf8_turkic_locale; /* 0x0430 | 0x0004 */ int Ilc_numeric_mutex_depth; /* 0x0434 | 0x0100 */ char Ilocale_utf8ness[256]; /* 0x0538 | 0x0008 */ SV *Iwarn_locale; /* 0x0540 | 0x0030 */ char *Icolors[6]; /* 0x0570 | 0x0008 */ peep_t Ipeepp; ... /* 0x1280 | 0x0008 */ SV *IPrivate_Use; The gcc version has a Ilc_numeric_mutex_depth that the msvc version doesn't. The relevant part of intrpvar.h: PERLVAR(I, in_utf8_turkic_locale, bool) #if defined(USE_ITHREADS) && ! defined(USE_THREAD_SAFE_LOCALE) PERLVARI(I, lc_numeric_mutex_depth, int, 0) /* Emulate general semaphore */ #endif PERLVARA(I, locale_utf8ness, 256, char) This conditional piece didn't yet exist in 5.26.n. Which is why that's the last version that actually works. USE_ITHREADS is defined in perls' config.h, but USE_THREAD_SAFE_LOCALE is derived from some other stuff. So that's the culprit. I gotta do something else for a bit, so I'll stop here for now. The error message about mismatched lib / perl binary could really use a bit more detail. It's pretty darn annoying to figure out right now what it could mean. Greetings, Andres Freund [1] On linux I'd just use pahole to display struct layouts, but on windows... Neither of the windows perl installations comes with debug symbols, afaict. For the gcc definition: I compiled a test.c with msys ucrt64, including -g3, set a breakpoint on main, dumped the struct with "ptype /ox my_interp" For the msvc definition: connected cdb.exe to a live backend, did a CREATE EXTENSION plperl, cdb stopped at exit, then I could dump the type with "dt plperl!PerlInterpreter" I'm sure there's a better way. And of course I'm mainly including this for a future self that might remember needing to something like this before...