Why cc_binary add a default '-Wl,-S' link flag?

65 views
Skip to first unread message

刘宾

unread,
May 11, 2023, 1:38:03 PM5/11/23
to bazel-discuss
I use bazel 6.10.
I run bazel like the following command:
bazel build \
  --platforms         //platforms:k8_clang13_coroutine_debug \
  --host_platform //platforms:k8_clang13_coroutine_debug \
  @protoc_gen_actor//:all


111.jpg
In the link stage there is a link flag '-Wl,-S' which strip the symbol infos from the binary.
So I can't debug.
222.jpg
my code just like this:
----
platforms/BUILD
333.jpg
I use a constraint value to mark debug

----
WORKSPACE
register_toolchains(
 "//toolchains:linux_x86_64_clang13_toolchain_debug"
)

----
.bazelrc
444jpg.jpg

----
toolchains/BUILD
555.jpg

----
toolchains/clang13_toolchain_config.bzl
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
    "tool_path", "feature", "flag_group", "flag_set",
    "env_entry", "env_set")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")

all_link_actions = [
  ACTION_NAMES.cpp_link_executable,
  ACTION_NAMES.cpp_link_dynamic_library,
  ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]

def link_flags(flags=[]):
  return feature(
      name = "default_linker_flags",
      enabled = True,
      flag_sets = [
      flag_set(
        actions = all_link_actions,
        flag_groups = ([
          flag_group(flags = flags),
          ]),
        ),
      ])

def cpp_opts(opts=[]):
  return feature(
      name = "default_cpp_complier",
      enabled = True,
      flag_sets = [
      flag_set(
        actions = [ACTION_NAMES.cpp_compile],
        flag_groups = ([
          flag_group(flags = opts),
          ]),
        ),
      ])

def c_opts(opts=[]):
  return feature(
      name = "default_c_complier",
      enabled = True,
      flag_sets = [
      flag_set(
        actions = [ACTION_NAMES.c_compile],
        flag_groups = ([
          flag_group(flags = opts),
          ]),
        ),
      ])

def _impl_debug(ctx):
    tool_paths = [
        tool_path(
           name = "gcc",
           path = "/usr/local/hologres-devel/bin/clang-13",
        ),
        tool_path(
            name = "ld",
            path = "/apsara/alicpp/built/clang-13/clang-13/bin/lld",
        ),
        tool_path(
            name = "ar",
            path = "/apsara/alicpp/built/clang-13/clang-13/bin/llvm-ar",
        ),
        tool_path(
            name = "cpp",
            path = "/bin/false",
        ),
        tool_path(
            name = "cxx",
            path = "/bin/false",
        ),
        tool_path(
            name = "gcov",
            path = "/bin/false",
        ),
        tool_path(
            name = "nm",
            path = "/bin/false",
        ),
        tool_path(
            name = "objdump",
            path = "/bin/false",
        ),
        tool_path(
            name = "strip",
            path = "/bin/false",
        ),
    ]
    features = [
      link_flags(["-ggdb", "-pthread", "-g", "-O0", "-lstdc++", "-lm", "-pthread"]),
      cpp_opts(["-ggdb", "-pthread", "-g", "-O0", "-std=gnu++17"]),
      c_opts(["-ggdb", "-pthread", "-g", "-O0"]),
    ]
    return cc_common.create_cc_toolchain_config_info(
        ctx = ctx,
        cxx_builtin_include_directories = [
          "/usr/include",
          "/apsara/alicpp/built/clang-13/clang-13",
          "/usr/local/hologres-devel/alicpp2/built/gcc-8.3.0-7u2/gcc-8.3.0/include",
        ],
        toolchain_identifier = "clang13-debug",
        host_system_name = "local",
        target_system_name = "local",
        target_cpu = "x86_64",
        target_libc = "unknown",
        compiler = "clang",
        abi_version = "unknown",
        abi_libc_version = "unknown",
        tool_paths = tool_paths,
        features = features,
    )

clang13_toolchain_config_debug = rule(
    implementation = _impl_debug,
    attrs = {},
    provides = [CcToolchainConfigInfo],
)

刘宾

unread,
May 11, 2023, 1:41:50 PM5/11/23
to bazel-discuss
the project BUILD file content:
cc_binary(
  name = "protoc-gen-actor",
  srcs = glob(["cpp/**/*.cc", "cpp/**/*.h"]),
  copts = [
    "-I external/protoc_gen_actor/cpp",
    "-I external/protoc_gen_actor/cpp/holo/flow",
    "-msse4.2",
    "-Wall",
    "-Werror",
    "-Wsign-compare",
    "-finline-functions",
    "-U_FORTIFY_SOURCE",
  ],
  deps = [
    "@protobuf//:protobuf",
    "@boost//:boost",
  ],
)
Reply all
Reply to author
Forward
0 new messages