Bug #7856

The usage of try_run in extconf.rb is broken when crosscompiling

Added by Luiz Angelo Daros de Luca about 1 year ago. Updated 12 months ago.

[ruby-core:52275]
Status:Closed
Priority:Normal
Assignee:Nobuyoshi Nakada
Category:ext
Target version:next minor
ruby -v:1.9.2p0 Backport:

Description

Hello,

Every "try_run" inside extconf.rb (found in some ext/*/extconf.rb) tries to compile and run the generated binary. However,
when crosscompiling, this simply can't work.

Please, make tryrun be ignored (or just test the compilation) when crosscompiling is detected. I tested this only at 1.9.2
but this might affect all versions that uses try
run to test dependencies.

Taking socket as an example, this can be solved individually, from the original:

getaddrinfook = (enableconfig("wide-getaddrinfo") && :wide) ||
(checking
for("wide getaddrinfo") {try_run(<<EOF)} && :os)

to:

getaddrinfook = (enableconfig("wide-getaddrinfo") && :wide) ||
(CROSS
COMPILING && :cross) ||
(checkingfor("wide getaddrinfo") {tryrun(<<EOF)} && :os)

or just allow the check for every try_run to be manually defined in ./configure script
like:

getaddrinfook = (enableconfig("wide-getaddrinfo") && :wide) ||
(enable
config("ignore-getaddrinfo-check") && :manual ) ||
(CROSS
COMPILING && && false) ||
(checkingfor("wide getaddrinfo") {tryrun(<<EOF)} && :os)

Regards,

History

#1 Updated by Luis Lavena about 1 year ago

  • Status changed from Open to Feedback
  • Priority changed from High to Normal

Hello,

Can you tell us more details about the platform you're targeting? The compiler you're using and what platform are you running it in?

Also, can you provide the exact output of mkmf.log and the error you're getting?

I can tell that I successfully cross-compile Ruby in OSX/Linux targeting Windows (MinGW) without issues.

The more details you provide, the better we will be able to spot the issue.

Thank you.

#2 Updated by Luiz Angelo Daros de Luca about 1 year ago

The problem was reported here:

https://dev.openwrt.org/ticket/9873

The mkmf.log just shows that the "checking wide getaddrinfo failed". The c code it generates is OK. The executable it compiles is also ok. However, the arch that is not compatible with the host machine to be able to exec it. I'm compiling in a Linux x8664 targeting a Linux mips 32. The generated test executable will be mips and it cannot run in a x8664 machine. This is an example of exec programs for each arch, host and target:

ruby: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xfe2cb0569dd24a811aad338f4763f442296f6fc6, not stripped

ruby: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), with unknown capability 0x41000000 = 0xf676e75, with unknown capability 0x10000 = 0x70403, not stripped

When I copy the test executable to the target machine and runs it, it works without problems.

As a principle, one cannot depend on the response of an executable to test a feature while in crosscompiling.

In your case, compiling to windows, you might just get and exception. I guess the problem with getaddrinfo is only trigged for IPv6 machines, that might not be your case, and it also skips the test is the ./configure option --enable-wide-getaddrinfo was set, that you might use.

In the past, the --enable-wide-getaddrinfo was suggested for Linux in order to fix the problem with IPv6. If enable-wide-getaddrinfo is used, it emulates the getaddrinfo using the function getipnodebyname. However, getipnodebyname is deprecated for glibc and absent in modern systems. So, the compiled socket.so will never resolve all its symbols and it will never work. For this reason, ruby does not work in OpenWRT since release 10.03 at april 2010.

This problem applies to any tryrun that does not check for crosscompiling. tk extension, for example, ignore some tryrun while crosscompiling.

#3 Updated by Koichi Sasada about 1 year ago

  • Assignee set to Nobuyoshi Nakada
  • Target version changed from 1.9.2 to next minor

#4 Updated by Akira Tanaka 12 months ago

  • Status changed from Feedback to Closed

I modified ext/socket/extconf.rb (r40464 and r40466)
and ext/curses/extconf.rb (r40468).

I think they don't use try_run while cross compiling after r40468.

Also available in: Atom PDF