-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hwasan] Optimize shadow shapshot size #67068
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-compiler-rt-sanitizer ChangesNow we copy only tags we will print. Full diff: https://github.com/llvm/llvm-project/pull/67068.diff 1 Files Affected:
diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 3c20effdd318b93..f5d7b9229da42af 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -323,6 +323,22 @@ static uptr GetGlobalSizeFromDescriptor(uptr ptr) {
void ReportStats() {}
+constexpr uptr kShadowDumpWidth = 16;
+constexpr uptr kShadowDumpHeight = 17;
+constexpr uptr kShadowDumpSize = kShadowDumpHeight * kShadowDumpWidth;
+
+constexpr uptr kShortDumpHeight = 3;
+constexpr uptr kShortDumpSize = kShortDumpHeight * kShadowDumpWidth;
+constexpr uptr kShortDumpOffset =
+ (kShadowDumpHeight - kShortDumpHeight) / 2 * kShadowDumpWidth;
+
+static uptr GetPrintTagStart(uptr addr) {
+ addr = MemToShadow(addr);
+ addr = RoundDownTo(addr, kShadowDumpWidth);
+ addr -= kShadowDumpWidth * (kShadowDumpHeight / 2);
+ return addr;
+}
+
template <typename PrintTag>
static void PrintTagInfoAroundAddr(uptr addr, uptr num_rows,
InternalScopedString &s,
@@ -352,7 +368,7 @@ static void PrintTagsAroundAddr(uptr addr, GetTag get_tag,
"Memory tags around the buggy address (one tag corresponds to %zd "
"bytes):\n",
kShadowAlignment);
- PrintTagInfoAroundAddr(addr, 17, s,
+ PrintTagInfoAroundAddr(addr, kShadowDumpHeight, s,
[&](InternalScopedString &s, uptr tag_addr) {
tag_t tag = get_tag(tag_addr);
s.AppendF("%02x", tag);
@@ -362,7 +378,7 @@ static void PrintTagsAroundAddr(uptr addr, GetTag get_tag,
"Tags for short granules around the buggy address (one tag corresponds "
"to %zd bytes):\n",
kShadowAlignment);
- PrintTagInfoAroundAddr(addr, 3, s,
+ PrintTagInfoAroundAddr(addr, kShortDumpHeight, s,
[&](InternalScopedString &s, uptr tag_addr) {
tag_t tag = get_tag(tag_addr);
if (tag >= 1 && tag <= kShadowAlignment) {
@@ -439,8 +455,8 @@ class BaseReport {
struct Shadow {
uptr addr = 0;
- tag_t tags[512] = {};
- tag_t short_tags[ARRAY_SIZE(tags)] = {};
+ tag_t tags[kShadowDumpSize] = {};
+ tag_t short_tags[kShortDumpSize] = {};
};
sptr FindMismatchOffset() const;
@@ -508,18 +524,24 @@ BaseReport::Shadow BaseReport::CopyShadow() const {
if (!MemIsApp(untagged_addr))
return result;
- result.addr = MemToShadow(untagged_addr) - ARRAY_SIZE(result.tags) / 2;
- for (uptr i = 0; i < ARRAY_SIZE(result.tags); ++i) {
- uptr tag_addr = result.addr + i;
- if (!MemIsShadow(tag_addr))
- continue;
- result.tags[i] = *reinterpret_cast<tag_t *>(tag_addr);
- uptr granule_addr = ShadowToMem(tag_addr);
- if (1 <= result.tags[i] && result.tags[i] <= kShadowAlignment &&
+ result.addr = GetPrintTagStart(untagged_addr + mismatch_offset);
+ uptr tag_addr = result.addr;
+ for (tag_t& tag_copy : result.tags) {
+ if (MemIsShadow(tag_addr))
+ tag_copy = *reinterpret_cast<tag_t *>(tag_addr);
+ ++tag_addr;
+ }
+
+ uptr short_tags_addr = result.addr + kShortDumpOffset;
+ for (tag_t& tag_copy : result.short_tags) {
+ tag_t tag = GetTagCopy(short_tags_addr);
+ uptr granule_addr = ShadowToMem(short_tags_addr);
+ if (1 <= tag && tag <= kShadowAlignment &&
IsAccessibleMemoryRange(granule_addr, kShadowAlignment)) {
- result.short_tags[i] =
+ tag_copy =
*reinterpret_cast<tag_t *>(granule_addr + kShadowAlignment - 1);
}
+ ++short_tags_addr;
}
return result;
}
@@ -532,8 +554,8 @@ tag_t BaseReport::GetTagCopy(uptr addr) const {
}
tag_t BaseReport::GetShortTagCopy(uptr addr) const {
- CHECK_GE(addr, shadow.addr);
- uptr idx = addr - shadow.addr;
+ CHECK_GE(addr, shadow.addr + kShortDumpOffset);
+ uptr idx = addr - shadow.addr - kShortDumpOffset;
CHECK_LT(idx, ARRAY_SIZE(shadow.short_tags));
return shadow.short_tags[idx];
}
|
fmayer
approved these changes
Sep 21, 2023
Now we copy only tags we will print. CHECKs in GetTagCopy and GetShortTagCopy ensure that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now we copy only tags we will print.
CHECKs in GetTagCopy and GetShortTagCopy ensure that.