diff options
author | Cherry Mui <cherryyz@google.com> | 2024-05-14 21:40:51 -0400 |
---|---|---|
committer | Cherry Mui <cherryyz@google.com> | 2024-05-15 14:41:10 +0000 |
commit | 27603028eb48c19964722e09ee7e4b1c44b960cc (patch) | |
tree | c5a11d25f52c9f9b06726ef1ad7ae98de84d1621 /src | |
parent | 805654077252b0f34fb4323a519618ffad5a611e (diff) | |
download | go-27603028eb48c19964722e09ee7e4b1c44b960cc.tar.gz go-27603028eb48c19964722e09ee7e4b1c44b960cc.zip |
cmd/internal/obj/x86: make SEH symbols content-addressable
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/internal/obj/link.go | 4 | ||||
-rw-r--r-- | src/cmd/internal/obj/objfile.go | 6 | ||||
-rw-r--r-- | src/cmd/internal/obj/sym.go | 7 | ||||
-rw-r--r-- | src/cmd/internal/obj/x86/seh.go | 5 |
4 files changed, 18 insertions, 4 deletions
diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index dac6e209f1..3ebaa2aa5c 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -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 diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index 3da8c30640..648aae4fa2 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -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) } diff --git a/src/cmd/internal/obj/sym.go b/src/cmd/internal/obj/sym.go index f27d4ef4fc..22153050f2 100644 --- a/src/cmd/internal/obj/sym.go +++ b/src/cmd/internal/obj/sym.go @@ -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{} diff --git a/src/cmd/internal/obj/x86/seh.go b/src/cmd/internal/obj/x86/seh.go index 71cdd36642..11963e53f9 100644 --- a/src/cmd/internal/obj/x86/seh.go +++ b/src/cmd/internal/obj/x86/seh.go @@ -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) }) } |