Build swoole-cli for Old Machines

swoole-cli is a static build of php cli, with many bundled extensions.

I love static binary.

But the official build failed on my old machine (Pentium T4500).

Illegal instruction ?

When I run the official binary, I got an Illegal instruction error:

$ ./swoole-cli
Illegal instruction (core dumped)

Seems my CPU is too old, and the official is built for modern CPUs.

I tried to build swoole-cli on my machine, but it still fails.

Let's see which instruction cause the problem with gdb.

$ gdb ./swoole-cli
(gdb) r
Program received signal SIGILL, Illegal instruction.
0x00000000007d01fc in zend_register_constant (c=c@entry=0x7fffffffd548) at Zend/zend_constants.c:586
586     Zend/zend_constants.c: No such file or directory.

(gdb) disassemble 0x7d01fc
...
   0x00000000007d01e8 <+228>:   pxor   0x12b2040(%rip),%xmm1        # 0x1a82230
   0x00000000007d01f0 <+236>:   pxor   0x12b2048(%rip),%xmm0        # 0x1a82240
   0x00000000007d01f8 <+244>:   por    %xmm1,%xmm0
=> 0x00000000007d01fc <+248>:   ptest  %xmm0,%xmm0
   0x00000000007d0201 <+253>:   jne    0x7d0229 <zend_register_constant+293>
   0x00000000007d0203 <+255>:   jmp    0x7d029f <zend_register_constant+411>
   0x00000000007d0208 <+260>:   test   $0x1,%r13b
...

Aha, ptest is introduced in SSE4.1, which is not support by my Pentium CPU.

Why SSE4.1

So the build system doesn't build based on my CPU, and it's hard-coded to use SSE4.1 .

I skim through the sapi/make.php script, and find this line:

make EXTRA_CFLAGS='-fno-ident -Xcompiler -march=nehalem -Xcompiler -mtune=haswell -Os

Okay, I change both -march and -mtune to native.

Rebuild and it runs correctly.

$ ./swoole-cli -v
Swoole 5.0.1 (cli) (built: Dec 28 2022 15:03:25) (NTS)
Kauruus
CC BY-SA 4.0
Website built with Franklin.jl and the Julia programming language.