Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go
Submodule go updated 571 files
28 changes: 20 additions & 8 deletions patches/0001-Vendor-external-dependencies.patch
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ Use a 'go' that was recently built by the current branch to ensure stable result
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/internal/sysdll/sys_windows.go

diff --git a/src/cmd/go.mod b/src/cmd/go.mod
index 3bc983397186a6..6556bfdbe3f0a4 100644
index d15db1306b8e0b..f726601843bdaa 100644
--- a/src/cmd/go.mod
+++ b/src/cmd/go.mod
@@ -4,6 +4,8 @@ go 1.27
Expand All @@ -536,9 +536,9 @@ index 3bc983397186a6..6556bfdbe3f0a4 100644
+ github.com/microsoft/go-infra/telemetry/config v0.0.0-20260128082012-a1498e2b57dd
golang.org/x/arch v0.23.1-0.20260109160903-657d90bd6695
golang.org/x/build v0.0.0-20260122183339-3ba88df37c64
golang.org/x/mod v0.32.0
golang.org/x/mod v0.34.0
diff --git a/src/cmd/go.sum b/src/cmd/go.sum
index 224585feb6332d..ebf6a4c11e165e 100644
index 23627773f00451..5ac25412c24ac4 100644
--- a/src/cmd/go.sum
+++ b/src/cmd/go.sum
@@ -4,6 +4,10 @@ github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 h1:z2ogiKUYzX5Is6zr/v
Expand Down Expand Up @@ -2147,7 +2147,7 @@ index 00000000000000..d592037b570130
+ return ok
+}
diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt
index ceed574b32b507..e29e38f7da3cb3 100644
index 7b5b9aa37f749c..c2b79ea9ca5213 100644
--- a/src/cmd/vendor/modules.txt
+++ b/src/cmd/vendor/modules.txt
@@ -16,6 +16,17 @@ github.com/google/pprof/third_party/svgpan
Expand Down Expand Up @@ -2197,11 +2197,15 @@ index 00000000000000..ae4055d2d71303
+// that are used by the backend package. This allows to track
+// their versions in a single patch file.
diff --git a/src/go.mod b/src/go.mod
<<<<<<< HEAD
index 2ac54d7b35e011..043e7ea6bbe4a8 100644
=======
index d6c515017a7009..17efde8b19a412 100644
>>>>>>> upstream/microsoft/main
--- a/src/go.mod
+++ b/src/go.mod
@@ -11,3 +11,9 @@ require (
golang.org/x/sys v0.40.1-0.20260116220947-d25a7aaff8c2 // indirect
golang.org/x/sys v0.42.1-0.20260320201212-a76ec62d6c53 // indirect
golang.org/x/text v0.33.1-0.20260122225119-3264de9174be // indirect
)
+
Expand All @@ -2211,7 +2215,11 @@ index d6c515017a7009..17efde8b19a412 100644
+ github.com/microsoft/go-crypto-winnative v0.0.0-20260307231751-f82d13314c5c
+)
diff --git a/src/go.sum b/src/go.sum
<<<<<<< HEAD
index ba6fd0576632d4..40a76b70d3cc2d 100644
=======
index 2223d2a7c231c1..0f168e2048a2e2 100644
>>>>>>> upstream/microsoft/main
--- a/src/go.sum
+++ b/src/go.sum
@@ -1,3 +1,9 @@
Expand All @@ -2225,7 +2233,7 @@ index 2223d2a7c231c1..0f168e2048a2e2 100644
golang.org/x/crypto v0.47.1-0.20260113154411-7d0074ccc6f1/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/net v0.49.1-0.20260122225915-f2078620ee33 h1:pNHjOZ0w6qb8R9EDmEsBXmV4o2YKLvtRiEk4q5gN5Hg=
diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go
index 863882aebf583e..a0436aa1901b7e 100644
index be424e1b16c8d0..722b21661f29a8 100644
--- a/src/go/build/deps_test.go
+++ b/src/go/build/deps_test.go
@@ -154,6 +154,13 @@ var depsRules = `
Expand Down Expand Up @@ -2305,7 +2313,7 @@ index 863882aebf583e..a0436aa1901b7e 100644
CRYPTO, FMT, math/big, internal/saferio
< crypto/internal/boring/bbig
< crypto/internal/fips140cache
@@ -924,7 +965,7 @@ var buildIgnore = []byte("\n//go:build ignore")
@@ -928,7 +969,7 @@ var buildIgnore = []byte("\n//go:build ignore")

func findImports(pkg string) ([]string, error) {
vpkg := pkg
Expand All @@ -2314,7 +2322,7 @@ index 863882aebf583e..a0436aa1901b7e 100644
vpkg = "vendor/" + pkg
}
dir := filepath.Join(Default.GOROOT, "src", vpkg)
@@ -934,7 +975,7 @@ func findImports(pkg string) ([]string, error) {
@@ -938,7 +979,7 @@ func findImports(pkg string) ([]string, error) {
}
var imports []string
var haveImport = map[string]bool{}
Expand Down Expand Up @@ -38188,7 +38196,11 @@ index 00000000000000..1722410e5af193
+ return getSystemDirectory() + "\\" + dll
+}
diff --git a/src/vendor/modules.txt b/src/vendor/modules.txt
<<<<<<< HEAD
index e8c6f1efb099eb..ad1216357d8cb2 100644
=======
index 48967bc9ee3bd2..203fcbdad089ae 100644
>>>>>>> upstream/microsoft/main
--- a/src/vendor/modules.txt
+++ b/src/vendor/modules.txt
@@ -1,3 +1,26 @@
Expand Down
18 changes: 9 additions & 9 deletions patches/0013-Add-Microsoft-version-information.patch
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ Microsoft build of Go version string.
create mode 100644 src/cmd/go/testdata/script/gotoolchain_local_ms.txt

diff --git a/doc/godebug.md b/doc/godebug.md
index 4c95ceb09bcbbe..6b052d8ce29b6a 100644
index beee0f46498d4d..f2eb13d1dde4d4 100644
--- a/doc/godebug.md
+++ b/doc/godebug.md
@@ -192,6 +192,15 @@ Microsoft build of Go 1.26 added a new `ms_tlsprofile` setting that controls the
@@ -218,6 +218,15 @@ Microsoft build of Go 1.26 added a new `ms_tlsprofile` setting that controls the
- "default": use the recommended Microsoft TLS settings. This is the default.
- "off": use the default upstream Go TLS settings.

Expand All @@ -51,7 +51,7 @@ index 4c95ceb09bcbbe..6b052d8ce29b6a 100644

Go 1.25 added a new `decoratemappings` setting that controls whether the Go
diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
index 917f682fd4bfaf..85512e38220de6 100644
index feef0080cb12d6..e9b74bd4abf191 100644
--- a/src/cmd/dist/build.go
+++ b/src/cmd/dist/build.go
@@ -450,6 +450,22 @@ func findgoversion() string {
Expand Down Expand Up @@ -334,10 +334,10 @@ index 00000000000000..24538695be2cf2
+go version
+stdout go1.501
diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go
index 0140c385e47991..727a992bdf7a11 100644
index 24fecd47360a8d..cb4b51df2aeebd 100644
--- a/src/cmd/link/internal/ld/main.go
+++ b/src/cmd/link/internal/ld/main.go
@@ -186,15 +186,20 @@ func Main(arch *sys.Arch, theArch Arch) {
@@ -188,15 +188,20 @@ func Main(arch *sys.Arch, theArch Arch) {
addstrdata1(ctxt, "runtime.defaultGOROOT="+buildcfg.GOROOT)
}

Expand All @@ -364,7 +364,7 @@ index 0140c385e47991..727a992bdf7a11 100644

// TODO(matloob): define these above and then check flag values here
if ctxt.Arch.Family == sys.AMD64 && buildcfg.GOOS == "plan9" {
@@ -210,10 +215,28 @@ func Main(arch *sys.Arch, theArch Arch) {
@@ -212,10 +217,28 @@ func Main(arch *sys.Arch, theArch Arch) {
objabi.Flagfn1("X", "add string value `definition` of the form importpath.name=value", func(s string) { addstrdata1(ctxt, s) })
objabi.Flagcount("v", "print link trace", &ctxt.Debugvlog)
objabi.Flagfn1("importcfg", "read import configuration from `file`", ctxt.readImportCfg)
Expand Down Expand Up @@ -443,7 +443,7 @@ index 89fd74eb823162..f6d6a78531fc75 100644
var Error error

diff --git a/src/internal/godebugs/table.go b/src/internal/godebugs/table.go
index 7a5ea67c7dca33..d3e5b7b71d528c 100644
index 1ba17bc136710f..a3868ad860ed4a 100644
--- a/src/internal/godebugs/table.go
+++ b/src/internal/godebugs/table.go
@@ -51,6 +51,7 @@ var All = []Info{
Expand Down Expand Up @@ -495,7 +495,7 @@ index a9f97a1a045525..991d5ef22c5df5 100644

// GOOS is the running program's operating system target:
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go
index 965ff8ab5167d5..2674b5d8844b18 100644
index 10754eee1cd999..20ce0d57d003bd 100644
--- a/src/runtime/runtime1.go
+++ b/src/runtime/runtime1.go
@@ -364,6 +364,9 @@ var debug struct {
Expand All @@ -509,7 +509,7 @@ index 965ff8ab5167d5..2674b5d8844b18 100644

var dbgvars = []*dbgVar{
@@ -401,6 +404,7 @@ var dbgvars = []*dbgVar{
{name: "tracebacklabels", atomic: &debug.tracebacklabels, def: 0},
{name: "tracebacklabels", atomic: &debug.tracebacklabels, def: 1},
{name: "tracefpunwindoff", value: &debug.tracefpunwindoff},
{name: "updatemaxprocs", value: &debug.updatemaxprocs, def: 1},
+ {name: "ms_version", atomic: &debug.msversion, def: 0},
Expand Down
216 changes: 216 additions & 0 deletions patches/0016-cmd-link-fix-host-object-s-.pdata-entries-order.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: bot-for-go[bot] <199222863+bot-for-go[bot]@users.noreply.github.com>
Date: Wed, 11 Mar 2026 13:14:41 +0100
Subject: [PATCH] cmd/link: fix host object's .pdata entries order

Host objects are expected to have their .pdata entries in the correct
order, but the Go internal linker might reorder some of the functions
associated with the .pdata entries. This causes the .pdata section
in the final binary to have entries in the wrong order, and therefore
issues with unwinding on Windows.

The fix is to treat the .pdata entries of host objects as individual
symbols that will be retained only if the function they are associated
with is retained. Also, those entries will be sorted together with the
.pdata entries emitted by the Go compiler, ensuring the correct order
in the final binary.

Fixes #65116

Change-Id: I421471b2aef519b0c20707a40c4b7957db5d2ed5
---
src/cmd/link/internal/ld/data.go | 14 ++++++
src/cmd/link/internal/ld/lib.go | 4 +-
src/cmd/link/internal/loadpe/ldpe.go | 17 +++++--
src/cmd/link/internal/loadpe/seh.go | 69 +++++++++++++++++++++-------
4 files changed, 79 insertions(+), 25 deletions(-)

diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go
index 1265b028e679fa..6ea55deebd8b16 100644
--- a/src/cmd/link/internal/ld/data.go
+++ b/src/cmd/link/internal/ld/data.go
@@ -1689,6 +1689,20 @@ func (ctxt *Link) dodata(symGroupType []sym.SymKind) {
ldr.SetAttrOnList(s, true)
}

+ // SEH symbols are tracked in side lists (sehp.pdata/xdata), so make
+ // them follow the same reachability decision used for all other data.
+ filterReachableSEH := func(syms []loader.Sym) []loader.Sym {
+ out := syms[:0]
+ for _, s := range syms {
+ if ldr.AttrReachable(s) {
+ out = append(out, s)
+ }
+ }
+ return out
+ }
+ sehp.pdata = filterReachableSEH(sehp.pdata)
+ sehp.xdata = filterReachableSEH(sehp.xdata)
+
// Now that we have the data symbols, but before we start
// to assign addresses, record all the necessary
// dynamic relocations. These will grow the relocation
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 1c2b344abef7aa..77397383a79e88 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -2411,9 +2411,7 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
if len(ls.Resources) != 0 {
setpersrc(ctxt, ls.Resources)
}
- if ls.PData != 0 {
- sehp.pdata = append(sehp.pdata, ls.PData)
- }
+ sehp.pdata = append(sehp.pdata, ls.PData...)
if ls.XData != 0 {
sehp.xdata = append(sehp.xdata, ls.XData)
}
diff --git a/src/cmd/link/internal/loadpe/ldpe.go b/src/cmd/link/internal/loadpe/ldpe.go
index 2073045c479a97..fe39fad429d1f8 100644
--- a/src/cmd/link/internal/loadpe/ldpe.go
+++ b/src/cmd/link/internal/loadpe/ldpe.go
@@ -222,7 +222,7 @@ var comdatDefinitions map[string]int64
type Symbols struct {
Textp []loader.Sym // text symbols
Resources []loader.Sym // .rsrc section or set of .rsrc$xx sections
- PData loader.Sym
+ PData []loader.Sym
XData loader.Sym
}

@@ -256,7 +256,10 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
defer f.Close()
state.f = f

- var ls Symbols
+ var (
+ ls Symbols
+ pdata loader.Sym
+ )

// TODO return error if found .cormeta

@@ -312,7 +315,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
ls.Resources = append(ls.Resources, s)
} else if bld.Type() == sym.SSEHSECT {
if sect.Name == ".pdata" {
- ls.PData = s
+ pdata = s
} else if sect.Name == ".xdata" {
ls.XData = s
}
@@ -596,8 +599,12 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
}
}

- if ls.PData != 0 {
- processSEH(l, arch, ls.PData, ls.XData)
+ if pdata != 0 {
+ subs, err := processSEH(l, arch, pdata)
+ if err != nil {
+ return nil, err
+ }
+ ls.PData = subs
}

return &ls, nil
diff --git a/src/cmd/link/internal/loadpe/seh.go b/src/cmd/link/internal/loadpe/seh.go
index 545958f1d60bee..91d67c67fa7380 100644
--- a/src/cmd/link/internal/loadpe/seh.go
+++ b/src/cmd/link/internal/loadpe/seh.go
@@ -21,24 +21,19 @@ const (
unwCodeSize = 2 // Bytes per unwind code.
)

-// processSEH walks all pdata relocations looking for exception handler function symbols.
-// We want to mark these as reachable if the function that they protect is reachable
-// in the final binary.
-func processSEH(ldr *loader.Loader, arch *sys.Arch, pdata sym.LoaderSym, xdata sym.LoaderSym) error {
+// processSEH walks host-object pdata relocations and returns the set of
+// per-entry pdata symbols created from the input section.
+func processSEH(ldr *loader.Loader, arch *sys.Arch, pdata sym.LoaderSym) ([]loader.Sym, error) {
switch arch.Family {
case sys.AMD64:
- ldr.SetAttrReachable(pdata, true)
- if xdata != 0 {
- ldr.SetAttrReachable(xdata, true)
- }
return processSEHAMD64(ldr, pdata)
default:
// TODO: support SEH on other architectures.
- return fmt.Errorf("unsupported architecture for SEH: %v", arch.Family)
+ return nil, fmt.Errorf("unsupported architecture for SEH: %v", arch.Family)
}
}

-func processSEHAMD64(ldr *loader.Loader, pdata sym.LoaderSym) error {
+func processSEHAMD64(ldr *loader.Loader, pdata sym.LoaderSym) ([]loader.Sym, error) {
// The following loop traverses a list of pdata entries,
// each entry being 3 relocations long. The first relocation
// is a pointer to the function symbol to which the pdata entry
@@ -48,18 +43,58 @@ func processSEHAMD64(ldr *loader.Loader, pdata sym.LoaderSym) error {
// https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64#struct-runtime_function
rels := ldr.Relocs(pdata)
if rels.Count()%3 != 0 {
- return fmt.Errorf(".pdata symbol %q has invalid relocation count", ldr.SymName(pdata))
+ return nil, fmt.Errorf(".pdata symbol %q has invalid relocation count", ldr.SymName(pdata))
}
+ data := ldr.Data(pdata)
+ entries := make([]loader.Sym, 0, rels.Count()/3)
+
for i := 0; i < rels.Count(); i += 3 {
- xrel := rels.At(i + 2)
- handler := findHandlerInXDataAMD64(ldr, xrel.Sym(), xrel.Add())
- if handler != 0 {
- sb := ldr.MakeSymbolUpdater(rels.At(i).Sym())
+ // Create a new symbol for the pdata entry.
+ entry := ldr.MakeSymbolBuilder("")
+ entry.SetType(sym.SSEHSECT)
+ entry.SetAlign(4)
+ entry.SetSize(12)
+ entryOff := int(rels.At(i).Off())
+ entryEnd := entryOff + 4*3
+ entry.SetData(data[entryOff:entryEnd:entryEnd])
+
+ // Add a relocation from the target function to the pdata entry
+ // and to the exception handler, if present, to ensure they are
+ // retained by dead code elimination.
+ if targetFunc := rels.At(i).Sym(); targetFunc != 0 {
+ sb := ldr.MakeSymbolUpdater(targetFunc)
r, _ := sb.AddRel(objabi.R_KEEP)
- r.SetSym(handler)
+ r.SetSym(entry.Sym())
+ xrel := rels.At(i + 2)
+ if xrel.Sym() != 0 {
+ r, _ = sb.AddRel(objabi.R_KEEP)
+ r.SetSym(xrel.Sym())
+ }
+ handler := findHandlerInXDataAMD64(ldr, xrel.Sym(), xrel.Add())
+ if handler != 0 {
+ r, _ = sb.AddRel(objabi.R_KEEP)
+ r.SetSym(handler)
+ }
}
+
+ // Copy the relocations from the original .pdata entry to the new symbol,
+ // adjusting the offsets.
+ for j := range 3 {
+ rOld := rels.At(i + j)
+ typ := rOld.Type()
+ if rOld.Weak() {
+ typ |= objabi.R_WEAK
+ }
+ rel, _ := entry.AddRel(typ)
+ rel.SetOff(int32(j * 4))
+ rel.SetSiz(rOld.Siz())
+ rel.SetSym(rOld.Sym())
+ rel.SetAdd(rOld.Add())
+ }
+
+ entries = append(entries, entry.Sym())
}
- return nil
+ return entries, nil
}

// findHandlerInXDataAMD64 finds the symbol in the .xdata section that
Loading