Trouble building 64-bit Ruby 1.8.3 on Solaris 10/AMD64

Hello, I'm attempting to build an AMD64 native Ruby interpreter on top
of Solaris 10 with gcc and have been running into a number of
problems.

The first is ensuring that the -m64 parameter, which instructs gcc to
build 64-bit executables, is passed correctly. It seems like LDFLAGS
is ignored.

If I ./configure CC=gcc CFLAGS=-m64 LDFLAGS=-m64 and try to compile I get:

gcc -fPIC -m64 -I. -I../.. -I../../. -I../.././ext/bigdecimal -c bigdecimal.c
gcc -Wl,-G -L'../..' -o ../../.ext/i386-solaris2.10/bigdecimal.so
bigdecimal.o -ldl -lm -lc
ld: fatal: file bigdecimal.o: wrong ELF class: ELFCLASS64

Because the -m64 parameter was not being passed during linking (same
behavior occurs if I set the CC/CFLAGS/LDFLAGS) environment variables.

As a workaround, I tried creating a wrapper script called "gcc64"
which contains the following:

#!/bin/sh

/usr/sfw/bin/gcc -m64 $*

And it compiles successfully, however:

# make test
make: Warning: Illegal dependency list for target `.DEFAULT'
not ok system 1 -- ./sample/test.rb:1643
not ok system 2 -- ./sample/test.rb:1644
not ok system 3 -- ./sample/test.rb:1650
not ok system 4 -- ./sample/test.rb:1651
not ok system 5 -- ./sample/test.rb:1658
not ok system 6 -- ./sample/test.rb:1668
not ok system 7 -- ./sample/test.rb:1669
sample/test.rb:2037: Invalid char `\377' in expression
not ok system 9 -- ./sample/test.rb:1711
test failed
*** Error code 1

Okay, not good. If I try to make install and install gems...

/root/rubygems-0.8.11/./post-install.rb:73:in `instance_eval': compile
error (SyntaxError)
/root/rubygems-0.8.11/./post-install.rb:73: Invalid char `\377' in
expression from setup.rb:583:in `try_run_hook'

For some reason there's a corrupt looking character at the bottom of
the file. If I edit the file with vim, it reports:

"post_install.rb" [Incomplete last line] 73 lines, 2018 characters

If I delete the offending line it solves *that* problem, but begins to
complain about other files in site_ruby having "Invalid char `\377' in
expression". It seems like virtually every file in site_ruby is
affected.

Any ideas?

Tony Arcieri

Two important things I forgot to mention:

1. Yes, this is successfully building a 64-bit binary.

2. No, the problem does NOT occur when I build a 32-bit binary:

# make test
make: Warning: Illegal dependency list for target `.DEFAULT'
test succeeded

Tony Arcieri

···

On 9/27/05, Tony Arcieri <bascule@gmail.com> wrote:

Hello, I'm attempting to build an AMD64 native Ruby interpreter on top
of Solaris 10 with gcc and have been running into a number of
problems.

The first is ensuring that the -m64 parameter, which instructs gcc to
build 64-bit executables, is passed correctly. It seems like LDFLAGS
is ignored.

If I ./configure CC=gcc CFLAGS=-m64 LDFLAGS=-m64 and try to compile I get:

gcc -fPIC -m64 -I. -I../.. -I../../. -I../.././ext/bigdecimal -c bigdecimal.c
gcc -Wl,-G -L'../..' -o ../../.ext/i386-solaris2.10/bigdecimal.so
bigdecimal.o -ldl -lm -lc
ld: fatal: file bigdecimal.o: wrong ELF class: ELFCLASS64

Because the -m64 parameter was not being passed during linking (same
behavior occurs if I set the CC/CFLAGS/LDFLAGS) environment variables.

As a workaround, I tried creating a wrapper script called "gcc64"
which contains the following:

#!/bin/sh

/usr/sfw/bin/gcc -m64 $*

And it compiles successfully, however:

# make test
make: Warning: Illegal dependency list for target `.DEFAULT'
not ok system 1 -- ./sample/test.rb:1643
not ok system 2 -- ./sample/test.rb:1644
not ok system 3 -- ./sample/test.rb:1650
not ok system 4 -- ./sample/test.rb:1651
not ok system 5 -- ./sample/test.rb:1658
not ok system 6 -- ./sample/test.rb:1668
not ok system 7 -- ./sample/test.rb:1669
sample/test.rb:2037: Invalid char `\377' in expression
not ok system 9 -- ./sample/test.rb:1711
test failed
*** Error code 1

Okay, not good. If I try to make install and install gems...

/root/rubygems-0.8.11/./post-install.rb:73:in `instance_eval': compile
error (SyntaxError)
/root/rubygems-0.8.11/./post-install.rb:73: Invalid char `\377' in
expression from setup.rb:583:in `try_run_hook'

For some reason there's a corrupt looking character at the bottom of
the file. If I edit the file with vim, it reports:

"post_install.rb" [Incomplete last line] 73 lines, 2018 characters

If I delete the offending line it solves *that* problem, but begins to
complain about other files in site_ruby having "Invalid char `\377' in
expression". It seems like virtually every file in site_ruby is
affected.

Any ideas?

Tony Arcieri

Hi,

At Wed, 28 Sep 2005 04:05:45 +0900,
Tony Arcieri wrote in [ruby-talk:157913]:

The first is ensuring that the -m64 parameter, which instructs gcc to
build 64-bit executables, is passed correctly. It seems like LDFLAGS
is ignored.

Try to use DLDFLAGS instead.

sample/test.rb:2037: Invalid char `\377' in expression

I hope it was fixed this morning.

···

--
Nobu Nakada

Hi,

At Wed, 28 Sep 2005 04:05:45 +0900,
Tony Arcieri wrote in [ruby-talk:157913]:
> The first is ensuring that the -m64 parameter, which instructs gcc to
> build 64-bit executables, is passed correctly. It seems like LDFLAGS
> is ignored.

Try to use DLDFLAGS instead.

DLDFLAGS didn't do anything.

> sample/test.rb:2037: Invalid char `\377' in expression

I hope it was fixed this morning.

I tried Ruby 1.8.2. It seemed to add the -m64 flag on its own. And
everything worked.

Something broke between Ruby 1.8.2. and 1.8.3, at least for Solaris 10/AMD64.

I'll go ahead and stick with Ruby 1.8.2 I guess, especially since I
can add DTrace instrumentation.

Tony Arcieri

···

On 9/27/05, nobuyoshi nakada <nobuyoshi.nakada@ge.com> wrote:

Hi,

At Thu, 29 Sep 2005 04:13:50 +0900,
Tony Arcieri wrote in [ruby-talk:158130]:

> > The first is ensuring that the -m64 parameter, which instructs gcc to
> > build 64-bit executables, is passed correctly. It seems like LDFLAGS
> > is ignored.
>
> Try to use DLDFLAGS instead.

DLDFLAGS didn't do anything.

I tried with DLDFLAGS=-m32 on cygwin and it worked fine.
Can't you show the config.log file? OK to even send directly
to nobu@ruby-lang.org.

Or you can do ./configure CC='gcc -m64'.

> > sample/test.rb:2037: Invalid char `\377' in expression
>
> I hope it was fixed this morning.

I tried Ruby 1.8.2. It seemed to add the -m64 flag on its own. And
everything worked.

I meant I committed a fix yesterday morning.

···

Wed Sep 28 08:12:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>

  * io.c (read_buffered_data): check if reached EOF. fixed: [ruby-dev:27334]

--
Nobu Nakada

I tried with DLDFLAGS=-m32 on cygwin and it worked fine.
Can't you show the config.log file? OK to even send directly
to nobu@ruby-lang.org.

If you want I could do this for experimental purposes, but my
workaround got the job done. CC=gcc -m64" would probably work too.

I meant I committed a fix yesterday morning.

        * io.c (read_buffered_data): check if reached EOF. fixed: [ruby-dev:27334]

I'm building Ruby for use with a production Rails application, so I
wanted to use a stable version. It sounds like you found the bug, so
I'll just update after the next stable release. Plus I want to use
the DTrace patch which is only available for 1.8.2

Tony Arcieri

···

On 9/28/05, nobuyoshi nakada <nobuyoshi.nakada@ge.com> wrote:

Wed Sep 28 08:12:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>

Hi,

At Thu, 29 Sep 2005 15:05:04 +0900,
Tony Arcieri wrote in [ruby-talk:158196]:

> I tried with DLDFLAGS=-m32 on cygwin and it worked fine.
> Can't you show the config.log file? OK to even send directly
> to nobu@ruby-lang.org.

If you want I could do this for experimental purposes, but my
workaround got the job done. CC=gcc -m64" would probably work too.

I'd like to know why DLDFLAGS can't be set only on Solaris.

> I meant I committed a fix yesterday morning.
>
>
> * io.c (read_buffered_data): check if reached EOF. fixed: [ruby-dev:27334]

I'm building Ruby for use with a production Rails application, so I
wanted to use a stable version. It sounds like you found the bug, so
I'll just update after the next stable release. Plus I want to use
the DTrace patch which is only available for 1.8.2

You mean [ruby-core:05557] and [ruby-core:05575]? Hmmm, I've
forgot it, but will post a patch for recent versions later.

···

> Wed Sep 28 08:12:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>

--
Nobu Nakada

I'd like to know why DLDFLAGS can't be set only on Solaris.

With DLDFLAGS=-m64 it do

gcc -fPIC -g -O2 -I. -I../.. -I../../. -I../.././ext/bigdecimal -c bigdecimal.c
In file included from ../../ruby.h:24,
                 from bigdecimal.c:23:
../../config.h:17:1: warning: "_FILE_OFFSET_BITS" redefined
In file included from /usr/include/iso/ctype_iso.h:30,
                 from /usr/include/ctype.h:18,
                 from bigdecimal.c:16:
/usr/include/sys/feature_tests.h:96:1: warning: this is the location of the previous definition
gcc -Wl,-G -m64 -L'../..' -o ../../.ext/sparc-solaris2.8/bigdecimal.so bigdecimal.o -ldl -lcrypt -lm -lc
ld: fatal: file bigdecimal.o: wrong ELF class: ELFCLASS32

With CC="gcc -m64"

compiling bigdecimal
gcc -m64 -fPIC -g -O2 -I. -I../.. -I../../. -I../.././ext/bigdecimal -c bigdecimal.c
gcc -m64 -Wl,-G -m64 -L'../..' -o ../../.ext/sparc-solaris2.8/bigdecimal.so bigdecimal.o -ldl -lm -lc

Guy Decoux

Hi,

At Thu, 29 Sep 2005 18:23:55 +0900,
ts wrote in [ruby-talk:158207]:

> I'd like to know why DLDFLAGS can't be set only on Solaris.

With DLDFLAGS=-m64 it do

gcc -fPIC -g -O2 -I. -I../.. -I../../. -I../.././ext/bigdecimal -c bigdecimal.c
In file included from ../../ruby.h:24,
                 from bigdecimal.c:23:
../../config.h:17:1: warning: "_FILE_OFFSET_BITS" redefined
In file included from /usr/include/iso/ctype_iso.h:30,
                 from /usr/include/ctype.h:18,
                 from bigdecimal.c:16:
/usr/include/sys/feature_tests.h:96:1: warning: this is the location of the previous definition
gcc -Wl,-G -m64 -L'../..' -o ../../.ext/sparc-solaris2.8/bigdecimal.so bigdecimal.o -ldl -lcrypt -lm -lc
ld: fatal: file bigdecimal.o: wrong ELF class: ELFCLASS32

DLDFLAGS itself seems to work.

With CC="gcc -m64"

compiling bigdecimal
gcc -m64 -fPIC -g -O2 -I. -I../.. -I../../. -I../.././ext/bigdecimal -c bigdecimal.c
gcc -m64 -Wl,-G -m64 -L'../..' -o ../../.ext/sparc-solaris2.8/bigdecimal.so bigdecimal.o -ldl -lm -lc

Or both of CFLAGS and DLDFLAGS are needed.

OK, understood. Thank you.

···

--
Nobu Nakada