[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / asan / asan_suppressions.cpp
blob8cb2c3e3b9b6a49132d24e7a8669591bee111b40
1 //===-- asan_suppressions.cpp ---------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of AddressSanitizer, an address sanity checker.
11 // Issue suppression and suppression-related functions.
12 //===----------------------------------------------------------------------===//
14 #include "asan_suppressions.h"
16 #include "asan_stack.h"
17 #include "sanitizer_common/sanitizer_placement_new.h"
18 #include "sanitizer_common/sanitizer_suppressions.h"
19 #include "sanitizer_common/sanitizer_symbolizer.h"
21 namespace __asan {
23 ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
24 static SuppressionContext *suppression_ctx = nullptr;
25 static const char kInterceptorName[] = "interceptor_name";
26 static const char kInterceptorViaFunction[] = "interceptor_via_fun";
27 static const char kInterceptorViaLibrary[] = "interceptor_via_lib";
28 static const char kODRViolation[] = "odr_violation";
29 static const char *kSuppressionTypes[] = {
30 kInterceptorName, kInterceptorViaFunction, kInterceptorViaLibrary,
31 kODRViolation};
33 SANITIZER_INTERFACE_WEAK_DEF(const char *, __asan_default_suppressions, void) {
34 return "";
37 void InitializeSuppressions() {
38 CHECK_EQ(nullptr, suppression_ctx);
39 suppression_ctx = new (suppression_placeholder)
40 SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
41 suppression_ctx->ParseFromFile(flags()->suppressions);
42 if (&__asan_default_suppressions)
43 suppression_ctx->Parse(__asan_default_suppressions());
46 bool IsInterceptorSuppressed(const char *interceptor_name) {
47 CHECK(suppression_ctx);
48 Suppression *s;
49 // Match "interceptor_name" suppressions.
50 return suppression_ctx->Match(interceptor_name, kInterceptorName, &s);
53 bool HaveStackTraceBasedSuppressions() {
54 CHECK(suppression_ctx);
55 return suppression_ctx->HasSuppressionType(kInterceptorViaFunction) ||
56 suppression_ctx->HasSuppressionType(kInterceptorViaLibrary);
59 bool IsODRViolationSuppressed(const char *global_var_name) {
60 CHECK(suppression_ctx);
61 Suppression *s;
62 // Match "odr_violation" suppressions.
63 return suppression_ctx->Match(global_var_name, kODRViolation, &s);
66 bool IsStackTraceSuppressed(const StackTrace *stack) {
67 if (!HaveStackTraceBasedSuppressions())
68 return false;
70 CHECK(suppression_ctx);
71 Symbolizer *symbolizer = Symbolizer::GetOrInit();
72 Suppression *s;
73 for (uptr i = 0; i < stack->size && stack->trace[i]; i++) {
74 uptr addr = stack->trace[i];
76 if (suppression_ctx->HasSuppressionType(kInterceptorViaLibrary)) {
77 // Match "interceptor_via_lib" suppressions.
78 if (const char *module_name = symbolizer->GetModuleNameForPc(addr))
79 if (suppression_ctx->Match(module_name, kInterceptorViaLibrary, &s))
80 return true;
83 if (suppression_ctx->HasSuppressionType(kInterceptorViaFunction)) {
84 SymbolizedStack *frames = symbolizer->SymbolizePC(addr);
85 CHECK(frames);
86 for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
87 const char *function_name = cur->info.function;
88 if (!function_name) {
89 continue;
91 // Match "interceptor_via_fun" suppressions.
92 if (suppression_ctx->Match(function_name, kInterceptorViaFunction,
93 &s)) {
94 frames->ClearAll();
95 return true;
98 frames->ClearAll();
101 return false;
104 } // namespace __asan