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

Static embedded php build - Segmentation fault(s) #634

Open
DubbleClick opened this issue Oct 14, 2023 · 6 comments
Open

Static embedded php build - Segmentation fault(s) #634

DubbleClick opened this issue Oct 14, 2023 · 6 comments

Comments

@DubbleClick
Copy link

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:

<?php

$image = new Imagick();
$image->newImage(1, 1, new ImagickPixel('#ffffff'));
$image->setImageFormat('png');
$pngData = $image->getImagesBlob();
echo $pngData;

?>

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 :

alpine:/opt/static-php-cli# ./bin/spc build imagick --with-libs=libpng,libjpeg,libwebp,freetype --enable-zts --build-emb
ed --build-cli --no-strip
     _        _   _                 _
 ___| |_ __ _| |_(_) ___      _ __ | |__  _ __
/ __| __/ _` | __| |/ __|____| '_ \| '_ \| '_ \
\__ \ || (_| | |_| | (_|_____| |_) | | | | |_) |
|___/\__\__,_|\__|_|\___|    | .__/|_| |_| .__/   v2.0.0
                             |_|         |_|
[16:11:54] [INFO] [EXEC] echo | gcc -E -x c - -march=corei7 2>/dev/null
[16:11:54] [INFO] [EXEC] echo | gcc -E -x c - -mtune=core-avx2 2>/dev/null
[16:11:54] [INFO] Build target: cli, embed
[16:11:54] [INFO] Enabled extensions: imagick
[16:11:54] [INFO] Required libraries: zlib, libpng, libjpeg, libwebp, freetype, imagemagick
[16:11:56] [NOTI] lib [pkg-config] already built
[16:11:56] [NOTI] lib [zlib] already built
[16:11:56] [NOTI] lib [libpng] already built
[16:11:56] [NOTI] lib [libjpeg] already built
[16:11:56] [NOTI] lib [libwebp] already built
[16:11:56] [NOTI] lib [freetype] already built
[16:11:56] [NOTI] lib [imagemagick] already built
[16:11:56] [INFO] Extension [imagick] patched before buildconf
[16:11:56] [INFO] Entering dir: /opt/static-php-cli/source/php-src
[16:11:56] [INFO] [EXEC] ./buildconf --force
[16:12:00] [INFO] Entering dir: /opt/static-php-cli/source/php-src
[16:12:00] [INFO] Using configure: --with-imagick=/opt/static-php-cli/buildroot
[16:12:00] [INFO] [EXEC] ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --enable-cli --disable-fpm --enable-embed=static --disable-micro --enable-zts --disable-zend-signals --enable-zend-max-execution-timers --with-imagick=/opt/static-php-cli/buildroot PKG_CONFIG='/opt/static-php-cli/buildroot/bin/pkg-config' PKG_CONFIG_PATH='/opt/static-php-cli/buildroot/lib/pkgconfig' CC='gcc' CXX='g++' CFLAGS='' LIBS='-ldl -lpthread' PATH='/opt/static-php-cli/buildroot/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin'
[16:12:07] [INFO] Extension [imagick] patched before make
[16:12:07] [INFO] cleaning up
[16:12:07] [INFO] Entering dir: /opt/static-php-cli/source/php-src
[16:12:07] [INFO] [EXEC] make clean
[16:12:08] [INFO] building cli
[16:12:08] [INFO] Entering dir: /opt/static-php-cli/source/php-src
[16:12:08] [INFO] [EXEC] sed -i "s|//lib|/lib|g" Makefile
[16:12:08] [INFO] [EXEC] make -j16 EXTRA_CFLAGS='-g -Os -fno-ident -Xcompiler -march=corei7 -Xcompiler -mtune=core-avx2' EXTRA_LIBS='/opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libfreetype.a /opt/static-php-cli/buildroot/lib/libwebp.a /opt/static-php-cli/buildroot/lib/libwebpdecoder.a /opt/static-php-cli/buildroot/lib/libwebpdemux.a /opt/static-php-cli/buildroot/lib/libwebpmux.a /opt/static-php-cli/buildroot/lib/libsharpyuv.a /opt/static-php-cli/buildroot/lib/libjpeg.a /opt/static-php-cli/buildroot/lib/libturbojpeg.a /opt/static-php-cli/buildroot/lib/libpng16.a /opt/static-php-cli/buildroot/lib/libz.a  /opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a  /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libjpeg.a /opt/static-php-cli/buildroot/lib/libpng.a /opt/static-php-cli/buildroot/lib/libwebp.a /opt/static-php-cli/buildroot/lib/libfreetype.a  /opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a  /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a -lgomp ' EXTRA_LDFLAGS_PROGRAM=' -all-static' cli
[16:12:39] [INFO] Deploying cli file
[16:12:39] [INFO] [EXEC] cp '/opt/static-php-cli/source/php-src/sapi/cli/php' '/opt/static-php-cli/buildroot/bin/'
[16:12:39] [INFO] building embed
[16:12:39] [INFO] Entering dir: /opt/static-php-cli/source/php-src
[16:12:39] [INFO] [EXEC] sed -i "s|//lib|/lib|g" Makefile
[16:12:39] [INFO] [EXEC] make INSTALL_ROOT=/opt/static-php-cli/buildroot -j16 EXTRA_CFLAGS='-g -Os -fno-ident -fPIE -Xcompiler -march=corei7 -Xcompiler -mtune=core-avx2' EXTRA_LIBS='/opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libfreetype.a /opt/static-php-cli/buildroot/lib/libwebp.a /opt/static-php-cli/buildroot/lib/libwebpdecoder.a /opt/static-php-cli/buildroot/lib/libwebpdemux.a /opt/static-php-cli/buildroot/lib/libwebpmux.a /opt/static-php-cli/buildroot/lib/libsharpyuv.a /opt/static-php-cli/buildroot/lib/libjpeg.a /opt/static-php-cli/buildroot/lib/libturbojpeg.a /opt/static-php-cli/buildroot/lib/libpng16.a /opt/static-php-cli/buildroot/lib/libz.a  /opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a  /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libjpeg.a /opt/static-php-cli/buildroot/lib/libpng.a /opt/static-php-cli/buildroot/lib/libwebp.a /opt/static-php-cli/buildroot/lib/libfreetype.a  /opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a  /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a -lgomp ' EXTRA_LDFLAGS_PROGRAM=' -all-static' install
[16:12:41] [INFO] running cli sanity check
[16:12:41] [INFO] [EXEC] /opt/static-php-cli/buildroot/bin/php -r "echo \"hello\";"
[16:12:41] [INFO] Build complete, used 47.315 s !
[16:12:41] [INFO] Static php binary path: /opt/static-php-cli/buildroot/bin/php
[16:12:41] [INFO] License path: /opt/static-php-cli/buildroot/license/
alpine:/opt/static-php-cli# cd /opt/frankenphp/caddy/frankenphp/
alpine:/opt/frankenphp/caddy/frankenphp# CGO_CFLAGS="$(/opt/static-php-cli/buildroot/bin/php-config --includes | sed s#-
I/#-I/opt/static-php-cli/buildroot/#g)"     CGO_LDFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(/opt/static-php-cli/
buildroot/bin/php-config --ldflags) -Wl,--start-group $(/opt/static-php-cli/buildroot/bin/php-config --libs | sed -e 's/
-lgcc_s//g') -Wl,--end-group"     LIBPHP_VERSION="$(/opt/static-php-cli/buildroot/bin/php-config --version)"     go buil
d -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -w -X 'git
hub.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $LIBPHP_VERSION Caddy'"
alpine:/opt/frankenphp/caddy/frankenphp# /opt/static-php-cli/buildroot/bin/php magick.php
�PNG

IHDR���7n�$ cHRMz&�����u0�`:��p��Q<�bKGD�݊��
alpine:/opt/frankenphp/caddy/frankenphp# ./frankenphp php-cli magick.php
Segmentation fault
alpine:/opt/frankenphp/caddy/frankenphp# tail magick.php
<?php

$image = new Imagick();
$image->newImage(1, 1, new ImagickPixel('#ffffff'));
$image->setImageFormat('png');
$pngData = $image->getImagesBlob();
echo $pngData;

?>
alpine:/opt/frankenphp/caddy/frankenphp# gdb ./frankenphp
GNU gdb (GDB) 13.1
...
Reading symbols from ./frankenphp...
(gdb) run php-cli magick.php
Starting program: /opt/frankenphp/caddy/frankenphp/frankenphp php-cli magick.php
[New LWP 1029]
[New LWP 1030]
[New LWP 1031]
[New LWP 1032]
[New LWP 1033]
[New LWP 1034]
[New LWP 1035]
[New LWP 1036]
[New LWP 1037]
[New LWP 1038]
[New LWP 1039]
[New LWP 1040]

Thread 13 "frankenphp" received signal SIGSEGV, Segmentation fault.
[Switching to LWP 1040]
GetPolicyInfo (name=name@entry=0x7ffff6b877e3 "cache:synchronize", exception=exception@entry=0x7fffad004eb0)
    at MagickCore/policy.c:301
301       if (IsPolicyCacheInstantiated(exception) == MagickFalse)
(gdb) bt
#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
#2  0x00007ffff61570c2 in AcquirePixelCache (number_threads=<optimized out>) at MagickCore/cache.c:218
#3  0x00007ffff6157490 in ClonePixelCache (cache=cache@entry=0x7fffacfda240) at MagickCore/cache.c:517
#4  0x00007ffff4b3df05 in GetImagePixelCache (image=image@entry=0x7fffacfb5290, clone=clone@entry=MagickTrue,
    exception=exception@entry=0x7ffff7ff7b20) at MagickCore/cache.c:1738
#5  0x00007ffff4b3fb61 in QueueAuthenticPixelCacheNexus (image=image@entry=0x7fffacfb5290, x=x@entry=0, y=y@entry=0,
    columns=1, rows=rows@entry=1, clone=clone@entry=MagickTrue, nexus_info=0x7fffad0136c0, exception=0x7ffff7ff7b20)
    at MagickCore/cache.c:4196
#6  0x00007ffff4b3fd5e in GetAuthenticPixelCacheNexus (image=0x7fffacfb5290, x=x@entry=0, y=y@entry=0,
    columns=<optimized out>, rows=rows@entry=1, nexus_info=0x7fffad0136c0, exception=0x7ffff7ff7b20)
    at MagickCore/cache.c:1348
#7  0x00007ffff4b409e1 in GetCacheViewAuthenticPixels (cache_view=cache_view@entry=0x7fffad001c80, x=x@entry=0,
    y=y@entry=0, columns=<optimized out>, rows=rows@entry=1, exception=exception@entry=0x7ffff7ff7b20)
    at MagickCore/cache-view.c:313
#8  0x00007ffff614a643 in SetImageDepth (image=image@entry=0x7fffacfb5290, depth=8,
    exception=exception@entry=0x7ffff7ff7b20) at MagickCore/attribute.c:2062
#9  0x00007ffff63b8c9e in WriteOnePNGImage (mng_info=mng_info@entry=0x7fffad14e100,
    IMimage_info=IMimage_info@entry=0x7fffacfb9280, IMimage=IMimage@entry=0x7fffacfe2200,
    exception=exception@entry=0x7ffff7ff7b20) at coders/png.c:8417
#10 0x00007ffff63c3d8d in WritePNGImage (image_info=image_info@entry=0x7fffacfb9280, image=image@entry=0x7fffacfe2200,
    exception=exception@entry=0x7ffff7ff7b20) at coders/png.c:12176
#11 0x00007ffff617d892 in WriteImage (image_info=image_info@entry=0x7fffacfce260, image=image@entry=0x7fffacfe2200,
    exception=exception@entry=0x7ffff7ff7b20) at MagickCore/constitute.c:1349
#12 0x00007ffff614dc74 in ImageToBlob (image_info=0x7fffacfe61f0, image=image@entry=0x7fffacfe2200,
    length=length@entry=0x7fffad4a42e0, exception=0x7ffff7ff7b20) at MagickCore/blob.c:2082
#13 0x00007ffff614e849 in ImagesToBlob (image_info=<optimized out>, images=0x7fffacfe2200,
--Type <RET> for more, q to quit, c to continue without paging--
    length=length@entry=0x7fffad4a42e0, exception=<optimized out>) at MagickCore/blob.c:2473
#14 0x00007ffff6124720 in MagickGetImagesBlob (wand=<optimized out>, length=length@entry=0x7fffad4a42e0)
    at MagickWand/magick-image.c:4242
#15 0x00007ffff60c9cc6 in zim_Imagick_getImagesBlob (execute_data=<optimized out>, return_value=0x7fffad212100)
    at /opt/static-php-cli/source/php-src/ext/imagick/imagick_class.c:8675
#16 0x00007ffff5f2df1c in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER ()
    at /opt/static-php-cli/source/php-src/Zend/zend_vm_execute.h:1951
#17 execute_ex (ex=<optimized out>) at /opt/static-php-cli/source/php-src/Zend/zend_vm_execute.h:56081
#18 0x00007ffff5f36a2e in zend_execute (op_array=0x7fffad276000, return_value=0x0)
    at /opt/static-php-cli/source/php-src/Zend/zend_vm_execute.h:60409
#19 0x00007ffff5ed8b28 in zend_execute_scripts (type=type@entry=8, retval=retval@entry=0x0,
    file_count=file_count@entry=3) at /opt/static-php-cli/source/php-src/Zend/zend.c:1833
#20 0x00007ffff5e975ad in php_execute_script (primary_file=0x7fffad4a67b0)
    at /opt/static-php-cli/source/php-src/main/main.c:2557
#21 0x00007ffff5e8e804 in execute_script_cli ()
#22 0x00007ffff65ada22 in start (p=0x7fffad4a6918) at src/thread/pthread_create.c:207
#23 0x00007ffff65aeeff in __clone () at src/thread/x86_64/clone.s:22
Backtrace stopped: frame did not save the PC
(gdb) quit
A debugging session is active.

        Inferior 1 [process 1026] will be killed.

Quit anyway? (y or n) y
alpine:/opt/frankenphp/caddy/frankenphp#

Important parts:

./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --enable-cli --disable-fpm --enable-embed=static --disable-micro --enable-zts --disable-zend-signals --enable-zend-max-execution-timers --with-imagick=/opt/static-php-cli/buildroot PKG_CONFIG='/opt/static-php-cli/buildroot/bin/pkg-config' PKG_CONFIG_PATH='/opt/static-php-cli/buildroot/lib/pkgconfig' CC='gcc' CXX='g++' CFLAGS='' LIBS='-ldl -lpthread' PATH='/opt/static-php-cli/buildroot/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin'
...
make INSTALL_ROOT=/opt/static-php-cli/buildroot -j16 EXTRA_CFLAGS='-g -Os -fno-ident -fPIE -Xcompiler -march=corei7 -Xcompiler -mtune=core-avx2' EXTRA_LIBS='/opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libfreetype.a /opt/static-php-cli/buildroot/lib/libwebp.a /opt/static-php-cli/buildroot/lib/libwebpdecoder.a /opt/static-php-cli/buildroot/lib/libwebpdemux.a /opt/static-php-cli/buildroot/lib/libwebpmux.a /opt/static-php-cli/buildroot/lib/libsharpyuv.a /opt/static-php-cli/buildroot/lib/libjpeg.a /opt/static-php-cli/buildroot/lib/libturbojpeg.a /opt/static-php-cli/buildroot/lib/libpng16.a /opt/static-php-cli/buildroot/lib/libz.a  /opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a  /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libjpeg.a /opt/static-php-cli/buildroot/lib/libpng.a /opt/static-php-cli/buildroot/lib/libwebp.a /opt/static-php-cli/buildroot/lib/libfreetype.a  /opt/static-php-cli/buildroot/lib/libMagick++-7.Q16HDRI.a /opt/static-php-cli/buildroot/lib/libMagickWand-7.Q16HDRI.a  /opt/static-php-cli/buildroot/lib/libMagickCore-7.Q16HDRI.a -lgomp ' EXTRA_LDFLAGS_PROGRAM=' -all-static' install

This was using gcc 12.2.1, but using gcc 11.3.0 results in the same error.

alpine:/opt/frankenphp/caddy/frankenphp# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/12.2.1/lto-wrapper
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-12-20220924/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --enable-checking=release --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-default-ssp --enable-languages=c,c++,d,objc,go,fortran,ada --disable-libssp --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-bugurl=https://gitlab.alpinelinux.org/alpine/aports/-/issues --with-system-zlib --with-linker-hash-style=gnu --with-pkgversion='Alpine 12.2.1_git20220924-r10'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10)
alpine:/opt/frankenphp/caddy/frankenphp# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/12.2.1/lto-wrapper
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-12-20220924/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --enable-checking=release --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-default-ssp --enable-languages=c,c++,d,objc,go,fortran,ada --disable-libssp --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-bugurl=https://gitlab.alpinelinux.org/alpine/aports/-/issues --with-system-zlib --with-linker-hash-style=gnu --with-pkgversion='Alpine 12.2.1_git20220924-r10'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10)
alpine:/opt/frankenphp/caddy/frankenphp# go version
go version go1.21.3 linux/amd64
@Danack
Copy link
Collaborator

Danack commented Oct 15, 2023

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:

  1. Stepping through the code and finding where the actual error is, contemplating what it's doing, and then summarising that here.

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

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

@DubbleClick
Copy link
Author

Thank you for the reply!

  1. Will try. I'm not familiar with gdb/linux debugging tools as I only work on native projects on Windows (until recently, to advance an easy-to-use version of FrankenPHP).
  2. I have. I've also turned off libjpeg support (which is said to be the only potentially non thread-safe part in ImageMagick). No change.
  3. It's a server in a private network, it's not openly accessible. Some small pdf creations happen directly upon request. It's possible to disable imagick for it and rely on gd, which works, but the pdf library uses imagick rather than gd when imagick is installed.

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.

@DubbleClick
Copy link
Author

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().

@Danack
Copy link
Collaborator

Danack commented Oct 24, 2023

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.

@Danack
Copy link
Collaborator

Danack commented Oct 24, 2023

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.

@DubbleClick
Copy link
Author

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.

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

2 participants