https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112014-09-24T06:28:52ZRuby Issue Tracking SystemRuby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=490842014-09-24T06:28:52ZAnonymous
<ul></ul><p>The segfault also occurs on the OS X 10.9 system ruby, <code>2.0.0-p481</code>; not sure about the most recent patch release.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=490922014-09-25T05:11:52ZAnonymous
<ul><li><strong>File</strong> <a href="/attachments/4718">ruby_2014-09-25-000925_haswell.log</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4718/ruby_2014-09-25-000925_haswell.log">ruby_2014-09-25-000925_haswell.log</a> added</li></ul><p>I've attached the OS X crash report.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=490932014-09-25T05:18:12ZAnonymous
<ul><li><strong>File</strong> <a href="/attachments/4719">ruby_2014-09-25-001644_haswell.log</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4719/ruby_2014-09-25-001644_haswell.log">ruby_2014-09-25-001644_haswell.log</a> added</li></ul><p>As I noted, running the example code on trunk does not segfault (it raises SystemStackError a second time, as I would expect):</p>
<pre><code>$ ruby -ve "l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end"
ruby 2.2.0dev (2014-09-25 trunk 47651) [x86_64-darwin13]
-e:1:in `block in <main>': stack level too deep (SystemStackError)
from -e:1:in `call'
from -e:1:in `block in <main>'
from -e:1:in `call'
from -e:1:in `block in <main>'
from -e:1:in `call'
from -e:1:in `block in <main>'
from -e:1:in `call'
from -e:1:in `block in <main>'
... 9604 levels...
from -e:1:in `call'
from -e:1:in `block in <main>'
from -e:1:in `call'
from -e:1:in `<main>'
</code></pre>
<p>However, if I run the same code in IRB, it <em>does</em> segfault:</p>
<pre><code>$ irb
irb(main):001:0> RUBY_DESCRIPTION
=> "ruby 2.2.0dev (2014-09-25 trunk 47651) [x86_64-darwin13]"
irb(main):002:0> l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end
Segmentation fault: 11
</code></pre>
<p>I've attached the crash report for this one as well.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=491022014-09-26T05:45:57Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>I can't reproduce it with irb, but it might access over the top of stack.<br>
Possibly, we need more margin for the guard page.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=493822014-10-13T07:37:01Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>I can't reproduce following versions:</p>
<pre><code>ruby 1.9.3p548 (2014-09-06) [x86_64-darwin13.4.0]
ruby 2.0.0p576 (2014-09-19 revision 47628) [x86_64-darwin13.4.0]
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
ruby 2.2.0preview1 (2014-09-17 trunk 47616) [x86_64-darwin13]
ruby 2.2.0dev (2014-10-13 trunk 47898) [x86_64-darwin13]
</code></pre> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=494102014-10-13T17:16:54ZAnonymous
<ul></ul><p>I can reproduce it on 2.0.0-p576 when compiled with <code>-Os</code>, but not <code>-O2</code>:</p>
<pre><code>$ make clean && ./configure --disable-install-doc CC=clang CFLAGS=-O2 && make -j12
$ ./miniruby -v
ruby 2.0.0p576 (2014-09-19 revision 47627) [x86_64-darwin13.4.0]
$ ./miniruby -e "l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end"
-e:1: stack level too deep (SystemStackError)
$ make clean && ./configure --disable-install-doc CC=clang CFLAGS=-Os && make -j12
$ ./miniruby -v
ruby 2.0.0p576 (2014-09-19 revision 47627) [x86_64-darwin13.4.0]
$ ./miniruby -e "l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end"
Segmentation fault: 11
</code></pre>
<p>On 2.1.3, it does not happen when compiled without optimizations, but even using <code>-O1</code> is enough to trigger it:</p>
<pre><code>$ make clean && ./configure --disable-install-doc CC=clang && make -j12
$ ./miniruby -v
ruby 2.1.3p242 (2014-09-19 revision 47629) [x86_64-darwin13.0]
$ ./miniruby -e "l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end"
-e:1: stack level too deep (SystemStackError)
$ make clean && ./configure --disable-install-doc CC=clang CFLAGS=-O1 && make -j12
$ ./miniruby -v
ruby 2.1.3p242 (2014-09-19 revision 47629) [x86_64-darwin13.0]
$ ./miniruby -e "l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end"
Segmentation fault: 11
</code></pre>
<p>And similarly on trunk, it is triggered with <code>-O1</code> or higher:</p>
<pre><code>$ make clean && ./configure --disable-install-doc CC=clang && make -j12
$ ./miniruby -v
ruby 2.2.0dev (2014-10-14 trunk 47906) [x86_64-darwin13]
$ ./miniruby -e "l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end"
-e:1:in `call': stack level too deep (SystemStackError)
make clean && ./configure --disable-install-doc CC=clang CFLAGS=-O1 && make -j12
$ ./miniruby -v
ruby 2.2.0dev (2014-10-14 trunk 47906) [x86_64-darwin13]
$ ./miniruby -e "l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end"
Segmentation fault: 11
</code></pre>
<p>I'm using the latest Apple clang:</p>
<pre><code>$ clang --version
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
</code></pre> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=494192014-10-14T01:49:52Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul></ul><p>I can't reproduce with gcc-4.9(not clang).</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=494292014-10-14T12:02:58Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul></ul><p>I can reproduce clang on linux.</p>
<pre><code>[hsbt@chkbuild001 ~]$ clang -v
clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-amazon-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-amazon-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-amazon-linux/4.8.2
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-amazon-linux/4.8.2
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
</code></pre> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=494772014-10-16T01:41:46ZAnonymous
<ul></ul><p>I can reproduce it with gcc 4.9.1 at <code>-Os</code>:</p>
<pre><code> $ gcc-4.9 --version
gcc-4.9 (Homebrew gcc 4.9.1) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ make clean && ./configure --disable-install-doc CC=gcc-4.9 CFLAGS=-Os && make -j12
$ ./miniruby -v
ruby 2.2.0dev (2014-10-16 trunk 47971) [x86_64-darwin13]
$ ./miniruby -e "l = -> { l.() }; begin; l.(); rescue SystemStackError; l.(); end"
Segmentation fault: 11
</code></pre> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=494852014-10-16T05:22:07Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/49485/diff?detail_id=35706">diff</a>)</li></ul><p>I could reproduce it with gcc-4.9 on either Linux and OS X.<br>
On Linux, SIGSEGV seems masked after the first stack overflow occurred, and it seems working by enabling interrupts.</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gh">diff --git c/eval.c i/eval.c
index 3e4ea16..6bd6ac9 100644
</span><span class="gd">--- c/eval.c
</span><span class="gi">+++ i/eval.c
</span><span class="p">@@ -500,7 +500,6 @@</span> setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
if (cause == Qundef) {
cause = nocause ? Qnil : get_thread_errinfo(th);
}
<span class="gd">- exc_setup_cause(mesg, cause);
</span>
file = rb_sourcefile();
if (file) line = rb_sourceline();
<span class="p">@@ -526,6 +525,7 @@</span> setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
set_backtrace(mesg, at);
}
}
<span class="gi">+ exc_setup_cause(mesg, cause);
</span>
if (!NIL_P(mesg)) {
th->errinfo = mesg;
<span class="gh">diff --git c/signal.c i/signal.c
index d3c7cb8..b939930 100644
</span><span class="gd">--- c/signal.c
</span><span class="gi">+++ i/signal.c
</span><span class="p">@@ -767,6 +767,7 @@</span> check_stack_overflow(const uintptr_t addr, const ucontext_t *ctx)
* place. */
th->tag = th->tag->prev;
}
<span class="gi">+ rb_enable_interrupt();
</span> ruby_thread_stack_overflow(th);
}
}
</code></pre>
<p>However, on OS X it makes the second stack overflow SIGILL, with no outputs.<br>
I have no idea what happens there.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=605492016-09-19T07:48:07Zbackus (John Backus)
<ul></ul><p>Any update on this issue? I ran into this bug yesterday and spent hours investigating the source of the segfault. Here is the code that caused the issue for me:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">foo</span>
<span class="n">define_singleton_method</span><span class="p">(</span><span class="ss">:method_missing</span><span class="p">)</span> <span class="p">{</span> <span class="o">|*|</span> <span class="n">invalid_method</span> <span class="p">}</span>
<span class="n">define_singleton_method</span><span class="p">(</span><span class="ss">:define_singleton_method</span><span class="p">)</span> <span class="p">{</span> <span class="o">|*|</span> <span class="n">invalid_method</span> <span class="p">}</span>
<span class="k">end</span>
<span class="n">foo</span>
<span class="k">begin</span>
<span class="n">do_not_segfault</span>
<span class="k">rescue</span> <span class="no">SystemStackError</span>
<span class="k">end</span>
<span class="n">do_not_segfault</span>
</code></pre> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=605572016-09-20T00:48:00Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>It causes <code>SystemStackError</code> as expected, with ruby 2.3.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=605972016-09-22T07:24:56Zbackus (John Backus)
<ul></ul><p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>It causes <code>SystemStackError</code> as expected, with ruby 2.3.</p>
</blockquote>
<p>No it definitely segfaults for me:</p>
<pre><code class="text syntaxhl" data-language="text">$ cat ex.rb
l = -> { l.() }
begin
l.()
rescue SystemStackError
l.() # segfault
end
$ which ruby
/Users/johnbackus/.rubies/ruby-2.3.1/bin/ruby
$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
$ ruby ex.rb
[1] 82276 segmentation fault ruby ex.rb
</code></pre>
<p>anything I can run to help you reproduce for 2.3 on OS X?</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=617212016-11-25T13:28:15Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul><p>ping nobu.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=647512017-05-11T05:47:22Zbackus (John Backus)
<ul></ul><p>ping nobu</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=647652017-05-12T06:27:15Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>On macOS, <code>--with-setjmp-type=setjmp</code> configuration option may fix it.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=647752017-05-12T07:54:11Zbackus (John Backus)
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>On macOS, <code>--with-setjmp-type=setjmp</code> configuration option may fix it.</p>
</blockquote>
<p>This does fix the issue on macOS for me, thank you. Maybe this should be the macOS default?</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=654062017-06-16T09:47:14Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p><code>SystemStackError</code> seems uncatchable since r58492.</p> Ruby master - Bug #10290: segfault when calling a lambda recursively after rescuing SystemStackErrorhttps://redmine.ruby-lang.org/issues/10290?journal_id=808772019-08-20T20:20:53Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>I was able to reproduce the segfault in ruby 2.3 and 2.4, but not in 2.5, 2.6, 2.7.0-preview1, or the master branch, so I think this problem is fixed. If this problem still occurs for you, please reply with your environment details.</p>