Backport #8169
closedmkmf generates inaccurate conftest.c test files
Description
mkmf seems to reproduce some of the functionality of GNU Autoconf, but it can generate test files that do not correctly probe for functionality and do not produce correct results. For example, ext/socket produces one conftest.c that looks like:
1: #include "ruby.h"
2:
3: /top/
4: int main() {return 0;}1: #include "ruby.h"
2:
3: /top/
4: int main() {return 0;}
5: extern int t(void);
6: int t(void) { getifaddrs(); return 0; }
When compiled to create an executable "conftest", there is no reference to function t(). Nothing forces t() to be a visible symbol in the final executable and nothing ensures that the linker preserves the function.
On systems where the linker performs garbage collection, such as AIX by default and GNU ld with --gc-sections, the reference to symbol "t" may be dropped, allowing the undefined reference to "getifaddrs" to be dropped, negating the entire purpose of the link test.
The symbol being tested must be called by / referenced by function main().
Updated by drbrain (Eric Hodel) over 11 years ago
- Category set to lib
- Status changed from Open to Assigned
- Assignee set to nobu (Nobuyoshi Nakada)
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r39958.
David, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
mkmf.rb: force refererence in MAIN_DOES_NOTHING
- lib/mkmf.rb (MAIN_DOES_NOTHING): force to refer symbols for tests
to be preserved. [ruby-core:53745] [Bug #8169]
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport200
- Category deleted (
lib) - Status changed from Closed to Assigned
- Assignee changed from nobu (Nobuyoshi Nakada) to nagachika (Tomoyuki Chikanaga)
Updated by edelsohn (David Edelsohn) over 11 years ago
The implementation of this fix does not resolve the problem as the author expects. It generates the following example of conftest.c:
#include "ruby.h"
/top/
extern int t(void);
int t(void) { TLSv1_1_method(); return 0; }
int main(void) {(void)t; return 0;}
Yes, main() now references "t", but the result of "t" is cast to void, which instructs the compiler that it can be thrown away. Therefore, the object file testcase does not reference the function TLSv1_1_method and does not test if it is present in the library.
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Tracker changed from Backport to Bug
- Project changed from Backport200 to Ruby master
- Status changed from Assigned to Open
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Status changed from Open to Closed
This issue was solved with changeset r39989.
David, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
mkmf.rb: force refererence in MAIN_DOES_NOTHING
- lib/mkmf.rb (MAIN_DOES_NOTHING): ensure symbols for tests to be
preserved. [ruby-core:53745] [Bug #8169]
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport200
- Status changed from Closed to Assigned
Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago
- Status changed from Assigned to Closed
This issue was solved with changeset r40289.
David, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 39958,39989: [Backport #8169]
* lib/mkmf.rb (MAIN_DOES_NOTHING): force to refer symbols for tests
to be preserved. [ruby-core:53745] [Bug #8169]
* lib/mkmf.rb (MAIN_DOES_NOTHING): ensure symbols for tests to be
preserved. [ruby-core:53745] [Bug #8169]