|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49648 Broken Macro in acinclude.m4
Submitted: 2009-09-24 03:59 UTC Modified: 2009-09-25 21:43 UTC
From: sven at whgl dot uni-frankfurt dot de Assigned:
Status: Wont fix Package: Compile Failure
PHP Version: 5.2.11 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: sven at whgl dot uni-frankfurt dot de
New email:
PHP Version: OS:


 [2009-09-24 03:59 UTC] sven at whgl dot uni-frankfurt dot de
It seems the PHP_CHEC_LIBRARY Macro wrapping AC_CHECK_LIBRARY is broken for all cases where extra-libs is needed. I'll be quoting directly from the following svn link:

--- snip --- Macro Prototype ---
1822 	dnl
1823 	dnl PHP_CHECK_LIBRARY(library, function [, action-found [, action-not-found [, extra-libs]]])
1824 	dnl
1825 	dnl Wrapper for AC_CHECK_LIB
1826 	dnl 
--- snip --- End Proto ---

Last Parameter ($5) is extra libs, now we look into the Macro:

1828 	save_old_LDFLAGS=$LDFLAGS
1829 	ac_stuff="$5"
1831 	save_ext_shared=$ext_shared
1832 	ext_shared=yes
1833 	PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
1834 	AC_CHECK_LIB([$1],[$2],[
1835 	LDFLAGS=$save_old_LDFLAGS
1836 	ext_shared=$save_ext_shared
1837 	$3
1838 	],[
1839 	LDFLAGS=$save_old_LDFLAGS
1840 	ext_shared=$save_ext_shared
1841 	unset ac_cv_lib_$1[]_$2
1842 	$4
1843 	])dnl
1844 	]) 

Instead of passing $5 into $5 of AC_CHECK_LIB some preprocessing is obviously done, LDFLAGS is stored and PHP_EVAL_LIBLINE is called with $5 and $LDFLAGS. This is indeed completely wrong. When we look at the inner workings of PHP_EVAL_LIBLINE, we can see the following:

403 	 -l*[)]
404 	ac_ii=`echo $ac_i|cut -c 3-`
405 	PHP_ADD_LIBRARY($ac_ii,1,$2)
406 	;;
407 	-L*[)]
408 	ac_ii=`echo $ac_i|cut -c 3-`
409 	PHP_ADD_LIBPATH($ac_ii,$2) 

Though libs and and lib includes are treated by different Macros, they both operate on $2 and indeed, when using the Macro, libs are added to LDFLAGS, which is not right.

The autoconf manual states that: -l<libname> Parameters go into LIBS and only all other linker flags go into LDFLAGS. This is important for the ordering of libs, because AC_CHECK_LIB will prepend the lib to be tested to LIBS, so other-libs, need to be in LIBS, because otherwise the ordering in the call to gcc for the conftest will be wrong and fail.

Reproduce code:
PHP_CHECK_LIB(libname,libsymbol,,,other-libs) where libname references symbols from other-libs.

Expected result:
The check should succeed if the libs are in place and gcc should be called properly.

Actual result:
The ordering will be wrong, gcc will fail to compile the conftest.c and thus the macro fails although it should net.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-24 08:41 UTC]
Not enough information. And there's nothing wrong with the macro either, it's been used in dozens of places without any problems. 
 [2009-09-25 03:07 UTC] sven at whgl dot uni-frankfurt dot de
Here is a thread on the PECL mailing list showing more details, including the wrong call to gcc.


when PHP_CHECK_LIB is called with [dhcpctl, libsym, pass, fail, -lomapi -ldst] will call gcc with:

cc -o conftest -g -O2   -lomapi -ldst conftest.c -ldhcpctl
                      [LDFLAGS, wrong placing!]     [LIBS]

other-libs need to be appended after -ldhcpctl and this is cleary the macro's fault, since passing $5 as 5th parameter to AC_CHECK_LIB (and removing the call to PHP_EVAL_LIBLINE restores the correct ordering of the parameters, as expected)

And, to quote from the autoconf manual!:

"Variable: LDFLAGS

    Options for the linker. If it is not set in the environment when configure runs, the default value is empty. configure uses this variable when linking programs to test for C, C++, Objective C, and Fortran features.

    This variable's contents should contain options like -s and -L that affect only the behavior of the linker. Please see the explanation of CFLAGS for what you can do if an option also affects other phases of the compiler.

    *Don't use this variable to pass library names (-l) to the linker; use LIBS instead. *


"Variable: LIBS

    -l options to pass to the linker. The default value is empty, but some Autoconf macros may prepend extra libraries to this variable if those libraries are found and provide necessary functions, see Libraries. configure uses this variable when linking programs to test for C, C++, and Fortran features. "

--- From AC_CHECK_LIB desc: --- 

If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro fails to detect that library is present, because linking the test program always fails with unresolved symbols. The other-libraries argument should be limited to cases where it is desirable to test for one library in the presence of another that is not already in LIBS. 

Since the dpendant libs are not in LIBS yet, PHP_CHECK_LIB needs to take care of either putting them there, or pushing them down into the 5th parameter of AC_CHECK_LIB. (which is not done either).
 [2009-09-25 07:20 UTC]
Where is the faulty config.m4 of yours or at least the call to the macro which you obviously did wrong. There's nothing wrong with the macro itself, it works exactly how it's supposed to..
 [2009-09-25 11:17 UTC] sven at whgl dot uni-frankfurt dot de
Here's the corresponding call from the config.m4, whre extra-libs is not placed where it should be:


      AC_DEFINE(HAVE_OMAPILIB,1,we have the DHCPCTL lib.[])
      AC_MSG_ERROR([dhcpctl lib not found.])
      -L$OMAPI_DIR/lib -lomapi -ldst
 [2009-09-25 21:42 UTC]
This macro was created as quick'n'dirty solution. And your problem is 
easily solved by simply passing the libs like this: -L$OMAPI_DIR/lib -
l$LIBNAME -lomapi -ldst

 [2009-09-25 21:43 UTC]
And as why "wont fix": There's really nothing to fix. The macro works 
just like I want it to work. Changing it would potentially cause more 
problems than solving any.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jun 29 17:04:06 2022 UTC