develooper Front page | perl.perl5.porters | Postings from March 2000

[ID 20000314.008] END blocks not executed in compiled binaries(-MO=C)

Thread Next
From:
Joe Smith
Date:
March 14, 2000 19:20
Subject:
[ID 20000314.008] END blocks not executed in compiled binaries(-MO=C)
Message ID:
200003150319.TAA18765@romana.Tymnet.COM

This is a bug report for perl from jms@romana.tymnet.com,
generated with the help of perlbug 1.27 running under perl v5.6.0.


-----------------------------------------------------------------
[Please enter your report here]

1) B/cc_harness does not specify DynaLoader.a to ld.
2) -l on the hash-bang line does not get propagated to the compiled binary.
   (Workaround: set $\ in an INIT block)
3) END blocks do not get printed when compiled binary is run.

Newsgroups: comp.lang.perl.moderated
Subject: Re: when are mainline statements run?

(romana/jms) jms@romana> cat fee.pl
#!/usr/local/bin/perl -wI.
BEGIN {$\ = "\n";}
INIT  {$\ = "\n";}		#(HACK) since -l not propagated
print "fee, top of file";
use fie;
print "fee, middle of file";
require 'foh.pm';
BEGIN { print "fee BEGIN"; }
CHECK { print "fee CHECK"; }
INIT { print "fee INIT"; }
END { print "fee END"; }
BEGIN { chop ($c_host = `hostname`); }
INIT  { chop ($e_host   = `hostname`); }
print "Compiled on $c_host, executed on $e_host" if $c_host ne $e_host;
print "fee, bottom of file";

(romana/jms) jms@romana> cat fie.pm
BEGIN { print "fie BEGIN"; }
CHECK { print "fie CHECK"; }
INIT { print "fie INIT"; }
END { print "fie END"; }
print "fie file";

(romana/jms) jms@romana> cat foh.pm
BEGIN { print "foh BEGIN"; }
CHECK { print "foh CHECK"; }
INIT { print "foh INIT"; }
END { print "foh END"; }
print "foh file";

(romana/jms) jms@romana> ./fee.pl
fie BEGIN
fie file
fee BEGIN
fee CHECK
fie CHECK
fie INIT
fee INIT
fee, top of file
fee, middle of file
foh BEGIN
foh file
fee, bottom of file
foh END
fee END
fie END

(romana/jms) jms@romana> sh -x bin/perl-cc fee
prog=fee
+ [ -f fee.pl ] 
+ perl -MO=C fee.pl 
Starting compile
Walking tree
Prescan
Saving methods
Writing output
Loaded B
Loaded IO
Loaded Fcntl
fee.pl syntax OK
+ perl /usr/local/lib/perl5/5.6.0/B/cc_harness -o fee fee.c 
gcc -fno-strict-aliasing -I/usr/local/include -I/opt/local/include -I/opt/gnu
/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/lib/perl5/5.
6.0/sun4-solaris/CORE -o fee fee.c  -L/usr/local/lib -L/opt/local/lib -L/opt/
gnu/lib  /usr/local/lib/perl5/5.6.0/sun4-solaris/CORE/libperl.a -lsocket -lns
l -lgdbm -ldb -ldl -lm -lc -lcrypt -lsec /usr/local/lib/perl5/5.6.0/sun4-sola
ris/auto/DynaLoader/DynaLoader.a
(romana/jms) jms@romana> ./fee
fie INIT
fee INIT
fee, top of file
fee, middle of file
foh BEGIN
foh file
fee, bottom of file
foh END
(romana/jms) jms@romana> rcp -p fee foh.pm gamma:
(romana/jms) jms@romana> rsh gamma ./fee
fie INIT
fee INIT
fee, top of file
fee, middle of file
foh BEGIN
foh file
Compiled on romana, executed on gamma
fee, bottom of file
foh END
(romana/jms) jms@romana> 

For compiled binaries (see "perldoc O" and "perldoc B"), the INIT blocks
are executed when the binary is run.  This can be several days after the
BEGIN and CHECK blocks have executed, and may be on another machine.

For 'require' files, the BEGIN and END blocks get executed when that
section is compiled on the fly.

I'm very surpised that "fee END" and "fie END" did not get executed.
	-Joe



[Please do not change anything below this line]
-----------------------------------------------------------------

---
Site configuration information for perl v5.6.0:

Configured by jms at Mon Mar 13 19:15:47 PST 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=solaris, osvers=2.7, archname=sun4-solaris
    uname='sunos romana 5.7 generic_106541-06 sun4u sparc sunw,ultra-5_10 '
    config_args='-de -D cc=gcc'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.95.2 19991024 (release)
    cppflags='-fno-strict-aliasing -I/usr/local/include -I/opt/local/include -I/opt/gnu/include'
    ccflags ='-fno-strict-aliasing -I/usr/local/include -I/opt/local/include -I/opt/gnu/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib -L/opt/local/lib -L/opt/gnu/lib '
    libpth=/usr/local/lib /opt/local/lib /opt/gnu/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt -lsec
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib -L/opt/local/lib -L/opt/gnu/lib'

Locally applied patches:
    v5.6.0-RC1

---
@INC for perl v5.6.0:
    /usr/local/lib/perl5/5.6.0/sun4-solaris
    /usr/local/lib/perl5/5.6.0
    /usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl/5.005/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.005
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl v5.6.0:
    HOME=/home/romana/jms
    LANG (unset)
    LANGUAGE (unset)
    LC_COLLATE=en_US
    LC_CTYPE=en_US
    LC_MESSAGES=C
    LC_MONETARY=en_US
    LC_NUMERIC=en_US
    LC_TIME=en_US
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/romana/jms/bin:/home/romana/jms/bin.sunos5:/home/romana/jms/bin.sun4:/usr/dt/bin:/usr/openwin/bin:/usr/newsprint/bin:/usr/X11R6/bin:/usr/X11R5/bin:/opt/SUNWspro/bin:/usr/ccs/bin:/usr/ucb:/usr/bin:/usr/sbin:/sbin:/usr/proc/bin:/opt/local/bin:/opt/local/etc:/opt/local/admin:/usr/local/bin:/usr/local/etc:/usr/local/admin:/usr/proc/bin:/opt/gnu/bin:/usr/local/samba/bin:/usr/tym:/usr/shosts:/www/mybin:/www/mybin:/www/mybin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About