This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Add support for linux/powerpc64 in buildgo.sh
ClosedPublic

Authored by cseo on Feb 7 2018, 8:41 AM.

Details

Reviewers
dvyukov
Summary

The current implementation of the Go sanitizer only works on x86_64. Added
some modifications to the buildgo.sh script and the Tsan code to make it
work on powerpc64/linux.

Event Timeline

cseo created this revision.Feb 7 2018, 8:41 AM
Herald added subscribers: Restricted Project, llvm-commits, delcypher and 4 others. · View Herald TranscriptFeb 7 2018, 8:41 AM

Is there an upstream Go bug for race on powerpc? Please CC me on it.

lib/tsan/go/buildgo.sh
141

Please dedup the common part "-DSANITIZER_DEBUG=0 -O3 -fomit-frame-pointer" and then add arch-specific flags separately.

lib/tsan/rtl/tsan_platform.h
420

I see that Go heap always starts at 0x00c0 on powerpc:

			switch {
			case GOARCH == "arm64" && GOOS == "darwin":
				p = uintptr(i)<<40 | uintptrMask&(0x0013<<28)
			case GOARCH == "arm64":
				p = uintptr(i)<<40 | uintptrMask&(0x0040<<32)
			default:
				p = uintptr(i)<<40 | uintptrMask&(0x00c0<<32)
			}

And you don't cover this region, instead it's occupied by shadow.
How does this work?

cseo updated this revision to Diff 141886.EditedApr 10 2018, 11:37 AM

Version 2: update memory mappings, changed buildgo.sh FLAGS.

  • Note: decided to drop Mapping44 because I could not find a system old

enough for me to test it.

  • Go issue related to this: 23731
dvyukov added inline comments.Apr 11 2018, 1:51 AM
lib/tsan/go/buildgo.sh
60

List of sources is completely identical to amd64 version, please don't duplicate it. Just keep it outside of the arch if.

lib/tsan/rtl/tsan_platform.h
445

kLoAppMemEnd is 0x010000000000ull, please adjust this line.

448

remove this line

464

I don't see where/how this is used.

468

What lives in kHiAppMemBeg-kHiAppMemEnd range?

472

I don't see where/how this is used.

819

This is full copy of the C++ mapping, right?
If so, I think it will be better to just say #if !SANITIZER_GO || defined(__powerpc64__) rather than duplicate it.
This also applies to some other functions that do the same.

876–877

Why?

lib/tsan/rtl/tsan_platform_linux.cc
239

No need to duplicate this call.
Let's do:

vmaSize = (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1);
...
#   elif defined(__powerpc64__)
#     if !SANITIZER_GO
if (vmaSize != 44 && vmaSize != 46 && vmaSize != 47) { ... }
#     else
if (vmaSize != 44 && vmaSize != 46) { ... }
#     endif
lib/tsan/rtl/tsan_rtl.cc
309 ↗(On Diff #141886)

These VPrintf's look redundant (and mis-aligned). We already print p, s and MemToMeta(p) few lines above.
ShadowToMem(s) will be printed if CHECK fails (it prints argument values).

cseo marked 6 inline comments as done.Apr 11 2018, 11:54 AM
cseo added inline comments.
lib/tsan/rtl/tsan_platform.h
468

ld.so and shared libraries.

Actually, let me ask you about this, since it seems I'm understanding wrongly how this should work. Is it necessary to map these memory areas for shared libraries? Or just executable/heap/shadow/meta are enough for the Go sanitizer?

dvyukov added inline comments.Apr 12 2018, 3:09 AM
lib/tsan/rtl/tsan_platform.h
468

For Go we care about and only need shadow for Go's heap and data/bss segment. All other addresses never passed to tsan runtime, they are filtered here:
https://github.com/golang/go/blob/master/src/runtime/race_amd64.s#L147

So I think we don't need vdso, HiAppMem and HeapMem, we probably need something closer to x86_64 Go mapping.

cseo added inline comments.Apr 12 2018, 6:16 AM
lib/tsan/rtl/tsan_platform.h
468

Excellent, thanks!

I'll make the changes and resubmit.

cseo updated this revision to Diff 142192.Apr 12 2018, 8:31 AM

Version 3: new mappings, dropped unneeded memory areas.

Much nicer now!
I think this is ready for commit after fixing these few nits.

lib/tsan/go/buildgo.sh
59

If I am reading this correctly, amd64 will not have -fPIC because this overrides whole OSCFLAGS rather than append to them. Do we need something like:

OSCFLAGS="$OSCFLAGS -ffreestanding -Wno-unused-const-variable -Werror -Wno-unknown-warning-option"

?

lib/tsan/rtl/tsan_platform.h
414

This should be:

0000 0000 1000 - 0000 1000 0000

438

This should be:

0000 0000 1000 - 0000 1000 0000

cseo updated this revision to Diff 142407.Apr 13 2018, 7:43 AM
cseo marked 3 inline comments as done.

Version 3: fixed OSCFLAGS for amd64 in buildgo.sh and some comments in tsan_platform.h.

dvyukov accepted this revision.Apr 13 2018, 8:56 AM

Looks good to me.
Do you have commit access, or you want me to commit it?

This revision is now accepted and ready to land.Apr 13 2018, 8:56 AM
cseo added a comment.Apr 13 2018, 9:30 AM

Looks good to me.
Do you have commit access, or you want me to commit it?

Could you please do it? I don't have commit access. Thanks!

lib/tsan/go/buildgo.sh
59

Oops... sorry about that.