From c579155a3ed7c4a9e4745c11a9c9550ec4c121ab Mon Sep 17 00:00:00 2001 From: Wren Turkal Date: Mon, 20 Sep 2021 04:48:10 -0700 Subject: [PATCH] Add ld path to binary search path when appropriate. The binary search path does not presently include the path of ld if the path of ld differs from the path of the cc compiler. This change adds the path of ld when its path differs from that of the cc compiler. Fixes: #13857 Closes #13942. PiperOrigin-RevId: 397720260 --- tools/cpp/unix_cc_configure.bzl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl index 371b66fe6a4062..27e46531461b34 100644 --- a/tools/cpp/unix_cc_configure.bzl +++ b/tools/cpp/unix_cc_configure.bzl @@ -424,11 +424,14 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools): cc_path = repository_ctx.path(cc) if not str(cc_path).startswith(str(repository_ctx.path(".")) + "/"): # cc is outside the repository, set -B - bin_search_flag = ["-B" + escape_string(str(cc_path.dirname))] + bin_search_flags = ["-B" + escape_string(str(cc_path.dirname))] else: # cc is inside the repository, don't set -B. - bin_search_flag = [] - + bin_search_flags = [] + if not gold_or_lld_linker_path: + ld_path = repository_ctx.path(tool_paths["ld"]) + if ld_path.dirname != cc_path.dirname: + bin_search_flags.append("-B" + str(ld_path.dirname)) coverage_compile_flags, coverage_link_flags = _coverage_flags(repository_ctx, darwin) builtin_include_directories = _uniq( _get_cxx_include_directories(repository_ctx, cc, "-xc") + @@ -566,7 +569,7 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools): "-undefined", "dynamic_lookup", "-headerpad_max_install_names", - ] if darwin else bin_search_flag + [ + ] if darwin else bin_search_flags + [ # Gold linker only? Can we enable this by default? # "-Wl,--warn-execstack", # "-Wl,--detect-odr-violations"