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

cmd/cgo: TestCgoFlagContainsSpace test failures #20324

Closed
ALTree opened this issue May 11, 2017 · 7 comments

Comments

@ALTree
Copy link
Member

commented May 11, 2017

Commit 1df777f broke all.bash on my debian system (and on the linux-386-sid and linux-amd64-sid builders).

TestCgoFlagContainsSpace fails with:

--- FAIL: TestCgoFlagContainsSpace (0.41s)
	go_test.go:310: running testgo [build]
	go_test.go:310: running testgo [run /tmp/gotest310476999/src/cgo/cgo.go]
	go_test.go:323: standard error:
	go_test.go:324: # command-line-arguments
		panic: exit status 1
		
		goroutine 1 [running]:
		main.main()
			/tmp/gotest310476999/src/cc/main.go:32 +0x181
		
	go_test.go:333: go [run /tmp/gotest310476999/src/cgo/cgo.go] failed unexpectedly: exit status 2

CL 43155 does not help, it still fails with this:

--- FAIL: TestCgoFlagContainsSpace (0.46s)
	go_test.go:301: running testgo [env CC]
	go_test.go:310: standard output:
	go_test.go:311: gcc
		
	go_test.go:301: running testgo [env GOGCCFLAGS]
	go_test.go:310: standard output:
	go_test.go:311: -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build221354564=/tmp/go-build -gno-record-gcc-switches
		
	go_test.go:4103: package main
				import (
					"os"
					"os/exec"
				)
		
				func main() {
					var success bool
					for _, arg := range os.Args {
						switch arg {
						case "-Ic flags":
							if success {
								panic("duplicate CFLAGS")
							}
							success = true
						case "-Lld flags":
							if success {
								panic("duplicate LDFLAGS")
							}
							success = true
						}
					}
					if !success {
						panic("args should contains '-Ic flags' or '-Lld flags'")
					}
					cc := []string{"gcc"}
					cc = append(cc, []string{"-fPIC", "-m64", "-pthread", "-fmessage-length=0", "-fdebug-prefix-map=/tmp/go-build221354564=/tmp/go-build", "-gno-record-gcc-switches"}...)
					cc = append(cc, os.Args[1:]...)
					cmd := exec.Command(cc[0], cc[1:]...)
					cmd.Stdin = os.Stdin
					cmd.Stdout = os.Stdout
					err := cmd.Run()
					if err != nil {
						panic(err)
					}
				}
			
	go_test.go:301: running testgo [build]
	go_test.go:301: running testgo [run /tmp/gotest620440761/src/cgo/cgo.go]
	go_test.go:314: standard error:
	go_test.go:315: # command-line-arguments
		panic: exit status 1
		
		goroutine 1 [running]:
		main.main()
			/tmp/gotest620440761/src/cc/main.go:35 +0x326
		
	go_test.go:324: go [run /tmp/gotest620440761/src/cgo/cgo.go] failed unexpectedly: exit status 2
$ uname -srvm
Linux 4.9.0-2-amd64 #1 SMP Debian 4.9.18-1 (2017-03-30) x86_64
$ gotip env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/adonizetti/gocode"
GORACE=""
GOROOT="/home/adonizetti/go"
GOTOOLDIR="/home/adonizetti/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build126439993=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

@ALTree ALTree added this to the Go1.9 milestone May 11, 2017

@hirochachacha

This comment has been minimized.

Copy link
Contributor

commented May 11, 2017

Unfortunately, I could not reproduce it on my env. (I don't know the meaning of 'sid')
Could you try a following patch?

diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index 131a0985ae..88c324befa 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -4055,7 +4055,7 @@ func TestCgoFlagContainsSpace(t *testing.T) {
 	tg := testgo(t)
 	defer tg.cleanup()
 
-	tg.tempFile("src/cc/main.go", fmt.Sprintf(`package main
+	tg.tempFile("src/gcc/main.go", fmt.Sprintf(`package main
 		import (
 			"os"
 			"os/exec"
@@ -4063,18 +4063,22 @@ func TestCgoFlagContainsSpace(t *testing.T) {
 
 		func main() {
 			var success bool
-			for _, arg := range os.Args {
-				switch arg {
-				case "-Ic flags":
-					if success {
-						panic("duplicate CFLAGS")
+			if os.Args[len(os.Args)-1] == "trivial.c" {
+				success = true
+			} else {
+				for _, arg := range os.Args {
+					switch arg {
+					case "-Ic flags":
+						if success {
+							panic("duplicate CFLAGS")
+						}
+						success = true
+					case "-Lld flags":
+						if success {
+							panic("duplicate LDFLAGS")
+						}
+						success = true
 					}
-					success = true
-				case "-Lld flags":
-					if success {
-						panic("duplicate LDFLAGS")
-					}
-					success = true
 				}
 			}
 			if !success {
@@ -4083,15 +4087,16 @@ func TestCgoFlagContainsSpace(t *testing.T) {
 			cmd := exec.Command(%q, os.Args[1:]...)
 			cmd.Stdin = os.Stdin
 			cmd.Stdout = os.Stdout
+			cmd.Stderr = os.Stderr
 			err := cmd.Run()
 			if err != nil {
 				panic(err)
 			}
 		}
 	`, testCC))
-	tg.cd(tg.path("src/cc"))
+	tg.cd(tg.path("src/gcc"))
 	tg.run("build")
-	tg.setenv("CC", tg.path("src/cc/cc"))
+	tg.setenv("CC", tg.path("src/gcc/gcc"))
 	tg.tempFile("src/cgo/cgo.go", `package main
 		// #cgo CFLAGS: -I"c flags"
 		// #cgo LDFLAGS: -L"ld flags"

Thanks.

@ALTree

This comment has been minimized.

Copy link
Member Author

commented May 11, 2017

sid is Debian Unstable: https://www.debian.org/releases/sid/

After your patch the test prints

--- FAIL: TestCgoFlagContainsSpace (0.38s)
	go_test.go:310: running testgo [build]
	go_test.go:310: running testgo [run /tmp/gotest074733030/src/cgo/cgo.go]
	go_test.go:323: standard error:
	go_test.go:324: # command-line-arguments
		/usr/bin/ld: -r and -pie may not be used together
		collect2: error: ld returned 1 exit status
		panic: exit status 1
		
		goroutine 1 [running]:
		main.main()
			/tmp/gotest074733030/src/gcc/main.go:33 +0x1a2
		
	go_test.go:333: go [run /tmp/gotest074733030/src/cgo/cgo.go] failed unexpectedly: exit status 2

This may be related to the debian transition to pie-by-default, see https://wiki.debian.org/Hardening/PIEByDefaultTransition

@ALTree

This comment has been minimized.

Copy link
Member Author

commented May 11, 2017

Did you edit your message? The patch I applied looks different from the one there's now in the message.

@hirochachacha

This comment has been minimized.

Copy link
Contributor

commented May 11, 2017

Oh, yes. I've edited it one hours ago.

@ALTree

This comment has been minimized.

Copy link
Member Author

commented May 11, 2017

The new version of the test in the patch above fixes the issue (at least on my machine).

@gopherbot

This comment has been minimized.

Copy link

commented May 12, 2017

CL https://golang.org/cl/43330 mentions this issue.

@hirochachacha

This comment has been minimized.

Copy link
Contributor

commented May 12, 2017

@gopherbot gopherbot closed this in 482da51 May 12, 2017

@golang golang locked and limited conversation to collaborators May 12, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.