Skip to content

[tsan] Go's thread sanitizer prints garbage #144400

Open
@tuliom

Description

@tuliom

tsan_go.cpp prints garbage under rare circumstances, e.g.

        WARNING: DATA RACE
        Write at 0x�gc000010258 by goroutine 6:
          main.store()
              /tmp/TestOutput2447268894/002/main.go:14 +0x75
          main.racer()
              /tmp/TestOutput2447268894/002/main.go:23 +0x42

The file is generated using buildgo.sh.

I've been able to reproduce this with LLVM 18, 20 and main.
While it seems easier to reproduce on s390x, I've already seen it happen on ppc64le.
The problem goes away when debug information is enabled or a lower -O is used.

Steps to reproduce the issue:

  1. Build compiler-rt using https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/tsan/go/buildgo.sh
  2. If memory is aligned, you'll see an output similar to this:
WARNING: DATA RACE
Read at 0x�'c011110000 by goroutine 2:
  <null>()
      <null>:0 +0x0

Previous write at 0x01c011110000 by main goroutine:
  <null>()
      <null>:0 +0x0
  <null>()
      <null>:0 +0x0

Goroutine 2 (running) created at:
  <null>()
      <null>:0 +0x0
==================
Found 1 data race(s)

This will generate gotsan.cpp, link it with https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/tsan/go/test.c and execute the test.

While debugging it, I noticed the problem happened when executing AppendNumber. internal_memset() is called with a 16-byte alignment, hitting this code.
AFAICS, this code is not storing anything in memory.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions