commit: 6b15667b8830964c37231fa5496a60a824dc85b6
Author: Z. Liu <zhixu.liu <AT> gmail <DOT> com>
AuthorDate: Tue Dec 23 11:49:10 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Dec 24 16:33:57 2025 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6b15667b
toolchain-funcs.eclass: fix pattern for detecting ld.bfd
See the test case below:
> out=$(echo -e "abcdef\n123456"); [[ ${out} =~ .*^"123456".* ]] && echo
> "matched" || echo "not matched"
This prints "matched" when using glibc, but "not matched" when using musl.
The root cause is that using ^ in the middle of the regex is undefined behavior.
Replace it with (^|$'\n'), i.e. match either the beginning of the string or a
position immediately following a newline.
Signed-off-by: Z. Liu <zhixu.liu <AT> gmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/45136
Closes: https://github.com/gentoo/gentoo/pull/45136
Signed-off-by: Sam James <sam <AT> gentoo.org>
eclass/toolchain-funcs.eclass | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 3787a84805f6..3f820c2d8559 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -474,7 +474,7 @@ tc-ld-is-bfd() {
EOF
out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version
"${base}.c" -o "${base}" 2>&1)
rm -f "${base}"*
- if [[ ! ${out} =~ .*^"GNU ld".* ]] ; then
+ if [[ ! ${out} =~ (^|$'\n')"GNU ld".* ]] ; then
return 1
fi