This project is closed and read-only.
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().