1 //===-- nsan_suppressions.cc ----------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "nsan_suppressions.h"
10 #include "nsan_flags.h"
11 #include "sanitizer_common/sanitizer_placement_new.h"
12 #include "sanitizer_common/sanitizer_stacktrace.h"
13 #include "sanitizer_common/sanitizer_symbolizer.h"
15 using namespace __sanitizer
;
16 using namespace __nsan
;
18 SANITIZER_INTERFACE_WEAK_DEF(const char *, __nsan_default_suppressions
, void) {
22 const char kSuppressionFcmp
[] = "fcmp";
23 const char kSuppressionConsistency
[] = "consistency";
25 alignas(64) static char suppression_placeholder
[sizeof(SuppressionContext
)];
26 static SuppressionContext
*suppression_ctx
;
28 // The order should match the enum CheckKind.
29 static const char *kSuppressionTypes
[] = {kSuppressionFcmp
,
30 kSuppressionConsistency
};
32 void __nsan::InitializeSuppressions() {
33 CHECK_EQ(nullptr, suppression_ctx
);
34 suppression_ctx
= new (suppression_placeholder
)
35 SuppressionContext(kSuppressionTypes
, ARRAY_SIZE(kSuppressionTypes
));
36 suppression_ctx
->ParseFromFile(flags().suppressions
);
37 suppression_ctx
->Parse(__nsan_default_suppressions());
40 static Suppression
*GetSuppressionForAddr(uptr addr
, const char *suppr_type
) {
41 Suppression
*s
= nullptr;
43 // Suppress by module name.
44 SuppressionContext
*suppressions
= suppression_ctx
;
45 if (const char *moduleName
=
46 Symbolizer::GetOrInit()->GetModuleNameForPc(addr
)) {
47 if (suppressions
->Match(moduleName
, suppr_type
, &s
))
51 // Suppress by file or function name.
52 SymbolizedStack
*frames
= Symbolizer::GetOrInit()->SymbolizePC(addr
);
53 for (SymbolizedStack
*cur
= frames
; cur
; cur
= cur
->next
) {
54 if (suppressions
->Match(cur
->info
.function
, suppr_type
, &s
) ||
55 suppressions
->Match(cur
->info
.file
, suppr_type
, &s
)) {
63 Suppression
*__nsan::GetSuppressionForStack(const StackTrace
*stack
,
65 for (uptr i
= 0, e
= stack
->size
; i
< e
; i
++) {
66 Suppression
*s
= GetSuppressionForAddr(
67 StackTrace::GetPreviousInstructionPc(stack
->trace
[i
]),
68 kSuppressionTypes
[static_cast<int>(k
)]);