Skip to content

Commit

Permalink
cmd/link/internal/ld: don't set IMAGE_FILE_DEBUG_STRIPPED on PE binaries
Browse files Browse the repository at this point in the history
The IMAGE_FILE_DEBUG_STRIPPED characteristic is used to inform that
the debugging information have been removed from the PE files and moved
into a DBG file, but the Go linker doesn't generate DBG files.

Having this characteristic can confuse debugging tools, so better
don't set it.

While here, remove also IMAGE_FILE_LINE_NUMS_STRIPPED, which is
deprecated and should be zero [1].

Fixes golang#59391

[1] https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#characteristics

Change-Id: Ia6b1dc3353bfa292a17c4bef17c9bac8dc95189a
Reviewed-on: https://go-review.googlesource.com/c/go/+/481615
Reviewed-by: Alex Brainman <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
Run-TryBot: Quim Muntal <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
  • Loading branch information
qmuntal committed Apr 7, 2023
1 parent 9be533a commit 949fdd9
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/cmd/link/internal/ld/pe.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,8 @@ func (f *peFile) writeFileHeader(ctxt *Link) {
// much more beneficial than having build timestamp in the header.
fh.TimeDateStamp = 0

if ctxt.LinkMode == LinkExternal {
fh.Characteristics = pe.IMAGE_FILE_LINE_NUMS_STRIPPED
} else {
fh.Characteristics = pe.IMAGE_FILE_EXECUTABLE_IMAGE | pe.IMAGE_FILE_DEBUG_STRIPPED
if ctxt.LinkMode != LinkExternal {
fh.Characteristics = pe.IMAGE_FILE_EXECUTABLE_IMAGE
switch ctxt.Arch.Family {
case sys.AMD64, sys.I386:
if ctxt.BuildMode != BuildModePIE {
Expand Down

0 comments on commit 949fdd9

Please sign in to comment.