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

duplicate stack extend reporting for xsubs #16126

Closed
p5pRT opened this issue Aug 28, 2017 · 10 comments
Closed

duplicate stack extend reporting for xsubs #16126

p5pRT opened this issue Aug 28, 2017 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 28, 2017

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

Searchable as RT131975$

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2017

From @tonycoz

Created by @tonycoz

This is just an RFC for the attached patch, which I'll apply on no
negative comments.

Dave's patches to Perl_runops_debug() have been great for reporting XS
code that doesn't properly extend the stack.

Unfortunately tracking down the location of the fault in complex code
can be difficult with the message reported by the run loop.

The attacked patch adds a similar check to pp_entersub when calling
XSUBs and reports the name of the XSUB to make it simpler to track
down the fault.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.27.4:

Configured by tony at Mon Aug 28 11:55:58 AEST 2017.

Summary of my perl5 (revision 5 version 27 subversion 4) configuration:
  Derived from: 43272d222fe12f33c708d42b2a71af36cc92e4bd
  Platform:
    osname=linux
    osvers=3.16.0-4-amd64
    archname=x86_64-linux
    uname='linux mars 3.16.0-4-amd64 #1 smp debian 3.16.43-2+deb8u1 (2017-06-18) x86_64 gnulinux '
    config_args='-des -Dusedevel -DDEBUGGING -Doptimize=-O0 -g -Dprefix=/home/tony/perl/blead'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O0 -g'
    cppflags='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='4.9.2'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O0 -g -L/usr/local/lib -fstack-protector-strong'

Locally applied patches:
    uncommitted-changes


@INC for perl 5.27.4:
    /home/tony/perl/blead/lib/site_perl/5.27.4/x86_64-linux
    /home/tony/perl/blead/lib/site_perl/5.27.4
    /home/tony/perl/blead/lib/5.27.4/x86_64-linux
    /home/tony/perl/blead/lib/5.27.4


Environment for perl 5.27.4:
    HOME=/home/tony
    LANG=en_AU.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/tony/perl5/perlbrew/bin:/home/tony/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    PERLBREW_BASHRC_VERSION=0.43
    PERLBREW_HOME=/home/tony/.perlbrew
    PERLBREW_MANPATH=
    PERLBREW_PATH=/home/tony/perl5/perlbrew/bin
    PERLBREW_ROOT=/home/tony/perl5/perlbrew
    PERLBREW_VERSION=0.67
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2017

From @tonycoz

0001-add-a-stack-extend-check-to-pp_entersub-for-XS-subs.patch
From d24e1a34cefd083ce0626044b19113376659f06a Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Mon, 28 Aug 2017 13:49:35 +1000
Subject: [PATCH] add a stack extend check to pp_entersub for XS subs

This allows us to report the XSUB involved by name (or at least by
filename) in the likely case that it was an XSUB that failed to
extend the stack.
---
 pp_hot.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/pp_hot.c b/pp_hot.c
index 528817f..c6aad16 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -4423,6 +4423,21 @@ PP(pp_entersub)
 	assert(CvXSUB(cv));
 	CvXSUB(cv)(aTHX_ cv);
 
+#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
+        /* This duplicates the check done in runops_debug(), but provides more
+         * information in the common case of the fault being with an XSUB.
+         *
+         * It should also catch an XSUB pushing more than it extends
+         * in scalar context.
+        */
+        if (PL_curstackinfo->si_stack_hwm < PL_stack_sp - PL_stack_base)
+            Perl_croak_nocontext(
+                "panic: XSUB %s::%s (%s) failed to extend arg stack: "
+                "base=%p, sp=%p, hwm=%p\n",
+                    HvNAME(GvSTASH(CvGV(cv))), GvNAME(CvGV(cv)), CvFILE(cv),
+                    PL_stack_base, PL_stack_sp,
+                    PL_stack_base + PL_curstackinfo->si_stack_hwm);
+#endif
 	/* Enforce some sanity in scalar context. */
 	if (is_scalar) {
             SV **svp = PL_stack_base + markix + 1;
-- 
2.1.4

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2017

From @cpansprout

On Sun, 27 Aug 2017 20​:58​:48 -0700, tonyc wrote​:

The attacked patch

I think that patch needs help!

adds a similar check to pp_entersub when calling
XSUBs and reports the name of the XSUB to make it simpler to track
down the fault.

+#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY

I think DEBUGGING_RE_ONLY only applies to headers. It’s redundant here.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2017

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2017

From @tonycoz

On Mon, 28 Aug 2017 13​:19​:26 -0700, sprout wrote​:

On Sun, 27 Aug 2017 20​:58​:48 -0700, tonyc wrote​:

adds a similar check to pp_entersub when calling
XSUBs and reports the name of the XSUB to make it simpler to track
down the fault.

+#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY

I think DEBUGGING_RE_ONLY only applies to headers. It’s redundant here.

It's based on Dave's changes which use the same condition. Especially​:

#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
/* high water mark​: for checking if the stack was correctly extended /
* tested for extension by each pp function */
  SSize_t si_stack_hwm;
#endif

Perhaps they all should only be checking DEBUGGING.

Tony

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2017

From @tonycoz

On Sun, 27 Aug 2017 20​:58​:48 -0700, tonyc wrote​:

This is just an RFC for the attached patch, which I'll apply on no
negative comments.

Dave's patches to Perl_runops_debug() have been great for reporting XS
code that doesn't properly extend the stack.

Unfortunately tracking down the location of the fault in complex code
can be difficult with the message reported by the run loop.

The attacked patch adds a similar check to pp_entersub when calling
XSUBs and reports the name of the XSUB to make it simpler to track
down the fault.

This was applied as cfbdacd.

Tony

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2017

@tonycoz - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2017

From @iabyn

On Sun, Sep 03, 2017 at 06​:32​:12PM -0700, Tony Cook via RT wrote​:

On Sun, 27 Aug 2017 20​:58​:48 -0700, tonyc wrote​:

This is just an RFC for the attached patch, which I'll apply on no
negative comments.

Dave's patches to Perl_runops_debug() have been great for reporting XS
code that doesn't properly extend the stack.

Unfortunately tracking down the location of the fault in complex code
can be difficult with the message reported by the run loop.

The attacked patch adds a similar check to pp_entersub when calling
XSUBs and reports the name of the XSUB to make it simpler to track
down the fault.

This was applied as cfbdacd.

Thanks for this!

--
Diplomacy is telling someone to go to hell in such a way that they'll
look forward to the trip

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2018

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release yesterday of Perl 5.28.0, this and 185 other issues have been
resolved.

Perl 5.28.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.28.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2018

@khwilliamson - Status changed from 'pending release' 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