Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime/race: race detector truncates command-line arguments on ppc64le #43883

Open
mdempsky opened this issue Jan 24, 2021 · 5 comments
Open

runtime/race: race detector truncates command-line arguments on ppc64le #43883

mdempsky opened this issue Jan 24, 2021 · 5 comments
Labels

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jan 24, 2021

When the program below is run with the race detector enabled, it truncates the command-line arguments list at the "" argument. In particular, this prevents using a race-detector-enabled cmd/compile on ppc64le, because cmd/go typically passes -D "".

I only see this on linux/ppc64le. I'm not able to reproduce the issue on linux/amd64.

$ go run hi.go -- one two "" three four
["/tmp/go-build2867456842/b001/exe/hi" "--" "one" "two" "" "three" "four"]
["one" "two" "" "three" "four"]

$ go run -race hi.go -- one two "" three four
["/tmp/go-build2206806436/b001/exe/hi" "--" "one" "two"]
["one" "two"]
package main

import (
	"flag"
	"fmt"
	"os"
)

func main() {
	fmt.Printf("%q\n", os.Args)
	flag.Parse()
	fmt.Printf("%q\n", flag.Args())
}

/cc @dvyukov

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 24, 2021

Change https://golang.org/cl/286173 mentions this issue: [dev.regabi] cmd/go: workaround -race issue on ppc64le

gopherbot pushed a commit that referenced this issue Jan 25, 2021
The race detector on ppc64le corrupts command-line arguments lists if
they contain an empty string, and cmd/go often generates compiler
argument lists containing `-D ""`. Since this is equivalent to not
specifying the `-D` flag at all, just do that. This allows using a
race-detector-enabled cmd/compile on ppc64le.

Updates #43883.

Change-Id: Ifac5cd9a44932129438b9b0b3ecc6101ad3716b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/286173
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jan 25, 2021

Just a guess: on some architectures, TSAN may re-exec the program (e.g. with ASLR disabled because it wants a specific memory layout). That re-exec might eat args. Maybe you could strace it to see if it re-exec? What is the output of ulimit -a on the machine?

@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented Jan 25, 2021

Maybe you could strace it to see if it re-exec?

That does seem like the culprit:

$ strace -f ./hi one two "" three four |& grep exec
execve("./hi", ["./hi", "one", "two", "", "three", "four"], 0x7fffe4ef9d90 /* 40 vars */) = 0
execve("/proc/self/exe", ["./hi", "one", "two"], 0x7fff96060000 /* 40 vars */) = 0

What is the output of ulimit -a on the machine?

$ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 246242
max locked memory       (kbytes, -l) 65536
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 246242
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jan 25, 2021

It's probably ASLR. Maybe you could try disable ASLR?

It is probably a bug in the re-exec code in TSAN.

@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented Jan 25, 2021

Yeah, looks like it's from TSAN working around ASLR:

$ ./hi one two "" three four
["./hi" "one" "two"]
["one" "two"]

$ setarch `uname -m` -R ./hi one two "" three four
["./hi" "one" "two" "" "three" "four"]
["one" "two" "" "three" "four"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants