Open DubbleClick opened 10 months ago
To set your expectations, I'm probably only going to be able to point you where to look, rather than investigate it for you, as:
Using the php-cli binary that was generated with the same ./php-src/configure command works with no problems.
that's pretty much how the library is meant to be used.
So, you'll need to step through the thing that is actually segafaulting:
0 GetPolicyInfo (name=name@entry=0x7ffff6b877e3 "cache:synchronize", exception=exception@entry=0x7fffad004eb0)
at MagickCore/policy.c:301
1 0x00007ffff622b1ae in GetPolicyValue (name=name@entry=0x7ffff6b877e3 "cache:synchronize")
at MagickCore/policy.c:565
Which, in the current version of ImageMagick looks like this.
I'm guessing the segfault is in LockSemaphoreInfo(). The fundamental problem you're probably seeing is ImageMagick makes assumptions about it being run in a single threaded environment, and that it will manage it's own threading/forking.
Probably what's happening is that just some assumption in the code is not valid, and so....segfaults.
I'd suggest:
Stepping through the code and finding where the actual error is, contemplating what it's doing, and then summarising that here.
Test the behaviour with OpenMP support both enabled and disabled, and with threading set to 1 or more than one. One of those options may work better than the others.
Question why you want to do this....For the record, I am "not sure" that Imagick should be run on a publicly accessible server. It's way safer to run it separately as a background job. And that also stops any problem in Imagick from affecting the other requests being processed.
Anyway, will be interested to see what you find out.
Thank you for the reply!
As an unfortunate addition to 1), using slightly different code unfortunately crashes in different parts of cache.c, so I'm not entirely sure it's related.
Thread 13 "frankenphp" hit Breakpoint 5, GetPolicyInfo (name=name@entry=0x5d1da1b "*",
exception=exception@entry=0x7fffb0791c10) at MagickCore/policy.c:301
301 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
(gdb) c
Continuing.
Thread 13 "frankenphp" hit Breakpoint 5, GetPolicyInfo (name=name@entry=0x5d1da1b "*",
exception=exception@entry=0x7fffb0791b50) at MagickCore/policy.c:301
301 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
(gdb) c
Continuing.
Thread 13 "frankenphp" hit Breakpoint 5, GetPolicyInfo (name=name@entry=0x5d7acf3 "cache:synchronize",
exception=exception@entry=0x7fffb0791bd0) at MagickCore/policy.c:301
301 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
(gdb) s
Thread 13 "frankenphp" received signal SIGSEGV, Segmentation fault.
GetPolicyInfo (name=name@entry=0x5d7acf3 "cache:synchronize", exception=exception@entry=0x7fffb0791bd0)
at MagickCore/policy.c:301
301 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
(gdb) s
Thread 13 "frankenphp" hit Breakpoint 5, GetPolicyInfo (name=name@entry=0x5d7acf3 "cache:synchronize",
exception=exception@entry=0x7fffb0791bd0) at MagickCore/policy.c:301
301 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
(gdb) s
Thread 13 "frankenphp" received signal SIGSEGV, Segmentation fault.
GetPolicyInfo (name=name@entry=0x5d7acf3 "cache:synchronize", exception=exception@entry=0x7fffb0791bd0)
at MagickCore/policy.c:301
301 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
(gdb) s
Couldn't get registers: No such process.
Couldn't get registers: No such process.
Seems to segfault right on the function call, can't even step into it like I could with the previous calls to IsPolicyCacheInstanciated()
.
Maybe it's possible that IsPolicyCacheInstantiated
has actually been inlined?
That bit of code is passing when name is "*" and failing when it's "cache:synchronize". Can you run it again, get the code to that line with name being "cache:synchronize" and then:
i. Print out the backtrace with the command 'bt'.
ii. Print out the registers with 'i r' apparently https://bob.cs.sonoma.edu/IntroCompOrg-RPi/sec-gdb2.html
iii. Switch to an assembly view https://stackoverflow.com/questions/1902901/show-current-assembly-instruction-in-gdb
And then copy+paste those to here....not sure they'll actually provide any info, but they might.
Actually, probably even simpler, maybe recompile ImageMagick with some printf's before each of the lines in the function IsPolicyCacheInstantiated as that can be a quicker way of finding out exactly where a fault occurs.
I usually use something like:
./configure --with-quantum-depth=16 \
--with-magick-plus-plus=no \
--without-perl \
--disable-docs \
--with-openexr=yes \
--with-fontconfig=yes \
--with-fftw \
--with-heic=yes \
--with-jpeg=yes \
--with-png=yes \
--with-tiff=yes \
--with-urw-base35-font-dir=/usr/share/fonts/type1/urw-base35 \
--with-webp=yes
to configure ImageMagick.
Maybe it's possible that
IsPolicyCacheInstantiated
has actually been inlined?
Hmm, it shouldn't get inlined with -O0, but I can disable inlining to make sure. And add some prints.
That bit of code is passing when name is "*" and failing when it's "cache:synchronize". Can you run it again, get the code to that line with name being "cache:synchronize" and then:
i. Print out the backtrace with the command 'bt'.
Same backtrace as above.
ii. Print out the registers with 'i r' apparently https://bob.cs.sonoma.edu/IntroCompOrg-RPi/sec-gdb2.html
iii. Switch to an assembly view https://stackoverflow.com/questions/1902901/show-current-assembly-instruction-in-gdb
And then copy+paste those to here....not sure they'll actually provide any info, but they might.
Will try tomorrow.
It was recommended to forward the issue here.
Attempting to use Imagick embedded to FrankenPHP leads to all kinds of segfaults with even very simple programs.
E.g. magick.php:
Important: Using the php-cli binary that was generated with the same
./php-src/configure
command works with no problems.Console log example using crazyccwhale/static-php-cli and dunglas/frankenphp :
Important parts:
This was using gcc 12.2.1, but using gcc 11.3.0 results in the same error.