Commit 4a9b30cf authored by Cherry Zhang's avatar Cherry Zhang

[dev.link] cmd/internal/goobj2: provide accessor methods for flags

Per Jeremy's comment in CL 199643. This makes the code read
better.

Change-Id: If270aecd712a27fb52e3faf5a4339200327d9ffe
Reviewed-on: https://go-review.googlesource.com/c/go/+/201023
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJeremy Faller <jeremy@golang.org>
parent 7256f500
......@@ -87,7 +87,7 @@ func (r *objReader) readNew() {
sym := Sym{
SymID: symID,
Kind: objabi.SymKind(osym.Type),
DupOK: osym.Flag&goobj2.SymFlagDupok != 0,
DupOK: osym.Dupok(),
Size: int64(osym.Siz),
Data: Data{int64(start + dataOff), siz},
}
......@@ -145,8 +145,8 @@ func (r *objReader) readNew() {
Args: int64(info.Args),
Frame: int64(info.Locals),
NoSplit: info.NoSplit != 0,
Leaf: osym.Flag&goobj2.SymFlagLeaf != 0,
TopFrame: osym.Flag&goobj2.SymFlagTopFrame != 0,
Leaf: osym.Leaf(),
TopFrame: osym.TopFrame(),
PCSP: Data{int64(pcdataBase + info.Pcsp), int64(info.Pcfile - info.Pcsp)},
PCFile: Data{int64(pcdataBase + info.Pcfile), int64(info.Pcline - info.Pcfile)},
PCLine: Data{int64(pcdataBase + info.Pcline), int64(info.Pcinline - info.Pcline)},
......
......@@ -220,6 +220,15 @@ func (s *Sym) Size() int {
return 4 + 2 + 1 + 1 + 4
}
func (s *Sym) Dupok() bool { return s.Flag&SymFlagDupok != 0 }
func (s *Sym) Local() bool { return s.Flag&SymFlagLocal != 0 }
func (s *Sym) Typelink() bool { return s.Flag&SymFlagTypelink != 0 }
func (s *Sym) Leaf() bool { return s.Flag&SymFlagLeaf != 0 }
func (s *Sym) CFunc() bool { return s.Flag&SymFlagCFunc != 0 }
func (s *Sym) ReflectMethod() bool { return s.Flag&SymFlagReflectMethod != 0 }
func (s *Sym) Shared() bool { return s.Flag&SymFlagShared != 0 }
func (s *Sym) TopFrame() bool { return s.Flag&SymFlagTopFrame != 0 }
// Symbol reference.
type SymRef struct {
PkgIdx uint32
......
......@@ -155,7 +155,7 @@ func (l *Loader) AddSym(name string, ver int, i Sym, r *oReader, dupok bool, typ
oldsym := goobj2.Sym{}
oldsym.Read(oldr.Reader, oldr.SymOff(li))
oldtyp := sym.AbiSymKindToSymKind[objabi.SymKind(oldsym.Type)]
if oldsym.Flag&goobj2.SymFlagDupok == 0 && !((oldtyp == sym.SDATA || oldtyp == sym.SNOPTRDATA || oldtyp == sym.SBSS || oldtyp == sym.SNOPTRBSS) && oldr.DataSize(li) == 0) { // only allow overwriting 0-sized data symbol
if !oldsym.Dupok() && !((oldtyp == sym.SDATA || oldtyp == sym.SNOPTRDATA || oldtyp == sym.SBSS || oldtyp == sym.SNOPTRBSS) && oldr.DataSize(li) == 0) { // only allow overwriting 0-sized data symbol
log.Fatalf("duplicated definition of symbol " + name)
}
l.overwrite[oldi] = i
......@@ -415,7 +415,7 @@ func LoadNew(l *Loader, arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *s
continue // don't add unnamed aux symbol
}
v := abiToVer(osym.ABI, localSymVersion)
dupok := osym.Flag&goobj2.SymFlagDupok != 0
dupok := osym.Dupok()
l.AddSym(name, v, istart+Sym(i), or, dupok, sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type)])
}
......@@ -566,7 +566,7 @@ func loadObjFull(l *Loader, r *oReader) {
continue
}
ver := abiToVer(osym.ABI, r.version)
dupok := osym.Flag&goobj2.SymFlagDupok != 0
dupok := osym.Dupok()
if dupsym := l.symsByName[nameVer{name, ver}]; dupsym != istart+Sym(i) {
if dupok && l.Reachable.Has(dupsym) {
// A dupok symbol is resolved to another package. We still need
......@@ -589,8 +589,8 @@ func loadObjFull(l *Loader, r *oReader) {
panic("name mismatch")
}
local := osym.Flag&goobj2.SymFlagLocal != 0
makeTypelink := osym.Flag&goobj2.SymFlagTypelink != 0
local := osym.Local()
makeTypelink := osym.Typelink()
size := osym.Siz
// Symbol data
......@@ -694,13 +694,13 @@ func loadObjFull(l *Loader, r *oReader) {
if info.NoSplit != 0 {
s.Attr |= sym.AttrNoSplit
}
if osym.Flag&goobj2.SymFlagReflectMethod != 0 {
if osym.ReflectMethod() {
s.Attr |= sym.AttrReflectMethod
}
if osym.Flag&goobj2.SymFlagShared != 0 {
if osym.Shared() {
s.Attr |= sym.AttrShared
}
if osym.Flag&goobj2.SymFlagTopFrame != 0 {
if osym.TopFrame() {
s.Attr |= sym.AttrTopFrame
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment