Skip to content

Commit aa31c67

Browse files
authored
fix(bindings): strip debug info on Windows to avoid Go 1.25 DWARF5 PE bug (#5524)
Go 1.25 switched to DWARF5 debug format by default. On Windows, the internal linker emits malformed PE section headers when DWARF5 sections are present, producing a binary that Windows refuses to execute: fork/exec wailsbindings.exe: %1 is not a valid Win32 application. fork/exec wailsbindings.exe: This version of %1 is not compatible with the version of Windows you're running. Pass -ldflags="-s -w" when building wailsbindings.exe on Windows. Stripping debug info removes DWARF5 sections entirely, producing clean PE headers. This is appropriate for a temporary tool binary that is deleted immediately after use and never debugged. The fix works regardless of whether the user's project uses CGO. Upstream: golang/go#75077, golang/go#75121 Fixes #4605 Fixes #4551
1 parent ff529b7 commit aa31c67

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

v2/pkg/commands/bindings/bindings.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ func GenerateBindings(options Options) (string, error) {
6060
// So, use the default C compiler, not the one set for cross compiling.
6161
envBuild = shell.RemoveEnv(envBuild, "CC")
6262

63-
stdout, stderr, err = shell.RunCommandWithEnv(envBuild, workingDirectory, options.Compiler, "build", "-buildvcs=false", "-tags", tagString, "-o", filename)
63+
buildArgs := []string{"build", "-buildvcs=false", "-tags", tagString, "-o", filename}
64+
if runtime.GOOS == "windows" {
65+
// Go 1.25 switched to DWARF5 by default, which causes the internal
66+
// linker to emit malformed PE section headers on Windows — the binary
67+
// won't run ("not a valid Win32 application" / "not compatible with
68+
// the version of Windows"). Stripping debug info avoids DWARF5
69+
// entirely and is appropriate for a temporary tool binary.
70+
// See golang/go#75077, golang/go#75121, wails#4551, wails#4605.
71+
buildArgs = append(buildArgs, "-ldflags=-s -w")
72+
}
73+
stdout, stderr, err = shell.RunCommandWithEnv(envBuild, workingDirectory, options.Compiler, buildArgs...)
6474
if err != nil {
6575
return stdout, fmt.Errorf("%s\n%s\n%s", stdout, stderr, err)
6676
}

0 commit comments

Comments
 (0)