Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XS with <= VC2003 has different interp struct against >= VC2005 Perl, ABI/segv #13667

Open
p5pRT opened this issue Mar 16, 2014 · 7 comments
Open
Labels
bulk88-query Closable? We might be able to close this ticket, but we need to check with the reporter distro-mswin32 type-core

Comments

@p5pRT
Copy link

p5pRT commented Mar 16, 2014

Migrated from rt.perl.org#121448 (status was 'new')

Searchable as RT121448$

@p5pRT
Copy link
Author

p5pRT commented Mar 16, 2014

From @bulk88

Created by @bulk88

Continuing from
https://groups.google.com/d/msg/perl.perl5.porters/n8lNwjkp_wk/_Om-44Wqn-YJ

bulk88 wrote​:

bulk88 wrote​:

Steve Hay wrote​:

In a couple of my XS modules I've long hand some rudimentary checks in
place to disallow building with a different compiler suite to that
which perl was built with, e.g. to disallow building with VC12 when
perl was built with VC6.

It has been mentioned to me several times over the years that there
should not be a problem with using a different compiler suite so the
checks are unnecessary, and I've finally got round to having a look...

It seems to be true in general that there is no problem, but there is
at least one thing that can go wrong due to VC7 and higher using
versioned C RTL DLLs (msvcr70.dll etc instead of msvcrt.dll) so that
two different C RTLs may get loaded (one by perl and a different one
by the XS module)​: If you use a mix of CRT I/O functions, some of
which are redirected by perl and others not, then you can end up
passing a file descriptor that was opened in one C RTL to the other C
RTL, which knows nothing about it.

This can happen, for example, if you obtain a file descriptor using
_sopen() (a Microsoft-specific variant of open(), which PerlIO doesn't
redefine) and pass it to close() (a standard C function, which PerlIO
does redefine). In this case the XS module's C RTL opens the file
descriptor, but because close() is redefined to a call within perl it
is perl's C RTL that is asked to close it, which will fail if that's a
different C RTL.

This is documented by MS.
http​://msdn.microsoft.com/en-us/library/ms235460.aspx

A similar thing can happen when mixing Windows API functions
(obviously not redefined by perl) with standard C functions, e.g.
opening a file descriptor with open() (using perl's C RTL) and then
passing it to _get_osfhandle() (in the XS module's C RTL).

I have found cases exactly like the above in my code and am in the
process of fixing them (either by using exclusively standard C
functions, all redefined by perl, or else by using exclusively
Microsoft-specific functions, none redefined by perl), but I have run
into another problem which causes certain combinations of VC++
versions to fail.

Then dont mix up CRTs in the first place. There are also the win32_*
functions that are exported that redirect to Perl's CRT DLL if you
want the same CRT as Perl.

One module crashes when using a member of the MY_CXT structure;
another crashes when calling chsize(), which is redefined as
(*my_perl->ILIO->pChsize)() when PERL_IMPLICIT_SYS is defined. In each
case, the struct member being used (MY_CXT.err_str in the former case;
my_perl->ILIO->pChsize in the latter case) is unexpectedly NULL
(0x00000000) with some combinations of C RTL DLLs.

Show the entire MY_CXT struct you created. Remember a MY_CXT struct
can never leave the compiland it was defined in. They are effectivly C
static declared. There is also win32_chsize. And NO_XSLOCKS define. If
my_perl->ILIO->pChsize (a vtable entry) is NULL, the problem is
somewhere in Perl, or your embeddeding code of Perl interp. I dont
understand "MY_CXT.err_str" to comment on that. If you have an
unthreaded Win32 Perl, my_perl is still a valid C symbol, but if you
use it, you will be broiled ;)
http​://perl5.git.perl.org/perl.git/blob/HEAD​:/perl.h#l4894 .

The crashes only happen when using a perl built with VC8 or higher and
using VC6 or VC7 to build the XS modules. Fortunately, that's an
unlikely combination​: If you have a VC8 or higher perl then you
probably built it yourself, so you would probably build the XS module
with the same version of VC++.

Mismatches the other way around do not seem to pose any problem, e.g.
a VC6 build of perl with VC12 being used to build the XS module.
(Which is good, since that's a more likely scenario, e.g. ActivePerl
used to be built with VC6, and is now built with a gcc port that also
uses msvcrt.dll like VC6 did.)

It would still be nice to understand what the problem is though. I'm
not sure if it's something I'm doing wrong, something wrong in perl, a
compiler bug that was fixed in VC8, or just some other fundamental
incompatibility between <=VC7 DLLs and >=VC8 DLLs?

The attached module illustrates the problem.

I'll try running it with a VC 2008/9.0 Perl with VC 2003/7.0 XS DLL.

Using a VC8 or higher build of perl but trying to build this module
with VC6 or VC7 causes both tests to fail​:

C​:\Dev\Temp\Foo-1.00>perl -Mblib t\test.t
1..2
# pOpen() is 00000000
not ok 1
# Failed test at t\test.t line 7.
# buf is 00000000
not ok 2
# Failed test at t\test.t line 8.
# Looks like you failed 2 tests of 2.

Using the same VC8 or higher build but now using VC8 or higher (but
not necessarily the same as was used for perl) to build this module is
fine​:

C​:\Dev\Temp\Foo-1.00>perl -Mblib t\test.t
1..2
# pOpen() is 61931230
ok 1
# buf is 003479A4
ok 2

Using a VC6 or VC7 build of perl is also fine, whatever version of
VC++ is used to build this module.

Can anyone explain what the problem here could be? Is it something
that I or we (p5p) could fix, or is it just a compiler problem that we
can't do anything about?

Can you attach your VC6/VC7 Foo.dll binary/DLL for me to look at?

NVM. Reproduced.

In VC2008, ILIO is at 0x8E4. In VC2003, ILIO is at 0x8CC.

VC2003
--------------------------------------------------------
38​: dMY_CXT;
39​: printf("# pOpen() is %p\n", my_perl->ILIO->pOpen);
100010A7 8D 9E CC 08 00 00 lea ebx,[esi+8CCh]
100010AD 8B 03 mov eax,dword ptr [ebx]
100010AF FF 70 3C push dword ptr [eax+3Ch]
100010B2 68 00 21 00 10 push offset string "# pOpen() is %p\n"
(10002100h)
100010B7 FF 15 20 20 00 10 call dword ptr [__imp__printf
(10002020h)]
--------------------------------------------------------
VC2008
--------------------------------------------------------
38​: dMY_CXT;
39​: printf("# pOpen() is %p\n", my_perl->ILIO->pOpen);
01FA10A7 8D 9E E4 08 00 00 lea ebx,[esi+8E4h]
01FA10AD 8B 03 mov eax,dword ptr [ebx]
01FA10AF FF 70 3C push dword ptr [eax+3Ch]
01FA10B2 68 EC 20 FA 01 push offset string "# pOpen() is %p\n"
(1FA20ECh)
01FA10B7 FF 15 7C 20 FA 01 call dword ptr [__imp__printf
(1FA207Ch)]
--------------------------------------------------------

This is a bug. I will investigate further. I suggest you file a RT
ticket. You can also investigate it yourself now. The C structs that
make up the interp struct don't match. This is wrong.

@@ -112973,9 +192597,50 @@


#pragma pack(pop)
-#line 639 "C:\\Program Files\\Microsoft Visual Studio .NET
2003\\VC7\\INCLUDE\\math.h"
-
-#line 641 "C:\\Program Files\\Microsoft Visual Studio .NET
2003\\VC7\\INCLUDE\\math.h"
+#line 594 "C:\\Program Files (x86)\\Microsoft Visual Studio
9.0\\VC\\INCLUDE\\math.h"
+
+#line 596 "C:\\Program Files (x86)\\Microsoft Visual Studio
9.0\\VC\\INCLUDE\\math.h"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#line 636 "C:\\Program Files (x86)\\Microsoft Visual Studio
9.0\\VC\\INCLUDE\\math.h"
+
#line 3834 "C:\\perl519\\lib\\CORE\\perl.h"


@@ -116243,6 +195908,7 @@



+
#line 12 "c:\\perl519\\lib\\core\\intrpvar.h"


@@ -116403,8 +196069,8 @@



-struct _stati64 Istatbuf;
-struct _stati64 Istatcache;
+struct _stat64 Istatbuf;
+struct _stat64 Istatcache;
GV * Istatgv;
SV * Istatname;

@@ -118632,7 +198298,7 @@

;

-__declspec(dllimport) char Perl_cando(PerlInterpreter* my_perl ,
mode_t mode, char effective, const struct _stati64* statbufp)
+__declspec(dllimport) char Perl_cando(PerlInterpreter* my_perl ,
mode_t mode, char effective, const struct _stat64* statbufp)

;

@@ -126405,6 +206071,7 @@



+
#line 5011 "C:\\perl519\\lib\\CORE\\perl.h"

What are those 2 structs for Istatbuf?

From 2003 line 114 "C​:\\Program Files\\Microsoft Visual Studio .NET 2003\\VC7\\INCLUDE\\sys/stat.h"

#line 114 "C:\\Program Files\\Microsoft Visual Studio .NET
2003\\VC7\\INCLUDE\\sys/stat.h"


struct _stati64 {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
};

struct __stat64 {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
__time64_t st_atime;
__time64_t st_mtime;
__time64_t st_ctime;
};

from 2008

struct _stat64 {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
__time64_t st_atime;
__time64_t st_mtime;
__time64_t st_ctime;
};

Perl in dosish.h has

#if defined(WIN64) || defined(USE_LARGE_FILES)
#define Stat_t struct _stati64
#else
#if defined(UNDER_CE)
#define Stat_t struct xcestat
#else
#define Stat_t struct stat
#endif
#endif

Both of my perls took the 1st branch, because of USE_LARGE_FILES, and
_stati64 has been there since forever in dosish.h:
https://github.com/perl/perl5/compare/6d1c0808b641926567cd16e07679f427c5fedc61..c623ac675720b3145d48cc2ea9474a0f3e0cbbca#diff-92ecd8641bdf73c214487b90076f4000
But in VC2008, _stati64 (from perl code/dosish.h) doesn't exist as a C struct. VC2008's headers stat.h contains

#ifdef _USE_32BIT_TIME_T
#define _fstat _fstat32
#define _fstati64 _fstat32i64
#define _stat _stat32
#define _stati64 _stat32i64
#define _wstat _wstat32
#define _wstati64 _wstat32i64

#else
#define _fstat _fstat64i32
#define _fstati64 _fstat64
#define _stat _stat64i32
#define _stati64 _stat64
#define _wstat _wstat64i32
#define _wstati64 _wstat64

#endif

2008's analog struct for 2003's _stati64 is:

#line 135 "C:\\Program Files (x86)\\Microsoft Visual Studio
9.0\\VC\\INCLUDE\\sys/stat.h"

struct _stat32i64 {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
__time32_t st_atime;
__time32_t st_mtime;
__time32_t st_ctime;
};

and 2003's analog struct for 2008's _stati64/_stat64 is, notice "__"

struct __stat64 {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
__time64_t st_atime;
__time64_t st_mtime;
__time64_t st_ctime;
};

See this commit by @jandubois for what is happening 45f6403

So something similar to that commit has to be done but in the reverse direction, but there is no macro to tell 2003 CRT headers do replace _stati64 struct with __stat64. This problem also affects win32_*
forwards like (from 2003 Foo.i)

__declspec(dllimport) int win32_fstat(int fd,struct _stati64
*sbufptr);
__declspec(dllimport) int win32_stat(const char *name,struct
_stati64 *sbufptr);

We have Stat_t as a Perl level token. This may need to be defined based
on whether _USE_32BIT_TIME_T is defined. If _USE_32BIT_TIME_T is not
defined (meaning Perl compiled with >= 2005), and VC 2003 or older
(_MSC_VER), Stat_t needs to resolve to "struct __stat64". Also
PL_statbuf is going away really soon,
https://rt.perl.org/Public/Bug/Display.html?id=121351 . IDK if
PL_statcache can go away also, I'll ask in that ticket. Removing those 2
interp vars still leaves the win32_* forwards broken.

Slightly related to the win32_* forward functions is my branch
https://github.com/bulk88/perl/tree/pefwd

There is also #9029 but I dont think its related to your/this bug.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.19.10:

Configured by Owner at Sat Mar 15 22:30:42 2014.

Summary of my perl5 (revision 5 version 19 subversion 10) configuration:
  Derived from: 2179658b5e799a6e3c4e736ec7c84b0f50bf3473
  Ancestor: e9251c1a8f4944e6dceff5240d9e109ba075ff29
  Platform:
    osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -O1 -MD -Zi -DNDEBUG -G7 -GL 
-DWIN32 -D_CONSOLE -DNO_STRICT  -DPERL_TEXTMODE_SCRIPTS 
-DPERL_HASH_FUNC_ONE_AT_A_TIME -DPERL_IMPLICIT_CONTEXT 
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T',
    optimize='-O1 -MD -Zi -DNDEBUG -G7 -GL',
    cppflags='-DWIN32'
    ccversion='13.10.6030', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', 
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf 
-ltcg  -libpath:"c:\perl519\lib\CORE"  -machine:x86'
    libpth="C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\lib"
    libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib 
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib 
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib 
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  
version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl519.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug 
-opt:ref,icf -ltcg  -libpath:"c:\perl519\lib\CORE"  -machine:x86'

Locally applied patches:
    uncommitted-changes
    2179658b5e799a6e3c4e736ec7c84b0f50bf3473


@INC for perl 5.19.10:
    C:/perl519/site/lib
    C:/perl519/lib
    .


Environment for perl 5.19.10:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\perl519\bin;C:\Program Files\Microsoft Visual Studio .NET 
2003\Common7\IDE;C:\Program Files\Microsoft Visual Studio .NET 
2003\VC7\BIN;C:\Program Files\Microsoft Visual Studio .NET 
2003\Common7\Tools;C:\Program Files\Microsoft Visual Studio .NET 
2003\Common7\Tools\bin\prerelease;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem;
    PERL_BADLANG (unset)
    SHELL (unset)


@p5pRT
Copy link
Author

p5pRT commented Mar 16, 2014

From @bulk88

On Sat Mar 15 22​:01​:09 2014, bulk88 wrote​:

We have Stat_t as a Perl level token. This may need to be defined
based
on whether _USE_32BIT_TIME_T is defined. If _USE_32BIT_TIME_T is not
defined (meaning Perl compiled with >= 2005), and VC 2003 or older
(_MSC_VER), Stat_t needs to resolve to "struct __stat64". Also
PL_statbuf is going away really soon,
https://rt.perl.org/Public/Bug/Display.html?id=121351 . IDK if
PL_statcache can go away also, I'll ask in that ticket. Removing those
2
interp vars still leaves the win32_* forwards broken.

I forgot to consider GCC. Strawberry 5.16's GCC headers have


#pragma pack(push,_CRT_PACKING)
# 58 "c​:\\sp3216\\c\\bin\\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/sys/stat.h" 3
# 1 "c​:\\sp3216\\c\\bin\\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/_mingw_stat64.h" 1 3
# 19 "c​:\\sp3216\\c\\bin\\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/_mingw_stat64.h" 3
  struct _stat {
  _dev_t st_dev;
  _ino_t st_ino;
  unsigned short st_mode;
  short st_nlink;
  short st_uid;
  short st_gid;
  _dev_t st_rdev;
  _off_t st_size;
  __time32_t st_atime;
  __time32_t st_mtime;
  __time32_t st_ctime;
  };

  struct stat {
  _dev_t st_dev;
  _ino_t st_ino;
  unsigned short st_mode;
  short st_nlink;
  short st_uid;
  short st_gid;
  _dev_t st_rdev;
  _off_t st_size;
  time_t st_atime;
  time_t st_mtime;
  time_t st_ctime;
  };

  struct _stati64 {
  _dev_t st_dev;
  _ino_t st_ino;
  unsigned short st_mode;
  short st_nlink;
  short st_uid;
  short st_gid;
  _dev_t st_rdev;
  __extension__ long long st_size;
  __time32_t st_atime;
  __time32_t st_mtime;
  __time32_t st_ctime;
  };

  struct _stat64i32 {
  _dev_t st_dev;
  _ino_t st_ino;
  unsigned short st_mode;
  short st_nlink;
  short st_uid;
  short st_gid;
  _dev_t st_rdev;
  _off_t st_size;
  __time64_t st_atime;
  __time64_t st_mtime;
  __time64_t st_ctime;
  };

  struct _stat64 {
  _dev_t st_dev;
  _ino_t st_ino;
  unsigned short st_mode;
  short st_nlink;
  short st_uid;
  short st_gid;
  _dev_t st_rdev;
  __extension__ long long st_size;
  __time64_t st_atime;
  __time64_t st_mtime;
  __time64_t st_ctime;
  };
# 59 "c​:\\sp3216\\c\\bin\\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/sys/stat.h" 2 3


interp struct section from SP.


# 82 "C​:\\sp3216\\perl\\lib\\CORE/intrpvar.h"
STRLEN Ina;

struct _stati64 Istatbuf;
struct _stati64 Istatcache;
GV * Istatgv;
SV * Istatname;

struct tms Itimesbuf;

PMOP * Icurpm;
# 114 "C​:\\sp3216\\perl\\lib\\CORE/intrpvar.h"


So GCC/Mingw thinks its a <= 2003, and its (strawberry's) Config.pm does NOT have _USE_32BIT_TIME_T. That isn't a mixed compiler build tho, nobody uses VC to compile XS with a Strawberry Perl (I've tried, lots of Config hacking, I gave up due to time). But there is a combo of VC Perl with GCC XS (btw, you are the maintainer of AP's dmake, see my ticket, https://rt.cpan.org/Public/Bug/Display.html?id=89440 ). ActivePerl <= 5.16 with the Mingw PPM packages is a common setup for some people. AP uses a AP-only module called ActivePerl​::Config (.pm) to change Config's values to work with GCC. It is _USE_32BIT_TIME_T unaware (maybe because ActiveState never used > VC6, and instead switched to Mingw for 5.18). IDK how self compiled VC Perl works with GCC XS and IDK if there will be a _USE_32BIT_TIME_T defined for doshish.h in that case.

So then a special case in doshish.h for Mingw is needed, but IDK exactly how to do it. Either test for Mingw or test for _USE_32BIT_TIME_T.

Remember, this fix will obviously fix blead, but what stable's will it be in? any maint releases? what stables will it be retrofitted to? what are your requirements for supporting a fix? fix it in ppport.h? idk...

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Mar 16, 2014

From @bulk88

Another fix idea is to just move PL_statcache and PL_statbuf to the end of the interp struct.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Mar 16, 2014

From @bulk88

Fixing Stat_t partially helped, compiling XS with VC 2003 with a VC 2005 Perl, before my fix, PL_LIO was at 0x8CC , after, 0x8DC, but its still not at 0x8E4 (correct offset) in VS 2005/2008. There is something else, not visible with diffing the interp struts after CPP, that is different.

dosish.h patch


#if defined(WIN64) || defined(USE_LARGE_FILES)
/* Perl was built with >= VC 2005, but XS is compiling < VC 2005
  so use 64 bit time struct from < VC 2005 for ABI compatiblity */
# if defined(_MSC_VER) && _MSC_VER < 1400 && !defined(_USE_32BIT_TIME_T)
# if _MSC_VER >= 1300
# define Stat_t struct __stat64
# else
# error Your Visual C 6 or older compiler does not define struct __stat64
# endif
# else
# define Stat_t struct _stati64
# endif
#else
#if defined(UNDER_CE)
#define Stat_t struct xcestat
#else
# if defined(_MSC_VER) && _MSC_VER < 1400 && !defined(_USE_32BIT_TIME_T)
# error Your Visual C 2003 or older compiler does not define struct _stat64i32
# else
# define Stat_t struct stat
# endif
#endif
#endif


void
one()
  PROTOTYPE​:

  PPCODE​:
  {
  dMY_CXT;
  printf("# pOpen() is %p Stat_t is %u MSC is %u intp is %u\n",
my_perl->ILIO->pOpen, sizeof(Stat_t), _MSC_VER, sizeof(struct interpreter));
  if (my_perl->ILIO->pOpen)
  XSRETURN_YES;
  else
  XSRETURN_EMPTY;
  }


VC 2003 before patch, 00003039 is "12345", a fake number so no segv


C​:\sources\Foo-1.00>perl -MFoo -E"Foo​::one"
# pOpen() is 00003039 Stat_t is 48 MSC is 1310 intp is 2632

C​:\sources\Foo-1.00>


VC 2003 after patch


C​:\sources\Foo-1.00>perl -MFoo -E"Foo​::one"
# pOpen() is 280BEDE6 Stat_t is 56 MSC is 1310 intp is 2648

C​:\sources\Foo-1.00>


VC 2005 (always correct, since this is VC 2005 Perl)


C​:\sources\Foo-1.00>perl -MFoo -E"Foo​::one"
# pOpen() is 280BF171 Stat_t is 56 MSC is 1400 intp is 2656

C​:\sources\Foo-1.00>


--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Mar 16, 2014

From @bulk88

On Sun Mar 16 01​:58​:05 2014, bulk88 wrote​:

Fixing Stat_t partially helped, compiling XS with VC 2003 with a VC
2005 Perl, before my fix, PL_LIO was at 0x8CC , after, 0x8DC, but its
still not at 0x8E4 (correct offset) in VS 2005/2008. There is
something else, not visible with diffing the interp struts after CPP,
that is different.


--- C​:\sources\Foo-1.00\vc8.txt
+++ C​:\sources\Foo-1.00\vc7.txt
@​@​ -110,191 +110,191 @​@​
minus_Eis 643
inplaceis 644
e_scriptis 648
-basetimeis 656
-maxsysfdis 664
-statusvalueis 668
-statusvalue_posixis 672
-sig_pendingis 676
-psig_pendis 680
-stdingvis 684
-stderrgvis 688
-argvgvis 692
-argvoutgvis 696
-argvout_stackis 700
-replgvis 704
-errgvis 708
-DBgvis 712
-DBlineis 716
-DBsubis 720
-DBsingleis 724
-DBtraceis 728
-DBsignalis 732
-dbargsis 736
-debstashis 740
-globalstashis 744
-curstnameis 748
-beginavis 752
-endavis 756
-unitcheckavis 760
-checkavis 764
-initavis 768
-fdpidis 772
-op_maskis 776
-main_cvis 780
-main_rootis 784
-main_startis 788
-eval_rootis 792
-eval_startis 796
-curcopdbis 800
-filemodeis 804
-lastfdis 808
-oldnameis 812
-Argvis 816
-Cmdis 820
-preambleavis 824
-mess_svis 828
-ors_svis 832
-forkprocessis 836
-gensymis 840
-cv_has_evalis 844
-taint_warnis 845
-laststypeis 846
-laststatvalis 848
-modcountis 852
-exitlistlenis 856
-exitlistis 860
-modglobalis 864
-profiledatais 868
-compilingis 872
-compcvis 920
-comppad_nameis 924
-comppad_name_fillis 928
-comppad_name_flooris 932
-sys_internis 936
-DBcvis 1788
-generationis 1792
-unicodeis 1796
-in_clean_objsis 1800
-in_clean_allis 1801
-nomemokis 1802
-savebeginis 1803
-delaymagic_uidis 1804
-delaymagic_euidis 1808
-delaymagic_gidis 1812
-delaymagic_egidis 1816
-anis 1820
-breakable_sub_genis 1824
-cop_seqmaxis 1828
-evalseqis 1832
-origalenis 1836
-origenvironis 1840
-osnameis 1844
-sighandlerpis 1848
-body_rootsis 1852
-debugis 1916
-maxois 1920
-runopsis 1924
-subnameis 1928
-sublineis 1932
-min_intro_pendingis 1936
-max_intro_pendingis 1940
-padixis 1944
-padix_flooris 1948
-collation_nameis 1952
-collxfrm_baseis 1956
-collxfrm_multis 1960
-collation_ixis 1964
-collation_standardis 1968
-unsafeis 1969
-colorsetis 1970
-phaseis 1972
-in_load_moduleis 1976
-perl_destruct_levelis 1977
-numeric_standardis 1978
-numeric_localis 1979
-numeric_nameis 1980
-numeric_radix_svis 1984
-Latin1is 1988
-UpperLatin1is 1992
-AboveLatin1is 1996
-NonL1NonFinalFoldis 2000
-HasMultiCharFoldis 2004
-utf8_markis 2008
-utf8_X_regular_beginis 2012
-utf8_X_extendis 2016
-utf8_toupperis 2020
-utf8_totitleis 2024
-utf8_toloweris 2028
-utf8_tofoldis 2032
-utf8_charname_beginis 2036
-utf8_charname_continueis 2040
-utf8_swash_ptrsis 2044
-Posix_ptrsis 2084
-XPosix_ptrsis 2152
-last_swash_hvis 2220
-last_swash_tmpsis 2224
-last_swash_slenis 2228
-last_swash_keyis 2232
-last_swash_klenis 2244
-pad_reset_pendingis 2245
-srand_calledis 2246
-psig_ptris 2248
-psig_nameis 2252
-Memis 2256
-MemSharedis 2260
-MemParseis 2264
-Envis 2268
-StdIOis 2272
-LIOis 2276
-Diris 2280
-Sockis 2284
-Procis 2288
-ptr_tableis 2292
-beginav_saveis 2296
-body_arenasis 2300
-regex_padis 2304
-regex_padavis 2308
-stashpadis 2312
-stashpadmaxis 2316
-stashpadixis 2320
-custom_op_namesis 2324
-custom_op_descsis 2328
-perliois 2332
-known_layersis 2336
-def_layerlistis 2340
-encodingis 2344
-utf8_idstartis 2348
-utf8_idcontis 2352
-utf8_xidstartis 2356
-utf8_perl_idstartis 2360
-utf8_perl_idcontis 2364
-utf8_xidcontis 2368
-sort_RealCmpis 2372
-checkav_saveis 2376
-unitcheckav_saveis 2380
-clocktickis 2384
-sharehookis 2388
-lockhookis 2392
-unlockhookis 2396
-threadhookis 2400
-destroyhookis 2404
-signalhookis 2408
-isarevis 2412
-registered_mrosis 2416
-blockhooksis 2420
-utf8_foldclosuresis 2424
-utf8_foldableis 2428
-custom_opsis 2432
-Xpvis 2436
-scopestack_nameis 2440
-debug_padis 2444
-globhookis 2492
-my_cxt_listis 2496
-my_cxt_sizeis 2500
-sv_constsis 2504
-random_stateis 2648
+basetimeis 652
+maxsysfdis 656
+statusvalueis 660
+statusvalue_posixis 664
+sig_pendingis 668
+psig_pendis 672
+stdingvis 676
+stderrgvis 680
+argvgvis 684
+argvoutgvis 688
+argvout_stackis 692
+replgvis 696
+errgvis 700
+DBgvis 704
+DBlineis 708
+DBsubis 712
+DBsingleis 716
+DBtraceis 720
+DBsignalis 724
+dbargsis 728
+debstashis 732
+globalstashis 736
+curstnameis 740
+beginavis 744
+endavis 748
+unitcheckavis 752
+checkavis 756
+initavis 760
+fdpidis 764
+op_maskis 768
+main_cvis 772
+main_rootis 776
+main_startis 780
+eval_rootis 784
+eval_startis 788
+curcopdbis 792
+filemodeis 796
+lastfdis 800
+oldnameis 804
+Argvis 808
+Cmdis 812
+preambleavis 816
+mess_svis 820
+ors_svis 824
+forkprocessis 828
+gensymis 832
+cv_has_evalis 836
+taint_warnis 837
+laststypeis 838
+laststatvalis 840
+modcountis 844
+exitlistlenis 848
+exitlistis 852
+modglobalis 856
+profiledatais 860
+compilingis 864
+compcvis 912
+comppad_nameis 916
+comppad_name_fillis 920
+comppad_name_flooris 924
+sys_internis 928
+DBcvis 1780
+generationis 1784
+unicodeis 1788
+in_clean_objsis 1792
+in_clean_allis 1793
+nomemokis 1794
+savebeginis 1795
+delaymagic_uidis 1796
+delaymagic_euidis 1800
+delaymagic_gidis 1804
+delaymagic_egidis 1808
+anis 1812
+breakable_sub_genis 1816
+cop_seqmaxis 1820
+evalseqis 1824
+origalenis 1828
+origenvironis 1832
+osnameis 1836
+sighandlerpis 1840
+body_rootsis 1844
+debugis 1908
+maxois 1912
+runopsis 1916
+subnameis 1920
+sublineis 1924
+min_intro_pendingis 1928
+max_intro_pendingis 1932
+padixis 1936
+padix_flooris 1940
+collation_nameis 1944
+collxfrm_baseis 1948
+collxfrm_multis 1952
+collation_ixis 1956
+collation_standardis 1960
+unsafeis 1961
+colorsetis 1962
+phaseis 1964
+in_load_moduleis 1968
+perl_destruct_levelis 1969
+numeric_standardis 1970
+numeric_localis 1971
+numeric_nameis 1972
+numeric_radix_svis 1976
+Latin1is 1980
+UpperLatin1is 1984
+AboveLatin1is 1988
+NonL1NonFinalFoldis 1992
+HasMultiCharFoldis 1996
+utf8_markis 2000
+utf8_X_regular_beginis 2004
+utf8_X_extendis 2008
+utf8_toupperis 2012
+utf8_totitleis 2016
+utf8_toloweris 2020
+utf8_tofoldis 2024
+utf8_charname_beginis 2028
+utf8_charname_continueis 2032
+utf8_swash_ptrsis 2036
+Posix_ptrsis 2076
+XPosix_ptrsis 2144
+last_swash_hvis 2212
+last_swash_tmpsis 2216
+last_swash_slenis 2220
+last_swash_keyis 2224
+last_swash_klenis 2236
+pad_reset_pendingis 2237
+srand_calledis 2238
+psig_ptris 2240
+psig_nameis 2244
+Memis 2248
+MemSharedis 2252
+MemParseis 2256
+Envis 2260
+StdIOis 2264
+LIOis 2268
+Diris 2272
+Sockis 2276
+Procis 2280
+ptr_tableis 2284
+beginav_saveis 2288
+body_arenasis 2292
+regex_padis 2296
+regex_padavis 2300
+stashpadis 2304
+stashpadmaxis 2308
+stashpadixis 2312
+custom_op_namesis 2316
+custom_op_descsis 2320
+perliois 2324
+known_layersis 2328
+def_layerlistis 2332
+encodingis 2336
+utf8_idstartis 2340
+utf8_idcontis 2344
+utf8_xidstartis 2348
+utf8_perl_idstartis 2352
+utf8_perl_idcontis 2356
+utf8_xidcontis 2360
+sort_RealCmpis 2364
+checkav_saveis 2368
+unitcheckav_saveis 2372
+clocktickis 2376
+sharehookis 2380
+lockhookis 2384
+unlockhookis 2388
+threadhookis 2392
+destroyhookis 2396
+signalhookis 2400
+isarevis 2404
+registered_mrosis 2408
+blockhooksis 2412
+utf8_foldclosuresis 2416
+utf8_foldableis 2420
+custom_opsis 2424
+Xpvis 2428
+scopestack_nameis 2432
+debug_padis 2436
+globhookis 2484
+my_cxt_listis 2488
+my_cxt_sizeis 2492
+sv_constsis 2496
+random_stateis 2640

C​:\sources\Foo-1.00>perl -MFoo -E"Foo​::one"
-# pOpen() is 00003039 Stat_t is 56 MSC is 1400 intp is 2656
+# pOpen() is 00003039 Stat_t is 56 MSC is 1310 intp is 2648

C​:\sources\Foo-1.00>
\ No newline at end of file


PL_e_script is a SV *. No drama can be there. PL_basetime is a time_t.


typedef __int64 __time64_t;
#line 56 "C​:\\Program Files\\Microsoft Visual Studio 8\\VC\\INCLUDE\\sys/types.h"
#line 58 "C​:\\Program Files\\Microsoft Visual Studio 8\\VC\\INCLUDE\\sys/types.h"
typedef __time64_t time_t;


#line 25 "C​:\\Program Files\\Microsoft Visual Studio .NET 2003\\VC7\\INCLUDE\\sys/types.h"
typedef long time_t;
#line 33 "C​:\\Program Files\\Microsoft Visual Studio .NET 2003\\VC7\\INCLUDE\\sys/types.h"
typedef __int64 __time64_t;
#line 36 "C​:\\Program Files\\Microsoft Visual Studio .NET 2003\\VC7\\INCLUDE\\sys/types.h"
#line 38 "C​:\\Program Files\\Microsoft Visual Studio .NET 2003\\VC7\\INCLUDE\\sys/types.h"


VC2005


#ifdef _USE_32BIT_TIME_T
#ifdef _WIN64
#include <crtwrn.h>
#pragma _CRT_WARNING( _NO_32BIT_TIME_T )
#undef _USE_32BIT_TIME_T
#endif
#else
#if _INTEGRAL_MAX_BITS < 64
#define _USE_32BIT_TIME_T
#endif
#endif

#ifndef _TIME32_T_DEFINED
typedef _W64 long __time32_t; /* 32-bit time value */
#define _TIME32_T_DEFINED
#endif

#ifndef _TIME64_T_DEFINED
#if _INTEGRAL_MAX_BITS >= 64
typedef __int64 __time64_t; /* 64-bit time value */
#endif
#define _TIME64_T_DEFINED
#endif

#ifndef _TIME_T_DEFINED
#ifdef _USE_32BIT_TIME_T
typedef __time32_t time_t; /* time value */
#else
typedef __time64_t time_t; /* time value */
#endif
#define _TIME_T_DEFINED /* avoid multiple def's of time_t */
#endif


VC 2003


#ifndef _TIME_T_DEFINED
#ifdef _WIN64
typedef __int64 time_t; /* time value */
#else
typedef long time_t; /* time value */
#endif
#if _INTEGRAL_MAX_BITS >= 64
typedef __int64 __time64_t;
#endif
#define _TIME_T_DEFINED /* avoid multiple def's of time_t */
#endif


VC 6


#ifndef _TIME_T_DEFINED
typedef long time_t;
#define _TIME_T_DEFINED
#endif


So this is more tricky, Time_t is a Perl type, and its defined in config_H.vc but time_t isn't a Perl type, its a C type. config_H.vc is not XS compile time dynamic like dosish.h/headers. Also, its not in VC 6. How will this be fixed?

--
bulk88 ~ bulk88 at hotmail.com

@toddr
Copy link
Member

toddr commented Feb 13, 2020

@bulk88 Assuming we do not continue to use VC2003, is there something that needs to be done here?

@toddr toddr added bulk88-query Closable? We might be able to close this ticket, but we need to check with the reporter labels Feb 13, 2020
@toddr
Copy link
Member

toddr commented Feb 13, 2020

@steve-m-hay this case seems to have opened out of a issue you had. Does it still need to be pursued? https://groups.google.com/forum/#!msg/perl.perl5.porters/n8lNwjkp_wk/_Om-44Wqn-YJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bulk88-query Closable? We might be able to close this ticket, but we need to check with the reporter distro-mswin32 type-core
Projects
None yet
Development

No branches or pull requests

3 participants