This is an archive of the discontinued LLVM Phabricator instance.

tsan: add notion of compressed addresses
ClosedPublic

Authored by dvyukov on Aug 9 2021, 12:53 AM.

Details

Summary

New tsan runtime will need to compress addresses/PCs to fewer bits.
Add CompressAddr/RestoreAddr functions that compress/restore
addresses to 44 bits.

Depends on D107744.

Diff Detail

Event Timeline

dvyukov requested review of this revision.Aug 9 2021, 12:53 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2021, 12:53 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
melver accepted this revision.Aug 9 2021, 9:06 AM
melver added inline comments.
compiler-rt/lib/tsan/rtl/tsan_platform.h
906

Just an idea: does it in any way make sense to make the compressed addr a stronger type, i.e.:

class CompressedAddr {
 public:
  explicit constexpr CompressedAddr(uptr addr) ...

  template <typename Mapping>
  uptr Restore() ....
};

Might make misuse harder.

I may have not paid attention how you pass around the compressed addr, so if that's infeasible, that's fine.

This revision is now accepted and ready to land.Aug 9 2021, 9:06 AM
dvyukov added inline comments.Aug 9 2021, 10:13 AM
compiler-rt/lib/tsan/rtl/tsan_platform.h
906

The only way compressed addresses will be used is within u64 bitfields, so even if use a strong enum class, we will need to cast to u64 immediately and back...
And it does not make sense to use compressed address in other contexts, because if it still takes whole u64, there is no point in compressing.

dvyukov updated this revision to Diff 365248.Aug 9 2021, 11:48 AM

changed SelectMapping to use template Arg and rebased

This revision was landed with ongoing or failed builds.Aug 10 2021, 11:09 AM
This revision was automatically updated to reflect the committed changes.
wolfgangp added inline comments.
compiler-rt/lib/tsan/rtl/tsan_platform.h
935

This is causing a build error in our bot (maybe the formatting should be %zx?)

In file included from ../rtl/tsan_rtl.h:44:0,
                 from tsan_go.cpp:13:
../rtl/tsan_platform.h: In instantiation of 'static __tsan::RestoreAddrImpl::Result __tsan::RestoreAddrImpl::Apply(__sanitizer::uptr) [with Mapping = __tsan::MappingGo48; __tsan::RestoreAddrImpl::Result = long unsigned int; __sanitizer::uptr = long unsigned int]':
../rtl/tsan_platform.h:648:43:   required from 'auto __tsan::SelectMapping(Arg) [with Func = __tsan::RestoreAddrImpl; Arg = long unsigned int]'
../rtl/tsan_platform.h:934:45:   required from here
../rtl/tsan_platform.h:926:11: error: format '%p' expects argument of type 'void*', but argument 2 has type '__sanitizer::uptr {aka long unsigned int}' [-Werror=format=]
     Printf("ThreadSanitizer: failed to restore address %p\n", addr);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: error: unrecognized command line option '-Wno-unknown-warning-option' [-Werror]
cc1plus: all warnings being treated as errors