-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cgo, cmd/go: add cgo -ldflags option, use it in cmd/go
This will automatically use a response file if ldflags is long, avoiding "argument list too long" errors with a very large CGO_LDFLAGS. Fixes #66456 Change-Id: I5f9ee86e03b4e6d6430f7f9d8357ef37a9c22465 Reviewed-on: https://go-review.googlesource.com/c/go/+/584655 Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
- Loading branch information
1 parent
f449452
commit a32e94d
Showing
4 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Issue #66456 | ||
|
||
[!cgo] skip | ||
[GOOS:windows] skip | ||
[GOOS:plan9] skip | ||
|
||
# Generate a file with a very long #cgo LDFLAGS line. | ||
# This used to cause "go build" to fail with "argument list too long". | ||
go generate | ||
|
||
# Build with the generated file. | ||
go build | ||
|
||
-- go.mod -- | ||
module cgolongcmd | ||
|
||
go 1.22 | ||
-- generate.go -- | ||
//go:build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"bytes" | ||
) | ||
|
||
func main() { | ||
var buf bytes.Buffer | ||
buf.WriteString("package p\n") | ||
buf.WriteString("// #cgo LDFLAGS:") | ||
for i := range 10000 { | ||
fmt.Fprintf(&buf, " -Wl,-rpath,/nonexistentpath/%d", i) | ||
} | ||
buf.WriteString("\n") | ||
buf.WriteString(`import "C"`+"\n") | ||
if err := os.WriteFile("generated.go", buf.Bytes(), 0o644); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
-- gen.go -- | ||
package p | ||
|
||
//go:generate go run generate.go |