<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/72297>72297</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
OpenMP segmentation fault when compiling php-imagick with clang+preload is enabled
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
danog
</td>
</tr>
</table>
<pre>
Ref https://github.com/Imagick/imagick/issues/637
Reproducer Dockerfile:
```
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
ENV CC=clang-16
ENV CXX=clang++-16
RUN true \
&& apt update \
&& apt install -y --no-install-recommends \
tzdata software-properties-common locales curl apt-utils gpg-agent cron logrotate \
gnupg2 ca-certificates lsb-release \
make pkg-config binutils wget \
&& wget https://apt.llvm.org/llvm.sh \
&& chmod +x llvm.sh \
&& ./llvm.sh 16 all \
&& apt update \
&& apt install -y php-dev
RUN apt install imagemagick libmagickcore-dev libmagickwand-dev -y && \
wget https://pecl.php.net/get/imagick && \
tar -xf imagick && \
rm imagick && \
cd imagick* && \
phpize && \
./configure --enable-debug && \
\
make -j100 && \
make install
ADD php.imagick.ini /etc/php/8.1/cli/php.ini
RUN rm /etc/php/8.1/cli/conf.d/*
RUN echo '<?php var_dump("Preloaded");' > /tmp/a.php
WORKDIR /app
```
php.imagick.ini:
```
memory_limit = -1
zend.assertions = 1
display_errors = On
display_startup_errors = On
extension=imagick
[opcache]
zend_extension=opcache
opcache.memory_consumption=64M
opcache.enable=1
opcache.enable_cli=1
opcache.jit=disable
opcache.preload=/tmp/a.php
opcache.preload_user=root
opcache.protect_memory=1
```
Result:
```
root@bcc7ee2f4cae:/app# php -v
AddressSanitizer:DEADLYSIGNAL
=================================================================
==10==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000018 (pc 0x7f2a66e96286 bp 0x000000000000 sp 0x7ffe502bfcc0 T0)
==10==The signal is caused by a WRITE memory access.
==10==Hint: address points to the zero page.
#0 0x7f2a66e96286 (/lib/x86_64-linux-gnu/libomp.so.5+0xa6286) (BuildId: 553aab45440348b202b8d0e3f285e2b48f827aea)
#1 0x7f2a66e1f9ac in __kmpc_set_lock (/lib/x86_64-linux-gnu/libomp.so.5+0x2f9ac) (BuildId: 553aab45440348b202b8d0e3f285e2b48f827aea)
#2 0x7f2a66b85353 in SetMagickResourceLimit (/lib/x86_64-linux-gnu/libMagickCore-6.Q16.so.6+0x18d353) (BuildId: 07037e3a04f36f23e9e9e17a83b2a3d5942c2670)
#3 0x7f2a699b4c3c in zm_activate_imagick /imagick-3.7.0/imagick.c:1236:3
#4 0x55e31cfe1acb in zend_activate_modules /php-src/Zend/zend_API.c:3091:7
#5 0x55e31cdd6217 in php_request_startup /php-src/main/main.c:1785:3
#6 0x7f2a675a0f81 in accel_finish_startup /php-src/ext/opcache/ZendAccelerator.c:4721:8
#7 0x7f2a6759e138 in accel_post_startup /php-src/ext/opcache/ZendAccelerator.c:3356:6
#8 0x55e31cfb9a85 in zend_post_startup /php-src/Zend/zend.c:1045:7
#9 0x55e31cdd89c6 in php_module_startup /php-src/main/main.c:2294:6
#10 0x55e31d536f38 in php_cli_startup /php-src/sapi/cli/php_cli.c:410:9
#11 0x55e31d533068 in main /php-src/sapi/cli/php_cli.c:1300:6
#12 0x7f2a6a3d5d8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: a43bfc8428df6623cd498c9c0caeb91aec9be4f9)
#13 0x7f2a6a3d5e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: a43bfc8428df6623cd498c9c0caeb91aec9be4f9)
#14 0x55e31c602354 in _start (/usr/local/bin/php+0x402354) (BuildId: b5620a3713a279732d643f558dbbee599c56c20b)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libomp.so.5+0xa6286) (BuildId: 553aab45440348b202b8d0e3f285e2b48f827aea)
==10==ABORTING
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWFtzozoS_jXKiwpKSFwf8mAP8WxqJ8msZ85tX1xCNFgTkFgkJk5-_ZbA14TJzqk9VVvrctmgvn3qbnU3cGNkrQCuUbREUX7FB7vV_XXJla6vCl0-X6-hwltrO4PYAtEVoqta2u1Q-EK3iK5uW15L8YjoSp6ujBnAILqKWYJIjshi-l1D1-tyENDjXItH6CvZgFN7xoNisv-Ot6v1wx0eikHZAbEFpT4Jz7lv7n_F-c3ydnG_Wa0f7r_e3OeI5UorqSz0XFj5HV7zf_iAWC4armoviM-Wf__9sI7oEtHlkboH_8s9tv0AGEUfphWMMUY0RjTGvLN46Epuf0yWyljeNNh7xp6ntLe_93oQum1BleZS1H3sS8ktx0ZX9on34HW97qC3EoznhLTCjRa8AYPF0DfOjDdY2Rhcd7XHa1AWi37kqntt36Bzn1oNXU2x4J5wmispuAWDG1N4PTTAzYxMyx8Bd4-1J7SqZI0LqSazTzXYWQeMhMss4p31m-Z76-u-RnQ1XprtrLTYtrrEiC53-D02_0xNEGPn7P8-Vt2280r4_joTzrlc4sOU_LiRxXQldA9O8LTyxFU5rnjPB1sX9md81IFo_G7b-QqsO3jj7_6czeqwvMfersLv8fTtu2RR4uNJXsxydNtOvsAsyYVgSoqhB-x5oHjROD8UQz0rcHEz5pX3LSBklnck751-Ho9FnjtM_h62L5XEiK7ACufCbYfoKvUDh6yR04pjeR3Rvn1PyG3KL8eoLF5LgthqjGiC2AfEnCz-zvtNObQdoimi9HMPjeYllIhSRDPElogmGLEbZ9A6rhV3UT7X-9vD-u_57RqPB6WbLY3nv6-2f6qplyIttLp_3jSylRYjlmMvmAgvoEqfG-NKgFZmpO1JpTRdw5830Pe6nygP6pJkLO_t0M2xwM6CMlIrxPJDWk3IoqXuBBdbQFF-ArE5FzgwjNT9jb_fg9DKDG1nJ844vLvkmhIPsTyYW9-4oL6hfZMWsbyUZhQ98-6BoZsCiVg-F7hXXJv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