From 5bc8fa74f5186dc7898126487c31283d0766a5b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Wed, 31 Aug 2022 14:25:11 +0100 Subject: [PATCH] cmd/go: support long commands in asm and cgo MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Run-TryBot: Daniel Martí Reviewed-by: Keith Randall Auto-Submit: Keith Randall Reviewed-by: Keith Randall TryBot-Result: Gopher Robot --- src/cmd/asm/internal/flags/flags.go | 3 +-- src/cmd/cgo/main.go | 3 +-- src/cmd/go/internal/work/exec.go | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cmd/asm/internal/flags/flags.go b/src/cmd/asm/internal/flags/flags.go index 1c8b908860..d5e818223b 100644 --- a/src/cmd/asm/internal/flags/flags.go +++ b/src/cmd/asm/internal/flags/flags.go @@ -73,8 +73,7 @@ func Usage() { } func Parse() { - flag.Usage = Usage - flag.Parse() + objabi.Flagparse(Usage) if flag.NArg() == 0 { flag.Usage() } diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 4f94d77c0a..55515a677f 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -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 diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 497d7fda3a..bba6e452ed 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -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 } -- 2.48.1