pmq20/ruby-packer

Cannot compile on Arch Linux - duplicate definitions and yydestruct errors

AnrichVS opened this issue · 2 comments

Hi,

I tried compiling a simply ruby program using Ruby Packer, and got various errors. I decided to attempt to compile Ruby Packer myself to see if this resolves the errors. Instead, I also got errors while trying to compile Ruby Packer.

OS: Arch Linux
Kernel: linux-lts 5.4.78-1
gdbm 1.18.1-3
libffi 3.3-4
ncurses 6.2-1
openssl 1.1.1.h-1
readline 8.0.004-1
zlib 1:1.2.11-4

The first error I got was:

/usr/bin/ld: ./libgdbmapp.a(parseopt.o):/tmp/rubyc/gdbm/src/parseopt.c:256: multiple definition of `parseopt_program_args'; gdbm_dump.o:/tmp/rubyc/gdbm/src/gdbm_dump.c:23: first defined here
/usr/bin/ld: ./libgdbmapp.a(parseopt.o):/tmp/rubyc/gdbm/src/parseopt.c:255: multiple definition of `parseopt_program_doc'; gdbm_dump.o:/tmp/rubyc/gdbm/src/gdbm_dump.c:22: first defined here
/usr/bin/ld: ./libgdbmapp.a(parseopt.o):/tmp/rubyc/gdbm/src/parseopt.c:256: multiple definition of `parseopt_program_args'; gdbm_load.o:/tmp/rubyc/gdbm/src/gdbm_load.c:33: first defined here
/usr/bin/ld: ./libgdbmapp.a(parseopt.o):/tmp/rubyc/gdbm/src/parseopt.c:255: multiple definition of `parseopt_program_doc'; gdbm_load.o:/tmp/rubyc/gdbm/src/gdbm_load.c:32: first defined here

To work around this I set the --allow-multiple-definition LDFLAGS:

LDFLAGS="--allow-multiple-definition" bundle exec rake rubyc

This however didn't solve the issue:

/usr/bin/ld: /usr/bin/ld: ./libgdbmapp.a(parseopt.o):/tmp/rubyc/gdbm/src/parseopt.c:256: multiple definition of `parseopt_program_args'; ./libgdbmapp.a(parseopt.o):/tmp/rubyc/gdbm/src/parseopt.c:256: multiple definition of `parseopt_program_args'; gdbm_load.o:/tmp/rubyc/gdbm/src/gdbm_load.c:33: first defined here
/usr/bin/ld: ./libgdbmapp.a(parseopt.o):/tmp/rubyc/gdbm/src/parseopt.c:255: multiple definition of `parseopt_program_doc'; gdbm_load.o:/tmp/rubyc/gdbm/src/gdbm_load.c:32: first defined here
gdbm_dump.o:/tmp/rubyc/gdbm/src/gdbm_dump.c:23: first defined here
/usr/bin/ld: ./libgdbmapp.a(parseopt.o):/tmp/rubyc/gdbm/src/parseopt.c:255: multiple definition of `parseopt_program_doc'; gdbm_dump.o:/tmp/rubyc/gdbm/src/gdbm_dump.c:22: first defined here

I then commented out the duplicate definitions (vendor/gdbm/src/parseopt.c:255 and vendor/gdbm/src/parseopt.c:256):

//char *parseopt_program_doc;
//char *parseopt_program_args;

I then got another error. This is the same error I receive when attempting to compile my own simple Ruby program using rubyc.

parse.c: In function ‘ruby_yyparse’:
parse.c:12323:51: error: macro "yydestruct" passed 5 arguments, but takes just 3
12323 |           if (yychar == END_OF_INPUT)
      |                                                   ^

I have attached the entire compile log:

Full compile log

Apparently this is a ruby bug of 2.6.6.
https://bugs.ruby-lang.org/issues/17106

This could be fixed by cherry picking this commit:
ruby/ruby@47720e2

Or rather, in this case, by adding the content of the commit manually to ruby/tool/ytab.sed .
I'm then stuck to another error:


/tmp/rubyc/ruby-2.7.1.dev/parse.y: In function ‘rb_yytnamerr’:
/tmp/rubyc/ruby-2.7.1.dev/parse.y:12744:23: warning: implicit declaration of function ‘yystpcpy’; did you mean ‘stpcpy’? [-Wimplicit-function-declaration]
12744 |     return (YYSIZE_T)(yystpcpy(yyres, yystr) - yyres);
      |                       ^~~~~~~~
      |                       stpcpy
/tmp/rubyc/ruby-2.7.1.dev/parse.y:12744:46: error: invalid operands to binary - (have ‘int’ and ‘char *’)
12744 |     return (YYSIZE_T)(yystpcpy(yyres, yystr) - yyres);
      |                       ~~~~~~~~~~~~~~~~~~~~~~ ^
      |                       |
      |                       int


Update: apparently the last error was fixed by changing yystpcpy to stpcpy and removing those statements

(void)yystpcpy; /* may not used in newer bison */

from the ruby code.