Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: XS Error: Segfault with B::HooksAtRuntime

by haj (Vicar)
on Aug 06, 2022 at 16:15 UTC ( [id://11145983]=note: print w/replies, xml ) Need Help??


in reply to Re: XS Error: Segfault with B::HooksAtRuntime
in thread XS Error: Segfault with B::HooksAtRuntime

I can't solve the problem, but that info turned out to be sufficient for me to guess where to poke. I can reproduce a segfault in just 7 lines of code.

File: mx_segfault.pl
use lib '.'; use Demo;
File: Demo.pm
package Demo; use MooseX::Extended; require Stuff;
File: Stuff.pm
package Stuff; use MooseX::Extended;
With this code, perl -wc mx_segfault.pl segfaults, and valgrind throws a 455-line tantrum.
==12066== Memcheck, a memory error detector ==12066== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et +al. ==12066== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyrigh +t info ==12066== Command: perl -wc mx_segfault.pl ==12066== ==12066== Invalid read of size 2 ==12066== at 0x251CCD: S_pop_eval_context_maybe_croak (in /home/haj +/perl5/perlbrew/perls/perl-5.36.0/bin/perl) ==12066== by 0x25FFA0: Perl_pp_leaveeval (in /home/haj/perl5/perlbr +ew/perls/perl-5.36.0/bin/perl) ==12066== by 0x213312: Perl_runops_standard (in /home/haj/perl5/per +lbrew/perls/perl-5.36.0/bin/perl) ==12066== by 0x177DFD: Perl_call_sv (in /home/haj/perl5/perlbrew/pe +rls/perl-5.36.0/bin/perl) ==12066== by 0x17A70D: Perl_call_list (in /home/haj/perl5/perlbrew/ +perls/perl-5.36.0/bin/perl) ==12066== by 0x15E84A: S_process_special_blocks (in /home/haj/perl5 +/perlbrew/perls/perl-5.36.0/bin/perl) ==12066== by 0x170805: Perl_newATTRSUB_x (in /home/haj/perl5/perlbr +ew/perls/perl-5.36.0/bin/perl) ==12066== by 0x1743DA: Perl_utilize (in /home/haj/perl5/perlbrew/pe +rls/perl-5.36.0/bin/perl) ==12066== by 0x1B000E: Perl_yyparse (in /home/haj/perl5/perlbrew/pe +rls/perl-5.36.0/bin/perl) ==12066== by 0x17E836: perl_parse (in /home/haj/perl5/perlbrew/perl +s/perl-5.36.0/bin/perl) ==12066== by 0x155295: main (in /home/haj/perl5/perlbrew/perls/perl +-5.36.0/bin/perl) ==12066== Address 0x4c2528a is 314 bytes inside a block of size 1,872 + free'd ==12066== at 0x483AD7B: realloc (vg_replace_malloc.c:834) ==12066== by 0x1F385C: Perl_safesysrealloc (in /home/haj/perl5/perl +brew/perls/perl-5.36.0/bin/perl) ==12066== by 0x24D3BB: Perl_cxinc (in /home/haj/perl5/perlbrew/perl +s/perl-5.36.0/bin/perl) ==12066== by 0x21CED4: Perl_pp_entersub (in /home/haj/perl5/perlbre +w/perls/perl-5.36.0/bin/perl) ==12066== by 0x213312: Perl_runops_standard (in /home/haj/perl5/per +lbrew/perls/perl-5.36.0/bin/perl) ==12066== by 0x25130B: S_docatch (in /home/haj/perl5/perlbrew/perls +/perl-5.36.0/bin/perl) ==12066== by 0x213312: Perl_runops_standard (in /home/haj/perl5/per +lbrew/perls/perl-5.36.0/bin/perl) ==12066== by 0x177C5A: Perl_call_sv (in /home/haj/perl5/perlbrew/pe +rls/perl-5.36.0/bin/perl) ==12066== by 0x87D828C: call_after (in /home/haj/perl5/perlbrew/per +ls/perl-5.36.0/lib/site_perl/5.36.0/x86_64-linux/auto/B/Hooks/AtRunti +me/AtRuntime.so) ==12066== by 0x24F7A1: Perl_leave_scope (in /home/haj/perl5/perlbre +w/perls/perl-5.36.0/bin/perl) ==12066== by 0x251CCC: S_pop_eval_context_maybe_croak (in /home/haj +/perl5/perlbrew/perls/perl-5.36.0/bin/perl) ==12066== by 0x25FFA0: Perl_pp_leaveeval (in /home/haj/perl5/perlbr +ew/perls/perl-5.36.0/bin/perl) ==12066== Block was alloc'd at ==12066== at 0x483877F: malloc (vg_replace_malloc.c:307) ==12066== by 0x1F3502: Perl_safesysmalloc (in /home/haj/perl5/perlb +rew/perls/perl-5.36.0/bin/perl) ==12066== by 0x24D316: Perl_new_stackinfo (in /home/haj/perl5/perlb +rew/perls/perl-5.36.0/bin/perl) ==12066== by 0x15E9D6: S_process_special_blocks (in /home/haj/perl5 +/perlbrew/perls/perl-5.36.0/bin/perl) ==12066== by 0x170805: Perl_newATTRSUB_x (in /home/haj/perl5/perlbr +ew/perls/perl-5.36.0/bin/perl) ==12066== by 0x1743DA: Perl_utilize (in /home/haj/perl5/perlbrew/pe +rls/perl-5.36.0/bin/perl) ==12066== by 0x1B000E: Perl_yyparse (in /home/haj/perl5/perlbrew/pe +rls/perl-5.36.0/bin/perl) ==12066== by 0x17E836: perl_parse (in /home/haj/perl5/perlbrew/perl +s/perl-5.36.0/bin/perl) ==12066== by 0x155295: main (in /home/haj/perl5/perlbrew/perls/perl +-5.36.0/bin/perl)

Replies are listed 'Best First'.
Re^3: XS Error: Segfault with B::HooksAtRuntime
by dave_the_m (Monsignor) on Aug 06, 2022 at 18:31 UTC
    In general terms, that valgrind output shows that the calling of a sub while running code via call_after() (which requires a new CXt_SUB context sub to be pushed) grows the context stack (by reallocating it). Sometime later when exiting a use/require, the Cxt_EVAL frame is accessed using the old context stack address (the smaller stack that was freed when a larger one was allocated). So maybe something is holding on to a context stack pointer when it shouldn't - either in core or XS.

    Dave.

Re^3: XS Error: Segfault with B::HooksAtRuntime
by Ovid (Cardinal) on Aug 06, 2022 at 16:44 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-03-29 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found