@kshyanashree Please cherry pick https://github.com/bazelbuild/bazel/commit/cd40666001e8d599bb61735898c195c6d2fae55b to close this one, thanks!  After cherry pick this one, we can create rc3 ;) > @kshyanashree Please cherry pick [cd40666](https://github.com/bazelbuild/bazel/commit/cd40666001e8d599bb61735898c195c6d2fae55b) to close this one, thanks!

Hi @meteorcloudy ! I have already cherry-picked this one here , but  check is failing due to missing CLA #16886 . Wanted to check with you. Thanks! For some reason the original commit was showing up as being authored by "noreply@google.com", which can't pass the CLA check. I think we can just force merge that PR. Merged in #16886

Let's create an rc3! Sure, Thanks @Wyverald!
[6.0.0] Missing linkopts when building a cc_test
Forked from #16877
src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
diff --git a/src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl b/src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
index 48a4f684d641fd..23982806a59d4d 100644
--- a/src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
+++ b/src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
@@ -366,12 +366,6 @@ def _get_preloaded_deps_from_dynamic_deps(ctx):
 
     return cc_common.merge_cc_infos(direct_cc_infos = cc_infos, cc_infos = cc_infos).linking_context.linker_inputs.to_list()
 
-def _get_canonical_form(label):
-    repository = label.workspace_name
-    if repository == "@":
-        repository = ""
-    return repository + "//" + label.package + ":" + label.name
-
 def _filter_libraries_that_are_linked_dynamically(ctx, cc_linking_context, cpp_config):
     merged_cc_shared_library_infos = merge_cc_shared_library_infos(ctx)
     preloaded_deps = _get_preloaded_deps_from_dynamic_deps(ctx)
@@ -399,7 +393,7 @@ def _filter_libraries_that_are_linked_dynamically(ctx, cc_linking_context, cpp_c
             continue
         linker_inputs_seen[stringified_linker_input] = True
         owner = str(linker_input.owner)
-        if owner not in link_dynamically_labels and (owner in link_statically_labels or _get_canonical_form(ctx.label) == owner):
+        if owner not in link_dynamically_labels and (owner in link_statically_labels or str(ctx.label) == owner):
             if owner in link_once_static_libs_map:
                 linked_statically_but_not_exported.setdefault(link_once_static_libs_map[owner], []).append(owner)
             else:
