Bug #13548

miniruby SEGV while building with non-default CFLAGS (caused by __builtin_setjmp)

Added by vp (Vladimir Pavlov) over 3 years ago. Updated about 1 year ago.

Target version:


Trying to build ruby-2.4.1 using gcc-5.4.0 I get the attached error. Just-released gcc-7.1.0 causes the similar error. Old gcc-4.8.4 builds successfully.

The build command is:

CFLAGS="-O1 -fweb -g" LDFLAGS=-g ./configure --enable-shared --enable-load-relative && make clean && MAKE="make V=1" make -j1 V=1

Digging into ruby sources leaded me to conclusion the issue is caused by (probably incorrect) using __builtin_setjmp() .

But the links below
get me to think you use setjmp in unportable way. Particularly, you assign the result of setjmp() call to a variable.

afaiu "library" versions of setjmp/longjmp don't require the code to be fully standard-compliant and might work even if the code is incorrect. But when using _builtin* versions the compiler hardly relies on standard compliance and treats ruby code as subjected to undefined behavior (gcc likes to behave like that last few years, even linux kernel used to have bugs appearing when building with newer gcc versions).

I would report the issue to gcc bugzilla too but they like "short piece of code to reproduce" that I failed to create. I don't know whether it's a bug in ruby or in gcc.

Please, try to fix the code if possible so it works with newer gcc version and _builtin-variants of setjmp/longjmp.

Right now adding --with-setjmp-type=setjmp to configure fixes the build.

P.S. From source code I understand it would require to rewrite huge parts of ruby to fix the issue, so I don't expect you fix that in the foreseeable future. Just decided to leave a note here.


builtin_setjmp.txt (8.98 KB) builtin_setjmp.txt vp (Vladimir Pavlov), 05/08/2017 03:25 PM

Also available in: Atom PDF