rurban / perl-compiler

B::C - Moved over from googlecode
https://code.google.com/p/perl-compiler/
Other
63 stars 23 forks source link

Removal of config changes how Config is compiled into binaries. #261

Closed toddr closed 8 years ago

toddr commented 9 years ago

As of commit eab6e437c7b62b6d75cce9674d7fdc486242132d, programs which compile and use Config are emitting warnings. Probably now B::C doesn't directly use Config, we need to remove some or all of the special handling?

$>perlcc -e 'use warnings; use Config; print "ok\n" if $Config{nv_preserves_uv_bits}'; echo; ./a.out
pcccVSd0.c:8485: warning: this decimal constant is unsigned only in ISO C90
pcccVSd0.c:8485: warning: this decimal constant is unsigned only in ISO C90
pcccVSd0.c:8486: warning: this decimal constant is unsigned only in ISO C90
pcccVSd0.c:8486: warning: this decimal constant is unsigned only in ISO C90
pcccVSd0.c:8487: warning: this decimal constant is unsigned only in ISO C90
pcccVSd0.c:8487: warning: this decimal constant is unsigned only in ISO C90
pcccVSd0.c:9084: warning: integer constant is too large for ‘unsigned long’ type
pcccVSd0.c:9085: warning: integer constant is too large for ‘unsigned long’ type

Subroutine non_bincompat_options redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 13.
Subroutine compile_date redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 17.
Subroutine local_patches redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 21.
Subroutine header_files redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 62.
Subroutine myconfig redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 123.
Subroutine config_sh redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 1430.
Subroutine config_re redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 1434.
Subroutine config_vars redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 1440.
Subroutine launcher redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 1464.
ok
toddr commented 9 years ago

Applying this patch corrects the warning issue. However I really think this is an opportunity to compile programs which haven't yet triggered Config_heavy.pl in BEGIN so they'll run time load it. I suspect that's related to this diff but I'm not sure of what it's trying to do so I'm not sure what the correct course of action is at this point.

diff --git a/lib/B/C.pm b/lib/B/C.pm
index a25c17a..77c5aa5 100644
--- a/lib/B/C.pm
+++ b/lib/B/C.pm
@@ -3432,6 +3432,7 @@ sub try_autoload {
                $fullname, $cvstashname ) if $debug{cv};
   # First some exceptions, fooled by goto
   if ($cvstashname eq 'Config') {
+    require 'Config_heavy.pl'; # Some programs won't even comile if you don't put this here.
     return svref_2object( \&{'Config::launcher'} );
   }
   if ($fullname eq 'utf8::SWASHNEW') {
toddr commented 9 years ago

An alternative patch which seems to work is this:

diff --git a/lib/B/C.pm b/lib/B/C.pm
index a25c17a..a436d53 100644
--- a/lib/B/C.pm
+++ b/lib/B/C.pm
@@ -3431,9 +3431,6 @@ sub try_autoload {
   warn sprintf( "No definition for sub %s. Try %s::AUTOLOAD\n",
                $fullname, $cvstashname ) if $debug{cv};
   # First some exceptions, fooled by goto
-  if ($cvstashname eq 'Config') {
-    return svref_2object( \&{'Config::launcher'} );
-  }
   if ($fullname eq 'utf8::SWASHNEW') {
     # utf8_heavy was loaded so far, so defer to a demand-loading stub
     my $stub = sub { require 'utf8_heavy.pl' unless $savINC{"utf8_heavy.pl"}; goto &utf8::SWASHNEW; };

With this solution, I get a significantly smaller binary.

With patch 1: -rwxr-xr-x. 1 root root 1097589 Oct 16 16:43 a.out 32743 a.out.c

With patch 2: -rwxr-xr-x. 1 root root 964149 Oct 16 16:41 a.out 29427 a.out.c

toddr commented 9 years ago

So that fixed 99% but now I'm getting this on only 2 tests. It appears my approach shows the limitations of AUTOLOAD in B::C.

$>git co t/v5.22.0/C-COMPILED/known_errors.txt; ./cprove -v op/range.t op/rand.t
# Running: prove -v t/v5.22.0/C-COMPILED/op/range.t t/v5.22.0/C-COMPILED/op/rand.t
t/v5.22.0/C-COMPILED/op/range.t .. 
1..12
ok 1 - op/range.t exists
ok 2 - Not in taint mode
ok 3 - /usr/local/cpanel/3rdparty/perl/522-debug/bin/perl -c  op/range.t
# [WARNING] skip SvSTASH for overloaded HV %Config:: flags=0x2280000c
# [WARNING] unknown (HV*)&sv_list[1101] found in @static_free
ok 4 - op/range.c is generated (-O3,-fno-fold)
ok 5 - op/range.bin is compiled and ready to run.
ok 6 - Output parsed by TAP::Harness
ok 7 - Exit signal is 0 
# Adding op/range.t PLAN error to known_errors.txt file
not ok 8 - Plan was valid

#   Failed test 'Plan was valid'
#   at /usr/local/cpanel/B-C/t/v5.22.0/C-COMPILED/op/../../../lib/KnownErrors.pm line 94.
# op/range.bin .. 
# Can't locate object method "FETCH" via package "Config" at op/range.t line 56.
# # Looks like you planned 141 tests but ran 10.
# 1..141
# ok 1
# ok 2
# ok 3
# ok 4
# ok 5
# ok 6
# ok 7
# ok 8
# ok 9
# ok 10
# Dubious, test returned 2 (wstat 512, 0x200)
# Failed 131/141 subtests 
# 
# Test Summary Report
# -------------------
# op/range.bin (Wstat: 512 Tests: 10 Failed: 0)
#   Non-zero exit status: 2
#   Parse errors: Bad plan.  You planned 141 tests but ran 10.
# Files=1, Tests=10,  0 wallclock secs ( 0.05 usr  0.01 sys +  0.02 cusr  0.00 csys =  0.08 CPU)
# Result: FAIL
ok 9 # skip TAP parse is unpredictable when plan is invalid
ok 10 # skip TAP parse is unpredictable when plan is invalid
ok 11 # skip TAP parse is unpredictable when plan is invalid
ok 12 # skip TAP parse is unpredictable when plan is invalid
# Looks like you failed 1 test of 12.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/12 subtests 
    (less 4 skipped subtests: 7 okay)
t/v5.22.0/C-COMPILED/op/rand.t ... 
1..12
ok 1 - op/rand.t exists
ok 2 - Not in taint mode
ok 3 - /usr/local/cpanel/3rdparty/perl/522-debug/bin/perl -c  op/rand.t
# [WARNING] skip SvSTASH for overloaded HV %Config:: flags=0x2280000c
# [WARNING] unknown (HV*)&sv_list[6] found in @static_free
ok 4 - op/rand.c is generated (-O3,-fno-fold)
ok 5 - op/rand.bin is compiled and ready to run.
ok 6 - Output parsed by TAP::Harness
ok 7 - Exit signal is 0 
# Adding op/rand.t PLAN error to known_errors.txt file
not ok 8 - Plan was valid

#   Failed test 'Plan was valid'
#   at /usr/local/cpanel/B-C/t/v5.22.0/C-COMPILED/op/../../../lib/KnownErrors.pm line 94.
# op/rand.bin .. 
# Can't locate object method "FETCH" via package "Config" at op/rand.t line 49.
# # Looks like you planned 10 tests but ran 0.
# 1..10
# Dubious, test returned 2 (wstat 512, 0x200)
# Failed 10/10 subtests 
# 
# Test Summary Report
# -------------------
# op/rand.bin (Wstat: 512 Tests: 0 Failed: 0)
#   Non-zero exit status: 2
#   Parse errors: Bad plan.  You planned 10 tests but ran 0.
# Files=1, Tests=0,  0 wallclock secs ( 0.06 usr  0.00 sys +  0.02 cusr  0.00 csys =  0.08 CPU)
# Result: FAIL
ok 9 # skip TAP parse is unpredictable when plan is invalid
ok 10 # skip TAP parse is unpredictable when plan is invalid
ok 11 # skip TAP parse is unpredictable when plan is invalid
ok 12 # skip TAP parse is unpredictable when plan is invalid
# Looks like you failed 1 test of 12.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/12 subtests 
    (less 4 skipped subtests: 7 okay)

Test Summary Report
-------------------
t/v5.22.0/C-COMPILED/op/range.t (Wstat: 256 Tests: 12 Failed: 1)
  Failed test:  8
  Non-zero exit status: 1
t/v5.22.0/C-COMPILED/op/rand.t (Wstat: 256 Tests: 12 Failed: 1)
  Failed test:  8
  Non-zero exit status: 1
Files=2, Tests=24,  5 wallclock secs ( 0.08 usr  0.01 sys +  4.76 cusr  0.23 csys =  5.08 CPU)
Result: FAIL
atoomic commented 8 years ago

op/range.t error can be sumup to

> perlcc -r -e 'use Config; print qq/ok\n/ if $Config{ivsize}'
/usr/local/cpanel/3rdparty/perl/522-debug/bin/perlcc: Unexpected compiler output
[WARNING] skip SvSTASH for overloaded HV %Config:: flags=0x2280000c
 [WARNING] unknown (HV*)&sv_list[2] found in @static_free
Can't locate object method "FETCH" via package "Config" at -e line 1.
atoomic commented 8 years ago

with master branch @7571cf4

> perlcc -r -e 'use Config; print qq/ok\n/ if $Config{ivsize}'
pccdJEtb.c:8489: warning: this decimal constant is unsigned only in ISO C90
pccdJEtb.c:8489: warning: this decimal constant is unsigned only in ISO C90
pccdJEtb.c:8490: warning: this decimal constant is unsigned only in ISO C90
pccdJEtb.c:8490: warning: this decimal constant is unsigned only in ISO C90
pccdJEtb.c:8491: warning: this decimal constant is unsigned only in ISO C90
pccdJEtb.c:8491: warning: this decimal constant is unsigned only in ISO C90
pccdJEtb.c:9088: warning: integer constant is too large for ‘unsigned long’ type
pccdJEtb.c:9089: warning: integer constant is too large for ‘unsigned long’ type
Subroutine non_bincompat_options redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 13.
Subroutine compile_date redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 17.
Subroutine local_patches redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 21.
Subroutine header_files redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 62.
Subroutine myconfig redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 123.
Subroutine config_sh redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 1430.
Subroutine config_re redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 1434.
Subroutine config_vars redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 1440.
Subroutine launcher redefined at /usr/local/cpanel/3rdparty/perl/522-debug/lib/perl5/5.22.0/i386-linux-debug-64int/Config_heavy.pl line 1464.
ok
atoomic commented 8 years ago

Todd fix + restoring a reverted patch fix the issue

diff --git a/lib/B/C/OverLoad/B/GV.pm b/lib/B/C/OverLoad/B/GV.pm
index 8d2775d..2d0ca65 100644
--- a/lib/B/C/OverLoad/B/GV.pm
+++ b/lib/B/C/OverLoad/B/GV.pm
@@ -83,6 +83,12 @@ sub savecv {
     # XXX fails and should not be needed. The B::C part should be skipped 9 lines above, but be defensive
     return if $fullname eq 'B::walksymtable' or $fullname eq 'B::C::walksymtable';

+    # Config is marked on any Config symbol. TIE and DESTROY are exceptions,
+    # used by the compiler itself
+    if ( $name eq 'Config' ) {
+        mark_package( 'Config', 1 ) if !is_package_used('Config');
+    }
+
     $B::C::dumped_package{$package} = 1 if !exists $B::C::dumped_package{$package} and $package !~ /::$/;
     debug( gv => "Saving GV \*$fullname 0x%x", ref $gv ? $$gv : 0 );
     $gv->save($fullname);
rurban commented 8 years ago

Give me a bit of time. This is complicated. Right now I'm working on Config as XS to get rid of all these hacks and save a significant amount of memory