]> Cypherpunks repositories - gostls13.git/commitdiff
ld: ensure that PE versions sync for internal and external linkage
authorJason A. Donenfeld <Jason@zx2c4.com>
Mon, 26 Aug 2019 13:21:36 +0000 (07:21 -0600)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 31 Aug 2019 14:56:29 +0000 (14:56 +0000)
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/+/191842
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/pe.go

index 0564501b459da3adca24906281308ec2f858b960..92dc9ba061173b28dcbaa272885acf0a1041f2bf 100644 (file)
@@ -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
index e3fe2f9ce509cc86b307a1fa06ad2865c6b1e391..ab51c874ce7358d8b031518ee012035b88c28b0e 100644 (file)
@@ -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)