cmd/link/internal/ld: don't set IMAGE_FILE_DEBUG_STRIPPED on PE binaries

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 #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 <alex.brainman@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
qmuntal 2023-04-03 10:01:43 +02:00 committed by Quim Muntal
parent 9be533a8ee
commit 949fdd9f0d
1 changed files with 2 additions and 4 deletions

View File

@ -888,10 +888,8 @@ func (f *peFile) writeFileHeader(ctxt *Link) {
// much more beneficial than having build timestamp in the header. // much more beneficial than having build timestamp in the header.
fh.TimeDateStamp = 0 fh.TimeDateStamp = 0
if ctxt.LinkMode == LinkExternal { if ctxt.LinkMode != LinkExternal {
fh.Characteristics = pe.IMAGE_FILE_LINE_NUMS_STRIPPED fh.Characteristics = pe.IMAGE_FILE_EXECUTABLE_IMAGE
} else {
fh.Characteristics = pe.IMAGE_FILE_EXECUTABLE_IMAGE | pe.IMAGE_FILE_DEBUG_STRIPPED
switch ctxt.Arch.Family { switch ctxt.Arch.Family {
case sys.AMD64, sys.I386: case sys.AMD64, sys.I386:
if ctxt.BuildMode != BuildModePIE { if ctxt.BuildMode != BuildModePIE {