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

END blocks not executed in compiled binaries (-MO=C) #1342

Closed
p5pRT opened this issue Mar 14, 2000 · 4 comments
Closed

END blocks not executed in compiled binaries (-MO=C) #1342

p5pRT opened this issue Mar 14, 2000 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 14, 2000

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

Searchable as RT2371$

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2000

From jms@tardis.tymnet.com

Created by jms@romana.tymnet.com

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

Perl Info


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


@p5pRT
Copy link
Author

p5pRT commented Mar 15, 2000

From @gsar

On Tue, 14 Mar 2000 19​:19​:47 PST, Joe Smith wrote​:

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.

The END blocks issues is a known one, and is on the todo list. Patches
welcome.

Sarathy
gsar@​ActiveState.com

@p5pRT
Copy link
Author

p5pRT commented Mar 19, 2000

From [Unknown Contact. See original ticket]

On Wed, Mar 15, 2000 at 09​:44​:08AM -0800, Gurusamy Sarathy wrote​:

On Tue, 14 Mar 2000 19​:19​:47 PST, Joe Smith wrote​:

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.

The END blocks issues is a known one, and is on the todo list. Patches
welcome.

Is the inconsistent handling of switches on the hash-bang line documented?
Note that -I is handled (but not in quite the same way) but -w and -l are not.

(romana/jms) jms@​romana> cat fee2.pl
#!/usr/local/bin/perl -wlI...
print "\$^W (set from -w) is $^W";
print "\$^I (set from -I) is @​INC";
printf '$\ (set from -l) is %03o',ord($\);
print "\nDone.";

(romana/jms) jms@​romana> ./fee2.pl
$^W (set from -w) is 1
$^I (set from -I) is ... /usr/local/lib/perl5/5.6.0/sun4-solaris /usr/local/li
b/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 . ...
$\ (set from -l) is 012
Done.
(romana/jms) jms@​romana> perl-cc fee2
prog=fee2
+ [ -f fee2.pl ]
+ perl -MO=C fee2.pl
Starting compile
Walking tree
Prescan
Saving methods
Writing output
Loaded B
Loaded IO
Loaded Fcntl
fee2.pl syntax OK
+ perl /usr/local/lib/perl5/5.6.0/B/cc_harness -o fee2 fee2.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 fee2 fee2.c -L/usr/local/lib -L/opt/local/lib -L/opt/g
nu/lib /usr/local/lib/perl5/5.6.0/sun4-solaris/CORE/libperl.a -lsocket -lnsl
-lgdbm -ldb -ldl -lm -lc -lcrypt -lsec /usr/local/lib/perl5/5.6.0/sun4-solaris
/auto/DynaLoader/DynaLoader.a
(romana/jms) jms@​romana> ./fee2
$^W (set from -w) is 0$^I (set from -I) is /usr/local/lib/perl5/5.6.0/sun4-sol
aris /usr/local/lib/perl5/5.6.0 /usr/local/lib/perl5/site_perl/5.6.0/sun4-sola
ris /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_pe
rl . ...$\ (set from -l) is 000
Done.(romana/jms) jms@​romana>

In the interpreted case, -I... is both prepended and appended to @​INC.
In the compiled case, -I... is appended only, and both -w and -l are unset.
So it is not the case where all of the options switches from the hashbang
line are ignored, just some of them.
  -Joe

@p5pRT p5pRT closed this as completed Jul 7, 2003
@p5pRT
Copy link
Author

p5pRT commented Jul 7, 2003

ziggy@panix.com - Status changed from 'open' to 'resolved'

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

No branches or pull requests

1 participant