commit: 2283662d49266d652f171cd6b75798166a86335b
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 21 03:59:08 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug 16 17:21:18 2024 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2283662d
toolchain-funcs.eclass: add tc-ld-is-bfd
This matches tc-ld-is-gold and tc-ld-is-lld.
Signed-off-by: Sam James <sam <AT> gentoo.org>
eclass/toolchain-funcs.eclass | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 50eb310b4bf1..121280a7f11f 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -447,6 +447,41 @@ econf_build() {
tc-env_build econf_env "$@"
}
+# @FUNCTION: tc-ld-is-bfd
+# @USAGE: [toolchain prefix]
+# @DESCRIPTION:
+# Return true if the current linker is set to GNU bfd.
+tc-ld-is-bfd() {
+ local out
+
+ # Ensure ld output is in English.
+ local -x LC_ALL=C
+
+ # First check the linker directly.
+ out=$($(tc-getLD "$@") --version 2>&1)
+ if [[ ${out} != "GNU ld"* ]] ; then
+ return 1
+ fi
+
+ # Then see if they're selecting bfd via compiler flags.
+ # Note: We're assuming they're using LDFLAGS to hold the
+ # options and not CFLAGS/CXXFLAGS.
+ local base="${T}/test-tc-bfd"
+ cat <<-EOF > "${base}.c"
+ int main(void) { return 0; }
+ EOF
+ out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version
"${base}.c" -o "${base}" 2>&1)
+ rm -f "${base}"*
+ if [[ ${out} != "GNU ld"* ]] ; then
+ return 1
+ fi
+
+ # It's bfd!
+ # We use positive logic here unlike tc-ld-is-gold and tc-ld-is-mold
+ # because LD might be bfd even if *FLAGS isn't.
+ return 0
+}
+
# @FUNCTION: tc-ld-is-gold
# @USAGE: [toolchain prefix]
# @DESCRIPTION: