LLVM: lib/Transforms/Utils/ASanStackFrameLayout.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
17#include
18
19namespace llvm {
20
21
22
23
24
25
26
27
32
33
34
36
37
38
39
43 if (Size <= 4) Res = 16;
44 else if (Size <= 16) Res = 32;
45 else if (Size <= 128) Res = Size + 32;
46 else if (Size <= 512) Res = Size + 64;
47 else if (Size <= 4096) Res = Size + 128;
48 else Res = Size + 256;
49 return alignTo(std::max(Res, 2 * Granularity), Alignment);
50}
51
52ASanStackFrameLayout
55 assert(Granularity >= 8 && Granularity <= 64 &&
56 (Granularity & (Granularity - 1)) == 0);
57 assert(MinHeaderSize >= 16 && (MinHeaderSize & (MinHeaderSize - 1)) == 0 &&
58 MinHeaderSize >= Granularity);
59 const size_t NumVars = Vars.size();
61 for (size_t i = 0; i < NumVars; i++)
62 Vars[i].Alignment = std::max(Vars[i].Alignment, kMinAlignment);
63
65
68 Layout.FrameAlignment = std::max(Granularity, Vars[0].Alignment);
70 std::max(std::max(MinHeaderSize, Granularity), Vars[0].Alignment);
72 for (size_t i = 0; i < NumVars; i++) {
73 bool IsLast = i == NumVars - 1;
74 uint64_t Alignment = std::max(Granularity, Vars[i].Alignment);
75 (void)Alignment;
77 assert((Alignment & (Alignment - 1)) == 0);
82 IsLast ? Granularity : std::max(Granularity, Vars[i + 1].Alignment);
85 Vars[i].Offset = Offset;
86 Offset += SizeWithRedzone;
87 }
88 if (Offset % MinHeaderSize) {
89 Offset += MinHeaderSize - (Offset % MinHeaderSize);
90 }
93 return Layout;
94}
95
100 StackDescription << Vars.size();
101
102 for (const auto &Var : Vars) {
103 std::string Name = Var.Name;
104 if (Var.Line) {
105 Name += ":";
107 }
108 StackDescription << " " << Var.Offset << " " << Var.Size << " "
109 << Name.size() << " " << Name;
110 }
111 return StackDescription.str();
112}
113
122 for (const auto &Var : Vars) {
124
125 SB.resize(SB.size() + Var.Size / Granularity, 0);
126 if (Var.Size % Granularity)
127 SB.push_back(Var.Size % Granularity);
128 }
130 return SB;
131}
132
138
139 for (const auto &Var : Vars) {
140 assert(Var.LifetimeSize <= Var.Size);
141 const uint64_t LifetimeShadowSize =
142 (Var.LifetimeSize + Granularity - 1) / Granularity;
146 }
147
148 return SB;
149}
150
151}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the SmallString class.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
LLVM_ABI SmallVector< uint8_t, 64 > GetShadowBytesAfterScope(const SmallVectorImpl< ASanStackVariableDescription > &Vars, const ASanStackFrameLayout &Layout)
Definition ASanStackFrameLayout.cpp:133
static bool CompareVars(const ASanStackVariableDescription &a, const ASanStackVariableDescription &b)
Definition ASanStackFrameLayout.cpp:28
LLVM_ABI SmallString< 64 > ComputeASanStackFrameDescription(const SmallVectorImpl< ASanStackVariableDescription > &Vars)
Definition ASanStackFrameLayout.cpp:96
static uint64_t VarAndRedzoneSize(uint64_t Size, uint64_t Granularity, uint64_t Alignment)
Definition ASanStackFrameLayout.cpp:40
LLVM_ABI SmallVector< uint8_t, 64 > GetShadowBytes(const SmallVectorImpl< ASanStackVariableDescription > &Vars, const ASanStackFrameLayout &Layout)
Definition ASanStackFrameLayout.cpp:115
static const uint64_t kMinAlignment
Definition ASanStackFrameLayout.cpp:35
static const int kAsanStackUseAfterScopeMagic
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
const char * to_string(ThinOrFullLTOPhase Phase)
LLVM_ABI ASanStackFrameLayout ComputeASanStackFrameLayout(SmallVectorImpl< ASanStackVariableDescription > &Vars, uint64_t Granularity, uint64_t MinHeaderSize)
Definition ASanStackFrameLayout.cpp:53
static const int kAsanStackLeftRedzoneMagic
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
static const int kAsanStackRightRedzoneMagic
static const int kAsanStackMidRedzoneMagic