]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/x86: make SEH symbols content-addressable
authorCherry Mui <cherryyz@google.com>
Wed, 15 May 2024 01:40:51 +0000 (21:40 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 15 May 2024 14:41:10 +0000 (14:41 +0000)
Currently, the SEH symbol is defined as an aux symbol of the
function symbol, without adding to ctxt.Data. Each function has
its own SEH symbol. As there are a lot of duplications of the
SEH symbol contents, currently a Go object file may contain many
copies of identical SEH symbols. They are deduplicated at link
time. But it does make the linker do redundant work, and make it
hard to reason about the SEH symbol writing in the object file
writer, and its resolution in the linker. In fact, in the object
file writer, the same SEH symbol may be added to the ctxt.defs
multiple times (as it is the aux of multiple function symbols),
which is not expected.

In fact, "aux symbol" is just a mechanism to associate auxiliary
data to another symbol. The auxiliary data symbol itself can be an
ordinary data symbol, even a content-addressable symbol. Define
the SEH symbol as a conntent-addressable symbol and add it to
ctxt.Data. This way there is only one definition of each unique
SEH symbol, which can be the aux of many functions.

While here, add a check to ensure that we add a symbol at most
once to the defs list.

Change-Id: Ie7a0cf02ca114060423e025931b30de97ca330fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/585656
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/internal/obj/link.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/sym.go
src/cmd/internal/obj/x86/seh.go

index dac6e209f192fb92909e8db58003a41dd5187b95..3ebaa2aa5ceabaf24744a80607964c0ff750fdd0 100644 (file)
@@ -1058,6 +1058,10 @@ type Link struct {
        // to Data.
        constSyms []*LSym
 
+       // Windows SEH symbols are also data symbols that can be created
+       // concurrently.
+       SEHSyms []*LSym
+
        // pkgIdx maps package path to index. The index is used for
        // symbol reference in the object file.
        pkgIdx map[string]int32
index 3da8c306405c9033471343f081e317df69e4cabe..648aae4fa20ff0a8a2557dfae86952b519fbf18d 100644 (file)
@@ -788,14 +788,18 @@ func genFuncInfoSyms(ctxt *Link) {
                fn.FuncInfoSym = isym
                b.Reset()
 
-               auxsyms := []*LSym{fn.dwarfRangesSym, fn.dwarfLocSym, fn.dwarfDebugLinesSym, fn.dwarfInfoSym, fn.WasmImportSym, fn.sehUnwindInfoSym}
+               auxsyms := []*LSym{fn.dwarfRangesSym, fn.dwarfLocSym, fn.dwarfDebugLinesSym, fn.dwarfInfoSym, fn.WasmImportSym}
                for _, s := range auxsyms {
                        if s == nil || s.Size == 0 {
                                continue
                        }
+                       if s.OnList() {
+                               panic("a symbol is added to defs multiple times")
+                       }
                        s.PkgIdx = goobj.PkgIdxSelf
                        s.SymIdx = symidx
                        s.Set(AttrIndexed, true)
+                       s.Set(AttrOnList, true)
                        symidx++
                        infosyms = append(infosyms, s)
                }
index f27d4ef4fcca5b20b11a40ffa47d4a0a7ea1aad1..22153050f26d99a5df71bbd5ae7ac67210e0a7ea 100644 (file)
@@ -245,6 +245,13 @@ func (ctxt *Link) NumberSyms() {
        ctxt.Data = append(ctxt.Data, ctxt.constSyms...)
        ctxt.constSyms = nil
 
+       // So are SEH symbols.
+       sort.Slice(ctxt.SEHSyms, func(i, j int) bool {
+               return ctxt.SEHSyms[i].Name < ctxt.SEHSyms[j].Name
+       })
+       ctxt.Data = append(ctxt.Data, ctxt.SEHSyms...)
+       ctxt.SEHSyms = nil
+
        ctxt.pkgIdx = make(map[string]int32)
        ctxt.defs = []*LSym{}
        ctxt.hashed64defs = []*LSym{}
index 71cdd3664202a1785d7a999d2d516a2b22dca144..11963e53f9f4c2ac8820242fe30d35b1dddc0d07 100644 (file)
@@ -151,6 +151,7 @@ func populateSeh(ctxt *obj.Link, s *obj.LSym) (sehsym *obj.LSym) {
                s.Type = objabi.SSEHUNWINDINFO
                s.Set(obj.AttrDuplicateOK, true)
                s.Set(obj.AttrLocal, true)
+               s.Set(obj.AttrContentAddressable, true)
                if exceptionHandler != nil {
                        r := obj.Addrel(s)
                        r.Off = int32(len(buf.data) - 4)
@@ -158,8 +159,6 @@ func populateSeh(ctxt *obj.Link, s *obj.LSym) (sehsym *obj.LSym) {
                        r.Sym = exceptionHandler
                        r.Type = objabi.R_PEIMAGEOFF
                }
-               // Note: AttrContentAddressable cannot be set here,
-               // because the content-addressable-handling code
-               // does not know about aux symbols.
+               ctxt.SEHSyms = append(ctxt.SEHSyms, s)
        })
 }