From 6349fcc2a6d1c7256aea4e75fd660e87f7c66ecd Mon Sep 17 00:00:00 2001 From: Andrew LeFevre Date: Wed, 2 Sep 2020 13:35:56 -0400 Subject: [PATCH] expose SymKind values --- goobj2/file.go | 46 +++++++++++++++++++++++++++++++++++++++++----- goobj2/write.go | 5 ++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/goobj2/file.go b/goobj2/file.go index 81b3540..7a770a1 100644 --- a/goobj2/file.go +++ b/goobj2/file.go @@ -90,7 +90,7 @@ type ArchiveHeader struct { type Sym struct { Name string ABI uint16 - Kind objabi.SymKind // kind of symbol + Kind SymKind // kind of symbol Flag uint8 Size uint32 // size of corresponding data Align uint32 @@ -145,8 +145,6 @@ type Func struct { dataSymIdx int } -// TODO: Add PCData []byte and PCDataIter (similar to liblink). - // A FuncData is a single function-specific data value. type FuncData struct { Sym *SymRef // symbol holding data @@ -163,6 +161,44 @@ type InlinedCall struct { ParentPC int32 } +// A SymKind describes the kind of memory represented by a symbol. +type SymKind uint8 + +// Defined SymKind values. +// Copied from cmd/internal/objabi +const ( + // An otherwise invalid zero value for the type + Sxxx SymKind = iota + // Executable instructions + STEXT + // Read only static data + SRODATA + // Static data that does not contain any pointers + SNOPTRDATA + // Static data + SDATA + // Statically data that is initially all 0s + SBSS + // Statically data that is initially all 0s and does not contain pointers + SNOPTRBSS + // Thread-local data that is initially all 0s + STLSBSS + // Debugging data + SDWARFINFO + SDWARFRANGE + SDWARFLOC + SDWARFLINES + // ABI alias. An ABI alias symbol is an empty symbol with a + // single relocation with 0 size that references the native + // function implementation symbol. + // + // TODO(austin): Remove this and all uses once the compiler + // generates real ABI wrappers rather than symbol aliases. + SABIALIAS + // Coverage instrumentation counter for libfuzzer. + SLIBFUZZER_EXTRA_COUNTER +) + type ImportCfg map[string]ExportInfo type ExportInfo struct { @@ -670,7 +706,7 @@ func (r *objReader) parseObject(prefix []byte, importMap ImportCfg, returnReader sym := &Sym{ Name: osym.Name(rr), ABI: osym.ABI(), - Kind: objabi.SymKind(osym.Type()), + Kind: SymKind(osym.Type()), Flag: osym.Flag(), Size: osym.Siz(), Align: osym.Align(), @@ -682,7 +718,7 @@ func (r *objReader) parseObject(prefix []byte, importMap ImportCfg, returnReader return // not a defined symbol from here } - if sym.Kind == objabi.STEXT { + if sym.Kind == STEXT { am.textSyms = append(am.textSyms, sym) } diff --git a/goobj2/write.go b/goobj2/write.go index 58bdb7c..97eab5f 100644 --- a/goobj2/write.go +++ b/goobj2/write.go @@ -16,7 +16,6 @@ import ( "github.com/Binject/debug/goobj2/internal/bio" "github.com/Binject/debug/goobj2/internal/goobj2" - "github.com/Binject/debug/goobj2/internal/objabi" ) // Write writes the contents of the parsed archive to disk. @@ -232,7 +231,7 @@ func (w *writer) StringTable() { w.AddString(s.Name) } - if s.Kind == objabi.STEXT && s.Func != nil { + if s.Kind == STEXT && s.Func != nil { for _, d := range s.Func.FuncData { w.AddString(d.Sym.Name) } @@ -261,7 +260,7 @@ func (w *writer) StringTable() { syms := [][]*Sym{w.ctxt.NonPkgSymDefs, w.ctxt.SymDefs, w.ctxt.NonPkgSymRefs} for _, list := range syms { for _, s := range list { - if s.Kind == objabi.STEXT { + if s.Kind == STEXT { continue }