From b6a4766d2237f9fcb9a043ef5a2d74a25c69d07b Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Sun, 5 Mar 2023 17:03:10 +1300 Subject: [PATCH] binutils: Allow gold to be statically linked gold uses g++ to link which doesn't recognise -all-static. It appears as if -static should work for both libtool and g++ but for some reason it doesn't. Remove the restriction that gold can't be included in a static toolchain. When a static toolchain is requested pass --with-gold-ldflags=--static to configure. Finally build gold separately so it does not get the extra_make_flags which may contain -all-static. Signed-off-by: Chris Packham --- config/binutils/binutils.in | 1 - scripts/build/binutils/binutils.sh | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config/binutils/binutils.in b/config/binutils/binutils.in index 0744080a..4a91a8f7 100644 --- a/config/binutils/binutils.in +++ b/config/binutils/binutils.in @@ -17,7 +17,6 @@ config BINUTILS_GOLD_SUPPORT bool default y depends on BINUTILS_GOLD_SUPPORTS_ARCH - depends on ! STATIC_TOOLCHAIN # Force using the BFD linker if needed. There are two options: # - For some C libraries (eg. glibc at least), BFD ld must be diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh index 4dc33221..6ae2f7cb 100644 --- a/scripts/build/binutils/binutils.sh +++ b/scripts/build/binutils/binutils.sh @@ -182,6 +182,16 @@ do_binutils_backend() { extra_config+=("--without-zstd") fi + # gold links with CXXLINK/g++, not libtool, and does not understand + # -all-static + if [ "${static_build}" = "y" ]; then + case "${CT_BINUTILS_LINKERS_LIST}" in + *gold*) + extra_config+=("--with-gold-ldflags=--static") + ;; + esac + fi + CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'" CT_DoExecLog CFG \ @@ -211,6 +221,13 @@ do_binutils_backend() { fi CT_DoLog EXTRA "Building binutils" + if [ "${static_build}" = "y" ]; then + case "${CT_BINUTILS_LINKERS_LIST}" in + *gold*) + CT_DoExecLog ALL make -C gold ${CT_JOBSFLAGS} + ;; + esac + fi CT_DoExecLog ALL make "${extra_make_flags[@]}" ${CT_JOBSFLAGS} CT_DoLog EXTRA "Installing binutils"