[vm] Allow non-TSAN gen_snapshot target TSAN AOT runtime

This is a revert of b6bbfff8c0c6c44cdab0d7d78 which temporarily disabled
this.

Turns out that a non-TSAN gen_snapshot would - when emitting code via
`Assembler::TsanLoadAcquire` - use an incorrect `Thread`-offset:

It calculated the offset via `Thread::OffsetFromThread`. That function
took a `dart::RuntimeEntry*` and tried to find its offset.

We happen to have the following leaf runtime entries:

  #define LEAF_RUNTIME_ENTRY_LIST(V)
      ...
      V(void, MsanUnpoison, void*, size_t)
      V(void, MsanUnpoisonParam, size_t)
      V(void, TsanLoadAcquire, void*)
      V(void, TsanStoreRelease, void*)
      ...

It loops over all runtime entries and finds the first one that has the
identical `dart::RuntimeEntry::function_` pointer.

Though all 4 of them are `nullptr` at `gen_snapshot` time, so when
searching for offset for

  `Thread::OffsetFromThread(kTsanLoadAcquireRuntimeEntry)`

it looked for the first runtime entry with `nullptr` function pointer -
which turned out to be `MsanUnpoison` (instead of `TsanLoadAcquire`).

=> The obvious fix is to use the `dart::RuntimeEntry*` pointer for
comparison instead of it's `function_` member.

TEST=ci
Issue b/287638965

Change-Id: I85c06674927978ef8561e9e7bdfab4823c0a8e1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312902
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
Martin Kustermann 2023-07-10 11:53:58 +00:00 committed by Commit Queue
parent 911b376f7e
commit 389aab624d
2 changed files with 4 additions and 3 deletions

View file

@ -38,7 +38,8 @@ extern "C" void __tsan_release(void* addr);
// Though in our AOT compiler we don't know whether the target AOT runtime will
// use TSAN or not, so we'll rely on the build rules telling us that
// information.
#if defined(USING_THREAD_SANITIZER) && !defined(TARGET_USES_THREAD_SANITIZER)
#if defined(USING_THREAD_SANITIZER) && !defined(DART_PRECOMPILER) && \
!defined(TARGET_USES_THREAD_SANITIZER)
#define TARGET_USES_THREAD_SANITIZER
#endif

View file

@ -1140,14 +1140,14 @@ bool Thread::ObjectAtOffset(intptr_t offset, Object* object) {
intptr_t Thread::OffsetFromThread(const RuntimeEntry* runtime_entry) {
#define COMPUTE_OFFSET(name) \
if (runtime_entry->function() == k##name##RuntimeEntry.function()) { \
if (runtime_entry == &k##name##RuntimeEntry) { \
return Thread::name##_entry_point_offset(); \
}
RUNTIME_ENTRY_LIST(COMPUTE_OFFSET)
#undef COMPUTE_OFFSET
#define COMPUTE_OFFSET(returntype, name, ...) \
if (runtime_entry->function() == k##name##RuntimeEntry.function()) { \
if (runtime_entry == &k##name##RuntimeEntry) { \
return Thread::name##_entry_point_offset(); \
}
LEAF_RUNTIME_ENTRY_LIST(COMPUTE_OFFSET)