msgpack / msgpack-ruby

MessagePack implementation for Ruby / msgpack.org[Ruby]
http://msgpack.org/
Apache License 2.0
764 stars 117 forks source link

Compile fails on older toolsets #334

Closed jmartin-tech closed 1 year ago

jmartin-tech commented 1 year ago

Reporting what looks like a unintended loss in compatibility for some old compilers.

When building bundles for compatibility using older platforms the gem fails to compile. There are many workarounds for this including update the build enviournment to bring in more current toolsets, however is seems reasonable to report the impacts.

It looks like #324 introduced syntax not compatible with some gcc old toolchains such as those in Centos6 and RHEL6. This results in 1.7.0 failing to build native objects on some older platforms.

unpacker.c: At top level:
unpacker.c:24: error: expected declaration specifiers or ‘...’ before ‘sizeof’
unpacker.c:25: error: expected declaration specifiers or ‘...’ before string constant
unpacker.c:23: warning: data definition has no type or storage class
unpacker.c:26: warning: type defaults to ‘int’ in declaration of ‘_Static_assert’
...
make: *** [unpacker.o] Error 1

make failed, exit code 2

Target toolset is:

ldd (GNU libc) 2.12
Copyright (C) 2010 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.
Written by Roland McGrath and Ulrich Drepper.
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)

Reproduction env:

docker run --rm=true --tty -u jenkins \
  rapid7/msf-centos6-x64-omnibus:2020_03 \
  bash -l -c "rvm get stable; rvm install 3.0.5; rvm use 3.0.5 && gem install msgpack -v 1.7.0"
byroot commented 1 year ago

Thanks for the report, could you test this branch: https://github.com/msgpack/msgpack-ruby/pull/335 ?

jmartin-tech commented 1 year ago

Branch builds in my test env, thanks for the quick look!

jmartin-tech commented 1 year ago
Pending: (Failures listed here are expected and do not affect your suite's status)

  1) MessagePack with other things raises an error on #unpack with garbage
     # but nothing was raised. why?
     # ./spec/msgpack_spec.rb:118

Finished in 23.29 seconds (files took 0.35594 seconds to load)
448 examples, 0 failures, 1 pending

msgpack 1.7.0 built to pkg/msgpack-1.7.0.gem.
[warn]: @param tag has unknown parameter name: obj
    in file `doclib/msgpack/factory.rb' near line 139
[warn]: Unknown tag @returns in file `doclib/msgpack/factory.rb` near line 150
[warn]: Unknown tag @returns in file `doclib/msgpack/factory.rb` near line 161
Files:          11
Modules:         1 (    1 undocumented)
Classes:        23 (   17 undocumented)
Constants:       5 (    1 undocumented)
Attributes:      6 (    0 undocumented)
Methods:        77 (    0 undocumented)
 83.04% documented

based on:

docker run --rm=true --tty -u jenkins \
  rapid7/msf-centos6-x64-omnibus:2020_03 \
  bash -l -c "cd ~/; git clone https://github.com/msgpack/msgpack-ruby; cd msgpack-ruby; git checkout test-static-insert; rvm get stable; rvm install 3.0.5; rvm use 3.0.5; bundle; rake; gem install --local pkg/msgpack"
jmartin-tech commented 1 year ago

Of note when building against Ruby 2.6.5 there are other failures.

mkdir -p tmp/x86_64-linux/msgpack/2.6.5
cd tmp/x86_64-linux/msgpack/2.6.5
/var/jenkins_home/.rvm/rubies/ruby-2.6.5/bin/ruby -I. -r.rake-compiler-siteconf.rb ../../../../ext/msgpack/extconf.rb
checking for ruby/st.h... yes
checking for st.h... yes
checking for rb_enc_interned_str() in ruby.h... no
checking for rb_hash_new_capa() in ruby.h... no
checking for whether -fvisibility=hidden is accepted as CFLAGS... yes
checking for whether -I.. is accepted as CFLAGS... yes
checking for whether -Wall is accepted as CFLAGS... yes
checking for whether -O3 is accepted as CFLAGS... yes
checking for whether -ggdb3 is accepted as CFLAGS... yes
checking for whether -DHASH_ASET_DEDUPE=1 is accepted as CFLAGS... yes
checking for whether -DSTR_UMINUS_DEDUPE_FROZEN=0 is accepted as CFLAGS... yes
creating Makefile
cd -
cd tmp/x86_64-linux/msgpack/2.6.5
/usr/bin/gmake
compiling ../../../../ext/msgpack/buffer.c
compiling ../../../../ext/msgpack/buffer_class.c
compiling ../../../../ext/msgpack/extension_value_class.c
compiling ../../../../ext/msgpack/factory_class.c
../../../../ext/msgpack/factory_class.c: In function ‘Factory_registered_types_internal’:
../../../../ext/msgpack/factory_class.c:189: error: ‘for’ loop initial declarations are only allowed in C99 mode
../../../../ext/msgpack/factory_class.c:189: note: use option -std=c99 or -std=gnu99 to compile your code
At top level:
cc1: warning: unrecognized command line option "-Wno-tautological-compare"
cc1: warning: unrecognized command line option "-Wno-self-assign"
cc1: warning: unrecognized command line option "-Wno-parentheses-equality"
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand"
cc1: warning: unrecognized command line option "-Wno-cast-function-type"
gmake: *** [factory_class.o] Error 1
rake aborted!
Command failed with status (2): [/usr/bin/gmake...]
/var/jenkins_home/.rvm/gems/ruby-2.6.5/gems/rake-compiler-1.2.1/lib/rake/extensiontask.rb:181:in `block (2 levels) in define_compile_tasks'
/var/jenkins_home/.rvm/gems/ruby-2.6.5/gems/rake-compiler-1.2.1/lib/rake/extensiontask.rb:180:in `block in define_compile_tasks'
/var/jenkins_home/.rvm/gems/ruby-2.6.5/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/var/jenkins_home/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `eval'
/var/jenkins_home/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => default => spec => compile => compile:x86_64-linux => compile:msgpack:x86_64-linux => copy:msgpack:x86_64-linux:2.6.5 => tmp/x86_64-linux/msgpack/2.6.5/msgpack.so
(See full trace by running task with --trace)
byroot commented 1 year ago

Hum, right. Static_assert is C11, so that's a bit complicated.

I converted it to a runtime assert during init and restored the -std=gnu99 flags.

So it should be good now.