• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright 2017 The Abseil Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
18load(
19    "//absl:copts/configure_copts.bzl",
20    "ABSL_DEFAULT_COPTS",
21    "ABSL_DEFAULT_LINKOPTS",
22    "ABSL_TEST_COPTS",
23)
24
25package(
26    default_visibility = ["//visibility:public"],
27)
28
29licenses(["notice"])
30
31cc_library(
32    name = "stacktrace",
33    srcs = [
34        "internal/stacktrace_aarch64-inl.inc",
35        "internal/stacktrace_arm-inl.inc",
36        "internal/stacktrace_config.h",
37        "internal/stacktrace_generic-inl.inc",
38        "internal/stacktrace_powerpc-inl.inc",
39        "internal/stacktrace_unimplemented-inl.inc",
40        "internal/stacktrace_win32-inl.inc",
41        "internal/stacktrace_x86-inl.inc",
42        "stacktrace.cc",
43    ],
44    hdrs = ["stacktrace.h"],
45    copts = ABSL_DEFAULT_COPTS,
46    linkopts = ABSL_DEFAULT_LINKOPTS,
47    deps = [
48        ":debugging_internal",
49        "//absl/base:config",
50        "//absl/base:core_headers",
51    ],
52)
53
54cc_library(
55    name = "symbolize",
56    srcs = [
57        "symbolize.cc",
58        "symbolize_darwin.inc",
59        "symbolize_elf.inc",
60        "symbolize_unimplemented.inc",
61        "symbolize_win32.inc",
62    ],
63    hdrs = [
64        "internal/symbolize.h",
65        "symbolize.h",
66    ],
67    copts = ABSL_DEFAULT_COPTS,
68    linkopts = ABSL_DEFAULT_LINKOPTS + select({
69        "//absl:windows": ["-DEFAULTLIB:dbghelp.lib"],
70        "//conditions:default": [],
71    }),
72    deps = [
73        ":debugging_internal",
74        ":demangle_internal",
75        "//absl/base",
76        "//absl/base:config",
77        "//absl/base:core_headers",
78        "//absl/base:dynamic_annotations",
79        "//absl/base:malloc_internal",
80        "//absl/base:raw_logging_internal",
81        "//absl/strings",
82    ],
83)
84
85cc_test(
86    name = "symbolize_test",
87    srcs = ["symbolize_test.cc"],
88    copts = ABSL_TEST_COPTS + select({
89        "//absl:windows": ["/Z7"],
90        "//conditions:default": [],
91    }),
92    linkopts = ABSL_DEFAULT_LINKOPTS + select({
93        "//absl:windows": ["/DEBUG"],
94        "//conditions:default": [],
95    }),
96    deps = [
97        ":stack_consumption",
98        ":symbolize",
99        "//absl/base",
100        "//absl/base:config",
101        "//absl/base:core_headers",
102        "//absl/base:raw_logging_internal",
103        "//absl/memory",
104        "//absl/strings",
105        "@com_google_googletest//:gtest",
106    ],
107)
108
109cc_library(
110    name = "examine_stack",
111    srcs = [
112        "internal/examine_stack.cc",
113    ],
114    hdrs = [
115        "internal/examine_stack.h",
116    ],
117    copts = ABSL_DEFAULT_COPTS,
118    linkopts = ABSL_DEFAULT_LINKOPTS,
119    visibility = ["//visibility:private"],
120    deps = [
121        ":stacktrace",
122        ":symbolize",
123        "//absl/base:config",
124        "//absl/base:core_headers",
125        "//absl/base:raw_logging_internal",
126    ],
127)
128
129cc_library(
130    name = "failure_signal_handler",
131    srcs = ["failure_signal_handler.cc"],
132    hdrs = ["failure_signal_handler.h"],
133    copts = ABSL_DEFAULT_COPTS,
134    linkopts = ABSL_DEFAULT_LINKOPTS,
135    deps = [
136        ":examine_stack",
137        ":stacktrace",
138        "//absl/base",
139        "//absl/base:config",
140        "//absl/base:core_headers",
141        "//absl/base:errno_saver",
142        "//absl/base:raw_logging_internal",
143    ],
144)
145
146cc_test(
147    name = "failure_signal_handler_test",
148    srcs = ["failure_signal_handler_test.cc"],
149    copts = ABSL_TEST_COPTS,
150    linkopts = select({
151        "//absl:windows": [],
152        "//absl:wasm": [],
153        "//conditions:default": ["-pthread"],
154    }) + ABSL_DEFAULT_LINKOPTS,
155    deps = [
156        ":failure_signal_handler",
157        ":stacktrace",
158        ":symbolize",
159        "//absl/base:raw_logging_internal",
160        "//absl/strings",
161        "@com_google_googletest//:gtest",
162    ],
163)
164
165cc_library(
166    name = "debugging_internal",
167    srcs = [
168        "internal/address_is_readable.cc",
169        "internal/elf_mem_image.cc",
170        "internal/vdso_support.cc",
171    ],
172    hdrs = [
173        "internal/address_is_readable.h",
174        "internal/elf_mem_image.h",
175        "internal/vdso_support.h",
176    ],
177    copts = ABSL_DEFAULT_COPTS,
178    linkopts = ABSL_DEFAULT_LINKOPTS,
179    deps = [
180        "//absl/base:config",
181        "//absl/base:core_headers",
182        "//absl/base:dynamic_annotations",
183        "//absl/base:errno_saver",
184        "//absl/base:raw_logging_internal",
185    ],
186)
187
188cc_library(
189    name = "demangle_internal",
190    srcs = ["internal/demangle.cc"],
191    hdrs = ["internal/demangle.h"],
192    copts = ABSL_DEFAULT_COPTS,
193    deps = [
194        "//absl/base",
195        "//absl/base:config",
196        "//absl/base:core_headers",
197    ],
198)
199
200cc_test(
201    name = "demangle_test",
202    srcs = ["internal/demangle_test.cc"],
203    copts = ABSL_TEST_COPTS,
204    linkopts = ABSL_DEFAULT_LINKOPTS,
205    deps = [
206        ":demangle_internal",
207        ":stack_consumption",
208        "//absl/base:config",
209        "//absl/base:core_headers",
210        "//absl/base:raw_logging_internal",
211        "//absl/memory",
212        "@com_google_googletest//:gtest_main",
213    ],
214)
215
216cc_library(
217    name = "leak_check",
218    srcs = ["leak_check.cc"],
219    hdrs = ["leak_check.h"],
220    linkopts = ABSL_DEFAULT_LINKOPTS,
221    deps = [
222        "//absl/base:config",
223        "//absl/base:core_headers",
224    ],
225)
226
227# Adding a dependency to leak_check_disable will disable
228# sanitizer leak checking (asan/lsan) in a test without
229# the need to mess around with build features.
230cc_library(
231    name = "leak_check_disable",
232    srcs = ["leak_check_disable.cc"],
233    linkopts = ABSL_DEFAULT_LINKOPTS,
234    linkstatic = 1,
235    deps = ["//absl/base:config"],
236    alwayslink = 1,
237)
238
239# These targets exists for use in tests only, explicitly configuring the
240# LEAK_SANITIZER macro. It must be linked with -fsanitize=leak for lsan.
241ABSL_LSAN_LINKOPTS = select({
242    "//absl:llvm_compiler": ["-fsanitize=leak"],
243    "//conditions:default": [],
244})
245
246cc_library(
247    name = "leak_check_api_enabled_for_testing",
248    testonly = 1,
249    srcs = ["leak_check.cc"],
250    hdrs = ["leak_check.h"],
251    copts = select({
252        "//absl:llvm_compiler": ["-DLEAK_SANITIZER"],
253        "//conditions:default": [],
254    }),
255    linkopts = ABSL_DEFAULT_LINKOPTS,
256    visibility = ["//visibility:private"],
257    deps = [
258        "//absl/base:config",
259    ],
260)
261
262cc_library(
263    name = "leak_check_api_disabled_for_testing",
264    testonly = 1,
265    srcs = ["leak_check.cc"],
266    hdrs = ["leak_check.h"],
267    copts = ["-ULEAK_SANITIZER"],
268    linkopts = ABSL_DEFAULT_LINKOPTS,
269    visibility = ["//visibility:private"],
270    deps = [
271        "//absl/base:config",
272    ],
273)
274
275cc_test(
276    name = "leak_check_test",
277    srcs = ["leak_check_test.cc"],
278    copts = select({
279        "//absl:llvm_compiler": ["-DABSL_EXPECT_LEAK_SANITIZER"],
280        "//conditions:default": [],
281    }),
282    linkopts = ABSL_LSAN_LINKOPTS + ABSL_DEFAULT_LINKOPTS,
283    tags = ["notsan"],
284    deps = [
285        ":leak_check_api_enabled_for_testing",
286        "//absl/base",
287        "@com_google_googletest//:gtest_main",
288    ],
289)
290
291cc_test(
292    name = "leak_check_no_lsan_test",
293    srcs = ["leak_check_test.cc"],
294    copts = ["-UABSL_EXPECT_LEAK_SANITIZER"],
295    linkopts = ABSL_DEFAULT_LINKOPTS,
296    tags = ["noasan"],
297    deps = [
298        ":leak_check_api_disabled_for_testing",
299        "//absl/base",  # for raw_logging
300        "@com_google_googletest//:gtest_main",
301    ],
302)
303
304# Test that leak checking is skipped when lsan is enabled but
305# ":leak_check_disable" is linked in.
306#
307# This test should fail in the absence of a dependency on ":leak_check_disable"
308cc_test(
309    name = "disabled_leak_check_test",
310    srcs = ["leak_check_fail_test.cc"],
311    linkopts = ABSL_LSAN_LINKOPTS + ABSL_DEFAULT_LINKOPTS,
312    tags = ["notsan"],
313    deps = [
314        ":leak_check_api_enabled_for_testing",
315        ":leak_check_disable",
316        "//absl/base",
317        "@com_google_googletest//:gtest_main",
318    ],
319)
320
321cc_library(
322    name = "stack_consumption",
323    testonly = 1,
324    srcs = ["internal/stack_consumption.cc"],
325    hdrs = ["internal/stack_consumption.h"],
326    copts = ABSL_DEFAULT_COPTS,
327    linkopts = ABSL_DEFAULT_LINKOPTS,
328    visibility = ["//visibility:private"],
329    deps = [
330        "//absl/base:config",
331        "//absl/base:core_headers",
332        "//absl/base:raw_logging_internal",
333    ],
334)
335
336cc_test(
337    name = "stack_consumption_test",
338    srcs = ["internal/stack_consumption_test.cc"],
339    copts = ABSL_TEST_COPTS,
340    linkopts = ABSL_DEFAULT_LINKOPTS,
341    deps = [
342        ":stack_consumption",
343        "//absl/base:core_headers",
344        "//absl/base:raw_logging_internal",
345        "@com_google_googletest//:gtest_main",
346    ],
347)
348