diff options
| author | Kevin Parsons <kevpar@microsoft.com> | 2023-01-17 08:02:17 +0000 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-01-20 20:52:48 +0000 |
| commit | e587a7691b8603a89f55a57f78dae5e20fdbf5d1 (patch) | |
| tree | 666e9ceda99c00d15432cd28febaa2f859d9f712 | |
| parent | b08d5ee5e9c700a1267f0b883702766a19d89b2d (diff) | |
| download | go-e587a7691b8603a89f55a57f78dae5e20fdbf5d1.tar.xz | |
cmd/link: fix incorrect DOS header on Windows binaries
The previous DOS header placed on Windows binaries was incorrect, as it had e_crlc (number of relocations) set to 4, instead of e_cparhdr (size of header in 16-bit words) set to 4. This resulted in execution starting at the beginning of the file, instead of where the DOS stub code actually exists.
Fixes #57834
Change-Id: I8c5966b65c72b2474b771b85aaadb61cad9f5be6
GitHub-Last-Rev: c715ad290a01218a1320834e519125e7a5f94384
GitHub-Pull-Request: golang/go#57835
Reviewed-on: https://go-review.googlesource.com/c/go/+/462054
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
| -rw-r--r-- | src/cmd/link/internal/ld/pe.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index 0e291311a0..10c1dc4ab3 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -152,6 +152,7 @@ const ( // DOS stub that prints out // "This program cannot be run in DOS mode." +// See IMAGE_DOS_HEADER in the Windows SDK for the format of the header used here. var dosstub = []uint8{ 0x4d, 0x5a, @@ -159,9 +160,9 @@ var dosstub = []uint8{ 0x00, 0x03, 0x00, - 0x04, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, |
