Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure extension is linked with -Wl,-z,nodelete #44

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
m4/** linguist-generated=true linguist-vendored=true
9 changes: 9 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
dnl $Id$
dnl config.m4 for extension vips

m4_include(m4/ax_require_defined.m4)
m4_include(m4/ax_append_flag.m4)
m4_include(m4/ax_check_link_flag.m4)
m4_include(m4/ax_append_link_flags.m4)

PHP_ARG_WITH(vips, for vips support,
[ --with-vips Include vips support])

Expand Down Expand Up @@ -35,6 +40,10 @@ if test x"$PHP_VIPS" != x"no"; then
],[$VIPS_LIBS]
)

# Mark DSO non-deletable at runtime.
# See: https://github.com/libvips/php-vips-ext/issues/43
AX_APPEND_LINK_FLAGS([-Wl,-z,nodelete])

AC_DEFINE(HAVE_VIPS, 1, [Whether you have vips])
PHP_NEW_EXTENSION(vips, vips.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 $VIPS_CFLAGS)
PHP_SUBST(VIPS_SHARED_LIBADD)
Expand Down
50 changes: 50 additions & 0 deletions m4/ax_append_flag.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions m4/ax_append_link_flags.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions m4/ax_check_link_flag.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions m4/ax_require_defined.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file role='src' name='php_vips.h'/>
<file role='src' name='vips.c'/>

<dir name="m4">
<file role='src' name='ax_append_flag.m4'/>
<file role='src' name='ax_append_link_flags.m4'/>
<file role='src' name='ax_check_link_flag.m4'/>
<file role='src' name='ax_require_defined.m4'/>
</dir>

<dir name="tests">
<file role='test' name='001.phpt'/>
<file role='test' name='002.phpt'/>
Expand Down
36 changes: 0 additions & 36 deletions vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "SAPI.h"
#include "php_vips.h"

#include <vips/vips.h>
Expand Down Expand Up @@ -2007,41 +2006,6 @@ static void php_free_gobject(zend_resource *rsrc)
*/
PHP_MINIT_FUNCTION(vips)
{
if (strcmp(sapi_module.name, "apache2handler") == 0) {
/* "apachectl graceful" can cause us terrible problems. What happens:
*
* - the main apache process unloads this extension, vips.so
* - in turn, the C runtime will unload libvips.so, the vips library,
* since vips.so is the only thing that references it
* - libvips.so in turn uses glib.so, but this is often not unloaded,
* since other parts of apache can be using it (glib could also
* possibly be preventing unload itself, I'm not sure)
* - the main apache process then reloads vips.so, which in turn will
* reload libvips.so as it starts up
* - vips.so tries to init libvips.so
* - libvips.so tries to register its types (such as VipsImage) with
* glib.so, but finds the types from the previous init still there
* - everything breaks
*
* A simple fix that will always work is just to lock libvips in
* memory and prevent unload. We intentionally leak refs to the shared
* library.
*
* We include the binary API version number that this extension needs.
* We can't just load .so, that's only installed with libvips-dev,
* which may not be present at runtime.
*/
#ifdef VIPS_SONAME
if (!dlopen(VIPS_SONAME, RTLD_LAZY | RTLD_NODELETE))
#else /*!VIPS_SONAME*/
if (!dlopen("libvips.so.42", RTLD_LAZY | RTLD_NODELETE))
#endif /*VIPS_SONAME*/
{
sapi_module.sapi_error(E_WARNING, "php-vips-ext: unable to lock "
"libvips -- graceful may be unreliable");
}
}

/* If you have INI entries, uncomment these lines
REGISTER_INI_ENTRIES();
*/
Expand Down