close

Project

General

Profile

Actions

Bug #22016

open
Image

ruby segfaults regularly

Bug #22016: ruby segfaults regularly

Added by wiz (Thomas Klausner) 9 days ago. Updated 4 days ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.2 (2026-03-17 revision d3da9fec82) +PRISM [x86_64-netbsd]
[ruby-core:125352]

Description

When using ruby 4.0.2 on NetBSD-11.99.5/x86_64, built from pkgsrc, I often get core dumps.
Recently it was quite easy to get them using asciidoctor to build the documentation for vms-empire (but that is just one example).

Here is the backtrace of the latest coredump:

GNU gdb (GDB) 17.1
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64--netbsd".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ruby40...

⚠️ warning: exec file is newer than core file.
[New process 29975]
[New process 316]
Core was generated by `ruby40'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007af7bc25f99a in _lwp_kill () from /usr/lib/libc.so.12
[Current thread is 1 (process 29975)]
#0  0x00007af7bc25f99a in _lwp_kill () from /usr/lib/libc.so.12
#1  0x00007af7bc926422 in rb_bug_for_fatal_signal (default_sighandler=0x0, sig=sig@entry=11, ctx=ctx@entry=0x7af7a1f6e420, fmt=fmt@entry=0x7af7bca2ec38 "Segmentation fault at %p") at error.c:1135
#2  0x00007af7bc7d2406 in sigsegv (sig=11, info=0x7af7a1f6e3a0, ctx=0x7af7a1f6e420) at signal.c:948
#3  <signal handler called>
#4  each_location (x=0x7f7fff7c3000, n=338431, cb=cb@entry=0x7af7bc6b4ef5 <gc_mark_machine_stack_location_maybe>, data=0x0) at gc.c:2682
#5  0x00007af7bc6a955b in each_location_ptr (data=0x0, start=<optimized out>, end=<optimized out>, cb=0x7af7bc6b4ef5 <gc_mark_machine_stack_location_maybe>) at gc.c:2691
#6  each_location_ptr (start=<optimized out>, end=<optimized out>, cb=0x7af7bc6b4ef5 <gc_mark_machine_stack_location_maybe>, data=0x0) at gc.c:2688
#7  rb_gc_mark_machine_context (ec=0x7af7bc023650) at gc.c:2978
#8  mark_current_machine_context (ec=0x7af7bc023650) at gc.c:2958
#9  rb_gc_mark_roots (objspace=<optimized out>, categoryp=0x0) at gc.c:3056
#10 mark_roots (objspace=<optimized out>, categoryp=0x0) at gc/default/default.c:4629
#11 0x00007af7bc6bd047 in gc_marks_start (objspace=0x7af7bc018000, full_mark=<optimized out>) at gc/default/default.c:5815
#12 gc_marks (objspace=0x7af7bc018000, full_mark=<optimized out>) at gc/default/default.c:5831
#13 gc_start (objspace=objspace@entry=0x7af7bc018000, reason=<optimized out>, reason@entry=256) at gc/default/default.c:6516
#14 0x00007af7bc6bdd17 in heap_prepare (objspace=0x7af7bc018000, heap=0x7af7bc018028) at gc/default/default.c:2086
#15 heap_next_free_page (objspace=0x7af7bc018000, heap=0x7af7bc018028) at gc/default/default.c:2301
#16 newobj_cache_miss (objspace=0x7af7bc018000, cache=0x7af7bc000000, heap_idx=0, vm_locked=vm_locked@entry=false) at gc/default/default.c:2408
#17 0x00007af7bc6be719 in newobj_alloc (objspace=<optimized out>, cache=<optimized out>, heap_idx=<optimized out>, vm_locked=false) at gc/default/default.c:2432
#18 rb_gc_impl_new_obj (objspace_ptr=<optimized out>, cache_ptr=<optimized out>, klass=135203969407320, flags=8218, wb_protected=<optimized out>, alloc_size=<optimized out>) at gc/default/default.c:2511
#19 newobj_of (cr=<optimized out>, klass=135203969407320, flags=8218, shape_id=0, wb_protected=<optimized out>, size=<optimized out>) at gc.c:996
#20 0x00007af7bc84fcca in svar_new (obj=<optimized out>) at vm_insnhelper.c:642
#21 lep_svar_set (ec=0x7af7bc023650, lep=0x7af7bbefe6a0, key=key@entry=1, val=val@entry=4) at vm_insnhelper.c:656
#22 0x00007af7bc860c19 in vm_cfp_svar_set (ec=<optimized out>, cfp=<optimized out>, key=1, val=4) at vm.c:2014
#23 0x00007af7bc7983f9 in rb_reg_search_set_match (re=re@entry=135203970164480, str=str@entry=135203969420880, pos=pos@entry=0, reverse=reverse@entry=0, set_backref_str=set_backref_str@entry=-1, 
    set_match=set_match@entry=0x7f7fff7bea60) at re.c:1795
#24 0x00007af7bc798707 in rb_reg_search0 (re=re@entry=135203970164480, str=str@entry=135203969420880, pos=pos@entry=0, reverse=reverse@entry=0, set_backref_str=set_backref_str@entry=-1, match=match@entry=0x7f7fff7bea60)
    at re.c:1857
#25 0x00007af7bc7ef856 in rb_pat_search0 (pat=pat@entry=135203970164480, str=str@entry=135203969420880, pos=pos@entry=0, set_backref_str=set_backref_str@entry=-1, match=match@entry=0x7f7fff7bea60) at string.c:6167
#26 0x00007af7bc7febcf in str_gsub (argc=<optimized out>, argv=<optimized out>, str=135203969420880, bang=0) at string.c:6352
#27 0x00007af7bc8612a1 in vm_call_cfunc_with_frame_ (ec=0x7af7bc023650, reg_cfp=0x7af7bbffe310, calling=<optimized out>, argc=1, argv=0x7af7bbefe6b0, stack_bottom=0x7af7bbefe6a8) at vm_insnhelper.c:3902
#28 0x00007af7bc865da4 in vm_sendish (ec=0x7af7bc023650, reg_cfp=0x7af7bbffe310, cd=0x7af7a0a0f8b0, block_handler=<optimized out>, method_explorer=<optimized out>) at vm_callinfo.h:450
#29 0x00007af7bc86c200 in vm_exec_core (ec=0x62, ec@entry=0x7af7bc023650) at insns.def:856
#30 0x00007af7bc871288 in vm_exec_loop (ec=<optimized out>, state=<optimized out>, tag=<optimized out>, result=<optimized out>) at vm.c:2825
#31 rb_vm_exec (ec=0x7af7bc023650) at vm.c:2801
#32 0x00007af7bc874d19 in invoke_iseq_block_from_c (ec=<optimized out>, captured=<optimized out>, self=<optimized out>, argc=<optimized out>, argv=<optimized out>, kw_splat=<optimized out>, 
    passed_block_handler=<optimized out>, cref=0x4, is_lambda=<optimized out>, me=0x0) at vm.c:1820
#33 0x00007af7bc87628e in vm_yield_with_cref (ec=<optimized out>, argc=1, argv=0x7f7fff7beec8, kw_splat=0, cref=0x0, is_lambda=0) at vm.c:1865
#34 vm_yield (ec=<optimized out>, argc=1, argv=0x7f7fff7beec8, kw_splat=0) at vm.c:1879
#35 rb_yield_0 (argc=1, argv=0x7f7fff7beec8) at vm_eval.c:1362
#36 rb_yield (val=<optimized out>) at vm_eval.c:1378
#37 0x00007af7bc6c2366 in each_value_i (key=<optimized out>, value=<optimized out>, _=<optimized out>) at hash.c:3033
#38 0x00007af7bc6c3d42 in hash_foreach_iter () at hash.c:1269
#39 0x00007af7bc7ddb73 in st_general_foreach (tab=<optimized out>, func=0x7af7bc6c3d1b <hash_foreach_iter>, replace=0x0, arg=140187723886960, check_p=1) at st.c:1564
#40 0x00007af7bc6c4c9c in hash_foreach_call (arg=140187723886960) at hash.c:1396
#41 0x00007af7bc69a725 in rb_ec_ensure (ec=0x7af7bc023650, b_proc=<optimized out>, data1=<optimized out>, e_proc=0x7af7bc6c224a <hash_foreach_ensure>, data2=135203970494680) at eval.c:1146
#42 0x00007af7bc69a8dc in rb_ensure (b_proc=<optimized out>, data1=<optimized out>, e_proc=<optimized out>, data2=<optimized out>) at eval.c:1163
#43 0x00007af7bc6c734c in rb_hash_foreach (hash=hash@entry=135203970494680, func=func@entry=0x7af7bc6c2345 <each_value_i>, farg=farg@entry=0) at hash.c:1420
#44 0x00007af7bc6c8404 in rb_hash_each_value (hash=135203970494680) at hash.c:3061
#45 0x00007af7bc8612a1 in vm_call_cfunc_with_frame_ (ec=0x7af7bc023650, reg_cfp=0x7af7bbffe3b8, calling=<optimized out>, argc=0, argv=0x7af7bbefe638, stack_bottom=0x7af7bbefe630) at vm_insnhelper.c:3902
#46 0x00007af7bc865da4 in vm_sendish (ec=0x7af7bc023650, reg_cfp=0x7af7bbffe3b8, cd=0x7af7a0ab1c60, block_handler=<optimized out>, method_explorer=<optimized out>) at vm_callinfo.h:450
#47 0x00007af7bc86c200 in vm_exec_core (ec=0x62, ec@entry=0x7af7bc023650) at insns.def:856
#48 0x00007af7bc871288 in vm_exec_loop (ec=<optimized out>, state=<optimized out>, tag=<optimized out>, result=<optimized out>) at vm.c:2825
#49 rb_vm_exec (ec=0x7af7bc023650) at vm.c:2801
#50 0x00007af7bc6fd247 in require_internal (ec=ec@entry=0x7af7bc023650, fname=<optimized out>, fname@entry=135203969759680, exception=exception@entry=1, warn=<optimized out>) at load.c:1341
#51 0x00007af7bc6fd2ef in rb_require_string_internal (fname=135203969759680, resurrect=resurrect@entry=false) at load.c:1451
#52 0x00007af7bc6fdcd8 in rb_require_string (fname=<optimized out>) at load.c:1437
#53 0x00007af7bc8612a1 in vm_call_cfunc_with_frame_ (ec=0x7af7bc023650, reg_cfp=0x7af7bbffe460, calling=<optimized out>, argc=1, argv=0x7af7bbefe5e0, stack_bottom=0x7af7bbefe5d8) at vm_insnhelper.c:3902
#54 0x00007af7bc86b8fd in vm_sendish (ec=<optimized out>, reg_cfp=<optimized out>, cd=<optimized out>, block_handler=<optimized out>, method_explorer=<optimized out>) at vm_callinfo.h:450
#55 vm_exec_core (ec=0x62, ec@entry=0x7af7bc023650) at insns.def:904
#56 0x00007af7bc871288 in vm_exec_loop (ec=<optimized out>, state=<optimized out>, tag=<optimized out>, result=<optimized out>) at vm.c:2825
#57 rb_vm_exec (ec=0x7af7bc023650) at vm.c:2801
#58 0x00007af7bc6fd247 in require_internal (ec=ec@entry=0x7af7bc023650, fname=<optimized out>, fname@entry=135203970210040, exception=exception@entry=1, warn=<optimized out>) at load.c:1341
#59 0x00007af7bc6fd2ef in rb_require_string_internal (fname=135203970210040, resurrect=resurrect@entry=false) at load.c:1451
#60 0x00007af7bc6fdcd8 in rb_require_string (fname=<optimized out>) at load.c:1437
#61 0x00007af7bc8612a1 in vm_call_cfunc_with_frame_ (ec=0x7af7bc023650, reg_cfp=0x7af7bbffe4d0, calling=<optimized out>, argc=1, argv=0x7af7bbefe580, stack_bottom=0x7af7bbefe578) at vm_insnhelper.c:3902
#62 0x00007af7bc86b8fd in vm_sendish (ec=<optimized out>, reg_cfp=<optimized out>, cd=<optimized out>, block_handler=<optimized out>, method_explorer=<optimized out>) at vm_callinfo.h:450
#63 vm_exec_core (ec=0x62, ec@entry=0x7af7bc023650) at insns.def:904
#64 0x00007af7bc871288 in vm_exec_loop (ec=<optimized out>, state=<optimized out>, tag=<optimized out>, result=<optimized out>) at vm.c:2825
#65 rb_vm_exec (ec=0x7af7bc023650) at vm.c:2801
#66 0x00007af7bc7c30ba in ruby_init_prelude () at ruby.c:1779
#67 ruby_opt_init (opt=opt@entry=0x7f7fff7c09d0) at ruby.c:1829
#68 0x00007af7bc7c5038 in ruby_opt_init (opt=0x7f7fff7c09d0) at ruby.c:1799
#69 prism_script (opt=0x7f7fff7c09d0, result=0x7f7fff7c0188) at ruby.c:2234
#70 process_options (argc=6, argc@entry=8, argv=0x7f7fff7c0c08, argv@entry=0x7f7fff7c0bf8, opt=0x7f7fff7c09d0) at ruby.c:2569
#71 0x00007af7bc7c54e0 in ruby_process_options (argc=argc@entry=8, argv=argv@entry=0x7f7fff7c0bf8) at ruby.c:226
#72 0x00007af7bc69b894 in ruby_options (argc=argc@entry=8, argv=argv@entry=0x7f7fff7c0bf8) at eval.c:119
#73 0x0000000000a045e3 in rb_main (argc=8, argv=0x7f7fff7c0bf8) at ./main.c:42
#74 main (argc=<optimized out>, argv=<optimized out>) at ./main.c:62
[?2004h(gdb) quit
[?2004l

Files

ruby-build.log (42.1 KB) ruby-build.log wiz (Thomas Klausner), 04/29/2026 05:55 PM

Image Updated by wiz (Thomas Klausner) 9 days ago Actions #1 [ruby-core:125353]

And here is the output of the process itself:

asciidoctor40 -D. -a nofooter -b manpage vms-empire.adoc
/usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:311: [BUG] Segmentation fault at 0x00007f7fff7c3000
ruby 4.0.2 (2026-03-17 revision d3da9fec82) +PRISM [x86_64-netbsd]

-- Control frame information -----------------------------------------------
c:0011 p:---- s:0050 e:000049 l:y b:---- CFUNC  :gsub
c:0010 p:0011 s:0045 e:000044 l:y b:0001 METHOD /usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:311
c:0009 p:0006 s:0038 e:000037 l:n b:---- BLOCK  /usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:329 [FINISH]
c:0008 p:---- s:0034 e:000033 l:y b:---- CFUNC  :each_value
c:0007 p:2379 s:0030 e:000029 l:y b:0001 CLASS  /usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:328
c:0006 p:0007 s:0027 e:000026 l:y b:0001 TOP    /usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:11 [FINISH]
c:0005 p:---- s:0024 e:000023 l:y b:---- CFUNC  :require
c:0004 p:0005 s:0019 e:000018 l:y b:0001 TOP    /usr/pkg/lib/ruby/4.0.0/rubygems.rb:9 [FINISH]
c:0003 p:---- s:0012 e:000011 l:y b:---- CFUNC  :require
c:0002 p:0012 s:0007 e:000006 l:y b:0001 TOP    <internal:gem_prelude>:2 [FINISH]
c:0001 p:0000 s:0003 E:000040 l:y b:---- DUMMY  [FINISH]

-- Ruby level backtrace information ----------------------------------------
<internal:gem_prelude>:2:in '<internal:gem_prelude>'
<internal:gem_prelude>:2:in 'require'
/usr/pkg/lib/ruby/4.0.0/rubygems.rb:9:in '<top (required)>'
/usr/pkg/lib/ruby/4.0.0/rubygems.rb:9:in 'require'
/usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:11:in '<top (required)>'
/usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:328:in '<module:RbConfig>'
/usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:328:in 'each_value'
/usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:329:in 'block in <module:RbConfig>'
/usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:311:in 'expand'
/usr/pkg/lib/ruby/4.0.0/x86_64-netbsd/rbconfig.rb:311:in 'gsub'

-- Threading information ---------------------------------------------------
Total ractor count: 1
Ruby thread count for this ractor: 1

-- C level backtrace information -------------------------------------------
unknown address_size:117Unexpected size of .debug_line in /usr/pkg/lib/libruby40.so.40
/usr/pkg/lib/libruby40.so.40(rb_profile_frame_full_label+0x21b) [0x7af7bc8881c4]
/usr/pkg/lib/libruby40.so.40(rb_bug_reporter_add+0x11b) [0x7af7bc690f6f]
/usr/pkg/lib/libruby40.so.40(rb_shape_memsize+0x5b) [0x7af7bc7d2406]
/usr/lib/libc.so.12(__sigtramp_siginfo_2+0x0) [0x7af7bc25fa50]
/usr/pkg/lib/libruby40.so.40(rb_find_file+0x2d) [0x7af7bc6a8437]
/usr/pkg/lib/libruby40.so.40(rb_find_file+0xc1) [0x7af7bc6a955b]
/usr/pkg/lib/libruby40.so.40(rb_gc_disable+0x35b) [0x7af7bc6bd047]
/usr/pkg/lib/libruby40.so.40(rb_gc_disable+0x2cd) [0x7af7bc6bdd17]
/usr/pkg/lib/libruby40.so.40(rb_gc_disable+0x28a) [0x7af7bc6be719]
/usr/pkg/lib/libruby40.so.40(rb_f_notimplement+0x76) [0x7af7bc84fcca]
/usr/pkg/lib/libruby40.so.40(rb_reg_onig_match+0x1cd) [0x7af7bc7983f9]
/usr/pkg/lib/libruby40.so.40(rb_str_buf_append+0xe3) [0x7af7bc7febcf]
/usr/pkg/lib/libruby40.so.40(rb_sourceline+0x142) [0x7af7bc8612a1]
/usr/pkg/lib/libruby40.so.40(rb_method_boundp+0x11e) [0x7af7bc865da4]
/usr/pkg/lib/libruby40.so.40(rb_check_funcall+0xa22) [0x7af7bc86c200]
/usr/pkg/lib/libruby40.so.40(rb_check_funcall+0xa9) [0x7af7bc871288]
/usr/pkg/lib/libruby40.so.40(rb_yield+0xdb) [0x7af7bc87628e]
/usr/pkg/lib/libruby40.so.40(rb_hash_freeze+0x21) [0x7af7bc6c2366]
/usr/pkg/lib/libruby40.so.40(rb_hash_freeze+0x27) [0x7af7bc6c3d42]
/usr/pkg/lib/libruby40.so.40(rb_st_numhash+0x94) [0x7af7bc7ddb73]
/usr/pkg/lib/libruby40.so.40(rb_hash_freeze+0x116) [0x7af7bc6c4c9c]
/usr/pkg/lib/libruby40.so.40(rb_protect+0xac) [0x7af7bc69a725]
/usr/pkg/lib/libruby40.so.40(rb_hash_foreach+0x97) [0x7af7bc6c734c]
/usr/pkg/lib/libruby40.so.40(rb_hash_clear+0x39) [0x7af7bc6c8404]
/usr/pkg/lib/libruby40.so.40(rb_sourceline+0x142) [0x7af7bc8612a1]
/usr/pkg/lib/libruby40.so.40(rb_method_boundp+0x11e) [0x7af7bc865da4]
/usr/pkg/lib/libruby40.so.40(rb_check_funcall+0xa22) [0x7af7bc86c200]
/usr/pkg/lib/libruby40.so.40(rb_check_funcall+0xa9) [0x7af7bc871288]
/usr/pkg/lib/libruby40.so.40(rb_iseq_trace_set_all+0x912) [0x7af7bc6fd247]
/usr/pkg/lib/libruby40.so.40(rb_iseq_trace_set_all+0x6f) [0x7af7bc6fd2ef]
/usr/pkg/lib/libruby40.so.40(rb_require_string+0x36) [0x7af7bc6fdcd8]
/usr/pkg/lib/libruby40.so.40(rb_sourceline+0x142) [0x7af7bc8612a1]
/usr/pkg/lib/libruby40.so.40(rb_check_funcall+0x11f) [0x7af7bc86b8fd]
/usr/pkg/lib/libruby40.so.40(rb_check_funcall+0xa9) [0x7af7bc871288]
/usr/pkg/lib/libruby40.so.40(rb_iseq_trace_set_all+0x912) [0x7af7bc6fd247]
/usr/pkg/lib/libruby40.so.40(rb_iseq_trace_set_all+0x6f) [0x7af7bc6fd2ef]
/usr/pkg/lib/libruby40.so.40(rb_require_string+0x36) [0x7af7bc6fdcd8]
/usr/pkg/lib/libruby40.so.40(rb_sourceline+0x142) [0x7af7bc8612a1]
/usr/pkg/lib/libruby40.so.40(rb_check_funcall+0x11f) [0x7af7bc86b8fd]
/usr/pkg/lib/libruby40.so.40(rb_check_funcall+0xa9) [0x7af7bc871288]
/usr/pkg/lib/libruby40.so.40(ruby_set_script_name+0xc0) [0x7af7bc7c30ba]
/usr/pkg/lib/libruby40.so.40(ruby_set_argv+0x1626) [0x7af7bc7c5038]
/usr/pkg/lib/libruby40.so.40(ruby_process_options+0x151) [0x7af7bc7c54e0]
/usr/pkg/lib/libruby40.so.40(ruby_options+0xcf) [0x7af7bc69b894]
/usr/pkg/bin/ruby40(rb_main+0x19) [0xa045e3] ./main.c:42
/usr/pkg/bin/ruby40(main) ./main.c:62
/usr/pkg/bin/ruby40(__start) (null):0

-- Other runtime information -----------------------------------------------

gmake: *** [Makefile:36: vms-empire.1] Segmentation fault (core dumped)
gmake: *** Waiting for unfinished jobs....
*** Error code 2


Image Updated by luke-gru (Luke Gruber) 4 days ago · Edited Actions #2 [ruby-core:125378]

Can you please provide the output of lscpu and/or uname -a along with the version of gcc? What happens when you install this exact Ruby version without pkgsrc, like from git or a tarball? Thanks.

Image Updated by wiz (Thomas Klausner) 4 days ago Actions #3 [ruby-core:125379]

Ruby does not compile out of the box for me, I'll attach the build log. I've attached the build log of a plain ruby build outside of pkgsrc, same system.
I don't know why it uses clang by default, 'cc' is gcc 14.3.0.

In case you're interested in the details of what pkgsrc does to build ruby, you can check https://github.com/NetBSD/pkgsrc/tree/trunk/lang/ruby40

There is no lscpu on NetBSD, the machine I'm using has a "AMD Ryzen 9 7950X 16-Core Processor", but others have seen this problem too.

Image Updated by wiz (Thomas Klausner) 4 days ago Actions #4 [ruby-core:125380]

Oh, sorry, you asked for more information:
uname -a was in the original bug report, I'm using NetBSD 11.99.5 on x86_64 (= amd64).

Actions

Also available in: PDF Atom