Issue #18049 has been updated by sydofficious (Kenneth Dunlap).


This turned out to be an issue with miniruby when the NetBSD kernel has PaX ASLR (Address Space Layout Randomization) enabled. The following patch, applied post-configure, works around the problem.

--- Makefile.orig 2021-07-28 13:31:38.018160281 -0400
+++ Makefile 2021-07-28 13:37:35.292884198 -0400
@@ -270,6 +270,7 @@
$(ECHO) linking $@
$(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(NORMALMAINOBJ) $(MINIOBJS) $(COMMONOBJS) $(MAINLIBS) $(LIBS) $(OUTFLAG)$@
$(Q) $(POSTLINK)

paxctl +a $@
$(PROGRAM):
@$(RM) $@

----------------------------------------
Bug #18049: Cannot build ruby-3.0.2 on NetBSD
https://bugs.ruby-lang.org/issues/18049#change-93046

* Author: sydofficious (Kenneth Dunlap)
* Status: Open
* Priority: Normal
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
I get random segfaults when attempting to build on NetBSD

uname -a
NetBSD juggler.panix.com 9.1 NetBSD 9.1 (PANIX-STD) #2: Thu Mar 18 17:46:23 EDT 2021  root / juggler.panix.com:/misc/obj64/misc/devel/netbsd/9.1/src/sys/arch/amd64/compile/PANIX-STD amd64

Configuration summary for ruby version 3.0.2

   * Installation prefix: /usr/local
   * exec prefix:         ${prefix}
   * arch:                x86_64-netbsd9.1
   * site arch:           ${arch}
   * RUBY_BASE_NAME:      ruby
   * enable shared:       yes
   * ruby lib prefix:     ${libdir}/${RUBY_BASE_NAME}
   * site libraries path: ${rubylibprefix}/${sitearch}
   * vendor path:         ${rubylibprefix}/vendor_ruby
   * target OS:           netbsd9.1
   * compiler:            gcc
   * with pthread:        yes
   * with coroutine:      ucontext
   * enable shared libs:  yes
   * dynamic library ext: so
   * CFLAGS:              ${optflags} ${debugflags} ${warnflags}
   * LDFLAGS:             -L. -fstack-protector-strong -Wl,-export-dynamic
   * DLDFLAGS:            -Wl,--compress-debug-sections=zlib
   * optflags:            -O3
   * debugflags:          -ggdb3
   * warnflags:           -Wall -Wextra -Wdeprecated-declarations\
                          -Wduplicated-cond -Wimplicit-function-declaration\
                          -Wimplicit-int -Wmisleading-indentation\
                          -Wpointer-arith -Wwrite-strings\
                          -Wimplicit-fallthrough=0 -Wmissing-noreturn\
                          -Wno-cast-function-type\
                          -Wno-constant-logical-operand -Wno-long-long\
                          -Wno-missing-field-initializers\
                          -Wno-overlength-strings\
                          -Wno-packed-bitfield-compat\
                          -Wno-parentheses-equality -Wno-self-assign\
                          -Wno-tautological-compare -Wno-unused-parameter\
                          -Wno-unused-value -Wsuggest-attribute=format\
                          -Wsuggest-attribute=noreturn -Wunused-variable
   * strip command:       strip -S -x
   * install doc:         no
   * JIT support:         yes
   * man page type:       man
   * BASERUBY -v:         ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38)\
                          [x86_64-netbsd9.1]


        BASERUBY = /usr/local/bin/ruby --disable=gems
        CC = gcc
        LD = ld
        LDSHARED = gcc -shared
        CFLAGS = -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -std=gnu99  -fPIC -pipe
        XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard -DRUBY_EXPORT -I. -I.ext/include/x86_64-netbsd9.1 -I./include -I. -I./enc/unicode/12.1.0
        CPPFLAGS =
        DLDFLAGS = -Wl,--compress-debug-sections=zlib -Wl,-soname,liblibruby30.so.30  -fstack-protector-strong
        SOLIBS = -lexecinfo -lz -lpthread -lrt -lrt -lcrypt -lm
        LANG = en_US.UTF-8
        LC_ALL =
        LC_CTYPE =
        MFLAGS =
gcc (nb4 20200810) 7.5.0

This particular time, it segfaulted here:

making prelude.rbinc
/usr/local/lib/ruby/3.0.0/ripper/lexer.rb:70: [BUG] Segmentation fault
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-netbsd9.1]

-- Control frame information -----------------------------------------------
c:0009 p:---- s:0037 e:000036 CFUNC  :new
c:0008 p:0043 s:0028 e:000027 CLASS  /usr/local/lib/ruby/3.0.0/ripper/lexer.rb:70
c:0007 p:0042 s:0025 e:000024 CLASS  /usr/local/lib/ruby/3.0.0/ripper/lexer.rb:55
c:0006 p:0013 s:0022 e:000021 TOP    /usr/local/lib/ruby/3.0.0/ripper/lexer.rb:14 [FINISH]
c:0005 p:---- s:0019 e:000018 CFUNC  :require
c:0004 p:0011 s:0014 e:000013 TOP    /usr/local/lib/ruby/3.0.0/ripper.rb:3 [FINISH]
c:0003 p:---- s:0011 e:000010 CFUNC  :require
c:0002 p:0005 s:0006 e:000005 EVAL   ./tool/mk_builtin_loader.rb:3 [FINISH]
c:0001 p:0000 s:0003 E:001d70 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
./tool/mk_builtin_loader.rb:3:in `<main>'
./tool/mk_builtin_loader.rb:3:in `require'
/usr/local/lib/ruby/3.0.0/ripper.rb:3:in `<top (required)>'
/usr/local/lib/ruby/3.0.0/ripper.rb:3:in `require'
/usr/local/lib/ruby/3.0.0/ripper/lexer.rb:14:in `<top (required)>'
/usr/local/lib/ruby/3.0.0/ripper/lexer.rb:55:in `<class:Ripper>'
/usr/local/lib/ruby/3.0.0/ripper/lexer.rb:70:in `<class:Lexer>'
/usr/local/lib/ruby/3.0.0/ripper/lexer.rb:70:in `new'

-- C level backtrace information -------------------------------------------
/usr/local/lib/libruby.so.30(rb_profile_frame_full_label+0x19) [0x79baa3ee2399]
/usr/local/lib/libruby.so.30(rb_profile_frame_full_label+0x8e) [0x79baa3ee243e]
/usr/local/lib/libruby.so.30(rb_bug+0x124) [0x79baa3cc3211]
/usr/local/lib/libruby.so.30(ruby_posix_signal+0x0) [0x79baa3e2eb49]
/usr/lib/libc.so.12(__sigtramp_siginfo_2+0x0) [0x79baa1aa1d50]

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

* Loaded script: ./tool/mk_builtin_loader.rb

* Loaded features:

    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 ruby2_keywords.rb
    5 /usr/local/lib/ruby/3.0.0/x86_64-netbsd9.1/enc/encdb.so
    6 /usr/local/lib/ruby/3.0.0/x86_64-netbsd9.1/enc/trans/transdb.so
    7 /usr/local/lib/ruby/3.0.0/x86_64-netbsd9.1/ripper.so
    8 /usr/local/lib/ruby/3.0.0/ripper/core.rb

gmake: *** [Makefile:1833: prelude.rbinc] Abort trap (core dumped)

Other times it will segfault in other places.  It seems pretty random.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>