Skip to content

Commit b766c6f

Browse files
committed
Added initial support for --config=asanwin - ASAN for Windows through LLVM installed in Program Files
1 parent 573d36e commit b766c6f

File tree

7 files changed

+71
-31
lines changed

7 files changed

+71
-31
lines changed

.bazelrc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ test --test_tag_filters=-jaeger,-opentracing,-opentracing_shim,-etw,-es,-prometh
2626
build --experimental_convenience_symlinks=clean
2727

2828
build:windows --copt="/Brepro" --copt="/guard:cf" --copt="/guard:ehcont" --copt="/Z7" --copt="/JMC-" --copt="/sdl"
29+
build:windows --host_copt="/Brepro" --copt="/guard:cf" --copt="/guard:ehcont" --copt="/Z7" --copt="/JMC-" --copt="/sdl"
2930
build:windows --linkopt="/Brepro" --linkopt="/guard:cf" --linkopt="/guard:ehcont" --linkopt="/DEBUG:FULL" --linkopt="/CETCOMPAT" --linkopt="/SWAPRUN:NET,CD" --linkopt="/OPT:REF,NOICF" --linkopt="/RELEASE" --linkopt="/DEBUGTYPE:CV,PDATA,FIXUP"
30-
build:windows --copt="/Zc:strictStrings"
31-
build:windows --copt="/Gy"
31+
build:windows --host_linkopt="/Brepro" --linkopt="/guard:cf" --linkopt="/guard:ehcont" --linkopt="/DEBUG:FULL" --linkopt="/CETCOMPAT" --linkopt="/SWAPRUN:NET,CD" --linkopt="/OPT:REF,NOICF" --linkopt="/RELEASE" --linkopt="/DEBUGTYPE:CV,PDATA,FIXUP"
32+
build:windows --copt="/Zc:strictStrings" --copt="/Gy"
33+
build:windows --host_copt="/Zc:strictStrings" --copt="/Gy"
3234
build:windows --host_linkopt="shell32.lib"
3335
# Requires Visual Studio 2019 Build Tools installed in default location with the latest compiler (14.29.30133) for x64
3436
build:windows --action_env=BAZEL_VC_FULL_VERSION=14.42.34433 --action_env=BAZEL_WINSDK_FULL_VERSION=10.0.22621.0
@@ -56,6 +58,16 @@ build:macos --action_env=CC=/opt/homebrew/opt/llvm/bin/clang
5658
build:macos --host_action_env=CC=/opt/homebrew/opt/llvm/bin/clang
5759
#build:macos --apple_generate_dsym --output_groups=+dsyms
5860

61+
# Windows specific asan setup
62+
# common:asanwin --copt -fsanitize=address,bool,float-cast-overflow,integer-divide-by-zero,null,return,returns-nonnull-attribute,shift-exponent,signed-integer-overflow,unreachable,vla-bound
63+
common:asanwin --copt -fsanitize=address,bool,float-cast-overflow,integer-divide-by-zero,null,return,returns-nonnull-attribute,shift-exponent,unreachable,vla-bound
64+
common:asanwin --copt -fsanitize-address-use-after-scope
65+
common:asanwin --copt -fno-sanitize-recover=all
66+
common:asanwin --copt -fno-sanitize-ignorelist --copt -MD
67+
common:asanwin --test_env=ASAN_OPTIONS=report_globals=0:detect_odr_violation=0
68+
common:asanwin --cc_output_directory_tag=asanwin
69+
common:asanwin --@otel_sdk//:asanwin=true
70+
5971
# --config=asan : Address Sanitizer.
6072
common:asan --copt -DADDRESS_SANITIZER
6173
common:asan --copt -fsanitize=address,bool,float-cast-overflow,integer-divide-by-zero,null,return,returns-nonnull-attribute,shift-exponent,signed-integer-overflow,unreachable,vla-bound
@@ -158,7 +170,6 @@ build --host_copt="-DGRPC_NO_ABSL_SYNC"
158170
# disable all GRPC experiments
159171
# build --define=grpc_experiments_are_final=true
160172

161-
162173
## This is what my ../top.bazelrc contains (not in the repo as local to my machine)
163174
# build --disk_cache=f:/b/d
164175
# common --repository_cache=f:/b/r

BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ config_setting(
2626
},
2727
)
2828

29+
bool_flag(
30+
name = "asanwin",
31+
build_setting_default = False,
32+
)
33+
34+
config_setting(
35+
name = "asanwin_enabled",
36+
flag_values = {
37+
"asanwin": "true",
38+
},
39+
)
40+
2941
otel_cc_library(
3042
name = "windows_only",
3143
target_compatible_with = select({

MODULE.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bazel_dep(name = "depend_on_what_you_use", version = "0.9.0")
1313
bazel_dep(name = "google_benchmark", version = "1.9.4")
1414
bazel_dep(name = "googletest", version = "1.17.0")
1515
bazel_dep(name = "re2", version = "2024-07-02.bcr.1")
16-
bazel_dep(name = "rules_go", version = "0.55.1")
16+
bazel_dep(name = "rules_go", version = "0.54.1")
1717
bazel_dep(name = "gazelle", version = "0.43.0")
1818
bazel_dep(name = "stardoc", version = "0.8.0")
1919
bazel_dep(name = "rules_android", version = "0.6.4")
@@ -62,6 +62,14 @@ use_repo(
6262
#
6363
bazel_dep(name = "grpc-java", version = "1.71.0")
6464

65+
new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
66+
67+
new_local_repository(
68+
name = "llvm_windows_install",
69+
build_file = "@otel_sdk//bazel:llvm_windows_install.BUILD",
70+
path = "C:/Program Files/LLVM",
71+
)
72+
6573
multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
6674
multitool.hub(lockfile = "@otel_sdk//:multitool.lock.json")
6775
use_repo(multitool, "multitool")

bazel/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ config_setting(
77
name = "windows",
88
constraint_values = ["@platforms//os:windows"],
99
)
10+
11+
exports_files([
12+
"llvm_windows_install.BUILD",
13+
])

bazel/llvm_windows_install.BUILD

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ASAN_FOLDER = "lib/clang/20/lib/windows/"
2+
3+
cc_import(
4+
name = "asan1",
5+
interface_library = ASAN_FOLDER + "clang_rt.asan_dynamic-x86_64.lib",
6+
shared_library = ASAN_FOLDER + "clang_rt.asan_dynamic-x86_64.dll",
7+
#alwayslink = 1,
8+
visibility = ["//visibility:public"],
9+
)
10+
11+
cc_import(
12+
name = "asan2",
13+
static_library = ASAN_FOLDER + "clang_rt.asan_dynamic_runtime_thunk-x86_64.lib",
14+
#alwayslink = 1,
15+
visibility = ["//visibility:public"],
16+
)
17+
18+
cc_library(
19+
name = "asan",
20+
deps = ["asan1", "asan2"],
21+
#alwayslink = 1,
22+
visibility = ["//visibility:public"],
23+
)

bazel/otel_cc.bzl

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,34 @@ load(
99
rules_cc_test = "cc_test",
1010
)
1111

12-
13-
def _is_windows_impl(ctx):
14-
if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]):
15-
return [DefaultInfo()]
16-
else:
17-
return [DefaultInfo()]
18-
19-
is_windows = rule(
20-
implementation = _is_windows_impl,
21-
attrs = {
22-
'_windows_constraint': attr.label(default = '@platforms//os:windows'),
23-
},
24-
)
25-
12+
def if_asanwin(a):
13+
return select({
14+
"@otel_sdk//:asanwin_enabled": a,
15+
"//conditions:default": [],
16+
})
2617

2718
def otel_cc_library(**kwargs):
28-
# dump = kwargs["name"] + ": "
29-
# dump = dump + " mod=" + native.module_name()
30-
# dump = dump + " ver=" + native.module_version()
31-
# dump = dump + " pkg=" + native.package_name()
32-
# dump = dump + " repo=" + native.repo_name()
33-
# print(dump)
34-
3519
# Link as .o (.obj) files, not .a (.lib)
3620
kwargs["alwayslink"] = kwargs.get("alwayslink", True)
37-
3821
# Don't create .so files for dbg/fastbuild, always create static libs
3922
kwargs["linkstatic"] = kwargs.get("linkstatic", True)
40-
41-
# x = is_windows(name=kwargs["name"]+"_is_windows")
42-
# print(x)
43-
4423
rules_cc_library(**kwargs)
4524

4625
def otel_cc_test_library(**kwargs):
4726
kwargs["testonly"] = kwargs.get("testonly", True)
4827
otel_cc_library(**kwargs)
4928

5029
def otel_cc_binary(**kwargs):
30+
kwargs["deps"] = kwargs.get("deps", []) + if_asanwin(["@llvm_windows_install//:asan"])
5131
rules_cc_binary(**kwargs)
5232

5333
def otel_cc_test(**kwargs):
34+
kwargs["deps"] = kwargs.get("deps", []) + if_asanwin(["@llvm_windows_install//:asan"])
5435
rules_cc_test(**kwargs)
5536

5637
def otel_cc_import(**kwargs):
5738
rules_cc_import(**kwargs)
5839

5940
def otel_cc_shared_library(**kwargs):
41+
kwargs["deps"] = kwargs.get("deps", []) + if_asanwin(["@llvm_windows_install//:asan"])
6042
native.cc_shared_library(**kwargs)

sdk/test/logs/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ otel_cc_test(
9797
]),
9898
)
9999

100-
cc_test(
100+
otel_cc_test(
101101
name = "logger_config_test",
102102
srcs = [
103103
"logger_config_test.cc",

0 commit comments

Comments
 (0)