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

Fcntl not thread-safe #9006

Closed
p5pRT opened this issue Aug 27, 2007 · 25 comments
Closed

Fcntl not thread-safe #9006

p5pRT opened this issue Aug 27, 2007 · 25 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 27, 2007

Migrated from rt.perl.org#44999 (status was 'resolved')

Searchable as RT44999$

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2007

From @jdhedden

This is a bug report for perl from jdhedden@​cpan.org,
generated with the help of perlbug 1.36 running under perl 5.9.5.


Occasionally, when running threaded applications that use
LWP​::Simple, errors such as the following occur​:
  Attempt to free non-existent shared string 'O_NOTRANS', Perl
interpreter​: 0x10569d98 during global destruction.
and/or
  Unbalanced string table refcount​: (1) for "F_NOTIFY" during global
destruction.

The reported strings are always those for Fcntl constants,
thus leading me to suspect that there is something
non-thread-safe about Fcntl.

The attached script reproduces the problem. It must be run
a few dozen times to get an instance of the errors above.
Most of the time, however, the script fails on Abort, Seg
Fault or Hangup.

Also attached is a sample of the script's output when the
above errors occur.

See http​://www.nntp.perl.org/group/perl.perl5.porters/2007/06/msg125684.html
and http​://www.nntp.perl.org/group/perl.perl5.porters/2007/08/msg127869.html
for additional reports on this problem.



Flags​:
  category=library
  severity=medium


Site configuration information for perl 5.9.5​:

Configured by Jerry at Mon Aug 27 12​:42​:03 EDT 2007.

Summary of my perl5 (revision 5 version 9 subversion 5 patch 31756)
configuration​:
  Platform​:
  osname=cygwin, osvers=1.5.24(0.15642), archname=cygwin-thread-multi-64int
  uname='cygwin_nt-5.1 pn100-02-2-054p 1.5.24(0.15642) 2007-01-31
10​:57 i686 cygwin '
  config_args='-de -Dusedevel -Dversiononly=no -Dinstallusrbinperl
-DPERL_OLD_COPY_ON_WRITE -Duse64bitint -Dusethreads -Uusemymalloc
-Dnoextensions=attrs IPC/SysV Sys/Syslog DB_File NDBM_File ODBM_File
SDBM_File Devel/DProf Devel/Peek re Text/Soundex Math/BigInt/FastCalc
Time/Piece -A define​:optimize=-O3 -pipe -funit-at-a-time
-mtune=pentium4m -march=pentium4 -mfpmath=sse -mieee-fp -mmmx -msse
-msse2 -A append​:ccflags= -DNO_MATHOMS'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__
-DNO_MATHOMS -fno-strict-aliasing -pipe',
  optimize='-O3 -pipe -funit-at-a-time -mtune=pentium4m
-march=pentium4 -mfpmath=sse -mieee-fp -mmmx -msse -msse2',
  cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -DNO_MATHOMS
-fno-strict-aliasing -pipe'
  ccversion='', gccversion='3.4.4 (cygming special, gdc 0.12, using
dmd 0.125)', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='g++', ldflags =' -Wl,--enable-auto-import
-Wl,--export-all-symbols -Wl,--stack,8388608
-Wl,--enable-auto-image-base -Wl,--enable-auto-import -s
-L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib /lib
  libs=-lgdbm -ldl -lcrypt -lgdbm_compat
  perllibs=-ldl -lcrypt -lgdbm_compat
  libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' -s'
  cccdlflags=' ', lddlflags=' --shared -Wl,--enable-auto-import
-Wl,--export-all-symbols -Wl,--stack,8388608
-Wl,--enable-auto-image-base -Wl,--enable-auto-import -s
-L/usr/local/lib'

Locally applied patches​:
  DEVEL


@​INC for perl 5.9.5​:
  /usr/lib/perl5/5.9.5/cygwin
  /usr/lib/perl5/5.9.5
  .


Environment for perl 5.9.5​:
  CYGWIN=ntsec
  HOME=/home/jhedden
  LANG=C
  LANGUAGE=C
  LC_ALL=C
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/home/jhedden/bin​:/usr/local/src/perl/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/X11R6/bin​:/c/Program
Files/WiX​:/c/djgpp/bin​:/c/Program
Files/apache-ant-1.7.0/bin​:/c/Program
Files/nant-0.85/bin​:/c/j2sdk1.4.2_14/bin​:/c/dev-cpp/bin/​:/c/WINDOWS/system32​:/c/WINDOWS​:/c/WINDOWS/system32/WBEM​:/c/blp/API/dde​:/c/blp/API​:/c/oracle/ora92/bin​:/c/Program
Files/Oracle/jre/1.3.1/bin​:/c/Program
Files/Oracle/jre/1.1.8/bin​:/c/Program
Files/Hummingbird/Connectivity/7.10/Accessories/​:.
  PERLIO=perlio
  PERL_BADLANG (unset)
  SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2007

From @jdhedden

fetch.pl

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2007

From @jdhedden

fetch.out

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2007

From @jdhedden

The code produced by ExtUtils​::Constant​::ProxySubs is not
thread-safe, namely it creates a static HV* to put 'missing'
constants in​:

  static HV *constant_missing = NULL;

This cause errors in threaded apps that use LWP of the form​:
  Unbalanced string table refcount​: (1) for "DN_DELETE" during
global destruction.
and
  Attempt to free non-existent shared string 'F_ALLOCSP64', Perl
interpreter​: 0x10569d98 during global destruction.

The attached patch corrects this by adding the hash to the
package.

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2007

From @jdhedden

eucps.patch
--- perl-current/lib/ExtUtils/Constant/ProxySubs.pm
+++ perl-current/lib/ExtUtils/Constant/ProxySubs.pm
@@ -9,7 +9,7 @@
 use ExtUtils::Constant::Utils qw(C_stringify);
 use ExtUtils::Constant::XS qw(%XS_TypeSet);
 
-$VERSION = '0.03';
+$VERSION = '0.04';
 @ISA = 'ExtUtils::Constant::XS';
 
 %type_to_struct =
@@ -218,7 +218,7 @@
 
 EOADD
 
-    print $c_fh $explosives ? <<"EXPLODE" : <<"DONT";
+    print $c_fh $explosives ? <<"EXPLODE" : "\n";
 
 static int
 Im_sorry_Dave(pTHX_ SV *sv, MAGIC *mg)
@@ -242,12 +242,6 @@
 
 EXPLODE
 
-#ifndef SYMBIAN
-static HV *${c_subname}_missing = NULL;
-#endif
-
-DONT
-
     print $xs_fh <<"EOBOOT";
 BOOT:
   {
@@ -255,6 +249,18 @@
     dTHX;
 #endif
     HV *symbol_table = get_hv("$symbol_table", TRUE);
+#ifndef SYMBIAN
+    /* When we create the 'missing' hash, it generates a 'used only once'
+     * warning.  Therefore, turn off warnings while we do this.
+     */
+    HV *${c_subname}_missing;
+    {
+        const bool warn_tmp = PL_dowarn;
+        PL_dowarn = 0;
+        ${c_subname}_missing = get_hv("${symbol_table}${c_subname}_missing", TRUE);
+        PL_dowarn = warn_tmp;
+    }
+#endif
 EOBOOT
 
     my %iterator;
@@ -320,11 +326,6 @@
 					      'symbol_table',
 					      $add_symbol_subname);
     }
-    print $xs_fh $explosives ? "\n" : <<"EOBOOT";
-#ifndef SYMBIAN
-	${c_subname}_missing = newHV();
-#endif
-EOBOOT
 
     print $xs_fh <<"EOBOOT";
 	while (value_for_notfound->name) {
@@ -464,6 +465,7 @@
 #ifdef SYMBIAN
 	sv = newSVpvf("%"SVf" is not a valid $package_sprintf_safe macro", sv);
 #else
+	HV *${c_subname}_missing = get_hv("${c_subname}_missing", FALSE);
 	if (hv_exists(${c_subname}_missing, s, SvUTF8(sv) ? -(I32)len : (I32)len)) {
 	    sv = newSVpvf("Your vendor has not defined $package_sprintf_safe macro %" SVf
 			  ", used", sv);

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2007

From @rgs

On 28/08/2007, Jerry D. Hedden <jdhedden@​cpan.org> wrote​:

The code produced by ExtUtils​::Constant​::ProxySubs is not
thread-safe, namely it creates a static HV* to put 'missing'
constants in​:

static HV \*constant\_missing = NULL;

This cause errors in threaded apps that use LWP of the form​:
Unbalanced string table refcount​: (1) for "DN_DELETE" during
global destruction.
and
Attempt to free non-existent shared string 'F_ALLOCSP64', Perl
interpreter​: 0x10569d98 during global destruction.

The attached patch corrects this by adding the hash to the
package.

At the risk of stepping over a user variable, it seems. Maybe should
we name it %xyz_miSSinG_ or something weirder?

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2007

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2007

From @jdhedden

Jerry D. Hedden wrote​:

The code produced by ExtUtils​::Constant​::ProxySubs is not
thread-safe, namely it creates a static HV* to put 'missing'
constants in​:

static HV \*constant\_missing = NULL;

This cause errors in threaded apps that use LWP of the form​:
Unbalanced string table refcount​: (1) for "DN_DELETE" during global destruction.
and
Attempt to free non-existent shared string 'F_ALLOCSP64', Perl interpreter​: 0x10569d98 during global destruction.

The attached patch corrects this by adding the hash to the
package.

Rafael Garcia-Suarez wrote​:

At the risk of stepping over a user variable, it seems.
Maybe should we name it %xyz_miSSinG_ or something
weirder?

The attached revised patch uses _M!55!NG which should
eliminate that possibility. (I tested it and it works.)

(Patch not attached in this posting to p5p because it gets
rejected as a possible virus​:

  PERM_FAILURE​: SMTP Error (state 16)​: 552 Probably the 'Hi' virus

Patch sent directly to Rafael.)

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2007

From @rgs

On 30/08/2007, Jerry D. Hedden <jdhedden@​cpan.org> wrote​:

Rafael Garcia-Suarez wrote​:

At the risk of stepping over a user variable, it seems.
Maybe should we name it %xyz_miSSinG_ or something
weirder?

The attached revised patch uses _M!55!NG which should
eliminate that possibility. (I tested it and it works.)

(I had to zip up the patch because p5p rejected it as a
possible virus.)

Thanks, applied as #31766.

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2007

From @steve-m-hay

Rafael Garcia-Suarez wrote​:

On 30/08/2007, Jerry D. Hedden <jdhedden@​cpan.org> wrote​:

Rafael Garcia-Suarez wrote​:

At the risk of stepping over a user variable, it seems.
Maybe should we name it %xyz_miSSinG_ or something
weirder?

The attached revised patch uses _M!55!NG which should
eliminate that possibility. (I tested it and it works.)

(I had to zip up the patch because p5p rejected it as a
possible virus.)

Thanks, applied as #31766.

That caused compiler errors on Win32 with VC++ which I fixed in #31769,
but I notice that I'm now getting quite a few warnings like​:

Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
../lib/POSIX.pm line 33.

Have I just broken this in #31769 or was there a problem at #31766
anyway (I can't tell because #31766 doesn't compile here)?

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2007

From @rgs

On 31/08/2007, Steve Hay <SteveHay@​planit.com> wrote​:

That caused compiler errors on Win32 with VC++ which I fixed in #31769,
but I notice that I'm now getting quite a few warnings like​:

Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
../lib/POSIX.pm line 33.

Have I just broken this in #31769 or was there a problem at #31766
anyway (I can't tell because #31766 doesn't compile here)?

I don't know, how do you get that warning ? Looking at the source code
<http​://public.activestate.com/cgi-bin/perlbrowse/p/31766> that
shouldn't occur.

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2007

From @steve-m-hay

Rafael Garcia-Suarez wrote​:

On 31/08/2007, Steve Hay <SteveHay@​planit.com> wrote​:

That caused compiler errors on Win32 with VC++ which I fixed in
#31769, but I notice that I'm now getting quite a few warnings like​:

Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
../lib/POSIX.pm line 33.

Have I just broken this in #31769 or was there a problem at #31766
anyway (I can't tell because #31766 doesn't compile here)?

I don't know, how do you get that warning ? Looking at the source code
<http​://public.activestate.com/cgi-bin/perlbrowse/p/31766> that
shouldn't occur.

Lots of tests causes, and so does this one-liner​:

C​:\p5p\bleadperl>.\perl -MPOSIX -e 1
Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
C​:/p5p/bleadperl/lib/POSIX.pm line 33.

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2007

From @jdhedden

Steve Hay wrote​:

That caused compiler errors on Win32 with VC++ which I fixed in
#31769, but I notice that I'm now getting quite a few warnings like​:

Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
../lib/POSIX.pm line 33.

Have I just broken this in #31769 or was there a problem at #31766
anyway (I can't tell because #31766 doesn't compile here)?

Rafael Garcia-Suarez wrote​:

I don't know, how do you get that warning ? Looking at the source code
<http​://public.activestate.com/cgi-bin/perlbrowse/p/31766> that
shouldn't occur.

Steve Hay wrote​:

Lots of tests causes, and so does this one-liner​:

C​:\p5p\bleadperl>.\perl -MPOSIX -e 1
Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
C​:/p5p/bleadperl/lib/POSIX.pm line 33.

I do not get any warnings using the following in the build dir
for either 31768 or 31770 (Cygwin Perl under Windows)​:

  ./perl -Ilib -MPOSIX -e 1

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2007

From @steve-m-hay

Jerry D. Hedden wrote​:

Steve Hay wrote​:

That caused compiler errors on Win32 with VC++ which I fixed in
#31769, but I notice that I'm now getting quite a few warnings like​:

Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
../lib/POSIX.pm line 33.

Have I just broken this in #31769 or was there a problem at #31766
anyway (I can't tell because #31766 doesn't compile here)?

Rafael Garcia-Suarez wrote​:

I don't know, how do you get that warning ? Looking at the source
code <http​://public.activestate.com/cgi-bin/perlbrowse/p/31766> that
shouldn't occur.

Steve Hay wrote​:

Lots of tests causes, and so does this one-liner​:

C​:\p5p\bleadperl>.\perl -MPOSIX -e 1
Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
C​:/p5p/bleadperl/lib/POSIX.pm line 33.

I do not get any warnings using the following in the build dir
for either 31768 or 31770 (Cygwin Perl under Windows)​:

\./perl \-Ilib \-MPOSIX \-e 1

After rebuilding without Vadim's ALL_STATIC patch I now don't see any
warnings either.

So the ALL_STATIC build option breaks the code added by 31766/31769 that
seeks to silence warnings. Or else I've cocked up somewhere, which is
probably the more likely of the two scenarios.

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2007

From @steve-m-hay

Steve Hay wrote​:

Jerry D. Hedden wrote​:

Steve Hay wrote​:

That caused compiler errors on Win32 with VC++ which I fixed in
#31769, but I notice that I'm now getting quite a few warnings like​:

Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
../lib/POSIX.pm line 33.

Have I just broken this in #31769 or was there a problem at #31766
anyway (I can't tell because #31766 doesn't compile here)?

Rafael Garcia-Suarez wrote​:

I don't know, how do you get that warning ? Looking at the source
code <http​://public.activestate.com/cgi-bin/perlbrowse/p/31766> that
shouldn't occur.

Steve Hay wrote​:

Lots of tests causes, and so does this one-liner​:

C​:\p5p\bleadperl>.\perl -MPOSIX -e 1
Name "POSIX​::constant_M!55!NG" used only once​: possible typo at
C​:/p5p/bleadperl/lib/POSIX.pm line 33.

I do not get any warnings using the following in the build dir
for either 31768 or 31770 (Cygwin Perl under Windows)​:

\./perl \-Ilib \-MPOSIX \-e 1

After rebuilding without Vadim's ALL_STATIC patch I now don't see any
warnings either.

So the ALL_STATIC build option breaks the code added by 31766/31769
that seeks to silence warnings. Or else I've cocked up somewhere,
which is probably the more likely of the two scenarios.

It wasn't just me being stupid​:

I've now put Vadim's patch back. After doing a normal build with "nmake"
I find that the POSIX one-liner above generates no warning. However,
after cleaning and rebuilding with "nmake ALL_STATIC=define" I now find
that the one-liner generates the warning about
"POSIX​::constant_M!55!NG".

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2007

From vadim@vkonovalov.ru

Steve Hay wrote​:

So the ALL_STATIC build option breaks the code added by 31766/31769
that seeks to silence warnings. Or else I've cocked up somewhere,
which is probably the more likely of the two scenarios.

It wasn't just me being stupid​:

I've now put Vadim's patch back. After doing a normal build with "nmake"
I find that the POSIX one-liner above generates no warning. However,
after cleaning and rebuilding with "nmake ALL_STATIC=define" I now find
that the one-liner generates the warning about
"POSIX​::constant_M!55!NG".

I'll look into POSIX​::constant_M!55!NG warning closely today, and tomorrow.

But, generally, the behaviour is of little surprise to me.
If you do not use ALL_STATIC, then nothing changes, otherwise, modules
are built statically into perl59.dll, and then these modules are tried
out from inside perl59.dll
Some modules do not work this way, unfortunately (for example they look
for their auxiliary files relative to its DLL, and get confused if its
not found)
But sometimes this could reveal some hidden bug, or just room to improve
the logic and code.
Modules behaving as "good citizens" should work identically irrelevant
on linkage.

As a side note, the final goal of approach is to create single-file
executable with perl+tcl/tk inside much like Tcl/Tk starkit at
http​://wiki.tcl.tk/3661, or PAR approach but without temporaries with
on-the-fly unzips.

Best regards,
Vadim.

@p5pRT
Copy link
Author

p5pRT commented Sep 1, 2007

From vadim@vkonovalov.ru

Vadim wrote​:

Steve Hay wrote​:

So the ALL_STATIC build option breaks the code added by 31766/31769
that seeks to silence warnings. Or else I've cocked up somewhere,
which is probably the more likely of the two scenarios.

It wasn't just me being stupid​:

I've now put Vadim's patch back. After doing a normal build with "nmake"
I find that the POSIX one-liner above generates no warning. However,
after cleaning and rebuilding with "nmake ALL_STATIC=define" I now find
that the one-liner generates the warning about
"POSIX​::constant_M!55!NG".

I'll look into POSIX​::constant_M!55!NG warning closely today, and tomorrow.

this warning is because the way of avoiding warning is "naive"

PL_dowarn is temporarily turned to 0 while doing assigmnet a value to
variable, but this do not work, because actual cheking for variable used
'only once' happened later.

See attached patch.

All in all, I must underline that this my patch is "safer" than my
previous patch into Extutils​::MakeMaker, because it only touches
territory which is usually *off*

Even introducing ALL_STATIC into win32/Makefile it actually do nothing
essential​: it only activates many statical extensions at once, but user
could include "bad" extensions to build statically anyway, and see same
test failures of List/Util ...

Best regards,
Vadim.

@p5pRT
Copy link
Author

p5pRT commented Sep 1, 2007

From vadim@vkonovalov.ru

Inline Patch
diff -ru bperl-31775-orig/lib/ExtUtils/Constant/ProxySubs.pm bperl-31775-devsta/lib/ExtUtils/Constant/ProxySubs.pm
--- bperl-31775-orig/lib/ExtUtils/Constant/ProxySubs.pm	2007-08-31 12:56:29.000000000 +0400
+++ bperl-31775-devsta/lib/ExtUtils/Constant/ProxySubs.pm	2007-09-01 23:38:20.484375000 +0400
@@ -315,10 +315,10 @@
 	/* When we create the 'missing' hash, it generates a 'used only once'
 	 * warning.  Therefore, turn off warnings while we do this.
 	 */
-	const bool warn_tmp = PL_dowarn;
-	PL_dowarn = 0;
-	${c_subname}_missing = get_hv("${symbol_table}${c_subname}_M!55!NG", TRUE);
-	PL_dowarn = warn_tmp;
+	constant_missing = get_hv("POSIX::constant_M!55!NG", TRUE);
+	/* When we create the 'missing' hash, it generates a 'used only once'
+	 * warning.  Avoid this: */
+	constant_missing = get_hv("POSIX::constant_M!55!NG", TRUE);
 #endif
 EOBOOT
 
diff -ru bperl-31775-orig/win32/FindExt.pm bperl-31775-devsta/win32/FindExt.pm
--- bperl-31775-orig/win32/FindExt.pm	2007-04-27 21:15:40.000000000 +0400
+++ bperl-31775-devsta/win32/FindExt.pm	2007-08-31 23:40:07.625000000 +0400
@@ -20,12 +20,17 @@
     return $ENV{'PWD'} = $_;
 }
 
-sub set_static_extensions
-{
+sub set_static_extensions {
     # adjust results of scan_ext, and also save
     # statics in case scan_ext hasn't been called yet.
+    # if '*' is passed then all XS extensions are static (with possible exclusions)
     %static = ();
-    for (@_) {
+    my @list = @_;
+    if ($_[0] eq '*') {
+	my %excl = map {$_=>1} map {m/^!(.*)$/} @_[1 .. $#_];
+	@list = grep {!exists $excl{$_}} keys %ext;
+    }
+    for (@list) {
         $static{$_} = 1;
         $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic';
     }
diff -ru bperl-31775-orig/win32/Makefile bperl-31775-devsta/win32/Makefile
--- bperl-31775-orig/win32/Makefile	2007-08-29 21:01:41.000000000 +0400
+++ bperl-31775-devsta/win32/Makefile	2007-09-01 23:23:10.203125000 +0400
@@ -176,6 +176,15 @@
 #BUILD_STATIC	= define
 
 #
+# in addition to BUILD_STATIC the option ALL_STATIC makes for *every*
+# extension to be statically built
+# This will result in very large perl executable, but the main purpose
+# is to have proper linking set so to be able to create miscellaneous
+# executables with different set of built-in extensions
+#
+#ALL_STATIC	= define
+
+#
 #
 # set the install locations of the compiler include/libraries
 # Running VCVARS32.BAT is *required* when using Visual C.
@@ -784,9 +793,17 @@
 SETARGV_OBJ	= setargv$(o)
 !ENDIF
 
-# specify static extensions here
+!IF "$(ALL_STATIC)" == "define"
+# some exclusions, unfortunately, until fixed:
+#  - Win32 extension contains overlapped symbols with win32.c (BUG!)
+#  - MakeMaker isn't capable enough for SDBM_File (smaller bug)
+#  - Encode (encoding search algorithm relies on shared library?)
+STATIC_EXT	= * !Win32 !SDBM_File !Encode
+!ELSE
+# specify static extensions here, for example:
 #STATIC_EXT	= Cwd Compress/Raw/Zlib
 STATIC_EXT	= Win32CORE
+!ENDIF
 
 DYNALOADER	= $(EXTDIR)\DynaLoader\DynaLoader
 
@@ -822,8 +839,8 @@
 # Top targets
 #
 
-all : .\config.h $(GLOBEXE) $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) $(PERLEXE) \
-	$(X2P) MakePPPort Extensions $(PERLSTATIC)
+all : .\config.h $(GLOBEXE) $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) MakePPPort \
+	$(PERLEXE) $(X2P) Extensions $(PERLSTATIC)
 	@echo	Everything is up to date. '$(MAKE_BARE) test' to run test suite.
 
 ..\regnodes.h : ..\regcomp.sym ..\regcomp.pl ..\regexp.h
@@ -1011,7 +1028,7 @@
 
 $(PERLEXESTATIC): $(PERLSTATICLIB) $(CONFIGPM) $(PERLEXEST_OBJ) $(PERLEXE_RES)
 	$(LINK32) -subsystem:console -out:$@ -stack:0x1000000 $(LINK_FLAGS) \
-	    @Extensions_static $(PERLSTATICLIB) \
+	    @Extensions_static $(PERLSTATICLIB) /PDB:NONE \
 	    $(LIBFILES) $(PERLEXEST_OBJ) $(SETARGV_OBJ) $(PERLEXE_RES)
 	$(EMBED_EXE_MANI)
 
diff -ru bperl-31775-orig/win32/buildext.pl bperl-31775-devsta/win32/buildext.pl
--- bperl-31775-orig/win32/buildext.pl	2006-06-13 23:29:35.000000000 +0400
+++ bperl-31775-devsta/win32/buildext.pl	2007-08-31 23:40:07.671875000 +0400
@@ -63,8 +63,7 @@
     print $fh "#ifdef STATIC2\n",(map {"    EXTERN_C void boot_$_ (pTHX_ CV* cv);\n"} @statics1),"#undef STATIC2\n#endif\n";
     print $fh "#ifdef STATIC3\n",(map {"    newXS(\"$statics2[$_]::bootstrap\", boot_$statics1[$_], file);\n"} 0 .. $#statics),"#undef STATIC3\n#endif\n";
     close $fh;
-  }
-  else {
+  } else {
     my %extralibs;
     for (@statics) {
       open my $fh, "<..\\lib\\auto\\$_\\extralibs.ld" or die "can't open <..\\lib\\auto\\$_\\extralibs.ld: $!";
@@ -76,17 +75,14 @@
   exit(0);
 }
 
-my $here = getcwd();
+(my $here = getcwd()) =~ s{/}{\\}g;
 my $perl = $^X;
-$here =~ s,/,\\,g;
-if ($perl =~ m#^\.\.#)
- {
-  $perl = "$here\\$perl";
- }
+if ($perl =~ m#^\.\.#) {
+    $perl = "$here\\$perl";
+}
 (my $topdir = $perl) =~ s/\\[^\\]+$//;
 # miniperl needs to find perlglob and pl2bat
 $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
-#print "PATH=$ENV{PATH}\n";
 my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
 unless (-f "$pl2bat.bat") {
     my @args = ($perl, ("$pl2bat.pl") x 2);
@@ -100,7 +96,7 @@
 my $dir  = shift;
 chdir($dir) || die "Cannot cd to $dir\n";
 my $targ  = shift;
-(my $ext = getcwd()) =~ s,/,\\,g;
+(my $ext = getcwd()) =~ s{/}{\\}g;
 my $code;
 FindExt::scan_ext($ext);
 FindExt::set_static_extensions(split ' ', $Config{static_ext}) if $ext ne "ext";

@p5pRT
Copy link
Author

p5pRT commented Sep 1, 2007

From vadim@vkonovalov.ru

Sorry, I sent wrong one last time, attached is "better" one (hopefully)

Vadim wrote​:

Steve Hay wrote​:

So the ALL_STATIC build option breaks the code added by 31766/31769
that seeks to silence warnings. Or else I've cocked up somewhere,
which is probably the more likely of the two scenarios.

It wasn't just me being stupid​:

I've now put Vadim's patch back. After doing a normal build with "nmake"
I find that the POSIX one-liner above generates no warning. However,
after cleaning and rebuilding with "nmake ALL_STATIC=define" I now find
that the one-liner generates the warning about
"POSIX​::constant_M!55!NG".

I'll look into POSIX​::constant_M!55!NG warning closely today, and tomorrow.

this warning is because the way of avoiding warning is "naive"

PL_dowarn is temporarily turned to 0 while doing assigmnet a value to
variable, but this do not work, because actual cheking for variable used
'only once' happened later.

See attached patch.

All in all, I must underline that this my patch is "safer" than my
previous patch into Extutils​::MakeMaker, because it only touches
territory which is usually *off*

Even introducing ALL_STATIC into win32/Makefile it actually do nothing
essential​: it only activates many statical extensions at once, but user
could include "bad" extensions to build statically anyway, and see same
test failures of List/Util ...

@p5pRT
Copy link
Author

p5pRT commented Sep 1, 2007

From vadim@vkonovalov.ru

Inline Patch
diff -ru bperl-31775-orig/lib/ExtUtils/Constant/ProxySubs.pm bperl-31775-devsta/lib/ExtUtils/Constant/ProxySubs.pm
--- bperl-31775-orig/lib/ExtUtils/Constant/ProxySubs.pm	2007-08-31 12:56:29.000000000 +0400
+++ bperl-31775-devsta/lib/ExtUtils/Constant/ProxySubs.pm	2007-09-01 23:38:20.484375000 +0400
@@ -315,10 +315,10 @@
 	/* When we create the 'missing' hash, it generates a 'used only once'
 	 * warning.  Therefore, turn off warnings while we do this.
 	 */
-	const bool warn_tmp = PL_dowarn;
-	PL_dowarn = 0;
-	${c_subname}_missing = get_hv("${symbol_table}${c_subname}_M!55!NG", TRUE);
-	PL_dowarn = warn_tmp;
+	${c_subname}_missing = get_hv("${symbol_table}${c_subname}_M!55!NG", TRUE);
+	/* When we create the 'missing' hash, it generates a 'used only once'
+	 * warning.  Avoid this: */
+	${c_subname}_missing = get_hv("${symbol_table}${c_subname}_M!55!NG", TRUE);
 #endif
 EOBOOT
 
diff -ru bperl-31775-orig/win32/FindExt.pm bperl-31775-devsta/win32/FindExt.pm
--- bperl-31775-orig/win32/FindExt.pm	2007-04-27 21:15:40.000000000 +0400
+++ bperl-31775-devsta/win32/FindExt.pm	2007-08-31 23:40:07.625000000 +0400
@@ -20,12 +20,17 @@
     return $ENV{'PWD'} = $_;
 }
 
-sub set_static_extensions
-{
+sub set_static_extensions {
     # adjust results of scan_ext, and also save
     # statics in case scan_ext hasn't been called yet.
+    # if '*' is passed then all XS extensions are static (with possible exclusions)
     %static = ();
-    for (@_) {
+    my @list = @_;
+    if ($_[0] eq '*') {
+	my %excl = map {$_=>1} map {m/^!(.*)$/} @_[1 .. $#_];
+	@list = grep {!exists $excl{$_}} keys %ext;
+    }
+    for (@list) {
         $static{$_} = 1;
         $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic';
     }
diff -ru bperl-31775-orig/win32/Makefile bperl-31775-devsta/win32/Makefile
--- bperl-31775-orig/win32/Makefile	2007-08-29 21:01:41.000000000 +0400
+++ bperl-31775-devsta/win32/Makefile	2007-09-01 23:23:10.203125000 +0400
@@ -176,6 +176,15 @@
 #BUILD_STATIC	= define
 
 #
+# in addition to BUILD_STATIC the option ALL_STATIC makes for *every*
+# extension to be statically built
+# This will result in very large perl executable, but the main purpose
+# is to have proper linking set so to be able to create miscellaneous
+# executables with different set of built-in extensions
+#
+#ALL_STATIC	= define
+
+#
 #
 # set the install locations of the compiler include/libraries
 # Running VCVARS32.BAT is *required* when using Visual C.
@@ -784,9 +793,17 @@
 SETARGV_OBJ	= setargv$(o)
 !ENDIF
 
-# specify static extensions here
+!IF "$(ALL_STATIC)" == "define"
+# some exclusions, unfortunately, until fixed:
+#  - Win32 extension contains overlapped symbols with win32.c (BUG!)
+#  - MakeMaker isn't capable enough for SDBM_File (smaller bug)
+#  - Encode (encoding search algorithm relies on shared library?)
+STATIC_EXT	= * !Win32 !SDBM_File !Encode
+!ELSE
+# specify static extensions here, for example:
 #STATIC_EXT	= Cwd Compress/Raw/Zlib
 STATIC_EXT	= Win32CORE
+!ENDIF
 
 DYNALOADER	= $(EXTDIR)\DynaLoader\DynaLoader
 
@@ -822,8 +839,8 @@
 # Top targets
 #
 
-all : .\config.h $(GLOBEXE) $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) $(PERLEXE) \
-	$(X2P) MakePPPort Extensions $(PERLSTATIC)
+all : .\config.h $(GLOBEXE) $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) MakePPPort \
+	$(PERLEXE) $(X2P) Extensions $(PERLSTATIC)
 	@echo	Everything is up to date. '$(MAKE_BARE) test' to run test suite.
 
 ..\regnodes.h : ..\regcomp.sym ..\regcomp.pl ..\regexp.h
@@ -1011,7 +1028,7 @@
 
 $(PERLEXESTATIC): $(PERLSTATICLIB) $(CONFIGPM) $(PERLEXEST_OBJ) $(PERLEXE_RES)
 	$(LINK32) -subsystem:console -out:$@ -stack:0x1000000 $(LINK_FLAGS) \
-	    @Extensions_static $(PERLSTATICLIB) \
+	    @Extensions_static $(PERLSTATICLIB) /PDB:NONE \
 	    $(LIBFILES) $(PERLEXEST_OBJ) $(SETARGV_OBJ) $(PERLEXE_RES)
 	$(EMBED_EXE_MANI)
 
diff -ru bperl-31775-orig/win32/buildext.pl bperl-31775-devsta/win32/buildext.pl
--- bperl-31775-orig/win32/buildext.pl	2006-06-13 23:29:35.000000000 +0400
+++ bperl-31775-devsta/win32/buildext.pl	2007-08-31 23:40:07.671875000 +0400
@@ -63,8 +63,7 @@
     print $fh "#ifdef STATIC2\n",(map {"    EXTERN_C void boot_$_ (pTHX_ CV* cv);\n"} @statics1),"#undef STATIC2\n#endif\n";
     print $fh "#ifdef STATIC3\n",(map {"    newXS(\"$statics2[$_]::bootstrap\", boot_$statics1[$_], file);\n"} 0 .. $#statics),"#undef STATIC3\n#endif\n";
     close $fh;
-  }
-  else {
+  } else {
     my %extralibs;
     for (@statics) {
       open my $fh, "<..\\lib\\auto\\$_\\extralibs.ld" or die "can't open <..\\lib\\auto\\$_\\extralibs.ld: $!";
@@ -76,17 +75,14 @@
   exit(0);
 }
 
-my $here = getcwd();
+(my $here = getcwd()) =~ s{/}{\\}g;
 my $perl = $^X;
-$here =~ s,/,\\,g;
-if ($perl =~ m#^\.\.#)
- {
-  $perl = "$here\\$perl";
- }
+if ($perl =~ m#^\.\.#) {
+    $perl = "$here\\$perl";
+}
 (my $topdir = $perl) =~ s/\\[^\\]+$//;
 # miniperl needs to find perlglob and pl2bat
 $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
-#print "PATH=$ENV{PATH}\n";
 my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
 unless (-f "$pl2bat.bat") {
     my @args = ($perl, ("$pl2bat.pl") x 2);
@@ -100,7 +96,7 @@
 my $dir  = shift;
 chdir($dir) || die "Cannot cd to $dir\n";
 my $targ  = shift;
-(my $ext = getcwd()) =~ s,/,\\,g;
+(my $ext = getcwd()) =~ s{/}{\\}g;
 my $code;
 FindExt::scan_ext($ext);
 FindExt::set_static_extensions(split ' ', $Config{static_ext}) if $ext ne "ext";

@p5pRT
Copy link
Author

p5pRT commented Sep 1, 2007

From vadim@vkonovalov.ru

Vadim wrote​:

Sorry, I sent wrong one last time, attached is "better" one (hopefully)

... and I didn't notice that I introduce unneeded extra comment.

ok, resending separate patch for .\lib\ExtUtils\Constant\ProxySubs.pm
and go2bed.
This portion is to replace ProxySubs.pm of my previous patch.

Vadim.

@p5pRT
Copy link
Author

p5pRT commented Sep 1, 2007

From vadim@vkonovalov.ru

Inline Patch
--- C:\Personal\builds\bperl-31775-orig\lib\ExtUtils\Constant\ProxySubs.pm	2007-08-31 12:56:29.000000000 +0400
+++ ProxySubs.pm	2007-09-02 00:20:20.468750000 +0400
@@ -312,13 +312,10 @@
 
     print $xs_fh <<"EOBOOT";
 #ifndef SYMBIAN
+	${c_subname}_missing = get_hv("${symbol_table}${c_subname}_M!55!NG", TRUE);
 	/* When we create the 'missing' hash, it generates a 'used only once'
-	 * warning.  Therefore, turn off warnings while we do this.
-	 */
-	const bool warn_tmp = PL_dowarn;
-	PL_dowarn = 0;
+	 * warning.  Avoid this: */
 	${c_subname}_missing = get_hv("${symbol_table}${c_subname}_M!55!NG", TRUE);
-	PL_dowarn = warn_tmp;
 #endif
 EOBOOT
 

@p5pRT
Copy link
Author

p5pRT commented Sep 3, 2007

From @steve-m-hay

Vadim wrote​:

Vadim wrote​:

Sorry, I sent wrong one last time, attached is "better" one
(hopefully)

... and I didn't notice that I introduce unneeded extra comment.

ok, resending separate patch for .\lib\ExtUtils\Constant\ProxySubs.pm
and go2bed.
This portion is to replace ProxySubs.pm of my previous patch.

Thanks, applied as #31785.
Previous patch for ALL_STATIC also applied as #31784 (with minor
tweaks).

@p5pRT
Copy link
Author

p5pRT commented Sep 3, 2007

From vadim@vkonovalov.ru

Steve Hay wrote​:

Vadim wrote​:

....

This portion is to replace ProxySubs.pm of my previous patch.

Thanks, applied as #31785.
Previous patch for ALL_STATIC also applied as #31784 (with minor
tweaks).

Thanks a lot!
You also changed makefile.mk accordingly, thank you for this also!
(honestly, I had intentions to do the same, once win32/Makefile change
will stabilize)

Fortunately I've found the reason of failed Hash/Util/FieldHash - that's
because these sub-extensions are not actually linked statically, and
therefore became lost extensions.

There is a distinction between a module built statically and its
submodule also built statically, because for later one we do not have a
special call in build_ext.pl

I'll send fixer patch, soon.

Best regards,
Vadim.

@p5pRT
Copy link
Author

p5pRT commented Aug 3, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant