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

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

Open
petk opened this issue Jun 4, 2024 · 4 comments
Open

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

petk opened this issue Jun 4, 2024 · 4 comments

Comments

@petk
Copy link
Member

petk commented Jun 4, 2024

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:

php-src/configure.ac

Lines 242 to 257 in bbbe56e

dnl Disable PIC mode by default where it is known to be safe to do so, to avoid
dnl the performance hit from the lost register.
AC_MSG_CHECKING([whether to force non-PIC code in shared modules])
case $host_alias in
i?86-*-linux*|i?86-*-freebsd*)
if test "${with_pic+set}" != "set" || test "$with_pic" = "no"; then
with_pic=no
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
;;
*)
AC_MSG_RESULT(no)
;;
esac

(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
Copy link
Member

devnexen commented Jun 4, 2024

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
Copy link
Member

devnexen commented Jun 4, 2024

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
Copy link
Member

nielsdos commented Jun 4, 2024

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
Copy link
Contributor

orlitzky commented Jul 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants