Your module (libphp5.so
) is linked to two shared libraries which are providing the same symbol (in this case the symbol is iconv
and the libraries are libiconv.so.2
and probably libc.so.6
).
When this happen, the first loaded symbol is used: probably libc.so.6
gets loaded before libiconv.so.2
and thus it's the one providing you with the iconv
symbol.
You can force the dynamic loader to load a library before any other; you can do this by setting the LD_PRELOAD
environment variable to the library you want to preload.
I'm not an expert about Apache, so I'm not totally sure about how it works, how it starts its process and what processes it uses, but I think that setting LD_PRELOAD
before running apache should do the trick:
LD_PRELOAD=/usr/local/lib/libiconv.so.2
A little example to show LD_PRELOAD
in action:
Will compile myfopen.c
as a shared library (myfopen.so
): it will provide a fopen
symbol (already defined in libc
):
$ cat myfopen.c
int fopen(const char *path, const char *mode){ return -1; }
$ gcc -o libmyfopen.so myfopen.c -shared
Compiling printfopen.c
as an executable (printfopen
) which just prints the result of fopen
; will link it against both libc
and libmyfopen
(LD_LIBRARY_PATH
is needed to let the linker look for the libraries also in .
):
$ cat printfopen.c
#include <stdio.h>
int main( ) {
printf( "%d
", fopen("","") );
return 0;
}
$ gcc -o printfopen printfopen.c -L. -lmyfopen
$ LD_LIBRARY_PATH=. ldd printfopen
linux-gate.so.1 => (0xb779d000)
libmyfopen.so => ./libmyfopen.so (0xb779a000)
libc.so.6 => /lib/libc.so.6 (0xb762f000)
/lib/ld-linux.so.2 (0xb779e000)
Now I'm running it, to test if LD_PRELOAD
works:
$ LD_LIBRARY_PATH=. ./printfopen
-1
$ LD_PRELOAD=/lib/libc.so.6 LD_LIBRARY_PATH=. ./printfopen
0
$ LD_PRELOAD=libmyfopen.so LD_LIBRARY_PATH=. ./printfopen
-1
By default it loads libmyfopen
before libc
, then I tried to force loading libc
and then libmyfopen
first.
I guess that in your case libc
is getting loaded before libiconv
because the former is loaded by the application (apache?) before it loads the PHP module.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…