Skip to content

Commit c23c958

Browse files
committed
Try to avoid unregistered globals when scanning the list
Change-Id: Ia14f19ba5805bcc1d0a99eed430da3d2996e1a2f
1 parent f5f4090 commit c23c958

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compiler-rt/lib/asan/asan_globals.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,28 @@ static u32 FindRegistrationSite(const Global *g) {
172172
return 0;
173173
}
174174

175+
#if SANITIZER_AMDGPU
176+
static bool IsValidGlobal(const Global *g) {
177+
return
178+
*(u8 *)MEM_TO_SHADOW((uptr)g) == kAsanGlobalRedzoneMagic &&
179+
*(u8 *)MEM_TO_SHADOW((uptr)g + sizeof(__asan_global) - sizeof(uptr))
180+
== kAsanGlobalRedzoneMagic &&
181+
g->size < g->size_with_redzone &&
182+
g->has_dynamic_init < 2 &&
183+
g->beg < kHighMemEnd;
184+
}
185+
#endif
186+
175187
int GetGlobalsForAddress(uptr addr, Global *globals, u32 *reg_sites,
176188
int max_globals) {
177189
if (!flags()->report_globals) return 0;
178190
Lock lock(&mu_for_globals);
179191
int res = 0;
180192
for (const auto &l : list_of_all_globals) {
193+
#if SANITIZER_AMDGPU
194+
if (!IsValidGlobal(l.g))
195+
continue;
196+
#endif
181197
const Global &g = *l.g;
182198
if (flags()->report_globals >= 2)
183199
ReportGlobal(g, "Search");

0 commit comments

Comments
 (0)