1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 "cmd/link/internal/loader"
10 "cmd/link/internal/sym"
17 func writeSEH(ctxt *Link) {
18 switch ctxt.Arch.Family {
24 func writeSEHAMD64(ctxt *Link) {
26 mkSecSym := func(name string, kind sym.SymKind) *loader.SymbolBuilder {
27 s := ldr.CreateSymForUpdate(name, 0)
32 pdata := mkSecSym(".pdata", sym.SPDATASECT)
33 // TODO: the following 12 bytes represent a dummy unwind info,
34 // remove once unwind infos are encoded in the .xdata section.
35 pdata.AddUint64(ctxt.Arch, 0)
36 pdata.AddUint32(ctxt.Arch, 0)
37 for _, s := range ctxt.Textp {
38 if fi := ldr.FuncInfo(s); !fi.Valid() || fi.TopFrame() {
41 uw := ldr.SEHUnwindSym(s)
47 // https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64#struct-runtime_function
48 pdata.AddPEImageRelativeAddrPlus(ctxt.Arch, s, 0)
49 pdata.AddPEImageRelativeAddrPlus(ctxt.Arch, s, ldr.SymSize(s))
50 // TODO: reference the .xdata symbol.
51 pdata.AddPEImageRelativeAddrPlus(ctxt.Arch, pdata.Sym(), 0)
53 sehp.pdata = pdata.Sym()