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

Segmentation fault on Ubuntu 23 #636

Open
adeshmrane opened this issue Oct 19, 2023 · 12 comments
Open

Segmentation fault on Ubuntu 23 #636

adeshmrane opened this issue Oct 19, 2023 · 12 comments

Comments

@adeshmrane
Copy link

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.

@Danack
Copy link
Collaborator

Danack commented Oct 24, 2023

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.

@adeshmrane
Copy link
Author

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=, argc=argc@entry=2, argv=argv@entry=0x7fffffffe518, env=env@entry=0x14342b0) at ./elf/dl-init.c:70
#2 0x00007ffff7fcd428 in call_init (env=0x14342b0, argv=0x7fffffffe518, argc=2, l=) at ./elf/dl-init.c:33
#3 _dl_init (main_map=0x1518820, argc=2, argv=0x7fffffffe518, env=0x14342b0) at ./elf/dl-init.c:117
#4 0x00007ffff7fc9562 in _GI_dl_catch_exception (exception=exception@entry=0x0, operate=operate@entry=0x7ffff7fd4280 <call_dl_init>, args=args@entry=0x7fffffffcbe0)
at ./elf/dl-catch.c:211
#5 0x00007ffff7fd4336 in dl_open_worker (a=0x7fffffffcd80) at ./elf/dl-open.c:808
#6 dl_open_worker (a=a@entry=0x7fffffffcd80) at ./elf/dl-open.c:771
#7 0x00007ffff7fc94dd in _GI_dl_catch_exception (exception=exception@entry=0x7fffffffcd60, operate=operate@entry=0x7ffff7fd42a0 <dl_open_worker>, args=args@entry=0x7fffffffcd80)
at ./elf/dl-catch.c:237
#8 0x00007ffff7fd46ac in _dl_open (file=0x7ffff5e09000 "/usr/local/apps/php81/ext/imagick.so", mode=, caller_dlopen=0x5c5ed3 <php_load_shlib+19>, nsid=,
argc=2, argv=0x7fffffffe518, env=0x14342b0) at ./elf/dl-open.c:884
#9 0x00007ffff608b11c in dlopen_doit (a=a@entry=0x7fffffffcff0) at ./dlfcn/dlopen.c:56
#10 0x00007ffff7fc94dd in _GI_dl_catch_exception (exception=exception@entry=0x7fffffffcf50, operate=0x7ffff608b0c0 <dlopen_doit>, args=0x7fffffffcff0) at ./elf/dl-catch.c:237
#11 0x00007ffff7fc9603 in _dl_catch_error (objname=0x7fffffffcfa8, errstring=0x7fffffffcfb0, mallocedp=0x7fffffffcfa7, operate=, args=)
at ./elf/dl-catch.c:256
#12 0x00007ffff608abef in _dlerror_run (operate=operate@entry=0x7ffff608b0c0 <dlopen_doit>, args=args@entry=0x7fffffffcff0) at ./dlfcn/dlerror.c:138
#13 0x00007ffff608b1d1 in dlopen_implementation (dl_caller=, mode=, file=) at ./dlfcn/dlopen.c:71
#14 ___dlopen (file=, mode=) at ./dlfcn/dlopen.c:81
#15 0x00000000005c5ed3 in php_load_shlib (path=, errp=0x7fffffffd080) at /setups/php-8.1.22/ext/standard/dl.c:88
#16 0x00000000005c5f7a in php_load_extension (filename=0x7ffff5e01190 "imagick.so", type=1, start_now=0) at /setups/php-8.1.22/ext/standard/dl.c:152
#17 0x000000000068494e in zend_llist_apply (l=l@entry=0x141ab58 <extension_lists+56>, func=func@entry=0x633960 <php_load_php_extension_cb>) at /setups/php-8.1.22/Zend/zend_llist.c:184
#18 0x0000000000634572 in php_ini_register_extensions () at /setups/php-8.1.22/main/php_ini.c:761
#19 0x000000000062e0d9 in php_module_startup (sf=, additional_modules=additional_modules@entry=0x0, num_additional_modules=num_additional_modules@entry=0)
at /setups/php-8.1.22/main/main.c:2259
#20 0x0000000000767b8d in php_cli_startup (sapi_module=) at /setups/php-8.1.22/sapi/cli/php_cli.c:409
#21 0x00000000004467a4 in main (argc=2, argv=0x1434de0) at /setups/php-8.1.22/sapi/cli/php_cli.c:1334

@Danack
Copy link
Collaborator

Danack commented Oct 24, 2023

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.

@adeshmrane
Copy link
Author

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

@Danack
Copy link
Collaborator

Danack commented Oct 25, 2023

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?

@adeshmrane
Copy link
Author

If I Run PHP without the imagick extension it works properly

@specializedtom
Copy link

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 .

@Danack
Copy link
Collaborator

Danack commented Nov 12, 2023

@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.

@specializedtom
Copy link

@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
Copy link
Author

@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

@valerioa
Copy link

valerioa commented Dec 20, 2023

I see the same behavior on Ubuntu 22.04.3

This is my workaround:

  1. download imagick-3.7.0 source
  2. unpack
  3. cd to imagick-3.7.0
  4. phpize
  5. ./configure
  6. make
  7. 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.

@Bacto
Copy link

Bacto commented Jan 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants