Skip to content

Commit bf9e5aa

Browse files
committed
fix(bindings): strip debug info on Windows to avoid Go 1.25 DWARF5 PE bug
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 03fab14 commit bf9e5aa

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

v2/pkg/commands/bindings/bindings.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ func GenerateBindings(options Options) (string, error) {
6262

6363
buildArgs := []string{"build", "-buildvcs=false", "-tags", tagString, "-o", filename}
6464
if runtime.GOOS == "windows" {
65-
// Go 1.25 changed external-linker behaviour on Windows, producing PE
66-
// binaries that Windows refuses to run ("not a valid Win32 application").
67-
// Force the internal linker to avoid this; it still supports CGO.
68-
// See https://github.com/wailsapp/wails/issues/4551 and #4605.
69-
buildArgs = append(buildArgs, "-ldflags=-linkmode=internal")
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")
7072
}
7173
stdout, stderr, err = shell.RunCommandWithEnv(envBuild, workingDirectory, options.Compiler, buildArgs...)
7274
if err != nil {

0 commit comments

Comments
 (0)