This is an archive of the discontinued LLVM Phabricator instance.

[hwasan] Record allocation thread id in HeapAllocationRecord
ClosedPublic

Authored by Enna1 on Mar 30 2023, 4:04 AM.

Details

Summary

Extend HeapAllocationRecord to record allocation thread id, print thread id in memory allocation stack trace.

Diff Detail

Event Timeline

Enna1 created this revision.Mar 30 2023, 4:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2023, 4:04 AM
Enna1 published this revision for review.Mar 30 2023, 4:07 AM
Enna1 added reviewers: kcc, eugenis, vitalybuka.
Enna1 added a subscriber: MTC.
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2023, 4:07 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
Enna1 updated this revision to Diff 509638.Mar 30 2023, 6:05 AM

clang-format

vitalybuka requested changes to this revision.Mar 31 2023, 8:30 PM
vitalybuka added inline comments.
compiler-rt/lib/hwasan/hwasan_allocator.h
122

thread id is part of alloc_context_id
why do we need another field?

This revision now requires changes to proceed.Mar 31 2023, 8:30 PM
Enna1 added inline comments.Mar 31 2023, 8:49 PM
compiler-rt/lib/hwasan/hwasan_allocator.h
122

Yes, thread id is part of alloc_context_id stored as atomic_uint64_t alloc_context_id in Metadata, u32 alloc_context_id stored in HeapAllocationRecord is without thread id.
What do you think add a function named inline u64 GetAllocContextId() const; and directly store u64 alloc_context_id in HeapAllocationRecord?

vitalybuka accepted this revision.Mar 31 2023, 9:47 PM
vitalybuka added inline comments.
compiler-rt/lib/hwasan/hwasan_allocator.cpp
359

@eugenis Unrelated to the patch but seems Deallocate must be called after ha->push

compiler-rt/lib/hwasan/hwasan_allocator.h
118–119

I guess you just resolved TODO, so please remove

122

missaligned, please clang-format

122

Yes, thread id is part of alloc_context_id stored as atomic_uint64_t alloc_context_id in Metadata, u32 alloc_context_id stored in HeapAllocationRecord is without thread id.
What do you think add a function named inline u64 GetAllocContextId() const; and directly store u64 alloc_context_id in HeapAllocationRecord?

thanks for pointing to this, I didn't noticed that first time

compiler-rt/lib/hwasan/hwasan_report.cpp
334

u32 should be %u

476
481
This revision is now accepted and ready to land.Mar 31 2023, 9:47 PM
Enna1 updated this revision to Diff 510177.Mar 31 2023, 10:07 PM

address review comments

Enna1 marked 4 inline comments as done.Mar 31 2023, 10:09 PM
Enna1 added inline comments.
compiler-rt/lib/hwasan/hwasan_allocator.h
122

clang-format complained about keeping this aligned

This revision was automatically updated to reflect the committed changes.