#49648 [NEW]: Broken Macro in acinclude.m4

From: Date: Thu, 24 Sep 2009 03:59:13 +0000
Subject: #49648 [NEW]: Broken Macro in acinclude.m4
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-142800@lists.php.net to get a copy of this message
From:             sven at whgl dot uni-frankfurt dot de
Operating system: Linux
PHP version:      5.2.11
PHP Bug Type:     Unknown/Other Function
Bug description:  Broken Macro in acinclude.m4

Description:
------------
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:
http://svn.php.net/viewvc/php/php-src/trunk/acinclude.m4?revision=287126&view=markup

--- 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:

1827 	AC_DEFUN([PHP_CHECK_LIBRARY], [
1828 	save_old_LDFLAGS=$LDFLAGS
1829 	ac_stuff="$5"
1830 	
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.

-- 
Edit bug report at http://bugs.php.net/?id=49648&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=49648&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=49648&r=trysnapshot53
Try a snapshot (PHP 6.0):            http://bugs.php.net/fix.php?id=49648&r=trysnapshot60
Fixed in SVN:                        http://bugs.php.net/fix.php?id=49648&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49648&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=49648&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=49648&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=49648&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=49648&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=49648&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=49648&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=49648&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=49648&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=49648&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49648&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49648&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=49648&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=49648&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=49648&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=49648&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=49648&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#142800) next »