]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: support long commands in asm and cgo
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 31 Aug 2022 13:25:11 +0000 (14:25 +0100)
committerGopher Robot <gobot@golang.org>
Thu, 1 Sep 2022 16:55:25 +0000 (16:55 +0000)
We have supported passing lists of arguments to the compiler and linker
for some time, since https://go.dev/issue/18468 was fixed.
The reason behind it is that some systems like Windows have relatively
small limits for commands, and some Go packages contain many source files.

This wasn't done for other Go toolchain programs like cgo and asm,
as there wasn't an initial need for it. A TODO was left for them.
The need has now arisen in the form of a bug report for a build of a
large Go package involving cgo.

Do asm as well, which could be triggered by lots of asm files.

I rebuilt Go itself with some basic logging to tell if any other
commands were being run with moderately large command lengths.
I only found one other: gcc being invoked with 300-500 bytes.

I didn't spot any length close to 1KiB, and we can't safely assume that
a user's CC compiler supports these "response files", so leave that as
another TODO for the future. Just like cgo and asm, we can revisit this
if any user reports a bug on the issue tracker.

Fixes #47235.

Change-Id: Ifcc099d7c0dfac3ed2c4e9e7a2d6e3d69b0ccb63
Reviewed-on: https://go-review.googlesource.com/c/go/+/427015
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/asm/internal/flags/flags.go
src/cmd/cgo/main.go
src/cmd/go/internal/work/exec.go

index 1c8b908860203b658e45749c27acd2615cf6831f..d5e818223ba1ae480805c6936a8df0179e2248f0 100644 (file)
@@ -73,8 +73,7 @@ func Usage() {
 }
 
 func Parse() {
-       flag.Usage = Usage
-       flag.Parse()
+       objabi.Flagparse(Usage)
        if flag.NArg() == 0 {
                flag.Usage()
        }
index 4f94d77c0ab74b703aa84082631cf6a57b22806c..55515a677f6df34a883a666d9cc6c3640b757229 100644 (file)
@@ -252,8 +252,7 @@ var gccBaseCmd []string
 
 func main() {
        objabi.AddVersionFlag() // -V
-       flag.Usage = usage
-       flag.Parse()
+       objabi.Flagparse(usage)
 
        if *dynobj != "" {
                // cgo -dynimport is essentially a separate helper command
index 497d7fda3a5922f758396ce620e8320e36c7cabd..bba6e452ed4080590bbd544ac75ccdea4c756a20 100644 (file)
@@ -3407,10 +3407,10 @@ func passLongArgsInResponseFiles(cmd *exec.Cmd) (cleanup func()) {
 func useResponseFile(path string, argLen int) bool {
        // Unless the program uses objabi.Flagparse, which understands
        // response files, don't use response files.
-       // TODO: do we need more commands? asm? cgo? For now, no.
+       // TODO: Note that other toolchains like CC are missing here for now.
        prog := strings.TrimSuffix(filepath.Base(path), ".exe")
        switch prog {
-       case "compile", "link":
+       case "compile", "link", "cgo", "asm":
        default:
                return false
        }