1
0
mirror of https://github.com/golang/go synced 2024-11-15 03:00:36 -07:00

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>
This commit is contained in:
Cherry Mui 2024-05-14 21:40:51 -04:00
parent 8056540772
commit 27603028eb
4 changed files with 18 additions and 4 deletions

View 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

View 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)
}

View 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{}

View 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)
})
}