Skip to content

Commit c9c7b5b

Browse files
authored
Merge pull request #44 from kleisauke/z_nodelete
Ensure extension is linked with `-Wl,-z,nodelete`
2 parents 04be18b + f08dc82 commit c9c7b5b

8 files changed

+201
-36
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
m4/** linguist-generated=true linguist-vendored=true

config.m4

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
dnl $Id$
22
dnl config.m4 for extension vips
33

4+
m4_include(m4/ax_require_defined.m4)
5+
m4_include(m4/ax_append_flag.m4)
6+
m4_include(m4/ax_check_link_flag.m4)
7+
m4_include(m4/ax_append_link_flags.m4)
8+
49
PHP_ARG_WITH(vips, for vips support,
510
[ --with-vips Include vips support])
611

@@ -35,6 +40,10 @@ if test x"$PHP_VIPS" != x"no"; then
3540
],[$VIPS_LIBS]
3641
)
3742

43+
# Mark DSO non-deletable at runtime.
44+
# See: https://github.com/libvips/php-vips-ext/issues/43
45+
AX_APPEND_LINK_FLAGS([-Wl,-z,nodelete])
46+
3847
AC_DEFINE(HAVE_VIPS, 1, [Whether you have vips])
3948
PHP_NEW_EXTENSION(vips, vips.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 $VIPS_CFLAGS)
4049
PHP_SUBST(VIPS_SHARED_LIBADD)

m4/ax_append_flag.m4

+50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

m4/ax_append_link_flags.m4

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

m4/ax_check_link_flag.m4

+53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

m4/ax_require_defined.m4

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.xml

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
4444
<file role='src' name='vips.stub.php'/>
4545
<file role='src' name='vips_arginfo.h'/>
4646

47+
<dir name="m4">
48+
<file role='src' name='ax_append_flag.m4'/>
49+
<file role='src' name='ax_append_link_flags.m4'/>
50+
<file role='src' name='ax_check_link_flag.m4'/>
51+
<file role='src' name='ax_require_defined.m4'/>
52+
</dir>
53+
4754
<dir name="tests">
4855
<file role='test' name='001.phpt'/>
4956
<file role='test' name='002.phpt'/>

vips.c

-36
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "php.h"
1414
#include "php_ini.h"
1515
#include "ext/standard/info.h"
16-
#include "SAPI.h"
1716
#include "php_vips.h"
1817

1918
#include <vips/vips.h>
@@ -2045,41 +2044,6 @@ static void php_free_gobject(zend_resource *rsrc)
20452044
*/
20462045
PHP_MINIT_FUNCTION(vips)
20472046
{
2048-
if (strcmp(sapi_module.name, "apache2handler") == 0) {
2049-
/* "apachectl graceful" can cause us terrible problems. What happens:
2050-
*
2051-
* - the main apache process unloads this extension, vips.so
2052-
* - in turn, the C runtime will unload libvips.so, the vips library,
2053-
* since vips.so is the only thing that references it
2054-
* - libvips.so in turn uses glib.so, but this is often not unloaded,
2055-
* since other parts of apache can be using it (glib could also
2056-
* possibly be preventing unload itself, I'm not sure)
2057-
* - the main apache process then reloads vips.so, which in turn will
2058-
* reload libvips.so as it starts up
2059-
* - vips.so tries to init libvips.so
2060-
* - libvips.so tries to register its types (such as VipsImage) with
2061-
* glib.so, but finds the types from the previous init still there
2062-
* - everything breaks
2063-
*
2064-
* A simple fix that will always work is just to lock libvips in
2065-
* memory and prevent unload. We intentionally leak refs to the shared
2066-
* library.
2067-
*
2068-
* We include the binary API version number that this extension needs.
2069-
* We can't just load .so, that's only installed with libvips-dev,
2070-
* which may not be present at runtime.
2071-
*/
2072-
#ifdef VIPS_SONAME
2073-
if (!dlopen(VIPS_SONAME, RTLD_LAZY | RTLD_NODELETE))
2074-
#else /*!VIPS_SONAME*/
2075-
if (!dlopen("libvips.so.42", RTLD_LAZY | RTLD_NODELETE))
2076-
#endif /*VIPS_SONAME*/
2077-
{
2078-
sapi_module.sapi_error(E_WARNING, "php-vips-ext: unable to lock "
2079-
"libvips -- graceful may be unreliable");
2080-
}
2081-
}
2082-
20832047
/* If you have INI entries, uncomment these lines
20842048
REGISTER_INI_ENTRIES();
20852049
*/

0 commit comments

Comments
 (0)