Bug #18049


Cannot build ruby-3.0.2 on NetBSD

Added by sydofficious (Kenneth Dunlap) over 1 year ago. Updated over 1 year ago.

Target version:


I get random segfaults when attempting to build on NetBSD

uname -a
NetBSD 9.1 NetBSD 9.1 (PANIX-STD) #2: Thu Mar 18 17:46:23 EDT 2021 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-constant-logical-operand -Wno-long-long\
                          -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)\

        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,  -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/ [0x79baa3ee2399]
/usr/local/lib/ [0x79baa3ee243e]
/usr/local/lib/ [0x79baa3cc3211]
/usr/local/lib/ [0x79baa3e2eb49]
/usr/lib/ [0x79baa1aa1d50]

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

* Loaded script: ./tool/mk_builtin_loader.rb

* Loaded features:

    1 thread.rb
    4 ruby2_keywords.rb
    5 /usr/local/lib/ruby/3.0.0/x86_64-netbsd9.1/enc/
    6 /usr/local/lib/ruby/3.0.0/x86_64-netbsd9.1/enc/trans/
    7 /usr/local/lib/ruby/3.0.0/x86_64-netbsd9.1/
    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.

Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #18050: Cannot build ruby-2.7.4 on NetBSDClosedActions

Updated by xtkoba (Tee KOBAYASHI) over 1 year ago

First, it should be clarified that it is the already installed /usr/local/bin/ruby (version 3.0.1p64) that segfaults here.

I guess that the source comes directly from a Git repository, as prelude.rbinc should be prebuilt in a release tarball which should be tried out for self-containedness.

To avoid using already installed Ruby interpreters try adding the option --with-baseruby=no to ./configure.

Updated by sydofficious (Kenneth Dunlap) over 1 year ago

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) $(POSTLINK)
+               paxctl +a $@

                @$(RM) $@
Actions #3

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Has duplicate Bug #18050: Cannot build ruby-2.7.4 on NetBSD added
Actions #4

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

Does this work?

diff --git a/ b/
index d018e8a6f4f..2d91972c218 100644
--- a/
+++ b/
@@ -1176,6 +1176,10 @@ main()
 [netbsd*], [	LIBS="-lm $LIBS"
+		AC_CHECK_PROGS(paxctl, paxctl)
+		AS_IF([test -n "$paxctl"], [
+		    POSTLINK="$paxctl +a\$@${POSTLINK:+; $POSTLINK}"
+		])
 [dragonfly*], [	LIBS="-lm $LIBS"

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

Maybe only miniruby needs to disable ASLR?

Actions #7

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Feedback

Also available in: Atom PDF