Skip to content

Commit f08dc82

Browse files
committedSep 6, 2021
Ensure extension is linked with -Wl,-z,nodelete
See: #43.
1 parent 310b029 commit f08dc82

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
@@ -42,6 +42,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
4242
<file role='src' name='php_vips.h'/>
4343
<file role='src' name='vips.c'/>
4444

45+
<dir name="m4">
46+
<file role='src' name='ax_append_flag.m4'/>
47+
<file role='src' name='ax_append_link_flags.m4'/>
48+
<file role='src' name='ax_check_link_flag.m4'/>
49+
<file role='src' name='ax_require_defined.m4'/>
50+
</dir>
51+
4552
<dir name="tests">
4653
<file role='test' name='001.phpt'/>
4754
<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>
@@ -2007,41 +2006,6 @@ static void php_free_gobject(zend_resource *rsrc)
20072006
*/
20082007
PHP_MINIT_FUNCTION(vips)
20092008
{
2010-
if (strcmp(sapi_module.name, "apache2handler") == 0) {
2011-
/* "apachectl graceful" can cause us terrible problems. What happens:
2012-
*
2013-
* - the main apache process unloads this extension, vips.so
2014-
* - in turn, the C runtime will unload libvips.so, the vips library,
2015-
* since vips.so is the only thing that references it
2016-
* - libvips.so in turn uses glib.so, but this is often not unloaded,
2017-
* since other parts of apache can be using it (glib could also
2018-
* possibly be preventing unload itself, I'm not sure)
2019-
* - the main apache process then reloads vips.so, which in turn will
2020-
* reload libvips.so as it starts up
2021-
* - vips.so tries to init libvips.so
2022-
* - libvips.so tries to register its types (such as VipsImage) with
2023-
* glib.so, but finds the types from the previous init still there
2024-
* - everything breaks
2025-
*
2026-
* A simple fix that will always work is just to lock libvips in
2027-
* memory and prevent unload. We intentionally leak refs to the shared
2028-
* library.
2029-
*
2030-
* We include the binary API version number that this extension needs.
2031-
* We can't just load .so, that's only installed with libvips-dev,
2032-
* which may not be present at runtime.
2033-
*/
2034-
#ifdef VIPS_SONAME
2035-
if (!dlopen(VIPS_SONAME, RTLD_LAZY | RTLD_NODELETE))
2036-
#else /*!VIPS_SONAME*/
2037-
if (!dlopen("libvips.so.42", RTLD_LAZY | RTLD_NODELETE))
2038-
#endif /*VIPS_SONAME*/
2039-
{
2040-
sapi_module.sapi_error(E_WARNING, "php-vips-ext: unable to lock "
2041-
"libvips -- graceful may be unreliable");
2042-
}
2043-
}
2044-
20452009
/* If you have INI entries, uncomment these lines
20462010
REGISTER_INI_ENTRIES();
20472011
*/

0 commit comments

Comments
 (0)
Please sign in to comment.