Commit c96d794f authored by Jason A. Donenfeld's avatar Jason A. Donenfeld

ld: ensure that PE versions sync for internal and external linkage

Previously users who opted into cgo might have received a bit of a
behavior surprise when their mingw installation defaulted to a
potentially older and different set of compatibility hacks. Since Go is
explicitly targeting >=6.1 for internal linkage, propagate these changes
to external linkage too.

While we're at it, we move these values into constant variables so that
they don't become out of sync and allow for easy updating as Go
gradually drops compatibility for older operating systems.

Change-Id: I41e654d135be6e3db9088e73efeb414933e36caa
Reviewed-on: https://go-review.googlesource.com/c/go/+/191842Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent 8fc35238
......@@ -1175,6 +1175,11 @@ func (ctxt *Link) hostlink() {
// Mark as having awareness of terminal services, to avoid
// ancient compatibility hacks.
argv = append(argv, "-Wl,--tsaware")
argv = append(argv, fmt.Sprintf("-Wl,--major-os-version=%d", PeMinimumTargetMajorVersion))
argv = append(argv, fmt.Sprintf("-Wl,--minor-os-version=%d", PeMinimumTargetMinorVersion))
argv = append(argv, fmt.Sprintf("-Wl,--major-subsystem-version=%d", PeMinimumTargetMajorVersion))
argv = append(argv, fmt.Sprintf("-Wl,--minor-subsystem-version=%d", PeMinimumTargetMinorVersion))
case objabi.Haix:
argv = append(argv, "-pthread")
// prevent ld to reorder .text functions to keep the same
......
......@@ -128,6 +128,11 @@ const (
IMAGE_REL_BASED_HIGHLOW = 3
)
const (
PeMinimumTargetMajorVersion = 6
PeMinimumTargetMinorVersion = 1
)
// DOS stub that prints out
// "This program cannot be run in DOS mode."
var dosstub = []uint8{
......@@ -830,18 +835,18 @@ func (f *peFile) writeOptionalHeader(ctxt *Link) {
oh.SectionAlignment = uint32(PESECTALIGN)
oh64.FileAlignment = uint32(PEFILEALIGN)
oh.FileAlignment = uint32(PEFILEALIGN)
oh64.MajorOperatingSystemVersion = 6
oh.MajorOperatingSystemVersion = 6
oh64.MinorOperatingSystemVersion = 1
oh.MinorOperatingSystemVersion = 1
oh64.MajorOperatingSystemVersion = PeMinimumTargetMajorVersion
oh.MajorOperatingSystemVersion = PeMinimumTargetMajorVersion
oh64.MinorOperatingSystemVersion = PeMinimumTargetMinorVersion
oh.MinorOperatingSystemVersion = PeMinimumTargetMinorVersion
oh64.MajorImageVersion = 1
oh.MajorImageVersion = 1
oh64.MinorImageVersion = 0
oh.MinorImageVersion = 0
oh64.MajorSubsystemVersion = 6
oh.MajorSubsystemVersion = 6
oh64.MinorSubsystemVersion = 1
oh.MinorSubsystemVersion = 1
oh64.MajorSubsystemVersion = PeMinimumTargetMajorVersion
oh.MajorSubsystemVersion = PeMinimumTargetMajorVersion
oh64.MinorSubsystemVersion = PeMinimumTargetMinorVersion
oh.MinorSubsystemVersion = PeMinimumTargetMinorVersion
oh64.SizeOfImage = f.nextSectOffset
oh.SizeOfImage = f.nextSectOffset
oh64.SizeOfHeaders = uint32(PEFILEHEADR)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment