php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19937 dynamic extension loading fails
Submitted: 2002-10-16 12:25 UTC Modified: 2003-07-18 18:49 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: ryan dot smith at openwave dot com Assigned:
Status: No Feedback Package: Dynamic loading
PHP Version: 4.3.0-dev OS: AIX 5.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ryan dot smith at openwave dot com
New email:
PHP Version: OS:

 

 [2002-10-16 12:25 UTC] ryan dot smith at openwave dot com
Attempting to dynamically load a module fails under AIX. The error message is:
PHP Warning:  Unable to load dynamic library '/usr/HTTPServer/libexec/firstmod.so' - Invalid argument in Unknown on line 0

This indicates that the failure occurs during the DL_LOAD.
The module does exist, and can be loaded with dlopen() in a test program.  PHP is being loaded as a dynamic module within the IBM HTTP server (based on Apache 1.3.12).

PHP was configured with:
CC='cc_r' \
CXX='xlC_r -E' \
'./configure' \
'--enable-c9x-inline' \
'--enable-shared' \
'--with-apxs=/usr/HTTPServer/bin/apxs' \
'--without-mysql' \
'--with-ldap=/users/rysmith/apache/openldap-2.0.25_AIX'

I've tried compiling the module in many ways:
(Simple)
cc -c test2.c
cc -G -o firstmod.so test2.o

(from sample IBM DSO makefile)
xlC_r -c   -I /users/rysmith/apache/php-4.2.3/Zend -I /users/rysmith/apache/php-4.2.3 -I/users/rysmith/apache/php-4.2.3/main -I/users/rysmith/apache/php-4.2.3/TSRM  -DAIX=42 -U__STR__ -DAIX_BIND_PROCESSOR -DUSE_HSREGEX -O2 -DSHARED_MODULE firstmod.c && mv firstmod.o firstmod.lo
ld -H512 -T512 -bhalt:4 -bM:SRE -bnoentry -bI:/users/rysmith/apache/php-4.2.3/ext/ryan/libphp4.exp -bE:`echo firstmod.so|sed -e 's:\.so$:.exp:'` -lc -o firstmod.so firstmod.lo 

Attempting to load the module from within a PHP script also fails in the same way.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-16 13:46 UTC] ryan dot smith at openwave dot com
I've additionally tried compiling the provided ldap extension as a shared object, using the PHP build system, but that fails to load as well.
 [2002-10-18 16:25 UTC] sniper@php.net
Exactly which module doesn't load? libphp4.so into apache?
Or some shared extension into PHP?
And why do you set 'CC' and 'CXX' before running configure?
Why do you pass configure '--enable-shared' ??


 [2002-10-18 16:35 UTC] ryan dot smith at openwave dot com
No, the libphp4.so loads fine into apache.  It's the PHP extensions which PHP loads, which do not load.  For example, ldap.  Or the sample module in the documentation.

I set CC and CXX so that I use the IBM compiler and not gcc.

(Although if I try with gcc, I get a core dump when the extensions load).
 [2002-10-18 16:47 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-10-18 17:53 UTC] ryan dot smith at openwave dot com
I just tried the latest snapshot, and it fails in the same way.  Note that I am using the ldap extension to test this, so my configuration differs slight - it has --with-ldap=shared,/users/rysmith/apache/openldap-2.0.25_AIX
 [2002-10-19 10:48 UTC] sniper@php.net
How exactly did you configure the loading of the extension
in php.ini ? 

 [2002-10-21 10:28 UTC] ryan dot smith at openwave dot com
By specifying an extension path and then the extension:

extension_dir=/usr/HTTPServer/libexec
extension=libldap.so

If you (or anyone) has a PHP setup that does demonstrate that this functionality works, I'd like to know.
 [2003-05-02 06:51 UTC] francois dot turi at globecast dot com
The following patch should fix problem of loading extension under AIX 4.3.3 like the java extension.

Under AIX, shared object are different from shared library.
The default library construction (as in the construction of
the JAVA extension) doesnt work correctly as it relies on dynamic linking from a library when only a shared object is given.
An exception appear as illegal instruction.

The following configuration are missing:

First of all:
=============
 one should construct correctly the export definition of libphp4.so.
In configure the following line should be changed:

********************************
diff configure configure.orig (sorry no -b available under AIX)
78084,78086c78084
< # FTU export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | sed '\''s/.* //'\'' | sort | uniq > $export_symbols'
< export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | sed '\''s/.* //'\'' | sort | uniq|awk -vlib=$SOHOME/$soname
 '\''BEGIN{printf "#!%s\n",lib}{print \$0}'\'' > $export_symbols'
< echo "FTU export_symbols_cmds=$export_symbols_cmds"
---
> export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | sed '\''s/.* //'\'' | sort | uniq > $export_symbols'
***************************


I added awk -vlib=$SOHOME/$soname 
 '\''BEGIN{printf "#!%s\n",lib}{print \$0}'\'' 
To the pipe so the first line will be read as:
#!/your/path/to/your/libphp4.so

And the rest is identical.
Before compiling your library you should setup the SOHOME variable as the path where your shared object (libphp4.so.0) will be running:

************
 export SOHOME=/s00/opendata/build/SSOD/php.430/current
************

Second important point:
========================
Refer the export file of php shared object in the construction of the java extension:
When compiling the JAVA extension you have to setup the following environement VARIABLE

*****************
export JAVA_SHARED_LIBADD="-Wl,-bI:.libs/libphp4.exp"
*****************

That line state that in the linking process (ld), the java extension will use the libphp4.exp file to find undefined function or global variable. By defaut such function will be resolve as running time.
On AIX such binding doesnt work because the libphp4.so is not a shared library (doesnt appear in the genmkd listing) but a share object.
You have to specify the full path to your share object while linking it to make him resolve correctly the reference to the Zend API.


Nota: the default exemple given to make an extension doesnt have that problem because it doesnt call any Zend API function stored in the libphp4.so.

External reference:
The followings redbooks explain the subtle difference between share objects and shared library under AIX:
Understanding C and C++ development on AIX
chapter 3 Compiling and Linking

original
http://www.redbooks.ibm.com/pubs/pdfs/redbooks/sg245674.pdf

latest draft (for 5.L)
http://www.redbooks.ibm.com/redpieces/pdfs/sg245674.pdf


Last point:
===========
The extension java should be rename after construction to 

cp -p  libjava.so.0  libphp_java.so

to work correctly.


About libtool:
==============

The first line in configure change the libtool which is in charge of creating the dynamic library. I cannot figure out if the bug is a php bug or a libtool bug.
 [2003-07-10 18:05 UTC] sniper@php.net
Could you try this patch:

Index: zend.h
===================================================================
RCS file: /repository/Zend/Attic/zend.h,v
retrieving revision 1.164.2.8
diff -u -r1.164.2.8 zend.h
--- zend.h      31 May 2003 01:37:43 -0000      1.164.2.8
+++ zend.h      10 Jul 2003 23:05:38 -0000
@@ -89,7 +89,11 @@
 #  define RTLD_GLOBAL 0
 # endif
 
-# define DL_LOAD(libname)                      dlopen(libname, RTLD_LAZY | RTLD_GLOBAL)
+# ifndef RTLD_PARENT
+#  define RTLD_PARENT 0
+# endif
+
+# define DL_LOAD(libname)                      dlopen(libname, RTLD_LAZY | RTLD_GLOBAL | RTLD_PARENT)
 # define DL_UNLOAD                                     dlclose
 # if DLSYM_NEEDS_UNDERSCORE
 #  define DL_FETCH_SYMBOL(h,s)         dlsym((h), "_" s)

 [2003-07-10 18:08 UTC] sniper@php.net
Here's an url to it:

http://www.php.net/~jani/dlopen_patch.txt

 [2003-07-18 18:49 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2006-04-21 07:04 UTC] jens_0 at hotmail dot com
Same thing here with Apache/1.3.31 (Unix)  PHP/4.0.6 using HP-UX or AIX concening libgd.so.
The extension won't load:
PHP Warning:  Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts/libgd.so' - Invalid argument in Unknown on line 0
 [2008-09-23 11:57 UTC] eilaf_mugbil at hotmail dot com
eilaf
 [2009-05-02 05:37 UTC] <span>nothanks at example dot com</span>
<b>Thanks</b> for this!
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 20:03:37 2021 UTC