| | |
| | |
| | |
| |
|
| | package loader |
| |
|
| | import ( |
| | "bytes" |
| | "cmd/internal/bio" |
| | "cmd/internal/goobj" |
| | "cmd/internal/obj" |
| | "cmd/internal/objabi" |
| | "cmd/internal/sys" |
| | "cmd/link/internal/sym" |
| | "debug/elf" |
| | "fmt" |
| | "internal/abi" |
| | "io" |
| | "iter" |
| | "log" |
| | "math/bits" |
| | "os" |
| | "sort" |
| | "strings" |
| | ) |
| |
|
| | var _ = fmt.Print |
| |
|
| | |
| | |
| | type Sym = sym.LoaderSym |
| |
|
| | |
| | |
| | type Relocs struct { |
| | rs []goobj.Reloc |
| |
|
| | li uint32 |
| | r *oReader |
| | l *Loader |
| | } |
| |
|
| | |
| | type ExtReloc struct { |
| | Xsym Sym |
| | Xadd int64 |
| | Type objabi.RelocType |
| | Size uint8 |
| | } |
| |
|
| | |
| | |
| | type Reloc struct { |
| | *goobj.Reloc |
| | r *oReader |
| | l *Loader |
| | } |
| |
|
| | func (rel Reloc) Type() objabi.RelocType { return objabi.RelocType(rel.Reloc.Type()) &^ objabi.R_WEAK } |
| | func (rel Reloc) Weak() bool { return objabi.RelocType(rel.Reloc.Type())&objabi.R_WEAK != 0 } |
| | func (rel Reloc) SetType(t objabi.RelocType) { rel.Reloc.SetType(uint16(t)) } |
| | func (rel Reloc) Sym() Sym { return rel.l.resolve(rel.r, rel.Reloc.Sym()) } |
| | func (rel Reloc) SetSym(s Sym) { rel.Reloc.SetSym(goobj.SymRef{PkgIdx: 0, SymIdx: uint32(s)}) } |
| | func (rel Reloc) IsMarker() bool { return rel.Siz() == 0 } |
| |
|
| | |
| | |
| | type Aux struct { |
| | *goobj.Aux |
| | r *oReader |
| | l *Loader |
| | } |
| |
|
| | func (a Aux) Sym() Sym { return a.l.resolve(a.r, a.Aux.Sym()) } |
| |
|
| | |
| | |
| | type oReader struct { |
| | *goobj.Reader |
| | unit *sym.CompilationUnit |
| | version int |
| | pkgprefix string |
| | syms []Sym |
| | pkg []uint32 |
| | ndef int |
| | nhashed64def int |
| | nhasheddef int |
| | objidx uint32 |
| | } |
| |
|
| | |
| | |
| | func (r *oReader) NAlldef() int { return r.ndef + r.nhashed64def + r.nhasheddef + r.NNonpkgdef() } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | type objSym struct { |
| | objidx uint32 |
| | s uint32 |
| | } |
| |
|
| | type nameVer struct { |
| | name string |
| | v int |
| | } |
| |
|
| | type Bitmap []uint32 |
| |
|
| | |
| | func (bm Bitmap) Set(i Sym) { |
| | n, r := uint(i)/32, uint(i)%32 |
| | bm[n] |= 1 << r |
| | } |
| |
|
| | |
| | func (bm Bitmap) Unset(i Sym) { |
| | n, r := uint(i)/32, uint(i)%32 |
| | bm[n] &^= (1 << r) |
| | } |
| |
|
| | |
| | func (bm Bitmap) Has(i Sym) bool { |
| | n, r := uint(i)/32, uint(i)%32 |
| | return bm[n]&(1<<r) != 0 |
| | } |
| |
|
| | |
| | func (bm Bitmap) Len() int { |
| | return len(bm) * 32 |
| | } |
| |
|
| | |
| | func (bm Bitmap) Count() int { |
| | s := 0 |
| | for _, x := range bm { |
| | s += bits.OnesCount32(x) |
| | } |
| | return s |
| | } |
| |
|
| | func MakeBitmap(n int) Bitmap { |
| | return make(Bitmap, (n+31)/32) |
| | } |
| |
|
| | |
| | |
| | func growBitmap(reqLen int, b Bitmap) Bitmap { |
| | curLen := b.Len() |
| | if reqLen > curLen { |
| | b = append(b, MakeBitmap(reqLen+1-curLen)...) |
| | } |
| | return b |
| | } |
| |
|
| | type symAndSize struct { |
| | sym Sym |
| | size uint32 |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | type Loader struct { |
| | objs []*oReader |
| | extStart Sym |
| | builtinSyms []Sym |
| |
|
| | objSyms []objSym |
| |
|
| | symsByName [2]map[string]Sym |
| | extStaticSyms map[nameVer]Sym |
| |
|
| | extReader *oReader |
| | payloadBatch []extSymPayload |
| | payloads []*extSymPayload |
| | values []int64 |
| |
|
| | sects []*sym.Section |
| | symSects []uint16 |
| |
|
| | align []uint8 |
| |
|
| | deferReturnTramp map[Sym]bool |
| |
|
| | objByPkg map[string]uint32 |
| |
|
| | anonVersion int |
| |
|
| | |
| | |
| | |
| | |
| | |
| | attrReachable Bitmap |
| | attrOnList Bitmap |
| | attrLocal Bitmap |
| | attrNotInSymbolTable Bitmap |
| | attrUsedInIface Bitmap |
| | attrSpecial Bitmap |
| | attrVisibilityHidden Bitmap |
| | attrDuplicateOK Bitmap |
| | attrShared Bitmap |
| | attrExternal Bitmap |
| | generatedSyms Bitmap |
| |
|
| | attrReadOnly map[Sym]bool |
| | attrCgoExportDynamic map[Sym]struct{} |
| | attrCgoExportStatic map[Sym]struct{} |
| |
|
| | |
| | outer []Sym |
| | sub map[Sym]Sym |
| |
|
| | dynimplib map[Sym]string |
| | dynimpvers map[Sym]string |
| | localentry map[Sym]uint8 |
| | extname map[Sym]string |
| | elfType map[Sym]elf.SymType |
| | elfSym map[Sym]int32 |
| | localElfSym map[Sym]int32 |
| | symPkg map[Sym]string |
| | plt map[Sym]int32 |
| | got map[Sym]int32 |
| | dynid map[Sym]int32 |
| | weakBinding map[Sym]bool |
| |
|
| | relocVariant map[relocId]sym.RelocVariant |
| |
|
| | |
| | |
| | |
| | Reachparent []Sym |
| |
|
| | |
| | CgoExports map[string]Sym |
| |
|
| | WasmExports []Sym |
| |
|
| | |
| | |
| | |
| | |
| | sizeFixups []symAndSize |
| |
|
| | flags uint32 |
| |
|
| | strictDupMsgs int |
| |
|
| | errorReporter *ErrorReporter |
| |
|
| | npkgsyms int |
| | nhashedsyms int |
| | } |
| |
|
| | const ( |
| | pkgDef = iota |
| | hashed64Def |
| | hashedDef |
| | nonPkgDef |
| | nonPkgRef |
| | ) |
| |
|
| | |
| | const ( |
| | nilObj = iota |
| | extObj |
| | goObjStart |
| | ) |
| |
|
| | |
| | |
| | type extSymPayload struct { |
| | name string |
| | size int64 |
| | ver int |
| | kind sym.SymKind |
| | objidx uint32 |
| | relocs []goobj.Reloc |
| | data []byte |
| | auxs []goobj.Aux |
| | } |
| |
|
| | const ( |
| | |
| | FlagStrictDups = 1 << iota |
| | FlagCheckLinkname |
| | ) |
| |
|
| | func NewLoader(flags uint32, reporter *ErrorReporter) *Loader { |
| | nbuiltin := goobj.NBuiltin() |
| | extReader := &oReader{objidx: extObj} |
| | ldr := &Loader{ |
| | objs: []*oReader{nil, extReader}, |
| | objSyms: make([]objSym, 1, 1), |
| | extReader: extReader, |
| | symsByName: [2]map[string]Sym{make(map[string]Sym, 80000), make(map[string]Sym, 50000)}, |
| | objByPkg: make(map[string]uint32), |
| | sub: make(map[Sym]Sym), |
| | dynimplib: make(map[Sym]string), |
| | dynimpvers: make(map[Sym]string), |
| | localentry: make(map[Sym]uint8), |
| | extname: make(map[Sym]string), |
| | attrReadOnly: make(map[Sym]bool), |
| | elfType: make(map[Sym]elf.SymType), |
| | elfSym: make(map[Sym]int32), |
| | localElfSym: make(map[Sym]int32), |
| | symPkg: make(map[Sym]string), |
| | plt: make(map[Sym]int32), |
| | got: make(map[Sym]int32), |
| | dynid: make(map[Sym]int32), |
| | weakBinding: make(map[Sym]bool), |
| | attrCgoExportDynamic: make(map[Sym]struct{}), |
| | attrCgoExportStatic: make(map[Sym]struct{}), |
| | deferReturnTramp: make(map[Sym]bool), |
| | extStaticSyms: make(map[nameVer]Sym), |
| | builtinSyms: make([]Sym, nbuiltin), |
| | flags: flags, |
| | errorReporter: reporter, |
| | sects: []*sym.Section{nil}, |
| | } |
| | reporter.ldr = ldr |
| | return ldr |
| | } |
| |
|
| | |
| | func (l *Loader) addObj(pkg string, r *oReader) { |
| | pkg = objabi.PathToPrefix(pkg) |
| | if _, ok := l.objByPkg[pkg]; !ok { |
| | l.objByPkg[pkg] = r.objidx |
| | } |
| | l.objs = append(l.objs, r) |
| | } |
| |
|
| | |
| | |
| | func (st *loadState) addSym(name string, ver int, r *oReader, li uint32, kind int, osym *goobj.Sym) Sym { |
| | l := st.l |
| | if l.extStart != 0 { |
| | panic("addSym called after external symbol is created") |
| | } |
| | i := Sym(len(l.objSyms)) |
| | if int(i) != len(l.objSyms) { |
| | panic("too many symbols") |
| | } |
| | addToGlobal := func() { |
| | l.objSyms = append(l.objSyms, objSym{r.objidx, li}) |
| | } |
| | if name == "" && kind != hashed64Def && kind != hashedDef { |
| | addToGlobal() |
| | return i |
| | } |
| | if ver == r.version { |
| | |
| | |
| | |
| | addToGlobal() |
| | return i |
| | } |
| | switch kind { |
| | case pkgDef: |
| | |
| | |
| | |
| | |
| | |
| | l.symsByName[ver][name] = i |
| | addToGlobal() |
| | return i |
| | case hashed64Def, hashedDef: |
| | |
| | |
| | |
| | |
| | var checkHash func() (symAndSize, bool) |
| | var addToHashMap func(symAndSize) |
| | var h64 uint64 |
| | var h *goobj.HashType |
| | if kind == hashed64Def { |
| | checkHash = func() (symAndSize, bool) { |
| | h64 = r.Hash64(li - uint32(r.ndef)) |
| | s, existed := st.hashed64Syms[h64] |
| | return s, existed |
| | } |
| | addToHashMap = func(ss symAndSize) { st.hashed64Syms[h64] = ss } |
| | } else { |
| | checkHash = func() (symAndSize, bool) { |
| | h = r.Hash(li - uint32(r.ndef+r.nhashed64def)) |
| | s, existed := st.hashedSyms[*h] |
| | return s, existed |
| | } |
| | addToHashMap = func(ss symAndSize) { st.hashedSyms[*h] = ss } |
| | } |
| | siz := osym.Siz() |
| | if s, existed := checkHash(); existed { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | if siz > s.size { |
| | |
| | l.objSyms[s.sym] = objSym{r.objidx, li} |
| | addToHashMap(symAndSize{s.sym, siz}) |
| | } |
| | return s.sym |
| | } |
| | addToHashMap(symAndSize{i, siz}) |
| | addToGlobal() |
| | return i |
| | } |
| |
|
| | |
| | |
| | oldi, existed := l.symsByName[ver][name] |
| | if !existed { |
| | l.symsByName[ver][name] = i |
| | addToGlobal() |
| | return i |
| | } |
| | |
| | |
| | |
| | |
| | oldsz := l.SymSize(oldi) |
| | sz := int64(r.Sym(li).Siz()) |
| | if osym.Dupok() { |
| | if l.flags&FlagStrictDups != 0 { |
| | l.checkdup(name, r, li, oldi) |
| | } |
| | if oldsz < sz { |
| | |
| | l.objSyms[oldi] = objSym{r.objidx, li} |
| | } |
| | return oldi |
| | } |
| | oldr, oldli := l.toLocal(oldi) |
| | oldsym := oldr.Sym(oldli) |
| | if oldsym.Dupok() { |
| | return oldi |
| | } |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | oldtyp := sym.AbiSymKindToSymKind[objabi.SymKind(oldsym.Type())] |
| | newtyp := sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type())] |
| | newIsText := newtyp.IsText() |
| | oldHasContent := oldr.DataSize(oldli) != 0 |
| | newHasContent := r.DataSize(li) != 0 |
| | oldIsBSS := oldtyp.IsData() && !oldHasContent |
| | newIsBSS := newtyp.IsData() && !newHasContent |
| | switch { |
| | case newIsText && oldIsBSS, |
| | newHasContent && oldIsBSS, |
| | newIsBSS && oldIsBSS && sz > oldsz: |
| | |
| | l.objSyms[oldi] = objSym{r.objidx, li} |
| | if oldsz > sz { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | l.sizeFixups = append(l.sizeFixups, symAndSize{oldi, uint32(oldsz)}) |
| | } |
| | case newIsBSS: |
| | |
| | if sz > oldsz { |
| | |
| | l.sizeFixups = append(l.sizeFixups, symAndSize{oldi, uint32(sz)}) |
| | } |
| | default: |
| | log.Fatalf("duplicated definition of symbol %s, from %s (type %s size %d) and %s (type %s size %d)", name, r.unit.Lib.Pkg, newtyp, sz, oldr.unit.Lib.Pkg, oldtyp, oldsz) |
| | } |
| | return oldi |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) newExtSym(name string, ver int) Sym { |
| | i := Sym(len(l.objSyms)) |
| | if int(i) != len(l.objSyms) { |
| | panic("too many symbols") |
| | } |
| | if l.extStart == 0 { |
| | l.extStart = i |
| | } |
| | l.growValues(int(i) + 1) |
| | l.growOuter(int(i) + 1) |
| | l.growAttrBitmaps(int(i) + 1) |
| | pi := l.newPayload(name, ver) |
| | l.objSyms = append(l.objSyms, objSym{l.extReader.objidx, uint32(pi)}) |
| | l.extReader.syms = append(l.extReader.syms, i) |
| | return i |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) LookupOrCreateSym(name string, ver int) Sym { |
| | i := l.Lookup(name, ver) |
| | if i != 0 { |
| | return i |
| | } |
| | i = l.newExtSym(name, ver) |
| | static := ver >= sym.SymVerStatic || ver < 0 |
| | if static { |
| | l.extStaticSyms[nameVer{name, ver}] = i |
| | } else { |
| | l.symsByName[ver][name] = i |
| | } |
| | return i |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) AddCgoExport(s Sym) { |
| | if l.CgoExports == nil { |
| | l.CgoExports = make(map[string]Sym) |
| | } |
| | l.CgoExports[l.SymName(s)] = s |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func (l *Loader) LookupOrCreateCgoExport(name string, ver int) Sym { |
| | if ver >= sym.SymVerStatic { |
| | return l.LookupOrCreateSym(name, ver) |
| | } |
| | if ver != 0 { |
| | panic("ver must be 0 or a static version") |
| | } |
| | |
| | if s, ok := l.CgoExports[name]; ok { |
| | return s |
| | } |
| | |
| | |
| | return l.LookupOrCreateSym(name, 0) |
| | } |
| |
|
| | func (l *Loader) IsExternal(i Sym) bool { |
| | r, _ := l.toLocal(i) |
| | return l.isExtReader(r) |
| | } |
| |
|
| | func (l *Loader) isExtReader(r *oReader) bool { |
| | return r == l.extReader |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) extIndex(i Sym) Sym { |
| | _, li := l.toLocal(i) |
| | return Sym(li) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) newPayload(name string, ver int) int { |
| | pi := len(l.payloads) |
| | pp := l.allocPayload() |
| | pp.name = name |
| | pp.ver = ver |
| | l.payloads = append(l.payloads, pp) |
| | l.growExtAttrBitmaps() |
| | return pi |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) getPayload(i Sym) *extSymPayload { |
| | if !l.IsExternal(i) { |
| | panic(fmt.Sprintf("bogus symbol index %d in getPayload", i)) |
| | } |
| | pi := l.extIndex(i) |
| | return l.payloads[pi] |
| | } |
| |
|
| | |
| | func (l *Loader) allocPayload() *extSymPayload { |
| | batch := l.payloadBatch |
| | if len(batch) == 0 { |
| | batch = make([]extSymPayload, 1000) |
| | } |
| | p := &batch[0] |
| | l.payloadBatch = batch[1:] |
| | return p |
| | } |
| |
|
| | func (ms *extSymPayload) Grow(siz int64) { |
| | if int64(int(siz)) != siz { |
| | log.Fatalf("symgrow size %d too long", siz) |
| | } |
| | if int64(len(ms.data)) >= siz { |
| | return |
| | } |
| | if cap(ms.data) < int(siz) { |
| | cl := len(ms.data) |
| | ms.data = append(ms.data, make([]byte, int(siz)+1-cl)...) |
| | ms.data = ms.data[0:cl] |
| | } |
| | ms.data = ms.data[:siz] |
| | } |
| |
|
| | |
| | func (l *Loader) toGlobal(r *oReader, i uint32) Sym { |
| | return r.syms[i] |
| | } |
| |
|
| | |
| | func (l *Loader) toLocal(i Sym) (*oReader, uint32) { |
| | return l.objs[l.objSyms[i].objidx], l.objSyms[i].s |
| | } |
| |
|
| | |
| | func (l *Loader) resolve(r *oReader, s goobj.SymRef) Sym { |
| | var rr *oReader |
| | switch p := s.PkgIdx; p { |
| | case goobj.PkgIdxInvalid: |
| | |
| | |
| | |
| | if l.isExtReader(r) { |
| | return Sym(s.SymIdx) |
| | } |
| | if s.SymIdx != 0 { |
| | panic("bad sym ref") |
| | } |
| | return 0 |
| | case goobj.PkgIdxHashed64: |
| | i := int(s.SymIdx) + r.ndef |
| | return r.syms[i] |
| | case goobj.PkgIdxHashed: |
| | i := int(s.SymIdx) + r.ndef + r.nhashed64def |
| | return r.syms[i] |
| | case goobj.PkgIdxNone: |
| | i := int(s.SymIdx) + r.ndef + r.nhashed64def + r.nhasheddef |
| | return r.syms[i] |
| | case goobj.PkgIdxBuiltin: |
| | if bi := l.builtinSyms[s.SymIdx]; bi != 0 { |
| | return bi |
| | } |
| | l.reportMissingBuiltin(int(s.SymIdx), r.unit.Lib.Pkg) |
| | return 0 |
| | case goobj.PkgIdxSelf: |
| | rr = r |
| | default: |
| | rr = l.objs[r.pkg[p]] |
| | } |
| | return l.toGlobal(rr, s.SymIdx) |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) reportMissingBuiltin(bsym int, reflib string) { |
| | bname, _ := goobj.BuiltinName(bsym) |
| | log.Fatalf("reference to undefined builtin %q from package %q", |
| | bname, reflib) |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) Lookup(name string, ver int) Sym { |
| | if ver >= sym.SymVerStatic || ver < 0 { |
| | return l.extStaticSyms[nameVer{name, ver}] |
| | } |
| | return l.symsByName[ver][name] |
| | } |
| |
|
| | |
| | func (l *Loader) checkdup(name string, r *oReader, li uint32, dup Sym) { |
| | p := r.Data(li) |
| | rdup, ldup := l.toLocal(dup) |
| | pdup := rdup.Data(ldup) |
| | reason := "same length but different contents" |
| | if len(p) != len(pdup) { |
| | reason = fmt.Sprintf("new length %d != old length %d", len(p), len(pdup)) |
| | } else if bytes.Equal(p, pdup) { |
| | |
| | szdup := l.SymSize(dup) |
| | sz := int64(r.Sym(li).Siz()) |
| | if szdup == sz { |
| | return |
| | } |
| | reason = fmt.Sprintf("different sizes: new size %d != old size %d", |
| | sz, szdup) |
| | } |
| | fmt.Fprintf(os.Stderr, "cmd/link: while reading object for '%v': duplicate symbol '%s', previous def at '%v', with mismatched payload: %s\n", r.unit.Lib, name, rdup.unit.Lib, reason) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | allowed := strings.HasPrefix(name, "go:info.go.interface") || |
| | strings.HasPrefix(name, "go:info.go.builtin") || |
| | strings.HasPrefix(name, "go:debuglines") |
| | if !allowed { |
| | l.strictDupMsgs++ |
| | } |
| | } |
| |
|
| | func (l *Loader) NStrictDupMsgs() int { return l.strictDupMsgs } |
| |
|
| | |
| | func (l *Loader) NSym() int { |
| | return len(l.objSyms) |
| | } |
| |
|
| | |
| | func (l *Loader) NDef() int { |
| | return int(l.extStart) |
| | } |
| |
|
| | |
| | func (l *Loader) NReachableSym() int { |
| | return l.attrReachable.Count() |
| | } |
| |
|
| | |
| | func (l *Loader) SymName(i Sym) string { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | return pp.name |
| | } |
| | r, li := l.toLocal(i) |
| | if r == nil { |
| | return "?" |
| | } |
| | return r.Sym(li).Name(r.Reader) |
| | } |
| |
|
| | |
| | func (l *Loader) SymVersion(i Sym) int { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | return pp.ver |
| | } |
| | r, li := l.toLocal(i) |
| | return abiToVer(r.Sym(li).ABI(), r.version) |
| | } |
| |
|
| | func (l *Loader) IsFileLocal(i Sym) bool { |
| | return l.SymVersion(i) >= sym.SymVerStatic |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) IsFromAssembly(i Sym) bool { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | if pp.objidx != 0 { |
| | r := l.objs[pp.objidx] |
| | return r.FromAssembly() |
| | } |
| | return false |
| | } |
| | r, _ := l.toLocal(i) |
| | return r.FromAssembly() |
| | } |
| |
|
| | |
| | func (l *Loader) SymType(i Sym) sym.SymKind { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | if pp != nil { |
| | return pp.kind |
| | } |
| | return 0 |
| | } |
| | r, li := l.toLocal(i) |
| | return sym.AbiSymKindToSymKind[objabi.SymKind(r.Sym(li).Type())] |
| | } |
| |
|
| | |
| | func (l *Loader) SymAttr(i Sym) uint8 { |
| | if l.IsExternal(i) { |
| | |
| | |
| | |
| | return 0 |
| | } |
| | r, li := l.toLocal(i) |
| | return r.Sym(li).Flag() |
| | } |
| |
|
| | |
| | func (l *Loader) SymSize(i Sym) int64 { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | return pp.size |
| | } |
| | r, li := l.toLocal(i) |
| | return int64(r.Sym(li).Siz()) |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) AttrReachable(i Sym) bool { |
| | return l.attrReachable.Has(i) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrReachable(i Sym, v bool) { |
| | if v { |
| | l.attrReachable.Set(i) |
| | } else { |
| | l.attrReachable.Unset(i) |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func (l *Loader) AttrOnList(i Sym) bool { |
| | return l.attrOnList.Has(i) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrOnList(i Sym, v bool) { |
| | if v { |
| | l.attrOnList.Set(i) |
| | } else { |
| | l.attrOnList.Unset(i) |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) AttrLocal(i Sym) bool { |
| | return l.attrLocal.Has(i) |
| | } |
| |
|
| | |
| | func (l *Loader) SetAttrLocal(i Sym, v bool) { |
| | if v { |
| | l.attrLocal.Set(i) |
| | } else { |
| | l.attrLocal.Unset(i) |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) AttrUsedInIface(i Sym) bool { |
| | return l.attrUsedInIface.Has(i) |
| | } |
| |
|
| | func (l *Loader) SetAttrUsedInIface(i Sym, v bool) { |
| | if v { |
| | l.attrUsedInIface.Set(i) |
| | } else { |
| | l.attrUsedInIface.Unset(i) |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) SymAddr(i Sym) int64 { |
| | if !l.AttrReachable(i) { |
| | panic("unreachable symbol in symaddr") |
| | } |
| | return l.values[i] |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) AttrNotInSymbolTable(i Sym) bool { |
| | return l.attrNotInSymbolTable.Has(i) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrNotInSymbolTable(i Sym, v bool) { |
| | if v { |
| | l.attrNotInSymbolTable.Set(i) |
| | } else { |
| | l.attrNotInSymbolTable.Unset(i) |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func (l *Loader) AttrVisibilityHidden(i Sym) bool { |
| | if !l.IsExternal(i) { |
| | return false |
| | } |
| | return l.attrVisibilityHidden.Has(l.extIndex(i)) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrVisibilityHidden(i Sym, v bool) { |
| | if !l.IsExternal(i) { |
| | panic("tried to set visibility attr on non-external symbol") |
| | } |
| | if v { |
| | l.attrVisibilityHidden.Set(l.extIndex(i)) |
| | } else { |
| | l.attrVisibilityHidden.Unset(l.extIndex(i)) |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) AttrDuplicateOK(i Sym) bool { |
| | if !l.IsExternal(i) { |
| | |
| | |
| | |
| | r, li := l.toLocal(i) |
| | return r.Sym(li).Dupok() |
| | } |
| | return l.attrDuplicateOK.Has(l.extIndex(i)) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrDuplicateOK(i Sym, v bool) { |
| | if !l.IsExternal(i) { |
| | panic("tried to set dupok attr on non-external symbol") |
| | } |
| | if v { |
| | l.attrDuplicateOK.Set(l.extIndex(i)) |
| | } else { |
| | l.attrDuplicateOK.Unset(l.extIndex(i)) |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) AttrShared(i Sym) bool { |
| | if !l.IsExternal(i) { |
| | |
| | |
| | |
| | r, _ := l.toLocal(i) |
| | return r.Shared() |
| | } |
| | return l.attrShared.Has(l.extIndex(i)) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrShared(i Sym, v bool) { |
| | if !l.IsExternal(i) { |
| | panic(fmt.Sprintf("tried to set shared attr on non-external symbol %d %s", i, l.SymName(i))) |
| | } |
| | if v { |
| | l.attrShared.Set(l.extIndex(i)) |
| | } else { |
| | l.attrShared.Unset(l.extIndex(i)) |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) AttrExternal(i Sym) bool { |
| | if !l.IsExternal(i) { |
| | return false |
| | } |
| | return l.attrExternal.Has(l.extIndex(i)) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrExternal(i Sym, v bool) { |
| | if !l.IsExternal(i) { |
| | panic(fmt.Sprintf("tried to set external attr on non-external symbol %q", l.SymName(i))) |
| | } |
| | if v { |
| | l.attrExternal.Set(l.extIndex(i)) |
| | } else { |
| | l.attrExternal.Unset(l.extIndex(i)) |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) AttrSpecial(i Sym) bool { |
| | return l.attrSpecial.Has(i) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrSpecial(i Sym, v bool) { |
| | if v { |
| | l.attrSpecial.Set(i) |
| | } else { |
| | l.attrSpecial.Unset(i) |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) AttrCgoExportDynamic(i Sym) bool { |
| | _, ok := l.attrCgoExportDynamic[i] |
| | return ok |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrCgoExportDynamic(i Sym, v bool) { |
| | if v { |
| | l.attrCgoExportDynamic[i] = struct{}{} |
| | } else { |
| | delete(l.attrCgoExportDynamic, i) |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) ForAllCgoExportDynamic(f func(Sym)) { |
| | for s := range l.attrCgoExportDynamic { |
| | f(s) |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) AttrCgoExportStatic(i Sym) bool { |
| | _, ok := l.attrCgoExportStatic[i] |
| | return ok |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrCgoExportStatic(i Sym, v bool) { |
| | if v { |
| | l.attrCgoExportStatic[i] = struct{}{} |
| | } else { |
| | delete(l.attrCgoExportStatic, i) |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) ForAllCgoExportStatic() iter.Seq[Sym] { |
| | return func(yield func(Sym) bool) { |
| | for s := range l.attrCgoExportStatic { |
| | if !yield(s) { |
| | break |
| | } |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) IsGeneratedSym(i Sym) bool { |
| | if !l.IsExternal(i) { |
| | return false |
| | } |
| | return l.generatedSyms.Has(l.extIndex(i)) |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) SetIsGeneratedSym(i Sym, v bool) { |
| | if !l.IsExternal(i) { |
| | panic("only external symbols can be generated") |
| | } |
| | if v { |
| | l.generatedSyms.Set(l.extIndex(i)) |
| | } else { |
| | l.generatedSyms.Unset(l.extIndex(i)) |
| | } |
| | } |
| |
|
| | func (l *Loader) AttrCgoExport(i Sym) bool { |
| | return l.AttrCgoExportDynamic(i) || l.AttrCgoExportStatic(i) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) AttrReadOnly(i Sym) bool { |
| | if v, ok := l.attrReadOnly[i]; ok { |
| | return v |
| | } |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | if pp.objidx != 0 { |
| | return l.objs[pp.objidx].ReadOnly() |
| | } |
| | return false |
| | } |
| | r, _ := l.toLocal(i) |
| | return r.ReadOnly() |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetAttrReadOnly(i Sym, v bool) { |
| | l.attrReadOnly[i] = v |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | func (l *Loader) AttrSubSymbol(i Sym) bool { |
| | |
| | |
| | o := l.OuterSym(i) |
| | if o == 0 { |
| | return false |
| | } |
| | return l.SubSym(o) != 0 |
| | } |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | func (l *Loader) IsReflectMethod(i Sym) bool { |
| | return l.SymAttr(i)&goobj.SymFlagReflectMethod != 0 |
| | } |
| |
|
| | |
| | func (l *Loader) IsNoSplit(i Sym) bool { |
| | return l.SymAttr(i)&goobj.SymFlagNoSplit != 0 |
| | } |
| |
|
| | |
| | func (l *Loader) IsGoType(i Sym) bool { |
| | return l.SymAttr(i)&goobj.SymFlagGoType != 0 |
| | } |
| |
|
| | |
| | func (l *Loader) IsTypelink(i Sym) bool { |
| | return l.SymAttr(i)&goobj.SymFlagTypelink != 0 |
| | } |
| |
|
| | |
| | func (l *Loader) IsItab(i Sym) bool { |
| | if l.IsExternal(i) { |
| | return false |
| | } |
| | r, li := l.toLocal(i) |
| | return r.Sym(li).IsItab() |
| | } |
| |
|
| | |
| | func (l *Loader) IsDict(i Sym) bool { |
| | if l.IsExternal(i) { |
| | return false |
| | } |
| | r, li := l.toLocal(i) |
| | return r.Sym(li).IsDict() |
| | } |
| |
|
| | |
| | func (l *Loader) IsPkgInit(i Sym) bool { |
| | if l.IsExternal(i) { |
| | return false |
| | } |
| | r, li := l.toLocal(i) |
| | return r.Sym(li).IsPkgInit() |
| | } |
| |
|
| | |
| | func (l *Loader) IsDeferReturnTramp(i Sym) bool { |
| | return l.deferReturnTramp[i] |
| | } |
| |
|
| | |
| | func (l *Loader) SetIsDeferReturnTramp(i Sym, v bool) { |
| | l.deferReturnTramp[i] = v |
| | } |
| |
|
| | |
| | func (l *Loader) growValues(reqLen int) { |
| | curLen := len(l.values) |
| | if reqLen > curLen { |
| | l.values = append(l.values, make([]int64, reqLen+1-curLen)...) |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) SymValue(i Sym) int64 { |
| | return l.values[i] |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymValue(i Sym, val int64) { |
| | l.values[i] = val |
| | } |
| |
|
| | |
| | func (l *Loader) AddToSymValue(i Sym, val int64) { |
| | l.values[i] += val |
| | } |
| |
|
| | |
| | func (l *Loader) Data(i Sym) []byte { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | if pp != nil { |
| | return pp.data |
| | } |
| | return nil |
| | } |
| | r, li := l.toLocal(i) |
| | return r.Data(li) |
| | } |
| |
|
| | |
| | func (l *Loader) DataString(i Sym) string { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | return string(pp.data) |
| | } |
| | r, li := l.toLocal(i) |
| | return r.DataString(li) |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) FreeData(i Sym) { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | if pp != nil { |
| | pp.data = nil |
| | } |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) SymAlign(i Sym) int32 { |
| | if int(i) >= len(l.align) { |
| | |
| | |
| | |
| | return 0 |
| | } |
| | |
| | |
| | |
| | abits := l.align[i] |
| | if abits == 0 { |
| | return 0 |
| | } |
| | return int32(1 << (abits - 1)) |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymAlign(i Sym, align int32) { |
| | |
| | if align < 0 || align&(align-1) != 0 { |
| | panic("bad alignment value") |
| | } |
| | if int(i) >= len(l.align) { |
| | l.align = append(l.align, make([]uint8, l.NSym()-len(l.align))...) |
| | } |
| | l.align[i] = uint8(bits.Len32(uint32(align))) |
| | } |
| |
|
| | |
| | func (l *Loader) SymSect(i Sym) *sym.Section { |
| | if int(i) >= len(l.symSects) { |
| | |
| | |
| | |
| | return nil |
| | } |
| | return l.sects[l.symSects[i]] |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymSect(i Sym, sect *sym.Section) { |
| | if int(i) >= len(l.symSects) { |
| | l.symSects = append(l.symSects, make([]uint16, l.NSym()-len(l.symSects))...) |
| | } |
| | l.symSects[i] = sect.Index |
| | } |
| |
|
| | |
| | func (l *Loader) NewSection() *sym.Section { |
| | sect := new(sym.Section) |
| | idx := len(l.sects) |
| | if idx != int(uint16(idx)) { |
| | panic("too many sections created") |
| | } |
| | sect.Index = uint16(idx) |
| | l.sects = append(l.sects, sect) |
| | return sect |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) SymDynimplib(i Sym) string { |
| | return l.dynimplib[i] |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymDynimplib(i Sym, value string) { |
| | |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol index in SetDynimplib") |
| | } |
| | if value == "" { |
| | delete(l.dynimplib, i) |
| | } else { |
| | l.dynimplib[i] = value |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) SymDynimpvers(i Sym) string { |
| | return l.dynimpvers[i] |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymDynimpvers(i Sym, value string) { |
| | |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol index in SetDynimpvers") |
| | } |
| | if value == "" { |
| | delete(l.dynimpvers, i) |
| | } else { |
| | l.dynimpvers[i] = value |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SymExtname(i Sym) string { |
| | if s, ok := l.extname[i]; ok { |
| | return s |
| | } |
| | return l.SymName(i) |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymExtname(i Sym, value string) { |
| | |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol index in SetExtname") |
| | } |
| | if value == "" { |
| | delete(l.extname, i) |
| | } else { |
| | l.extname[i] = value |
| | } |
| | } |
| |
|
| | func (l *Loader) SymWeakBinding(i Sym) bool { |
| | return l.weakBinding[i] |
| | } |
| |
|
| | func (l *Loader) SetSymWeakBinding(i Sym, v bool) { |
| | |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol index in SetSymWeakBinding") |
| | } |
| | l.weakBinding[i] = v |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func (l *Loader) SymElfType(i Sym) elf.SymType { |
| | if et, ok := l.elfType[i]; ok { |
| | return et |
| | } |
| | return elf.STT_NOTYPE |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymElfType(i Sym, et elf.SymType) { |
| | |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol index in SetSymElfType") |
| | } |
| | if et == elf.STT_NOTYPE { |
| | delete(l.elfType, i) |
| | } else { |
| | l.elfType[i] = et |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SymElfSym(i Sym) int32 { |
| | return l.elfSym[i] |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymElfSym(i Sym, es int32) { |
| | if i == 0 { |
| | panic("bad sym index") |
| | } |
| | if es == 0 { |
| | delete(l.elfSym, i) |
| | } else { |
| | l.elfSym[i] = es |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SymLocalElfSym(i Sym) int32 { |
| | return l.localElfSym[i] |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymLocalElfSym(i Sym, es int32) { |
| | if i == 0 { |
| | panic("bad sym index") |
| | } |
| | if es == 0 { |
| | delete(l.localElfSym, i) |
| | } else { |
| | l.localElfSym[i] = es |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) SymPlt(s Sym) int32 { |
| | if v, ok := l.plt[s]; ok { |
| | return v |
| | } |
| | return -1 |
| | } |
| |
|
| | |
| | func (l *Loader) SetPlt(i Sym, v int32) { |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol for SetPlt") |
| | } |
| | if v == -1 { |
| | delete(l.plt, i) |
| | } else { |
| | l.plt[i] = v |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) SymGot(s Sym) int32 { |
| | if v, ok := l.got[s]; ok { |
| | return v |
| | } |
| | return -1 |
| | } |
| |
|
| | |
| | func (l *Loader) SetGot(i Sym, v int32) { |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol for SetGot") |
| | } |
| | if v == -1 { |
| | delete(l.got, i) |
| | } else { |
| | l.got[i] = v |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) SymDynid(i Sym) int32 { |
| | if s, ok := l.dynid[i]; ok { |
| | return s |
| | } |
| | return -1 |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymDynid(i Sym, val int32) { |
| | |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol index in SetSymDynid") |
| | } |
| | if val == -1 { |
| | delete(l.dynid, i) |
| | } else { |
| | l.dynid[i] = val |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) DynidSyms() []Sym { |
| | sl := make([]Sym, 0, len(l.dynid)) |
| | for s := range l.dynid { |
| | sl = append(sl, s) |
| | } |
| | sort.Slice(sl, func(i, j int) bool { return sl[i] < sl[j] }) |
| | return sl |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) SymGoType(i Sym) Sym { return l.aux1(i, goobj.AuxGotype) } |
| |
|
| | |
| | |
| | func (l *Loader) SymUnit(i Sym) *sym.CompilationUnit { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | if pp.objidx != 0 { |
| | r := l.objs[pp.objidx] |
| | return r.unit |
| | } |
| | return nil |
| | } |
| | r, _ := l.toLocal(i) |
| | return r.unit |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) SymPkg(i Sym) string { |
| | if f, ok := l.symPkg[i]; ok { |
| | return f |
| | } |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | if pp.objidx != 0 { |
| | r := l.objs[pp.objidx] |
| | return r.unit.Lib.Pkg |
| | } |
| | return "" |
| | } |
| | r, _ := l.toLocal(i) |
| | return r.unit.Lib.Pkg |
| | } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) SetSymPkg(i Sym, pkg string) { |
| | |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol index in SetSymPkg") |
| | } |
| | l.symPkg[i] = pkg |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func (l *Loader) SymLocalentry(i Sym) uint8 { |
| | return l.localentry[i] |
| | } |
| |
|
| | |
| | func (l *Loader) SetSymLocalentry(i Sym, value uint8) { |
| | |
| | if i >= Sym(len(l.objSyms)) || i == 0 { |
| | panic("bad symbol index in SetSymLocalentry") |
| | } |
| | if value == 0 { |
| | delete(l.localentry, i) |
| | } else { |
| | l.localentry[i] = value |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) NAux(i Sym) int { |
| | if l.IsExternal(i) { |
| | return 0 |
| | } |
| | r, li := l.toLocal(i) |
| | return r.NAux(li) |
| | } |
| |
|
| | |
| | func (l *Loader) Aux(i Sym, j int) Aux { |
| | if l.IsExternal(i) { |
| | return Aux{} |
| | } |
| | r, li := l.toLocal(i) |
| | if j >= r.NAux(li) { |
| | return Aux{} |
| | } |
| | return Aux{r.Aux(li, j), r, l} |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) WasmImportSym(fnSymIdx Sym) Sym { |
| | if !l.SymType(fnSymIdx).IsText() { |
| | log.Fatalf("error: non-function sym %d/%s t=%s passed to WasmImportSym", fnSymIdx, l.SymName(fnSymIdx), l.SymType(fnSymIdx).String()) |
| | } |
| | return l.aux1(fnSymIdx, goobj.AuxWasmImport) |
| | } |
| |
|
| | func (l *Loader) WasmTypeSym(s Sym) Sym { |
| | return l.aux1(s, goobj.AuxWasmType) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SEHUnwindSym(fnSymIdx Sym) Sym { |
| | if !l.SymType(fnSymIdx).IsText() { |
| | log.Fatalf("error: non-function sym %d/%s t=%s passed to SEHUnwindSym", fnSymIdx, l.SymName(fnSymIdx), l.SymType(fnSymIdx).String()) |
| | } |
| |
|
| | return l.aux1(fnSymIdx, goobj.AuxSehUnwindInfo) |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) GetFuncDwarfAuxSyms(fnSymIdx Sym) (auxDwarfInfo, auxDwarfLoc, auxDwarfRanges, auxDwarfLines Sym) { |
| | if !l.SymType(fnSymIdx).IsText() { |
| | log.Fatalf("error: non-function sym %d/%s t=%s passed to GetFuncDwarfAuxSyms", fnSymIdx, l.SymName(fnSymIdx), l.SymType(fnSymIdx).String()) |
| | } |
| | r, auxs := l.auxs(fnSymIdx) |
| |
|
| | for i := range auxs { |
| | a := &auxs[i] |
| | switch a.Type() { |
| | case goobj.AuxDwarfInfo: |
| | auxDwarfInfo = l.resolve(r, a.Sym()) |
| | if l.SymType(auxDwarfInfo) != sym.SDWARFFCN { |
| | panic("aux dwarf info sym with wrong type") |
| | } |
| | case goobj.AuxDwarfLoc: |
| | auxDwarfLoc = l.resolve(r, a.Sym()) |
| | if l.SymType(auxDwarfLoc) != sym.SDWARFLOC { |
| | panic("aux dwarf loc sym with wrong type") |
| | } |
| | case goobj.AuxDwarfRanges: |
| | auxDwarfRanges = l.resolve(r, a.Sym()) |
| | if l.SymType(auxDwarfRanges) != sym.SDWARFRANGE { |
| | panic("aux dwarf ranges sym with wrong type") |
| | } |
| | case goobj.AuxDwarfLines: |
| | auxDwarfLines = l.resolve(r, a.Sym()) |
| | if l.SymType(auxDwarfLines) != sym.SDWARFLINES { |
| | panic("aux dwarf lines sym with wrong type") |
| | } |
| | } |
| | } |
| | return |
| | } |
| |
|
| | func (l *Loader) GetVarDwarfAuxSym(i Sym) Sym { |
| | aux := l.aux1(i, goobj.AuxDwarfInfo) |
| | if aux != 0 && l.SymType(aux) != sym.SDWARFVAR { |
| | fmt.Println(l.SymName(i), l.SymType(i), l.SymType(aux), sym.SDWARFVAR) |
| | panic("aux dwarf info sym with wrong type") |
| | } |
| | return aux |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) AddInteriorSym(container Sym, interior Sym) { |
| | |
| | |
| | if len(l.Data(interior)) != 0 { |
| | panic("unexpected non-empty interior symbol") |
| | } |
| | |
| | if l.AttrNotInSymbolTable(interior) { |
| | panic("interior symbol must be in symtab") |
| | } |
| | |
| | if l.OuterSym(container) != 0 { |
| | panic("outer has outer itself") |
| | } |
| | |
| | if l.SubSym(interior) != 0 { |
| | panic("sub set for subsym") |
| | } |
| | |
| | if l.OuterSym(interior) != 0 { |
| | panic("outer already set for subsym") |
| | } |
| | l.sub[interior] = l.sub[container] |
| | l.sub[container] = interior |
| | l.outer[interior] = container |
| | } |
| |
|
| | |
| | func (l *Loader) OuterSym(i Sym) Sym { |
| | return l.outer[i] |
| | } |
| |
|
| | |
| | func (l *Loader) SubSym(i Sym) Sym { |
| | return l.sub[i] |
| | } |
| |
|
| | |
| | func (l *Loader) growOuter(reqLen int) { |
| | curLen := len(l.outer) |
| | if reqLen > curLen { |
| | l.outer = append(l.outer, make([]Sym, reqLen-curLen)...) |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) SetCarrierSym(s Sym, c Sym) { |
| | if c == 0 { |
| | panic("invalid carrier in SetCarrierSym") |
| | } |
| | if s == 0 { |
| | panic("invalid sub-symbol in SetCarrierSym") |
| | } |
| | |
| | |
| | |
| | if len(l.Data(c)) != 0 { |
| | panic("unexpected non-empty carrier symbol") |
| | } |
| | l.outer[s] = c |
| | |
| | |
| | if l.outer[c] != 0 { |
| | panic("invalid nested carrier sym") |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) InitReachable() { |
| | l.growAttrBitmaps(l.NSym() + 1) |
| | } |
| |
|
| | type symWithVal struct { |
| | s Sym |
| | v int64 |
| | } |
| | type bySymValue []symWithVal |
| |
|
| | func (s bySymValue) Len() int { return len(s) } |
| | func (s bySymValue) Swap(i, j int) { s[i], s[j] = s[j], s[i] } |
| | func (s bySymValue) Less(i, j int) bool { return s[i].v < s[j].v } |
| |
|
| | |
| | |
| | |
| | func (l *Loader) SortSub(s Sym) Sym { |
| |
|
| | if s == 0 || l.sub[s] == 0 { |
| | return s |
| | } |
| |
|
| | |
| | |
| | |
| | sl := []symWithVal{} |
| | for ss := l.sub[s]; ss != 0; ss = l.sub[ss] { |
| | sl = append(sl, symWithVal{s: ss, v: l.SymValue(ss)}) |
| | } |
| | sort.Stable(bySymValue(sl)) |
| |
|
| | |
| | ns := Sym(0) |
| | for i := len(sl) - 1; i >= 0; i-- { |
| | s := sl[i].s |
| | l.sub[s] = ns |
| | ns = s |
| | } |
| |
|
| | |
| | l.sub[s] = sl[0].s |
| | return sl[0].s |
| | } |
| |
|
| | |
| | func (l *Loader) SortSyms(ss []Sym) { |
| | sort.SliceStable(ss, func(i, j int) bool { return l.SymValue(ss[i]) < l.SymValue(ss[j]) }) |
| | } |
| |
|
| | |
| | func (l *Loader) growAttrBitmaps(reqLen int) { |
| | if reqLen > l.attrReachable.Len() { |
| | |
| | l.attrReachable = growBitmap(reqLen, l.attrReachable) |
| | l.attrOnList = growBitmap(reqLen, l.attrOnList) |
| | l.attrLocal = growBitmap(reqLen, l.attrLocal) |
| | l.attrNotInSymbolTable = growBitmap(reqLen, l.attrNotInSymbolTable) |
| | l.attrUsedInIface = growBitmap(reqLen, l.attrUsedInIface) |
| | l.attrSpecial = growBitmap(reqLen, l.attrSpecial) |
| | } |
| | l.growExtAttrBitmaps() |
| | } |
| |
|
| | func (l *Loader) growExtAttrBitmaps() { |
| | |
| | extReqLen := len(l.payloads) |
| | if extReqLen > l.attrVisibilityHidden.Len() { |
| | l.attrVisibilityHidden = growBitmap(extReqLen, l.attrVisibilityHidden) |
| | l.attrDuplicateOK = growBitmap(extReqLen, l.attrDuplicateOK) |
| | l.attrShared = growBitmap(extReqLen, l.attrShared) |
| | l.attrExternal = growBitmap(extReqLen, l.attrExternal) |
| | l.generatedSyms = growBitmap(extReqLen, l.generatedSyms) |
| | } |
| | } |
| |
|
| | func (relocs *Relocs) Count() int { return len(relocs.rs) } |
| |
|
| | |
| | func (relocs *Relocs) At(j int) Reloc { |
| | if relocs.l.isExtReader(relocs.r) { |
| | return Reloc{&relocs.rs[j], relocs.r, relocs.l} |
| | } |
| | return Reloc{&relocs.rs[j], relocs.r, relocs.l} |
| | } |
| |
|
| | |
| | func (l *Loader) Relocs(i Sym) Relocs { |
| | r, li := l.toLocal(i) |
| | if r == nil { |
| | panic(fmt.Sprintf("trying to get oreader for invalid sym %d\n\n", i)) |
| | } |
| | return l.relocs(r, li) |
| | } |
| |
|
| | |
| | func (l *Loader) relocs(r *oReader, li uint32) Relocs { |
| | var rs []goobj.Reloc |
| | if l.isExtReader(r) { |
| | pp := l.payloads[li] |
| | rs = pp.relocs |
| | } else { |
| | rs = r.Relocs(li) |
| | } |
| | return Relocs{ |
| | rs: rs, |
| | li: li, |
| | r: r, |
| | l: l, |
| | } |
| | } |
| |
|
| | func (l *Loader) auxs(i Sym) (*oReader, []goobj.Aux) { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | return l.objs[pp.objidx], pp.auxs |
| | } else { |
| | r, li := l.toLocal(i) |
| | return r, r.Auxs(li) |
| | } |
| | } |
| |
|
| | |
| | func (l *Loader) aux1(i Sym, t uint8) Sym { |
| | r, auxs := l.auxs(i) |
| | for j := range auxs { |
| | a := &auxs[j] |
| | if a.Type() == t { |
| | return l.resolve(r, a.Sym()) |
| | } |
| | } |
| | return 0 |
| | } |
| |
|
| | func (l *Loader) Pcsp(i Sym) Sym { return l.aux1(i, goobj.AuxPcsp) } |
| |
|
| | |
| | |
| | func (l *Loader) PcdataAuxs(i Sym, tmp []Sym) (pcsp, pcfile, pcline, pcinline Sym, pcdata []Sym) { |
| | pcdata = tmp[:0] |
| | r, auxs := l.auxs(i) |
| | for j := range auxs { |
| | a := &auxs[j] |
| | switch a.Type() { |
| | case goobj.AuxPcsp: |
| | pcsp = l.resolve(r, a.Sym()) |
| | case goobj.AuxPcline: |
| | pcline = l.resolve(r, a.Sym()) |
| | case goobj.AuxPcfile: |
| | pcfile = l.resolve(r, a.Sym()) |
| | case goobj.AuxPcinline: |
| | pcinline = l.resolve(r, a.Sym()) |
| | case goobj.AuxPcdata: |
| | pcdata = append(pcdata, l.resolve(r, a.Sym())) |
| | } |
| | } |
| | return |
| | } |
| |
|
| | |
| | func (l *Loader) NumPcdata(i Sym) int { |
| | n := 0 |
| | _, auxs := l.auxs(i) |
| | for j := range auxs { |
| | a := &auxs[j] |
| | if a.Type() == goobj.AuxPcdata { |
| | n++ |
| | } |
| | } |
| | return n |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) Funcdata(i Sym, tmp []Sym) []Sym { |
| | fd := tmp[:0] |
| | r, auxs := l.auxs(i) |
| | for j := range auxs { |
| | a := &auxs[j] |
| | if a.Type() == goobj.AuxFuncdata { |
| | fd = append(fd, l.resolve(r, a.Sym())) |
| | } |
| | } |
| | return fd |
| | } |
| |
|
| | |
| | func (l *Loader) NumFuncdata(i Sym) int { |
| | n := 0 |
| | _, auxs := l.auxs(i) |
| | for j := range auxs { |
| | a := &auxs[j] |
| | if a.Type() == goobj.AuxFuncdata { |
| | n++ |
| | } |
| | } |
| | return n |
| | } |
| |
|
| | |
| | type FuncInfo struct { |
| | l *Loader |
| | r *oReader |
| | data []byte |
| | lengths goobj.FuncInfoLengths |
| | } |
| |
|
| | func (fi *FuncInfo) Valid() bool { return fi.r != nil } |
| |
|
| | func (fi *FuncInfo) Args() int { |
| | return int((*goobj.FuncInfo)(nil).ReadArgs(fi.data)) |
| | } |
| |
|
| | func (fi *FuncInfo) Locals() int { |
| | return int((*goobj.FuncInfo)(nil).ReadLocals(fi.data)) |
| | } |
| |
|
| | func (fi *FuncInfo) FuncID() abi.FuncID { |
| | return (*goobj.FuncInfo)(nil).ReadFuncID(fi.data) |
| | } |
| |
|
| | func (fi *FuncInfo) FuncFlag() abi.FuncFlag { |
| | return (*goobj.FuncInfo)(nil).ReadFuncFlag(fi.data) |
| | } |
| |
|
| | func (fi *FuncInfo) StartLine() int32 { |
| | return (*goobj.FuncInfo)(nil).ReadStartLine(fi.data) |
| | } |
| |
|
| | |
| | |
| | func (fi *FuncInfo) Preload() { |
| | fi.lengths = (*goobj.FuncInfo)(nil).ReadFuncInfoLengths(fi.data) |
| | } |
| |
|
| | func (fi *FuncInfo) NumFile() uint32 { |
| | if !fi.lengths.Initialized { |
| | panic("need to call Preload first") |
| | } |
| | return fi.lengths.NumFile |
| | } |
| |
|
| | func (fi *FuncInfo) File(k int) goobj.CUFileIndex { |
| | if !fi.lengths.Initialized { |
| | panic("need to call Preload first") |
| | } |
| | return (*goobj.FuncInfo)(nil).ReadFile(fi.data, fi.lengths.FileOff, uint32(k)) |
| | } |
| |
|
| | |
| | |
| | |
| | func (fi *FuncInfo) TopFrame() bool { |
| | return (fi.FuncFlag() & abi.FuncFlagTopFrame) != 0 |
| | } |
| |
|
| | type InlTreeNode struct { |
| | Parent int32 |
| | File goobj.CUFileIndex |
| | Line int32 |
| | Func Sym |
| | ParentPC int32 |
| | } |
| |
|
| | func (fi *FuncInfo) NumInlTree() uint32 { |
| | if !fi.lengths.Initialized { |
| | panic("need to call Preload first") |
| | } |
| | return fi.lengths.NumInlTree |
| | } |
| |
|
| | func (fi *FuncInfo) InlTree(k int) InlTreeNode { |
| | if !fi.lengths.Initialized { |
| | panic("need to call Preload first") |
| | } |
| | node := (*goobj.FuncInfo)(nil).ReadInlTree(fi.data, fi.lengths.InlTreeOff, uint32(k)) |
| | return InlTreeNode{ |
| | Parent: node.Parent, |
| | File: node.File, |
| | Line: node.Line, |
| | Func: fi.l.resolve(fi.r, node.Func), |
| | ParentPC: node.ParentPC, |
| | } |
| | } |
| |
|
| | func (l *Loader) FuncInfo(i Sym) FuncInfo { |
| | r, auxs := l.auxs(i) |
| | for j := range auxs { |
| | a := &auxs[j] |
| | if a.Type() == goobj.AuxFuncInfo { |
| | b := r.Data(a.Sym().SymIdx) |
| | return FuncInfo{l, r, b, goobj.FuncInfoLengths{}} |
| | } |
| | } |
| | return FuncInfo{} |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) Preload(localSymVersion int, f *bio.Reader, lib *sym.Library, unit *sym.CompilationUnit, length int64) goobj.FingerprintType { |
| | roObject, readonly, err := f.Slice(uint64(length)) |
| | if err != nil { |
| | log.Fatal("cannot read object file:", err) |
| | } |
| | r := goobj.NewReaderFromBytes(roObject, readonly) |
| | if r == nil { |
| | if len(roObject) >= 8 && bytes.Equal(roObject[:8], []byte("\x00go114ld")) { |
| | log.Fatalf("found object file %s in old format", f.File().Name()) |
| | } |
| | panic("cannot read object file") |
| | } |
| | pkgprefix := objabi.PathToPrefix(lib.Pkg) + "." |
| | ndef := r.NSym() |
| | nhashed64def := r.NHashed64def() |
| | nhasheddef := r.NHasheddef() |
| | or := &oReader{ |
| | Reader: r, |
| | unit: unit, |
| | version: localSymVersion, |
| | pkgprefix: pkgprefix, |
| | syms: make([]Sym, ndef+nhashed64def+nhasheddef+r.NNonpkgdef()+r.NNonpkgref()), |
| | ndef: ndef, |
| | nhasheddef: nhasheddef, |
| | nhashed64def: nhashed64def, |
| | objidx: uint32(len(l.objs)), |
| | } |
| |
|
| | if r.Unlinkable() { |
| | log.Fatalf("link: unlinkable object (from package %s) - compiler requires -p flag", lib.Pkg) |
| | } |
| |
|
| | |
| | lib.Autolib = append(lib.Autolib, r.Autolib()...) |
| |
|
| | |
| | nfile := r.NFile() |
| | unit.FileTable = make([]string, nfile) |
| | for i := range unit.FileTable { |
| | unit.FileTable[i] = r.File(i) |
| | } |
| |
|
| | l.addObj(lib.Pkg, or) |
| |
|
| | |
| | f.MustSeek(length, io.SeekCurrent) |
| |
|
| | return r.Fingerprint() |
| | } |
| |
|
| | |
| | type loadState struct { |
| | l *Loader |
| | hashed64Syms map[uint64]symAndSize |
| | hashedSyms map[goobj.HashType]symAndSize |
| |
|
| | linknameVarRefs []linknameVarRef |
| | } |
| |
|
| | type linknameVarRef struct { |
| | pkg string |
| | name string |
| | sym Sym |
| | } |
| |
|
| | |
| | func (st *loadState) preloadSyms(r *oReader, kind int) { |
| | l := st.l |
| | var start, end uint32 |
| | switch kind { |
| | case pkgDef: |
| | start = 0 |
| | end = uint32(r.ndef) |
| | case hashed64Def: |
| | start = uint32(r.ndef) |
| | end = uint32(r.ndef + r.nhashed64def) |
| | case hashedDef: |
| | start = uint32(r.ndef + r.nhashed64def) |
| | end = uint32(r.ndef + r.nhashed64def + r.nhasheddef) |
| | case nonPkgDef: |
| | start = uint32(r.ndef + r.nhashed64def + r.nhasheddef) |
| | end = uint32(r.ndef + r.nhashed64def + r.nhasheddef + r.NNonpkgdef()) |
| | default: |
| | panic("preloadSyms: bad kind") |
| | } |
| | l.growAttrBitmaps(len(l.objSyms) + int(end-start)) |
| | loadingRuntimePkg := r.unit.Lib.Pkg == "runtime" |
| | for i := start; i < end; i++ { |
| | osym := r.Sym(i) |
| | var name string |
| | var v int |
| | if kind != hashed64Def && kind != hashedDef { |
| | name = osym.Name(r.Reader) |
| | v = abiToVer(osym.ABI(), r.version) |
| | } |
| | gi := st.addSym(name, v, r, i, kind, osym) |
| | r.syms[i] = gi |
| | if kind == nonPkgDef && osym.IsLinkname() && r.DataSize(i) == 0 && strings.Contains(name, ".") { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | st.linknameVarRefs = append(st.linknameVarRefs, linknameVarRef{r.unit.Lib.Pkg, name, gi}) |
| | } |
| | if osym.Local() { |
| | l.SetAttrLocal(gi, true) |
| | } |
| | if osym.UsedInIface() { |
| | l.SetAttrUsedInIface(gi, true) |
| | } |
| | if strings.HasPrefix(name, "runtime.") || |
| | (loadingRuntimePkg && strings.HasPrefix(name, "type:")) { |
| | if bi := goobj.BuiltinIdx(name, int(osym.ABI())); bi != -1 { |
| | |
| | l.builtinSyms[bi] = gi |
| | } |
| | } |
| | if a := int32(osym.Align()); a != 0 && a > l.SymAlign(gi) { |
| | l.SetSymAlign(gi, a) |
| | } |
| | if osym.WasmExport() { |
| | l.WasmExports = append(l.WasmExports, gi) |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) LoadSyms(arch *sys.Arch) { |
| | |
| | |
| | |
| | var symSize, hashedSize, hashed64Size int |
| | for _, r := range l.objs[goObjStart:] { |
| | symSize += r.ndef + r.nhasheddef/2 + r.nhashed64def/2 + r.NNonpkgdef() |
| | hashedSize += r.nhasheddef / 2 |
| | hashed64Size += r.nhashed64def / 2 |
| | } |
| | |
| | l.objSyms = make([]objSym, 1, symSize) |
| |
|
| | st := loadState{ |
| | l: l, |
| | hashed64Syms: make(map[uint64]symAndSize, hashed64Size), |
| | hashedSyms: make(map[goobj.HashType]symAndSize, hashedSize), |
| | } |
| |
|
| | for _, r := range l.objs[goObjStart:] { |
| | st.preloadSyms(r, pkgDef) |
| | } |
| | l.npkgsyms = l.NSym() |
| | for _, r := range l.objs[goObjStart:] { |
| | st.preloadSyms(r, hashed64Def) |
| | st.preloadSyms(r, hashedDef) |
| | st.preloadSyms(r, nonPkgDef) |
| | } |
| | for _, vr := range st.linknameVarRefs { |
| | l.checkLinkname(vr.pkg, vr.name, vr.sym) |
| | } |
| | l.nhashedsyms = len(st.hashed64Syms) + len(st.hashedSyms) |
| | for _, r := range l.objs[goObjStart:] { |
| | loadObjRefs(l, r, arch) |
| | } |
| | for _, sf := range l.sizeFixups { |
| | pp := l.cloneToExternal(sf.sym) |
| | pp.size = int64(sf.size) |
| | } |
| | l.values = make([]int64, l.NSym(), l.NSym()+1000) |
| | l.outer = make([]Sym, l.NSym(), l.NSym()+1000) |
| | } |
| |
|
| | func loadObjRefs(l *Loader, r *oReader, arch *sys.Arch) { |
| | |
| | ndef := uint32(r.NAlldef()) |
| | for i, n := uint32(0), uint32(r.NNonpkgref()); i < n; i++ { |
| | osym := r.Sym(ndef + i) |
| | name := osym.Name(r.Reader) |
| | v := abiToVer(osym.ABI(), r.version) |
| | gi := l.LookupOrCreateSym(name, v) |
| | r.syms[ndef+i] = gi |
| | if osym.IsLinkname() { |
| | |
| | |
| | |
| | |
| | l.checkLinkname(r.unit.Lib.Pkg, name, gi) |
| | } |
| | if osym.Local() { |
| | l.SetAttrLocal(gi, true) |
| | } |
| | if osym.UsedInIface() { |
| | l.SetAttrUsedInIface(gi, true) |
| | } |
| | } |
| |
|
| | |
| | npkg := r.NPkg() |
| | r.pkg = make([]uint32, npkg) |
| | for i := 1; i < npkg; i++ { |
| | pkg := r.Pkg(i) |
| | objidx, ok := l.objByPkg[pkg] |
| | if !ok { |
| | log.Fatalf("%v: reference to nonexistent package %s", r.unit.Lib, pkg) |
| | } |
| | r.pkg[i] = objidx |
| | } |
| |
|
| | |
| | for i, n := 0, r.NRefFlags(); i < n; i++ { |
| | rf := r.RefFlags(i) |
| | gi := l.resolve(r, rf.Sym()) |
| | if rf.Flag2()&goobj.SymFlagUsedInIface != 0 { |
| | l.SetAttrUsedInIface(gi, true) |
| | } |
| | } |
| | } |
| |
|
| | func abiToVer(abi uint16, localSymVersion int) int { |
| | var v int |
| | if abi == goobj.SymABIstatic { |
| | |
| | v = localSymVersion |
| | } else if abiver := sym.ABIToVersion(obj.ABI(abi)); abiver != -1 { |
| | |
| | v = abiver |
| | } else { |
| | log.Fatalf("invalid symbol ABI: %d", abi) |
| | } |
| | return v |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | var blockedLinknames = map[string][]string{ |
| | |
| | "runtime.coroswitch": {"iter"}, |
| | "runtime.newcoro": {"iter"}, |
| | |
| | "go:fipsinfo": {"crypto/internal/fips140/check"}, |
| | |
| | |
| | "crypto/internal/fips140.fatal": {"crypto/internal/fips140"}, |
| | "crypto/internal/fips140.getIndicator": {"crypto/internal/fips140"}, |
| | "crypto/internal/fips140.setIndicator": {"crypto/internal/fips140"}, |
| | "crypto/internal/sysrand.fatal": {"crypto/internal/sysrand"}, |
| | "crypto/rand.fatal": {"crypto/rand"}, |
| | "internal/runtime/maps.errNilAssign": {"internal/runtime/maps"}, |
| | "internal/runtime/maps.fatal": {"internal/runtime/maps"}, |
| | "internal/runtime/maps.newarray": {"internal/runtime/maps"}, |
| | "internal/runtime/maps.newobject": {"internal/runtime/maps"}, |
| | "internal/runtime/maps.rand": {"internal/runtime/maps"}, |
| | "internal/runtime/maps.typedmemclr": {"internal/runtime/maps"}, |
| | "internal/runtime/maps.typedmemmove": {"internal/runtime/maps"}, |
| | "internal/sync.fatal": {"internal/sync"}, |
| | "internal/sync.runtime_canSpin": {"internal/sync"}, |
| | "internal/sync.runtime_doSpin": {"internal/sync"}, |
| | "internal/sync.runtime_nanotime": {"internal/sync"}, |
| | "internal/sync.runtime_Semrelease": {"internal/sync"}, |
| | "internal/sync.runtime_SemacquireMutex": {"internal/sync"}, |
| | "internal/sync.throw": {"internal/sync"}, |
| | "internal/synctest.Run": {"internal/synctest"}, |
| | "internal/synctest.Wait": {"internal/synctest"}, |
| | "internal/synctest.acquire": {"internal/synctest"}, |
| | "internal/synctest.release": {"internal/synctest"}, |
| | "internal/synctest.inBubble": {"internal/synctest"}, |
| | "runtime.getStaticuint64s": {"reflect"}, |
| | "sync.runtime_SemacquireWaitGroup": {"sync"}, |
| | "time.runtimeNow": {"time"}, |
| | "time.runtimeNano": {"time"}, |
| | |
| | |
| | "runtime.mapaccess1": {"runtime"}, |
| | "runtime.mapaccess1_fast32": {"runtime"}, |
| | "runtime.mapaccess1_fast64": {"runtime"}, |
| | "runtime.mapaccess1_faststr": {"runtime"}, |
| | "runtime.mapdelete_fast32": {"runtime"}, |
| | "runtime.mapdelete_fast64": {"runtime"}, |
| | "runtime.mapdelete_faststr": {"runtime"}, |
| | |
| | |
| | "internal/cpu.riscvHWProbe": {"internal/cpu"}, |
| | "internal/runtime/cgroup.throw": {"internal/runtime/cgroup"}, |
| | "internal/runtime/maps.typeString": {"internal/runtime/maps"}, |
| | "internal/synctest.IsInBubble": {"internal/synctest"}, |
| | "internal/synctest.associate": {"internal/synctest"}, |
| | "internal/synctest.disassociate": {"internal/synctest"}, |
| | "internal/synctest.isAssociated": {"internal/synctest"}, |
| | "runtime/trace.runtime_readTrace": {"runtime/trace"}, |
| | "runtime/trace.runtime_traceClockUnitsPerSecond": {"runtime/trace"}, |
| | "sync_test.runtime_blockUntilEmptyCleanupQueue": {"sync_test"}, |
| | "time.runtimeIsBubbled": {"time"}, |
| | "unique.runtime_blockUntilEmptyCleanupQueue": {"unique"}, |
| | |
| | "net.newWindowsFile": {"net"}, |
| | "testing/synctest.testingSynctestTest": {"testing/synctest"}, |
| | |
| | |
| | "crypto/fips140.isBypassed": {"crypto/fips140"}, |
| | "crypto/fips140.setBypass": {"crypto/fips140"}, |
| | "crypto/fips140.unsetBypass": {"crypto/fips140"}, |
| | "crypto/subtle.setDITEnabled": {"crypto/subtle"}, |
| | "crypto/subtle.setDITDisabled": {"crypto/subtle"}, |
| | "internal/cpu.sysctlbynameBytes": {"internal/cpu"}, |
| | "internal/cpu.sysctlbynameInt32": {"internal/cpu"}, |
| | "runtime.pprof_goroutineLeakProfileWithLabels": {"runtime/pprof"}, |
| | "runtime/pprof.runtime_goroutineLeakGC": {"runtime/pprof"}, |
| | "runtime/pprof.runtime_goroutineleakcount": {"runtime/pprof"}, |
| | "runtime/secret.appendSignalStacks": {"runtime/secret"}, |
| | "runtime/secret.count": {"runtime/secret"}, |
| | "runtime/secret.dec": {"runtime/secret"}, |
| | "runtime/secret.eraseSecrets": {"runtime/secret"}, |
| | "runtime/secret.getStack": {"runtime/secret"}, |
| | "runtime/secret.inc": {"runtime/secret"}, |
| | "syscall.rawsyscalln": {"syscall"}, |
| | "syscall.runtimeClearenv": {"syscall"}, |
| | "syscall.syscalln": {"syscall"}, |
| | |
| | "crypto/internal/rand.SetTestingReader": {"testing/cryptotest"}, |
| | "testing.checkParallel": {"testing/cryptotest"}, |
| | "runtime.addmoduledata": {}, |
| | } |
| |
|
| | |
| | func (l *Loader) checkLinkname(pkg, name string, s Sym) { |
| | if l.flags&FlagCheckLinkname == 0 { |
| | return |
| | } |
| |
|
| | error := func() { |
| | log.Fatalf("%s: invalid reference to %s", pkg, name) |
| | } |
| | pkgs, ok := blockedLinknames[name] |
| | if ok { |
| | for _, p := range pkgs { |
| | if pkg == p { |
| | return |
| | } |
| | |
| | |
| | if strings.HasPrefix(pkg, "crypto/internal/fips140/v") { |
| | parts := strings.Split(pkg, "/") |
| | parts = append(parts[:3], parts[4:]...) |
| | pkg := strings.Join(parts, "/") |
| | if pkg == p { |
| | return |
| | } |
| | } |
| | } |
| | error() |
| | } |
| | r, li := l.toLocal(s) |
| | if r == l.extReader { |
| | return |
| | } |
| | if !r.Std() { |
| | return |
| | } |
| | if r.unit.Lib.Pkg == pkg { |
| | return |
| | } |
| | osym := r.Sym(li) |
| | if osym.IsLinkname() || osym.ABIWrapper() { |
| | |
| | |
| | |
| | |
| | |
| | return |
| | } |
| | error() |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func (l *Loader) TopLevelSym(s Sym) bool { |
| | return topLevelSym(l.SymName(s), l.SymType(s)) |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func topLevelSym(sname string, skind sym.SymKind) bool { |
| | if sname != "" { |
| | return true |
| | } |
| | switch skind { |
| | case sym.SDWARFFCN, sym.SDWARFABSFCN, sym.SDWARFTYPE, sym.SDWARFCONST, sym.SDWARFCUINFO, sym.SDWARFRANGE, sym.SDWARFLOC, sym.SDWARFLINES, sym.SGOFUNC: |
| | return true |
| | default: |
| | return false |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) cloneToExternal(symIdx Sym) *extSymPayload { |
| | if l.IsExternal(symIdx) { |
| | panic("sym is already external, no need for clone") |
| | } |
| |
|
| | |
| | r, li := l.toLocal(symIdx) |
| | osym := r.Sym(li) |
| | sname := osym.Name(r.Reader) |
| | sver := abiToVer(osym.ABI(), r.version) |
| | skind := sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type())] |
| |
|
| | |
| | pi := l.newPayload(sname, sver) |
| | pp := l.payloads[pi] |
| | pp.kind = skind |
| | pp.ver = sver |
| | pp.size = int64(osym.Siz()) |
| | pp.objidx = r.objidx |
| |
|
| | |
| | |
| | if li < uint32(r.NAlldef()) { |
| |
|
| | |
| | relocs := l.Relocs(symIdx) |
| | pp.relocs = make([]goobj.Reloc, relocs.Count()) |
| | for i := range pp.relocs { |
| | |
| | |
| | rel := relocs.At(i) |
| | pp.relocs[i].Set(rel.Off(), rel.Siz(), uint16(rel.Type()), rel.Add(), goobj.SymRef{PkgIdx: 0, SymIdx: uint32(rel.Sym())}) |
| | } |
| |
|
| | |
| | pp.data = r.Data(li) |
| | } |
| |
|
| | |
| | |
| | auxs := r.Auxs(li) |
| | pp.auxs = auxs |
| |
|
| | |
| | |
| | |
| | l.objSyms[symIdx] = objSym{l.extReader.objidx, uint32(pi)} |
| | l.extReader.syms = append(l.extReader.syms, symIdx) |
| |
|
| | |
| | l.SetAttrDuplicateOK(symIdx, r.Sym(li).Dupok()) |
| | l.SetAttrShared(symIdx, r.Shared()) |
| |
|
| | return pp |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) CopySym(src, dst Sym) { |
| | if !l.IsExternal(dst) { |
| | panic("dst is not external") |
| | } |
| | if !l.IsExternal(src) { |
| | panic("src is not external") |
| | } |
| | l.payloads[l.extIndex(dst)] = l.payloads[l.extIndex(src)] |
| | l.SetSymPkg(dst, l.SymPkg(src)) |
| | |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) CreateExtSym(name string, ver int) Sym { |
| | return l.newExtSym(name, ver) |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) CreateStaticSym(name string) Sym { |
| | |
| | |
| | l.anonVersion-- |
| | return l.newExtSym(name, l.anonVersion) |
| | } |
| |
|
| | func (l *Loader) FreeSym(i Sym) { |
| | if l.IsExternal(i) { |
| | pp := l.getPayload(i) |
| | *pp = extSymPayload{} |
| | } |
| | } |
| |
|
| | |
| | |
| | type relocId struct { |
| | sym Sym |
| | ridx int |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) SetRelocVariant(s Sym, ri int, v sym.RelocVariant) { |
| | |
| | if relocs := l.Relocs(s); ri >= relocs.Count() { |
| | panic("invalid relocation ID") |
| | } |
| | if l.relocVariant == nil { |
| | l.relocVariant = make(map[relocId]sym.RelocVariant) |
| | } |
| | if v != 0 { |
| | l.relocVariant[relocId{s, ri}] = v |
| | } else { |
| | delete(l.relocVariant, relocId{s, ri}) |
| | } |
| | } |
| |
|
| | |
| | |
| | func (l *Loader) RelocVariant(s Sym, ri int) sym.RelocVariant { |
| | return l.relocVariant[relocId{s, ri}] |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | func (l *Loader) UndefinedRelocTargets(limit int) ([]Sym, []Sym) { |
| | result, fromr := []Sym{}, []Sym{} |
| | outerloop: |
| | for si := Sym(1); si < Sym(len(l.objSyms)); si++ { |
| | relocs := l.Relocs(si) |
| | for ri := 0; ri < relocs.Count(); ri++ { |
| | r := relocs.At(ri) |
| | rs := r.Sym() |
| | if rs != 0 && l.SymType(rs) == sym.SXREF && l.SymName(rs) != ".got" { |
| | result = append(result, rs) |
| | fromr = append(fromr, si) |
| | if limit != -1 && len(result) >= limit { |
| | break outerloop |
| | } |
| | } |
| | } |
| | } |
| | return result, fromr |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func (l *Loader) AssignTextSymbolOrder(libs []*sym.Library, intlibs []bool, extsyms []Sym) []Sym { |
| |
|
| | |
| | for _, lib := range libs { |
| | if len(lib.Textp) != 0 { |
| | panic("expected empty Textp slice for library") |
| | } |
| | if len(lib.DupTextSyms) != 0 { |
| | panic("expected empty DupTextSyms slice for library") |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | assignedToUnit := MakeBitmap(l.NSym() + 1) |
| |
|
| | |
| | textp := []Sym{} |
| | for _, sym := range extsyms { |
| | if !l.attrReachable.Has(sym) { |
| | continue |
| | } |
| | textp = append(textp, sym) |
| | } |
| |
|
| | |
| | |
| | for _, r := range l.objs[goObjStart:] { |
| | lib := r.unit.Lib |
| | for i, n := uint32(0), uint32(r.NAlldef()); i < n; i++ { |
| | gi := l.toGlobal(r, i) |
| | if !l.attrReachable.Has(gi) { |
| | continue |
| | } |
| | osym := r.Sym(i) |
| | st := sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type())] |
| | if !st.IsText() { |
| | continue |
| | } |
| | dupok := osym.Dupok() |
| | if r2, i2 := l.toLocal(gi); r2 != r || i2 != i { |
| | |
| | |
| | |
| | |
| | lib.DupTextSyms = append(lib.DupTextSyms, gi) |
| | continue |
| | } |
| | if dupok { |
| | lib.DupTextSyms = append(lib.DupTextSyms, gi) |
| | continue |
| | } |
| |
|
| | lib.Textp = append(lib.Textp, gi) |
| | } |
| | } |
| |
|
| | |
| | for _, doInternal := range [2]bool{true, false} { |
| | for idx, lib := range libs { |
| | if intlibs[idx] != doInternal { |
| | continue |
| | } |
| | lists := [2][]sym.LoaderSym{lib.Textp, lib.DupTextSyms} |
| | for i, list := range lists { |
| | for _, s := range list { |
| | sym := s |
| | if !assignedToUnit.Has(sym) { |
| | textp = append(textp, sym) |
| | unit := l.SymUnit(sym) |
| | if unit != nil { |
| | unit.Textp = append(unit.Textp, s) |
| | assignedToUnit.Set(sym) |
| | } |
| | |
| | |
| | |
| | |
| | |
| | if i == 1 && l.SymPkg(sym) != lib.Pkg { |
| | l.SetSymPkg(sym, lib.Pkg) |
| | } |
| | } |
| | } |
| | } |
| | lib.Textp = nil |
| | lib.DupTextSyms = nil |
| | } |
| | } |
| |
|
| | return textp |
| | } |
| |
|
| | |
| | type ErrorReporter struct { |
| | ldr *Loader |
| | AfterErrorAction func() |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | func (reporter *ErrorReporter) Errorf(s Sym, format string, args ...any) { |
| | if s != 0 && reporter.ldr.SymName(s) != "" { |
| | |
| | |
| | format = strings.ReplaceAll(reporter.ldr.SymName(s), "%", "%%") + ": " + format |
| | } else { |
| | format = fmt.Sprintf("sym %d: %s", s, format) |
| | } |
| | format += "\n" |
| | fmt.Fprintf(os.Stderr, format, args...) |
| | reporter.AfterErrorAction() |
| | } |
| |
|
| | |
| | func (l *Loader) GetErrorReporter() *ErrorReporter { |
| | return l.errorReporter |
| | } |
| |
|
| | |
| | func (l *Loader) Errorf(s Sym, format string, args ...any) { |
| | l.errorReporter.Errorf(s, format, args...) |
| | } |
| |
|
| | |
| | func (l *Loader) Stat() string { |
| | s := fmt.Sprintf("%d symbols, %d reachable\n", l.NSym(), l.NReachableSym()) |
| | s += fmt.Sprintf("\t%d package symbols, %d hashed symbols, %d non-package symbols, %d external symbols\n", |
| | l.npkgsyms, l.nhashedsyms, int(l.extStart)-l.npkgsyms-l.nhashedsyms, l.NSym()-int(l.extStart)) |
| | return s |
| | } |
| |
|
| | |
| | func (l *Loader) Dump() { |
| | fmt.Println("objs") |
| | for _, r := range l.objs[goObjStart:] { |
| | if r != nil { |
| | fmt.Println(r.unit.Lib) |
| | } |
| | } |
| | fmt.Println("extStart:", l.extStart) |
| | fmt.Println("Nsyms:", len(l.objSyms)) |
| | fmt.Println("syms") |
| | for i := Sym(1); i < Sym(len(l.objSyms)); i++ { |
| | pi := "" |
| | if l.IsExternal(i) { |
| | pi = fmt.Sprintf("<ext %d>", l.extIndex(i)) |
| | } |
| | sect := "" |
| | if l.SymSect(i) != nil { |
| | sect = l.SymSect(i).Name |
| | } |
| | fmt.Printf("%v %v %v %v %x %v\n", i, l.SymName(i), l.SymType(i), pi, l.SymValue(i), sect) |
| | } |
| | fmt.Println("symsByName") |
| | for name, i := range l.symsByName[0] { |
| | fmt.Println(i, name, 0) |
| | } |
| | for name, i := range l.symsByName[1] { |
| | fmt.Println(i, name, 1) |
| | } |
| | fmt.Println("payloads:") |
| | for i := range l.payloads { |
| | pp := l.payloads[i] |
| | fmt.Println(i, pp.name, pp.ver, pp.kind) |
| | } |
| | } |
| |
|