Project

General

Profile

Actions

Bug #7856

closed

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

Added by luizluca (Luiz Angelo Daros de Luca) about 11 years ago. Updated almost 11 years ago.

Status:
Closed
Target version:
ruby -v:
1.9.2p0
Backport:
[ruby-core:52275]

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 try_run 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:

getaddr_info_ok = (enable_config("wide-getaddrinfo") && :wide) ||
(checking_for("wide getaddrinfo") {try_run(<<EOF)} && :os)

to:

getaddr_info_ok = (enable_config("wide-getaddrinfo") && :wide) ||
(CROSS_COMPILING && :cross) ||
(checking_for("wide getaddrinfo") {try_run(<<EOF)} && :os)

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

getaddr_info_ok = (enable_config("wide-getaddrinfo") && :wide) ||
(enable_config("ignore-getaddr_info-check") && :manual ) ||
(CROSS_COMPILING && <warn the user to use --ignore-getaddr_info-check> && false) ||
(checking_for("wide getaddrinfo") {try_run(<<EOF)} && :os)

Regards,

Updated by luislavena (Luis Lavena) about 11 years ago

  • Status changed from Open to Feedback
  • Priority changed from 5 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.

Updated by luizluca (Luiz Angelo Daros de Luca) about 11 years 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 x86_64 targeting a Linux mips 32. The generated test executable will be mips and it cannot run in a x86_64 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 try_run that does not check for crosscompiling. tk extension, for example, ignore some try_run while crosscompiling.

Updated by ko1 (Koichi Sasada) about 11 years ago

  • Assignee set to nobu (Nobuyoshi Nakada)
  • Target version changed from 1.9.2 to 2.6

Updated by akr (Akira Tanaka) almost 11 years 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0