This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Make AnnotateNewMemory functional
Needs ReviewPublic

Authored by protze.joachim on Aug 17 2023, 12:39 AM.

Details

Summary

When memory is allocated with new/malloc, TSan has interceptors to reset the shadow state for the allocation.
If allocation is implemented with memory management, TSan misses the new semantics.

For OpenMP-aware analysis with libarcher, we have the problem that libomp manages the memory for internal data structures and we observe spurious accesses to these data structures from instrumented application code. The accesses are not synchronized from application point of view, but by scheduling decisions and internal synchronization in the OpenMP runtime. This annotation removes the false positives without missing actual races.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2023, 12:39 AM
Herald added a subscriber: Enna1. · View Herald Transcript
protze.joachim requested review of this revision.Aug 17 2023, 12:39 AM

@dvyukov what do you think?
Should I move this to a GitHub PR, or can we get this accepted before Phabricator EoL?

[[ https://simplified.com/ai-logo-maker/

AI Logo Maker ]]uses advanced AI algorithms to create high-quality logos that are visually appealing and relevant to your business. With its powerful design tools and intuitive interface, AI Logo Maker makes it easy to create a logo that looks like it was designed by a professional designer.
dvyukov added a comment.EditedSep 28 2023, 7:35 AM

Looking at the code, OnUserAlloc cannot be called repeatedly on the same memory without OnUserFree.

You should get DCHECK failures in tests here:

void MetaMap::AllocBlock(ThreadState *thr, uptr pc, uptr p, uptr sz) {
...

DCHECK_EQ(*meta, 0);

In release builds it will cause silent memory leaks at least.

Also, this needs tests.

It's better to pass true as the last argument of OnUserAlloc, then tsan will be able to catch unsafe publication of this memory.

It's also better to add new malloc/free allocations. I see the old one was close semantically:
https://chromium.googlesource.com/chromium/src/base/+/f86dd125dc43d6dba04b61e73ac8a2bd4636c3f8/dynamic_annotations.h#108
But it was dead for the past 10+ years and I hate reviving old Valgrind annotations. There are sure still uses of these out there that will suddenly become non-nop.

Please add new annotations to compiler-rt/include/sanitizer/tsan_interface.h