Bug #31506 detection of function's availability is wrong in configure.in
Submitted: 10 Oct 2007 15:03 Modified: 13 Apr 2009 23:39
Reporter: Guilhem Bichot Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.2-bk OS:Any
Assigned to: Staale Smedseng CPU Architecture:Any

[10 Oct 2007 15:03] Guilhem Bichot
Description:
Found in 5.2 but probably exists in older ones too.
In several places in configure.in we have patterns like this:
AC_CHECK_FUNC(p2open, , AC_CHECK_LIB(gen, p2open))
AC_CHECK_FUNC(sched_yield, , AC_CHECK_LIB(posix4, sched_yield))
This is wrong, per autoconf's doc: it first looks for p2open. Assuming it is not found, it executes AC_CHECK_LIB, and so there is no chance that HAVE_P2OPEN is defined, as what AC_CHECK_LIB does is merely see if library "gen" exists (by seeing if it contains a symbol named p2open) and if yes, define HAVE_LIBGEN and add -lgen to the linker flags. The intention was very probably to see if libgen exists and if yes, re-do the check for p2open and if it is found, define HAVE_P2OPEN.
There are several ones of these.

How to repeat:
seeing build failures on Solaris 10 when adding a call to sched_yield() in a function: looking at config.log, posix4 is present and contains sched_yield() but HAVE_SCHED_YIELD is not defined in config.h.

Suggested fix:
AC_CHECK_FUNC(sched_yield, , AC_CHECK_LIB(posix4, sched_yield, [AC_DEFINE(HAVE_SCHED_YIELD]))
maybe ?
Whatever the fix is, please test it on some platform when the AC_CHECK_LIB is actually executed.
Maybe "configure" does some caching of what functions it has seen so far,
for example
AC_CHECK_FUNC(sched_yield, , AC_CHECK_LIB(posix4, sched_yield))
AC_CHECK_FUNCS(sched_yield)
is (from my little tests) not doing the desired thing: the second check still says "no".
Note that the case of sched_yield is already fixed by me in 5.2-backup tree.
[18 Dec 2008 13:27] Guilhem Bichot
It is still true in 5.1 and 6.0:

[INS 14:24 /m/bzrrepos/mysql-6.0 $] grep AC_CHECK_FUNC.*AC_CHECK_LIB configure.in
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
AC_CHECK_FUNC(p2open, , AC_CHECK_LIB(gen, p2open))
AC_CHECK_FUNC(bind, , AC_CHECK_LIB(bind, bind))
  AC_CHECK_FUNC(gtty, , AC_CHECK_LIB(compat, gtty))
[INS 14:24 /m/bzrrepos/mysql-6.0 $] cd ../mysql-5.1
[INS 14:25 /m/bzrrepos/mysql-5.1 $] grep AC_CHECK_FUNC.*AC_CHECK_LIB configure.in
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
AC_CHECK_FUNC(p2open, , AC_CHECK_LIB(gen, p2open))
AC_CHECK_FUNC(bind, , AC_CHECK_LIB(bind, bind))
AC_CHECK_FUNC(sched_yield, , AC_CHECK_LIB(posix4, sched_yield))
  AC_CHECK_FUNC(gtty, , AC_CHECK_LIB(compat, gtty))

In 6.0 I have already made a fix for sched_yield, which seems to work, it's this:
AC_CHECK_FUNC(sched_yield, , AC_CHECK_LIB(posix4, sched_yield,
[AC_DEFINE(HAVE_SCHED_YIELD) LIBS="$LIBS -lposix4"]))
[18 Feb 2009 14:49] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/66771

2805 Staale Smedseng	2009-02-18
      Bug#31506 detection of function's availability is wrong in 
      configure.in
      
      Replacing AC_CHECK_FUNC+AC_CHECK_LIB combination with 
      AC_SEARCH_LIBS.
[19 Feb 2009 10:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/66860

2804 Staale Smedseng	2009-02-19
      Bug#31506 detection of function's availability is wrong in
      configure.in
      
      Replacing AC_CHECK_FUNC+AC_CHECK_LIB combination with
      AC_SEARCH_LIBS.
[13 Mar 2009 19:03] Bugs System
Pushed into 5.1.33 (revid:joro@sun.com-20090313111355-7bsi1hgkvrg8pdds) (version source revid:staale.smedseng@sun.com-20090219102452-9wf3408qyzuh6cv9) (merge vers: 5.1.33) (pib:6)
[18 Mar 2009 13:19] Bugs System
Pushed into 6.0.11-alpha (revid:joro@sun.com-20090318122208-1b5kvg6zeb4hxwp9) (version source revid:staale.smedseng@sun.com-20090219102944-cs2jv7bemk585sq3) (merge vers: 6.0.10-alpha) (pib:6)
[13 Apr 2009 23:39] Paul DuBois
Noted in 5.1.33, 6.0.11 changelogs.

Detection by configure of several functions such as setsockopt(),
bind(), sched_yield(), and gtty() could fail.
[9 May 2009 16:42] Bugs System
Pushed into 5.1.34-ndb-6.2.18 (revid:jonas@mysql.com-20090508185236-p9b3as7qyauybefl) (version source revid:jonas@mysql.com-20090508100057-30ote4xggi4nq14v) (merge vers: 5.1.33-ndb-6.2.18) (pib:6)
[9 May 2009 17:39] Bugs System
Pushed into 5.1.34-ndb-6.3.25 (revid:jonas@mysql.com-20090509063138-1u3q3v09wnn2txyt) (version source revid:jonas@mysql.com-20090508175813-s6yele2z3oh6o99z) (merge vers: 5.1.33-ndb-6.3.25) (pib:6)
[9 May 2009 18:37] Bugs System
Pushed into 5.1.34-ndb-7.0.6 (revid:jonas@mysql.com-20090509154927-im9a7g846c6u1hzc) (version source revid:jonas@mysql.com-20090509073226-09bljakh9eppogec) (merge vers: 5.1.33-ndb-7.0.6) (pib:6)