clang: lib/CodeGen/SanitizerMetadata.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

16

17using namespace clang;

18using namespace CodeGen;

19

20SanitizerMetadata::SanitizerMetadata(CodeGenModule &CGM) : CGM(CGM) {}

21

23 return SS.hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress |

24 SanitizerKind::HWAddress | SanitizerKind::MemTag |

25 SanitizerKind::Type);

26}

27

29 if (Mask & (SanitizerKind::Address | SanitizerKind::KernelAddress))

30 Mask |= SanitizerKind::Address | SanitizerKind::KernelAddress;

31

32 return Mask;

33}

34

36

37

38

39 if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())

40 return false;

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60 if (G.hasSection())

61 return false;

62

63 return true;

64}

65

70 bool IsDynInit) {

73 return;

74

77 SanitizerSet NoSanitizeAttrSet = {NoSanitizeAttrMask &

78 FsanitizeArgument.Mask};

79

80 llvm::GlobalVariable::SanitizerMetadata Meta;

81 if (GV->hasSanitizerMetadata())

82 Meta = GV->getSanitizerMetadata();

83

84 Meta.NoAddress |= NoSanitizeAttrSet.hasOneOf(SanitizerKind::Address);

86 FsanitizeArgument.Mask & SanitizerKind::Address, GV, Loc, Ty);

87

88 Meta.NoHWAddress |= NoSanitizeAttrSet.hasOneOf(SanitizerKind::HWAddress);

90 FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);

91

93 Meta.Memtag |= static_cast<bool>(FsanitizeArgument.Mask &

94 SanitizerKind::MemtagGlobals);

95 Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);

97 FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);

98 } else {

99 Meta.Memtag = false;

100 }

101

102 Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&

103 FsanitizeArgument.has(SanitizerKind::Address) &&

105 SanitizerKind::KernelAddress,

106 GV, Loc, Ty, "init");

107

108 GV->setSanitizerMetadata(Meta);

109

111 NoSanitizeAttrMask & SanitizerKind::Type)

112 return;

113

116 return;

117

118 llvm::Metadata *GlobalMetadata[] = {llvm::ConstantAsMetadata::get(GV),

119 TBAAInfo};

120

121

122 if (llvm::MDNode::getIfExists(CGM.getLLVMContext(), GlobalMetadata))

123 return;

124

125 llvm::MDNode *ThisGlobal =

126 llvm::MDNode::get(CGM.getLLVMContext(), GlobalMetadata);

127 llvm::NamedMDNode *TysanGlobals =

128 CGM.getModule().getOrInsertNamedMetadata("llvm.tysan.globals");

129 TysanGlobals->addOperand(ThisGlobal);

130}

131

133 bool IsDynInit) {

135 return;

136 std::string QualName;

137 llvm::raw_string_ostream OS(QualName);

138 D.printQualifiedName(OS);

139

140 auto getNoSanitizeMask = [](const VarDecl &D) {

141 if (D.hasAttr())

142 return SanitizerKind::All;

143

146 NoSanitizeMask |= Attr->getMask();

147

148

149

150 if (D.hasExternalStorage() || D.getType()->isIncompleteType())

151 NoSanitizeMask |= SanitizerKind::Type;

152

153 return NoSanitizeMask;

154 };

155

157 IsDynInit);

158}

159

162}

C Language Family Type Representation.

Attr - This represents one attribute.

This class organizes the cross-function state that is used while generating LLVM code.

llvm::Module & getModule() const

bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, SourceLocation Loc) const

const LangOptions & getLangOpts() const

ASTContext & getContext() const

llvm::MDNode * getTBAATypeInfo(QualType QTy)

getTBAATypeInfo - Get metadata used to describe accesses to objects of the given type.

llvm::LLVMContext & getLLVMContext()

llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const

SourceLocation getLocation() const

SanitizerSet Sanitize

Set of enabled sanitizers.

A (possibly-)qualified type.

bool isNull() const

Return true if this QualType doesn't point to a type yet.

Encodes a location in the source.

Represents a variable declaration or definition.

The JSON file list parser is used to communicate input to InstallAPI.

bool has(SanitizerMask K) const

Check if a certain (single) sanitizer is enabled.

SanitizerMask Mask

Bitmask of enabled sanitizers.

bool hasOneOf(SanitizerMask K) const

Check if one or more sanitizers are enabled.