On Thu, 10 Jun 2004 01:13:00 +0900, Jim Freeze <jim / freeze.org> wrote:

>Hi
>
>While porting to an opteron 64bit computer, we noticed one
>of our .so file was aborting. The problem was fixed by
>adding a simple #include <re.h> to the .c file.
>
>My question is, why is it required to include this file for opteron,
>but not for the 32bit x86 machines. Without the include statement, I get
>the error below on the 64 bit machine, but not on 32bit x86
>or 64bit Solaris.
>
> uname -a
> Linux op2 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:32:58 EDT 2003 x86_64
> x86_64 x86_64 GNU/Linux
>
> make
> gcc -fPIC -O2 -g -pipe -Wall -fPIC -I.
> -I/usr/lib64/ruby/1.8/x86_64-linux-gnu
> -I/usr/lib64/ruby/1.8/x86_64-linux-gnu -I.   -c netlistparser.c
> netlistparser.c: In function `Init_netlistparser':
> netlistparser.c:113: warning: implicit declaration of function
> `rb_reg_regcomp'
> gcc -shared  -L"/usr/lib64" -o netlistparser.so netlistparser.o  -lruby
> -ldl -lcrypt -lm  -lc

Almost certainly the actual function definition doesn't match with the
defaults used by the compiler in the absence of a prototype. I don't
have access to the ruby source here but my guess is that
rb_reg_regcomp actually uses/returns a 64-bit value but the compiler
assumed a 32-bit value. When you execute the .so, rb_reg_regcomp puts
a 64-bit value on the stack but the caller only takes a 32-bit value
off. Boom. Adding the include file makes the prototype available to
the compiler.