From: xtkoba+ruby@... Date: 2021-03-04T22:51:09+00:00 Subject: [ruby-core:102735] [Ruby master Bug#16784] Compiling with --enable-load-relative and "musl-gcc -static" yields "negative string size (or size too big) (ArgumentError)" Issue #16784 has been updated by xtkoba (Tee KOBAYASHI). I have confirmed this issue with a recent 3.1.0dev version (33dc0a070a): ``` $ ./miniruby -e "" ./miniruby: negative string size (or size too big) (ArgumentError) ``` An observation using GDB: ``` Breakpoint 1, ruby_init_loadpath () at ../ruby.c:614 614 VALUE load_path, archlibdir = 0; (gdb) next 616 const char *paths = ruby_initial_load_paths; (gdb) 630 sopath = runtime_libruby_path(); (gdb) 631 libpath = RSTRING_PTR(sopath); (gdb) 633 p = strrchr(libpath, '/'); (gdb) 634 if (p) { (gdb) 675 baselen = p - libpath; (gdb) 676 rb_str_resize(sopath, baselen); (gdb) p baselen $1 = 18446743798821772880 (gdb) p p $2 = 0x0 (gdb) p libpath $3 = 0x400096a1b0 "" ``` It seems that in line 675 `baselen` is set to a wrong value when `p` is equal to `NULL`. A proposed workaround: ``` --- a/ruby.c +++ b/ruby.c @@ -671,8 +671,11 @@ p = p2; } #endif + baselen = p - libpath; + } + else { + baselen = 0; } - baselen = p - libpath; rb_str_resize(sopath, baselen); libpath = RSTRING_PTR(sopath); #define PREFIX_PATH() sopath ``` ---------------------------------------- Bug #16784: Compiling with --enable-load-relative and "musl-gcc -static" yields "negative string size (or size too big) (ArgumentError)" https://bugs.ruby-lang.org/issues/16784#change-90741 * Author: runlevel5 (Trung Le) * Status: Open * Priority: Normal * ruby -v: ruby 2.6.6p146 (2020-03-31 revision 67876) [powerpc64le-linux-musl] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- ``` $ uname -ar Linux localhost 5.4.27-0-lts #1-Alpine SMP Mon, 23 Mar 2020 18:15:20 UTC ppc64le Linux $ gcc --version gcc (Alpine 9.2.0) 9.2.0 Copyright (C) 2019 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. $ apk info musl musl-1.1.24-r2 description: the musl c library (libc) implementation ruby-2.6.6> CC="gcc -static" ./configure --enable-load-relative Configuration summary for ruby version 2.6.6 * Installation prefix: /usr/local * exec prefix: ${prefix} * arch: powerpc64le-linux-musl * site arch: ${arch} * RUBY_BASE_NAME: ruby * ruby lib prefix: ${libdir}/${RUBY_BASE_NAME} * site libraries path: ${rubylibprefix}/${sitearch} * vendor path: ${rubylibprefix}/vendor_ruby * target OS: linux-musl * compiler: gcc -static * with pthread: yes * enable shared libs: no * dynamic library ext: so * CFLAGS: ${optflags} ${debugflags} ${warnflags} * LDFLAGS: -L. -fstack-protector-strong -rdynamic \ -Wl,-export-dynamic * DLDFLAGS: -Wl,--compress-debug-sections=zlib * optflags: -O3 * debugflags: -ggdb3 * warnflags: -Wall -Wextra -Wdeclaration-after-statement \ -Wdeprecated-declarations -Wduplicated-cond \ -Wimplicit-function-declaration -Wimplicit-int \ -Wmisleading-indentation -Wpointer-arith \ -Wrestrict -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: yes * JIT support: yes * man page type: man ruby-2.6.6> make ... building rb_mjit_header.h linking miniruby rb_mjit_header.h updated generating encdb.h building .ext/include/powerpc64le-linux-musl/rb_mjit_min_header-2.6.6.h ./miniruby -I./lib -I. -I.ext/common ./tool/transform_mjit_header.rb "gcc -static " rb_mjit_header.h .ext/include/powerpc64le-linux-musl/rb_mjit_min_header-2.6.6.h Traceback (most recent call last): Traceback (most recent call last): ./miniruby: negative string size (or size too big) (ArgumentError) ./miniruby: negative string size (or size too big) (ArgumentError) make: *** [uncommon.mk:781: .rbconfig.time] Error 1 make: *** Waiting for unfinished jobs.... make: *** [uncommon.mk:233: .ext/include/powerpc64le-linux-musl/rb_mjit_min_header-2.6.6.h] Error 1 Traceback (most recent call last): ./miniruby: negative string size (or size too big) (ArgumentError) make: *** [uncommon.mk:1033: encdb.h] Error 1 ruby-2.6.6> ./miniruby ./miniruby: negative string size (or size too big) (ArgumentError) ``` Seems to me the miniruby binary is not correctly compiled if CC is `musl-gcc -static` (static linking) and `--enable-load-relative` option is enabled. -- https://bugs.ruby-lang.org/ Unsubscribe: