• 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:msvc_compiler": ["-DEFAULTLIB:dbghelp.lib"],
70        "//absl:clang-cl_compiler": ["-DEFAULTLIB:dbghelp.lib"],
71        "//conditions:default": [],
72    }),
73    deps = [
74        ":debugging_internal",
75        ":demangle_internal",
76        "//absl/base",
77        "//absl/base:config",
78        "//absl/base:core_headers",
79        "//absl/base:dynamic_annotations",
80        "//absl/base:malloc_internal",
81        "//absl/base:raw_logging_internal",
82        "//absl/strings",
83    ],
84)
85
86cc_test(
87    name = "symbolize_test",
88    srcs = ["symbolize_test.cc"],
89    copts = ABSL_TEST_COPTS + select({
90        "//absl:msvc_compiler": ["/Z7"],
91        "//absl:clang-cl_compiler": ["/Z7"],
92        "//conditions:default": [],
93    }),
94    linkopts = ABSL_DEFAULT_LINKOPTS + select({
95        "//absl:msvc_compiler": ["/DEBUG"],
96        "//absl:clang-cl_compiler": ["/DEBUG"],
97        "//conditions:default": [],
98    }),
99    deps = [
100        ":stack_consumption",
101        ":symbolize",
102        "//absl/base",
103        "//absl/base:config",
104        "//absl/base:core_headers",
105        "//absl/base:raw_logging_internal",
106        "//absl/memory",
107        "//absl/strings",
108        "@com_google_googletest//:gtest",
109    ],
110)
111
112cc_library(
113    name = "examine_stack",
114    srcs = [
115        "internal/examine_stack.cc",
116    ],
117    hdrs = [
118        "internal/examine_stack.h",
119    ],
120    copts = ABSL_DEFAULT_COPTS,
121    linkopts = ABSL_DEFAULT_LINKOPTS,
122    visibility = ["//visibility:private"],
123    deps = [
124        ":stacktrace",
125        ":symbolize",
126        "//absl/base:config",
127        "//absl/base:core_headers",
128        "//absl/base:raw_logging_internal",
129    ],
130)
131
132cc_library(
133    name = "failure_signal_handler",
134    srcs = ["failure_signal_handler.cc"],
135    hdrs = ["failure_signal_handler.h"],
136    copts = ABSL_DEFAULT_COPTS,
137    linkopts = ABSL_DEFAULT_LINKOPTS,
138    deps = [
139        ":examine_stack",
140        ":stacktrace",
141        "//absl/base",
142        "//absl/base:config",
143        "//absl/base:core_headers",
144        "//absl/base:errno_saver",
145        "//absl/base:raw_logging_internal",
146    ],
147)
148
149cc_test(
150    name = "failure_signal_handler_test",
151    srcs = ["failure_signal_handler_test.cc"],
152    copts = ABSL_TEST_COPTS,
153    linkopts = select({
154        "//absl:msvc_compiler": [],
155        "//absl:clang-cl_compiler": [],
156        "//absl:wasm": [],
157        "//conditions:default": ["-pthread"],
158    }) + ABSL_DEFAULT_LINKOPTS,
159    deps = [
160        ":failure_signal_handler",
161        ":stacktrace",
162        ":symbolize",
163        "//absl/base:raw_logging_internal",
164        "//absl/strings",
165        "@com_google_googletest//:gtest",
166    ],
167)
168
169cc_library(
170    name = "debugging_internal",
171    srcs = [
172        "internal/address_is_readable.cc",
173        "internal/elf_mem_image.cc",
174        "internal/vdso_support.cc",
175    ],
176    hdrs = [
177        "internal/address_is_readable.h",
178        "internal/elf_mem_image.h",
179        "internal/vdso_support.h",
180    ],
181    copts = ABSL_DEFAULT_COPTS,
182    linkopts = ABSL_DEFAULT_LINKOPTS,
183    deps = [
184        "//absl/base:config",
185        "//absl/base:core_headers",
186        "//absl/base:dynamic_annotations",
187        "//absl/base:errno_saver",
188        "//absl/base:raw_logging_internal",
189    ],
190)
191
192cc_library(
193    name = "demangle_internal",
194    srcs = ["internal/demangle.cc"],
195    hdrs = ["internal/demangle.h"],
196    copts = ABSL_DEFAULT_COPTS,
197    deps = [
198        "//absl/base",
199        "//absl/base:config",
200        "//absl/base:core_headers",
201    ],
202)
203
204cc_test(
205    name = "demangle_test",
206    srcs = ["internal/demangle_test.cc"],
207    copts = ABSL_TEST_COPTS,
208    linkopts = ABSL_DEFAULT_LINKOPTS,
209    deps = [
210        ":demangle_internal",
211        ":stack_consumption",
212        "//absl/base:config",
213        "//absl/base:core_headers",
214        "//absl/base:raw_logging_internal",
215        "//absl/memory",
216        "@com_google_googletest//:gtest_main",
217    ],
218)
219
220cc_library(
221    name = "leak_check",
222    srcs = ["leak_check.cc"],
223    hdrs = ["leak_check.h"],
224    linkopts = ABSL_DEFAULT_LINKOPTS,
225    deps = [
226        "//absl/base:config",
227        "//absl/base:core_headers",
228    ],
229)
230
231# Adding a dependency to leak_check_disable will disable
232# sanitizer leak checking (asan/lsan) in a test without
233# the need to mess around with build features.
234cc_library(
235    name = "leak_check_disable",
236    srcs = ["leak_check_disable.cc"],
237    linkopts = ABSL_DEFAULT_LINKOPTS,
238    linkstatic = 1,
239    deps = ["//absl/base:config"],
240    alwayslink = 1,
241)
242
243# These targets exists for use in tests only, explicitly configuring the
244# LEAK_SANITIZER macro. It must be linked with -fsanitize=leak for lsan.
245ABSL_LSAN_LINKOPTS = select({
246    "//absl:clang_compiler": ["-fsanitize=leak"],
247    "//conditions:default": [],
248})
249
250cc_library(
251    name = "leak_check_api_enabled_for_testing",
252    testonly = 1,
253    srcs = ["leak_check.cc"],
254    hdrs = ["leak_check.h"],
255    copts = select({
256        "//absl:clang_compiler": ["-DLEAK_SANITIZER"],
257        "//conditions:default": [],
258    }),
259    linkopts = ABSL_DEFAULT_LINKOPTS,
260    visibility = ["//visibility:private"],
261    deps = [
262        "//absl/base:config",
263        "//absl/base:core_headers",
264    ],
265)
266
267cc_library(
268    name = "leak_check_api_disabled_for_testing",
269    testonly = 1,
270    srcs = ["leak_check.cc"],
271    hdrs = ["leak_check.h"],
272    copts = ["-ULEAK_SANITIZER"],
273    linkopts = ABSL_DEFAULT_LINKOPTS,
274    visibility = ["//visibility:private"],
275    deps = [
276        "//absl/base:config",
277        "//absl/base:core_headers",
278    ],
279)
280
281cc_test(
282    name = "leak_check_test",
283    srcs = ["leak_check_test.cc"],
284    copts = select({
285        "//absl:clang_compiler": ["-DABSL_EXPECT_LEAK_SANITIZER"],
286        "//conditions:default": [],
287    }),
288    linkopts = ABSL_LSAN_LINKOPTS + ABSL_DEFAULT_LINKOPTS,
289    tags = ["notsan"],
290    deps = [
291        ":leak_check_api_enabled_for_testing",
292        "//absl/base",
293        "@com_google_googletest//:gtest_main",
294    ],
295)
296
297cc_test(
298    name = "leak_check_no_lsan_test",
299    srcs = ["leak_check_test.cc"],
300    copts = ["-UABSL_EXPECT_LEAK_SANITIZER"],
301    linkopts = ABSL_DEFAULT_LINKOPTS,
302    tags = ["noasan"],
303    deps = [
304        ":leak_check_api_disabled_for_testing",
305        "//absl/base",  # for raw_logging
306        "@com_google_googletest//:gtest_main",
307    ],
308)
309
310# Test that leak checking is skipped when lsan is enabled but
311# ":leak_check_disable" is linked in.
312#
313# This test should fail in the absence of a dependency on ":leak_check_disable"
314cc_test(
315    name = "disabled_leak_check_test",
316    srcs = ["leak_check_fail_test.cc"],
317    linkopts = ABSL_LSAN_LINKOPTS + ABSL_DEFAULT_LINKOPTS,
318    tags = ["notsan"],
319    deps = [
320        ":leak_check_api_enabled_for_testing",
321        ":leak_check_disable",
322        "//absl/base",
323        "@com_google_googletest//:gtest_main",
324    ],
325)
326
327cc_library(
328    name = "stack_consumption",
329    testonly = 1,
330    srcs = ["internal/stack_consumption.cc"],
331    hdrs = ["internal/stack_consumption.h"],
332    copts = ABSL_DEFAULT_COPTS,
333    linkopts = ABSL_DEFAULT_LINKOPTS,
334    visibility = ["//visibility:private"],
335    deps = [
336        "//absl/base:config",
337        "//absl/base:core_headers",
338        "//absl/base:raw_logging_internal",
339    ],
340)
341
342cc_test(
343    name = "stack_consumption_test",
344    srcs = ["internal/stack_consumption_test.cc"],
345    copts = ABSL_TEST_COPTS,
346    linkopts = ABSL_DEFAULT_LINKOPTS,
347    tags = ["notsan"],
348    deps = [
349        ":stack_consumption",
350        "//absl/base:core_headers",
351        "//absl/base:raw_logging_internal",
352        "@com_google_googletest//:gtest_main",
353    ],
354)
355