imagick
imagick copied to clipboard
Segmentation fault on Ubuntu 23
when I enable the Imagick extension on Ubuntu 23.04 I get segmentation fault On other distributions, the extension is working properly
root@/home/salman# /usr/local/apps/php80/bin/php -v Segmentation fault (core dumped)
if I disable the extension PHP is working properly.
What you're seeing sounds like it is peculiar to your system and the libraries on it, so it's unlikely I'll be able to provide even any insight.
If you generate a backtrace of the segmentation fault (using the instructions at https://bugs.php.net/bugs-generating-backtrace.php) I might be able to provide a bit of a clue where to look.
Thanks for reply
This may help.
(gdb) run -v The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /usr/local/apps/php81/bin/php -v [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7ad0ade in ?? () from /lib/x86_64-linux-gnu/libgomp.so.1
(gdb) bt
#0 0x00007ffff7ad0ade in ?? () from /lib/x86_64-linux-gnu/libgomp.so.1
#1 0x00007ffff7fcd33e in call_init (l=
Well, libgomp.so.1 looks to be the culprit, so it's the OpenMP that appears to be the problem.
Can you find out what version you have on the system where you're having a problem, and on the systems where you're not seeing problems? And then post that info here.
You might want to try disabling OpenMP in ImageMagick, by using the configure option --disable-openmp
when compiling it, if you just want to get stuff working.
I am getting the above issue on Ubuntu 23.04
On same system extension for PHP 7.4 is working fine but extensions for PHP 8.0, 8.1, and 8.2 give the above error.
The same php package works on Ubuntu 22 and below versions.
Don't know how to get a version of libgomp sharing the below output for ldconfig
ldconfig -p | grep libgomp
libgomp.so.1 (libc6,x86-64) => /lib64/libgomp.so.1
Hmmm.
Maybe do dpkg -l | grep libgomp
to get the exact version according to https://superuser.com/questions/690306/find-out-library-version
But if other versions of PHP are working maybe that's not the cause. Or at least not the only cause.
Can you try running PHP without any other extensions loaded or compiled in?
If I Run PHP without the imagick extension it works properly
FYI, I just ran into this libgomp issue in the middle of upgrading my Fedora 37 server to Fedora 38 server. Unfortunately I also pulled the latest imagick repo and recompiled. So I am not sure what build of imagick I was on prior and whether that will make a difference.
For now I will install PHP without imagick installed until a working version of imagick plays nicely with libgomp . FYI, the libgomp RPM version that comes with Fedora 38 is v13.2.1-4.fc38 .
@adeshmrane or @specializedtom any chance of a Dockerfile that reproduces this issue?
As you're both seeing it, there's probably a problem to be investigated, but starting with the bug in front of me is much easier than trying to guess what the problem is.
@adeshmrane or @specializedtom any chance of a Dockerfile that reproduces this issue?
As you're both seeing it, there's probably a problem to be investigated, but starting with the bug in front of me is much easier than trying to guess what the problem is.
The only other change I can think of that could of brought on this error, is that the virtual box I am running it on, now has dual processors. I didn't have to recompile my existing version of imagick to get things running (post upgrade). This is prior to updating the Linux OS from Fedora 37 to Fedora 38, which required PHP to be recompiled and linked after upgrade.
I tried adding --disable-openmp
into my configure statement, however it does not recognise it. I am using the current pulled master.
./configure --prefix=/opt/php82 --with-php-config=/opt/php82/bin/php-config --disable-openmp configure: WARNING: unrecognized options: --disable-openmp
Can multi-processor support for imagick be disabled via the PHP.INI file, seeing as it successfully compiles and links? I am trying to link imagick into a PHP 8.2.7 codebase.
@adeshmrane or @specializedtom any chance of a Dockerfile that reproduces this issue?
As you're both seeing it, there's probably a problem to be investigated, but starting with the bug in front of me is much easier than trying to guess what the problem is.
Sorry for the delay
You can replicate this by compiling php with the imagick extension and trying to load this on Ubuntu 23
without loading extension all works good but when you load extension it gives error
I see the same behavior on Ubuntu 22.04.3
This is my workaround:
- download imagick-3.7.0 source
- unpack
- cd to imagick-3.7.0
- phpize
- ./configure
- make
- make install
the last compilation action is
gcc -shared .libs/imagick_file.o .libs/imagick_class.o .libs/imagickdraw_class.o .libs/imagickpixel_class.o .libs/imagickpixeliterator_class.o .libs/imagick_helpers.o .libs/imagick.o .libs/imagickkernel_class.o .libs/shim_im6_to_im7.o -Wl,--rpath -Wl,/usr/local/pkg/gcc-13.2.0/lib/../lib64 -Wl,--rpath -Wl,/usr/local/pkg/gcc-13.2.0/lib/../lib64 /usr/local/pkg/gcc-13.2.0/lib/../lib64/libgomp.so /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so /usr/lib/x86_64-linux-gnu/libMagickCore-6.Q16.so -Wl,-soname -Wl,imagick.so -o .libs/imagick.so
With the module linked that way, php will crash.
remove /usr/local/pkg/gcc-13.2.0/lib/../lib64/libgomp.so
from the link statement (I use gccin a non-standard location - remove the link to libgomp.so) and run
gcc -shared .libs/imagick_file.o .libs/imagick_class.o .libs/imagickdraw_class.o .libs/imagickpixel_class.o .libs/imagickpixeliterator_class.o .libs/imagick_helpers.o .libs/imagick.o .libs/imagickkernel_class.o .libs/shim_im6_to_im7.o -Wl,--rpath -Wl,/usr/local/pkg/gcc-13.2.0/lib/../lib64 -Wl,--rpath -Wl,/usr/local/pkg/gcc-13.2.0/lib/../lib64 /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so /usr/lib/x86_64-linux-gnu/libMagickCore-6.Q16.so -Wl,-soname -Wl,imagick.so -o .libs/imagick.so
Copy .libs/imagick.so to your extension directory
php works again.
Hi,
I have the same problem (segmentation fault) with Ubuntu 23.04, Imagick 3.7.0 and PHP 8.3.2. Note that with Ubuntu 22.04 it works well.
Here is a Dockerfile that reproduces the issue (using asdf to install PHP and Imagick from sources):
FROM ubuntu:23.04
RUN apt update \
&& apt upgrade -y
RUN apt install -y --no-install-recommends \
git \
gdb \
build-essential \
curl wget ca-certificates \
locate \
autoconf \
bison re2c libxml2-dev libsqlite3-dev libcurl4-openssl-dev libgd-dev libonig-dev libpq-dev libreadline-dev libzip-dev \
libmagickwand-dev file
# Install asdf & PHP
SHELL [ "/bin/bash" , "-lc" ]
RUN git clone --depth=1 https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0 \
&& . ~/.asdf/asdf.sh \
# Install PHP
&& asdf plugin add php \
&& asdf install php latest \
&& asdf global php latest
# Install imagick
RUN . ~/.asdf/asdf.sh \
&& pecl install --configureoptions 'with-imagick="autodetect"' imagick
RUN echo '. "$HOME/.asdf/asdf.sh"' > ~/.bashrc
ENTRYPOINT [ "/bin/bash" ]
Build it:
docker build -t imagick-segfault .
Note that for an unknown reason building imagick sometimes works and sometimes fails with an error "Unterminated preprocessor conditions" and "ERROR: failed to solve: process "/bin/bash -lc . ~/.asdf/asdf.sh && pecl install --configureoptions 'with-imagick="autodetect"' imagick" did not complete successfully: exit code: 1" Restarting the build multiple times will make it work. Very strange error and no idea why nor if it is related with the segfault.
Run the container:
docker run -it imagick-segfault
Run PHP without imagick works:
php -v
Add imagick, and then we get a "Segmentation fault":
echo 'extension=imagick.so' >> $(asdf where php)/conf.d/php.ini
php -v
GDB:
gdb /root/.asdf/installs/php/8.3.2/bin/php
(gdb) run
Starting program: /root/.asdf/installs/php/8.3.2/bin/php
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007f8fbeb1dade in ?? () from /lib/x86_64-linux-gnu/libgomp.so.1
(gdb) bt
#0 0x00007f8fbeb1dade in ?? () from /lib/x86_64-linux-gnu/libgomp.so.1
#1 0x00007f8fc31e133e in ?? () from /lib64/ld-linux-x86-64.so.2
#2 0x00007f8fc31e1428 in ?? () from /lib64/ld-linux-x86-64.so.2
#3 0x00007f8fc31dd562 in _dl_catch_exception () from /lib64/ld-linux-x86-64.so.2
#4 0x00007f8fc31e8336 in ?? () from /lib64/ld-linux-x86-64.so.2
#5 0x00007f8fc31dd4dd in _dl_catch_exception () from /lib64/ld-linux-x86-64.so.2
#6 0x00007f8fc31e86ac in ?? () from /lib64/ld-linux-x86-64.so.2
#7 0x00007f8fc1ce011c in ?? () from /usr/lib/x86_64-linux-gnu/libc.so.6
#8 0x00007f8fc31dd4dd in _dl_catch_exception () from /lib64/ld-linux-x86-64.so.2
#9 0x00007f8fc31dd603 in ?? () from /lib64/ld-linux-x86-64.so.2
#10 0x00007f8fc1cdfbef in ?? () from /usr/lib/x86_64-linux-gnu/libc.so.6
#11 0x00007f8fc1ce01d1 in dlopen () from /usr/lib/x86_64-linux-gnu/libc.so.6
#12 0x000056373831d666 in php_load_shlib (errp=<synthetic pointer>, path=<optimized out>) at /tmp/tmp.vLVGQl9wip/php-src-php-8.3.2/ext/standard/dl.c:88
#13 php_load_extension (filename=0x7f8fbec04000 "imagick.so", type=1, start_now=0) at /tmp/tmp.vLVGQl9wip/php-src-php-8.3.2/ext/standard/dl.c:152
#14 0x00005637384139ee in zend_llist_apply (l=l@entry=0x5637394214b8 <extension_lists+56>, func=func@entry=0x5637383b95d0 <php_load_php_extension_cb>) at /tmp/tmp.vLVGQl9wip/php-src-php-8.3.2/Zend/zend_llist.c:184
#15 0x00005637383ba2d3 in php_ini_register_extensions () at /tmp/tmp.vLVGQl9wip/php-src-php-8.3.2/main/php_ini.c:751
#16 0x00005637383b2af8 in php_module_startup (sf=<optimized out>, additional_module=0x0) at /tmp/tmp.vLVGQl9wip/php-src-php-8.3.2/main/main.c:2218
#17 0x000056373805b4b9 in main (argc=1, argv=0x56373a05bb00) at /tmp/tmp.vLVGQl9wip/php-src-php-8.3.2/sapi/cli/php_cli.c:1307
Maybe related with #637, #624 and #609