Bug 266175

Summary: lang/php81 fails to build WITH=ZTS on aarch64
Product: Ports & Packages Reporter: Konstantin Pavlov <thresh>
Component: Individual Port(s)Assignee: Muhammad Moinur Rahman <bofh>
Status: Closed FIXED    
Severity: Affects Only Me CC: chris, cyberbotx, danfe, fluffy, hlh
Priority: --- Flags: bugzilla: maintainer-feedback? (bofh)
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
/usr/ports/lang/php81/files/patch-TSRM_TSRM.c
none
Try disabling shared for aarch64
none
Skip bad TSRM code on FreeBSD/aarch64
none
Disable JIT for opcache on aarch64 none

Description Konstantin Pavlov 2022-09-02 13:26:39 UTC
lang/php81 version 8.1.9 fails to build on aarch64 on FreeBSD 13.1

Steps to reproduce:
1. spin up an official FreeBSD AWS aarch64 instance
2. build php81:

cd /usr/ports/lang/php81
make all-depends-list | cut -c 12- | xargs pkg install -y
export BATCH=yes
make -j4 WITH=ZTS PREFIX=/usr/opt/php81 package

The result will be:

--- libphp.la ---
ld: error: relocation R_AARCH64_TLSLE_ADD_TPREL_HI12 against _tsrm_ls_cache cannot be used with -shared
>>> defined in Zend/.libs/zend.o
>>> referenced by TSRM.c
>>>               TSRM/.libs/TSRM.o:(tsrm_get_ls_cache_tcb_offset)

ld: error: relocation R_AARCH64_TLSLE_ADD_TPREL_LO12_NC against _tsrm_ls_cache cannot be used with -shared
>>> defined in Zend/.libs/zend.o
>>> referenced by TSRM.c
>>>               TSRM/.libs/TSRM.o:(tsrm_get_ls_cache_tcb_offset)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** [libphp.la] Error code 1

make[1]: stopped in /usr/ports/lang/php81/work/php-8.1.9
*** [do-build] Error code 1

make: stopped in /usr/ports/lang/php81
Comment 1 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2022-09-03 11:42:43 UTC
(In reply to Konstantin Pavlov from comment #0)
I am not sure but it looks like the problem is with the compilers and I will request you to build the entire lang/php81 rather than mixing and matching pkg and ports.
Comment 2 Naram Qashat 2022-11-28 06:39:48 UTC
Can I ask for this to be re-opened? I have run into this exact same problem with php 8.1.13 after the default PHP version was changed, except this happened within a poudriere build so I am not mixing and matching like the previous comment suggested for the OP.

I have a full poudriere build log of the failure here: https://poudriere.cyberbotx.com:8766/data/local_aarch64-default/2022-11-28_01h20m54s/logs/errors/php81-8.1.13.log
Comment 3 Henri Hennebert 2023-02-02 08:20:01 UTC
On a rockpro64:

FreeBSD keystone.lab.bel 13.1-STABLE FreeBSD 13.1-STABLE #0 stable/13-n253596-fbdde1029e92: Mon Jan 23 19:26:21 CET 2023     root@keystone.lab.bel:/usr/obj/usr/src/arm64.aarch64/sys/ROCKPRO64 arm64

cat /var/db/ports/lang_php81/options 
# This file is auto-generated by 'make config'.
# Options for php81-8.1.14
_OPTIONS_READ=php81-8.1.14
_FILE_COMPLETE_OPTIONS_LIST=CGI CLI DEBUG EMBED FPM IPV6 LINKTHR MYSQLND PHPDBG ZTS
OPTIONS_FILE_SET+=CGI
OPTIONS_FILE_SET+=CLI
OPTIONS_FILE_UNSET+=DEBUG
OPTIONS_FILE_SET+=EMBED
OPTIONS_FILE_SET+=FPM
OPTIONS_FILE_SET+=IPV6
OPTIONS_FILE_SET+=LINKTHR
OPTIONS_FILE_UNSET+=MYSQLND
OPTIONS_FILE_UNSET+=PHPDBG
OPTIONS_FILE_SET+=ZTS

MAKE_JOBS_UNSAFE=yes make

produce the same error:

/bin/sh /usr/ports/lang/php81/work/php-8.1.14/libtool --silent --preserve-dup-deps --tag CC --mode=link cc -shared -fno-common -Wstrict-prototypes -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -fvisibility=hidden -DZTS -DZEND_SIGNALS   -rpath /usr/ports/lang/php81/work/php-8.1.14/libs -avoid-version -module -L/usr/local/lib -L/usr/lib -lcrypto -lssl  -fstack-protector-strong  -R /usr/local/lib ext/date/php_date.lo ext/date/lib/astro.lo ext/date/lib/dow.lo ext/date/lib/parse_date.lo ext/date/lib/parse_tz.lo ext/date/lib/parse_posix.lo ext/date/lib/timelib.lo ext/date/lib/tm2unixtime.lo ext/date/lib/unixtime2tm.lo ext/date/lib/parse_iso_intervals.lo ext/date/lib/interval.lo ext/libxml/libxml.lo ext/openssl/openssl.lo ext/openssl/xp_ssl.lo ext/pcre/pcre2lib/pcre2_auto_possess.lo ext/pcre/pcre2lib/pcre2_chartables.lo ext/pcre/pcre2lib/pcre2_compile.lo ext/pcre/pcre2lib/pcre2_config.lo ext/pcre/pcre2lib/pcre2_context.lo ext/pcre/pcre2lib/pcre2_dfa_match.lo ext/pcre/pcre2lib/pcre2_error.lo ext/pcre/pcre2lib/pcre2_jit_compile.lo ext/pcre/pcre2lib/pcre2_maketables.lo ext/pcre/pcre2lib/pcre2_match.lo ext/pcre/pcre2lib/pcre2_match_data.lo ext/pcre/pcre2lib/pcre2_newline.lo ext/pcre/pcre2lib/pcre2_ord2utf.lo ext/pcre/pcre2lib/pcre2_pattern_info.lo ext/pcre/pcre2lib/pcre2_serialize.lo ext/pcre/pcre2lib/pcre2_string_utils.lo ext/pcre/pcre2lib/pcre2_study.lo ext/pcre/pcre2lib/pcre2_substitute.lo ext/pcre/pcre2lib/pcre2_substring.lo ext/pcre/pcre2lib/pcre2_tables.lo ext/pcre/pcre2lib/pcre2_ucd.lo ext/pcre/pcre2lib/pcre2_valid_utf.lo ext/pcre/pcre2lib/pcre2_xclass.lo ext/pcre/pcre2lib/pcre2_find_bracket.lo ext/pcre/pcre2lib/pcre2_convert.lo ext/pcre/pcre2lib/pcre2_extuni.lo ext/pcre/pcre2lib/pcre2_script_run.lo ext/pcre/php_pcre.lo ext/hash/hash.lo ext/hash/hash_md.lo ext/hash/hash_sha.lo ext/hash/hash_ripemd.lo ext/hash/hash_haval.lo ext/hash/hash_tiger.lo ext/hash/hash_gost.lo ext/hash/hash_snefru.lo ext/hash/hash_whirlpool.lo ext/hash/hash_adler32.lo ext/hash/hash_crc32.lo ext/hash/hash_fnv.lo ext/hash/hash_joaat.lo ext/hash/sha3/generic64lc/KeccakP-1600-opt64.lo ext/hash/sha3/generic64lc/KeccakHash.lo ext/hash/sha3/generic64lc/KeccakSponge.lo ext/hash/hash_sha3.lo ext/hash/murmur/PMurHash.lo ext/hash/murmur/PMurHash128.lo ext/hash/hash_murmur.lo ext/hash/hash_xxhash.lo ext/json/json.lo ext/json/json_encoder.lo ext/json/json_parser.lo ext/json/json_scanner.lo ext/reflection/php_reflection.lo ext/spl/php_spl.lo ext/spl/spl_functions.lo ext/spl/spl_iterators.lo ext/spl/spl_array.lo ext/spl/spl_directory.lo ext/spl/spl_exceptions.lo ext/spl/spl_observer.lo ext/spl/spl_dllist.lo ext/spl/spl_heap.lo ext/spl/spl_fixedarray.lo ext/standard/crypt_freesec.lo ext/standard/crypt_blowfish.lo ext/standard/crypt_sha512.lo ext/standard/crypt_sha256.lo ext/standard/php_crypt_r.lo ext/standard/array.lo ext/standard/base64.lo ext/standard/basic_functions.lo ext/standard/browscap.lo ext/standard/crc32.lo ext/standard/crypt.lo ext/standard/datetime.lo ext/standard/dir.lo ext/standard/dl.lo ext/standard/dns.lo ext/standard/exec.lo ext/standard/file.lo ext/standard/filestat.lo ext/standard/flock_compat.lo ext/standard/formatted_print.lo ext/standard/fsock.lo ext/standard/head.lo ext/standard/html.lo ext/standard/image.lo ext/standard/info.lo ext/standard/iptc.lo ext/standard/lcg.lo ext/standard/link.lo ext/standard/mail.lo ext/standard/math.lo ext/standard/md5.lo ext/standard/metaphone.lo ext/standard/microtime.lo ext/standard/pack.lo ext/standard/pageinfo.lo ext/standard/quot_print.lo ext/standard/rand.lo ext/standard/mt_rand.lo ext/standard/soundex.lo ext/standard/string.lo ext/standard/scanf.lo ext/standard/syslog.lo ext/standard/type.lo ext/standard/uniqid.lo ext/standard/url.lo ext/standard/var.lo ext/standard/versioning.lo ext/standard/assert.lo ext/standard/strnatcmp.lo ext/standard/levenshtein.lo ext/standard/incomplete_class.lo ext/standard/url_scanner_ex.lo ext/standard/ftp_fopen_wrapper.lo ext/standard/http_fopen_wrapper.lo ext/standard/php_fopen_wrapper.lo ext/standard/credits.lo ext/standard/css.lo ext/standard/var_unserializer.lo ext/standard/ftok.lo ext/standard/sha1.lo ext/standard/user_filters.lo ext/standard/uuencode.lo ext/standard/filters.lo ext/standard/proc_open.lo ext/standard/streamsfuncs.lo ext/standard/http.lo ext/standard/password.lo ext/standard/random.lo ext/standard/net.lo ext/standard/hrtime.lo ext/standard/crc32_x86.lo Zend/asm/make_arm64_aapcs_elf_gas.lo Zend/asm/jump_arm64_aapcs_elf_gas.lo TSRM/TSRM.lo main/main.lo main/snprintf.lo main/spprintf.lo main/fopen_wrappers.lo main/alloca.lo main/php_scandir.lo main/php_ini.lo main/SAPI.lo main/rfc1867.lo main/php_content_types.lo main/strlcpy.lo main/strlcat.lo main/explicit_bzero.lo main/reentrancy.lo main/php_variables.lo main/php_ticks.lo main/network.lo main/php_open_temporary_file.lo main/output.lo main/getopt.lo main/php_syslog.lo main/streams/streams.lo main/streams/cast.lo main/streams/memory.lo main/streams/filter.lo main/streams/plain_wrapper.lo main/streams/userspace.lo main/streams/transports.lo main/streams/xp_socket.lo main/streams/mmap.lo main/streams/glob_wrapper.lo Zend/zend_language_parser.lo Zend/zend_language_scanner.lo Zend/zend_ini_parser.lo Zend/zend_ini_scanner.lo Zend/zend_alloc.lo Zend/zend_compile.lo Zend/zend_constants.lo Zend/zend_dtrace.lo Zend/zend_execute_API.lo Zend/zend_highlight.lo Zend/zend_llist.lo Zend/zend_vm_opcodes.lo Zend/zend_opcode.lo Zend/zend_operators.lo Zend/zend_ptr_stack.lo Zend/zend_stack.lo Zend/zend_variables.lo Zend/zend.lo Zend/zend_API.lo Zend/zend_extensions.lo Zend/zend_hash.lo Zend/zend_list.lo Zend/zend_builtin_functions.lo Zend/zend_attributes.lo Zend/zend_execute.lo Zend/zend_ini.lo Zend/zend_sort.lo Zend/zend_multibyte.lo Zend/zend_stream.lo Zend/zend_iterators.lo Zend/zend_interfaces.lo Zend/zend_exceptions.lo Zend/zend_strtod.lo Zend/zend_gc.lo Zend/zend_closures.lo Zend/zend_weakrefs.lo Zend/zend_float.lo Zend/zend_string.lo Zend/zend_signal.lo Zend/zend_generators.lo Zend/zend_virtual_cwd.lo Zend/zend_ast.lo Zend/zend_objects.lo Zend/zend_object_handlers.lo Zend/zend_objects_API.lo Zend/zend_default_classes.lo Zend/zend_inheritance.lo Zend/zend_smart_str.lo Zend/zend_cpuinfo.lo Zend/zend_gdb.lo Zend/zend_observer.lo Zend/zend_system_id.lo Zend/zend_enum.lo Zend/zend_fibers.lo Zend/Optimizer/zend_optimizer.lo Zend/Optimizer/pass1.lo Zend/Optimizer/pass3.lo Zend/Optimizer/optimize_func_calls.lo Zend/Optimizer/block_pass.lo Zend/Optimizer/optimize_temp_vars_5.lo Zend/Optimizer/nop_removal.lo Zend/Optimizer/compact_literals.lo Zend/Optimizer/zend_cfg.lo Zend/Optimizer/zend_dfg.lo Zend/Optimizer/dfa_pass.lo Zend/Optimizer/zend_ssa.lo Zend/Optimizer/zend_inference.lo Zend/Optimizer/zend_func_info.lo Zend/Optimizer/zend_call_graph.lo Zend/Optimizer/sccp.lo Zend/Optimizer/scdf.lo Zend/Optimizer/dce.lo Zend/Optimizer/escape_analysis.lo Zend/Optimizer/compact_vars.lo Zend/Optimizer/zend_dump.lo sapi/embed/php_embed.lo main/internal_functions.lo -lcrypt -lcrypt -lutil -lm -lpthread -lxml2 -lssl -lcrypto -largon2 -lcrypt  -o libphp.la
ld: error: relocation R_AARCH64_TLSLE_ADD_TPREL_HI12 against _tsrm_ls_cache cannot be used with -shared
>>> defined in Zend/.libs/zend.o
>>> referenced by TSRM.c
>>>               TSRM/.libs/TSRM.o:(tsrm_get_ls_cache_tcb_offset)

ld: error: relocation R_AARCH64_TLSLE_ADD_TPREL_LO12_NC against _tsrm_ls_cache cannot be used with -shared
>>> defined in Zend/.libs/zend.o
>>> referenced by TSRM.c
>>>               TSRM/.libs/TSRM.o:(tsrm_get_ls_cache_tcb_offset)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make[2]: stopped in /usr/ports/lang/php81/work/php-8.1.14
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/lang/php81
*** Error code 1

Stop.
make: stopped in /usr/ports/lang/php81
Comment 4 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-02-02 11:13:23 UTC
Let me know how it goes after:
echo "WITH_MPM=event" >> /etc/make.conf

Or in relavent make.conf for poudriere.
Comment 5 Henri Hennebert 2023-02-02 13:38:59 UTC
(In reply to Muhammad Moinur Rahman from comment #4)
same error with

tail /etc/make.conf
KERNCONF?=ROCKPRO64
MODULES_OVERRIDE=zfs dwwdt cryptodev fdescfs netgraph rc4 accf_http accf_data dtrace ksyms tmpfs nullfs fusefs if_enc spi fdt spigen usb/ucom usb/uftdi rtwn rtwn_usb rtwnfw wlan_xauth random_fortuna random_other mac_ntpd rtsx allwinner dtb/allwinner dtb/rockchip

DEFAULT_VERSIONS+= php=8.1
DEFAULT_VERSIONS+= bdb=18
DEFAULT_VERSIONS+= emacs=devel_full
#--- BATCH=yes
WITH_CCACHE_BUILD=yes
CCACHE_DIR=/var/cache/ports-ccache
WITH_MPM=event
Comment 6 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-02-02 13:49:41 UTC
(In reply to Henri Hennebert from comment #5)
Can you retry once more disabling ccache?
Comment 7 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-02-02 14:28:33 UTC
Currently I don't have a aarch64 machine to test these but more or less this feels like an issue of compiler limitation rather than php itself.
Comment 8 Henri Hennebert 2023-02-02 16:52:28 UTC
(In reply to Muhammad Moinur Rahman from comment #6)
Same error (after more time)

tail /etc/make.conf
KERNCONF?=ROCKPRO64
MODULES_OVERRIDE=zfs dwwdt cryptodev fdescfs netgraph rc4 accf_http accf_data dtrace ksyms tmpfs nullfs fusefs if_enc spi fdt spigen usb/ucom usb/uftdi rtwn rtwn_usb rtwnfw wlan_xauth random_fortuna random_other mac_ntpd rtsx allwinner dtb/allwinner dtb/rockchip

DEFAULT_VERSIONS+= php=8.1
DEFAULT_VERSIONS+= bdb=18
DEFAULT_VERSIONS+= emacs=devel_full
#--- BATCH=yes
#---WITH_CCACHE_BUILD=yes
#---CCACHE_DIR=/var/cache/ports-ccache
WITH_MPM=event
Comment 9 Henri Hennebert 2023-02-02 16:58:34 UTC
(In reply to Muhammad Moinur Rahman from comment #7)
On

FreeBSD morzine.restart.bel 13.1-STABLE FreeBSD 13.1-STABLE #0 stable/13-n253367-f61fca7409f6-dirty: Mon Jan  9 18:50:27 CET 2023     root@morzine.restart.bel:/usr/obj/usr/src/amd64.amd64/sys/MORZINE amd64

tail /etc/make.conf 
KERNCONF?=MORZINE
DEFAULT_VERSIONS+= bdb=18
DEFAULT_VERSIONS+= php=8.1
DEFAULT_VERSIONS+= perl5=5.36
DEFAULT_VERSIONS+= pgsql=14
DEFAULT_VERSIONS+= nodejs=16
#---BATCH=yes
WITH_CCACHE_BUILD=yes
CCACHE_DIR=/var/cache/ports-ccache

and

cat /var/db/ports/lang_php81/options 
# This file is auto-generated by 'make config'.
# Options for php81-8.1.14
_OPTIONS_READ=php81-8.1.14
_FILE_COMPLETE_OPTIONS_LIST=CGI CLI DEBUG DTRACE EMBED FPM IPV6 LINKTHR  MYSQLND PHPDBG ZTS
OPTIONS_FILE_SET+=CGI
OPTIONS_FILE_SET+=CLI
OPTIONS_FILE_UNSET+=DEBUG
OPTIONS_FILE_SET+=DTRACE
OPTIONS_FILE_SET+=EMBED
OPTIONS_FILE_SET+=FPM
OPTIONS_FILE_SET+=IPV6
OPTIONS_FILE_SET+=LINKTHR
OPTIONS_FILE_UNSET+=MYSQLND
OPTIONS_FILE_UNSET+=PHPDBG
OPTIONS_FILE_SET+=ZTS

All build without problem.
Comment 10 Dima Panov freebsd_committer freebsd_triage 2023-02-06 17:49:21 UTC
Can confirm.
Builds fine for 13.1/14.0-amd64 but same fail with complain on relocation on aarch64

ZTS is on
WITH_MPM=event in make.conf

NO_CCACHE knob have no effect
Comment 11 Dima Panov freebsd_committer freebsd_triage 2023-02-06 17:51:22 UTC
(In reply to Dima Panov from comment #10)
BTW, play with port's llvm 13/14/15 does no effect -- php 8.1/8.2 fails with same error with ZTS enabled
Comment 12 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-04-09 07:03:13 UTC
It chocks on the assembly code added to the tsrm_get_ls_cache_tcb_offset() function as part of this commit:

https://github.com/php/php-src/commit/735e4ccf5e9726eb5611eef591ed3bcfaf9148c4

Until it's fixed to work on FreeBSD, you can remove the #elif defined(__aarch64__) block or extra-guard it with && !defined(__FreeBSD__).

(In reply to Naram Qashat from comment #2)
> Can I ask for this to be re-opened?
Of course.  It's still a valid bug, affects current PHP versions, and should not have been prematurely closed in the first place.
Comment 13 Henri Hennebert 2023-04-09 10:40:52 UTC
Created attachment 241370 [details]
/usr/ports/lang/php81/files/patch-TSRM_TSRM.c

A rapid hack.

Add this file as /usr/ports/lang/php81/files/patch-TSRM_TSRM.c 

It compile and run OK as a php-fpm. I don't test it under mod_php81.
Comment 14 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-04-09 11:09:32 UTC
(In reply to Henri Hennebert from comment #13)

Why such uglification when there's a clean way of guarding it?  Also, it might be incomplete because tsrm_get_ls_cache_tcb_offset() is called in ext/opcache/jit/zend_jit_arm64.dasc and there's a ZEND_ASSERT that it does not return zero.

Please don't attach naive patches, it's not helping and just adds more noise.
Comment 15 Henri Hennebert 2023-04-09 11:40:29 UTC
(In reply to Alexey Dokuchaev from comment #14)

You are completely right, I don't use opcache since I encounter some problem with 7.4.5, so it a dangerous solution for everyone.

For the ugliness, as said, it was just a rapid mean to unlock the situation, and was not a proposition for a commit.

Anyway sorry to have offended your love of aesthetics ;-)
Comment 16 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-04-09 12:14:12 UTC
(In reply to Henri Hennebert from comment #15)
> it was just a rapid mean to unlock the situation
The situation was "unlocked" with comment #12, I'm sure everyone can crank a patch based on that.

> Anyway sorry to have offended your love of aesthetics ;-)
Shall you provide a real working tsrm_get_ls_cache_tcb_offset() implementation for FreeBSD, I'll numb my sens esthétique, I promise. :-)
Comment 17 Henri Hennebert 2023-04-09 12:28:38 UTC
(In reply to Alexey Dokuchaev from comment #16)

I have no knowledge of arm assemply code and of the overall implementation of php. Sorry, I can't help :-(

More seriously, I enable opcache and I encounter no problem after some test. just in case it help...

Opcode Caching 	Up and Running
Optimization 	Enabled
SHM Cache 	Enabled
File Cache 	Disabled
JIT 	Disabled
Startup 	OK
Shared memory model 	mmap
Cache hits 	1338
Cache misses 	200
Used memory 	10399520
Free memory 	123818208
Wasted memory 	0
Interned Strings Used memory 	995568
Interned Strings Free memory 	2149696
Cached scripts 	201
Cached keys 	304
Max keys 	3907
OOM restarts 	0
Hash keys restarts 	0
Comment 18 Henri Hennebert 2023-04-09 12:51:25 UTC
(In reply to Henri Hennebert from comment #17)

To enable jit:

With opcache.jit_buffer_size=128M in php.ini, I hit a crach :-/
Comment 19 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-04-09 13:50:46 UTC
Comment on attachment 241370 [details]
/usr/ports/lang/php81/files/patch-TSRM_TSRM.c

This is not acceptable maybe we should add !defined(__FreeBSD__)
Comment 20 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-04-09 13:52:24 UTC
So far from the log it looks like this is not workable when we are enabling shared libraries so I want to try to disable this and retry once more before making the final call to solve this. As I don't have an aarch64 box at hand at this moment if someone can try and give me some feedback that would be really great.
Comment 21 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-04-09 13:53:16 UTC
Created attachment 241375 [details]
Try disabling shared for aarch64
Comment 22 Henri Hennebert 2023-04-09 14:35:35 UTC
(In reply to Muhammad Moinur Rahman from comment #21)

Same error with this patch of Makefile

ld: error: relocation R_AARCH64_TLSLE_ADD_TPREL_HI12 against _tsrm_ls_cache cannot be used with -shared
Comment 23 Dima Panov freebsd_committer freebsd_triage 2023-04-09 15:53:48 UTC
Created attachment 241379 [details]
Skip bad TSRM code on FreeBSD/aarch64

No need to disable shared, only guard bad aarch64 code with !defined(__FreeBSD__)


Works both for php81 and php82 on m1pro machine
Comment 24 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-04-09 16:45:25 UTC
(In reply to Muhammad Moinur Rahman from comment #19)
> This is not acceptable, maybe we should add !defined(__FreeBSD__)
Maybe we should ask on e.g. -hackers@ to have a look at this code for advice on why existing code does not suit FreeBSD and how it should be written?

(In reply to Muhammad Moinur Rahman from comment #21)
> Try disabling shared for aarch64
I think this is bogus.  The problematic code is still there, you won't solve the problem by trying to mask it out.
Comment 25 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-04-09 16:49:34 UTC
(In reply to Alexey Dokuchaev from comment #24)

> I think this is bogus.  The problematic code is still there, you won't solve the problem by trying to mask it out.

If you see the log the compiler complains about shared whether the code is there or not hence gave it a try.

ld: error: relocation R_AARCH64_TLSLE_ADD_TPREL_HI12 against _tsrm_ls_cache cannot be used with -shared


I will commit fluffy's patch on php82 and get some feedback from all of you about runtime then will commit this on php81 based on the feedback.
Comment 26 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-04-09 16:59:59 UTC
(In reply to Muhammad Moinur Rahman from comment #25)
> I will commit fluffy's patch [...]
Please see the comment #14 about ZEND_ASSERT() in ext/opcache/jit/zend_jit_arm64.dasc before you do.  And I still think you might want to ask our experts if it's possible to fix the code rather than simply disable it.
Comment 27 Dima Panov freebsd_committer freebsd_triage 2023-04-09 18:15:36 UTC
May be temporary add --disable-opcache-jit to CONFIGURE_ARGS for aarch64 to skip JIT usage?
Comment 28 Dima Panov freebsd_committer freebsd_triage 2023-04-09 18:24:12 UTC
Created attachment 241382 [details]
Disable JIT for opcache on aarch64
Comment 29 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-04-10 16:55:39 UTC
Thanks fluffy. I will commit this tonight on php82.

On another note diizzy@ took some time to check whether if it builds with gcc and this is what the findings are:

01:43 <diizzy> using gcc fails with this atomic issue
01:43 <diizzy> http://webapp.org.ua/dev/running-php-5-2-fpm-on-arm-processor/
01:44 <diizzy> and no matter what I throw in terms of flags or even using binutils as linker makes php bomb using clang 14
01:55 <diizzy> php82 also files in the same way
01:59 <diizzy> https://github.com/php/php-src/blob/master/TSRM/TSRM.c#L752
02:03 <diizzy> maybe forcing return 0; fixes it
02:08 <diizzy> it does, if it works correctly is another story
Comment 30 Dima Panov freebsd_committer freebsd_triage 2023-04-11 09:23:00 UTC
(In reply to Muhammad Moinur Rahman from comment #29)
php81 and php82 are identical in this TSRM code, push to the both please :)
Comment 31 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-04-11 16:02:41 UTC
(In reply to Dima Panov from comment #30)
Do we need both the patches or just the later one?
Comment 32 Dima Panov freebsd_committer freebsd_triage 2023-04-11 17:37:10 UTC
(In reply to Muhammad Moinur Rahman from comment #31)
first for TSRM, second is for port's Makefile.

Identical for php81 and php82
Comment 33 commit-hook freebsd_committer freebsd_triage 2023-04-12 05:40:12 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c89b6f2799891129e89d1b4fedf8e25865241060

commit c89b6f2799891129e89d1b4fedf8e25865241060
Author:     Dima Panov <fluffy@FreeBSD.org>
AuthorDate: 2023-04-12 04:05:35 +0000
Commit:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
CommitDate: 2023-04-12 05:39:13 +0000

    lang/php8[12]: Fix build on aarch64 with ZTS

    - Refresh patches

    PR:             266175
    Reported by:    thresh@nginx.com
    Sponsored by:   Bounce Experts

 lang/php81/Makefile                                           |  4 ++++
 lang/php81/files/patch-TSRM_TSRM.c (new)                      | 11 +++++++++++
 lang/php81/files/patch-build_Makefile.global                  |  4 ++--
 lang/php81/files/patch-configure.ac                           |  6 +++---
 lang/php81/files/patch-ext_mysqli_mysqli__nonapi.c            |  6 +++---
 lang/php81/files/patch-ext_mysqli_mysqli__prop.c              |  6 +++---
 lang/php81/files/patch-ext_mysqli_php__mysqli__structs.h      |  6 +++---
 .../files/patch-ext_pcre_pcre2lib_sljit_sljitConfigInternal.h |  4 ++--
 lang/php81/files/patch-sapi_apache2handler_config.m4          |  6 +++---
 lang/php81/files/patch-sapi_fpm_config.m4                     |  4 ++--
 lang/php81/files/patch-sapi_fpm_www.conf.in                   |  4 ++--
 lang/php82/Makefile                                           |  6 +++++-
 lang/php82/files/patch-TSRM_TSRM.c (new)                      | 11 +++++++++++
 lang/php82/files/patch-configure.ac                           | 10 +++++-----
 lang/php82/files/patch-ext_hash_xxhash_xxhash.h               |  4 ++--
 lang/php82/files/patch-sapi_apache2handler_config.m4          |  6 +++---
 lang/php82/files/patch-sapi_fpm_config.m4                     |  4 ++--
 lang/php82/files/patch-sapi_fpm_www.conf.in                   |  4 ++--
 18 files changed, 68 insertions(+), 38 deletions(-)
Comment 34 Christos Chatzaras 2023-04-12 08:54:16 UTC
After fetching the latest port tree I get:

pkg version -vL=
php81-opcache-8.1.17               ?   orphaned: www/php81-opcache
php81-pdo-8.1.17                   ?   orphaned: databases/php81-pdo
php81-pdo_dblib-8.1.17             ?   orphaned: databases/php81-pdo_dblib
php81-pdo_mysql-8.1.17             ?   orphaned: databases/php81-pdo_mysql
php81-pdo_sqlite-8.1.17            ?   orphaned: databases/php81-pdo_sqlite

I believe it's related to this commit.
Comment 35 Dima Panov freebsd_committer freebsd_triage 2023-04-12 10:55:57 UTC
(In reply to commit-hook from comment #33)

+.if ${ARCH} == aarch64
+CONFIGURE_ARGS+=        --disable-opcache-jit
+.else
+CONFIGURE_ARGS+=        --enable-opcache
+.endif

Oh, man. This disable opcache module on aarch64 instead of only jit part. 
There was a reason why I've split arch check from module definition to get a valid string for CONFIGURE_ARGS contains both parts "--enable-opcache --disable-opcache-jit"

Second is ARCH macro is unavailable before including <bsd.ports.pre.mk>
Comment 36 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-04-12 10:58:53 UTC
(In reply to Dima Panov from comment #35)

The whole commit is a mess, if I'd known it would be handled like this, I would've fixed it myself.
Comment 37 commit-hook freebsd_committer freebsd_triage 2023-04-12 12:54:39 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=318b1cc930e6d576fb053ff4acf677ebf7e5ac99

commit 318b1cc930e6d576fb053ff4acf677ebf7e5ac99
Author:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
AuthorDate: 2023-04-12 12:50:59 +0000
Commit:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
CommitDate: 2023-04-12 12:53:27 +0000

    lang/php8[12]: Fix bulk build

    PR:             266175
    Reported by:    fluffy
    Sponsored by:   Bounce Experts

 lang/php81/Makefile | 8 ++++----
 lang/php82/Makefile | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
Comment 38 Henri Hennebert 2023-04-16 09:15:42 UTC
If I read correctly tsrm_get_ls_cache_tcb_offset(void) even on amd64 it return 0.

I try with opcache.jit_buffer_size=128M in php.ini on a amd64 and get httpd exiting with signal 11 when running a php app.