msan4.go 878 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. // The memory profiler can call copy from a slice on the system stack,
  6. // which msan used to think meant a reference to uninitialized memory.
  7. /*
  8. #include <time.h>
  9. #include <unistd.h>
  10. extern void Nop(char*);
  11. // Use weak as a hack to permit defining a function even though we use export.
  12. void poison() __attribute__ ((weak));
  13. // Poison the stack.
  14. void poison() {
  15. char a[1024];
  16. Nop(&a[0]);
  17. }
  18. */
  19. import "C"
  20. import (
  21. "runtime"
  22. )
  23. func main() {
  24. runtime.MemProfileRate = 1
  25. start(100)
  26. }
  27. func start(i int) {
  28. if i == 0 {
  29. return
  30. }
  31. C.poison()
  32. // Tie up a thread.
  33. // We won't actually wait for this sleep to complete.
  34. go func() { C.sleep(1) }()
  35. start(i - 1)
  36. }
  37. //export Nop
  38. func Nop(*C.char) {
  39. }