Navigation Menu

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

Incorrect coderef in MODIFY_CODE_ATTRIBUTES #9780

Closed
p5pRT opened this issue Jun 25, 2009 · 5 comments
Closed

Incorrect coderef in MODIFY_CODE_ATTRIBUTES #9780

p5pRT opened this issue Jun 25, 2009 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 25, 2009

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

Searchable as RT66970$

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2009

From alan@pit27.pair.com

Created by alan@pit27.pair.com

If you use an attribute on a sub definition which has already had a
reference made to it previously in the current compilation, or which
has already had another attribute applied to it in a separate sub
declaration, any attributes added at sub definition time cause
MODIFY_CODE_ATTRIBUTES to receive a bogus coderef for the sub.

I can reproduce this bug in perl 5.8.9 and perl 5.10.0, on freebsd 6.

* Sample code​:

#!/usr/local/bin/perl
use strict;

sub MODIFY_CODE_ATTRIBUTES {
  my ($pkg, $code, @​att) = @​_;
  warn "MODIFY_CODE_ATTRIBUTE for $code\n";
  return;
}

BEGIN { print "* sub foo has a reference constructed at compile time\n" }

BEGIN { warn " BEGIN before​: ". \&foo. "\n" }
sub foo : declaration {}
BEGIN { warn " BEGIN after​: ". \&foo. "\n" }

BEGIN { print "\n* sub bar has multiple attribute declarations\n" }

sub bar : before;
sub bar : declaration {}
sub bar : after;

BEGIN { print "\n* sub baz is free from interference\n" }

sub baz : declaration {}

print "\n* foo is​: ", \&foo, "\n";
print "* bar is​: ", \&bar, "\n";
print "* baz is​: ", \&baz, "\n";

__END__

* Sample buggy output​:

* sub foo has a reference constructed at compile time
  BEGIN before​: CODE(0x806b130)
MODIFY_CODE_ATTRIBUTE for CODE(0x806b124)
  BEGIN after​: CODE(0x806b130)

* sub bar has multiple attribute declarations
MODIFY_CODE_ATTRIBUTE for CODE(0x806b178)
MODIFY_CODE_ATTRIBUTE for CODE(0x806b0a0)
MODIFY_CODE_ATTRIBUTE for CODE(0x806b178)

* sub baz is free from interference
MODIFY_CODE_ATTRIBUTE for CODE(0x806b1b4)

* foo is​: CODE(0x806b130)
* bar is​: CODE(0x806b178)
* baz is​: CODE(0x806b1b4)

In the output above, sub foo's MODIFY_CODE_ATTRIBUTES $code ref does not
match the reference taken before the sub definition. bar's $code in
MODIFY_CODE_ATTRIBUTES is different in the case where the attribute is
directly added to the sub as it is being defined. baz's $code matches,
and no reference to sub baz existed prior to adding the attribute at
sub definition time.

This bug prevents the use of MODIFY_CODE_ATTRIBUTES to consistently store
metadata about a coderef if an attribute is added at sub definition time.
Instead, it requires that all attributes be added in separate attribute
declarations.

I haven't looked at the code, but my guess is that the attribute system is
constructing a random coderef at sub definition time, and passing it to
MODIFY_CODE_ATTRIBUTES, but then the coderef is not installed into the
symbol table because there is already another code ref there.

Thank you for your help,
Alan Ferrency

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.8.9:

Configured by alan at Tue Jun 16 16:19:31 EDT 2009.

Summary of my perl5 (revision 5 version 8 subversion 9) configuration:
  Platform:
    osname=freebsd, osvers=6.1-stable, archname=i386-freebsd-64int
    uname='freebsd pit27.pair.com 6.1-stable freebsd 6.1-stable #3: tue may 16 12:04:45 edt 2006 cap@pit54.pair.com:usrsrcsysi386compilepair_ws i386 '
    config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.8.9/mach -Dprivlib=/usr/local/lib/perl5/5.8.9 -Dman3dir=/usr/local/lib/perl5/5.8.9/perl/man/man3 -Dman1dir=/usr/local/man/man1 -Dsitearch=/usr/local/lib/perl5/site_perl/5.8.9/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.8.9 -Dscriptdir=/usr/local/bin -Dsiteman3dir=/usr/local/lib/perl5/5.8.9/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Duseshrplib -Dinc_version_list=none -Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -Doptimize=-O2 -fno-strict-aliasing -pipe -Ud_dosuid -Ui_gdbm -Dusethreads=n -Dusemymalloc=y -Duse64bitint'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include',
    optimize='-O2 -fno-strict-aliasing -pipe',
    cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='3.4.4 [FreeBSD] 20050518', 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=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -Wl,-E  -L/usr/local/lib'
    libpth=/usr/lib /usr/local/lib
    libs=-lgdbm -lm -lcrypt -lutil
    perllibs=-lm -lcrypt -lutil
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -Wl,-R/usr/local/lib/perl5/5.8.9/mach/CORE'
    cccdlflags='-DPIC -fPIC', lddlflags='-shared  -L/usr/local/lib'

Locally applied patches:
    defined-or


@INC for perl v5.8.9:
    /usr/local/lib/perl5/5.8.9/BSDPAN
    /usr/local/lib/perl5/site_perl/5.8.9/mach
    /usr/local/lib/perl5/site_perl/5.8.9
    /usr/local/lib/perl5/5.8.9/mach
    /usr/local/lib/perl5/5.8.9
    .


Environment for perl v5.8.9:
    HOME=/usr/home/staff/alan
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/X11R6/bin:/usr/home/staff/alan/bin
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2009

From p5p@spam.wizbit.be

Running it with blead​:

Version​: 5.011000
* sub foo has a reference constructed at compile time
  BEGIN before​: CODE(0x8857858)
MODIFY_CODE_ATTRIBUTE for CODE(0x8857848) & declaration
  BEGIN after​: CODE(0x8857858)

* sub bar has multiple attribute declarations
MODIFY_CODE_ATTRIBUTE for CODE(0x8857798) & before
MODIFY_CODE_ATTRIBUTE for CODE(0x88577c8) & declaration
MODIFY_CODE_ATTRIBUTE for CODE(0x8857798) & after

* sub baz is free from interference
MODIFY_CODE_ATTRIBUTE for CODE(0x88577f8) & declaration

* foo is​: CODE(0x8857858)
* bar is​: CODE(0x8857798)
* baz is​: CODE(0x88577f8)

Running it with perl-5.6.0​:

Version​: 5.006
* sub foo has a reference constructed at compile time
  BEGIN before​: CODE(0x9ae382c)
MODIFY_CODE_ATTRIBUTE for CODE(0x9ae3808) & declaration
  BEGIN after​: CODE(0x9ae382c)

* sub bar has multiple attribute declarations
MODIFY_CODE_ATTRIBUTE for CODE(0x9aeebc0) & before
MODIFY_CODE_ATTRIBUTE for CODE(0x9aeec38) & declaration
MODIFY_CODE_ATTRIBUTE for CODE(0x9aeebc0) & after

* sub baz is free from interference
MODIFY_CODE_ATTRIBUTE for CODE(0x9ae788c) & declaration

* foo is​: CODE(0x9ae382c)
* bar is​: CODE(0x9aeebc0)
* baz is​: CODE(0x9ae788c)

=> Both produce uncorrect/unexpected output.

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2009

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

@p5pRT
Copy link
Author

p5pRT commented Sep 6, 2009

From @rgs

Resolved in blead perl by this change :

http​://perl5.git.perl.org/perl.git/commitdiff/09330df80caf214f375fcf0c04857347e3b17c69

@p5pRT
Copy link
Author

p5pRT commented Sep 6, 2009

@rgs - 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