如何配置bazel以运行地址/内存清理器?



我在bazel中有项目,具有非常简单的bulid规则

cc_binary(
name = "search",
srcs = [
"iterator_range.h",
"main.cpp",
"parse.cpp",
"parse.h",
"search_server.cpp",
"search_server.h",
"test_runner.h",
"profile.h",
]
)

我越来越Segmentation fault 11

我尝试使用此配置但出现错误

every rule of type cc_binary implicitly depends upon the target '//tools/lrte:toolchain', but this target coul
d not be found because of: no such package 'tools/lrte': BUILD file not found in any of the following directories

我试图在tools/lrte处添加BUILD文件,但它导致了更多像no such attribute 'dynamic_runtime_libs' in 'cc_toolchain' rule这样的错误。

文档说:

默认情况下,Bazel 会自动为您的构建配置 CcToolchainConfigInfo,但您可以选择手动配置它。

由于我不想手动进行工具链配置(我认为(,我试图从.bazelrc中删除build:asan --crosstool_top //tools/lrte:toolchain行。然后我还必须删除关于编译器的第二行,它起作用了。所以我的最终.bazelrc(.bazelrc应该WORKSPACE相同的目录(配置如下所示:

build:asan --strip=never
build:asan --copt -fsanitize=address
build:asan --copt -DADDRESS_SANITIZER
build:asan --copt -O1
build:asan --copt -g
build:asan --copt -fno-omit-frame-pointer
build:asan --linkopt -fsanitize=address

使用地址清理器运行 bazel 的方法:

bazel build -c dbg --config=asan path/to/module:target
bazel run -c dbg --config=asan path/to/module:target

最新更新