1 | //===------- Definition of the SanitizerBinaryMetadata class ----*- C++ -*-===// |
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 declares the SanitizerBinaryMetadata pass. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERBINARYMETADATA_H |
13 | #define LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERBINARYMETADATA_H |
14 | |
15 | #include "llvm/ADT/ArrayRef.h" |
16 | #include "llvm/IR/Function.h" |
17 | #include "llvm/IR/Module.h" |
18 | #include "llvm/IR/PassManager.h" |
19 | #include "llvm/Transforms/Instrumentation.h" |
20 | |
21 | namespace llvm { |
22 | |
23 | struct SanitizerBinaryMetadataOptions { |
24 | bool Covered = false; |
25 | bool Atomics = false; |
26 | bool UAR = false; |
27 | SanitizerBinaryMetadataOptions() = default; |
28 | }; |
29 | |
30 | inline constexpr int kSanitizerBinaryMetadataAtomicsBit = 0; |
31 | inline constexpr int kSanitizerBinaryMetadataUARBit = 1; |
32 | inline constexpr int kSanitizerBinaryMetadataUARHasSizeBit = 2; |
33 | |
34 | inline constexpr uint64_t kSanitizerBinaryMetadataAtomics = |
35 | 1 << kSanitizerBinaryMetadataAtomicsBit; |
36 | inline constexpr uint64_t kSanitizerBinaryMetadataUAR = |
37 | 1 << kSanitizerBinaryMetadataUARBit; |
38 | inline constexpr uint64_t kSanitizerBinaryMetadataUARHasSize = |
39 | 1 << kSanitizerBinaryMetadataUARHasSizeBit; |
40 | |
41 | inline constexpr char kSanitizerBinaryMetadataCoveredSection[] = |
42 | "sanmd_covered" ; |
43 | inline constexpr char kSanitizerBinaryMetadataAtomicsSection[] = |
44 | "sanmd_atomics" ; |
45 | |
46 | /// Public interface to the SanitizerBinaryMetadata module pass for emitting |
47 | /// metadata for binary analysis sanitizers. |
48 | // |
49 | /// The pass should be inserted after optimizations. |
50 | class SanitizerBinaryMetadataPass |
51 | : public PassInfoMixin<SanitizerBinaryMetadataPass> { |
52 | public: |
53 | explicit SanitizerBinaryMetadataPass( |
54 | SanitizerBinaryMetadataOptions Opts = {}, |
55 | ArrayRef<std::string> IgnorelistFiles = {}); |
56 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
57 | static bool isRequired() { return true; } |
58 | |
59 | private: |
60 | const SanitizerBinaryMetadataOptions Options; |
61 | const ArrayRef<std::string> IgnorelistFiles; |
62 | }; |
63 | |
64 | } // namespace llvm |
65 | |
66 | #endif |
67 | |