php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45740 Fileinfo/libmagic linking fails with undefined symbol .asprintf/.vasprintf
Submitted: 2008-08-07 07:15 UTC Modified: 2008-09-10 00:57 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: Bjorn dot Wiberg at its dot uu dot se Assigned: derick (profile)
Status: Closed Package: Compile Failure
PHP Version: 5.3CVS-2008-08-07 (snap) OS: IBM AIX 5.3 5300-08-01-0819
Private report: No CVE-ID: None
 [2008-08-07 07:15 UTC] Bjorn dot Wiberg at its dot uu dot se
Description:
------------
Linking failure referring to undefined symbols ".vasprintf" and ".asprintf".

Looking in ext/fileinfo/libmagic indicates that those functions are used in funcs.c and softmagic.c.

Googling indicates that asprintf() and vasprintf() require stdio.h and linking against the C library (-lc).

Reproduce code:
---------------
#! /bin/sh
#
# Created by configure

LDFLAGS='-Wl,-bbigtoc' \
CC='gcc' \
'./configure' \
'--enable-bcmath' \
'--enable-calendar' \
'--enable-cli' \
'--enable-dba' \
'--enable-dbase' \
'--enable-debug' \
'--enable-exif' \
'--enable-flatfile' \
'--enable-ftp' \
'--enable-gd-jis-conv' \
'--enable-gd-native-ttf' \
'--enable-inifile' \
'--enable-mbstring' \
'--enable-pcntl' \
'--enable-shmop' \
'--enable-soap' \
'--enable-sockets' \
'--enable-sqlite-utf8' \
'--enable-sysvmsg' \
'--enable-sysvsem' \
'--enable-sysvshm' \
'--enable-wddx' \
'--enable-zip' \
'--enable-zend-multibyte' \
'--prefix=/apache/php' \
'--with-apxs2=/apache/bin/apxs' \
'--with-bz2' \
'--with-cdb' \
'--with-curl' \
'--with-freetype-dir' \
'--with-gd' \
'--with-gdbm' \
'--with-gettext' \
'--with-jpeg-dir' \
'--with-ldap' \
'--with-libxml-dir=/usr/local' \
'--with-mime-magic' \
'--with-mysql=mysqlnd' \
'--with-mysqli=mysqlnd' \
'--with-openssl=/opt/freeware' \
'--with-pdo-mysql=mysqlnd' \
'--with-png-dir' \
'--with-xmlrpc' \
'--with-xpm-dir' \
'--with-xsl' \
'--with-zlib' \
'--with-zlib-dir' \
"$@"

(GNU) make

Expected result:
----------------
Successful compilation/linking.

Actual result:
--------------
---8<--- excerpt ---8<---
2/usr/lib -L/gestconf/project/GNOME_ACL/GNOME/build/M_acc_gnome2_12_0f1/export/power_510_32/usr/lib -L/gestconf/project/GNOME_ACL/GNOME/build/acc_gnome2_12_0f1/export/power_510_32/usr/lib -L/gestconf/project/GNOME_ACL/GNOME/build/GNOME_2_12_0/export/power_510_32/usr/lib -lz -lX11 -lXpm -lpng -L/gestconf/project/GNOME_ACL/GNOME/build/BLD_M_gnome2_14f1/export/power_510_32/usr/lib -L/gestconf/project/GNOME_ACL/GNOME/build/M_acc_gnome2_14_0f1/export/power_510_32/usr/lib -L/gestconf/project/GNOME_ACL/GNOME/build/acc_gnome2_14_0f1/export/power_510_32/usr/lib -L/gestconf/project/GNOME_ACL/GNOME/build/GNOME_2_14_0/export/power_510_32/usr/lib -L/users/project/PDP/PDP_51_vac_6_14/usr/ccs/lib -L/users/project/PDP/PDP_51_vac_6_14/usr/lib -lz -lm -lz -ljpeg -lssl -lcrypto -lgdbm -lbz2 -lz -lssl -lcrypto -lm -lz -liconv -lm -lcurl -lssl -lcrypto -lz -lssl -lcrypto -lz -lz -liconv -lm -lz -liconv -lm -lz -liconv -lm -lz -liconv -lm -lz -liconv -lm -lz -liconv -lm -lz -liconv -lm -lz -liconv -lm -lxslt -lz -liconv -lm -lxml2 -lpthread -lz -liconv -lm -lz -liconv -lm -Wl,-blibpath:/usr/local/lib:/opt/freeware/lib:/usr/X11R6/lib:/opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.0.0:/opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.0.0/../../..:/usr/lib:/lib 
ld: 0711-224 WARNING: Duplicate symbol: php_optidx
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
ld: 0711-317 ERROR: Undefined symbol: .vasprintf
ld: 0711-317 ERROR: Undefined symbol: .asprintf
collect2: ld returned 8 exit status
make: *** [sapi/cli/php] Error 1
Bad exit status from /var/opt/freeware/tmp/rpm-tmp.2294 (%build)
-->8--- end excerpt --->8---

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-07 13:38 UTC] Bjorn dot Wiberg at its dot uu dot se
A small sidenote: I'm not sure which libmagic PHP is using; the libmagic I have tried separately (on AIX) is the one from ftp://ftp.astron.com/pub/file/ ("The file(1) command and libmagic(3) library"), and I don't recall encountering anything like this with that one.
 [2008-08-07 22:07 UTC] jani@php.net
FYI: We have a bundled libmagic. Whatever you have in your system has nothing to with this.
 [2008-08-07 22:09 UTC] jani@php.net
Of course since you have also enabled the old deprecated mime magic extension, it will cause linking with the external libmagic too..
 [2008-08-08 05:17 UTC] Bjorn dot Wiberg at its dot uu dot se
The old mime_magic extension has, to my knowledge, never required nor used libmagic. We "converted" to Fileinfo and libmagic about half a year ago. Prior to that, we only used mime_magic. I plan on removing the mime_magic flag after alpha2 is released (as, if I interpret the road map correctly, some "last" function needed to cover up for mime_magic will be available then).

Regarding the bundled libmagic, my (sidenote) question was whether the bundled one was another libmagic library than the one I pointed out (in case there are several implementations with a similar name). I know that my "separate" libmagic won't be used and that it has nothing (else) to do with the bundled one.

The bug report is only about asprintf and vasprintf. There are some HAVE_ASPRINTF defines (something like that) in the bundled source and I guess that something is wrong there, i.e., that those are set without asprintf or vasprintf being available. Or that some configure check has detected that those are available but that the bundled libmagic does not include all needed headers and does not link with the C library as the man pages for asprintf/vasprintf indicate.

On the other hand, those man pages also say that those functions are a GNU feature, so that they might not be available on all platforms. Which is why the HAVE_ASPRINTF stuff appears important...

I'm thankful for you looking into this. We're close to the goal now, i.e. successful compilation, even though I know that AIX may sound obscure to some. ;-)

Best regards,
Bj?rn
 [2008-08-10 20:26 UTC] tony2001@php.net
Here is a patch that fixes *sprintf() compile issues:
http://dev.daylessday.org/diff/magic_sprintf.diff

Though it still segfault both on Linux (in regfree()) and AIX (see bt below):
(gdb) r -r '$r = finfo_open(); var_dump(finfo_file($r, "stub.c"));'
Starting program: /fastemp/tony/5_3/sapi/cli/php -r '$r = finfo_open(); var_dump(finfo_file($r, "stub.c"));'

Program received signal SIGSEGV, Segmentation fault.
0x10341ee4 in bs1 (m=0x103eda68) at /fastemp/tony/5_3/ext/fileinfo/libmagic/apprentice.c:2159
2159            m->cont_level = swap2(m->cont_level);
(gdb) bt
#0  0x10341ee4 in bs1 (m=0x103eda68) at /fastemp/tony/5_3/ext/fileinfo/libmagic/apprentice.c:2159
#1  0x10341c24 in byteswap (magic=0x103eda68, nmagic=8476) at /fastemp/tony/5_3/ext/fileinfo/libmagic/apprentice.c:2089
#2  0x10341838 in apprentice_map (ms=0x201a1ad8, magicp=0x2ff22008, nmagicp=0x2ff2200c, fn=0x0)
    at /fastemp/tony/5_3/ext/fileinfo/libmagic/apprentice.c:1988
#3  0x1033c570 in apprentice_1 (ms=0x201a1ad8, fn=0x0, action=0, mlist=0x201a1bf8) at /fastemp/tony/5_3/ext/fileinfo/libmagic/apprentice.c:277
#4  0x1033c8d0 in file_apprentice (ms=0x201a1ad8, fn=0x0, action=0) at /fastemp/tony/5_3/ext/fileinfo/libmagic/apprentice.c:358
#5  0x1033b8c0 in magic_load (ms=0x201a1ad8, magicfile=0x0) at /fastemp/tony/5_3/ext/fileinfo/libmagic/magic.c:178
#6  0x1033a848 in zif_finfo_open (ht=0, return_value=0x20065178, return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
    at /fastemp/tony/5_3/ext/fileinfo/fileinfo.c:341
#7  0x10099bfc in zend_do_fcall_common_helper_SPEC (execute_data=0x201619b8) at /fastemp/tony/5_3/Zend/zend_vm_execute.h:315
#8  0x1009ef74 in ZEND_DO_FCALL_SPEC_CONST_HANDLER (execute_data=0x201619b8) at /fastemp/tony/5_3/Zend/zend_vm_execute.h:1569
#9  0x10098e3c in execute (op_array=0x200658cc) at /fastemp/tony/5_3/Zend/zend_vm_execute.h:65
#10 0x100379a4 in zend_eval_string (str=0x2ff22bf2 "$r = finfo_open(); var_dump(finfo_file($r, \"stub.c\"));", retval_ptr=0x0,
    string_name=0x10366fb8 "Command line code") at /fastemp/tony/5_3/Zend/zend_execute_API.c:1111
#11 0x10037be0 in zend_eval_string_ex (str=0x2ff22bf2 "$r = finfo_open(); var_dump(finfo_file($r, \"stub.c\"));", retval_ptr=0x0,
    string_name=0x10366fb8 "Command line code", handle_exceptions=1) at /fastemp/tony/5_3/Zend/zend_execute_API.c:1146
#12 0x10002d40 in main (argc=3, argv=0x2ff22b44) at /fastemp/tony/5_3/sapi/cli/php_cli.c:1194

 [2008-09-10 00:57 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 14:01:30 2024 UTC