Backport #8169

mkmf generates inaccurate conftest.c test files

Added by David Edelsohn about 1 year ago. Updated about 1 year ago.

[ruby-core:53745]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

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().


Related issues

Related to Backport93 - Backport #8216: Request of backport of fix for Bug #8169 Closed 04/04/2013

Associated revisions

Revision 40289
Added by Tomoyuki Chikanaga about 1 year ago

merge revision(s) 39958,39989: [Backport #8169]

* lib/mkmf.rb (MAIN_DOES_NOTHING): force to refer symbols for tests
  to be preserved.   [Bug #8169]

* lib/mkmf.rb (MAIN_DOES_NOTHING): ensure symbols for tests to be
  preserved.   [Bug #8169]

History

#1 Updated by Eric Hodel about 1 year ago

  • Category set to lib
  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada

#2 Updated by Nobuyoshi Nakada about 1 year 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 MAINDOESNOTHING

  • lib/mkmf.rb (MAINDOESNOTHING): force to refer symbols for tests to be preserved. [Bug #8169]

#3 Updated by Nobuyoshi Nakada about 1 year ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Category deleted (lib)
  • Status changed from Closed to Assigned
  • Assignee changed from Nobuyoshi Nakada to Tomoyuki Chikanaga

#4 Updated by David Edelsohn about 1 year 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) { TLSv11method(); 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 TLSv11method and does not test if it is present in the library.

#5 Updated by Nobuyoshi Nakada about 1 year ago

  • Tracker changed from Backport to Bug
  • Project changed from Backport200 to ruby-trunk
  • Status changed from Assigned to Open

#6 Updated by Nobuyoshi Nakada about 1 year 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 MAINDOESNOTHING

  • lib/mkmf.rb (MAINDOESNOTHING): ensure symbols for tests to be preserved. [Bug #8169]

#7 Updated by Nobuyoshi Nakada about 1 year ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Status changed from Closed to Assigned

#8 Updated by Tomoyuki Chikanaga about 1 year 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.   [Bug #8169]

* lib/mkmf.rb (MAIN_DOES_NOTHING): ensure symbols for tests to be
  preserved.   [Bug #8169]

Also available in: Atom PDF