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

overload stringify 5.18-5.22 #219

Closed
atoomic opened this issue Sep 30, 2015 · 19 comments
Closed

overload stringify 5.18-5.22 #219

atoomic opened this issue Sep 30, 2015 · 19 comments

Comments

@atoomic
Copy link
Collaborator

atoomic commented Sep 30, 2015

Env:
perl 5.20.2
B::C using bc522 with HEAD @734e776 ( cannot use 23016e1 with 5.20 )

Steps to reproduce

> cat test.pl
package OverloadTest;
use overload '""' => sub { ${$_[0]} };

package main;
my $foo = bless \(my $bar = "ok"), "OverloadTest";
print $foo."\n";

> perl test.pl
ok
> perlcc -r test.pl
pccOxMXJ.c:8483: warning: initialization makes pointer from integer without a cast
....

Seems a regression as this is working on 5.14

@rurban
Copy link
Owner

rurban commented Oct 2, 2015

This started failing with 5.18.
testcase: t/issue172.t also with t/testc.sh 172 and now t/testc.sh 219
See old ticket GH #174

Maybe the root-cause is my workaround for the broken %version:: SvSTASH. See https://rt.cpan.org/Ticket/Display.html?id=81635

Update: It is not. Work in the branch overload-219

@rurban rurban self-assigned this Oct 8, 2015
@rurban rurban changed the title Overload issue in 5.20+ overload "" 5.18-5.22 Oct 8, 2015
@rurban rurban changed the title overload "" 5.18-5.22 overload stringify 5.18-5.22 Oct 8, 2015
@toddr
Copy link
Collaborator

toddr commented Oct 19, 2015

Right. You reported the bug against version except Devel::Peek and version are both perl as upstream. https://rt.cpan.org/Public/Bug/Display.html?id=107459

@toddr
Copy link
Collaborator

toddr commented Oct 20, 2015

Bisected in blead.

c07f9fb2c73bebcf70fabbf464c0c3452af4fcbf is the first bad commit
commit c07f9fb2c73bebcf70fabbf464c0c3452af4fcbf
Author: Father Chrysostomos [email protected]
Date: Tue Nov 20 13:47:27 2012 -0800

Revert "Revert "8c34e50dc slowed down detruction with no DESTROY""

This reverts commit 95f9781bc2fad025553db0160ef9c2c5363312a1.

Now that the crash has been fixed by the preceding commit, we can
reinstate 7cc6787e9db.

:100644 100644 2d1d887fe8b4256b2b5682dc6d26065f12ab5a6d be2038f4e7cdaf2d918c5df419348fca09290ab0 M mro.c
:100644 100644 9f5c157a87b3f41f96566337e612a3674c129bbd a7914988e7861ead362d718960a408fd5bd0a5e3 M sv.c
bisect run success

@toddr
Copy link
Collaborator

toddr commented Oct 20, 2015

Output at offending commit:

cd t && (rm -f perl; /bin/ln -s ../perl perl)
SV = IV(0x8c1e234) at 0x8c1e238
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x8c1e418
SV = PVHV(0x8c24010) at 0x8c1e418
REFCNT = 4
FLAGS = (OOK,OVERLOAD,SHAREKEYS)
STASH = 0x10/root/bisect.sh: line 10: 26914 Segmentation fault ./perl -Ilib -MDevel::Peek=Dump -E'version->new("v5.22.0");Dump(%version::)'

@toddr
Copy link
Collaborator

toddr commented Oct 20, 2015

Reported to upstream. https://rt.perl.org/Public/Bug/Display.html?id=126410

@toddr
Copy link
Collaborator

toddr commented Oct 20, 2015

Even with the patch applied to upstream, the original problem continues to be an issue so I think the upstream Devel::Peek regression is probably a distraction from the primary issue.

@toddr
Copy link
Collaborator

toddr commented Oct 20, 2015

Test results with fix sent to upstream compiled in to perl 5.22.0

$>perlcc -e'package OverloadTest; use overload q{""} => sub { ${$_[0]} }; package main; my $foo = bless \(my $bar = "ok"), "OverloadTest"; print $foo."\n";' ; ./a.out
./a.out
/usr/local/cpanel/3rdparty/perl/522-debug/bin/perlcc: Unexpected compiler output
[WARNING] skip SvSTASH for overloaded HV %Errno:: flags=0x3280000c
 [WARNING] unknown (HV*)&sv_list[455] found in @static_free
OverloadTest=SCALAR(0x8112fb0)

@toddr
Copy link
Collaborator

toddr commented Oct 21, 2015

Todd to bisect this today.

rurban pushed a commit that referenced this issue Oct 21, 2015
apply the patch from [perl #126410] for my_curse.
improve the logic to detect this crash, so it should work now also with
unpatched perls >= O3
GH #219
@rurban
Copy link
Owner

rurban commented Oct 21, 2015

Patched my_curse for -fno-destruct (-O3) so we don't even need the core patch on older perls.
See bd78fe8

@toddr
Copy link
Collaborator

toddr commented Oct 21, 2015

$>git bisect bad
bee7c5743fabd49c584c5edbb637c66c5c25ca9a is the first bad commit
commit bee7c5743fabd49c584c5edbb637c66c5c25ca9a
Author: Father Chrysostomos <[email protected]>
Date:   Fri May 18 17:02:39 2012 -0700

    sv.c: Don’t fiddle with AMAGIC in sv_bless

    Since overloading itself now checks whether caches are up to date, and
    since changes to the stash (@ISA, methods) turn the flag on and over-
    loading itself turns the flag off when it can, sv_bless no longer
    needs to deal with it at all.

:040000 040000 4a9679f7a036de75ae61b9dda7ebecc3bf5335ba 634b1a9b9c56600fac5f9d9e4335474d106cd95e M  lib
:100644 100644 0c940cb434f461f262ab8263d2f9f1552a04bcf2 1e7f4d2e341d79f5306194808fd65530a1f628f6 M  sv.c
diff --git a/sv.c b/sv.c
index 0c940cb..1e7f4d2 100644
--- a/sv.c
+++ b/sv.c
@@ -9518,11 +9518,6 @@ Perl_sv_bless(pTHX_ SV *const sv, HV *const stash)
     SvUPGRADE(tmpRef, SVt_PVMG);
     SvSTASH_set(tmpRef, MUTABLE_HV(SvREFCNT_inc_simple(stash)));

-    if (Gv_AMG(stash))
-       SvAMAGIC_on(sv);
-    else
-       (void)SvAMAGIC_off(sv);
-
     if(SvSMAGICAL(tmpRef))
         if(mg_find(tmpRef, PERL_MAGIC_ext) || mg_find(tmpRef, PERL_MAGIC_uvar))
             mg_set(tmpRef);

@rurban
Copy link
Owner

rurban commented Oct 21, 2015

Uh, now that's interesting and should be pretty simple to fix, thanks!
It says that we have to trigger Gv_AMG, which initializes and updated the overload cache by ourselves now.

atoomic added a commit to atoomic/perl-compiler that referenced this issue Oct 21, 2015
rurban pushed a commit that referenced this issue Oct 22, 2015
apply the patch from [perl #126410] for my_curse.
improve the logic to detect this crash, so it should work now also with
unpatched perls >= O3
GH #219
rurban pushed a commit that referenced this issue Oct 22, 2015
Apply the patch from [perl #126410] for my_curse.
See GH #219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
rurban pushed a commit that referenced this issue Oct 26, 2015
Apply the patch from [perl #126410] for my_curse.
See GH #219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
rurban pushed a commit that referenced this issue Oct 26, 2015
Apply the patch from [perl #126410] for my_curse.
See GH #219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
rurban pushed a commit that referenced this issue Oct 27, 2015
Apply the patch from [perl #126410] for my_curse.
See GH #219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
rurban pushed a commit that referenced this issue Oct 28, 2015
Apply the patch from [perl #126410] for my_curse.
See GH #219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
rurban pushed a commit that referenced this issue Oct 28, 2015
Apply the patch from [perl #126410] for my_curse.
See GH #219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
rurban pushed a commit that referenced this issue Oct 28, 2015
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot). Note that make_sv_object already mortalizes.
Apply the patch from [perl #126410] for my_curse. See GH #219

5.18 AMG has no SvSTASH
rurban pushed a commit that referenced this issue Nov 7, 2015
Apply the patch from [perl #126410] for my_curse.
See GH #219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
rurban pushed a commit to cpanel/perl-compiler that referenced this issue Nov 10, 2015
Apply the patch from [perl #126410] for my_curse.
See GH rurban#219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
@atoomic
Copy link
Collaborator Author

atoomic commented Nov 10, 2015

a workaround for it is to adjust ISA at run time (using the overload branch)

#!perl 

package OverloadTest;
use overload '""' => sub { ${$_[0]} };

package main;
my $foo = bless \(my $bar = "ok" ), "OverloadTest";

INIT {
    push @OverloadTest::ISA, 'overload';
}
print "$foo\n";
> perlcc -S -r test.pl
ok

@toddr
Copy link
Collaborator

toddr commented Nov 10, 2015

This is because the HvMROMETA (xpvhv_aux) is updated for the stash when @isa is changed. We need to start capturing and saving xpvhv_aux for all stashes for now on. This also would probably take away the need to set 'c3' on classes during XS init since this is simply populating that data.

@atoomic
Copy link
Collaborator Author

atoomic commented Nov 10, 2015

this dirty commit fixes the overload
cpanel@356e9e1

rurban pushed a commit that referenced this issue Nov 10, 2015
and fix -DMG issues with wrong CV stashes.
Harmonize gv_stashpv, always using const strings.
Also force saving the @isa before calling gv_stashpvn()
so that gv_stashpvn can correctly populate its stashcache.
Fixes GH #219 for 5.18-5.22
@toddr
Copy link
Collaborator

toddr commented Nov 10, 2015

@rurban While that does fix things, the correct solution is to save and properly attach xpvhv_aux where necessary. From the looks of it, the data is static?

@rurban
Copy link
Owner

rurban commented Nov 10, 2015

No, it's dynamic. I only save it for RITER/EITER, see there. However the code in mro_isa_changed_in or gv_stashpvnalready calls HvMROMETA() which initializes the xpvhv_aux struct.
Testing in branch debug-stashcv-gh219 dbfa262

I tested a static xpvhv_aux and it was not possible.

rurban pushed a commit that referenced this issue Nov 10, 2015
and fix -DMG issues with wrong CV stashes.
Harmonize gv_stashpv, always using const strings.
Also force saving the @isa before calling gv_stashpvn()
so that gv_stashpvn can correctly populate its stashcache.
Fixes GH #219 for 5.18-5.22
rurban pushed a commit that referenced this issue Nov 10, 2015
and fix -DMG issues with wrong CV stashes.
Harmonize gv_stashpv, always using const strings.
Also force saving the @isa before calling gv_stashpvn()
so that gv_stashpvn can correctly populate its stashcache.
Fixes GH #219 and GH #172 for 5.18-5.22
@rurban
Copy link
Owner

rurban commented Nov 10, 2015

Fixed with 1.52_18, thanks @atoomic

@rurban rurban closed this as completed Nov 10, 2015
rurban pushed a commit that referenced this issue Nov 11, 2015
Apply the patch from [perl #126410] for my_curse.
See GH #219

5.18 AMG has no SvSTASH

It still crashed with %version.
Provide our own B::HV::SvSTASH method and check against an invalid
STASH ptr (< arenaroot).
rurban pushed a commit that referenced this issue Nov 11, 2015
confirmed.
add 5.14->5.22 symlinks for same testfiles.
but there are not many.
We should add version checks/skips into the tests
rurban pushed a commit to cpanel/perl-compiler that referenced this issue Nov 11, 2015
and fix -DMG issues with wrong CV stashes.
Harmonize gv_stashpv, always using const strings.
Also force saving the @isa before calling gv_stashpvn()
so that gv_stashpvn can correctly populate its stashcache.
Fixes GH rurban#219 and GH rurban#172 for 5.18-5.22

(cherry picked from commit 02eb705)
Signed-off-by: Nicolas Rochelemagne <[email protected]>
rurban pushed a commit that referenced this issue Nov 11, 2015
op/dump.t, op/pack.t
rurban pushed a commit that referenced this issue Nov 14, 2015
confirmed.
add 5.14->5.22 symlinks for same testfiles.
but there are not many.
We should add version checks/skips into the tests
rurban pushed a commit that referenced this issue Nov 14, 2015
op/dump.t, op/pack.t
rurban pushed a commit that referenced this issue Nov 20, 2015
confirmed.
add 5.14->5.22 symlinks for same testfiles.
but there are not many.
We should add version checks/skips into the tests
rurban pushed a commit that referenced this issue Nov 20, 2015
op/dump.t, op/pack.t
rurban pushed a commit that referenced this issue Nov 20, 2015
confirmed.
add 5.14->5.22 symlinks for same testfiles.
but there are not many.
We should add version checks/skips into the tests
rurban pushed a commit that referenced this issue Nov 20, 2015
op/dump.t, op/pack.t
rurban pushed a commit that referenced this issue Nov 20, 2015
confirmed.
add 5.14->5.22 symlinks for same testfiles.
but there are not many.
We should add version checks/skips into the tests
rurban pushed a commit that referenced this issue Nov 20, 2015
op/dump.t, op/pack.t
atoomic added a commit to cpanel/perl-compiler that referenced this issue Aug 9, 2016
atoomic pushed a commit to cpanel/perl-compiler that referenced this issue Aug 9, 2016
Apply the patch from [perl #126410] for my_curse. See GH rurban#219
Fix a couple of sprintf names.
Initialize overload cache for AMAGIC. WIP rurban#219

Using the patched B::HV::SvSTASH does not help yet, it rather
regresses. So disable it for now, until it can be used.

(cherry picked from commit ce25407)
Signed-off-by: Nicolas Rochelemagne <[email protected]>
toddr added a commit to cpanel/perl-compiler that referenced this issue Jun 10, 2017
These all appear to be PAD related. Since we're saving the PAD statically with an immortal flag, we're not having issues any more.

#26
rurban#219
rurban#277
atoomic added a commit to cpanel/perl-compiler that referenced this issue Jul 18, 2017
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

3 participants