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/go, cmd/link: use Windows response files for gcc/g++ to avoid arg length limits #28372

Open
therecipe opened this issue Oct 24, 2018 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@therecipe
Copy link

therecipe commented Oct 24, 2018

What version of Go are you using (go version)?

1.11.1

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

windows 386/amd64

What did you do?

Tried to compile a cgo program.

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
)

func main() {
	testCgo("c")
	testCgo("cpp")
}

func testCgo(ending string) {
	tmpdir, _ := ioutil.TempDir("", "cgo_resp_issue")
	defer os.RemoveAll(tmpdir)

	ioutil.WriteFile(filepath.Join(tmpdir, "gofile.go"), []byte(fmt.Sprint("package main\nimport \"C\"\nfunc main(){}")), 0644)
	for i := 0; i < 1000; i++ {
		ioutil.WriteFile(filepath.Join(tmpdir, fmt.Sprintf("cfile_%v."+ending, i)), []byte(fmt.Sprintf("void func_%v(){}", i)), 0644)
	}

	cmd := exec.Command("go", "build", "-v", "-x", "-ldflags=all=\"-extldflags=-v\"")
	cmd.Dir = tmpdir
	if out, err := cmd.CombinedOutput(); err != nil {
		println("failed:", ending, err.Error(), string(out))
	}
}

What did you expect to see?

a successful compilation

What did you see instead?

gcc: error: CreateProcess: No such file or directory
and/or
g++: error: CreateProcess: No such file or directory

Possible solution?

This patch works for my needs.
It's mostly a copy of: https://go-review.googlesource.com/c/go/+/110395
But I also needed to escape the backslashes to make it work.

[patch omitted]

More info

The issue is related to: #18468
and https://github.com/golang/go/blob/master/src/cmd/go/internal/work/exec.go#L2851

The problem is caused by the 32K character limit on windows
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createprocessasuserw

The maximum length of this string is 32K characters.


Also, once there is support for msvc on windows (#20982) it might be good idea to whitelist cl as well.

@ianlancetaylor
Copy link
Contributor

Sorry about this, but please don't send us patches in github issues. Please send us a pull request using either Github or Gerrit. See https://golang.org/doc/contribute.html. That will handle copyright issues for us. I've removed your patch from this issue to avoid confusion. Thanks.

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 24, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 24, 2018
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants