package/gcc: ensure __register_frame is optimized out for glibc

On some architectures when building with -O0 the __register_frame
symbol fails to get optimized out which can cause linking failures
when building glibc.

To fix this set -O1 for GCC target libs when building with glibc
and BR2_OPTIMIZE_0 on the problematic target architectures.

This was reported both to GCC [1] and glibc [2] upstream. It is not
entirely clear yet where the bug lies exactly. At the moment the
assumption is that it's GCC, so create a symbol
BR2_TOOLCHAIN_HAS_GCC_BUG_107728.

This issue only seems to occur when linking glibc, not with anything
else, so only compile libgcc from host-gcc-initial with -O1.

Fixes:
 - http://autobuild.buildroot.net/results/89b/89b6c6924240b7cf82035a844f3573673e91b364
 - http://autobuild.buildroot.net/results/46f/46f4ec99d2b23d354a4bb5e92123d64f0da6ed27
 - http://autobuild.buildroot.net/results/839/839f929f700cf181ebdf34389c7806a96f55813e
 - http://autobuild.buildroot.net/results/0e2/0e202bf53a683930f3cad6edef2a4dea629eaecb
 - http://autobuild.buildroot.net/results/8a8/8a8c917f597fdcca744e696e19e9300b64004335
 - http://autobuild.buildroot.net/results/c05/c058b27ed2834dfa633b63ec6c3639ab1e8bf412
 - http://autobuild.buildroot.net/results/8ba/8ba8882a861cf7df359c23969c09b2be0725b2e5

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107728
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=29621

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
2022.11.x
James Hilliard 2022-10-28 16:38:44 -06:00 committed by Arnout Vandecappelle
parent f324758f67
commit 0fc5c1ccdb
2 changed files with 19 additions and 0 deletions

View File

@ -43,6 +43,13 @@ HOST_GCC_INITIAL_CONF_OPTS = \
HOST_GCC_INITIAL_CONF_ENV = \
$(HOST_GCC_COMMON_CONF_ENV)
# Enable GCC target libs optimizations to optimize out __register_frame
# when needed for some architectures when building with glibc.
ifeq ($(BR2_TOOLCHAIN_HAS_GCC_BUG_107728),y)
HOST_GCC_INITIAL_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS) -O1"
HOST_GCC_INITIAL_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS) -O1"
endif
HOST_GCC_INITIAL_MAKE_OPTS = $(HOST_GCC_COMMON_MAKE_OPTS) all-gcc all-target-libgcc
HOST_GCC_INITIAL_INSTALL_OPTS = install-gcc install-target-libgcc

View File

@ -227,6 +227,18 @@ config BR2_TOOLCHAIN_HAS_GCC_BUG_104028
bool
default y if BR2_m68k
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107728
# https://sourceware.org/bugzilla/show_bug.cgi?id=29621
config BR2_TOOLCHAIN_HAS_GCC_BUG_107728
bool
depends on BR2_TOOLCHAIN_USES_GLIBC
depends on BR2_OPTIMIZE_0
default y if BR2_microblazebe || BR2_microblazeel \
|| BR2_mips || BR2_mipsel \
|| BR2_nios2 \
|| BR2_or1k \
|| BR2_sh
config BR2_TOOLCHAIN_HAS_NATIVE_RPC
bool