[php-src] Issue #12349: Linking failure on `ARM` with `mold`
| From: | jpalus | Date: | Mon, 02 Oct 2023 21:04:07 +0000 |
| Subject: | [php-src] Issue #12349: Linking failure on `ARM` with `mold` | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245482@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12349
Author: jpalus
### Description
Building
PHP 8.2.11 on ARM (32-bit) using mold 2.2.0 as
linker fails with following errors (shortened for readability):
```console
/bin/sh /home/users/builder/rpm/BUILD/php-8.2.11/libtool --silent --preserve-dup-deps --tag CC
--mode=link /usr/libexec/icecc/bin/g++ -shared ... -o ext/intl/intl.la ... -Wl,-fuse-ld=mold ...
mold: error: ext/intl/msgformat/.libs/msgformat_helpers.o:(.ARM.extab): R_ARM_PREL31 relocation at
offset 0x0 against symbol `__gxx_personality_v0' can not be used; recompile with -fPIC
mold: error: ext/intl/msgformat/.libs/msgformat_helpers.o:(.ARM.extab): R_ARM_PREL31 relocation at
offset 0x28 against symbol `__gxx_personality_v0' can not be used; recompile with -fPIC
mold: error:
ext/intl/msgformat/.libs/msgformat_helpers.o:(.ARM.extab.text._ZNSt6vectorIN6icu_7311FormattableESaIS1_EE17_M_default_appendEj):
R_ARM_PREL31 relocation at offset 0x0 against sym
bol `__gxx_personality_v0' can not be used; recompile with -fPIC
mold: error: ext/intl/breakiterator/.libs/codepointiterator_internal.o:(.ARM.extab): R_ARM_PREL31
relocation at offset 0xc against symbol `__gxx_personality_v0' can not be used; recompile wit
h -fPIC
...
```
How it works with binutils is not clear to me, however the reason why it fails with
mold is somewhat hidden by the use of --silent flag passed to
libtool. If it's dropped then that's the exact command being run by
libtool:
```console
/bin/sh /home/users/builder/rpm/BUILD/php-8.2.11/libtool --preserve-dup-deps --tag CC --mode=link
/usr/libexec/icecc/bin/g++ ...
libtool: link: /usr/libexec/icecc/bin/gcc -shared -fPIC -DPIC ...
```
Even though C++ compiler was passed to libtool invocation, C compiler was used for
linking in the end. For linking libtool prefers compiler set with --tag:
```sh
# Commands used to build a shared archive.
archive_cmds="\$CC -shared \$pic_flag \$compiler_flags \$libobjs \$deplibs \$wl-soname
\$wl\$soname -o \$lib"
```
$CC evaluates to compiler determined during configure time and follows
settings for current --tag so either C compiler for --tag=CC or C++
compiler for --tag=CXX. Unfortunately PHP is using single global
--tag setting:
https://github.com/php/php-src/blob/bdc87b0f66666e188e35d61b9ad9199db378c4ab/configure.ac#L1575
Since all compile/link commands already have logic for using either C or C++ compiler in
libtool invocation I think it would be reasonable to drop global --tag
parameter and shift it to individual libtool invocations so it matches with expected
compiler.
### PHP Version
PHP 8.2.11
### Operating System
PLD Linux