Project

General

Profile

Actions

Bug #18062

closed

Ruby with enabled LTO segfaults during build

Added by vo.x (Vit Ondruch) over 3 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
[ruby-core:104780]

Description

After a while, I am trying to enable LTO for Ruby in Fedora. Previously I hit #17052, but now I observe issues much earlier during compliation already:

./miniruby -I./lib -I. -I.ext/common  ./tool/generic_erb.rb -c -o encdb.h ./template/encdb.h.tmpl ./enc enc
<internal:gc>:240: [BUG] Segmentation fault at 0x0000000000000004
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0003 p:0008 s:0011 e:000008 CLASS  <internal:gc>:240
c:0002 p:0015 s:0006 e:000005 TOP    <internal:gc>:235 [FINISH]
c:0001 p:0000 s:0003 E:000230 (none) [FINISH]
-- Ruby level backtrace information ----------------------------------------
<internal:gc>:235:in `<internal:gc>'
<internal:gc>:240:in `<module:ObjectSpace>'
-- Machine register context ------------------------------------------------
 RIP: 0x00005585da1c832a RBP: 0x000022f100140003 RSP: 0x00007ffd6460a6a0
 RAX: 0x0000000000000001 RBX: 0x00000000000022f1 RCX: 0x00005585dade5d90
 RDX: 0x000022f100140003 RDI: 0x00005585dae0c2d8 RSI: 0x0000000000000000
  R8: 0x0000000000000000  R9: 0x00007ffd6460a6e0 R10: 0x00005585daebbe50
 R11: 0x00007f00a785baa0 R12: 0x0000000000000000 R13: 0x00005585dade5d90
 R14: 0x00005585dae0c2d8 R15: 0x00005585dade5d90 EFL: 0x0000000000010202
-- C level backtrace information -------------------------------------------
./miniruby(rb_print_backtrace+0x19) [0x5585da1cdba9]
./miniruby(rb_vm_bugreport+0x215) [0x5585da1d1a05]
./miniruby(rb_bug_for_fatal_signal+0xf4) [0x5585da004fc4]
./miniruby(sigsegv+0x4d) [0x5585da13709d]
[0x7f00a76a4760]
./miniruby(vm_ccs_push.part.0.lto_priv.0+0x2a) [0x5585da1c832a]
./miniruby(vm_search_cc+0xfe) [0x5585da1a7b7e]
./miniruby(vm_search_method_slowpath0.lto_priv.0+0x40) [0x5585da1a7d30]
./miniruby(vm_sendish.lto_priv.0+0x6e4) [0x5585da1aeff4]
./miniruby(vm_exec_core.lto_priv.0+0xa8) [0x5585da1b25b8]
./miniruby(rb_vm_exec+0x110) [0x5585da1c9ea0]
./miniruby(ruby_opt_init+0x6f) [0x5585da1355af]
./miniruby(load_file_internal+0x4b2) [0x5585da1376e2]
./miniruby(rb_ensure+0x106) [0x5585da00d5a6]
./miniruby(process_options+0x19e5) [0x5585da139a65]
./miniruby(ruby_process_options+0x151) [0x5585da13a551]
./miniruby(ruby_options+0x119) [0x5585da012de9]
./miniruby(main+0x57) [0x5585d9f8a1e7]
-- Other runtime information -----------------------------------------------
* Loaded script: ./miniruby
* Loaded features:
    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 ruby2_keywords.rb
* Process memory map:
5585d9f5d000-5585d9f85000 r--p 00000000 fc:05 137001366                  /builddir/build/BUILD/ruby-3.0.2/miniruby
5585d9f85000-5585da1f2000 r-xp 00028000 fc:05 137001366                  /builddir/build/BUILD/ruby-3.0.2/miniruby
5585da1f2000-5585da2f6000 r--p 00295000 fc:05 137001366                  /builddir/build/BUILD/ruby-3.0.2/miniruby
5585da2f6000-5585da2fd000 r--p 00398000 fc:05 137001366                  /builddir/build/BUILD/ruby-3.0.2/miniruby
5585da2fd000-5585da2fe000 rw-p 0039f000 fc:05 137001366                  /builddir/build/BUILD/ruby-3.0.2/miniruby
5585da2fe000-5585da30e000 rw-p 00000000 00:00 0 
5585dad8d000-5585daed3000 rw-p 00000000 00:00 0                          [heap]
7f00a28ae000-7f00a409b000 r--s 00000000 fc:05 137001366                  /builddir/build/BUILD/ruby-3.0.2/miniruby
7f00a409b000-7f00a409e000 r--p 00000000 fc:05 270435464                  /usr/lib64/libgcc_s-11-20210728.so.1
7f00a409e000-7f00a40b0000 r-xp 00003000 fc:05 270435464                  /usr/lib64/libgcc_s-11-20210728.so.1
7f00a40b0000-7f00a40b3000 r--p 00015000 fc:05 270435464                  /usr/lib64/libgcc_s-11-20210728.so.1
7f00a40b3000-7f00a40b4000 r--p 00017000 fc:05 270435464                  /usr/lib64/libgcc_s-11-20210728.so.1
7f00a40b4000-7f00a40b5000 rw-p 00018000 fc:05 270435464                  /usr/lib64/libgcc_s-11-20210728.so.1
7f00a40b5000-7f00a40b6000 ---p 00000000 00:00 0 
7f00a40b6000-7f00a4157000 rw-p 00000000 00:00 0 
7f00a4157000-7f00a4158000 ---p 00000000 00:00 0 
7f00a4158000-7f00a41f9000 rw-p 00000000 00:00 0 
7f00a41f9000-7f00a41fa000 ---p 00000000 00:00 0 
7f00a41fa000-7f00a429b000 rw-p 00000000 00:00 0 
7f00a429b000-7f00a429c000 ---p 00000000 00:00 0 
7f00a429c000-7f00a433d000 rw-p 00000000 00:00 0 
7f00a433d000-7f00a433e000 ---p 00000000 00:00 0 
7f00a433e000-7f00a43df000 rw-p 00000000 00:00 0 
7f00a43df000-7f00a43e0000 ---p 00000000 00:00 0 
7f00a43e0000-7f00a4481000 rw-p 00000000 00:00 0 
7f00a4481000-7f00a4482000 ---p 00000000 00:00 0 
7f00a4482000-7f00a4523000 rw-p 00000000 00:00 0 
7f00a4523000-7f00a4524000 ---p 00000000 00:00 0 
7f00a4524000-7f00a45c5000 rw-p 00000000 00:00 0 
7f00a45c5000-7f00a45c6000 ---p 00000000 00:00 0 
7f00a45c6000-7f00a4667000 rw-p 00000000 00:00 0 
7f00a4667000-7f00a4668000 ---p 00000000 00:00 0 
7f00a4668000-7f00a4709000 rw-p 00000000 00:00 0 
7f00a4709000-7f00a470a000 ---p 00000000 00:00 0 
7f00a470a000-7f00a47ab000 rw-p 00000000 00:00 0 
7f00a47ab000-7f00a47ac000 ---p 00000000 00:00 0 
7f00a47ac000-7f00a484d000 rw-p 00000000 00:00 0 
7f00a484d000-7f00a484e000 ---p 00000000 00:00 0 
7f00a484e000-7f00a48ef000 rw-p 00000000 00:00 0 
7f00a48ef000-7f00a48f0000 ---p 00000000 00:00 0 
7f00a48f0000-7f00a4991000 rw-p 00000000 00:00 0 
7f00a4991000-7f00a4992000 ---p 00000000 00:00 0 
7f00a4992000-7f00a4a33000 rw-p 00000000 00:00 0 
7f00a4a33000-7f00a4a34000 ---p 00000000 00:00 0 
7f00a4a34000-7f00a4ad5000 rw-p 00000000 00:00 0 
7f00a4ad5000-7f00a4ad6000 ---p 00000000 00:00 0 
7f00a4ad6000-7f00a4b77000 rw-p 00000000 00:00 0 
7f00a4b77000-7f00a4b78000 ---p 00000000 00:00 0 
7f00a4b78000-7f00a4c19000 rw-p 00000000 00:00 0 
7f00a4c19000-7f00a4c1a000 ---p 00000000 00:00 0 
7f00a4c1a000-7f00a4cbb000 rw-p 00000000 00:00 0 
7f00a4cbb000-7f00a4cbc000 ---p 00000000 00:00 0 
7f00a4cbc000-7f00a4d5d000 rw-p 00000000 00:00 0 
7f00a4d5d000-7f00a4d5e000 ---p 00000000 00:00 0 
7f00a4d5e000-7f00a4dff000 rw-p 00000000 00:00 0 
7f00a4dff000-7f00a4e00000 ---p 00000000 00:00 0 
7f00a4e00000-7f00a4ea1000 rw-p 00000000 00:00 0 
7f00a4ea1000-7f00a4ea2000 ---p 00000000 00:00 0 
7f00a4ea2000-7f00a4f43000 rw-p 00000000 00:00 0 
7f00a4f43000-7f00a4f44000 ---p 00000000 00:00 0 
7f00a4f44000-7f00a4fe5000 rw-p 00000000 00:00 0 
7f00a4fe5000-7f00a4fe6000 ---p 00000000 00:00 0 
7f00a4fe6000-7f00a5087000 rw-p 00000000 00:00 0 
7f00a5087000-7f00a5088000 ---p 00000000 00:00 0 
7f00a5088000-7f00a5129000 rw-p 00000000 00:00 0 
7f00a5129000-7f00a512a000 ---p 00000000 00:00 0 
7f00a512a000-7f00a51cb000 rw-p 00000000 00:00 0 
7f00a51cb000-7f00a51cc000 ---p 00000000 00:00 0 
7f00a51cc000-7f00a526d000 rw-p 00000000 00:00 0 
7f00a526d000-7f00a526e000 ---p 00000000 00:00 0 
7f00a526e000-7f00a530f000 rw-p 00000000 00:00 0 
7f00a530f000-7f00a5310000 ---p 00000000 00:00 0 
7f00a5310000-7f00a53b1000 rw-p 00000000 00:00 0 
7f00a53b1000-7f00a53b2000 ---p 00000000 00:00 0 
7f00a53b2000-7f00a5453000 rw-p 00000000 00:00 0 
7f00a5453000-7f00a5454000 ---p 00000000 00:00 0 
7f00a5454000-7f00a7662000 rw-p 00000000 00:00 0 
7f00a7662000-7f00a768e000 r--p 00000000 fc:05 270939738                  /usr/lib64/libc.so.6
7f00a768e000-7f00a7803000 r-xp 0002c000 fc:05 270939738                  /usr/lib64/libc.so.6
7f00a7803000-7f00a7857000 r--p 001a1000 fc:05 270939738                  /usr/lib64/libc.so.6
7f00a7857000-7f00a7858000 ---p 001f5000 fc:05 270939738                  /usr/lib64/libc.so.6
7f00a7858000-7f00a785b000 r--p 001f5000 fc:05 270939738                  /usr/lib64/libc.so.6
7f00a785b000-7f00a785e000 rw-p 001f8000 fc:05 270939738                  /usr/lib64/libc.so.6
7f00a785e000-7f00a786b000 rw-p 00000000 00:00 0 
7f00a786b000-7f00a787a000 r--p 00000000 fc:05 270939741                  /usr/lib64/libm.so.6
7f00a787a000-7f00a78eb000 r-xp 0000f000 fc:05 270939741                  /usr/lib64/libm.so.6
7f00a78eb000-7f00a7945000 r--p 00080000 fc:05 270939741                  /usr/lib64/libm.so.6
7f00a7945000-7f00a7946000 r--p 000d9000 fc:05 270939741                  /usr/lib64/libm.so.6
7f00a7946000-7f00a7947000 rw-p 000da000 fc:05 270939741                  /usr/lib64/libm.so.6
7f00a7947000-7f00a7949000 r--p 00000000 fc:05 271023995                  /usr/lib64/libcrypt.so.2.0.0
7f00a7949000-7f00a795d000 r-xp 00002000 fc:05 271023995                  /usr/lib64/libcrypt.so.2.0.0
7f00a795d000-7f00a7976000 r--p 00016000 fc:05 271023995                  /usr/lib64/libcrypt.so.2.0.0
7f00a7976000-7f00a7977000 ---p 0002f000 fc:05 271023995                  /usr/lib64/libcrypt.so.2.0.0
7f00a7977000-7f00a7978000 r--p 0002f000 fc:05 271023995                  /usr/lib64/libcrypt.so.2.0.0
7f00a7978000-7f00a7981000 rw-p 00000000 00:00 0 
7f00a7981000-7f00a7992000 r--p 00000000 fc:05 271068897                  /usr/lib64/libgmp.so.10.4.0
7f00a7992000-7f00a7a0a000 r-xp 00011000 fc:05 271068897                  /usr/lib64/libgmp.so.10.4.0
7f00a7a0a000-7f00a7a21000 r--p 00089000 fc:05 271068897                  /usr/lib64/libgmp.so.10.4.0
7f00a7a21000-7f00a7a23000 r--p 0009f000 fc:05 271068897                  /usr/lib64/libgmp.so.10.4.0
7f00a7a23000-7f00a7a24000 rw-p 000a1000 fc:05 271068897                  /usr/lib64/libgmp.so.10.4.0
7f00a7a24000-7f00a7a27000 r--p 00000000 fc:05 271023970                  /usr/lib64/libz.so.1.2.11
7f00a7a27000-7f00a7a35000 r-xp 00003000 fc:05 271023970                  /usr/lib64/libz.so.1.2.11
7f00a7a35000-7f00a7a3b000 r--p 00011000 fc:05 271023970                  /usr/lib64/libz.so.1.2.11
7f00a7a3b000-7f00a7a3c000 ---p 00017000 fc:05 271023970                  /usr/lib64/libz.so.1.2.11
7f00a7a3c000-7f00a7a3d000 r--p 00017000 fc:05 271023970                  /usr/lib64/libz.so.1.2.11
7f00a7a3d000-7f00a7a3e000 rw-p 00000000 00:00 0 
7f00a7a41000-7f00a7a43000 rw-p 00000000 00:00 0 
7f00a7a43000-7f00a7a44000 r--p 00000000 fc:05 270939734                  /usr/lib64/ld-linux-x86-64.so.2
7f00a7a44000-7f00a7a69000 r-xp 00001000 fc:05 270939734                  /usr/lib64/ld-linux-x86-64.so.2
7f00a7a69000-7f00a7a73000 r--p 00026000 fc:05 270939734                  /usr/lib64/ld-linux-x86-64.so.2
7f00a7a73000-7f00a7a75000 r--p 0002f000 fc:05 270939734                  /usr/lib64/ld-linux-x86-64.so.2
7f00a7a75000-7f00a7a77000 rw-p 00031000 fc:05 270939734                  /usr/lib64/ld-linux-x86-64.so.2
7ffd63e17000-7ffd64616000 rw-p 00000000 00:00 0                          [stack]
7ffd64762000-7ffd64766000 r--p 00000000 00:00 0                          [vvar]
7ffd64766000-7ffd64768000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
make: *** [uncommon.mk:1096: encdb.h] Aborted (core dumped)

Files

0001-Get-rid-of-type-punning-pointer-cast.patch (1.41 KB) 0001-Get-rid-of-type-punning-pointer-cast.patch nobu (Nobuyoshi Nakada), 08/06/2021 12:10 PM
4716.patch (7.33 KB) 4716.patch 3.0.2 patch vo.x (Vit Ondruch), 08/09/2021 09:41 AM
jaruga_make_cflags_with_O2_lto_flags.log (16.2 KB) jaruga_make_cflags_with_O2_lto_flags.log jaruga (Jun Aruga), 08/10/2021 06:25 PM
jaruga_make_check.log (263 KB) jaruga_make_check.log jaruga (Jun Aruga), 08/10/2021 06:25 PM

Updated by vo.x (Vit Ondruch) over 3 years ago

GDB output:

$ gdb ./miniruby  
GNU gdb (GDB) Fedora 10.2-6.fc35
Copyright (C) 2021 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-redhat-linux-gnu".
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 ./miniruby...
(gdb) r -I./lib -I. -I.ext/common  ./tool/generic_erb.rb -c -o encdb.h ./template/encdb.h.tmpl ./enc enc
Starting program: /builddir/build/BUILD/ruby-3.0.2/miniruby -I./lib -I. -I.ext/common  ./tool/generic_erb.rb -c -o encdb.h ./template/encdb.h.tmpl ./enc enc
Download failed: No route to host.  Continuing without debug info for /builddir/build/BUILD/ruby-3.0.2/system-supplied DSO at 0x7ffff7fc9000.
Download failed: No route to host.  Continuing without debug info for /lib64/libz.so.1.
Download failed: No route to host.  Continuing without debug info for /lib64/libgmp.so.10.
Download failed: No route to host.  Continuing without debug info for /lib64/libcrypt.so.2.
Download failed: No route to host.  Continuing without debug info for /lib64/libm.so.6.
Download failed: No route to host.  Continuing without debug info for /lib64/libc.so.6.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
vm_ccs_push.part.0.lto_priv.0 (klass=93824996623120, ccs=0x0, ci=0x22f100140003, cc=0x55555595ddf0) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1579
1579	    if (UNLIKELY(ccs->len == ccs->capa)) {
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.34-1.fc35.x86_64 gmp-6.2.0-7.fc35.x86_64 libxcrypt-4.4.23-2.fc35.x86_64 zlib-1.2.11-30.fc35.x86_64
(gdb) where 
#0  vm_ccs_push.part.0.lto_priv.0 (klass=93824996623120, ccs=0x0, ci=0x22f100140003, cc=0x55555595ddf0) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1579
#1  0x000055555579eb7e in vm_ccs_push (cc=0x55555595ddf0, ci=0x22f100140003, ccs=<optimized out>, klass=93824996623120) at ./include/ruby/internal/fl_type.h:237
#2  vm_search_cc (klass=klass@entry=93824996623120, ci=0x22f100140003) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1718
#3  0x000055555579ed30 in rb_vm_search_method_slowpath (klass=93824996623120, ci=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1736
#4  vm_search_method_slowpath0 (cd_owner=93824996467240, cd=cd@entry=0x555555a358f0, klass=93824996623120) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1758
#5  0x00005555557a5ff4 in vm_search_method_fastpath (klass=<optimized out>, cd=0x555555a358f0, cd_owner=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1824
#6  vm_sendish (ec=0x555555909c80, reg_cfp=0x7ffff7b84f68, cd=0x555555a358f0, block_handler=<optimized out>, method_explorer=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:4526
#7  0x00005555557a95b8 in vm_exec_core (ec=0x555555909c80, initial=0) at /builddir/build/BUILD/ruby-3.0.2/insns.def:789
#8  0x00005555557c0ea0 in rb_vm_exec (ec=0x555555909c80, mjit_enable_p=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm.c:2172
#9  0x000055555572c5af in rb_load_with_builtin_functions (table=0x5555558f0240 <gc_table>, feature_name=0x55555588e0c3 "gc") at /builddir/build/BUILD/ruby-3.0.2/mini_builtin.c:48
#10 Init_builtin_gc () at /builddir/build/BUILD/ruby-3.0.2/gc.rbinc:212
#11 rb_call_builtin_inits () at /builddir/build/BUILD/ruby-3.0.2/inits.c:88
#12 ruby_opt_init (opt=0x7fffffffdfb0) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:1520
#13 ruby_opt_init (opt=opt@entry=0x7fffffffdfb0) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:1506
#14 0x000055555572e6e2 in load_file_internal (argp_v=140737488309936) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:2181
#15 0x00005555556045a6 in rb_ensure (b_proc=0x55555572e230 <load_file_internal>, data1=140737488309936, e_proc=<optimized out>, data2=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/eval.c:1162
#16 0x0000555555730a65 in load_file (opt=0x7fffffffdfb0, script=1, f=<optimized out>, fname=<optimized out>, parser=93824996498920) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:2323
#17 process_options (argc=6, argv=0x7fffffffe350, opt=0x7fffffffdfb0) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:1960
#18 0x0000555555731551 in ruby_process_options (argc=11, argv=0x7fffffffe328) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:230
#19 0x0000555555609de9 in ruby_options (argc=11, argv=0x7fffffffe328) at /builddir/build/BUILD/ruby-3.0.2/eval.c:138
#20 0x00005555555811e7 in main (argc=<optimized out>, argv=<optimized out>) at ./main.c:50
(gdb) list
1574	    }
1575	    else if (! vm_ci_markable(ci)) {
1576	        return;
1577	    }
1578	
1579	    if (UNLIKELY(ccs->len == ccs->capa)) {
1580	        if (ccs->capa == 0) {
1581	            ccs->capa = 1;
1582	            ccs->entries = ALLOC_N(struct rb_class_cc_entries_entry, ccs->capa);
1583	        }
(gdb) 
1584	        else {
1585	            ccs->capa *= 2;
1586	            REALLOC_N(ccs->entries, struct rb_class_cc_entries_entry, ccs->capa);
1587	        }
1588	    }
1589	    VM_ASSERT(ccs->len < ccs->capa);
1590	
1591	    const int pos = ccs->len++;
1592	    RB_OBJ_WRITE(klass, &ccs->entries[pos].ci, ci);
1593	    RB_OBJ_WRITE(klass, &ccs->entries[pos].cc, cc);
(gdb) 

Updated by vo.x (Vit Ondruch) over 3 years ago

I'd say it goes sideways somewhere here:

https://github.com/ruby/ruby/blob/0db68f023372b634603c74fca94588b457be084c/vm_insnhelper.c#L1708

I'm not sure why the rb_id_table_lookup does not provide any value for css, but there is no check for NULL further down the path.

Updated by vo.x (Vit Ondruch) over 3 years ago

vo.x (Vit Ondruch) wrote in #note-2:

I'd say it goes sideways somewhere here:

https://github.com/ruby/ruby/blob/0db68f023372b634603c74fca94588b457be084c/vm_insnhelper.c#L1708

I'm not sure why the rb_id_table_lookup does not provide any value for css, but there is no check for NULL further down the path.

Actually, this is weird:

Breakpoint 1, vm_ccs_push (cc=0x55555595ddf0, ci=0x22f100140003, ccs=0x555555a31f80, klass=93824996623120) at ./include/ruby/internal/fl_type.h:237
237	    return RBASIC(obj)->flags & flags;
(gdb) s
vm_ccs_push.part.0.lto_priv.0 (klass=93824996623120, ccs=0x0, ci=0x22f100140003, cc=0x55555595ddf0) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1570
1570	vm_ccs_push(VALUE klass, struct rb_class_cc_entries *ccs, const struct rb_callinfo *ci, const struct rb_callcache *cc)

It seems the ccs has some non NULL value initially, but it changes into NULL with the next step ...

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • File 0001-Get-rid-of-type-punning-pointer-cast.patch added

Maybe a strict aliasing issue?

Updated by vo.x (Vit Ondruch) over 3 years ago

nobu (Nobuyoshi Nakada) wrote in #note-4:

Maybe a strict aliasing issue?

The patch changes the error:

./miniruby -I./lib -I. -I.ext/common  ./tool/generic_erb.rb -c -o encdb.h ./template/encdb.h.tmpl ./enc enc
<internal:ractor>:431: [BUG] Segmentation fault at 0x0000000000000004
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0003 p:0046 s:0013 e:000008 CLASS  <internal:ractor>:431
c:0002 p:0007 s:0006 e:000005 TOP    <internal:ractor>:228 [FINISH]
c:0001 p:0000 s:0003 E:001c30 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
<internal:ractor>:228:in `<internal:ractor>'
<internal:ractor>:431:in `<class:Ractor>'

-- Machine register context ------------------------------------------------
 RIP: 0x0000559b9c12eb82 RBP: 0x0000559b9cefc210 RSP: 0x00007ffd3ab56bd0
 RAX: 0x0000000000000001 RBX: 0x000000000000009f RCX: 0x00007fa0da7cb060
 RDX: 0x0000000000000003 RDI: 0x0000559b9cef4650 RSI: 0x000000000000009f
  R8: 0x0000000000000003  R9: 0x00007ffd3ab56bd8 R10: 0x0000559b9ce01a30
 R11: 0x00007ffd3ab56a10 R12: 0x0000009f00100007 R13: 0x0000559b9ce3d5e0
 R14: 0x0000559b9ced0d80 R15: 0x0000559b9ce3d658 EFL: 0x0000000000010202

-- C level backtrace information -------------------------------------------
./miniruby(rb_print_backtrace+0x19) [0x559b9c154c49]
./miniruby(rb_vm_bugreport+0x215) [0x559b9c158aa5]
./miniruby(rb_bug_for_fatal_signal+0xf4) [0x559b9bf8bfe4]
./miniruby(sigsegv+0x4d) [0x559b9c0be14d]
[0x7fa0da910760]
./miniruby(vm_search_cc+0x62) [0x559b9c12eb82]
./miniruby(vm_search_method_slowpath0.lto_priv.0+0x40) [0x559b9c12edd0]
./miniruby(vm_sendish.lto_priv.0+0x6e4) [0x559b9c136094]
./miniruby(vm_exec_core.lto_priv.0+0xa8) [0x559b9c139658]
./miniruby(rb_vm_exec+0x110) [0x559b9c150f40]
./miniruby(ruby_opt_init+0x8a) [0x559b9c0bc67a]
./miniruby(load_file_internal+0x4b2) [0x559b9c0be792]
./miniruby(rb_ensure+0x106) [0x559b9bf945c6]
./miniruby(process_options+0x19e5) [0x559b9c0c0b15]
./miniruby(ruby_process_options+0x151) [0x559b9c0c1601]
./miniruby(ruby_options+0x119) [0x559b9bf99e09]
./miniruby(main+0x57) [0x559b9bf111e7]

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

* Loaded script: ./miniruby

* Loaded features:

    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 ruby2_keywords.rb

* Process memory map:

559b9bee4000-559b9bf0c000 r--p 00000000 00:21 26171793                   /builddir/build/BUILD/ruby-3.0.2/miniruby
559b9bf0c000-559b9c179000 r-xp 00028000 00:21 26171793                   /builddir/build/BUILD/ruby-3.0.2/miniruby
559b9c179000-559b9c27d000 r--p 00295000 00:21 26171793                   /builddir/build/BUILD/ruby-3.0.2/miniruby
559b9c27d000-559b9c284000 r--p 00398000 00:21 26171793                   /builddir/build/BUILD/ruby-3.0.2/miniruby
559b9c284000-559b9c285000 rw-p 0039f000 00:21 26171793                   /builddir/build/BUILD/ruby-3.0.2/miniruby
559b9c285000-559b9c295000 rw-p 00000000 00:00 0 
559b9cdc6000-559b9cf0c000 rw-p 00000000 00:00 0                          [heap]
7fa0d5b1a000-7fa0d7307000 r--s 00000000 00:21 26171793                   /builddir/build/BUILD/ruby-3.0.2/miniruby
7fa0d7307000-7fa0d730a000 r--p 00000000 00:21 26128883                   /usr/lib64/libgcc_s-11-20210728.so.1
7fa0d730a000-7fa0d731c000 r-xp 00003000 00:21 26128883                   /usr/lib64/libgcc_s-11-20210728.so.1
7fa0d731c000-7fa0d731f000 r--p 00015000 00:21 26128883                   /usr/lib64/libgcc_s-11-20210728.so.1
7fa0d731f000-7fa0d7320000 r--p 00017000 00:21 26128883                   /usr/lib64/libgcc_s-11-20210728.so.1
7fa0d7320000-7fa0d7321000 rw-p 00018000 00:21 26128883                   /usr/lib64/libgcc_s-11-20210728.so.1
7fa0d7321000-7fa0d7322000 ---p 00000000 00:00 0 
7fa0d7322000-7fa0d73c3000 rw-p 00000000 00:00 0 
7fa0d73c3000-7fa0d73c4000 ---p 00000000 00:00 0 
7fa0d73c4000-7fa0d7465000 rw-p 00000000 00:00 0 
7fa0d7465000-7fa0d7466000 ---p 00000000 00:00 0 
7fa0d7466000-7fa0d7507000 rw-p 00000000 00:00 0 
7fa0d7507000-7fa0d7508000 ---p 00000000 00:00 0 
7fa0d7508000-7fa0d75a9000 rw-p 00000000 00:00 0 
7fa0d75a9000-7fa0d75aa000 ---p 00000000 00:00 0 
7fa0d75aa000-7fa0d764b000 rw-p 00000000 00:00 0 
7fa0d764b000-7fa0d764c000 ---p 00000000 00:00 0 
7fa0d764c000-7fa0d76ed000 rw-p 00000000 00:00 0 
7fa0d76ed000-7fa0d76ee000 ---p 00000000 00:00 0 
7fa0d76ee000-7fa0d778f000 rw-p 00000000 00:00 0 
7fa0d778f000-7fa0d7790000 ---p 00000000 00:00 0 
7fa0d7790000-7fa0d7831000 rw-p 00000000 00:00 0 
7fa0d7831000-7fa0d7832000 ---p 00000000 00:00 0 
7fa0d7832000-7fa0d78d3000 rw-p 00000000 00:00 0 
7fa0d78d3000-7fa0d78d4000 ---p 00000000 00:00 0 
7fa0d78d4000-7fa0d7975000 rw-p 00000000 00:00 0 
7fa0d7975000-7fa0d7976000 ---p 00000000 00:00 0 
7fa0d7976000-7fa0d7a17000 rw-p 00000000 00:00 0 
7fa0d7a17000-7fa0d7a18000 ---p 00000000 00:00 0 
7fa0d7a18000-7fa0d7ab9000 rw-p 00000000 00:00 0 
7fa0d7ab9000-7fa0d7aba000 ---p 00000000 00:00 0 
7fa0d7aba000-7fa0d7b5b000 rw-p 00000000 00:00 0 
7fa0d7b5b000-7fa0d7b5c000 ---p 00000000 00:00 0 
7fa0d7b5c000-7fa0d7bfd000 rw-p 00000000 00:00 0 
7fa0d7bfd000-7fa0d7bfe000 ---p 00000000 00:00 0 
7fa0d7bfe000-7fa0d7c9f000 rw-p 00000000 00:00 0 
7fa0d7c9f000-7fa0d7ca0000 ---p 00000000 00:00 0 
7fa0d7ca0000-7fa0d7d41000 rw-p 00000000 00:00 0 
7fa0d7d41000-7fa0d7d42000 ---p 00000000 00:00 0 
7fa0d7d42000-7fa0d7de3000 rw-p 00000000 00:00 0 
7fa0d7de3000-7fa0d7de4000 ---p 00000000 00:00 0 
7fa0d7de4000-7fa0d7e85000 rw-p 00000000 00:00 0 
7fa0d7e85000-7fa0d7e86000 ---p 00000000 00:00 0 
7fa0d7e86000-7fa0d7f27000 rw-p 00000000 00:00 0 
7fa0d7f27000-7fa0d7f28000 ---p 00000000 00:00 0 
7fa0d7f28000-7fa0d7fc9000 rw-p 00000000 00:00 0 
7fa0d7fc9000-7fa0d7fca000 ---p 00000000 00:00 0 
7fa0d7fca000-7fa0d806b000 rw-p 00000000 00:00 0 
7fa0d806b000-7fa0d806c000 ---p 00000000 00:00 0 
7fa0d806c000-7fa0d810d000 rw-p 00000000 00:00 0 
7fa0d810d000-7fa0d810e000 ---p 00000000 00:00 0 
7fa0d810e000-7fa0d81af000 rw-p 00000000 00:00 0 
7fa0d81af000-7fa0d81b0000 ---p 00000000 00:00 0 
7fa0d81b0000-7fa0d8251000 rw-p 00000000 00:00 0 
7fa0d8251000-7fa0d8252000 ---p 00000000 00:00 0 
7fa0d8252000-7fa0d82f3000 rw-p 00000000 00:00 0 
7fa0d82f3000-7fa0d82f4000 ---p 00000000 00:00 0 
7fa0d82f4000-7fa0d8395000 rw-p 00000000 00:00 0 
7fa0d8395000-7fa0d8396000 ---p 00000000 00:00 0 
7fa0d8396000-7fa0d8437000 rw-p 00000000 00:00 0 
7fa0d8437000-7fa0d8438000 ---p 00000000 00:00 0 
7fa0d8438000-7fa0d84d9000 rw-p 00000000 00:00 0 
7fa0d84d9000-7fa0d84da000 ---p 00000000 00:00 0 
7fa0d84da000-7fa0d857b000 rw-p 00000000 00:00 0 
7fa0d857b000-7fa0d857c000 ---p 00000000 00:00 0 
7fa0d857c000-7fa0d861d000 rw-p 00000000 00:00 0 
7fa0d861d000-7fa0d861e000 ---p 00000000 00:00 0 
7fa0d861e000-7fa0d86bf000 rw-p 00000000 00:00 0 
7fa0d86bf000-7fa0d86c0000 ---p 00000000 00:00 0 
7fa0d86c0000-7fa0da8ce000 rw-p 00000000 00:00 0 
7fa0da8ce000-7fa0da8fa000 r--p 00000000 00:21 26129154                   /usr/lib64/libc.so.6
7fa0da8fa000-7fa0daa6f000 r-xp 0002c000 00:21 26129154                   /usr/lib64/libc.so.6
7fa0daa6f000-7fa0daac3000 r--p 001a1000 00:21 26129154                   /usr/lib64/libc.so.6
7fa0daac3000-7fa0daac4000 ---p 001f5000 00:21 26129154                   /usr/lib64/libc.so.6
7fa0daac4000-7fa0daac7000 r--p 001f5000 00:21 26129154                   /usr/lib64/libc.so.6
7fa0daac7000-7fa0daaca000 rw-p 001f8000 00:21 26129154                   /usr/lib64/libc.so.6
7fa0daaca000-7fa0daad7000 rw-p 00000000 00:00 0 
7fa0daad7000-7fa0daae6000 r--p 00000000 00:21 26129157                   /usr/lib64/libm.so.6
7fa0daae6000-7fa0dab57000 r-xp 0000f000 00:21 26129157                   /usr/lib64/libm.so.6
7fa0dab57000-7fa0dabb1000 r--p 00080000 00:21 26129157                   /usr/lib64/libm.so.6
7fa0dabb1000-7fa0dabb2000 r--p 000d9000 00:21 26129157                   /usr/lib64/libm.so.6
7fa0dabb2000-7fa0dabb3000 rw-p 000da000 00:21 26129157                   /usr/lib64/libm.so.6
7fa0dabb3000-7fa0dabb5000 r--p 00000000 00:21 26129209                   /usr/lib64/libcrypt.so.2.0.0
7fa0dabb5000-7fa0dabc9000 r-xp 00002000 00:21 26129209                   /usr/lib64/libcrypt.so.2.0.0
7fa0dabc9000-7fa0dabe2000 r--p 00016000 00:21 26129209                   /usr/lib64/libcrypt.so.2.0.0
7fa0dabe2000-7fa0dabe3000 ---p 0002f000 00:21 26129209                   /usr/lib64/libcrypt.so.2.0.0
7fa0dabe3000-7fa0dabe4000 r--p 0002f000 00:21 26129209                   /usr/lib64/libcrypt.so.2.0.0
7fa0dabe4000-7fa0dabed000 rw-p 00000000 00:00 0 
7fa0dabed000-7fa0dabfe000 r--p 00000000 00:21 26129286                   /usr/lib64/libgmp.so.10.4.0
7fa0dabfe000-7fa0dac76000 r-xp 00011000 00:21 26129286                   /usr/lib64/libgmp.so.10.4.0
7fa0dac76000-7fa0dac8d000 r--p 00089000 00:21 26129286                   /usr/lib64/libgmp.so.10.4.0
7fa0dac8d000-7fa0dac8f000 r--p 0009f000 00:21 26129286                   /usr/lib64/libgmp.so.10.4.0
7fa0dac8f000-7fa0dac90000 rw-p 000a1000 00:21 26129286                   /usr/lib64/libgmp.so.10.4.0
7fa0dac90000-7fa0dac93000 r--p 00000000 00:21 26129192                   /usr/lib64/libz.so.1.2.11
7fa0dac93000-7fa0daca1000 r-xp 00003000 00:21 26129192                   /usr/lib64/libz.so.1.2.11
7fa0daca1000-7fa0daca7000 r--p 00011000 00:21 26129192                   /usr/lib64/libz.so.1.2.11
7fa0daca7000-7fa0daca8000 ---p 00017000 00:21 26129192                   /usr/lib64/libz.so.1.2.11
7fa0daca8000-7fa0daca9000 r--p 00017000 00:21 26129192                   /usr/lib64/libz.so.1.2.11
7fa0daca9000-7fa0dacac000 rw-p 00000000 00:00 0 
7fa0dacaf000-7fa0dacb0000 r--p 00000000 00:21 26129150                   /usr/lib64/ld-linux-x86-64.so.2
7fa0dacb0000-7fa0dacd5000 r-xp 00001000 00:21 26129150                   /usr/lib64/ld-linux-x86-64.so.2
7fa0dacd5000-7fa0dacdf000 r--p 00026000 00:21 26129150                   /usr/lib64/ld-linux-x86-64.so.2
7fa0dacdf000-7fa0dace1000 r--p 0002f000 00:21 26129150                   /usr/lib64/ld-linux-x86-64.so.2
7fa0dace1000-7fa0dace3000 rw-p 00031000 00:21 26129150                   /usr/lib64/ld-linux-x86-64.so.2
7ffd3a364000-7ffd3ab63000 rw-p 00000000 00:00 0                          [stack]
7ffd3abf2000-7ffd3abf6000 r--p 00000000 00:00 0                          [vvar]
7ffd3abf6000-7ffd3abf8000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

and GDB:

(gdb) where 
#0  vm_search_cc (klass=klass@entry=93824996595160, ci=0x9f00100007) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1642
#1  0x000055555579edd0 in rb_vm_search_method_slowpath (klass=93824996595160, ci=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1738
#2  vm_search_method_slowpath0 (cd_owner=93824996395200, cd=cd@entry=0x555555a3cb10, klass=93824996595160) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1760
#3  0x00005555557a6094 in vm_search_method_fastpath (klass=<optimized out>, cd=0x555555a3cb10, cd_owner=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:1826
#4  vm_sendish (ec=0x555555909c80, reg_cfp=0x7ffff7b84f68, cd=0x555555a3cb10, block_handler=<optimized out>, method_explorer=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:4528
#5  0x00005555557a9658 in vm_exec_core (ec=0x555555909c80, initial=159) at /builddir/build/BUILD/ruby-3.0.2/insns.def:789
#6  0x00005555557c0f40 in rb_vm_exec (ec=0x555555909c80, mjit_enable_p=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm.c:2172
#7  0x000055555572c67a in rb_load_with_builtin_functions (table=0x5555558f0400 <ractor_table>, feature_name=0x55555581e2fd "ractor") at /builddir/build/BUILD/ruby-3.0.2/mini_builtin.c:48
#8  Init_builtin_ractor () at /builddir/build/BUILD/ruby-3.0.2/ractor.rbinc:710
#9  rb_call_builtin_inits () at /builddir/build/BUILD/ruby-3.0.2/inits.c:89
#10 ruby_opt_init (opt=0x7fffffffdfd0) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:1520
#11 ruby_opt_init (opt=opt@entry=0x7fffffffdfd0) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:1506
#12 0x000055555572e792 in load_file_internal (argp_v=140737488309968) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:2181
#13 0x00005555556045c6 in rb_ensure (b_proc=0x55555572e2e0 <load_file_internal>, data1=140737488309968, e_proc=<optimized out>, data2=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/eval.c:1162
#14 0x0000555555730b15 in load_file (opt=0x7fffffffdfd0, script=1, f=<optimized out>, fname=<optimized out>, parser=93824996498920) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:2323
#15 process_options (argc=6, argv=0x7fffffffe370, opt=0x7fffffffdfd0) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:1960
#16 0x0000555555731601 in ruby_process_options (argc=11, argv=0x7fffffffe348) at /builddir/build/BUILD/ruby-3.0.2/ruby.c:230
#17 0x0000555555609e09 in ruby_options (argc=11, argv=0x7fffffffe348) at /builddir/build/BUILD/ruby-3.0.2/eval.c:138
#18 0x00005555555811e7 in main (argc=<optimized out>, argv=<optimized out>) at ./main.c:50
(gdb) list 
1637	    struct rb_id_table *cc_tbl = RCLASS_CC_TBL(klass);
1638	    struct rb_class_cc_entries *ccs = NULL;
1639	
1640	    if (cc_tbl) {
1641	        if (rb_id_table_lookup(cc_tbl, mid, (VALUE *)&ccs)) {
1642	            const int ccs_len = ccs->len;
1643	            VM_ASSERT(vm_ccs_verify(ccs, mid, klass));
1644	
1645	            if (UNLIKELY(METHOD_ENTRY_INVALIDATED(ccs->cme))) {
1646	                rb_vm_ccs_free(ccs);

Updated by vo.x (Vit Ondruch) over 3 years ago

I should probably include a few more lines from the log which include the build options:

gcc -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -m64 -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard -DRUBY_EXPORT -I. -I.ext/include/x86_64-linux -I./include -I. -I./enc/unicode/12.1.0    -o vm.o -c vm.c
gcc -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -m64 -L. -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fstack-protector-strong -rdynamic -Wl,-export-dynamic -fstack-protector-strong  main.o dmydln.o miniinit.o dmyext.o abrt.o array.o ast.o bignum.o class.o compar.o compile.o complex.o cont.o debug.o debug_counter.o dir.o dln_find.o encoding.o enum.o enumerator.o error.o eval.o file.o gc.o hash.o inits.o io.o iseq.o load.o marshal.o math.o memory_view.o mjit.o mjit_compile.o node.o numeric.o object.o pack.o parse.o proc.o process.o ractor.o random.o range.o rational.o re.o regcomp.o regenc.o regerror.o regexec.o regparse.o regsyntax.o ruby.o scheduler.o signal.o sprintf.o st.o strftime.o string.o struct.o symbol.o thread.o time.o transcode.o transient_heap.o util.o variable.o version.o vm.o vm_backtrace.o vm_dump.o vm_sync.o vm_trace.o coroutine/amd64/Context.o probes.o enc/ascii.o enc/us_ascii.o enc/unicode.o enc/utf_8.o enc/trans/newline.o setproctitle.o strlcat.o strlcpy.o addr2line.o  -lz -lpthread -lrt -lrt -lgmp -ldl -lcrypt -lm  -lm   -o miniruby
Actions #7

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • File deleted (0001-Get-rid-of-type-punning-pointer-cast.patch)
Actions #8

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

vo.x (Vit Ondruch) wrote in #note-5:

1641	        if (rb_id_table_lookup(cc_tbl, mid, (VALUE *)&ccs)) {
1642	            const int ccs_len = ccs->len;

I've missed here.

Updated by vo.x (Vit Ondruch) over 3 years ago

nobu (Nobuyoshi Nakada) wrote in #note-8:
Thx, this helps. Howeverer, there is more:

(gdb) r -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems "./libexec/rdoc" --root "." --encoding=UTF-8 --all --ri --op ".ext/rdoc" --page-dir "./doc" --no-force-update  "."
Starting program: /builddir/build/BUILD/ruby-3.0.2/miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems "./libexec/rdoc" --root "." --encoding=UTF-8 --all --ri --op ".ext/rdoc" --page-dir "./doc" --no-force-update  "."
Download failed: No route to host.  Continuing without debug info for /builddir/build/BUILD/ruby-3.0.2/system-supplied DSO at 0x7ffff7fc9000.
Download failed: No route to host.  Continuing without debug info for /lib64/libz.so.1.
Download failed: No route to host.  Continuing without debug info for /lib64/libgmp.so.10.
Download failed: No route to host.  Continuing without debug info for /lib64/libcrypt.so.2.
Download failed: No route to host.  Continuing without debug info for /lib64/libm.so.6.
Download failed: No route to host.  Continuing without debug info for /lib64/libc.so.6.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
process 105 is executing new program: /builddir/build/BUILD/ruby-3.0.2/ruby
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.34-1.fc35.x86_64 gmp-6.2.0-7.fc35.x86_64 libxcrypt-4.4.24-1.fc35.x86_64 zlib-1.2.11-30.fc35.x86_64
Download failed: No route to host.  Continuing without debug info for /lib64/libc.so.6.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Download failed: No route to host.  Continuing without debug info for /lib64/libz.so.1.
Download failed: No route to host.  Continuing without debug info for /lib64/libgmp.so.10.
Download failed: No route to host.  Continuing without debug info for /lib64/libcrypt.so.2.
Download failed: No route to host.  Continuing without debug info for /lib64/libm.so.6.

Program received signal SIGSEGV, Segmentation fault.
clear_method_cache_by_id_in_class.part.0.lto_priv.0 (klass=<optimized out>, mid=33041) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:210
210	                vm_me_invalidate_cache((rb_callable_method_entry_t *)cme);
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.34-1.fc35.x86_64 gmp-6.2.0-7.fc35.x86_64 libxcrypt-4.4.24-1.fc35.x86_64 zlib-1.2.11-30.fc35.x86_64
(gdb) where 
#0  clear_method_cache_by_id_in_class.part.0.lto_priv.0 (klass=<optimized out>, mid=33041) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:210
#1  0x00007ffff7e6befb in clear_method_cache_by_id_in_class (mid=33041, klass=93824993043920) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:140
#2  clear_iclass_method_cache_by_id (d=33041, iclass=93824993043920) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:223
#3  rb_class_foreach_subclass (arg=33041, f=<optimized out>, klass=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/class.c:133
#4  rb_clear_method_cache (mid=33041, klass_or_module=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:246
#5  rb_clear_method_cache (klass_or_module=<optimized out>, mid=33041) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:236
#6  0x00007ffff7e6cbfa in rb_method_entry_make (klass=klass@entry=93824993044000, mid=mid@entry=33041, defined_class=defined_class@entry=93824993044000, visi=METHOD_VISI_PUBLIC, 
    type=type@entry=VM_METHOD_TYPE_ISEQ, def=0x555555895650, def@entry=0x0, original_id=33041, opts=0x7fffffffc840) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:844
#7  0x00007ffff7e6cf83 in rb_add_method (visi=<optimized out>, opts=0x7fffffffc840, type=VM_METHOD_TYPE_ISEQ, mid=33041, klass=93824993044000) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:901
#8  rb_add_method_iseq (klass=93824993044000, mid=33041, iseq=<optimized out>, cref=<optimized out>, visi=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_method.c:918
#9  0x00007ffff7e6f6bf in vm_define_method (is_singleton=<optimized out>, iseqval=<optimized out>, id=<optimized out>, obj=<optimized out>, ec=<optimized out>)
    at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:4438
#10 vm_exec_core (ec=0x55555555de90, initial=2065) at /builddir/build/BUILD/ruby-3.0.2/insns.def:744
#11 0x00007ffff7e874c0 in rb_vm_exec (ec=0x55555555de90, mjit_enable_p=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm.c:2172
#12 0x00007ffff7d39986 in require_internal (ec=0x55555555de90, fname=<optimized out>, exception=1) at /builddir/build/BUILD/ruby-3.0.2/load.c:1065
#13 0x00007ffff7d39b21 in rb_require_string (fname=93824992360440) at /builddir/build/BUILD/ruby-3.0.2/load.c:1142
#14 0x00007ffff7e66732 in vm_call_cfunc_with_frame (ec=0x55555555de90, reg_cfp=0x7ffff77feec0, calling=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:2929
#15 0x00007ffff7e6a356 in vm_sendish (ec=0x55555555de90, reg_cfp=0x7ffff77feec0, cd=0x55555576bd00, block_handler=<optimized out>, method_explorer=<optimized out>)
    at /builddir/build/BUILD/ruby-3.0.2/vm_callinfo.h:336
#16 0x00007ffff7e6eb48 in vm_exec_core (ec=0x55555555de90, initial=2065) at /builddir/build/BUILD/ruby-3.0.2/insns.def:789
#17 0x00007ffff7e874c0 in rb_vm_exec (ec=0x55555555de90, mjit_enable_p=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm.c:2172
#18 0x00007ffff7d39986 in require_internal (ec=0x55555555de90, fname=<optimized out>, exception=1) at /builddir/build/BUILD/ruby-3.0.2/load.c:1065
#19 0x00007ffff7d39b21 in rb_require_string (fname=93824992525560) at /builddir/build/BUILD/ruby-3.0.2/load.c:1142
#20 0x00007ffff7e66732 in vm_call_cfunc_with_frame (ec=0x55555555de90, reg_cfp=0x7ffff77fef30, calling=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:2929
#21 0x00007ffff7e6a356 in vm_sendish (ec=0x55555555de90, reg_cfp=0x7ffff77fef30, cd=0x5555556b6df0, block_handler=<optimized out>, method_explorer=<optimized out>)
    at /builddir/build/BUILD/ruby-3.0.2/vm_callinfo.h:336
#22 0x00007ffff7e6eb48 in vm_exec_core (ec=0x55555555de90, initial=2065) at /builddir/build/BUILD/ruby-3.0.2/insns.def:789
#23 0x00007ffff7e874c0 in rb_vm_exec (ec=0x55555555de90, mjit_enable_p=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm.c:2172
#24 0x00007ffff7d39986 in require_internal (ec=0x55555555de90, fname=<optimized out>, exception=1) at /builddir/build/BUILD/ruby-3.0.2/load.c:1065
#25 0x00007ffff7d39b21 in rb_require_string (fname=93824992518640) at /builddir/build/BUILD/ruby-3.0.2/load.c:1142
#26 0x00007ffff7e66732 in vm_call_cfunc_with_frame (ec=0x55555555de90, reg_cfp=0x7ffff77fefa0, calling=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm_insnhelper.c:2929
#27 0x00007ffff7e6a356 in vm_sendish (ec=0x55555555de90, reg_cfp=0x7ffff77fefa0, cd=0x5555556b4f60, block_handler=<optimized out>, method_explorer=<optimized out>)
    at /builddir/build/BUILD/ruby-3.0.2/vm_callinfo.h:336
#28 0x00007ffff7e6eb48 in vm_exec_core (ec=0x55555555de90, initial=2065) at /builddir/build/BUILD/ruby-3.0.2/insns.def:789
#29 0x00007ffff7e874c0 in rb_vm_exec (ec=0x55555555de90, mjit_enable_p=<optimized out>) at /builddir/build/BUILD/ruby-3.0.2/vm.c:2172
#30 0x00007ffff7ceb06f in rb_ec_exec_node (ec=ec@entry=0x55555555de90, n=n@entry=0x55555559a790) at /builddir/build/BUILD/ruby-3.0.2/eval.c:317
#31 0x00007ffff7ceb18a in ruby_run_node (n=0x55555559a790) at /builddir/build/BUILD/ruby-3.0.2/eval.c:375
#32 0x000055555555518f in main (argc=<optimized out>, argv=<optimized out>) at ./main.c:50
(gdb) list
205	        }
206	        else {
207	            rb_vm_t *vm = GET_VM();
208	            if (rb_id_table_lookup(vm->negative_cme_table, mid, (VALUE *)&cme)) {
209	                rb_id_table_delete(vm->negative_cme_table, mid);
210	                vm_me_invalidate_cache((rb_callable_method_entry_t *)cme);
211	
212	                RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
213	            }
214	        }

Updated by vo.x (Vit Ondruch) over 3 years ago

Testing with Ruby 3.0.2, I had to modify the patch slightly and I was able to build the Ruby as well as pass test suite. However, I'd like if you can review the modifications I did for Ruby 3.0.2 in the vm_method.c hunks (I have replaced the hunk #4 with hunk #5).

Updated by vo.x (Vit Ondruch) over 3 years ago

Unfortunately, testing on other arches, the #17052 is still an issue :(

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

That patch seems fine, but maybe f4ce78d5c139 and 9c769575bfa2 also need to be backported.

Updated by vo.x (Vit Ondruch) over 3 years ago

  • Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: REQUIRED

nobu (Nobuyoshi Nakada) wrote in #note-13:

That patch seems fine

Thx for confirmation

but maybe f4ce78d5c139 and 9c769575bfa2 also need to be backported.

If would definitely make my life easier, but nobody have requested the backport of #17553 yet and I have not met the issue myself. For the moment, I'm going to set the backport flag for this ticket and let @nagachika (Tomoyuki Chikanaga) to decide.

I still have to figure out if I am going to use this downstream or not.

Updated by jaruga (Jun Aruga) over 3 years ago

I identified which compiler flags make this error, segmentation fault. I tested it on the latest master 28d03ee776af4d630556fcaad7305340cbcf9cde . I think this info helps for developers to reproduce this error on their machine.

My testing environment is Fedora 34 x86_64 and the used gcc version is as follows.

$ gcc --version
gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)
Copyright (C) 2021 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.

As a note, on Fedora, the following cflags is set as a default for both gcc and clang.
https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/rawhide/f/macros#_341

%_gcc_lto_cflags -flto=auto -ffat-lto-objects
%_clang_lto_cflags -flto
...
%_general_options -O2 %{?_lto_cflags} -fexceptions -g -grecord-gcc-switches -pipe

CFLAGS='-flto=auto -ffat-lto-objects' => make: ok

First, I confirmed that with CFLAGS='-flto=auto -ffat-lto-objects', the make command works and finishes without error against my expectation.

$ git clean -fdx
$ autoconf
$ CFLAGS='-flto=auto -ffat-lto-objects' ./configure --enable-shared --prefix $(pwd)/dest
$ make 2>&1 | tee make.log

CFLAGS='-O2 -flto=auto -ffat-lto-objects' => make: error

After spending some time, I found the CFLAGS='-O2 -flto=auto -ffat-lto-objects' (-O2 + lto flags) causes the make error. I would attach the log as jaruga_make_cflags_with_O2_lto_flags.log.

$ git clean -fdx
$ autoconf
$ CFLAGS='-O2 -flto=auto -ffat-lto-objects' \
  ./configure --enable-shared --prefix $(pwd)/dest
$ make 2>&1 | tee make.log
...
+ cp enc/jis/props.h.blt enc/jis/props.h
generating encdb.h
<internal:gc>:240: [BUG] Segmentation fault at 0x0000000000000004
ruby 3.1.0dev (2021-08-10T10:08:38Z master 28d03ee776) [x86_64-linux]
...
  => error

CFLAGS='-O2 -flto=auto -ffat-lto-objects' + a commit on the PR https://github.com/ruby/ruby/pull/4716 => make: ok, make check: error

On the latest master 28d03ee776af4d630556fcaad7305340cbcf9cde + applying a commit on the PR https://github.com/ruby/ruby/pull/4716 , the make is ok, but make check still has error. I would attach the log as jaruga_make_check.log.

$ git clean -fdx
$ autoconf
$ CFLAGS='-O2 -flto=auto -ffat-lto-objects' \
  ./configure --enable-shared --prefix $(pwd)/dest
$ make 2>&1 | tee make.log
$ make check 2>&1 | tee make_check.log
...
Run options:-
  --seed=91697
  "--ruby=./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems"
  --excludes-dir=./test/excludes
  --name=!/memory_leak/

# Running tests:

Leaked file descriptor: DRbTests::TestDRbTCP#test_immediate_close: 12 : #<TCPSocket:fd 12, AF_INET6, ::1, 38855>
Leaked file descriptor: DRbTests::TestDRbTCP#test_immediate_close: 13 : #<IO:fd 13>
Leaked file descriptor: PPTestModule::PPFileStatTest#test_nothing_raised: 7 #<File::Stat dev=0xfd02, ino=13370094, mode=0100664, nlink=1, uid=0, gid=0, rdev=0x0, size=9253600, blksize=4096, blocks=18080, atime=2021-08-10 19:54:31.33281203 +0200, mtime=2021-08-10 19:54:31.331812023 +0200, ctime=2021-08-10 19:54:31.331812023 +0200>
COMMAND     PID   USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME 
ruby    1158696 jaruga    7r   REG  253,2  9253600 13370094 /var/lib/sss/mc/passwd
/home/jaruga/var/git/ruby/ruby/test/ruby/test_hash.rb:2080: [BUG] Segmentation fault at 0x0000000000000003
ruby 3.1.0dev (2021-08-10T17:41:00Z master 5340724165) [x86_64-linux]
...
  => error
Actions #16

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset git|a0a8f2abf533702b2cd96e79f700ce5b9cd94f50.


Get rid of type-punning pointer casts [Bug #18062]

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Status changed from Closed to Open

As https://github.com/ruby/ruby/pull/4716 itself seems to make things better at least, I merged it for now.

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

I could reproduce the segfault with the master c59da370a5d, just by Hash.ruby2_keywords_hash?(1).

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x3)
    frame #0: 0x00000001000c82f0 miniruby`rb_hash_s_ruby2_keywords_hash_p.lto_priv.0
miniruby`rb_hash_s_ruby2_keywords_hash_p.lto_priv.0:
->  0x1000c82f0 <+0>: movq   (%rsi), %rax
    0x1000c82f3 <+3>: movq   %rsi, %rdi
    0x1000c82f6 <+6>: andl   $0x7, %esi
    0x1000c82f9 <+9>: jne    0x1002b6683               ; rb_hash_s_ruby2_keywords_hash_p.lto_priv.0.cold
Target 0: (miniruby) stopped.
(lldb) disassemble 
miniruby`rb_hash_s_ruby2_keywords_hash_p.lto_priv.0:
->  0x1000c82f0 <+0>:  movq   (%rsi), %rax
    0x1000c82f3 <+3>:  movq   %rsi, %rdi
    0x1000c82f6 <+6>:  andl   $0x7, %esi
    0x1000c82f9 <+9>:  jne    0x1002b6683               ; rb_hash_s_ruby2_keywords_hash_p.lto_priv.0.cold
    0x1000c82ff <+15>: testq  $-0x9, %rdi
    0x1000c8306 <+22>: je     0x1002b6683               ; rb_hash_s_ruby2_keywords_hash_p.lto_priv.0.cold
    0x1000c830c <+28>: movq   %rax, %rdx
    0x1000c830f <+31>: andl   $0x1f, %edx
    0x1000c8312 <+34>: cmpq   $0x8, %rdx
    0x1000c8316 <+38>: jne    0x1002b6683               ; rb_hash_s_ruby2_keywords_hash_p.lto_priv.0.cold
    0x1000c831c <+44>: andl   $0x2000, %eax             ; imm = 0x2000 
    0x1000c8321 <+49>: movl   $0x14, %edx
    0x1000c8326 <+54>: cmovneq %rdx, %rax
    0x1000c832a <+58>: retq   
    0x1000c832b <+59>: nopl   (%rax,%rax)
(lldb) p $rsi
(unsigned long) $0 = 3

Seems rbimpl_RB_TYPE_P_fastpath is re-ordered, and RB_BUILTIN_TYPE(obj) is fetched before RB_SPECIAL_CONST_P(obj).

    else if (RB_SPECIAL_CONST_P(obj)) {
        return false;
    }
    else if (t == RB_BUILTIN_TYPE(obj)) {
        return true;
    }

Updated by vo.x (Vit Ondruch) over 3 years ago

Just curious, would it make sense to update the Ruby CI to test LTO? Maybe even by default? Would there be any downside?

Updated by jaruga (Jun Aruga) over 3 years ago

Just curious, would it make sense to update the Ruby CI to test LTO? Maybe even by default? Would there be any downside?

Yes, I think it makes sense to me, and the .github/workflows/compilers.yml is a right place to add. Actually I have been trying to add the cases like this on a branch on forked repo on the yesterday's latest master 28d03ee776af4d630556fcaad7305340cbcf9cde . You can see the cI result. The behavior is a little different. The make is ok against my expectation. But it's dead in the process of make test with wrong result "green". Now I am trying to reproduce it on Ruby CI's Fedora 32 server (it's the latest version Fedora server on Ruby CI servers) for developer's convenience.

Fiber count: 10000 (skipping)
PASS all 1417 tests

For detail of the current compilers.yml matrix syntax's limitation, we can only set a kind of environment variable. E.g. we can not set both default_cc and optflags variables for a case of the matrix. I am trying to change the limitaion too for a better implementation.

diff --git a/.github/workflows/compilers.yml b/.github/workflows/compilers.yml
index af0be21272..31112c79bf 100644
--- a/.github/workflows/compilers.yml
+++ b/.github/workflows/compilers.yml
@@ -55,6 +55,7 @@ jobs:
           - { key: default_cc, name: gcc-6,     value: gcc-6,     container: gcc-6 }
           - { key: default_cc, name: gcc-5,     value: gcc-5,     container: gcc-5 }
           - { key: default_cc, name: gcc-4.8,   value: gcc-4.8,   container: gcc-4.8 }
+          - { key: default_cc, name: 'gcc-11 -O2 -flto=auto -ffat-lto-objects', value: 'gcc-11 -O2 -flto=auto -ffat-lto-objects' ,container: gcc-11 }
           - { key: default_cc, name: clang-14,  value: clang-14,  container: clang-14 }
           - { key: default_cc, name: clang-13,  value: clang-13,  container: clang-13 }
           - { key: default_cc, name: clang-12,  value: clang-12,  container: clang-12 }
@@ -67,6 +68,7 @@ jobs:
           - { key: default_cc, name: clang-5.0, value: clang-5.0, container: clang-5.0 }
           - { key: default_cc, name: clang-4.0, value: clang-4.0, container: clang-4.0 }
           - { key: default_cc, name: clang-3.9, value: clang-3.9, container: clang-3.9 }
+          - { key: default_cc, name: 'clang-14 -O2 -flto=auto', value: 'clang-14 -O2 -flto=auto', container: clang-14 }
 
           - { key: crosshost, name: aarch64-linux-gnu,     value: aarch64-linux-gnu, container: crossbuild-essential-arm64 }
 #         - { key: crosshost, name: arm-linux-gnueabi,     value: arm-linux-gnueabi }

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

Probably a memory barrier would work.

diff --git a/include/ruby/internal/value_type.h b/include/ruby/internal/value_type.h
index 52b284cb4a2..f6231d2dcac 100644
--- a/include/ruby/internal/value_type.h
+++ b/include/ruby/internal/value_type.h
@@ -156,6 +156,11 @@ RB_BUILTIN_TYPE(VALUE obj)
 {
     RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
 
+#if defined __GNUC__ && !defined __clang__
+    /* Don't move the access to `flags` before the preceding
+     * RB_SPECIAL_CONST_P check. */
+    __asm volatile("": : :"memory");
+#endif
     VALUE ret = RBASIC(obj)->flags & RUBY_T_MASK;
     return RBIMPL_CAST((enum ruby_value_type)ret);
 }
@@ -351,6 +356,7 @@ Check_Type(VALUE v, enum ruby_value_type t)
 
   slowpath: /* <- :TODO: mark this label as cold. */
     rb_check_type(v, t);
+    RBIMPL_UNREACHABLE();
 }
 
 #endif /* RBIMPL_VALUE_TYPE_H */
Actions #22

Updated by jaruga (Jun Aruga) over 3 years ago

But it's dead in the process of make test with wrong result "green".

Sorry, my mistake. The make test just finished without error on the Ubuntu container. So, the "green" is correct. The steps after make install were skipped due to the conditional execution for the CI result.

Updated by jaruga (Jun Aruga) over 3 years ago

nobu (Nobuyoshi Nakada) wrote in #note-21:

Probably a memory barrier would work.

I confirmed that the make and make check work with the patch applied on the latest master 79cc566ab4cdf75f125ecf413a27d353a9756c08 on my local Fedora 34 (gcc 11.2.1-1) with CFLAGS='-O2 -flto=auto -ffat-lto-objects' by following commands.

git clean -fdx
autoconf
CFLAGS='-O2 -flto=auto -ffat-lto-objects' \
  ./configure --enable-shared --prefix $(pwd)/dest
make 2>&1 | tee make.log
make check 2>&1 | tee make_check.log

However with the GitHub Actions CI where I added the new cases as I wrote above. Both the gcc/clang cases still fail after applying the patch.

Before applying the patch.
https://github.com/junaruga/ruby/runs/3302937317?check_suite_focus=true#step:16:126

After applying the patch.
https://github.com/junaruga/ruby/runs/3303099400?check_suite_focus=true#step:16:226

Updated by vo.x (Vit Ondruch) over 3 years ago

So I have tried to get more details about the #17052:

$ gdb --args ./miniruby -e'Process.kill("SIGSEGV",$$)'
GNU gdb (GDB) Fedora 10.2-6.fc35
Copyright (C) 2021 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 "ppc64le-redhat-linux-gnu".
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 ./miniruby...
warning: File "/builddir/build/BUILD/ruby-3.0.2/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
	add-auto-load-safe-path /builddir/build/BUILD/ruby-3.0.2/.gdbinit
line to your configuration file "/builddir/.gdbinit".
To completely disable this security protection add
	set auto-load safe-path /
line to your configuration file "/builddir/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
	info "(gdb)Auto-loading safe path"
(gdb) r
Starting program: /builddir/build/BUILD/ruby-3.0.2/miniruby -eProcess.kill\(\"SIGSEGV\",\$\$\)
Download failed: No route to host.  Continuing without debug info for /lib64/libz.so.1.
Download failed: No route to host.  Continuing without debug info for /lib64/libgmp.so.10.
Download failed: No route to host.  Continuing without debug info for /lib64/libcrypt.so.2.
Download failed: No route to host.  Continuing without debug info for /lib64/libm.so.6.
Download failed: No route to host.  Continuing without debug info for /lib64/libc.so.6.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7aa8810 in kill () from /lib64/libc.so.6
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.34-1.fc35.ppc64le gmp-6.2.0-7.fc35.ppc64le libxcrypt-4.4.24-1.fc35.ppc64le zlib-1.2.11-30.fc35.ppc64le
(gdb) c
Continuing.
-e:1: [BUG] Segmentation fault at 0x590fb15c0000001f
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [powerpc64le-linux]

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0012 e:000011 CFUNC  :kill
c:0002 p:0015 s:0006 e:000005 EVAL   -e:1 [FINISH]
c:0001 p:0000 s:0003 E:0013f0 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
-e:1:in `<main>'
-e:1:in `kill'

-- C level backtrace information -------------------------------------------

Program received signal SIGSEGV, Segmentation fault.
0x000000010031fa44 in uleb128 (p=0x1005986a0) at addr2line.c:200
200		unsigned char b = *(unsigned char *)(*p)++;
(gdb) bt
#0  0x000000010031fa44 in uleb128 (p=0x1005986a0) at addr2line.c:200
#1  di_read_die (reader=0x100598668, die=0x100598588) at addr2line.c:1335
#2  0x0000000100337d4c in read_abstract_origin (line=0x1005985f8, abstract_origin=760312297580551, reader=0x100598668) at addr2line.c:1604
#3  debug_info_read (traces=<optimized out>, offset=<optimized out>, lines=<optimized out>, num_traces=<optimized out>, reader=<optimized out>) at addr2line.c:1668
#4  fill_lines (num_traces=num_traces@entry=19, check_debuglink=check_debuglink@entry=1, objp=0x100599010, objp@entry=0x1005990a0, lines=lines@entry=0x1005e2c50, offset=0, offset@entry=-1, 
    traces=<optimized out>) at addr2line.c:1888
#5  0x0000000100338d1c in rb_dump_backtrace_with_lines.constprop.0 (num_traces=<optimized out>, traces=<optimized out>) at addr2line.c:2287
#6  0x000000010031dfec in rb_print_backtrace () at vm_dump.c:760
#7  0x00000001003356a8 in rb_vm_bugreport.constprop.0 (ctx=<optimized out>) at vm_dump.c:998
#8  0x00000001000cd8c4 in rb_bug_for_fatal_signal (default_sighandler=0x0, sig=<optimized out>, ctx=<optimized out>, fmt=0x100383a98 "Segmentation fault at %p") at error.c:786
#9  0x0000000100256388 in sigsegv (sig=<optimized out>, info=0x10059a330, ctx=0x1005995b0) at signal.c:960
#10 <signal handler called>
#11 0x00007ffff7aa8810 in kill () from /lib64/libc.so.6
#12 0x000000010025ad70 in rb_f_kill (argc=<optimized out>, argv=0x7ffff78e0050) at signal.c:439
#13 0x00000001001fb448 in proc_rb_f_kill (c=<optimized out>, v=<optimized out>, _=<optimized out>) at process.c:8605
#14 0x00000001002e92d8 in ractor_safe_call_cfunc_m1 (recv=<optimized out>, argc=<optimized out>, argv=<optimized out>, func=<optimized out>) at vm_insnhelper.c:2739
#15 0x00000001002f2120 in vm_call_cfunc_with_frame (ec=0x100491ac0, reg_cfp=0x7fffffffe170, calling=<optimized out>) at vm_insnhelper.c:2929
#16 0x00000001002f4f34 in vm_sendish (ec=0x100491ac0, reg_cfp=0x7ffff79dffa0, cd=0x1005c2eb0, block_handler=<optimized out>, method_explorer=<optimized out>) at vm_insnhelper.c:4530
#17 0x00000001002fa2ac in vm_exec_core (ec=0x100491ac0, initial=<optimized out>) at insns.def:789
#18 0x0000000100315200 in rb_vm_exec (ec=0x100491ac0, mjit_enable_p=<optimized out>) at vm.c:2172
#19 0x0000000100317040 in rb_iseq_eval_main (iseq=0x1004a9fb0) at vm.c:2420
#20 0x00000001000d7c8c in rb_ec_exec_node (ec=ec@entry=0x100491ac0, n=n@entry=0x1004a9fb0) at eval.c:317
#21 0x00000001000d7df4 in ruby_run_node (n=0x1004a9fb0) at eval.c:375
#22 0x000000010002afb8 in main (argc=<optimized out>, argv=<optimized out>) at ./main.c:50
(gdb) 

Updated by xtkoba (Tee KOBAYASHI) over 3 years ago

I would humbly advise that the -fno-strict-aliasing flag be appended to CFLAGS by default. See also #17540.

Updated by vo.x (Vit Ondruch) over 3 years ago

xtkoba (Tee KOBAYASHI) wrote in #note-25:

I would humbly advise that the -fno-strict-aliasing flag be appended to CFLAGS by default. See also #17540.

I have not find any guidelines about/against -fno-strict-aliasing in Fedora, so from that POV it would be acceptable. But I would like to avoid to have this as a downstream only option. Therefore if this should be the solution, I'd prefer if this option is applied upstream.

BTW, In your experience, do you think trying something like [1] could help catch such issues earlier?

[1] https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8#catching-strict-aliasing-violations

Updated by xtkoba (Tee KOBAYASHI) over 3 years ago

vo.x (Vit Ondruch) wrote in #note-26:

BTW, In your experience, do you think trying something like [1] could help catch such issues earlier?

I'm sorry but I'm not familiar with techniques for detecting strict aliasing violation. It would be nice if we had some sort of sanitizer for that. It seems there was once a project to implement one [2], which is not heard now.

[2] https://llvm.org/devmtg/2017-10/slides/Finkel-The%20Type%20Sanitizer.pdf

Updated by alanwu (Alan Wu) over 3 years ago

I was able to reduce the Hash.ruby2_keywords_hash?(1) repro and report it to GCC.
It looks like we are hitting an optimizer bug with LTO: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101868

For workarounds, putting __attribute__ ((optimize (1))) on functions that experience this might be an option.

Updated by vo.x (Vit Ondruch) over 3 years ago

Just testing the issue from comment 24 and there is not difference with or without -fno-strict-aliasing

Updated by xtkoba (Tee KOBAYASHI) over 3 years ago

The problem described in #note-24 does not look like very much related to the other part. Maybe worth reopening #17052?

Actions #31

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset git|573eef7c897ff938539270e605445da13093d664.


Indicate the slow path of Check_Type never return [Bug #18062]

Though this call to rb_check_type is just to raise an exception
and never return actually, it can return at least formally. That
means a caller function looks like it will access flags even in
the special-const cases, and some optimizers may unify the access
with the same access just following the call, and re-order it
before the guard.

Actions #33

Updated by mame (Yusuke Endoh) over 2 years ago

  • Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: REQUIRED to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONTNEED
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0