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

Linking failure on ARM with mold #12349

Closed
jpalus opened this issue Oct 2, 2023 · 0 comments
Closed

Linking failure on ARM with mold #12349

jpalus opened this issue Oct 2, 2023 · 0 comments

Comments

@jpalus
Copy link
Contributor

jpalus commented Oct 2, 2023

Description

Building PHP 8.2.11 on ARM (32-bit) using mold 2.2.0 as linker fails with following errors (shortened for readability):

/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:

/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:

# 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:

PHP_SET_LIBTOOL_VARIABLE([--tag CC])

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

jpalus added a commit to jpalus/php-src that referenced this issue Oct 2, 2023
Global --tag=CC defined in configure.ac is not correct in all cases. For example
linking objects that were compiled from C++ sources needs to be done with C++
compiler, however for link mode libtool will prefer compiler indicated with
--tag.

Fixes phpGH-12349
jpalus added a commit to jpalus/php-src that referenced this issue Oct 2, 2023
Global --tag=CC defined in configure.ac is not correct in all cases. For example
linking objects that were compiled from C++ sources needs to be done with C++
compiler, however for link mode libtool will prefer compiler indicated with
--tag.

Fixes phpGH-12349
@petk petk closed this as completed in d57a776 Jan 10, 2024
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

2 participants