diff --git a/cc/private/toolchain/unix_cc_configure.bzl b/cc/private/toolchain/unix_cc_configure.bzl index 3a93f9ff8..7b3211072 100644 --- a/cc/private/toolchain/unix_cc_configure.bzl +++ b/cc/private/toolchain/unix_cc_configure.bzl @@ -196,8 +196,13 @@ def _find_linker_path(repository_ctx, cc, linker, is_clang): # Extract linker path from: # /usr/bin/clang ... - # "/usr/bin/ld.lld" -pie -z ... - linker_command = result.stderr.splitlines()[-1] + # "/usr/bin/ld.lld" -pie -z ... + # We use the leading space and quoted path to find invocations. + # https://github.com/llvm/llvm-project/blob/85c78274358717e4d5d019a801decba5c1add484/clang/lib/Driver/Job.cpp#L207-L209 + invocations = [line for line in result.stderr.splitlines() if line.startswith(" \"")] + if not invocations: + return linker + linker_command = invocations[-1] return linker_command.strip().split(" ")[0].strip("\"'") def _add_compiler_option_if_supported(repository_ctx, cc, option):