php / php-src

The PHP Interpreter
https://www.php.net
Other
37.78k stars 7.72k forks source link

Build fails on 32-bit Linux and FreeBSD with Clang #14467

Open petk opened 2 months ago

petk commented 2 months ago

Description

The following code:

./buildconf
./configure
make

Resulted in this output on FreeBSD 14 32-bit with Clang 16.0.6 (default compiler selected by the system):

ld: error: relocation R_386_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in ext/opcache/.libs/zend_accelerator_debug.o
>>> referenced by zend_accelerator_debug.c:58 (ext/opcache/zend_accelerator_debug.c:58)
>>>               ext/opcache/.libs/zend_accelerator_debug.o:(zend_accel_error_va_args)

make: stopped in .../php-src

But I expected this output instead:

# builds successfullly

On Debian 32-bit with Clang this happens:

ext/standard/base64.o: unsupported non-PIC call to IFUNC `php_base64_encode_ex'
/usr/bin/ld: failed to set dynamic section sizes: bad value
/usr/bin/ld: /usr/bin/ld: ext/standard/base64.o: unsupported non-PIC call to IFUNC `ext/standard/base64.ophp_base64_encode_ex: unsupported non-PIC call to IFUNC `'php_base64_encode_ex

When using GCC it works ok. Issue is that there is a check to disable PIC mode for shared extensions on 32-bit Linux and FreeBSD: https://github.com/php/php-src/blob/bbbe56eecc6ff6b3971ba4f924d51c9aa11955c5/configure.ac#L242-L257

(Probably solution would be to skip the non-PIC mode for Clang on 32-bit)

PHP Version

PHP 8.2, 8.3 and 8.4-dev

Operating System

32-bit Linux and FreeBSD

devnexen commented 2 months ago

Might not be related but ifunc had been disabled for quite a time on freebsd then had been enabled for freebsd >= 12 months ago. But nielsdos was willing to look into this I believe so we ll see :)

devnexen commented 2 months ago

To keep in mind for future update

FreeBSD 15.0 is not expected to include support for 32-bit platforms other than armv7. The armv6, i386, and powerpc platforms are deprecated and will be removed. 64-bit systems will still be able to run older 32-bit binaries.

We expect to support armv7 as a Tier 2 architecture in FreeBSD 15.0 and stable/15. However, we also anticipate that armv7 may be removed in FreeBSD 16.0. We will provide an update on the status of armv7 for both 15.x and 16.x at the time of 15.0 release.

Support for executing 32-bit binaries on 64-bit platforms via the COMPAT_FREEBSD32 option will continue for at least the stable/15 and stable/16 branches. Support for compiling individual 32-bit applications via cc -m32 will also continue for at least the stable/15 branch, which includes suitable headers in /usr/include and libraries in /usr/lib32.

Ports will not include support for deprecated 32-bit platforms for FreeBSD 15.0 and later releases. These future releases will not include binary packages or support for building packages from ports for deprecated 32-bit platforms.
nielsdos commented 2 months ago

I can reproduce this for FreeBSD at least, didn't test for Linux (yet). The FreeBSD issue is not related to ifuncs but is simply because the opcache dso in this case is not built with PIC. I guess it should be auto-enabled on this platform.

You can reproduce the problem simply with:

int x;
int foo(void) { return x; }

Compile with clang -shared file.c -o file.so and observe the same error.

It doesn't happen on 64-bit because IIRC fPIC is mandatory there.

orlitzky commented 1 month ago

We have a report of this as well with our hardened gcc: https://bugs.gentoo.org/930145