Skip to content

Commit 082efba

Browse files
authored
[asan] Make GetFakeStackFast()/GetFakeStackFastAlways() lazily init fake_stack_tls (llvm#163481)
To simplify implementation of llvm#160135
1 parent 6fbc7d3 commit 082efba

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

compiler-rt/lib/asan/asan_fake_stack.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,25 @@ static FakeStack* GetFakeStack() {
231231
}
232232

233233
static FakeStack* GetFakeStackFast() {
234-
if (FakeStack* fs = GetTLSFakeStack())
234+
FakeStack* fs = GetTLSFakeStack();
235+
if (LIKELY(fs))
235236
return fs;
236237
if (!__asan_option_detect_stack_use_after_return)
237238
return nullptr;
238-
return GetFakeStack();
239+
fs = GetFakeStack();
240+
if (LIKELY(fs))
241+
SetTLSFakeStack(fs);
242+
return fs;
239243
}
240244

241245
static FakeStack* GetFakeStackFastAlways() {
242-
if (FakeStack* fs = GetTLSFakeStack())
246+
FakeStack* fs = GetTLSFakeStack();
247+
if (LIKELY(fs))
243248
return fs;
244-
return GetFakeStack();
249+
fs = GetFakeStack();
250+
if (LIKELY(fs))
251+
SetTLSFakeStack(fs);
252+
return fs;
245253
}
246254

247255
static ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size) {

compiler-rt/lib/asan/asan_fake_stack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class FakeStack {
195195
void *true_start;
196196
};
197197

198-
void SetTLSFakeStack(FakeStack *fs);
198+
void SetTLSFakeStack(FakeStack* fs);
199199

200200
} // namespace __asan
201201

0 commit comments

Comments
 (0)