summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
diff options
context:
space:
mode:
authorWalter Lee <waltl@google.com>2017-11-18 01:13:18 +0000
committerWalter Lee <waltl@google.com>2017-11-18 01:13:18 +0000
commit9abeecc07cfacb7dca544470ee701cda54e203c2 (patch)
treeed9c989030763dec4eedd788f0d0bc779e4d8284 /llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
parente77c8425e168aa93968c47689e2bf976fc46a2d2 (diff)
downloadbcm5719-llvm-9abeecc07cfacb7dca544470ee701cda54e203c2.tar.gz
bcm5719-llvm-9abeecc07cfacb7dca544470ee701cda54e203c2.zip
[asan] Add a full redzone after every stack variable
We were not doing that for large shadow granularity. Also add more stack frame layout tests for large shadow granularity. Differential Revision: https://reviews.llvm.org/D39475 llvm-svn: 318581
Diffstat (limited to 'llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp b/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
index df9d5da9e26..364878dc588 100644
--- a/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
+++ b/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
@@ -36,9 +36,11 @@ static inline bool CompareVars(const ASanStackVariableDescription &a,
// with e.g. alignment 1 and alignment 16 do not get reordered by CompareVars.
static const size_t kMinAlignment = 16;
+// We want to add a full redzone after every variable.
// The larger the variable Size the larger is the redzone.
// The resulting frame size is a multiple of Alignment.
-static size_t VarAndRedzoneSize(size_t Size, size_t Alignment) {
+static size_t VarAndRedzoneSize(size_t Size, size_t Granularity,
+ size_t Alignment) {
size_t Res = 0;
if (Size <= 4) Res = 16;
else if (Size <= 16) Res = 32;
@@ -46,7 +48,7 @@ static size_t VarAndRedzoneSize(size_t Size, size_t Alignment) {
else if (Size <= 512) Res = Size + 64;
else if (Size <= 4096) Res = Size + 128;
else Res = Size + 256;
- return alignTo(Res, Alignment);
+ return alignTo(std::max(Res, 2 * Granularity), Alignment);
}
ASanStackFrameLayout
@@ -80,7 +82,8 @@ ComputeASanStackFrameLayout(SmallVectorImpl<ASanStackVariableDescription> &Vars,
assert(Size > 0);
size_t NextAlignment = IsLast ? Granularity
: std::max(Granularity, Vars[i + 1].Alignment);
- size_t SizeWithRedzone = VarAndRedzoneSize(Size, NextAlignment);
+ size_t SizeWithRedzone = VarAndRedzoneSize(Size, Granularity,
+ NextAlignment);
Vars[i].Offset = Offset;
Offset += SizeWithRedzone;
}
OpenPOWER on IntegriCloud