From a8bfb03dd4e0a090d4d6e68b9d6f5ed528ea3987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikk=20Margus=20M=C3=B6ll?= Date: Fri, 29 Sep 2023 05:45:10 +0800 Subject: [PATCH 01/12] fix: generate moduledata --- gen.go | 4 +- gen_moduledata.go | 331 +++++++++++++++++++++++ moduledata.go | 614 ++---------------------------------------- moduledata_gen.go | 662 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1011 insertions(+), 600 deletions(-) create mode 100644 gen_moduledata.go create mode 100644 moduledata_gen.go diff --git a/gen.go b/gen.go index d55d93d..7cd9dc3 100644 --- a/gen.go +++ b/gen.go @@ -1,6 +1,6 @@ // This file is part of GoRE. // -// Copyright (C) 2019-2021 GoRE Authors +// Copyright (C) 2019-2023 GoRE Authors // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -18,7 +18,7 @@ //go:build ignore // +build ignore -// This program generates stdpkgs_gen.go. It can be invoked by running +// This program generates stdpkgs_gen.go and goversion_gen.go. It can be invoked by running // go generate package main diff --git a/gen_moduledata.go b/gen_moduledata.go new file mode 100644 index 0000000..5cf4eed --- /dev/null +++ b/gen_moduledata.go @@ -0,0 +1,331 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2023 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +//go:build ignore +// +build ignore + +// This program generates stdpkgs_gen.go and goversion_gen.go. It can be invoked by running +// go generate +package main + +import ( + "bytes" + "fmt" + "go/format" + "os" + "reflect" + "strings" +) + +const header = ` +// This file is part of GoRE. +// +// Copyright (C) 2019-2023 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by go generate; DO NOT EDIT. + +package gore + +` + +func typeDef(b *bytes.Buffer, st reflect.Type, bits int) { + typeName := "uint64" + if bits == 32 { + typeName = "uint32" + } + + fmt.Fprintf(b, "type %s%d struct {\n", st.Name(), bits) + + for i := 0; i < st.NumField(); i++ { + field := st.Field(i) + fieldName := strings.ToUpper(field.Name[:1]) + field.Name[1:] + t := field.Type.Kind() + switch t { + case reflect.Uintptr: + fmt.Fprintf(b, "%s %s\n", fieldName, typeName) + case reflect.String: + fmt.Fprintf(b, "%s, %[1]slen %s\n", fieldName, typeName) + case reflect.Pointer: + fmt.Fprintf(b, "%s %s\n", fieldName, typeName) + case reflect.Slice: + fmt.Fprintf(b, "%s, %[1]slen, %[1]scap %s\n", fieldName, typeName) + + default: + panic(fmt.Sprintf("unhandled type: %+v", t)) + } + } + + fmt.Fprint(b, "}\n\n") +} + +func toModuledata(b *bytes.Buffer, st reflect.Type, bits int) { + fmt.Fprintf(b, "func (md %s%d) toModuledata() moduledata {\n", st.Name(), bits) + fmt.Fprint(b, "return moduledata{\n") + + for _, names := range [][2]string{ + {"Text", "Text"}, + {"NoPtrData", "Noptrdata"}, + {"Data", "Data"}, + {"Bss", "Bss"}, + {"NoPtrBss", "Noptrbss"}, + {"Types", "Types"}, + } { + modFieldE(b, st, bits, names[0], names[1]) + } + + for _, names := range [][2]string{ + {"Typelink", "Typelinks"}, + {"ITabLink", "Itablinks"}, + {"FuncTab", "Ftab"}, + {"PCLNTab", "Pclntable"}, + } { + modFieldLen(b, st, bits, names[0], names[1]) + } + + fmt.Fprint(b, "}\n}\n\n") +} + +func modFieldE(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { + endName := "E" + strings.ToLower(parsedName) + if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { + return + } + if bits == 32 { + fmt.Fprintf(b, "%sAddr: uint64(md.%[3]s),\n%[1]sLen: uint64(md.%s - md.%s),\n", modName, endName, parsedName) + } else { + fmt.Fprintf(b, "%sAddr: md.%[3]s,\n%[1]sLen: md.%s - md.%s,\n", modName, endName, parsedName) + } +} + +func modFieldLen(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { + lenName := parsedName + "len" + if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { + return + } + if bits == 32 { + fmt.Fprintf(b, "%sAddr: uint64(md.%s),\n%[1]sLen: uint64(md.%[3]s),\n", modName, parsedName, lenName) + } else { + fmt.Fprintf(b, "%sAddr: md.%s,\n%[1]sLen: md.%[3]s,\n", modName, parsedName, lenName) + } +} + +func main() { + + b := &bytes.Buffer{} + check1(b.WriteString(header)) + + for _, iface := range []any{ + moduledata20{}, + moduledata18{}, + moduledata16{}, + moduledata8{}, + moduledata7{}, + moduledata5{}, + } { + o := reflect.TypeOf(iface) + typeDef(b, o, 64) + toModuledata(b, o, 64) + typeDef(b, o, 32) + toModuledata(b, o, 32) + } + + fmted := check1(format.Source(b.Bytes())) + check(os.WriteFile("moduledata_gen.go", fmted, 0o666)) +} + +func check(err error) { + if err != nil { + panic(err) + } +} + +func check1[T any](arg1 T, err error) T { + check(err) + return arg1 +} + +/* + Internal module structures from Go's runtime. +*/ + +// Moduledata structure for Go 1.20 and newer (at least up to the last field covered here) + +type moduledata20 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + covctrs, ecovctrs uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + rodata uintptr + gofunc uintptr // go.func.* + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.18 and Go 1.19 + +type moduledata18 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + rodata uintptr + gofunc uintptr // go.func.* + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.16 to 1.17 + +type moduledata16 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.8 to 1.15 + +type moduledata8 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.7 + +type moduledata7 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.5 to 1.6 + +type moduledata5 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + + typelinks []*_type +} + +// dummy definitions +type initTask struct{} +type pcHeader struct{} +type functab struct{} +type textsect struct{} +type itab struct{} +type ptabEntry struct{} +type modulehash struct{} +type _type struct{} diff --git a/moduledata.go b/moduledata.go index 8f00952..bf50235 100644 --- a/moduledata.go +++ b/moduledata.go @@ -1,6 +1,6 @@ // This file is part of GoRE. // -// Copyright (C) 2019-2022 GoRE Authors +// Copyright (C) 2019-2023 GoRE Authors // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -17,13 +17,14 @@ package gore +//go:generate go run gen_moduledata.go + import ( "bytes" "encoding/binary" "errors" "fmt" "io" - "reflect" ) // Moduledata extracts the file's moduledata. @@ -87,7 +88,7 @@ type moduledata struct { fh fileHandler } -// Text returns the text secion. +// Text returns the text section. func (m moduledata) Text() ModuleDataSection { return ModuleDataSection{ Address: m.TextAddr, @@ -256,7 +257,7 @@ func parseModuledata(fileInfo *FileInfo, f fileHandler) (moduledata, error) { } // buf will hold the struct type that represents the data in the file we are processing. - var buf interface{} + var buf modulable is32bit := fileInfo.WordSize == intSize32 // Determine what kind of struct we need to extract the module data from the file. @@ -301,16 +302,13 @@ func parseModuledata(fileInfo *FileInfo, f fileHandler) (moduledata, error) { // Read the module struct from the file. r := bytes.NewReader(data) - err = readStruct(r, fileInfo.ByteOrder, buf) + err = binary.Read(r, fileInfo.ByteOrder, buf) if err != nil { return moduledata{}, fmt.Errorf("error when reading module data from file: %w", err) } // Convert the read struct to the type we return to the caller. - md, err := processModuledata(buf) - if err != nil { - return md, fmt.Errorf("error when processing module data: %w", err) - } + md := buf.toModuledata() // Add the file handler. md.fh = f @@ -318,597 +316,17 @@ func parseModuledata(fileInfo *FileInfo, f fileHandler) (moduledata, error) { return md, nil } -func readUIntTo64(r io.Reader, byteOrder binary.ByteOrder, is32bit bool) (uint64, error) { +func readUIntTo64(r io.Reader, byteOrder binary.ByteOrder, is32bit bool) (addr uint64, err error) { if is32bit { - var addr uint32 - err := binary.Read(r, byteOrder, &addr) - return uint64(addr), err - } - var addr uint64 - err := binary.Read(r, byteOrder, &addr) - return addr, err -} - -// readStruct performs a binary read from the reader to the data object. Data object must -// be a pointer to the struct. -func readStruct(r io.Reader, byteOrder binary.ByteOrder, data interface{}) error { - return binary.Read(r, byteOrder, data) -} - -func processModuledata(data interface{}) (moduledata, error) { - md := moduledata{} - // This will panic if the data passed in is not a pointer to - // a struct. But this function should not be called outside - // of this file, we can ensure this is always the case. - val := reflect.ValueOf(data).Elem() - - extractModFieldValue(&md, "TextAddr", val, "Text") - extractModFieldValue(&md, "TextLen", val, "Etext") - if md.TextLen > md.TextAddr { - md.TextLen = md.TextLen - md.TextAddr - } - - extractModFieldValue(&md, "NoPtrDataAddr", val, "Noptrdata") - extractModFieldValue(&md, "NoPtrDataLen", val, "Enoptrdata") - if md.NoPtrDataLen > md.NoPtrDataAddr { - md.NoPtrDataLen = md.NoPtrDataLen - md.NoPtrDataAddr - } - - extractModFieldValue(&md, "DataAddr", val, "Data") - extractModFieldValue(&md, "DataLen", val, "Edata") - if md.DataLen > md.DataAddr { - md.DataLen = md.DataLen - md.DataAddr - } - - extractModFieldValue(&md, "BssAddr", val, "Bss") - extractModFieldValue(&md, "BssLen", val, "Ebss") - if md.BssLen > md.BssAddr { - md.BssLen = md.BssLen - md.BssAddr - } - - extractModFieldValue(&md, "NoPtrBssAddr", val, "Noptrbss") - extractModFieldValue(&md, "NoPtrBssLen", val, "Enoptrbss") - if md.NoPtrBssLen > md.NoPtrBssAddr { - md.NoPtrBssLen = md.NoPtrBssLen - md.NoPtrBssAddr - } - - extractModFieldValue(&md, "TypelinkAddr", val, "Typelinks") - extractModFieldValue(&md, "TypelinkLen", val, "Typelinkslen") - extractModFieldValue(&md, "ITabLinkAddr", val, "Itablinks") - extractModFieldValue(&md, "ITabLinkLen", val, "Itablinkslen") - extractModFieldValue(&md, "FuncTabAddr", val, "Ftab") - extractModFieldValue(&md, "FuncTabLen", val, "Ftablen") - extractModFieldValue(&md, "PCLNTabAddr", val, "Pclntable") - extractModFieldValue(&md, "PCLNTabLen", val, "Pclntablelen") - - extractModFieldValue(&md, "TypesAddr", val, "Types") - extractModFieldValue(&md, "TypesLen", val, "Etypes") - if md.TypesLen > md.TypesAddr { - md.TypesLen = md.TypesLen - md.TypesAddr - } - - extractModFieldValue(&md, "GoFuncVal", val, "GoFunc") - - return md, nil -} - -func extractModFieldValue(md *moduledata, dst string, val reflect.Value, src string) { - field := val.FieldByName(src) - // Not all versions of the module struct has all the fields. If we don't have the - // field, we skip it. - if !field.IsValid() { - return - } - - // Save 32 to 64 uint casting if needed. - var num uint64 - switch field.Interface().(type) { - case uint64: - num = field.Uint() - case uint32: - t := field.Interface().(uint32) - num = uint64(t) + var addr32 uint32 + err = binary.Read(r, byteOrder, &addr32) + addr = uint64(addr32) + } else { + err = binary.Read(r, byteOrder, &addr) } - - // Set the value. - mdField := reflect.ValueOf(md).Elem().FieldByName(dst) - mdField.SetUint(num) -} - -/* - Internal module structures from Go's runtime. -*/ - -// Moduledata structure for Go 1.20 and newer - -type moduledata2064 struct { - PcHeader uint64 - Funcnametab, Funcnametablen, Funcnametabcap uint64 - Cutab, Cutablen, Cutabcap uint64 - Filetab, Filetablen, Filetabcap uint64 - Pctab, Pctablen, Pctabcap uint64 - Pclntable, Pclntablelen, Pclntablecap uint64 - Ftab, Ftablen, Ftabcap uint64 - Findfunctab uint64 - Minpc, Maxpc uint64 - - Text, Etext uint64 - Noptrdata, Enoptrdata uint64 - Data, Edata uint64 - Bss, Ebss uint64 - Noptrbss, Enoptrbss uint64 - Covctrs, Ecovctrs uint64 - End, Gcdata, Gcbss uint64 - Types, Etypes uint64 - RData uint64 - GoFunc uint64 - - Textsectmap, Textsectmaplen, Textsectmapcap uint64 - Typelinks, Typelinkslen, Typelinkscap uint64 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint64 - - Ptab, Ptablen, Ptabcap uint64 - - Pluginpath, Pluginpathlen uint64 - Pkghashes, Pkghasheslen, Pkghashescap uint64 - - Modulename, Modulenamelen uint64 - Modulehashes, Modulehasheslen, Modulehashescap uint64 - - /* These fields we are not planning to use so skipping the parsing of them. - - hasmain uint8 // 1 if module contains the main function, 0 otherwise - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - bad bool // module failed to load and should be ignored - - next *moduledata - */ + return } -type moduledata2032 struct { - PcHeader uint32 - Funcnametab, Funcnametablen, Funcnametabcap uint32 - Cutab, Cutablen, Cutabcap uint32 - Filetab, Filetablen, Filetabcap uint32 - Pctab, Pctablen, Pctabcap uint32 - Pclntable, Pclntablelen, Pclntablecap uint32 - Ftab, Ftablen, Ftabcap uint32 - Findfunctab uint32 - Minpc, Maxpc uint32 - - Text, Etext uint32 - Noptrdata, Enoptrdata uint32 - Data, Edata uint32 - Bss, Ebss uint32 - Noptrbss, Enoptrbss uint32 - Covctrs, Ecovctrs uint32 - End, Gcdata, Gcbss uint32 - Types, Etypes uint32 - RData uint32 - GoFunc uint32 - - Textsectmap, Textsectmaplen, Textsectmapcap uint32 - Typelinks, Typelinkslen, Typelinkscap uint32 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint32 - - Ptab, Ptablen, Ptabcap uint32 - - Pluginpath, Pluginpathlen uint32 - Pkghashes, Pkghasheslen, Pkghashescap uint32 - - Modulename, Modulenamelen uint32 - Modulehashes, Modulehasheslen, Modulehashescap uint32 - - /* These fields we are not planning to use so skipping the parsing of them. - - hasmain uint8 // 1 if module contains the main function, 0 otherwise - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - bad bool // module failed to load and should be ignored - - next *moduledata - */ -} - -// Moduledata structure for Go 1.18 and Go 1.19 - -type moduledata1864 struct { - PcHeader uint64 - Funcnametab, Funcnametablen, Funcnametabcap uint64 - Cutab, Cutablen, Cutabcap uint64 - Filetab, Filetablen, Filetabcap uint64 - Pctab, Pctablen, Pctabcap uint64 - Pclntable, Pclntablelen, Pclntablecap uint64 - Ftab, Ftablen, Ftabcap uint64 - Findfunctab uint64 - Minpc, Maxpc uint64 - - Text, Etext uint64 - Noptrdata, Enoptrdata uint64 - Data, Edata uint64 - Bss, Ebss uint64 - Noptrbss, Enoptrbss uint64 - End, Gcdata, Gcbss uint64 - Types, Etypes uint64 - RData uint64 - GoFunc uint64 - - Textsectmap, Textsectmaplen, Textsectmapcap uint64 - Typelinks, Typelinkslen, Typelinkscap uint64 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint64 - - Ptab, Ptablen, Ptabcap uint64 - - Pluginpath, Pluginpathlen uint64 - Pkghashes, Pkghasheslen, Pkghashescap uint64 - - Modulename, Modulenamelen uint64 - Modulehashes, Modulehasheslen, Modulehashescap uint64 - - /* These fields we are not planning to use so skipping the parsing of them. - - hasmain uint8 // 1 if module contains the main function, 0 otherwise - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - bad bool // module failed to load and should be ignored - - next *moduledata - */ -} - -type moduledata1832 struct { - PcHeader uint32 - Funcnametab, Funcnametablen, Funcnametabcap uint32 - Cutab, Cutablen, Cutabcap uint32 - Filetab, Filetablen, Filetabcap uint32 - Pctab, Pctablen, Pctabcap uint32 - Pclntable, Pclntablelen, Pclntablecap uint32 - Ftab, Ftablen, Ftabcap uint32 - Findfunctab uint32 - Minpc, Maxpc uint32 - - Text, Etext uint32 - Noptrdata, Enoptrdata uint32 - Data, Edata uint32 - Bss, Ebss uint32 - Noptrbss, Enoptrbss uint32 - End, Gcdata, Gcbss uint32 - Types, Etypes uint32 - RData uint32 - GoFunc uint32 - - Textsectmap, Textsectmaplen, Textsectmapcap uint32 - Typelinks, Typelinkslen, Typelinkscap uint32 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint32 - - Ptab, Ptablen, Ptabcap uint32 - - Pluginpath, Pluginpathlen uint32 - Pkghashes, Pkghasheslen, Pkghashescap uint32 - - Modulename, Modulenamelen uint32 - Modulehashes, Modulehasheslen, Modulehashescap uint32 - - /* These fields we are not planning to use so skipping the parsing of them. - - hasmain uint8 // 1 if module contains the main function, 0 otherwise - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - bad bool // module failed to load and should be ignored - - next *moduledata - */ -} - -// Moduledata structure for Go 1.16 to 1.17 - -type moduledata1664 struct { - PcHeader uint64 - Funcnametab, Funcnametablen, Funcnametabcap uint64 - Cutab, Cutablen, Cutabcap uint64 - Filetab, Filetablen, Filetabcap uint64 - Pctab, Pctablen, Pctabcap uint64 - Pclntable, Pclntablelen, Pclntablecap uint64 - Ftab, Ftablen, Ftabcap uint64 - Findfunctab uint64 - Minpc, Maxpc uint64 - - Text, Etext uint64 - Noptrdata, Enoptrdata uint64 - Data, Edata uint64 - Bss, Ebss uint64 - Noptrbss, Enoptrbss uint64 - End, Gcdata, Gcbss uint64 - Types, Etypes uint64 - - Textsectmap, Textsectmaplen, Textsectmapcap uint64 - Typelinks, Typelinkslen, Typelinkscap uint64 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint64 - - Ptab, Ptablen, Ptabcap uint64 - - Pluginpath, Pluginpathlen uint64 - Pkghashes, Pkghasheslen, Pkghashescap uint64 - - Modulename, Modulenamelen uint64 - Modulehashes, Modulehasheslen, Modulehashescap uint64 - - /* These fields we are not planning to use so skipping the parsing of them. - - hasmain uint8 // 1 if module contains the main function, 0 otherwise - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - bad bool // module failed to load and should be ignored - - next *moduledata - */ -} - -type moduledata1632 struct { - PcHeader uint32 - Funcnametab, Funcnametablen, Funcnametabcap uint32 - Cutab, Cutablen, Cutabcap uint32 - Filetab, Filetablen, Filetabcap uint32 - Pctab, Pctablen, Pctabcap uint32 - Pclntable, Pclntablelen, Pclntablecap uint32 - Ftab, Ftablen, Ftabcap uint32 - Findfunctab uint32 - Minpc, Maxpc uint32 - - Text, Etext uint32 - Noptrdata, Enoptrdata uint32 - Data, Edata uint32 - Bss, Ebss uint32 - Noptrbss, Enoptrbss uint32 - End, Gcdata, Gcbss uint32 - Types, Etypes uint32 - - Textsectmap, Textsectmaplen, Textsectmapcap uint32 - Typelinks, Typelinkslen, Typelinkscap uint32 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint32 - - Ptab, Ptablen, Ptabcap uint32 - - Pluginpath, Pluginpathlen uint32 - Pkghashes, Pkghasheslen, Pkghashescap uint32 - - Modulename, Modulenamelen uint32 - Modulehashes, Modulehasheslen, Modulehashescap uint32 - - /* These fields we are not planning to use so skipping the parsing of them. - - hasmain uint8 // 1 if module contains the main function, 0 otherwise - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - bad bool // module failed to load and should be ignored - - next *moduledata - */ -} - -// Moduledata structure for Go 1.8 to 1.15 - -type moduledata864 struct { - Pclntable, Pclntablelen, Pclntablecap uint64 - Ftab, Ftablen, Ftabcap uint64 - Filetab, Filetablen, Filetabcap uint64 - Findfunctab uint64 - Minpc, Maxpc uint64 - - Text, Etext uint64 - Noptrdata, Enoptrdata uint64 - Data, Edata uint64 - Bss, Ebss uint64 - Noptrbss, Enoptrbss uint64 - End, Gcdata, Gcbss uint64 - Types, Etypes uint64 - - Textsectmap, Textsectmaplen, Textsectmapcap uint64 - Typelinks, Typelinkslen, Typelinkscap uint64 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint64 - - Ptab, Ptablen, Ptabcap uint64 - - Pluginpath, Pluginpathlen uint64 - Pkghashes, Pkghasheslen, Pkghashescap uint64 - - Modulename, Modulenamelen uint64 - Modulehashes, Modulehasheslen, Modulehashescap uint64 - - /* These fields we are not planning to use so skipping the parsing of them. - - hasmain uint8 // 1 if module contains the main function, 0 otherwise - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - bad bool // module failed to load and should be ignored - - next *moduledata - */ -} - -type moduledata832 struct { - Pclntable, Pclntablelen, Pclntablecap uint32 - Ftab, Ftablen, Ftabcap uint32 - Filetab, Filetablen, Filetabcap uint32 - Findfunctab uint32 - Minpc, Maxpc uint32 - - Text, Etext uint32 - Noptrdata, Enoptrdata uint32 - Data, Edata uint32 - Bss, Ebss uint32 - Noptrbss, Enoptrbss uint32 - End, Gcdata, Gcbss uint32 - Types, Etypes uint32 - - Textsectmap, Textsectmaplen, Textsectmapcap uint32 - Typelinks, Typelinkslen, Typelinkscap uint32 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint32 - - Ptab, Ptablen, Ptabcap uint32 - - Pluginpath, Pluginpathlen uint32 - Pkghashes, Pkghasheslen, Pkghashescap uint32 - - Modulename, Modulenamelen uint32 - Modulehashes, Modulehasheslen, Modulehashescap uint32 - - /* These fields we are not planning to use so skipping the parsing of them. - - hasmain uint8 // 1 if module contains the main function, 0 otherwise - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - bad bool // module failed to load and should be ignored - - next *moduledata - */ -} - -// Moduledata structure for Go 1.7 - -type moduledata764 struct { - Pclntable, Pclntablelen, Pclntablecap uint64 - Ftab, Ftablen, Ftabcap uint64 - Filetab, Filetablen, Filetabcap uint64 - Findfunctab uint64 - Minpc, Maxpc uint64 - - Text, Etext uint64 - Noptrdata, Enoptrdata uint64 - Data, Edata uint64 - Bss, Ebss uint64 - Noptrbss, Enoptrbss uint64 - End, Gcdata, Gcbss uint64 - Types, Etypes uint64 - - Typelinks, Typelinkslen, Typelinkscap uint64 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint64 - - Modulename, Modulenamelen uint64 - Modulehashes, Modulehasheslen, Modulehashescap uint64 - - /* These fields we are not planning to use so skipping the parsing of them. - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - next *moduledata - */ -} - -type moduledata732 struct { - Pclntable, Pclntablelen, Pclntablecap uint32 - Ftab, Ftablen, Ftabcap uint32 - Filetab, Filetablen, Filetabcap uint32 - Findfunctab uint32 - Minpc, Maxpc uint32 - - Text, Etext uint32 - Noptrdata, Enoptrdata uint32 - Data, Edata uint32 - Bss, Ebss uint32 - Noptrbss, Enoptrbss uint32 - End, Gcdata, Gcbss uint32 - Types, Etypes uint32 - - Typelinks, Typelinkslen, Typelinkscap uint32 // offsets from types - Itablinks, Itablinkslen, Itablinkscap uint32 - - Modulename, Modulenamelen uint32 - Modulehashes, Modulehasheslen, Modulehashescap uint32 - - /* These fields we are not planning to use so skipping the parsing of them. - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - next *moduledata - */ -} - -// Moduledata structure for Go 1.5 to 1.6 - -type moduledata564 struct { - Pclntable, Pclntablelen, Pclntablecap uint64 - Ftab, Ftablen, Ftabcap uint64 - Filetab, Filetablen, Filetabcap uint64 - Findfunctab uint64 - Minpc, Maxpc uint64 - - Text, Etext uint64 - Noptrdata, Enoptrdata uint64 - Data, Edata uint64 - Bss, Ebss uint64 - Noptrbss, Enoptrbss uint64 - End, Gcdata, Gcbss uint64 - - Typelinks, Typelinkslen, Typelinkscap uint64 - - Modulename, Modulenamelen uint64 - Modulehashes, Modulehasheslen, Modulehashescap uint64 - - /* These fields we are not planning to use so skipping the parsing of them. - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - next *moduledata - */ -} - -type moduledata532 struct { - Pclntable, Pclntablelen, Pclntablecap uint32 - Ftab, Ftablen, Ftabcap uint32 - Filetab, Filetablen, Filetabcap uint32 - Findfunctab uint32 - Minpc, Maxpc uint32 - - Text, Etext uint32 - Noptrdata, Enoptrdata uint32 - Data, Edata uint32 - Bss, Ebss uint32 - Noptrbss, Enoptrbss uint32 - End, Gcdata, Gcbss uint32 - - Typelinks, Typelinkslen, Typelinkscap uint32 - - Modulename, Modulenamelen uint32 - Modulehashes, Modulehasheslen, Modulehashescap uint32 - - /* These fields we are not planning to use so skipping the parsing of them. - - gcdatamask, gcbssmask bitvector - - typemap map[typeOff]*_type // offset to *_rtype in previous module - - next *moduledata - */ +type modulable interface { + toModuledata() moduledata } diff --git a/moduledata_gen.go b/moduledata_gen.go new file mode 100644 index 0000000..dff5498 --- /dev/null +++ b/moduledata_gen.go @@ -0,0 +1,662 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2023 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by go generate; DO NOT EDIT. + +package gore + +type moduledata2064 struct { + PcHeader uint64 + Funcnametab, Funcnametablen, Funcnametabcap uint64 + Cutab, Cutablen, Cutabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Pctab, Pctablen, Pctabcap uint64 + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + Covctrs uint64 + Ecovctrs uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Rodata uint64 + Gofunc uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 +} + +func (md moduledata2064) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata2032 struct { + PcHeader uint32 + Funcnametab, Funcnametablen, Funcnametabcap uint32 + Cutab, Cutablen, Cutabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Pctab, Pctablen, Pctabcap uint32 + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + Covctrs uint32 + Ecovctrs uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Rodata uint32 + Gofunc uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 +} + +func (md moduledata2032) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata1864 struct { + PcHeader uint64 + Funcnametab, Funcnametablen, Funcnametabcap uint64 + Cutab, Cutablen, Cutabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Pctab, Pctablen, Pctabcap uint64 + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Rodata uint64 + Gofunc uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 +} + +func (md moduledata1864) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata1832 struct { + PcHeader uint32 + Funcnametab, Funcnametablen, Funcnametabcap uint32 + Cutab, Cutablen, Cutabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Pctab, Pctablen, Pctabcap uint32 + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Rodata uint32 + Gofunc uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 +} + +func (md moduledata1832) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata1664 struct { + PcHeader uint64 + Funcnametab, Funcnametablen, Funcnametabcap uint64 + Cutab, Cutablen, Cutabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Pctab, Pctablen, Pctabcap uint64 + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 +} + +func (md moduledata1664) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata1632 struct { + PcHeader uint32 + Funcnametab, Funcnametablen, Funcnametabcap uint32 + Cutab, Cutablen, Cutabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Pctab, Pctablen, Pctabcap uint32 + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 +} + +func (md moduledata1632) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata864 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 +} + +func (md moduledata864) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata832 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 +} + +func (md moduledata832) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata764 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 +} + +func (md moduledata764) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata732 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 +} + +func (md moduledata732) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata564 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 +} + +func (md moduledata564) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata532 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 +} + +func (md moduledata532) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} From 41faa4bfd55c9d087a52ba18db5c16e8f04d24f6 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Thu, 1 Feb 2024 03:06:10 +0800 Subject: [PATCH 02/12] refactor: rewrite generate code --- gen.go | 435 ++++++++++++++++++++-- gen_moduledata.go | 331 ----------------- goversion.go | 2 + moduledata.go | 2 +- package.go | 2 +- stdpkg_gen.go | 922 +++++++++++++++++++++++----------------------- 6 files changed, 860 insertions(+), 834 deletions(-) delete mode 100644 gen_moduledata.go diff --git a/gen.go b/gen.go index 7cd9dc3..879e63b 100644 --- a/gen.go +++ b/gen.go @@ -15,8 +15,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -//go:build ignore -// +build ignore +//go:build gore_generate +// +build gore_generate // This program generates stdpkgs_gen.go and goversion_gen.go. It can be invoked by running // go generate @@ -30,10 +30,12 @@ import ( "errors" "fmt" "go/format" + "golang.org/x/mod/semver" "io" "net/http" "os" "path/filepath" + "reflect" "strings" "text/template" "time" @@ -99,6 +101,30 @@ var goversions = map[string]*GoVersion{ } `)) +const moduleDataHeader = ` +// This file is part of GoRE. +// +// Copyright (C) 2019-2023 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by go generate; DO NOT EDIT. + +package gore + +` + var client = &http.Client{} var authRequest func(*http.Request) @@ -135,6 +161,7 @@ const ( commitRequestURLFormatStr = "https://api.github.com/repos/golang/go/git/commits/%s" outputFile = "stdpkg_gen.go" goversionOutputFile = "goversion_gen.go" + moduleDataOutputFile = "moduledata_gen.go" ) var ( @@ -223,7 +250,7 @@ func writeOnDemand(new []byte, target string) { } } -func processGoVersions() { +func generateGoVersions() { tags := make([]*tagResp, 0) // Fetch all tags @@ -238,13 +265,13 @@ func processGoVersions() { resp, err := client.Do(req) if err != nil { fmt.Println("Error when fetching tags:", err.Error()) - resp.Body.Close() + _ = resp.Body.Close() continue } next := getNextPageURL(resp) *requestURL = next body, err := io.ReadAll(resp.Body) - resp.Body.Close() + _ = resp.Body.Close() if err != nil { fmt.Println("Error when ready response body:", err) continue @@ -265,7 +292,9 @@ func processGoVersions() { fmt.Println("Error when opening goversions.csv:", err) return } - defer f.Close() + defer func(f *os.File) { + _ = f.Close() + }(f) knownVersions, err := getStoredGoversions(f) if err != nil { fmt.Println("Error when getting stored go versions:", err) @@ -283,7 +312,7 @@ func processGoVersions() { continue } if v, known := knownVersions[tag.Name]; known { - fmt.Fprintf(f, "%s,%s,%s\n", v.Name, v.Sha, v.Date) + _, _ = fmt.Fprintf(f, "%s,%s,%s\n", v.Name, v.Sha, v.Date) continue } @@ -292,11 +321,11 @@ func processGoVersions() { resp, err := client.Do(req) if err != nil { fmt.Println("Error when fetching commit info:", err) - resp.Body.Close() + _ = resp.Body.Close() continue } body, err := io.ReadAll(resp.Body) - resp.Body.Close() + _ = resp.Body.Close() var commit commitLong err = json.Unmarshal(body, &commit) @@ -304,7 +333,7 @@ func processGoVersions() { fmt.Println("Error when parsing commit json:", err) continue } - fmt.Fprintf(f, "%s,%s,%s\n", tag.Name, commit.Sha, commit.Committer.Date) + _, _ = fmt.Fprintf(f, "%s,%s,%s\n", tag.Name, commit.Sha, commit.Committer.Date) fmt.Println("New tag found:", tag.Name) knownVersions[tag.Name] = &goversion{Name: tag.Name, Sha: commit.Sha, Date: commit.Committer.Date} } @@ -378,40 +407,359 @@ func getNextPageURL(r *http.Response) string { return "" } -func main() { - processGoVersions() +func skipPath(path string) bool { + for _, exclude := range excludedPaths { + if strings.HasPrefix(path, exclude) { + return true + } + } + return false +} - resp, err := client.Get(fmt.Sprintf(requestURLFormatStr, "master")) - if err != nil { - fmt.Println("Error when fetching go src data:", err) +func typeDef(b *bytes.Buffer, st reflect.Type, bits int) { + typeName := "uint64" + if bits == 32 { + typeName = "uint32" + } + + _, _ = fmt.Fprintf(b, "type %s%d struct {\n", st.Name(), bits) + + for i := 0; i < st.NumField(); i++ { + field := st.Field(i) + fieldName := strings.ToUpper(field.Name[:1]) + field.Name[1:] + t := field.Type.Kind() + switch t { + case reflect.Uintptr: + _, _ = fmt.Fprintf(b, "%s %s\n", fieldName, typeName) + case reflect.String: + _, _ = fmt.Fprintf(b, "%s, %[1]slen %s\n", fieldName, typeName) + case reflect.Pointer: + _, _ = fmt.Fprintf(b, "%s %s\n", fieldName, typeName) + case reflect.Slice: + _, _ = fmt.Fprintf(b, "%s, %[1]slen, %[1]scap %s\n", fieldName, typeName) + + default: + panic(fmt.Sprintf("unhandled type: %+v", t)) + } + } + + _, _ = fmt.Fprint(b, "}\n\n") +} + +func toModuledata(b *bytes.Buffer, st reflect.Type, bits int) { + _, _ = fmt.Fprintf(b, "func (md %s%d) toModuledata() moduledata {\n", st.Name(), bits) + _, _ = fmt.Fprint(b, "return moduledata{\n") + + for _, names := range [][2]string{ + {"Text", "Text"}, + {"NoPtrData", "Noptrdata"}, + {"Data", "Data"}, + {"Bss", "Bss"}, + {"NoPtrBss", "Noptrbss"}, + {"Types", "Types"}, + } { + modFieldE(b, st, bits, names[0], names[1]) + } + + for _, names := range [][2]string{ + {"Typelink", "Typelinks"}, + {"ITabLink", "Itablinks"}, + {"FuncTab", "Ftab"}, + {"PCLNTab", "Pclntable"}, + } { + modFieldLen(b, st, bits, names[0], names[1]) + } + + _, _ = fmt.Fprint(b, "}\n}\n\n") +} + +func modFieldE(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { + endName := "E" + strings.ToLower(parsedName) + if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { return } - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - if err != nil { - fmt.Println("Error when reading response body:", err) + if bits == 32 { + _, _ = fmt.Fprintf(b, "%sAddr: uint64(md.%[3]s),\n%[1]sLen: uint64(md.%s - md.%s),\n", modName, endName, parsedName) + } else { + _, _ = fmt.Fprintf(b, "%sAddr: md.%[3]s,\n%[1]sLen: md.%s - md.%s,\n", modName, endName, parsedName) + } +} + +func modFieldLen(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { + lenName := parsedName + "len" + if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { return } - var master ghResp - err = json.Unmarshal(body, &master) + if bits == 32 { + _, _ = fmt.Fprintf(b, "%sAddr: uint64(md.%s),\n%[1]sLen: uint64(md.%[3]s),\n", modName, parsedName, lenName) + } else { + _, _ = fmt.Fprintf(b, "%sAddr: md.%s,\n%[1]sLen: md.%[3]s,\n", modName, parsedName, lenName) + } +} + +func generateModuleData() { + b := &bytes.Buffer{} + b.WriteString(moduleDataHeader) + + for _, iface := range []any{ + moduledata20{}, + moduledata18{}, + moduledata16{}, + moduledata8{}, + moduledata7{}, + moduledata5{}, + } { + o := reflect.TypeOf(iface) + typeDef(b, o, 64) + toModuledata(b, o, 64) + typeDef(b, o, 32) + toModuledata(b, o, 32) + } + + out, err := format.Source(b.Bytes()) + if err != nil { + panic(err) + } + + err = os.WriteFile(moduleDataOutputFile, out, 0o666) if err != nil { - fmt.Println("Error when decoding the response body:", err) - return + panic(err) } - var stdPkgs []string - for _, tree := range master.Trees { - if tree.Gittype != "tree" { - continue +} + +/* + Internal module structures from Go's runtime. + TODO: auto extract from golang source runtime package. +*/ + +// Moduledata structure for Go 1.20 and newer (at least up to the last field covered here) + +type moduledata20 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + covctrs, ecovctrs uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + rodata uintptr + gofunc uintptr // go.func.* + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.18 and Go 1.19 + +type moduledata18 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + rodata uintptr + gofunc uintptr // go.func.* + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.16 to 1.17 + +type moduledata16 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.8 to 1.15 + +type moduledata8 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.7 + +type moduledata7 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.5 to 1.6 + +type moduledata5 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + + typelinks []*_type +} + +// dummy definitions +type initTask struct{} +type pcHeader struct{} +type functab struct{} +type textsect struct{} +type itab struct{} +type ptabEntry struct{} +type modulehash struct{} +type _type struct{} + +func generateStdPkgs() { + collect := func(ver string) []string { + resp, err := client.Get(fmt.Sprintf(requestURLFormatStr, "master")) + if err != nil { + fmt.Println("Error when fetching go src data:", err) + return nil } - if !strings.HasPrefix(tree.Path, "src") || skipPath(tree.Path) { - continue + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) + body, err := io.ReadAll(resp.Body) + if err != nil { + fmt.Println("Error when reading response body:", err) + return nil } - // Skip src folder. - if tree.Path == "src" { - continue + var master ghResp + err = json.Unmarshal(body, &master) + if err != nil { + fmt.Println("Error when decoding the response body:", err) + return nil } - // Strip "src/" and add to the list. - stdPkgs = append(stdPkgs, strings.TrimPrefix(tree.Path, "src/")) + var stdPkgs []string + for _, tree := range master.Trees { + if tree.Gittype != "tree" { + continue + } + if !strings.HasPrefix(tree.Path, "src") || skipPath(tree.Path) { + continue + } + // Skip src folder. + if tree.Path == "src" { + continue + } + // Strip "src/" and add to the list. + stdPkgs = append(stdPkgs, strings.TrimPrefix(tree.Path, "src/")) + } + + return stdPkgs + } + + f, err := os.OpenFile(filepath.Join("resources", "goversions.csv"), os.O_CREATE|os.O_RDWR, 0664) + if err != nil { + fmt.Println("Error when opening goversions.csv:", err) + return + } + defer func(f *os.File) { + _ = f.Close() + }(f) + knownVersions, err := getStoredGoversions(f) + + branchs := map[string]struct{}{} + for ver := range knownVersions { + rawver := "v" + strings.TrimPrefix(ver, "go") + sver := semver.MajorMinor(rawver) + if sver != "" { + sver = "go" + strings.TrimPrefix(sver, "v") + branchs["release-branch."+sver] = struct{}{} + } + } + + stdpkgsSet := map[string]struct{}{} + + for branch := range branchs { + fmt.Println("Fetching std pkgs for branch:", branch) + pkgs := collect(branch) + for _, pkg := range pkgs { + stdpkgsSet[pkg] = struct{}{} + } + } + + stdPkgs := make([]string, 0, len(stdpkgsSet)) + for pkg := range stdpkgsSet { + stdPkgs = append(stdPkgs, pkg) } // Generate the code. @@ -432,11 +780,18 @@ func main() { writeOnDemand(buf.Bytes(), outputFile) } -func skipPath(path string) bool { - for _, exclude := range excludedPaths { - if strings.HasPrefix(path, exclude) { - return true - } +func main() { + if len(os.Args) != 2 { + fmt.Println("go run gen.go [stdpkgs|goversion|moduledata]") + return + } + + switch os.Args[1] { + case "stdpkgs": + generateStdPkgs() + case "goversion": + generateGoVersions() + case "moduledata": + generateModuleData() } - return false } diff --git a/gen_moduledata.go b/gen_moduledata.go deleted file mode 100644 index 5cf4eed..0000000 --- a/gen_moduledata.go +++ /dev/null @@ -1,331 +0,0 @@ -// This file is part of GoRE. -// -// Copyright (C) 2019-2023 GoRE Authors -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -//go:build ignore -// +build ignore - -// This program generates stdpkgs_gen.go and goversion_gen.go. It can be invoked by running -// go generate -package main - -import ( - "bytes" - "fmt" - "go/format" - "os" - "reflect" - "strings" -) - -const header = ` -// This file is part of GoRE. -// -// Copyright (C) 2019-2023 GoRE Authors -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Code generated by go generate; DO NOT EDIT. - -package gore - -` - -func typeDef(b *bytes.Buffer, st reflect.Type, bits int) { - typeName := "uint64" - if bits == 32 { - typeName = "uint32" - } - - fmt.Fprintf(b, "type %s%d struct {\n", st.Name(), bits) - - for i := 0; i < st.NumField(); i++ { - field := st.Field(i) - fieldName := strings.ToUpper(field.Name[:1]) + field.Name[1:] - t := field.Type.Kind() - switch t { - case reflect.Uintptr: - fmt.Fprintf(b, "%s %s\n", fieldName, typeName) - case reflect.String: - fmt.Fprintf(b, "%s, %[1]slen %s\n", fieldName, typeName) - case reflect.Pointer: - fmt.Fprintf(b, "%s %s\n", fieldName, typeName) - case reflect.Slice: - fmt.Fprintf(b, "%s, %[1]slen, %[1]scap %s\n", fieldName, typeName) - - default: - panic(fmt.Sprintf("unhandled type: %+v", t)) - } - } - - fmt.Fprint(b, "}\n\n") -} - -func toModuledata(b *bytes.Buffer, st reflect.Type, bits int) { - fmt.Fprintf(b, "func (md %s%d) toModuledata() moduledata {\n", st.Name(), bits) - fmt.Fprint(b, "return moduledata{\n") - - for _, names := range [][2]string{ - {"Text", "Text"}, - {"NoPtrData", "Noptrdata"}, - {"Data", "Data"}, - {"Bss", "Bss"}, - {"NoPtrBss", "Noptrbss"}, - {"Types", "Types"}, - } { - modFieldE(b, st, bits, names[0], names[1]) - } - - for _, names := range [][2]string{ - {"Typelink", "Typelinks"}, - {"ITabLink", "Itablinks"}, - {"FuncTab", "Ftab"}, - {"PCLNTab", "Pclntable"}, - } { - modFieldLen(b, st, bits, names[0], names[1]) - } - - fmt.Fprint(b, "}\n}\n\n") -} - -func modFieldE(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { - endName := "E" + strings.ToLower(parsedName) - if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { - return - } - if bits == 32 { - fmt.Fprintf(b, "%sAddr: uint64(md.%[3]s),\n%[1]sLen: uint64(md.%s - md.%s),\n", modName, endName, parsedName) - } else { - fmt.Fprintf(b, "%sAddr: md.%[3]s,\n%[1]sLen: md.%s - md.%s,\n", modName, endName, parsedName) - } -} - -func modFieldLen(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { - lenName := parsedName + "len" - if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { - return - } - if bits == 32 { - fmt.Fprintf(b, "%sAddr: uint64(md.%s),\n%[1]sLen: uint64(md.%[3]s),\n", modName, parsedName, lenName) - } else { - fmt.Fprintf(b, "%sAddr: md.%s,\n%[1]sLen: md.%[3]s,\n", modName, parsedName, lenName) - } -} - -func main() { - - b := &bytes.Buffer{} - check1(b.WriteString(header)) - - for _, iface := range []any{ - moduledata20{}, - moduledata18{}, - moduledata16{}, - moduledata8{}, - moduledata7{}, - moduledata5{}, - } { - o := reflect.TypeOf(iface) - typeDef(b, o, 64) - toModuledata(b, o, 64) - typeDef(b, o, 32) - toModuledata(b, o, 32) - } - - fmted := check1(format.Source(b.Bytes())) - check(os.WriteFile("moduledata_gen.go", fmted, 0o666)) -} - -func check(err error) { - if err != nil { - panic(err) - } -} - -func check1[T any](arg1 T, err error) T { - check(err) - return arg1 -} - -/* - Internal module structures from Go's runtime. -*/ - -// Moduledata structure for Go 1.20 and newer (at least up to the last field covered here) - -type moduledata20 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - covctrs, ecovctrs uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - rodata uintptr - gofunc uintptr // go.func.* - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.18 and Go 1.19 - -type moduledata18 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - rodata uintptr - gofunc uintptr // go.func.* - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.16 to 1.17 - -type moduledata16 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.8 to 1.15 - -type moduledata8 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.7 - -type moduledata7 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.5 to 1.6 - -type moduledata5 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - - typelinks []*_type -} - -// dummy definitions -type initTask struct{} -type pcHeader struct{} -type functab struct{} -type textsect struct{} -type itab struct{} -type ptabEntry struct{} -type modulehash struct{} -type _type struct{} diff --git a/goversion.go b/goversion.go index befff42..c2d1779 100644 --- a/goversion.go +++ b/goversion.go @@ -15,6 +15,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +//go:generate go run gen.go goversion + package gore import ( diff --git a/moduledata.go b/moduledata.go index bf50235..61cd80e 100644 --- a/moduledata.go +++ b/moduledata.go @@ -17,7 +17,7 @@ package gore -//go:generate go run gen_moduledata.go +//go:generate go run gen.go moduledata import ( "bytes" diff --git a/package.go b/package.go index 2264381..e064e37 100644 --- a/package.go +++ b/package.go @@ -25,7 +25,7 @@ import ( "strings" ) -//go:generate go run gen.go +//go:generate go run gen.go stdpkgs var ( knownRepos = []string{"golang.org", "github.com", "gitlab.com"} diff --git a/stdpkg_gen.go b/stdpkg_gen.go index aa41d7d..56b60e7 100644 --- a/stdpkg_gen.go +++ b/stdpkg_gen.go @@ -17,487 +17,487 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated at -// 2024-01-25 19:24:26.1768459 +0000 UTC +// 2024-01-31 19:04:26.4224606 +0000 UTC package gore var stdPkgs = map[string]struct{}{ - "archive": {}, - "archive/tar": {}, - "archive/tar/testdata": {}, - "archive/zip": {}, - "archive/zip/testdata": {}, - "arena": {}, - "bufio": {}, - "builtin": {}, - "bytes": {}, - "cmp": {}, - "compress": {}, - "compress/bzip2": {}, - "compress/bzip2/testdata": {}, - "compress/flate": {}, - "compress/flate/testdata": {}, - "compress/gzip": {}, - "compress/gzip/testdata": {}, - "compress/lzw": {}, - "compress/testdata": {}, - "compress/zlib": {}, - "container": {}, - "container/heap": {}, - "container/list": {}, - "container/ring": {}, - "context": {}, - "crypto": {}, - "crypto/aes": {}, - "crypto/boring": {}, - "crypto/cipher": {}, - "crypto/des": {}, - "crypto/dsa": {}, - "crypto/ecdh": {}, - "crypto/ecdsa": {}, - "crypto/ecdsa/testdata": {}, - "crypto/ed25519": {}, - "crypto/ed25519/testdata": {}, - "crypto/elliptic": {}, - "crypto/hmac": {}, - "crypto/internal": {}, - "crypto/internal/alias": {}, - "crypto/internal/bigmod": {}, - "crypto/internal/bigmod/_asm": {}, - "crypto/internal/boring": {}, - "crypto/internal/boring/bbig": {}, - "crypto/internal/boring/bcache": {}, - "crypto/internal/boring/fipstls": {}, - "crypto/internal/boring/sig": {}, - "crypto/internal/boring/syso": {}, - "crypto/internal/edwards25519": {}, - "crypto/internal/edwards25519/field": {}, - "crypto/internal/edwards25519/field/_asm": {}, - "crypto/internal/nistec": {}, - "crypto/internal/nistec/fiat": {}, - "crypto/internal/randutil": {}, - "crypto/md5": {}, - "crypto/rand": {}, - "crypto/rc4": {}, - "crypto/rsa": {}, - "crypto/rsa/testdata": {}, - "crypto/sha1": {}, - "crypto/sha256": {}, - "crypto/sha512": {}, - "crypto/subtle": {}, - "crypto/tls": {}, - "crypto/tls/fipsonly": {}, - "crypto/tls/testdata": {}, - "crypto/x509": {}, - "crypto/x509/internal": {}, - "crypto/x509/internal/macos": {}, - "crypto/x509/pkix": {}, - "crypto/x509/testdata": {}, - "database": {}, - "database/sql": {}, - "database/sql/driver": {}, - "debug": {}, - "debug/buildinfo": {}, - "debug/dwarf": {}, - "debug/dwarf/testdata": {}, - "debug/elf": {}, - "debug/elf/testdata": {}, - "debug/gosym": {}, - "debug/gosym/testdata": {}, - "debug/macho": {}, - "debug/macho/testdata": {}, - "debug/pe": {}, - "debug/pe/testdata": {}, - "debug/plan9obj": {}, - "debug/plan9obj/testdata": {}, - "embed": {}, - "embed/internal": {}, - "embed/internal/embedtest": {}, - "embed/internal/embedtest/testdata": {}, - "embed/internal/embedtest/testdata/-not-hidden": {}, - "embed/internal/embedtest/testdata/.hidden": {}, + "runtime/testdata/testwinlibsignal": {}, + "crypto/elliptic": {}, + "crypto/rsa/testdata": {}, + "crypto/sha1": {}, + "crypto/sha256": {}, + "encoding/csv": {}, + "go/importer": {}, + "net/http/httptrace": {}, + "testing/internal/testdeps": {}, + "compress/gzip": {}, "embed/internal/embedtest/testdata/.hidden/.more": {}, - "embed/internal/embedtest/testdata/.hidden/_more": {}, - "embed/internal/embedtest/testdata/.hidden/more": {}, - "embed/internal/embedtest/testdata/_hidden": {}, - "embed/internal/embedtest/testdata/i": {}, - "embed/internal/embedtest/testdata/i/j": {}, - "embed/internal/embedtest/testdata/i/j/k": {}, - "encoding": {}, - "encoding/ascii85": {}, - "encoding/asn1": {}, - "encoding/base32": {}, - "encoding/base64": {}, - "encoding/binary": {}, - "encoding/csv": {}, - "encoding/gob": {}, - "encoding/hex": {}, - "encoding/json": {}, - "encoding/json/testdata": {}, - "encoding/pem": {}, - "encoding/xml": {}, - "errors": {}, - "expvar": {}, - "flag": {}, - "fmt": {}, - "go": {}, - "go/ast": {}, - "go/build": {}, - "go/build/constraint": {}, - "go/build/testdata": {}, - "go/build/testdata/alltags": {}, - "go/build/testdata/bads": {}, - "go/build/testdata/cgo_disabled": {}, - "go/build/testdata/directives": {}, - "go/build/testdata/doc": {}, - "go/build/testdata/empty": {}, - "go/build/testdata/multi": {}, - "go/build/testdata/non_source_tags": {}, - "go/build/testdata/other": {}, - "go/build/testdata/other/file": {}, - "go/build/testdata/withvendor": {}, - "go/build/testdata/withvendor/src": {}, - "go/build/testdata/withvendor/src/a": {}, - "go/build/testdata/withvendor/src/a/b": {}, - "go/build/testdata/withvendor/src/a/vendor": {}, - "go/build/testdata/withvendor/src/a/vendor/c": {}, - "go/build/testdata/withvendor/src/a/vendor/c/d": {}, - "go/constant": {}, - "go/doc": {}, - "go/doc/comment": {}, - "go/doc/comment/testdata": {}, - "go/doc/testdata": {}, - "go/doc/testdata/examples": {}, - "go/doc/testdata/pkgdoc": {}, - "go/format": {}, - "go/importer": {}, - "go/internal": {}, - "go/internal/gccgoimporter": {}, - "go/internal/gccgoimporter/testdata": {}, - "go/internal/gcimporter": {}, - "go/internal/gcimporter/testdata": {}, - "go/internal/gcimporter/testdata/versions": {}, - "go/internal/srcimporter": {}, - "go/internal/srcimporter/testdata": {}, - "go/internal/srcimporter/testdata/issue20855": {}, - "go/internal/srcimporter/testdata/issue23092": {}, + "encoding/base32": {}, + "internal/lazyregexp": {}, + "internal/trace/v2/testdata/cmd/gotraceraw": {}, + "net/http/httputil": {}, + "internal/testenv": {}, + "internal/trace/v2/raw": {}, + "os": {}, + "compress/bzip2": {}, + "debug/gosym": {}, + "go/token": {}, + "internal/trace/v2/testdata/fuzz": {}, + "os/user": {}, + "flag": {}, + "image/gif": {}, + "internal/fmtsort": {}, + "testing/quick": {}, + "archive/tar/testdata": {}, + "crypto/tls": {}, + "errors": {}, + "io/ioutil/testdata": {}, + "testing": {}, + "compress/flate/testdata": {}, + "go/internal/srcimporter/testdata/issue23092": {}, + "internal/testlog": {}, + "internal/trace/v2/testdata": {}, + "runtime/coverage/testdata/issue56006": {}, + "crypto/subtle": {}, + "net/http/fcgi": {}, + "runtime/trace": {}, + "crypto/ecdh": {}, + "crypto/internal/boring/fipstls": {}, + "embed/internal/embedtest": {}, + "container/list": {}, + "crypto/ed25519/testdata": {}, + "go/build/testdata/withvendor/src/a/b": {}, + "hash/adler32": {}, + "unicode/utf8": {}, + "arena": {}, + "crypto/tls/fipsonly": {}, + "go/build/testdata/multi": {}, + "go/build/testdata/withvendor": {}, + "go/parser": {}, + "image": {}, + "internal/obscuretestdata": {}, + "vendor/golang.org/x/text/unicode": {}, + "crypto/internal/edwards25519/field/_asm": {}, + "go/build/testdata/doc": {}, + "math/big": {}, + "encoding/asn1": {}, + "go/constant": {}, + "internal/coverage/encodecounter": {}, + "internal/coverage/stringtab": {}, + "internal/diff": {}, + "internal/sysinfo": {}, + "internal/testpty": {}, + "runtime/internal/atomic": {}, + "internal/saferio": {}, + "vendor/golang.org/x/crypto/internal/alias": {}, + "compress/lzw": {}, + "crypto/hmac": {}, + "crypto/x509": {}, + "internal/trace/v2/testdata/generators": {}, + "internal/types/testdata/check/importdecl1": {}, + "iter": {}, + "vendor/golang.org/x/net/http/httpguts": {}, + "internal/godebug": {}, + "runtime/internal": {}, + "internal/trace/v2/internal/testgen": {}, + "compress/gzip/testdata": {}, + "debug/elf": {}, + "debug/macho": {}, + "encoding/json/testdata": {}, "go/internal/srcimporter/testdata/issue24392": {}, - "go/internal/typeparams": {}, - "go/parser": {}, - "go/parser/testdata": {}, - "go/parser/testdata/goversion": {}, - "go/parser/testdata/issue42951": {}, - "go/parser/testdata/issue42951/not_a_file.go": {}, - "go/parser/testdata/resolution": {}, - "go/printer": {}, - "go/printer/testdata": {}, - "go/scanner": {}, - "go/token": {}, - "go/types": {}, - "go/types/testdata": {}, - "go/types/testdata/local": {}, - "go/version": {}, - "hash": {}, - "hash/adler32": {}, - "hash/crc32": {}, - "hash/crc64": {}, - "hash/fnv": {}, - "hash/maphash": {}, - "html": {}, - "html/template": {}, - "html/template/testdata": {}, - "image": {}, - "image/color": {}, - "image/color/palette": {}, - "image/draw": {}, - "image/gif": {}, - "image/internal": {}, - "image/internal/imageutil": {}, - "image/jpeg": {}, "image/png": {}, - "image/png/testdata": {}, - "image/png/testdata/pngsuite": {}, - "image/testdata": {}, - "index": {}, - "index/suffixarray": {}, - "internal": {}, - "internal/abi": {}, - "internal/abi/testdata": {}, - "internal/bisect": {}, - "internal/buildcfg": {}, - "internal/bytealg": {}, - "internal/cfg": {}, - "internal/chacha8rand": {}, - "internal/coverage": {}, - "internal/coverage/calloc": {}, - "internal/coverage/cformat": {}, - "internal/coverage/cmerge": {}, - "internal/coverage/decodecounter": {}, - "internal/coverage/decodemeta": {}, - "internal/coverage/encodecounter": {}, - "internal/coverage/encodemeta": {}, - "internal/coverage/pods": {}, - "internal/coverage/rtcov": {}, - "internal/coverage/slicereader": {}, - "internal/coverage/slicewriter": {}, - "internal/coverage/stringtab": {}, - "internal/coverage/test": {}, - "internal/coverage/uleb128": {}, - "internal/cpu": {}, - "internal/dag": {}, - "internal/diff": {}, - "internal/diff/testdata": {}, - "internal/fmtsort": {}, + "internal/syscall/unix": {}, + "internal/trace/v2/testdata/cmd/gotracevalidate": {}, + "internal/trace/v2/testdata/testprog": {}, + "internal/types/testdata/check": {}, + "runtime/debug/testdata/fuzz": {}, + "runtime/testdata/testwinlib": {}, + "runtime/testdata/testwinlibthrow": {}, + "crypto/sha512": {}, + "embed/internal/embedtest/testdata/i": {}, + "internal/zstd": {}, + "mime": {}, + "net/http/httptest": {}, + "text": {}, + "vendor/golang.org/x/crypto/internal": {}, + "vendor": {}, + "vendor/golang.org/x/crypto/chacha20": {}, + "encoding/pem": {}, "internal/fuzz": {}, - "internal/goarch": {}, - "internal/godebug": {}, - "internal/godebugs": {}, - "internal/goexperiment": {}, - "internal/goos": {}, - "internal/goroot": {}, - "internal/gover": {}, - "internal/goversion": {}, - "internal/intern": {}, - "internal/itoa": {}, - "internal/lazyregexp": {}, - "internal/lazytemplate": {}, - "internal/nettrace": {}, - "internal/obscuretestdata": {}, - "internal/oserror": {}, + "net/internal": {}, + "log": {}, + "crypto/x509/pkix": {}, + "html/template": {}, + "image/color/palette": {}, "internal/pkgbits": {}, - "internal/platform": {}, - "internal/poll": {}, - "internal/profile": {}, - "internal/race": {}, + "internal/types/testdata/check/importdecl0": {}, + "internal/types/testdata/examples": {}, + "internal/xcoff/testdata": {}, + "net/http/pprof/testdata": {}, + "vendor/golang.org/x/net/http2/hpack": {}, + "crypto/ecdsa": {}, + "runtime/testdata/testfds": {}, + "internal/abi/testdata": {}, + "runtime/race/internal": {}, + "runtime/testdata/testfaketime": {}, + "crypto/internal/boring/bcache": {}, + "embed/internal/embedtest/testdata": {}, + "internal/trace/traceviewer/static": {}, + "go/build/testdata/empty": {}, + "internal/trace/v2/event": {}, + "net/http/internal/ascii": {}, + "runtime/pprof/testdata/mappingtest": {}, + "testing/iotest": {}, + "vendor/golang.org/x/net/http2": {}, + "internal/syscall": {}, + "internal/types/errors": {}, + "vendor/golang.org/x/text/unicode/norm": {}, "internal/reflectlite": {}, - "internal/safefilepath": {}, - "internal/saferio": {}, + "expvar": {}, + "internal/trace/v2": {}, + "vendor/golang.org/x/net/idna": {}, + "crypto/ed25519": {}, + "encoding/ascii85": {}, + "hash/fnv": {}, + "internal/profile": {}, "internal/singleflight": {}, - "internal/syscall": {}, - "internal/syscall/execenv": {}, - "internal/syscall/unix": {}, - "internal/syscall/windows": {}, - "internal/syscall/windows/registry": {}, - "internal/syscall/windows/sysdll": {}, - "internal/sysinfo": {}, - "internal/testenv": {}, - "internal/testlog": {}, - "internal/testpty": {}, - "internal/trace": {}, - "internal/trace/testdata": {}, - "internal/trace/traceviewer": {}, + "sort": {}, + "go/parser/testdata/issue42951/not_a_file.go": {}, + "mime/testdata": {}, + "net/mail": {}, + "runtime/race": {}, + "testing/fstest": {}, + "go/internal": {}, "internal/trace/traceviewer/format": {}, - "internal/trace/traceviewer/static": {}, - "internal/trace/v2": {}, - "internal/trace/v2/event": {}, + "net/internal/cgotest": {}, + "archive": {}, + "compress/zlib": {}, "internal/trace/v2/event/go122": {}, - "internal/trace/v2/internal": {}, - "internal/trace/v2/internal/testgen": {}, + "log/slog/internal/buffer": {}, + "net/url": {}, + "regexp/syntax": {}, + "vendor/golang.org/x/net/dns": {}, + "go/internal/gcimporter": {}, + "context": {}, + "crypto/internal/boring/syso": {}, + "debug/elf/testdata": {}, + "internal/coverage/slicereader": {}, + "vendor/golang.org/x/crypto/internal/poly1305": {}, + "cmp": {}, + "go/parser/testdata/resolution": {}, + "go/printer": {}, + "internal/bytealg": {}, + "internal/dag": {}, + "internal/syscall/windows/sysdll": {}, + "archive/zip/testdata": {}, + "vendor/golang.org/x/net": {}, + "database": {}, + "embed/internal/embedtest/testdata/-not-hidden": {}, + "os/testdata/issue37161": {}, + "plugin": {}, + "regexp/testdata": {}, + "runtime/internal/math": {}, + "os/exec": {}, + "compress/flate": {}, + "crypto/internal/edwards25519/field": {}, + "go/doc/comment": {}, + "go/scanner": {}, + "log/slog/internal/benchmarks": {}, + "math/rand/v2": {}, + "mime/quotedprintable": {}, + "os/signal": {}, + "runtime/metrics": {}, + "vendor/golang.org/x/net/lif": {}, + "container/heap": {}, + "crypto/rand": {}, + "internal/goexperiment": {}, + "log/slog/internal/slogtest": {}, + "crypto/rsa": {}, + "internal/lazytemplate": {}, + "runtime/debug/testdata": {}, + "runtime/testdata/testprogcgo": {}, + "vendor/golang.org/x/crypto/cryptobyte": {}, + "hash/crc64": {}, + "embed": {}, + "fmt": {}, + "go/build/testdata/withvendor/src/a/vendor/c/d": {}, + "go/types/testdata": {}, + "index": {}, + "internal/buildcfg": {}, + "text/tabwriter": {}, + "net/smtp": {}, + "os/testdata/dirfs": {}, + "runtime/coverage/testdata/issue59563": {}, + "vendor/golang.org": {}, + "crypto/internal/nistec/fiat": {}, + "internal/race": {}, + "internal/syscall/windows/registry": {}, + "internal/trace/v2/internal": {}, + "net/http/testdata": {}, + "vendor/golang.org/x/net/http/httpproxy": {}, + "go/build/testdata/withvendor/src": {}, + "go/doc/testdata/examples": {}, + "runtime/testdata/testwinsignal": {}, + "syscall": {}, + "vendor/golang.org/x/net/http": {}, + "container": {}, + "debug/dwarf/testdata": {}, + "go/format": {}, + "crypto/tls/testdata": {}, + "encoding/base64": {}, + "internal/syscall/execenv": {}, + "net/http/pprof": {}, + "runtime/race/testdata": {}, + "text/template/parse": {}, + "go/parser/testdata/goversion": {}, + "internal/itoa": {}, + "runtime": {}, + "internal/types/testdata/spec": {}, + "maps": {}, + "runtime/pprof": {}, + "vendor/golang.org/x/sys/cpu": {}, + "container/ring": {}, + "internal/cpu": {}, + "internal/unsafeheader": {}, + "regexp": {}, + "crypto/internal/bigmod/_asm": {}, + "embed/internal/embedtest/testdata/i/j/k": {}, + "internal/goroot": {}, + "net/netip": {}, + "archive/tar": {}, + "math/cmplx": {}, + "debug/plan9obj": {}, + "go/doc": {}, + "internal/coverage/calloc": {}, + "runtime/testdata/testsuid": {}, + "internal/coverage/slicewriter": {}, + "internal/trace/v2/version": {}, + "vendor/golang.org/x/net/nettest": {}, + "go/build/testdata/alltags": {}, + "internal/goarch": {}, + "os/exec/internal": {}, + "crypto/internal/randutil": {}, + "encoding/gob": {}, + "html/template/testdata": {}, + "math": {}, + "net/internal/socktest": {}, + "bytes": {}, + "slices": {}, + "go/build/testdata/other/file": {}, + "go/internal/gcimporter/testdata/versions": {}, + "image/jpeg": {}, + "log/internal": {}, + "debug": {}, + "internal/safefilepath": {}, + "runtime/internal/wasitest/testdata": {}, + "unsafe": {}, + "vendor/golang.org/x/text/unicode/bidi": {}, + "compress": {}, + "image/png/testdata/pngsuite": {}, + "math/rand": {}, + "go/internal/gccgoimporter/testdata": {}, + "go/internal/srcimporter/testdata/issue20855": {}, + "internal/trace/v2/testdata/fuzz/FuzzReader": {}, + "unicode": {}, + "vendor/golang.org/x/text/secure/bidirule": {}, + "go/doc/testdata": {}, + "image/draw": {}, + "runtime/testdata/testwintls": {}, + "sync": {}, + "sync/atomic": {}, + "syscall/js": {}, + "text/template/testdata": {}, + "net/testdata": {}, + "vendor/golang.org/x": {}, + "vendor/golang.org/x/text/secure": {}, + "text/template": {}, + "go/build/constraint": {}, + "internal/types/testdata": {}, + "path": {}, + "crypto/internal/alias": {}, + "image/testdata": {}, + "internal/syscall/windows": {}, + "internal/trace/testdata": {}, + "net/http/internal/testcert": {}, + "vendor/golang.org/x/net/dns/dnsmessage": {}, + "internal/types": {}, + "go/build/testdata/withvendor/src/a": {}, + "image/color": {}, + "os/testdata": {}, + "vendor/golang.org/x/crypto": {}, + "debug/gosym/testdata": {}, + "debug/macho/testdata": {}, + "go/types/testdata/local": {}, + "internal/godebugs": {}, + "internal/txtar": {}, + "runtime/internal/startlinetest": {}, + "strconv": {}, + "embed/internal": {}, + "internal/coverage/decodemeta": {}, + "internal/coverage/encodemeta": {}, + "mime/multipart/testdata": {}, + "internal/abi": {}, + "internal/coverage/test": {}, + "crypto/cipher": {}, + "crypto/internal/nistec": {}, + "embed/internal/embedtest/testdata/.hidden/more": {}, + "go/parser/testdata/issue42951": {}, + "internal/coverage/cmerge": {}, "internal/trace/v2/internal/testgen/go122": {}, - "internal/trace/v2/raw": {}, - "internal/trace/v2/testdata": {}, + "vendor/golang.org/x/net/route": {}, + "encoding/binary": {}, + "go/build/testdata/withvendor/src/a/vendor": {}, + "internal/poll": {}, + "internal/types/testdata/fixedbugs": {}, + "compress/bzip2/testdata": {}, + "go/printer/testdata": {}, + "vendor/golang.org/x/text": {}, + "reflect": {}, + "crypto/md5": {}, + "database/sql/driver": {}, + "encoding": {}, + "encoding/xml": {}, + "go/doc/testdata/pkgdoc": {}, + "go/internal/gccgoimporter": {}, + "internal/coverage/pods": {}, + "hash/crc32": {}, + "internal/trace/v2/testtrace": {}, + "io": {}, + "runtime/cgo": {}, + "time": {}, + "crypto/internal/boring/sig": {}, + "embed/internal/embedtest/testdata/i/j": {}, + "internal/coverage": {}, + "runtime/testdata/testprogcgo/windows": {}, + "internal/cfg": {}, + "strings": {}, + "go/build/testdata/bads": {}, + "internal/intern": {}, "internal/trace/v2/testdata/cmd": {}, - "internal/trace/v2/testdata/cmd/gotraceraw": {}, - "internal/trace/v2/testdata/cmd/gotracevalidate": {}, - "internal/trace/v2/testdata/fuzz": {}, - "internal/trace/v2/testdata/fuzz/FuzzReader": {}, - "internal/trace/v2/testdata/generators": {}, - "internal/trace/v2/testdata/testprog": {}, "internal/trace/v2/testdata/tests": {}, - "internal/trace/v2/testtrace": {}, - "internal/trace/v2/version": {}, - "internal/txtar": {}, - "internal/types": {}, - "internal/types/errors": {}, - "internal/types/testdata": {}, - "internal/types/testdata/check": {}, "internal/types/testdata/check/decls2": {}, - "internal/types/testdata/check/importdecl0": {}, - "internal/types/testdata/check/importdecl1": {}, - "internal/types/testdata/check/issue25008": {}, - "internal/types/testdata/examples": {}, - "internal/types/testdata/fixedbugs": {}, - "internal/types/testdata/spec": {}, - "internal/unsafeheader": {}, - "internal/xcoff": {}, - "internal/xcoff/testdata": {}, - "internal/zstd": {}, - "internal/zstd/testdata": {}, - "io": {}, - "io/fs": {}, "io/ioutil": {}, - "io/ioutil/testdata": {}, - "iter": {}, - "log": {}, - "log/internal": {}, - "log/slog": {}, + "debug/pe": {}, + "image/png/testdata": {}, + "internal/trace/traceviewer": {}, + "bufio": {}, + "crypto/x509/testdata": {}, + "embed/internal/embedtest/testdata/.hidden": {}, + "debug/dwarf": {}, + "internal/coverage/cformat": {}, + "internal/goversion": {}, "log/slog/internal": {}, - "log/slog/internal/benchmarks": {}, - "log/slog/internal/buffer": {}, - "log/slog/internal/slogtest": {}, - "log/syslog": {}, - "maps": {}, - "math": {}, - "math/big": {}, - "math/bits": {}, - "math/cmplx": {}, - "math/rand": {}, - "math/rand/v2": {}, - "mime": {}, - "mime/multipart": {}, - "mime/multipart/testdata": {}, - "mime/quotedprintable": {}, - "mime/testdata": {}, - "net": {}, + "testdata": {}, + "crypto/des": {}, "net/http": {}, - "net/http/cgi": {}, - "net/http/cookiejar": {}, - "net/http/fcgi": {}, - "net/http/httptest": {}, - "net/http/httptrace": {}, - "net/http/httputil": {}, + "runtime/internal/sys": {}, + "runtime/race/internal/amd64v3": {}, + "embed/internal/embedtest/testdata/_hidden": {}, + "internal/diff/testdata": {}, + "internal/trace": {}, "net/http/internal": {}, - "net/http/internal/ascii": {}, - "net/http/internal/testcert": {}, - "net/http/pprof": {}, - "net/http/pprof/testdata": {}, - "net/http/testdata": {}, - "net/internal": {}, - "net/internal/cgotest": {}, - "net/internal/socktest": {}, - "net/mail": {}, - "net/netip": {}, - "net/rpc": {}, - "net/rpc/jsonrpc": {}, - "net/smtp": {}, - "net/testdata": {}, - "net/textproto": {}, - "net/url": {}, - "os": {}, - "os/exec": {}, - "os/exec/internal": {}, - "os/exec/internal/fdtest": {}, - "os/signal": {}, - "os/testdata": {}, - "os/testdata/dirfs": {}, - "os/testdata/dirfs/dir": {}, - "os/testdata/issue37161": {}, - "os/user": {}, - "path": {}, - "path/filepath": {}, - "plugin": {}, - "reflect": {}, - "reflect/internal": {}, - "reflect/internal/example1": {}, - "reflect/internal/example2": {}, - "regexp": {}, - "regexp/syntax": {}, - "regexp/testdata": {}, - "runtime": {}, - "runtime/asan": {}, - "runtime/cgo": {}, - "runtime/coverage": {}, - "runtime/coverage/testdata": {}, - "runtime/coverage/testdata/issue56006": {}, - "runtime/coverage/testdata/issue59563": {}, - "runtime/debug": {}, - "runtime/debug/testdata": {}, - "runtime/debug/testdata/fuzz": {}, "runtime/debug/testdata/fuzz/FuzzParseBuildInfoRoundTrip": {}, - "runtime/internal": {}, - "runtime/internal/atomic": {}, - "runtime/internal/math": {}, - "runtime/internal/startlinetest": {}, - "runtime/internal/sys": {}, - "runtime/internal/syscall": {}, - "runtime/internal/wasitest": {}, - "runtime/internal/wasitest/testdata": {}, - "runtime/metrics": {}, - "runtime/msan": {}, - "runtime/pprof": {}, - "runtime/pprof/testdata": {}, - "runtime/pprof/testdata/mappingtest": {}, - "runtime/race": {}, - "runtime/race/internal": {}, - "runtime/race/internal/amd64v1": {}, - "runtime/race/internal/amd64v3": {}, - "runtime/race/testdata": {}, - "runtime/testdata": {}, - "runtime/testdata/testexithooks": {}, - "runtime/testdata/testfaketime": {}, - "runtime/testdata/testfds": {}, - "runtime/testdata/testprog": {}, - "runtime/testdata/testprogcgo": {}, - "runtime/testdata/testprogcgo/windows": {}, - "runtime/testdata/testprognet": {}, - "runtime/testdata/testsuid": {}, - "runtime/testdata/testwinlib": {}, - "runtime/testdata/testwinlibsignal": {}, - "runtime/testdata/testwinlibthrow": {}, - "runtime/testdata/testwinsignal": {}, - "runtime/testdata/testwintls": {}, - "runtime/trace": {}, - "slices": {}, - "sort": {}, - "strconv": {}, - "strconv/testdata": {}, - "strings": {}, - "sync": {}, - "sync/atomic": {}, - "syscall": {}, - "syscall/js": {}, - "testdata": {}, - "testing": {}, - "testing/fstest": {}, - "testing/internal": {}, - "testing/internal/testdeps": {}, - "testing/iotest": {}, - "testing/quick": {}, - "testing/slogtest": {}, - "text": {}, - "text/scanner": {}, - "text/tabwriter": {}, - "text/template": {}, - "text/template/parse": {}, - "text/template/testdata": {}, - "time": {}, - "time/testdata": {}, - "time/tzdata": {}, - "unicode": {}, - "unicode/utf16": {}, - "unicode/utf8": {}, - "unsafe": {}, - "vendor": {}, - "vendor/golang.org": {}, - "vendor/golang.org/x": {}, - "vendor/golang.org/x/crypto": {}, - "vendor/golang.org/x/crypto/chacha20": {}, - "vendor/golang.org/x/crypto/chacha20poly1305": {}, - "vendor/golang.org/x/crypto/cryptobyte": {}, - "vendor/golang.org/x/crypto/cryptobyte/asn1": {}, - "vendor/golang.org/x/crypto/hkdf": {}, - "vendor/golang.org/x/crypto/internal": {}, - "vendor/golang.org/x/crypto/internal/alias": {}, - "vendor/golang.org/x/crypto/internal/poly1305": {}, - "vendor/golang.org/x/net": {}, - "vendor/golang.org/x/net/dns": {}, - "vendor/golang.org/x/net/dns/dnsmessage": {}, - "vendor/golang.org/x/net/http": {}, - "vendor/golang.org/x/net/http/httpguts": {}, - "vendor/golang.org/x/net/http/httpproxy": {}, - "vendor/golang.org/x/net/http2": {}, - "vendor/golang.org/x/net/http2/hpack": {}, - "vendor/golang.org/x/net/idna": {}, - "vendor/golang.org/x/net/lif": {}, - "vendor/golang.org/x/net/nettest": {}, - "vendor/golang.org/x/net/route": {}, - "vendor/golang.org/x/sys": {}, - "vendor/golang.org/x/sys/cpu": {}, - "vendor/golang.org/x/text": {}, - "vendor/golang.org/x/text/secure": {}, - "vendor/golang.org/x/text/secure/bidirule": {}, - "vendor/golang.org/x/text/transform": {}, - "vendor/golang.org/x/text/unicode": {}, - "vendor/golang.org/x/text/unicode/bidi": {}, - "vendor/golang.org/x/text/unicode/norm": {}, + "go/internal/gcimporter/testdata": {}, + "net/rpc/jsonrpc": {}, + "crypto/internal": {}, + "debug/pe/testdata": {}, + "runtime/pprof/testdata": {}, + "runtime/testdata/testprognet": {}, + "time/tzdata": {}, + "crypto/aes": {}, + "crypto/x509/internal": {}, + "go/internal/srcimporter/testdata": {}, + "internal/goos": {}, + "runtime/asan": {}, + "time/testdata": {}, + "net/http/cgi": {}, + "reflect/internal/example1": {}, + "crypto/internal/edwards25519": {}, + "go": {}, + "internal/coverage/rtcov": {}, + "internal/zstd/testdata": {}, + "runtime/msan": {}, + "text/scanner": {}, + "go/build/testdata/withvendor/src/a/vendor/c": {}, + "go/doc/comment/testdata": {}, + "internal/chacha8rand": {}, + "archive/zip": {}, + "crypto/internal/bigmod": {}, + "go/build/testdata/cgo_disabled": {}, + "vendor/golang.org/x/crypto/chacha20poly1305": {}, + "vendor/golang.org/x/sys": {}, + "image/internal": {}, + "math/bits": {}, + "net/textproto": {}, + "internal/coverage/decodecounter": {}, + "net/rpc": {}, + "vendor/golang.org/x/text/transform": {}, + "go/internal/typeparams": {}, + "internal/gover": {}, + "runtime/debug": {}, + "crypto/boring": {}, + "hash/maphash": {}, + "index/suffixarray": {}, + "internal": {}, + "log/slog": {}, + "reflect/internal/example2": {}, + "crypto/ecdsa/testdata": {}, + "crypto/internal/boring": {}, + "go/build/testdata/directives": {}, + "crypto/internal/boring/bbig": {}, + "database/sql": {}, + "go/version": {}, + "html": {}, + "debug/buildinfo": {}, + "embed/internal/embedtest/testdata/.hidden/_more": {}, + "testing/slogtest": {}, + "go/build": {}, + "go/build/testdata/other": {}, + "internal/bisect": {}, + "internal/oserror": {}, + "os/testdata/dirfs/dir": {}, + "crypto/rc4": {}, + "encoding/hex": {}, + "hash": {}, + "internal/nettrace": {}, + "path/filepath": {}, + "crypto": {}, + "go/build/testdata/non_source_tags": {}, + "internal/types/testdata/check/issue25008": {}, + "runtime/coverage/testdata": {}, + "runtime/testdata": {}, + "runtime/testdata/testprog": {}, + "debug/plan9obj/testdata": {}, + "internal/xcoff": {}, + "net": {}, + "crypto/dsa": {}, + "go/build/testdata": {}, + "mime/multipart": {}, + "runtime/internal/wasitest": {}, + "unicode/utf16": {}, + "builtin": {}, + "encoding/json": {}, + "go/ast": {}, + "runtime/coverage": {}, + "net/http/cookiejar": {}, + "runtime/testdata/testexithooks": {}, + "strconv/testdata": {}, + "vendor/golang.org/x/crypto/cryptobyte/asn1": {}, + "os/exec/internal/fdtest": {}, + "go/parser/testdata": {}, + "io/fs": {}, + "go/types": {}, + "reflect/internal": {}, + "runtime/internal/syscall": {}, + "runtime/race/internal/amd64v1": {}, + "go/internal/srcimporter": {}, + "log/syslog": {}, + "compress/testdata": {}, + "crypto/x509/internal/macos": {}, + "internal/coverage/uleb128": {}, + "internal/platform": {}, + "image/internal/imageutil": {}, + "testing/internal": {}, + "vendor/golang.org/x/crypto/hkdf": {}, } From 65445bde7e559898da035f0903f91d75207a7c28 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Thu, 1 Feb 2024 03:49:54 +0800 Subject: [PATCH 03/12] fix: add gofuncval --- file_test.go | 5 ++--- gen.go | 13 +++++++++++++ moduledata_gen.go | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/file_test.go b/file_test.go index 47fda6e..7d228fb 100644 --- a/file_test.go +++ b/file_test.go @@ -101,9 +101,8 @@ func TestGoldFiles(t *testing.T) { // Get info from filename gold-os-arch-goversion fileInfo := strings.Split(file, "-") - // If patch level is 0, it is dropped. For example. 10.0.0 is 10.0. - // This was changed in 1.21 so if the version is 1.21 or greater, we take - // the whole string. + // If the patch level is 0, it is dropped. For example. 10.0.0 is 10.0 + // Up until 1.21.0, if patch level is 0, it is dropped. For example. 10.0.0 is 10.0 var actualVersion string verArr := strings.Split(fileInfo[3], ".") if len(verArr) == 3 && verArr[2] == "0" && mustParse(strconv.Atoi(verArr[1])) < 21 { diff --git a/gen.go b/gen.go index 879e63b..0b003f1 100644 --- a/gen.go +++ b/gen.go @@ -470,6 +470,8 @@ func toModuledata(b *bytes.Buffer, st reflect.Type, bits int) { modFieldLen(b, st, bits, names[0], names[1]) } + modFieldVal(b, st, bits, "GoFunc", "Gofunc") + _, _ = fmt.Fprint(b, "}\n}\n\n") } @@ -497,6 +499,17 @@ func modFieldLen(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName } } +func modFieldVal(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { + if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { + return + } + if bits == 32 { + _, _ = fmt.Fprintf(b, "%sVal: uint64(md.%s),\n", modName, parsedName) + } else { + _, _ = fmt.Fprintf(b, "%sVal: md.%s,\n", modName, parsedName) + } +} + func generateModuleData() { b := &bytes.Buffer{} b.WriteString(moduleDataHeader) diff --git a/moduledata_gen.go b/moduledata_gen.go index dff5498..0dc96fc 100644 --- a/moduledata_gen.go +++ b/moduledata_gen.go @@ -76,6 +76,7 @@ func (md moduledata2064) toModuledata() moduledata { FuncTabLen: md.Ftablen, PCLNTabAddr: md.Pclntable, PCLNTabLen: md.Pclntablelen, + GoFuncVal: md.Gofunc, } } @@ -136,6 +137,7 @@ func (md moduledata2032) toModuledata() moduledata { FuncTabLen: uint64(md.Ftablen), PCLNTabAddr: uint64(md.Pclntable), PCLNTabLen: uint64(md.Pclntablelen), + GoFuncVal: uint64(md.Gofunc), } } @@ -194,6 +196,7 @@ func (md moduledata1864) toModuledata() moduledata { FuncTabLen: md.Ftablen, PCLNTabAddr: md.Pclntable, PCLNTabLen: md.Pclntablelen, + GoFuncVal: md.Gofunc, } } @@ -252,6 +255,7 @@ func (md moduledata1832) toModuledata() moduledata { FuncTabLen: uint64(md.Ftablen), PCLNTabAddr: uint64(md.Pclntable), PCLNTabLen: uint64(md.Pclntablelen), + GoFuncVal: uint64(md.Gofunc), } } From 4022e1379aef082f23ae380ffb151381160be3b1 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Thu, 1 Feb 2024 19:08:04 +0800 Subject: [PATCH 04/12] refactor: move gen.go and sort stdpkgs --- gen.go => gen/gen.go | 45 ++- goversion.go | 2 +- moduledata.go | 2 +- package.go | 2 +- stdpkg_gen.go | 922 +++++++++++++++++++++---------------------- 5 files changed, 491 insertions(+), 482 deletions(-) rename gen.go => gen/gen.go (94%) diff --git a/gen.go b/gen/gen.go similarity index 94% rename from gen.go rename to gen/gen.go index 0b003f1..bb62253 100644 --- a/gen.go +++ b/gen/gen.go @@ -15,10 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -//go:build gore_generate -// +build gore_generate - -// This program generates stdpkgs_gen.go and goversion_gen.go. It can be invoked by running +// This program generates stdpkgs_gen.go, goversion_gen.go and moduledata_gen.go. It can be invoked by running // go generate package main @@ -36,6 +33,8 @@ import ( "os" "path/filepath" "reflect" + "runtime" + "sort" "strings" "text/template" "time" @@ -156,20 +155,27 @@ type ghTree struct { Url string `json:"url"` } +func getSourceDir() string { + _, filename, _, ok := runtime.Caller(0) + if !ok { + panic("No caller information") + } + return filepath.Dir(filename) +} + const ( requestURLFormatStr = "https://api.github.com/repos/golang/go/git/trees/%s?recursive=0" commitRequestURLFormatStr = "https://api.github.com/repos/golang/go/git/commits/%s" - outputFile = "stdpkg_gen.go" - goversionOutputFile = "goversion_gen.go" - moduleDataOutputFile = "moduledata_gen.go" ) var ( tagsRequestURL = "https://api.github.com/repos/golang/go/tags" -) + excludedPaths = []string{"src/cmd"} -var ( - excludedPaths = []string{"src/cmd"} + goversionCsv = filepath.Join(getSourceDir(), "..", "resources", "goversions.csv") + outputFile = filepath.Join(getSourceDir(), "..", "stdpkg_gen.go") + goversionOutputFile = filepath.Join(getSourceDir(), "..", "goversion_gen.go") + moduleDataOutputFile = filepath.Join(getSourceDir(), "..", "moduledata_gen.go") ) type tagResp struct { @@ -287,7 +293,7 @@ func generateGoVersions() { // Get mode commit info for new tags - f, err := os.OpenFile(filepath.Join("resources", "goversions.csv"), os.O_CREATE|os.O_RDWR, 0664) + f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) if err != nil { fmt.Println("Error when opening goversions.csv:", err) return @@ -295,7 +301,7 @@ func generateGoVersions() { defer func(f *os.File) { _ = f.Close() }(f) - knownVersions, err := getStoredGoversions(f) + knownVersions, err := getCsvStoredGoversions(f) if err != nil { fmt.Println("Error when getting stored go versions:", err) return @@ -356,7 +362,7 @@ func generateGoVersions() { writeOnDemand(buf.Bytes(), goversionOutputFile) } -func getStoredGoversions(f *os.File) (map[string]*goversion, error) { +func getCsvStoredGoversions(f *os.File) (map[string]*goversion, error) { vers := make(map[string]*goversion) r := bufio.NewScanner(f) // Read header @@ -740,7 +746,7 @@ func generateStdPkgs() { return stdPkgs } - f, err := os.OpenFile(filepath.Join("resources", "goversions.csv"), os.O_CREATE|os.O_RDWR, 0664) + f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) if err != nil { fmt.Println("Error when opening goversions.csv:", err) return @@ -748,7 +754,7 @@ func generateStdPkgs() { defer func(f *os.File) { _ = f.Close() }(f) - knownVersions, err := getStoredGoversions(f) + knownVersions, err := getCsvStoredGoversions(f) branchs := map[string]struct{}{} for ver := range knownVersions { @@ -770,10 +776,13 @@ func generateStdPkgs() { } } - stdPkgs := make([]string, 0, len(stdpkgsSet)) + pkgs := make([]string, 0, len(stdpkgsSet)) for pkg := range stdpkgsSet { - stdPkgs = append(stdPkgs, pkg) + pkgs = append(pkgs, pkg) } + sort.Slice(pkgs, func(i, j int) bool { + return pkgs[i] < pkgs[j] + }) // Generate the code. buf := bytes.NewBuffer(nil) @@ -783,7 +792,7 @@ func generateStdPkgs() { StdPkg []string }{ Timestamp: time.Now().UTC(), - StdPkg: stdPkgs, + StdPkg: pkgs, }) if err != nil { fmt.Println("Error when generating the code:", err) diff --git a/goversion.go b/goversion.go index c2d1779..f3e4295 100644 --- a/goversion.go +++ b/goversion.go @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -//go:generate go run gen.go goversion +//go:generate go run ./gen goversion package gore diff --git a/moduledata.go b/moduledata.go index 61cd80e..21731ba 100644 --- a/moduledata.go +++ b/moduledata.go @@ -17,7 +17,7 @@ package gore -//go:generate go run gen.go moduledata +//go:generate go run ./gen moduledata import ( "bytes" diff --git a/package.go b/package.go index e064e37..f861677 100644 --- a/package.go +++ b/package.go @@ -25,7 +25,7 @@ import ( "strings" ) -//go:generate go run gen.go stdpkgs +//go:generate go run ./gen stdpkgs var ( knownRepos = []string{"golang.org", "github.com", "gitlab.com"} diff --git a/stdpkg_gen.go b/stdpkg_gen.go index 56b60e7..138c350 100644 --- a/stdpkg_gen.go +++ b/stdpkg_gen.go @@ -17,487 +17,487 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated at -// 2024-01-31 19:04:26.4224606 +0000 UTC +// 2024-02-01 11:07:16.5469259 +0000 UTC package gore var stdPkgs = map[string]struct{}{ - "runtime/testdata/testwinlibsignal": {}, - "crypto/elliptic": {}, - "crypto/rsa/testdata": {}, - "crypto/sha1": {}, - "crypto/sha256": {}, - "encoding/csv": {}, - "go/importer": {}, - "net/http/httptrace": {}, - "testing/internal/testdeps": {}, - "compress/gzip": {}, + "archive": {}, + "archive/tar": {}, + "archive/tar/testdata": {}, + "archive/zip": {}, + "archive/zip/testdata": {}, + "arena": {}, + "bufio": {}, + "builtin": {}, + "bytes": {}, + "cmp": {}, + "compress": {}, + "compress/bzip2": {}, + "compress/bzip2/testdata": {}, + "compress/flate": {}, + "compress/flate/testdata": {}, + "compress/gzip": {}, + "compress/gzip/testdata": {}, + "compress/lzw": {}, + "compress/testdata": {}, + "compress/zlib": {}, + "container": {}, + "container/heap": {}, + "container/list": {}, + "container/ring": {}, + "context": {}, + "crypto": {}, + "crypto/aes": {}, + "crypto/boring": {}, + "crypto/cipher": {}, + "crypto/des": {}, + "crypto/dsa": {}, + "crypto/ecdh": {}, + "crypto/ecdsa": {}, + "crypto/ecdsa/testdata": {}, + "crypto/ed25519": {}, + "crypto/ed25519/testdata": {}, + "crypto/elliptic": {}, + "crypto/hmac": {}, + "crypto/internal": {}, + "crypto/internal/alias": {}, + "crypto/internal/bigmod": {}, + "crypto/internal/bigmod/_asm": {}, + "crypto/internal/boring": {}, + "crypto/internal/boring/bbig": {}, + "crypto/internal/boring/bcache": {}, + "crypto/internal/boring/fipstls": {}, + "crypto/internal/boring/sig": {}, + "crypto/internal/boring/syso": {}, + "crypto/internal/edwards25519": {}, + "crypto/internal/edwards25519/field": {}, + "crypto/internal/edwards25519/field/_asm": {}, + "crypto/internal/nistec": {}, + "crypto/internal/nistec/fiat": {}, + "crypto/internal/randutil": {}, + "crypto/md5": {}, + "crypto/rand": {}, + "crypto/rc4": {}, + "crypto/rsa": {}, + "crypto/rsa/testdata": {}, + "crypto/sha1": {}, + "crypto/sha256": {}, + "crypto/sha512": {}, + "crypto/subtle": {}, + "crypto/tls": {}, + "crypto/tls/fipsonly": {}, + "crypto/tls/testdata": {}, + "crypto/x509": {}, + "crypto/x509/internal": {}, + "crypto/x509/internal/macos": {}, + "crypto/x509/pkix": {}, + "crypto/x509/testdata": {}, + "database": {}, + "database/sql": {}, + "database/sql/driver": {}, + "debug": {}, + "debug/buildinfo": {}, + "debug/dwarf": {}, + "debug/dwarf/testdata": {}, + "debug/elf": {}, + "debug/elf/testdata": {}, + "debug/gosym": {}, + "debug/gosym/testdata": {}, + "debug/macho": {}, + "debug/macho/testdata": {}, + "debug/pe": {}, + "debug/pe/testdata": {}, + "debug/plan9obj": {}, + "debug/plan9obj/testdata": {}, + "embed": {}, + "embed/internal": {}, + "embed/internal/embedtest": {}, + "embed/internal/embedtest/testdata": {}, + "embed/internal/embedtest/testdata/-not-hidden": {}, + "embed/internal/embedtest/testdata/.hidden": {}, "embed/internal/embedtest/testdata/.hidden/.more": {}, - "encoding/base32": {}, - "internal/lazyregexp": {}, - "internal/trace/v2/testdata/cmd/gotraceraw": {}, - "net/http/httputil": {}, - "internal/testenv": {}, - "internal/trace/v2/raw": {}, - "os": {}, - "compress/bzip2": {}, - "debug/gosym": {}, - "go/token": {}, - "internal/trace/v2/testdata/fuzz": {}, - "os/user": {}, - "flag": {}, - "image/gif": {}, - "internal/fmtsort": {}, - "testing/quick": {}, - "archive/tar/testdata": {}, - "crypto/tls": {}, - "errors": {}, - "io/ioutil/testdata": {}, - "testing": {}, - "compress/flate/testdata": {}, - "go/internal/srcimporter/testdata/issue23092": {}, - "internal/testlog": {}, - "internal/trace/v2/testdata": {}, - "runtime/coverage/testdata/issue56006": {}, - "crypto/subtle": {}, - "net/http/fcgi": {}, - "runtime/trace": {}, - "crypto/ecdh": {}, - "crypto/internal/boring/fipstls": {}, - "embed/internal/embedtest": {}, - "container/list": {}, - "crypto/ed25519/testdata": {}, - "go/build/testdata/withvendor/src/a/b": {}, - "hash/adler32": {}, - "unicode/utf8": {}, - "arena": {}, - "crypto/tls/fipsonly": {}, - "go/build/testdata/multi": {}, - "go/build/testdata/withvendor": {}, - "go/parser": {}, - "image": {}, - "internal/obscuretestdata": {}, - "vendor/golang.org/x/text/unicode": {}, - "crypto/internal/edwards25519/field/_asm": {}, - "go/build/testdata/doc": {}, - "math/big": {}, - "encoding/asn1": {}, - "go/constant": {}, - "internal/coverage/encodecounter": {}, - "internal/coverage/stringtab": {}, - "internal/diff": {}, - "internal/sysinfo": {}, - "internal/testpty": {}, - "runtime/internal/atomic": {}, - "internal/saferio": {}, - "vendor/golang.org/x/crypto/internal/alias": {}, - "compress/lzw": {}, - "crypto/hmac": {}, - "crypto/x509": {}, - "internal/trace/v2/testdata/generators": {}, - "internal/types/testdata/check/importdecl1": {}, - "iter": {}, - "vendor/golang.org/x/net/http/httpguts": {}, - "internal/godebug": {}, - "runtime/internal": {}, - "internal/trace/v2/internal/testgen": {}, - "compress/gzip/testdata": {}, - "debug/elf": {}, - "debug/macho": {}, - "encoding/json/testdata": {}, + "embed/internal/embedtest/testdata/.hidden/_more": {}, + "embed/internal/embedtest/testdata/.hidden/more": {}, + "embed/internal/embedtest/testdata/_hidden": {}, + "embed/internal/embedtest/testdata/i": {}, + "embed/internal/embedtest/testdata/i/j": {}, + "embed/internal/embedtest/testdata/i/j/k": {}, + "encoding": {}, + "encoding/ascii85": {}, + "encoding/asn1": {}, + "encoding/base32": {}, + "encoding/base64": {}, + "encoding/binary": {}, + "encoding/csv": {}, + "encoding/gob": {}, + "encoding/hex": {}, + "encoding/json": {}, + "encoding/json/testdata": {}, + "encoding/pem": {}, + "encoding/xml": {}, + "errors": {}, + "expvar": {}, + "flag": {}, + "fmt": {}, + "go": {}, + "go/ast": {}, + "go/build": {}, + "go/build/constraint": {}, + "go/build/testdata": {}, + "go/build/testdata/alltags": {}, + "go/build/testdata/bads": {}, + "go/build/testdata/cgo_disabled": {}, + "go/build/testdata/directives": {}, + "go/build/testdata/doc": {}, + "go/build/testdata/empty": {}, + "go/build/testdata/multi": {}, + "go/build/testdata/non_source_tags": {}, + "go/build/testdata/other": {}, + "go/build/testdata/other/file": {}, + "go/build/testdata/withvendor": {}, + "go/build/testdata/withvendor/src": {}, + "go/build/testdata/withvendor/src/a": {}, + "go/build/testdata/withvendor/src/a/b": {}, + "go/build/testdata/withvendor/src/a/vendor": {}, + "go/build/testdata/withvendor/src/a/vendor/c": {}, + "go/build/testdata/withvendor/src/a/vendor/c/d": {}, + "go/constant": {}, + "go/doc": {}, + "go/doc/comment": {}, + "go/doc/comment/testdata": {}, + "go/doc/testdata": {}, + "go/doc/testdata/examples": {}, + "go/doc/testdata/pkgdoc": {}, + "go/format": {}, + "go/importer": {}, + "go/internal": {}, + "go/internal/gccgoimporter": {}, + "go/internal/gccgoimporter/testdata": {}, + "go/internal/gcimporter": {}, + "go/internal/gcimporter/testdata": {}, + "go/internal/gcimporter/testdata/versions": {}, + "go/internal/srcimporter": {}, + "go/internal/srcimporter/testdata": {}, + "go/internal/srcimporter/testdata/issue20855": {}, + "go/internal/srcimporter/testdata/issue23092": {}, "go/internal/srcimporter/testdata/issue24392": {}, - "image/png": {}, - "internal/syscall/unix": {}, - "internal/trace/v2/testdata/cmd/gotracevalidate": {}, - "internal/trace/v2/testdata/testprog": {}, - "internal/types/testdata/check": {}, - "runtime/debug/testdata/fuzz": {}, - "runtime/testdata/testwinlib": {}, - "runtime/testdata/testwinlibthrow": {}, - "crypto/sha512": {}, - "embed/internal/embedtest/testdata/i": {}, - "internal/zstd": {}, - "mime": {}, - "net/http/httptest": {}, - "text": {}, - "vendor/golang.org/x/crypto/internal": {}, - "vendor": {}, - "vendor/golang.org/x/crypto/chacha20": {}, - "encoding/pem": {}, - "internal/fuzz": {}, - "net/internal": {}, - "log": {}, - "crypto/x509/pkix": {}, + "go/internal/typeparams": {}, + "go/parser": {}, + "go/parser/testdata": {}, + "go/parser/testdata/goversion": {}, + "go/parser/testdata/issue42951": {}, + "go/parser/testdata/issue42951/not_a_file.go": {}, + "go/parser/testdata/resolution": {}, + "go/printer": {}, + "go/printer/testdata": {}, + "go/scanner": {}, + "go/token": {}, + "go/types": {}, + "go/types/testdata": {}, + "go/types/testdata/local": {}, + "go/version": {}, + "hash": {}, + "hash/adler32": {}, + "hash/crc32": {}, + "hash/crc64": {}, + "hash/fnv": {}, + "hash/maphash": {}, + "html": {}, "html/template": {}, + "html/template/testdata": {}, + "image": {}, + "image/color": {}, "image/color/palette": {}, - "internal/pkgbits": {}, - "internal/types/testdata/check/importdecl0": {}, - "internal/types/testdata/examples": {}, - "internal/xcoff/testdata": {}, - "net/http/pprof/testdata": {}, - "vendor/golang.org/x/net/http2/hpack": {}, - "crypto/ecdsa": {}, - "runtime/testdata/testfds": {}, + "image/draw": {}, + "image/gif": {}, + "image/internal": {}, + "image/internal/imageutil": {}, + "image/jpeg": {}, + "image/png": {}, + "image/png/testdata": {}, + "image/png/testdata/pngsuite": {}, + "image/testdata": {}, + "index": {}, + "index/suffixarray": {}, + "internal": {}, + "internal/abi": {}, "internal/abi/testdata": {}, - "runtime/race/internal": {}, - "runtime/testdata/testfaketime": {}, - "crypto/internal/boring/bcache": {}, - "embed/internal/embedtest/testdata": {}, - "internal/trace/traceviewer/static": {}, - "go/build/testdata/empty": {}, - "internal/trace/v2/event": {}, - "net/http/internal/ascii": {}, - "runtime/pprof/testdata/mappingtest": {}, - "testing/iotest": {}, - "vendor/golang.org/x/net/http2": {}, - "internal/syscall": {}, - "internal/types/errors": {}, - "vendor/golang.org/x/text/unicode/norm": {}, - "internal/reflectlite": {}, - "expvar": {}, - "internal/trace/v2": {}, - "vendor/golang.org/x/net/idna": {}, - "crypto/ed25519": {}, - "encoding/ascii85": {}, - "hash/fnv": {}, + "internal/bisect": {}, + "internal/buildcfg": {}, + "internal/bytealg": {}, + "internal/cfg": {}, + "internal/chacha8rand": {}, + "internal/coverage": {}, + "internal/coverage/calloc": {}, + "internal/coverage/cformat": {}, + "internal/coverage/cmerge": {}, + "internal/coverage/decodecounter": {}, + "internal/coverage/decodemeta": {}, + "internal/coverage/encodecounter": {}, + "internal/coverage/encodemeta": {}, + "internal/coverage/pods": {}, + "internal/coverage/rtcov": {}, + "internal/coverage/slicereader": {}, + "internal/coverage/slicewriter": {}, + "internal/coverage/stringtab": {}, + "internal/coverage/test": {}, + "internal/coverage/uleb128": {}, + "internal/cpu": {}, + "internal/dag": {}, + "internal/diff": {}, + "internal/diff/testdata": {}, + "internal/fmtsort": {}, + "internal/fuzz": {}, + "internal/goarch": {}, + "internal/godebug": {}, + "internal/godebugs": {}, + "internal/goexperiment": {}, + "internal/goos": {}, + "internal/goroot": {}, + "internal/gover": {}, + "internal/goversion": {}, + "internal/intern": {}, + "internal/itoa": {}, + "internal/lazyregexp": {}, + "internal/lazytemplate": {}, + "internal/nettrace": {}, + "internal/obscuretestdata": {}, + "internal/oserror": {}, + "internal/pkgbits": {}, + "internal/platform": {}, + "internal/poll": {}, "internal/profile": {}, + "internal/race": {}, + "internal/reflectlite": {}, + "internal/safefilepath": {}, + "internal/saferio": {}, "internal/singleflight": {}, - "sort": {}, - "go/parser/testdata/issue42951/not_a_file.go": {}, - "mime/testdata": {}, - "net/mail": {}, - "runtime/race": {}, - "testing/fstest": {}, - "go/internal": {}, + "internal/syscall": {}, + "internal/syscall/execenv": {}, + "internal/syscall/unix": {}, + "internal/syscall/windows": {}, + "internal/syscall/windows/registry": {}, + "internal/syscall/windows/sysdll": {}, + "internal/sysinfo": {}, + "internal/testenv": {}, + "internal/testlog": {}, + "internal/testpty": {}, + "internal/trace": {}, + "internal/trace/testdata": {}, + "internal/trace/traceviewer": {}, "internal/trace/traceviewer/format": {}, - "net/internal/cgotest": {}, - "archive": {}, - "compress/zlib": {}, + "internal/trace/traceviewer/static": {}, + "internal/trace/v2": {}, + "internal/trace/v2/event": {}, "internal/trace/v2/event/go122": {}, - "log/slog/internal/buffer": {}, - "net/url": {}, - "regexp/syntax": {}, - "vendor/golang.org/x/net/dns": {}, - "go/internal/gcimporter": {}, - "context": {}, - "crypto/internal/boring/syso": {}, - "debug/elf/testdata": {}, - "internal/coverage/slicereader": {}, - "vendor/golang.org/x/crypto/internal/poly1305": {}, - "cmp": {}, - "go/parser/testdata/resolution": {}, - "go/printer": {}, - "internal/bytealg": {}, - "internal/dag": {}, - "internal/syscall/windows/sysdll": {}, - "archive/zip/testdata": {}, - "vendor/golang.org/x/net": {}, - "database": {}, - "embed/internal/embedtest/testdata/-not-hidden": {}, - "os/testdata/issue37161": {}, - "plugin": {}, - "regexp/testdata": {}, - "runtime/internal/math": {}, - "os/exec": {}, - "compress/flate": {}, - "crypto/internal/edwards25519/field": {}, - "go/doc/comment": {}, - "go/scanner": {}, - "log/slog/internal/benchmarks": {}, - "math/rand/v2": {}, - "mime/quotedprintable": {}, - "os/signal": {}, - "runtime/metrics": {}, - "vendor/golang.org/x/net/lif": {}, - "container/heap": {}, - "crypto/rand": {}, - "internal/goexperiment": {}, - "log/slog/internal/slogtest": {}, - "crypto/rsa": {}, - "internal/lazytemplate": {}, - "runtime/debug/testdata": {}, - "runtime/testdata/testprogcgo": {}, - "vendor/golang.org/x/crypto/cryptobyte": {}, - "hash/crc64": {}, - "embed": {}, - "fmt": {}, - "go/build/testdata/withvendor/src/a/vendor/c/d": {}, - "go/types/testdata": {}, - "index": {}, - "internal/buildcfg": {}, - "text/tabwriter": {}, - "net/smtp": {}, - "os/testdata/dirfs": {}, - "runtime/coverage/testdata/issue59563": {}, - "vendor/golang.org": {}, - "crypto/internal/nistec/fiat": {}, - "internal/race": {}, - "internal/syscall/windows/registry": {}, - "internal/trace/v2/internal": {}, - "net/http/testdata": {}, - "vendor/golang.org/x/net/http/httpproxy": {}, - "go/build/testdata/withvendor/src": {}, - "go/doc/testdata/examples": {}, - "runtime/testdata/testwinsignal": {}, - "syscall": {}, - "vendor/golang.org/x/net/http": {}, - "container": {}, - "debug/dwarf/testdata": {}, - "go/format": {}, - "crypto/tls/testdata": {}, - "encoding/base64": {}, - "internal/syscall/execenv": {}, - "net/http/pprof": {}, - "runtime/race/testdata": {}, - "text/template/parse": {}, - "go/parser/testdata/goversion": {}, - "internal/itoa": {}, - "runtime": {}, - "internal/types/testdata/spec": {}, - "maps": {}, - "runtime/pprof": {}, - "vendor/golang.org/x/sys/cpu": {}, - "container/ring": {}, - "internal/cpu": {}, - "internal/unsafeheader": {}, - "regexp": {}, - "crypto/internal/bigmod/_asm": {}, - "embed/internal/embedtest/testdata/i/j/k": {}, - "internal/goroot": {}, - "net/netip": {}, - "archive/tar": {}, - "math/cmplx": {}, - "debug/plan9obj": {}, - "go/doc": {}, - "internal/coverage/calloc": {}, - "runtime/testdata/testsuid": {}, - "internal/coverage/slicewriter": {}, - "internal/trace/v2/version": {}, - "vendor/golang.org/x/net/nettest": {}, - "go/build/testdata/alltags": {}, - "internal/goarch": {}, - "os/exec/internal": {}, - "crypto/internal/randutil": {}, - "encoding/gob": {}, - "html/template/testdata": {}, - "math": {}, - "net/internal/socktest": {}, - "bytes": {}, - "slices": {}, - "go/build/testdata/other/file": {}, - "go/internal/gcimporter/testdata/versions": {}, - "image/jpeg": {}, - "log/internal": {}, - "debug": {}, - "internal/safefilepath": {}, - "runtime/internal/wasitest/testdata": {}, - "unsafe": {}, - "vendor/golang.org/x/text/unicode/bidi": {}, - "compress": {}, - "image/png/testdata/pngsuite": {}, - "math/rand": {}, - "go/internal/gccgoimporter/testdata": {}, - "go/internal/srcimporter/testdata/issue20855": {}, - "internal/trace/v2/testdata/fuzz/FuzzReader": {}, - "unicode": {}, - "vendor/golang.org/x/text/secure/bidirule": {}, - "go/doc/testdata": {}, - "image/draw": {}, - "runtime/testdata/testwintls": {}, - "sync": {}, - "sync/atomic": {}, - "syscall/js": {}, - "text/template/testdata": {}, - "net/testdata": {}, - "vendor/golang.org/x": {}, - "vendor/golang.org/x/text/secure": {}, - "text/template": {}, - "go/build/constraint": {}, - "internal/types/testdata": {}, - "path": {}, - "crypto/internal/alias": {}, - "image/testdata": {}, - "internal/syscall/windows": {}, - "internal/trace/testdata": {}, - "net/http/internal/testcert": {}, - "vendor/golang.org/x/net/dns/dnsmessage": {}, - "internal/types": {}, - "go/build/testdata/withvendor/src/a": {}, - "image/color": {}, - "os/testdata": {}, - "vendor/golang.org/x/crypto": {}, - "debug/gosym/testdata": {}, - "debug/macho/testdata": {}, - "go/types/testdata/local": {}, - "internal/godebugs": {}, - "internal/txtar": {}, - "runtime/internal/startlinetest": {}, - "strconv": {}, - "embed/internal": {}, - "internal/coverage/decodemeta": {}, - "internal/coverage/encodemeta": {}, - "mime/multipart/testdata": {}, - "internal/abi": {}, - "internal/coverage/test": {}, - "crypto/cipher": {}, - "crypto/internal/nistec": {}, - "embed/internal/embedtest/testdata/.hidden/more": {}, - "go/parser/testdata/issue42951": {}, - "internal/coverage/cmerge": {}, + "internal/trace/v2/internal": {}, + "internal/trace/v2/internal/testgen": {}, "internal/trace/v2/internal/testgen/go122": {}, - "vendor/golang.org/x/net/route": {}, - "encoding/binary": {}, - "go/build/testdata/withvendor/src/a/vendor": {}, - "internal/poll": {}, - "internal/types/testdata/fixedbugs": {}, - "compress/bzip2/testdata": {}, - "go/printer/testdata": {}, - "vendor/golang.org/x/text": {}, - "reflect": {}, - "crypto/md5": {}, - "database/sql/driver": {}, - "encoding": {}, - "encoding/xml": {}, - "go/doc/testdata/pkgdoc": {}, - "go/internal/gccgoimporter": {}, - "internal/coverage/pods": {}, - "hash/crc32": {}, - "internal/trace/v2/testtrace": {}, - "io": {}, - "runtime/cgo": {}, - "time": {}, - "crypto/internal/boring/sig": {}, - "embed/internal/embedtest/testdata/i/j": {}, - "internal/coverage": {}, - "runtime/testdata/testprogcgo/windows": {}, - "internal/cfg": {}, - "strings": {}, - "go/build/testdata/bads": {}, - "internal/intern": {}, + "internal/trace/v2/raw": {}, + "internal/trace/v2/testdata": {}, "internal/trace/v2/testdata/cmd": {}, + "internal/trace/v2/testdata/cmd/gotraceraw": {}, + "internal/trace/v2/testdata/cmd/gotracevalidate": {}, + "internal/trace/v2/testdata/fuzz": {}, + "internal/trace/v2/testdata/fuzz/FuzzReader": {}, + "internal/trace/v2/testdata/generators": {}, + "internal/trace/v2/testdata/testprog": {}, "internal/trace/v2/testdata/tests": {}, + "internal/trace/v2/testtrace": {}, + "internal/trace/v2/version": {}, + "internal/txtar": {}, + "internal/types": {}, + "internal/types/errors": {}, + "internal/types/testdata": {}, + "internal/types/testdata/check": {}, "internal/types/testdata/check/decls2": {}, + "internal/types/testdata/check/importdecl0": {}, + "internal/types/testdata/check/importdecl1": {}, + "internal/types/testdata/check/issue25008": {}, + "internal/types/testdata/examples": {}, + "internal/types/testdata/fixedbugs": {}, + "internal/types/testdata/spec": {}, + "internal/unsafeheader": {}, + "internal/xcoff": {}, + "internal/xcoff/testdata": {}, + "internal/zstd": {}, + "internal/zstd/testdata": {}, + "io": {}, + "io/fs": {}, "io/ioutil": {}, - "debug/pe": {}, - "image/png/testdata": {}, - "internal/trace/traceviewer": {}, - "bufio": {}, - "crypto/x509/testdata": {}, - "embed/internal/embedtest/testdata/.hidden": {}, - "debug/dwarf": {}, - "internal/coverage/cformat": {}, - "internal/goversion": {}, + "io/ioutil/testdata": {}, + "iter": {}, + "log": {}, + "log/internal": {}, + "log/slog": {}, "log/slog/internal": {}, - "testdata": {}, - "crypto/des": {}, + "log/slog/internal/benchmarks": {}, + "log/slog/internal/buffer": {}, + "log/slog/internal/slogtest": {}, + "log/syslog": {}, + "maps": {}, + "math": {}, + "math/big": {}, + "math/bits": {}, + "math/cmplx": {}, + "math/rand": {}, + "math/rand/v2": {}, + "mime": {}, + "mime/multipart": {}, + "mime/multipart/testdata": {}, + "mime/quotedprintable": {}, + "mime/testdata": {}, + "net": {}, "net/http": {}, - "runtime/internal/sys": {}, - "runtime/race/internal/amd64v3": {}, - "embed/internal/embedtest/testdata/_hidden": {}, - "internal/diff/testdata": {}, - "internal/trace": {}, + "net/http/cgi": {}, + "net/http/cookiejar": {}, + "net/http/fcgi": {}, + "net/http/httptest": {}, + "net/http/httptrace": {}, + "net/http/httputil": {}, "net/http/internal": {}, + "net/http/internal/ascii": {}, + "net/http/internal/testcert": {}, + "net/http/pprof": {}, + "net/http/pprof/testdata": {}, + "net/http/testdata": {}, + "net/internal": {}, + "net/internal/cgotest": {}, + "net/internal/socktest": {}, + "net/mail": {}, + "net/netip": {}, + "net/rpc": {}, + "net/rpc/jsonrpc": {}, + "net/smtp": {}, + "net/testdata": {}, + "net/textproto": {}, + "net/url": {}, + "os": {}, + "os/exec": {}, + "os/exec/internal": {}, + "os/exec/internal/fdtest": {}, + "os/signal": {}, + "os/testdata": {}, + "os/testdata/dirfs": {}, + "os/testdata/dirfs/dir": {}, + "os/testdata/issue37161": {}, + "os/user": {}, + "path": {}, + "path/filepath": {}, + "plugin": {}, + "reflect": {}, + "reflect/internal": {}, + "reflect/internal/example1": {}, + "reflect/internal/example2": {}, + "regexp": {}, + "regexp/syntax": {}, + "regexp/testdata": {}, + "runtime": {}, + "runtime/asan": {}, + "runtime/cgo": {}, + "runtime/coverage": {}, + "runtime/coverage/testdata": {}, + "runtime/coverage/testdata/issue56006": {}, + "runtime/coverage/testdata/issue59563": {}, + "runtime/debug": {}, + "runtime/debug/testdata": {}, + "runtime/debug/testdata/fuzz": {}, "runtime/debug/testdata/fuzz/FuzzParseBuildInfoRoundTrip": {}, - "go/internal/gcimporter/testdata": {}, - "net/rpc/jsonrpc": {}, - "crypto/internal": {}, - "debug/pe/testdata": {}, - "runtime/pprof/testdata": {}, - "runtime/testdata/testprognet": {}, - "time/tzdata": {}, - "crypto/aes": {}, - "crypto/x509/internal": {}, - "go/internal/srcimporter/testdata": {}, - "internal/goos": {}, - "runtime/asan": {}, - "time/testdata": {}, - "net/http/cgi": {}, - "reflect/internal/example1": {}, - "crypto/internal/edwards25519": {}, - "go": {}, - "internal/coverage/rtcov": {}, - "internal/zstd/testdata": {}, - "runtime/msan": {}, - "text/scanner": {}, - "go/build/testdata/withvendor/src/a/vendor/c": {}, - "go/doc/comment/testdata": {}, - "internal/chacha8rand": {}, - "archive/zip": {}, - "crypto/internal/bigmod": {}, - "go/build/testdata/cgo_disabled": {}, - "vendor/golang.org/x/crypto/chacha20poly1305": {}, - "vendor/golang.org/x/sys": {}, - "image/internal": {}, - "math/bits": {}, - "net/textproto": {}, - "internal/coverage/decodecounter": {}, - "net/rpc": {}, - "vendor/golang.org/x/text/transform": {}, - "go/internal/typeparams": {}, - "internal/gover": {}, - "runtime/debug": {}, - "crypto/boring": {}, - "hash/maphash": {}, - "index/suffixarray": {}, - "internal": {}, - "log/slog": {}, - "reflect/internal/example2": {}, - "crypto/ecdsa/testdata": {}, - "crypto/internal/boring": {}, - "go/build/testdata/directives": {}, - "crypto/internal/boring/bbig": {}, - "database/sql": {}, - "go/version": {}, - "html": {}, - "debug/buildinfo": {}, - "embed/internal/embedtest/testdata/.hidden/_more": {}, - "testing/slogtest": {}, - "go/build": {}, - "go/build/testdata/other": {}, - "internal/bisect": {}, - "internal/oserror": {}, - "os/testdata/dirfs/dir": {}, - "crypto/rc4": {}, - "encoding/hex": {}, - "hash": {}, - "internal/nettrace": {}, - "path/filepath": {}, - "crypto": {}, - "go/build/testdata/non_source_tags": {}, - "internal/types/testdata/check/issue25008": {}, - "runtime/coverage/testdata": {}, - "runtime/testdata": {}, - "runtime/testdata/testprog": {}, - "debug/plan9obj/testdata": {}, - "internal/xcoff": {}, - "net": {}, - "crypto/dsa": {}, - "go/build/testdata": {}, - "mime/multipart": {}, - "runtime/internal/wasitest": {}, - "unicode/utf16": {}, - "builtin": {}, - "encoding/json": {}, - "go/ast": {}, - "runtime/coverage": {}, - "net/http/cookiejar": {}, - "runtime/testdata/testexithooks": {}, - "strconv/testdata": {}, - "vendor/golang.org/x/crypto/cryptobyte/asn1": {}, - "os/exec/internal/fdtest": {}, - "go/parser/testdata": {}, - "io/fs": {}, - "go/types": {}, - "reflect/internal": {}, - "runtime/internal/syscall": {}, - "runtime/race/internal/amd64v1": {}, - "go/internal/srcimporter": {}, - "log/syslog": {}, - "compress/testdata": {}, - "crypto/x509/internal/macos": {}, - "internal/coverage/uleb128": {}, - "internal/platform": {}, - "image/internal/imageutil": {}, - "testing/internal": {}, - "vendor/golang.org/x/crypto/hkdf": {}, + "runtime/internal": {}, + "runtime/internal/atomic": {}, + "runtime/internal/math": {}, + "runtime/internal/startlinetest": {}, + "runtime/internal/sys": {}, + "runtime/internal/syscall": {}, + "runtime/internal/wasitest": {}, + "runtime/internal/wasitest/testdata": {}, + "runtime/metrics": {}, + "runtime/msan": {}, + "runtime/pprof": {}, + "runtime/pprof/testdata": {}, + "runtime/pprof/testdata/mappingtest": {}, + "runtime/race": {}, + "runtime/race/internal": {}, + "runtime/race/internal/amd64v1": {}, + "runtime/race/internal/amd64v3": {}, + "runtime/race/testdata": {}, + "runtime/testdata": {}, + "runtime/testdata/testexithooks": {}, + "runtime/testdata/testfaketime": {}, + "runtime/testdata/testfds": {}, + "runtime/testdata/testprog": {}, + "runtime/testdata/testprogcgo": {}, + "runtime/testdata/testprogcgo/windows": {}, + "runtime/testdata/testprognet": {}, + "runtime/testdata/testsuid": {}, + "runtime/testdata/testwinlib": {}, + "runtime/testdata/testwinlibsignal": {}, + "runtime/testdata/testwinlibthrow": {}, + "runtime/testdata/testwinsignal": {}, + "runtime/testdata/testwintls": {}, + "runtime/trace": {}, + "slices": {}, + "sort": {}, + "strconv": {}, + "strconv/testdata": {}, + "strings": {}, + "sync": {}, + "sync/atomic": {}, + "syscall": {}, + "syscall/js": {}, + "testdata": {}, + "testing": {}, + "testing/fstest": {}, + "testing/internal": {}, + "testing/internal/testdeps": {}, + "testing/iotest": {}, + "testing/quick": {}, + "testing/slogtest": {}, + "text": {}, + "text/scanner": {}, + "text/tabwriter": {}, + "text/template": {}, + "text/template/parse": {}, + "text/template/testdata": {}, + "time": {}, + "time/testdata": {}, + "time/tzdata": {}, + "unicode": {}, + "unicode/utf16": {}, + "unicode/utf8": {}, + "unsafe": {}, + "vendor": {}, + "vendor/golang.org": {}, + "vendor/golang.org/x": {}, + "vendor/golang.org/x/crypto": {}, + "vendor/golang.org/x/crypto/chacha20": {}, + "vendor/golang.org/x/crypto/chacha20poly1305": {}, + "vendor/golang.org/x/crypto/cryptobyte": {}, + "vendor/golang.org/x/crypto/cryptobyte/asn1": {}, + "vendor/golang.org/x/crypto/hkdf": {}, + "vendor/golang.org/x/crypto/internal": {}, + "vendor/golang.org/x/crypto/internal/alias": {}, + "vendor/golang.org/x/crypto/internal/poly1305": {}, + "vendor/golang.org/x/net": {}, + "vendor/golang.org/x/net/dns": {}, + "vendor/golang.org/x/net/dns/dnsmessage": {}, + "vendor/golang.org/x/net/http": {}, + "vendor/golang.org/x/net/http/httpguts": {}, + "vendor/golang.org/x/net/http/httpproxy": {}, + "vendor/golang.org/x/net/http2": {}, + "vendor/golang.org/x/net/http2/hpack": {}, + "vendor/golang.org/x/net/idna": {}, + "vendor/golang.org/x/net/lif": {}, + "vendor/golang.org/x/net/nettest": {}, + "vendor/golang.org/x/net/route": {}, + "vendor/golang.org/x/sys": {}, + "vendor/golang.org/x/sys/cpu": {}, + "vendor/golang.org/x/text": {}, + "vendor/golang.org/x/text/secure": {}, + "vendor/golang.org/x/text/secure/bidirule": {}, + "vendor/golang.org/x/text/transform": {}, + "vendor/golang.org/x/text/unicode": {}, + "vendor/golang.org/x/text/unicode/bidi": {}, + "vendor/golang.org/x/text/unicode/norm": {}, } From 9b75c6bc987c4ca697d7168278fb576367f3e625 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Thu, 1 Feb 2024 22:47:27 +0800 Subject: [PATCH 05/12] refactor: split generate to standalone package --- gen/client.go | 33 ++ gen/gen.go | 783 +-------------------------------- gen/goversion.go | 105 +++++ gen/moduledata.go | 311 +++++++++++++ gen/static.go | 114 +++++ gen/stdpkgs.go | 119 +++++ gen/types.go | 24 ++ gen/utils.go | 117 +++++ go.mod | 2 + go.sum | 8 + stdpkg_gen.go | 1054 +++++++++++++++++++++++++-------------------- 11 files changed, 1412 insertions(+), 1258 deletions(-) create mode 100644 gen/client.go create mode 100644 gen/goversion.go create mode 100644 gen/moduledata.go create mode 100644 gen/static.go create mode 100644 gen/stdpkgs.go create mode 100644 gen/types.go create mode 100644 gen/utils.go diff --git a/gen/client.go b/gen/client.go new file mode 100644 index 0000000..9e5258f --- /dev/null +++ b/gen/client.go @@ -0,0 +1,33 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2024 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "os" + + "github.com/google/go-github/v58/github" +) + +var githubClient = github.NewClient(nil) + +func init() { + token := os.Getenv("GITHUB_TOKEN") + if token != "" { + githubClient = githubClient.WithAuthToken(token) + } +} diff --git a/gen/gen.go b/gen/gen.go index bb62253..a89fdd7 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -1,6 +1,6 @@ // This file is part of GoRE. // -// Copyright (C) 2019-2023 GoRE Authors +// Copyright (C) 2019-2024 GoRE Authors // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -21,790 +21,13 @@ package main import ( - "bufio" - "bytes" - "encoding/json" - "errors" "fmt" - "go/format" - "golang.org/x/mod/semver" - "io" - "net/http" "os" - "path/filepath" - "reflect" - "runtime" - "sort" - "strings" - "text/template" - "time" ) -var packageTemplate = template.Must(template.New("").Parse(`// This file is part of GoRE. -// -// Copyright (C) 2019-2021 GoRE Authors -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Code generated by go generate; DO NOT EDIT. -// This file was generated at -// {{ .Timestamp }} - -package gore - -var stdPkgs = map[string]struct{}{ -{{- range .StdPkg }} - {{ printf "\"%s\": {}" . }}, -{{- end }} -} -`)) - -var goversionTemplate = template.Must(template.New("").Parse(`// This file is part of GoRE. -// -// Copyright (C) 2019-2021 GoRE Authors -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Code generated by go generate; DO NOT EDIT. -// This file was generated at -// {{ .Timestamp }} - -package gore - -var goversions = map[string]*GoVersion{ -{{- range .GoVersions }} - {{ printf "\"%s\": {Name: \"%s\", SHA: \"%s\", Timestamp: \"%s\"}" .Name .Name .Sha .Date }}, -{{- end }} -} -`)) - -const moduleDataHeader = ` -// This file is part of GoRE. -// -// Copyright (C) 2019-2023 GoRE Authors -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Code generated by go generate; DO NOT EDIT. - -package gore - -` - -var client = &http.Client{} - -var authRequest func(*http.Request) - -func init() { - token := os.Getenv("GITHUB_TOKEN") - if token != "" { - authRequest = func(r *http.Request) { - r.Header.Set("Authorization", "Bearer "+token) - } - } else { - authRequest = func(r *http.Request) {} - } -} - -type ghResp struct { - Sha string `json:"sha"` - Url string `json:"url"` - Trees []ghTree `json:"tree"` - Truncated bool `json:"truncated"` -} - -type ghTree struct { - Path string `json:"path"` - Mode string `json:"mode"` - Gittype string `json:"type"` - Sha string `json:"sha"` - Size int `json:"size"` - Url string `json:"url"` -} - -func getSourceDir() string { - _, filename, _, ok := runtime.Caller(0) - if !ok { - panic("No caller information") - } - return filepath.Dir(filename) -} - -const ( - requestURLFormatStr = "https://api.github.com/repos/golang/go/git/trees/%s?recursive=0" - commitRequestURLFormatStr = "https://api.github.com/repos/golang/go/git/commits/%s" -) - -var ( - tagsRequestURL = "https://api.github.com/repos/golang/go/tags" - excludedPaths = []string{"src/cmd"} - - goversionCsv = filepath.Join(getSourceDir(), "..", "resources", "goversions.csv") - outputFile = filepath.Join(getSourceDir(), "..", "stdpkg_gen.go") - goversionOutputFile = filepath.Join(getSourceDir(), "..", "goversion_gen.go") - moduleDataOutputFile = filepath.Join(getSourceDir(), "..", "moduledata_gen.go") -) - -type tagResp struct { - Name string - Commit *commitShort -} - -type commitShort struct { - Sha string - URL string -} - -type commitLong struct { - Sha string - Committer committer -} - -type committer struct { - Name string - Date string -} - -type goversion struct { - Name string - Sha string - Date string -} - -// diffCode returns false if a and b have different other than the date. -func diffCode(a, b string) bool { - if a == b { - return false - } - - aLines := strings.Split(a, "\n") - bLines := strings.Split(b, "\n") - - // ignore the license and the date - aLines = aLines[21:] - bLines = bLines[21:] - - if len(aLines) != len(bLines) { - return true - } - - for i := 0; i < len(aLines); i++ { - if aLines[i] != bLines[i] { - return true - } - } - - return false -} - -func writeOnDemand(new []byte, target string) { - old, err := os.ReadFile(target) - if err != nil { - fmt.Println("Error when reading the old file:", target, err) - return - } - - old, _ = format.Source(old) - new, _ = format.Source(new) - - // Compare the old and the new. - if !diffCode(string(old), string(new)) { - fmt.Println(target + " no changes.") - return - } - - fmt.Println(target + " changes detected.") - - // Write the new file. - err = os.WriteFile(target, new, 0664) - if err != nil { - fmt.Println("Error when writing the new file:", err) - return - } -} - -func generateGoVersions() { - tags := make([]*tagResp, 0) - - // Fetch all tags - - var requestURL *string - - requestURL = &tagsRequestURL - for *requestURL != "" { - fmt.Println("Fetching latests tags") - req, _ := http.NewRequest(http.MethodGet, *requestURL, nil) - authRequest(req) - resp, err := client.Do(req) - if err != nil { - fmt.Println("Error when fetching tags:", err.Error()) - _ = resp.Body.Close() - continue - } - next := getNextPageURL(resp) - *requestURL = next - body, err := io.ReadAll(resp.Body) - _ = resp.Body.Close() - if err != nil { - fmt.Println("Error when ready response body:", err) - continue - } - var newTags []*tagResp - err = json.Unmarshal(body, &newTags) - if err != nil { - fmt.Println("Error when parsing the json:", string(body), err) - continue - } - tags = append(tags, newTags...) - } - - // Get mode commit info for new tags - - f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) - if err != nil { - fmt.Println("Error when opening goversions.csv:", err) - return - } - defer func(f *os.File) { - _ = f.Close() - }(f) - knownVersions, err := getCsvStoredGoversions(f) - if err != nil { - fmt.Println("Error when getting stored go versions:", err) - return - } - - _, err = fmt.Fprintln(f, "version,sha,date") - if err != nil { - fmt.Println("Error when writing csv header:", err) - return - } - - for _, tag := range tags { - if strings.HasPrefix(tag.Name, "weekly") || strings.HasPrefix(tag.Name, "release") { - continue - } - if v, known := knownVersions[tag.Name]; known { - _, _ = fmt.Fprintf(f, "%s,%s,%s\n", v.Name, v.Sha, v.Date) - continue - } - - req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf(commitRequestURLFormatStr, tag.Commit.Sha), nil) - authRequest(req) - resp, err := client.Do(req) - if err != nil { - fmt.Println("Error when fetching commit info:", err) - _ = resp.Body.Close() - continue - } - body, err := io.ReadAll(resp.Body) - _ = resp.Body.Close() - - var commit commitLong - err = json.Unmarshal(body, &commit) - if err != nil { - fmt.Println("Error when parsing commit json:", err) - continue - } - _, _ = fmt.Fprintf(f, "%s,%s,%s\n", tag.Name, commit.Sha, commit.Committer.Date) - fmt.Println("New tag found:", tag.Name) - knownVersions[tag.Name] = &goversion{Name: tag.Name, Sha: commit.Sha, Date: commit.Committer.Date} - } - - // Generate the code. - buf := bytes.NewBuffer(nil) - - err = goversionTemplate.Execute(buf, struct { - Timestamp time.Time - GoVersions map[string]*goversion - }{ - Timestamp: time.Now().UTC(), - GoVersions: knownVersions, - }) - if err != nil { - fmt.Println("Error when generating the code:", err) - return - } - - writeOnDemand(buf.Bytes(), goversionOutputFile) -} - -func getCsvStoredGoversions(f *os.File) (map[string]*goversion, error) { - vers := make(map[string]*goversion) - r := bufio.NewScanner(f) - // Read header - if !r.Scan() { - return nil, errors.New("empty file") - } - r.Text() - - for r.Scan() { - row := r.Text() - if row == "" { - continue - } - data := strings.Split(row, ",") - if data[0] == "" { - // No version - continue - } - version := strings.TrimSpace(data[0]) - sha := strings.TrimSpace(data[1]) - date := strings.TrimSpace(data[2]) - vers[version] = &goversion{Name: version, Sha: sha, Date: date} - } - _, err := f.Seek(0, 0) - return vers, err -} - -func getNextPageURL(r *http.Response) string { - h := r.Header.Get("Link") - if h == "" { - return "" - } - // Either we this type: - // ; rel="next", ; rel="last" - // or this type: - // ; rel="prev", ; rel="first" - data := strings.Split(h, ",") - for _, l := range data { - ll := strings.Split(l, ";") - if len(ll) != 2 { - continue - } - if strings.TrimSpace(ll[1]) != "rel=\"next\"" { - continue - } - return strings.TrimLeft(strings.TrimRight(strings.TrimSpace(ll[0]), ">"), "<") - } - return "" -} - -func skipPath(path string) bool { - for _, exclude := range excludedPaths { - if strings.HasPrefix(path, exclude) { - return true - } - } - return false -} - -func typeDef(b *bytes.Buffer, st reflect.Type, bits int) { - typeName := "uint64" - if bits == 32 { - typeName = "uint32" - } - - _, _ = fmt.Fprintf(b, "type %s%d struct {\n", st.Name(), bits) - - for i := 0; i < st.NumField(); i++ { - field := st.Field(i) - fieldName := strings.ToUpper(field.Name[:1]) + field.Name[1:] - t := field.Type.Kind() - switch t { - case reflect.Uintptr: - _, _ = fmt.Fprintf(b, "%s %s\n", fieldName, typeName) - case reflect.String: - _, _ = fmt.Fprintf(b, "%s, %[1]slen %s\n", fieldName, typeName) - case reflect.Pointer: - _, _ = fmt.Fprintf(b, "%s %s\n", fieldName, typeName) - case reflect.Slice: - _, _ = fmt.Fprintf(b, "%s, %[1]slen, %[1]scap %s\n", fieldName, typeName) - - default: - panic(fmt.Sprintf("unhandled type: %+v", t)) - } - } - - _, _ = fmt.Fprint(b, "}\n\n") -} - -func toModuledata(b *bytes.Buffer, st reflect.Type, bits int) { - _, _ = fmt.Fprintf(b, "func (md %s%d) toModuledata() moduledata {\n", st.Name(), bits) - _, _ = fmt.Fprint(b, "return moduledata{\n") - - for _, names := range [][2]string{ - {"Text", "Text"}, - {"NoPtrData", "Noptrdata"}, - {"Data", "Data"}, - {"Bss", "Bss"}, - {"NoPtrBss", "Noptrbss"}, - {"Types", "Types"}, - } { - modFieldE(b, st, bits, names[0], names[1]) - } - - for _, names := range [][2]string{ - {"Typelink", "Typelinks"}, - {"ITabLink", "Itablinks"}, - {"FuncTab", "Ftab"}, - {"PCLNTab", "Pclntable"}, - } { - modFieldLen(b, st, bits, names[0], names[1]) - } - - modFieldVal(b, st, bits, "GoFunc", "Gofunc") - - _, _ = fmt.Fprint(b, "}\n}\n\n") -} - -func modFieldE(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { - endName := "E" + strings.ToLower(parsedName) - if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { - return - } - if bits == 32 { - _, _ = fmt.Fprintf(b, "%sAddr: uint64(md.%[3]s),\n%[1]sLen: uint64(md.%s - md.%s),\n", modName, endName, parsedName) - } else { - _, _ = fmt.Fprintf(b, "%sAddr: md.%[3]s,\n%[1]sLen: md.%s - md.%s,\n", modName, endName, parsedName) - } -} - -func modFieldLen(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { - lenName := parsedName + "len" - if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { - return - } - if bits == 32 { - _, _ = fmt.Fprintf(b, "%sAddr: uint64(md.%s),\n%[1]sLen: uint64(md.%[3]s),\n", modName, parsedName, lenName) - } else { - _, _ = fmt.Fprintf(b, "%sAddr: md.%s,\n%[1]sLen: md.%[3]s,\n", modName, parsedName, lenName) - } -} - -func modFieldVal(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { - if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { - return - } - if bits == 32 { - _, _ = fmt.Fprintf(b, "%sVal: uint64(md.%s),\n", modName, parsedName) - } else { - _, _ = fmt.Fprintf(b, "%sVal: md.%s,\n", modName, parsedName) - } -} - -func generateModuleData() { - b := &bytes.Buffer{} - b.WriteString(moduleDataHeader) - - for _, iface := range []any{ - moduledata20{}, - moduledata18{}, - moduledata16{}, - moduledata8{}, - moduledata7{}, - moduledata5{}, - } { - o := reflect.TypeOf(iface) - typeDef(b, o, 64) - toModuledata(b, o, 64) - typeDef(b, o, 32) - toModuledata(b, o, 32) - } - - out, err := format.Source(b.Bytes()) - if err != nil { - panic(err) - } - - err = os.WriteFile(moduleDataOutputFile, out, 0o666) - if err != nil { - panic(err) - } -} - -/* - Internal module structures from Go's runtime. - TODO: auto extract from golang source runtime package. -*/ - -// Moduledata structure for Go 1.20 and newer (at least up to the last field covered here) - -type moduledata20 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - covctrs, ecovctrs uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - rodata uintptr - gofunc uintptr // go.func.* - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.18 and Go 1.19 - -type moduledata18 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - rodata uintptr - gofunc uintptr // go.func.* - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.16 to 1.17 - -type moduledata16 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.8 to 1.15 - -type moduledata8 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.7 - -type moduledata7 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - typelinks []int32 // offsets from types - itablinks []*itab -} - -// Moduledata structure for Go 1.5 to 1.6 - -type moduledata5 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - - typelinks []*_type -} - -// dummy definitions -type initTask struct{} -type pcHeader struct{} -type functab struct{} -type textsect struct{} -type itab struct{} -type ptabEntry struct{} -type modulehash struct{} -type _type struct{} - -func generateStdPkgs() { - collect := func(ver string) []string { - resp, err := client.Get(fmt.Sprintf(requestURLFormatStr, "master")) - if err != nil { - fmt.Println("Error when fetching go src data:", err) - return nil - } - defer func(Body io.ReadCloser) { - _ = Body.Close() - }(resp.Body) - body, err := io.ReadAll(resp.Body) - if err != nil { - fmt.Println("Error when reading response body:", err) - return nil - } - var master ghResp - err = json.Unmarshal(body, &master) - if err != nil { - fmt.Println("Error when decoding the response body:", err) - return nil - } - var stdPkgs []string - for _, tree := range master.Trees { - if tree.Gittype != "tree" { - continue - } - if !strings.HasPrefix(tree.Path, "src") || skipPath(tree.Path) { - continue - } - // Skip src folder. - if tree.Path == "src" { - continue - } - // Strip "src/" and add to the list. - stdPkgs = append(stdPkgs, strings.TrimPrefix(tree.Path, "src/")) - } - - return stdPkgs - } - - f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) - if err != nil { - fmt.Println("Error when opening goversions.csv:", err) - return - } - defer func(f *os.File) { - _ = f.Close() - }(f) - knownVersions, err := getCsvStoredGoversions(f) - - branchs := map[string]struct{}{} - for ver := range knownVersions { - rawver := "v" + strings.TrimPrefix(ver, "go") - sver := semver.MajorMinor(rawver) - if sver != "" { - sver = "go" + strings.TrimPrefix(sver, "v") - branchs["release-branch."+sver] = struct{}{} - } - } - - stdpkgsSet := map[string]struct{}{} - - for branch := range branchs { - fmt.Println("Fetching std pkgs for branch:", branch) - pkgs := collect(branch) - for _, pkg := range pkgs { - stdpkgsSet[pkg] = struct{}{} - } - } - - pkgs := make([]string, 0, len(stdpkgsSet)) - for pkg := range stdpkgsSet { - pkgs = append(pkgs, pkg) - } - sort.Slice(pkgs, func(i, j int) bool { - return pkgs[i] < pkgs[j] - }) - - // Generate the code. - buf := bytes.NewBuffer(nil) - - err = packageTemplate.Execute(buf, struct { - Timestamp time.Time - StdPkg []string - }{ - Timestamp: time.Now().UTC(), - StdPkg: pkgs, - }) - if err != nil { - fmt.Println("Error when generating the code:", err) - return - } - - writeOnDemand(buf.Bytes(), outputFile) -} - func main() { if len(os.Args) != 2 { - fmt.Println("go run gen.go [stdpkgs|goversion|moduledata]") + fmt.Println("go run ./gen [stdpkgs|goversion|moduledata]") return } @@ -815,5 +38,7 @@ func main() { generateGoVersions() case "moduledata": generateModuleData() + default: + fmt.Println("go run ./gen [stdpkgs|goversion|moduledata]") } } diff --git a/gen/goversion.go b/gen/goversion.go new file mode 100644 index 0000000..fd89ef8 --- /dev/null +++ b/gen/goversion.go @@ -0,0 +1,105 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2024 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "bytes" + "context" + "fmt" + "github.com/google/go-github/v58/github" + "os" + "strings" + "time" +) + +func generateGoVersions() { + ctx := context.Background() + + opts := &github.ListOptions{PerPage: 100} + var allTags []*github.RepositoryTag + for { + tags, resp, err := githubClient.Repositories.ListTags(ctx, "golang", "go", opts) + if err != nil { + fmt.Println(err) + return + } + allTags = append(allTags, tags...) + if resp.NextPage == 0 { + break + } + opts.Page = resp.NextPage + } + + // Get mode commit info for new tags + + f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) + if err != nil { + fmt.Println("Error when opening goversions.csv:", err) + return + } + defer func(f *os.File) { + _ = f.Close() + }(f) + knownVersions, err := getCsvStoredGoversions(f) + if err != nil { + fmt.Println("Error when getting stored go versions:", err) + return + } + + _, err = fmt.Fprintln(f, "version,sha,date") + if err != nil { + fmt.Println("Error when writing csv header:", err) + return + } + + for _, tag := range allTags { + if strings.HasPrefix(tag.GetName(), "weekly") || strings.HasPrefix(tag.GetName(), "release") { + continue + } + if v, known := knownVersions[tag.GetName()]; known { + _, _ = fmt.Fprintf(f, "%s,%s,%s\n", v.Name, v.Sha, v.Date) + continue + } + + commit, _, err := githubClient.Repositories.GetCommit(ctx, "golang", "go", tag.GetCommit().GetSHA(), nil) + if err != nil { + fmt.Println("Error when getting commit info:", err) + return + } + _, _ = fmt.Fprintf(f, "%s,%s,%s\n", tag.GetName(), commit.GetSHA(), commit.GetCommitter().GetCreatedAt().String()) + fmt.Println("New tag found:", tag.Name) + knownVersions[tag.GetName()] = &goversion{Name: tag.GetName(), Sha: commit.GetSHA(), Date: commit.GetCommitter().GetCreatedAt().String()} + } + + // Generate the code. + buf := bytes.NewBuffer(nil) + + err = goversionTemplate.Execute(buf, struct { + Timestamp time.Time + GoVersions map[string]*goversion + }{ + Timestamp: time.Now().UTC(), + GoVersions: knownVersions, + }) + if err != nil { + fmt.Println("Error when generating the code:", err) + return + } + + writeOnDemand(buf.Bytes(), goversionOutputFile) +} diff --git a/gen/moduledata.go b/gen/moduledata.go new file mode 100644 index 0000000..d6c1b30 --- /dev/null +++ b/gen/moduledata.go @@ -0,0 +1,311 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2024 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "bytes" + "fmt" + "go/format" + "os" + "reflect" + "strings" +) + +func typeDef(b *bytes.Buffer, st reflect.Type, bits int) { + typeName := "uint64" + if bits == 32 { + typeName = "uint32" + } + + _, _ = fmt.Fprintf(b, "type %s%d struct {\n", st.Name(), bits) + + for i := 0; i < st.NumField(); i++ { + field := st.Field(i) + fieldName := strings.ToUpper(field.Name[:1]) + field.Name[1:] + t := field.Type.Kind() + switch t { + case reflect.Uintptr: + _, _ = fmt.Fprintf(b, "%s %s\n", fieldName, typeName) + case reflect.String: + _, _ = fmt.Fprintf(b, "%s, %[1]slen %s\n", fieldName, typeName) + case reflect.Pointer: + _, _ = fmt.Fprintf(b, "%s %s\n", fieldName, typeName) + case reflect.Slice: + _, _ = fmt.Fprintf(b, "%s, %[1]slen, %[1]scap %s\n", fieldName, typeName) + + default: + panic(fmt.Sprintf("unhandled type: %+v", t)) + } + } + + _, _ = fmt.Fprint(b, "}\n\n") +} + +func toModuledata(b *bytes.Buffer, st reflect.Type, bits int) { + _, _ = fmt.Fprintf(b, "func (md %s%d) toModuledata() moduledata {\n", st.Name(), bits) + _, _ = fmt.Fprint(b, "return moduledata{\n") + + for _, names := range [][2]string{ + {"Text", "Text"}, + {"NoPtrData", "Noptrdata"}, + {"Data", "Data"}, + {"Bss", "Bss"}, + {"NoPtrBss", "Noptrbss"}, + {"Types", "Types"}, + } { + modFieldE(b, st, bits, names[0], names[1]) + } + + for _, names := range [][2]string{ + {"Typelink", "Typelinks"}, + {"ITabLink", "Itablinks"}, + {"FuncTab", "Ftab"}, + {"PCLNTab", "Pclntable"}, + } { + modFieldLen(b, st, bits, names[0], names[1]) + } + + modFieldVal(b, st, bits, "GoFunc", "Gofunc") + + _, _ = fmt.Fprint(b, "}\n}\n\n") +} + +func modFieldE(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { + endName := "E" + strings.ToLower(parsedName) + if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { + return + } + if bits == 32 { + _, _ = fmt.Fprintf(b, "%sAddr: uint64(md.%[3]s),\n%[1]sLen: uint64(md.%s - md.%s),\n", modName, endName, parsedName) + } else { + _, _ = fmt.Fprintf(b, "%sAddr: md.%[3]s,\n%[1]sLen: md.%s - md.%s,\n", modName, endName, parsedName) + } +} + +func modFieldLen(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { + lenName := parsedName + "len" + if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { + return + } + if bits == 32 { + _, _ = fmt.Fprintf(b, "%sAddr: uint64(md.%s),\n%[1]sLen: uint64(md.%[3]s),\n", modName, parsedName, lenName) + } else { + _, _ = fmt.Fprintf(b, "%sAddr: md.%s,\n%[1]sLen: md.%[3]s,\n", modName, parsedName, lenName) + } +} + +func modFieldVal(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { + if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { + return + } + if bits == 32 { + _, _ = fmt.Fprintf(b, "%sVal: uint64(md.%s),\n", modName, parsedName) + } else { + _, _ = fmt.Fprintf(b, "%sVal: md.%s,\n", modName, parsedName) + } +} + +func generateModuleData() { + b := &bytes.Buffer{} + b.WriteString(moduleDataHeader) + + for _, iface := range []any{ + moduledata20{}, + moduledata18{}, + moduledata16{}, + moduledata8{}, + moduledata7{}, + moduledata5{}, + } { + o := reflect.TypeOf(iface) + typeDef(b, o, 64) + toModuledata(b, o, 64) + typeDef(b, o, 32) + toModuledata(b, o, 32) + } + + out, err := format.Source(b.Bytes()) + if err != nil { + panic(err) + } + + err = os.WriteFile(moduleDataOutputFile, out, 0o666) + if err != nil { + panic(err) + } +} + +/* + Internal module structures from Go's runtime. + TODO: auto extract from golang source runtime package. +*/ + +// Moduledata structure for Go 1.20 and newer (at least up to the last field covered here) + +type moduledata20 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + covctrs, ecovctrs uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + rodata uintptr + gofunc uintptr // go.func.* + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.18 and Go 1.19 + +type moduledata18 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + rodata uintptr + gofunc uintptr // go.func.* + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.16 to 1.17 + +type moduledata16 struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []functab + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.8 to 1.15 + +type moduledata8 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + textsectmap []textsect + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.7 + +type moduledata7 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + + typelinks []int32 // offsets from types + itablinks []*itab +} + +// Moduledata structure for Go 1.5 to 1.6 + +type moduledata5 struct { + pclntable []byte + ftab []functab + filetab []uint32 + findfunctab uintptr + minpc, maxpc uintptr + + text, etext uintptr + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + end, gcdata, gcbss uintptr + + typelinks []*_type +} + +// dummy definitions +type initTask struct{} +type pcHeader struct{} +type functab struct{} +type textsect struct{} +type itab struct{} +type ptabEntry struct{} +type modulehash struct{} +type _type struct{} diff --git a/gen/static.go b/gen/static.go new file mode 100644 index 0000000..225d8e7 --- /dev/null +++ b/gen/static.go @@ -0,0 +1,114 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2024 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "path/filepath" + "text/template" +) + +var packageTemplate = template.Must(template.New("").Parse(`// This file is part of GoRE. +// +// Copyright (C) 2019-2021 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by go generate; DO NOT EDIT. +// This file was generated at +// {{ .Timestamp }} + +package gore + +var stdPkgs = map[string]struct{}{ +{{- range .StdPkg }} + {{ printf "\"%s\": {}" . }}, +{{- end }} +} +`)) + +var goversionTemplate = template.Must(template.New("").Parse(`// This file is part of GoRE. +// +// Copyright (C) 2019-2021 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by go generate; DO NOT EDIT. +// This file was generated at +// {{ .Timestamp }} + +package gore + +var goversions = map[string]*GoVersion{ +{{- range .GoVersions }} + {{ printf "\"%s\": {Name: \"%s\", SHA: \"%s\", Timestamp: \"%s\"}" .Name .Name .Sha .Date }}, +{{- end }} +} +`)) + +const moduleDataHeader = ` +// This file is part of GoRE. +// +// Copyright (C) 2019-2023 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by go generate; DO NOT EDIT. + +package gore + +` + +var ( + goversionCsv = filepath.Join(getSourceDir(), "resources", "goversions.csv") + outputFile = filepath.Join(getSourceDir(), "stdpkg_gen.go") + goversionOutputFile = filepath.Join(getSourceDir(), "goversion_gen.go") + moduleDataOutputFile = filepath.Join(getSourceDir(), "moduledata_gen.go") +) diff --git a/gen/stdpkgs.go b/gen/stdpkgs.go new file mode 100644 index 0000000..b8860c9 --- /dev/null +++ b/gen/stdpkgs.go @@ -0,0 +1,119 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2024 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "bytes" + "context" + "fmt" + "golang.org/x/mod/semver" + "os" + "sort" + "strings" + "time" +) + +func generateStdPkgs() { + collect := func(ver string) ([]string, error) { + ctx := context.Background() + tree, _, err := githubClient.Git.GetTree(ctx, "golang", "go", ver, true) + if err != nil { + return nil, err + } + + var stdPkgs []string + for _, entry := range tree.Entries { + if *entry.Type != "tree" { + continue + } + + if !strings.HasPrefix(entry.GetPath(), "src/") || + strings.HasPrefix(entry.GetPath(), "src/cmd") || + strings.HasSuffix(entry.GetPath(), "_asm") || + strings.Contains(entry.GetPath(), "/testdata") { + continue + } + + stdPkgs = append(stdPkgs, strings.TrimPrefix(entry.GetPath(), "src/")) + } + return stdPkgs, nil + } + + f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) + if err != nil { + fmt.Println("Error when opening goversions.csv:", err) + return + } + defer func(f *os.File) { + _ = f.Close() + }(f) + knownVersions, err := getCsvStoredGoversions(f) + + branchs := map[string]struct{}{} + for ver := range knownVersions { + rawver := "v" + strings.TrimPrefix(ver, "go") + sver := semver.MajorMinor(rawver) + if sver != "" { + sver = "go" + strings.TrimPrefix(sver, "v") + if sver == "go1.0" { + sver = "go1" + } + + branchs["release-branch."+sver] = struct{}{} + } + } + + stdpkgsSet := map[string]struct{}{} + + for branch := range branchs { + fmt.Println("Fetching std pkgs for branch:", branch) + pkgs, err := collect(branch) + if err != nil { + fmt.Println("Error when fetching std pkgs:", err) + return + } + for _, pkg := range pkgs { + stdpkgsSet[pkg] = struct{}{} + } + } + + pkgs := make([]string, 0, len(stdpkgsSet)) + for pkg := range stdpkgsSet { + pkgs = append(pkgs, pkg) + } + sort.Slice(pkgs, func(i, j int) bool { + return pkgs[i] < pkgs[j] + }) + + // Generate the code. + buf := bytes.NewBuffer(nil) + + err = packageTemplate.Execute(buf, struct { + Timestamp time.Time + StdPkg []string + }{ + Timestamp: time.Now().UTC(), + StdPkg: pkgs, + }) + if err != nil { + fmt.Println("Error when generating the code:", err) + return + } + + writeOnDemand(buf.Bytes(), outputFile) +} diff --git a/gen/types.go b/gen/types.go new file mode 100644 index 0000000..6ddaec0 --- /dev/null +++ b/gen/types.go @@ -0,0 +1,24 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2024 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +type goversion struct { + Name string + Sha string + Date string +} diff --git a/gen/utils.go b/gen/utils.go new file mode 100644 index 0000000..2bc97bd --- /dev/null +++ b/gen/utils.go @@ -0,0 +1,117 @@ +// This file is part of GoRE. +// +// Copyright (C) 2019-2024 GoRE Authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "bufio" + "errors" + "fmt" + "go/format" + "os" + "path/filepath" + "runtime" + "strings" +) + +// diffCode returns false if a and b have different other than the date. +func diffCode(a, b string) bool { + if a == b { + return false + } + + aLines := strings.Split(a, "\n") + bLines := strings.Split(b, "\n") + + // ignore the license and the date + aLines = aLines[21:] + bLines = bLines[21:] + + if len(aLines) != len(bLines) { + return true + } + + for i := 0; i < len(aLines); i++ { + if aLines[i] != bLines[i] { + return true + } + } + + return false +} + +func writeOnDemand(new []byte, target string) { + old, err := os.ReadFile(target) + if err != nil { + fmt.Println("Error when reading the old file:", target, err) + return + } + + old, _ = format.Source(old) + new, _ = format.Source(new) + + // Compare the old and the new. + if !diffCode(string(old), string(new)) { + fmt.Println(target + " no changes.") + return + } + + fmt.Println(target + " changes detected.") + + // Write the new file. + err = os.WriteFile(target, new, 0664) + if err != nil { + fmt.Println("Error when writing the new file:", err) + return + } +} + +func getSourceDir() string { + _, filename, _, ok := runtime.Caller(0) + if !ok { + panic("No caller information") + } + return filepath.Join(filepath.Dir(filename), "..") +} + +func getCsvStoredGoversions(f *os.File) (map[string]*goversion, error) { + vers := make(map[string]*goversion) + r := bufio.NewScanner(f) + // Read header + if !r.Scan() { + return nil, errors.New("empty file") + } + r.Text() + + for r.Scan() { + row := r.Text() + if row == "" { + continue + } + data := strings.Split(row, ",") + if data[0] == "" { + // No version + continue + } + version := strings.TrimSpace(data[0]) + sha := strings.TrimSpace(data[1]) + date := strings.TrimSpace(data[2]) + vers[version] = &goversion{Name: version, Sha: sha, Date: date} + } + _, err := f.Seek(0, 0) + return vers, err +} diff --git a/go.mod b/go.mod index 9ff3ed4..db3f5bf 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/goretk/gore go 1.21 require ( + github.com/google/go-github/v58 v58.0.0 github.com/stretchr/testify v1.8.4 golang.org/x/arch v0.6.0 golang.org/x/mod v0.14.0 @@ -10,6 +11,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 065e681..5349b46 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-github/v58 v58.0.0 h1:Una7GGERlF/37XfkPwpzYJe0Vp4dt2k1kCjlxwjIvzw= +github.com/google/go-github/v58 v58.0.0/go.mod h1:k4hxDKEfoWpSqFlc8LTpGd9fu2KrV1YAa6Hi6FmDNY4= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= @@ -8,6 +15,7 @@ golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc= golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/stdpkg_gen.go b/stdpkg_gen.go index 138c350..2326608 100644 --- a/stdpkg_gen.go +++ b/stdpkg_gen.go @@ -17,487 +17,583 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated at -// 2024-02-01 11:07:16.5469259 +0000 UTC +// 2024-02-01 14:41:54.4508801 +0000 UTC package gore var stdPkgs = map[string]struct{}{ - "archive": {}, - "archive/tar": {}, - "archive/tar/testdata": {}, - "archive/zip": {}, - "archive/zip/testdata": {}, - "arena": {}, - "bufio": {}, - "builtin": {}, - "bytes": {}, - "cmp": {}, - "compress": {}, - "compress/bzip2": {}, - "compress/bzip2/testdata": {}, - "compress/flate": {}, - "compress/flate/testdata": {}, - "compress/gzip": {}, - "compress/gzip/testdata": {}, - "compress/lzw": {}, - "compress/testdata": {}, - "compress/zlib": {}, - "container": {}, - "container/heap": {}, - "container/list": {}, - "container/ring": {}, - "context": {}, - "crypto": {}, - "crypto/aes": {}, - "crypto/boring": {}, - "crypto/cipher": {}, - "crypto/des": {}, - "crypto/dsa": {}, - "crypto/ecdh": {}, - "crypto/ecdsa": {}, - "crypto/ecdsa/testdata": {}, - "crypto/ed25519": {}, - "crypto/ed25519/testdata": {}, - "crypto/elliptic": {}, - "crypto/hmac": {}, - "crypto/internal": {}, - "crypto/internal/alias": {}, - "crypto/internal/bigmod": {}, - "crypto/internal/bigmod/_asm": {}, - "crypto/internal/boring": {}, - "crypto/internal/boring/bbig": {}, - "crypto/internal/boring/bcache": {}, - "crypto/internal/boring/fipstls": {}, - "crypto/internal/boring/sig": {}, - "crypto/internal/boring/syso": {}, - "crypto/internal/edwards25519": {}, - "crypto/internal/edwards25519/field": {}, - "crypto/internal/edwards25519/field/_asm": {}, - "crypto/internal/nistec": {}, - "crypto/internal/nistec/fiat": {}, - "crypto/internal/randutil": {}, - "crypto/md5": {}, - "crypto/rand": {}, - "crypto/rc4": {}, - "crypto/rsa": {}, - "crypto/rsa/testdata": {}, - "crypto/sha1": {}, - "crypto/sha256": {}, - "crypto/sha512": {}, - "crypto/subtle": {}, - "crypto/tls": {}, - "crypto/tls/fipsonly": {}, - "crypto/tls/testdata": {}, - "crypto/x509": {}, - "crypto/x509/internal": {}, - "crypto/x509/internal/macos": {}, - "crypto/x509/pkix": {}, - "crypto/x509/testdata": {}, - "database": {}, - "database/sql": {}, - "database/sql/driver": {}, - "debug": {}, - "debug/buildinfo": {}, - "debug/dwarf": {}, - "debug/dwarf/testdata": {}, - "debug/elf": {}, - "debug/elf/testdata": {}, - "debug/gosym": {}, - "debug/gosym/testdata": {}, - "debug/macho": {}, - "debug/macho/testdata": {}, - "debug/pe": {}, - "debug/pe/testdata": {}, - "debug/plan9obj": {}, - "debug/plan9obj/testdata": {}, - "embed": {}, - "embed/internal": {}, - "embed/internal/embedtest": {}, - "embed/internal/embedtest/testdata": {}, - "embed/internal/embedtest/testdata/-not-hidden": {}, - "embed/internal/embedtest/testdata/.hidden": {}, - "embed/internal/embedtest/testdata/.hidden/.more": {}, - "embed/internal/embedtest/testdata/.hidden/_more": {}, - "embed/internal/embedtest/testdata/.hidden/more": {}, - "embed/internal/embedtest/testdata/_hidden": {}, - "embed/internal/embedtest/testdata/i": {}, - "embed/internal/embedtest/testdata/i/j": {}, - "embed/internal/embedtest/testdata/i/j/k": {}, - "encoding": {}, - "encoding/ascii85": {}, - "encoding/asn1": {}, - "encoding/base32": {}, - "encoding/base64": {}, - "encoding/binary": {}, - "encoding/csv": {}, - "encoding/gob": {}, - "encoding/hex": {}, - "encoding/json": {}, - "encoding/json/testdata": {}, - "encoding/pem": {}, - "encoding/xml": {}, - "errors": {}, - "expvar": {}, - "flag": {}, - "fmt": {}, - "go": {}, - "go/ast": {}, - "go/build": {}, - "go/build/constraint": {}, - "go/build/testdata": {}, - "go/build/testdata/alltags": {}, - "go/build/testdata/bads": {}, - "go/build/testdata/cgo_disabled": {}, - "go/build/testdata/directives": {}, - "go/build/testdata/doc": {}, - "go/build/testdata/empty": {}, - "go/build/testdata/multi": {}, - "go/build/testdata/non_source_tags": {}, - "go/build/testdata/other": {}, - "go/build/testdata/other/file": {}, - "go/build/testdata/withvendor": {}, - "go/build/testdata/withvendor/src": {}, - "go/build/testdata/withvendor/src/a": {}, - "go/build/testdata/withvendor/src/a/b": {}, - "go/build/testdata/withvendor/src/a/vendor": {}, - "go/build/testdata/withvendor/src/a/vendor/c": {}, - "go/build/testdata/withvendor/src/a/vendor/c/d": {}, - "go/constant": {}, - "go/doc": {}, - "go/doc/comment": {}, - "go/doc/comment/testdata": {}, - "go/doc/testdata": {}, - "go/doc/testdata/examples": {}, - "go/doc/testdata/pkgdoc": {}, - "go/format": {}, - "go/importer": {}, - "go/internal": {}, - "go/internal/gccgoimporter": {}, - "go/internal/gccgoimporter/testdata": {}, - "go/internal/gcimporter": {}, - "go/internal/gcimporter/testdata": {}, - "go/internal/gcimporter/testdata/versions": {}, - "go/internal/srcimporter": {}, - "go/internal/srcimporter/testdata": {}, - "go/internal/srcimporter/testdata/issue20855": {}, - "go/internal/srcimporter/testdata/issue23092": {}, - "go/internal/srcimporter/testdata/issue24392": {}, - "go/internal/typeparams": {}, - "go/parser": {}, - "go/parser/testdata": {}, - "go/parser/testdata/goversion": {}, - "go/parser/testdata/issue42951": {}, - "go/parser/testdata/issue42951/not_a_file.go": {}, - "go/parser/testdata/resolution": {}, - "go/printer": {}, - "go/printer/testdata": {}, - "go/scanner": {}, - "go/token": {}, - "go/types": {}, - "go/types/testdata": {}, - "go/types/testdata/local": {}, - "go/version": {}, - "hash": {}, - "hash/adler32": {}, - "hash/crc32": {}, - "hash/crc64": {}, - "hash/fnv": {}, - "hash/maphash": {}, - "html": {}, - "html/template": {}, - "html/template/testdata": {}, - "image": {}, - "image/color": {}, - "image/color/palette": {}, - "image/draw": {}, - "image/gif": {}, - "image/internal": {}, - "image/internal/imageutil": {}, - "image/jpeg": {}, - "image/png": {}, - "image/png/testdata": {}, - "image/png/testdata/pngsuite": {}, - "image/testdata": {}, - "index": {}, - "index/suffixarray": {}, - "internal": {}, - "internal/abi": {}, - "internal/abi/testdata": {}, - "internal/bisect": {}, - "internal/buildcfg": {}, - "internal/bytealg": {}, - "internal/cfg": {}, - "internal/chacha8rand": {}, - "internal/coverage": {}, - "internal/coverage/calloc": {}, - "internal/coverage/cformat": {}, - "internal/coverage/cmerge": {}, - "internal/coverage/decodecounter": {}, - "internal/coverage/decodemeta": {}, - "internal/coverage/encodecounter": {}, - "internal/coverage/encodemeta": {}, - "internal/coverage/pods": {}, - "internal/coverage/rtcov": {}, - "internal/coverage/slicereader": {}, - "internal/coverage/slicewriter": {}, - "internal/coverage/stringtab": {}, - "internal/coverage/test": {}, - "internal/coverage/uleb128": {}, - "internal/cpu": {}, - "internal/dag": {}, - "internal/diff": {}, - "internal/diff/testdata": {}, - "internal/fmtsort": {}, - "internal/fuzz": {}, - "internal/goarch": {}, - "internal/godebug": {}, - "internal/godebugs": {}, - "internal/goexperiment": {}, - "internal/goos": {}, - "internal/goroot": {}, - "internal/gover": {}, - "internal/goversion": {}, - "internal/intern": {}, - "internal/itoa": {}, - "internal/lazyregexp": {}, - "internal/lazytemplate": {}, - "internal/nettrace": {}, - "internal/obscuretestdata": {}, - "internal/oserror": {}, - "internal/pkgbits": {}, - "internal/platform": {}, - "internal/poll": {}, - "internal/profile": {}, - "internal/race": {}, - "internal/reflectlite": {}, - "internal/safefilepath": {}, - "internal/saferio": {}, - "internal/singleflight": {}, - "internal/syscall": {}, - "internal/syscall/execenv": {}, - "internal/syscall/unix": {}, - "internal/syscall/windows": {}, - "internal/syscall/windows/registry": {}, - "internal/syscall/windows/sysdll": {}, - "internal/sysinfo": {}, - "internal/testenv": {}, - "internal/testlog": {}, - "internal/testpty": {}, - "internal/trace": {}, - "internal/trace/testdata": {}, - "internal/trace/traceviewer": {}, - "internal/trace/traceviewer/format": {}, - "internal/trace/traceviewer/static": {}, - "internal/trace/v2": {}, - "internal/trace/v2/event": {}, - "internal/trace/v2/event/go122": {}, - "internal/trace/v2/internal": {}, - "internal/trace/v2/internal/testgen": {}, - "internal/trace/v2/internal/testgen/go122": {}, - "internal/trace/v2/raw": {}, - "internal/trace/v2/testdata": {}, - "internal/trace/v2/testdata/cmd": {}, - "internal/trace/v2/testdata/cmd/gotraceraw": {}, - "internal/trace/v2/testdata/cmd/gotracevalidate": {}, - "internal/trace/v2/testdata/fuzz": {}, - "internal/trace/v2/testdata/fuzz/FuzzReader": {}, - "internal/trace/v2/testdata/generators": {}, - "internal/trace/v2/testdata/testprog": {}, - "internal/trace/v2/testdata/tests": {}, - "internal/trace/v2/testtrace": {}, - "internal/trace/v2/version": {}, - "internal/txtar": {}, - "internal/types": {}, - "internal/types/errors": {}, - "internal/types/testdata": {}, - "internal/types/testdata/check": {}, - "internal/types/testdata/check/decls2": {}, - "internal/types/testdata/check/importdecl0": {}, - "internal/types/testdata/check/importdecl1": {}, - "internal/types/testdata/check/issue25008": {}, - "internal/types/testdata/examples": {}, - "internal/types/testdata/fixedbugs": {}, - "internal/types/testdata/spec": {}, - "internal/unsafeheader": {}, - "internal/xcoff": {}, - "internal/xcoff/testdata": {}, - "internal/zstd": {}, - "internal/zstd/testdata": {}, - "io": {}, - "io/fs": {}, - "io/ioutil": {}, - "io/ioutil/testdata": {}, - "iter": {}, - "log": {}, - "log/internal": {}, - "log/slog": {}, - "log/slog/internal": {}, - "log/slog/internal/benchmarks": {}, - "log/slog/internal/buffer": {}, - "log/slog/internal/slogtest": {}, - "log/syslog": {}, - "maps": {}, - "math": {}, - "math/big": {}, - "math/bits": {}, - "math/cmplx": {}, - "math/rand": {}, - "math/rand/v2": {}, - "mime": {}, - "mime/multipart": {}, - "mime/multipart/testdata": {}, - "mime/quotedprintable": {}, - "mime/testdata": {}, - "net": {}, - "net/http": {}, - "net/http/cgi": {}, - "net/http/cookiejar": {}, - "net/http/fcgi": {}, - "net/http/httptest": {}, - "net/http/httptrace": {}, - "net/http/httputil": {}, - "net/http/internal": {}, - "net/http/internal/ascii": {}, - "net/http/internal/testcert": {}, - "net/http/pprof": {}, - "net/http/pprof/testdata": {}, - "net/http/testdata": {}, - "net/internal": {}, - "net/internal/cgotest": {}, - "net/internal/socktest": {}, - "net/mail": {}, - "net/netip": {}, - "net/rpc": {}, - "net/rpc/jsonrpc": {}, - "net/smtp": {}, - "net/testdata": {}, - "net/textproto": {}, - "net/url": {}, - "os": {}, - "os/exec": {}, - "os/exec/internal": {}, - "os/exec/internal/fdtest": {}, - "os/signal": {}, - "os/testdata": {}, - "os/testdata/dirfs": {}, - "os/testdata/dirfs/dir": {}, - "os/testdata/issue37161": {}, - "os/user": {}, - "path": {}, - "path/filepath": {}, - "plugin": {}, - "reflect": {}, - "reflect/internal": {}, - "reflect/internal/example1": {}, - "reflect/internal/example2": {}, - "regexp": {}, - "regexp/syntax": {}, - "regexp/testdata": {}, - "runtime": {}, - "runtime/asan": {}, - "runtime/cgo": {}, - "runtime/coverage": {}, - "runtime/coverage/testdata": {}, - "runtime/coverage/testdata/issue56006": {}, - "runtime/coverage/testdata/issue59563": {}, - "runtime/debug": {}, - "runtime/debug/testdata": {}, - "runtime/debug/testdata/fuzz": {}, - "runtime/debug/testdata/fuzz/FuzzParseBuildInfoRoundTrip": {}, - "runtime/internal": {}, - "runtime/internal/atomic": {}, - "runtime/internal/math": {}, - "runtime/internal/startlinetest": {}, - "runtime/internal/sys": {}, - "runtime/internal/syscall": {}, - "runtime/internal/wasitest": {}, - "runtime/internal/wasitest/testdata": {}, - "runtime/metrics": {}, - "runtime/msan": {}, - "runtime/pprof": {}, - "runtime/pprof/testdata": {}, - "runtime/pprof/testdata/mappingtest": {}, - "runtime/race": {}, - "runtime/race/internal": {}, - "runtime/race/internal/amd64v1": {}, - "runtime/race/internal/amd64v3": {}, - "runtime/race/testdata": {}, - "runtime/testdata": {}, - "runtime/testdata/testexithooks": {}, - "runtime/testdata/testfaketime": {}, - "runtime/testdata/testfds": {}, - "runtime/testdata/testprog": {}, - "runtime/testdata/testprogcgo": {}, - "runtime/testdata/testprogcgo/windows": {}, - "runtime/testdata/testprognet": {}, - "runtime/testdata/testsuid": {}, - "runtime/testdata/testwinlib": {}, - "runtime/testdata/testwinlibsignal": {}, - "runtime/testdata/testwinlibthrow": {}, - "runtime/testdata/testwinsignal": {}, - "runtime/testdata/testwintls": {}, - "runtime/trace": {}, - "slices": {}, - "sort": {}, - "strconv": {}, - "strconv/testdata": {}, - "strings": {}, - "sync": {}, - "sync/atomic": {}, - "syscall": {}, - "syscall/js": {}, - "testdata": {}, - "testing": {}, - "testing/fstest": {}, - "testing/internal": {}, - "testing/internal/testdeps": {}, - "testing/iotest": {}, - "testing/quick": {}, - "testing/slogtest": {}, - "text": {}, - "text/scanner": {}, - "text/tabwriter": {}, - "text/template": {}, - "text/template/parse": {}, - "text/template/testdata": {}, - "time": {}, - "time/testdata": {}, - "time/tzdata": {}, - "unicode": {}, - "unicode/utf16": {}, - "unicode/utf8": {}, - "unsafe": {}, - "vendor": {}, - "vendor/golang.org": {}, - "vendor/golang.org/x": {}, - "vendor/golang.org/x/crypto": {}, - "vendor/golang.org/x/crypto/chacha20": {}, - "vendor/golang.org/x/crypto/chacha20poly1305": {}, - "vendor/golang.org/x/crypto/cryptobyte": {}, - "vendor/golang.org/x/crypto/cryptobyte/asn1": {}, - "vendor/golang.org/x/crypto/hkdf": {}, - "vendor/golang.org/x/crypto/internal": {}, - "vendor/golang.org/x/crypto/internal/alias": {}, - "vendor/golang.org/x/crypto/internal/poly1305": {}, - "vendor/golang.org/x/net": {}, - "vendor/golang.org/x/net/dns": {}, - "vendor/golang.org/x/net/dns/dnsmessage": {}, - "vendor/golang.org/x/net/http": {}, - "vendor/golang.org/x/net/http/httpguts": {}, - "vendor/golang.org/x/net/http/httpproxy": {}, - "vendor/golang.org/x/net/http2": {}, - "vendor/golang.org/x/net/http2/hpack": {}, - "vendor/golang.org/x/net/idna": {}, - "vendor/golang.org/x/net/lif": {}, - "vendor/golang.org/x/net/nettest": {}, - "vendor/golang.org/x/net/route": {}, - "vendor/golang.org/x/sys": {}, - "vendor/golang.org/x/sys/cpu": {}, - "vendor/golang.org/x/text": {}, - "vendor/golang.org/x/text/secure": {}, - "vendor/golang.org/x/text/secure/bidirule": {}, - "vendor/golang.org/x/text/transform": {}, - "vendor/golang.org/x/text/unicode": {}, - "vendor/golang.org/x/text/unicode/bidi": {}, - "vendor/golang.org/x/text/unicode/norm": {}, + "archive": {}, + "archive/tar": {}, + "archive/zip": {}, + "arena": {}, + "bufio": {}, + "builtin": {}, + "bytes": {}, + "cmp": {}, + "compress": {}, + "compress/bzip2": {}, + "compress/flate": {}, + "compress/gzip": {}, + "compress/lzw": {}, + "compress/zlib": {}, + "container": {}, + "container/heap": {}, + "container/list": {}, + "container/ring": {}, + "context": {}, + "crypto": {}, + "crypto/aes": {}, + "crypto/boring": {}, + "crypto/cipher": {}, + "crypto/des": {}, + "crypto/dsa": {}, + "crypto/ecdh": {}, + "crypto/ecdsa": {}, + "crypto/ed25519": {}, + "crypto/ed25519/internal": {}, + "crypto/ed25519/internal/edwards25519": {}, + "crypto/ed25519/internal/edwards25519/field": {}, + "crypto/elliptic": {}, + "crypto/elliptic/internal": {}, + "crypto/elliptic/internal/fiat": {}, + "crypto/elliptic/internal/nistec": {}, + "crypto/hmac": {}, + "crypto/internal": {}, + "crypto/internal/alias": {}, + "crypto/internal/bigmod": {}, + "crypto/internal/boring": {}, + "crypto/internal/boring/bbig": {}, + "crypto/internal/boring/bcache": {}, + "crypto/internal/boring/fipstls": {}, + "crypto/internal/boring/sig": {}, + "crypto/internal/boring/syso": {}, + "crypto/internal/cipherhw": {}, + "crypto/internal/edwards25519": {}, + "crypto/internal/edwards25519/field": {}, + "crypto/internal/nistec": {}, + "crypto/internal/nistec/fiat": {}, + "crypto/internal/randutil": {}, + "crypto/internal/subtle": {}, + "crypto/md5": {}, + "crypto/rand": {}, + "crypto/rc4": {}, + "crypto/rsa": {}, + "crypto/sha1": {}, + "crypto/sha256": {}, + "crypto/sha512": {}, + "crypto/subtle": {}, + "crypto/tls": {}, + "crypto/tls/fipsonly": {}, + "crypto/x509": {}, + "crypto/x509/internal": {}, + "crypto/x509/internal/macos": {}, + "crypto/x509/pkix": {}, + "database": {}, + "database/sql": {}, + "database/sql/driver": {}, + "debug": {}, + "debug/buildinfo": {}, + "debug/dwarf": {}, + "debug/elf": {}, + "debug/gosym": {}, + "debug/macho": {}, + "debug/pe": {}, + "debug/plan9obj": {}, + "embed": {}, + "embed/internal": {}, + "embed/internal/embedtest": {}, + "encoding": {}, + "encoding/ascii85": {}, + "encoding/asn1": {}, + "encoding/base32": {}, + "encoding/base64": {}, + "encoding/binary": {}, + "encoding/csv": {}, + "encoding/gob": {}, + "encoding/hex": {}, + "encoding/json": {}, + "encoding/pem": {}, + "encoding/xml": {}, + "errors": {}, + "expvar": {}, + "flag": {}, + "fmt": {}, + "go": {}, + "go/ast": {}, + "go/build": {}, + "go/build/constraint": {}, + "go/constant": {}, + "go/doc": {}, + "go/doc/comment": {}, + "go/format": {}, + "go/importer": {}, + "go/internal": {}, + "go/internal/gccgoimporter": {}, + "go/internal/gcimporter": {}, + "go/internal/srcimporter": {}, + "go/internal/typeparams": {}, + "go/parser": {}, + "go/printer": {}, + "go/scanner": {}, + "go/token": {}, + "go/types": {}, + "go/types/fixedbugs": {}, + "hash": {}, + "hash/adler32": {}, + "hash/crc32": {}, + "hash/crc64": {}, + "hash/fnv": {}, + "hash/maphash": {}, + "html": {}, + "html/template": {}, + "image": {}, + "image/color": {}, + "image/color/palette": {}, + "image/draw": {}, + "image/gif": {}, + "image/internal": {}, + "image/internal/imageutil": {}, + "image/jpeg": {}, + "image/png": {}, + "index": {}, + "index/suffixarray": {}, + "internal": {}, + "internal/abi": {}, + "internal/bisect": {}, + "internal/buildcfg": {}, + "internal/bytealg": {}, + "internal/cfg": {}, + "internal/coverage": {}, + "internal/coverage/calloc": {}, + "internal/coverage/cformat": {}, + "internal/coverage/cmerge": {}, + "internal/coverage/decodecounter": {}, + "internal/coverage/decodemeta": {}, + "internal/coverage/encodecounter": {}, + "internal/coverage/encodemeta": {}, + "internal/coverage/pods": {}, + "internal/coverage/rtcov": {}, + "internal/coverage/slicereader": {}, + "internal/coverage/slicewriter": {}, + "internal/coverage/stringtab": {}, + "internal/coverage/test": {}, + "internal/coverage/uleb128": {}, + "internal/cpu": {}, + "internal/dag": {}, + "internal/diff": {}, + "internal/execabs": {}, + "internal/fmtsort": {}, + "internal/format": {}, + "internal/fuzz": {}, + "internal/goarch": {}, + "internal/godebug": {}, + "internal/godebugs": {}, + "internal/goexperiment": {}, + "internal/golang.org": {}, + "internal/golang.org/x": {}, + "internal/golang.org/x/net": {}, + "internal/golang.org/x/net/http2": {}, + "internal/golang.org/x/net/http2/hpack": {}, + "internal/goos": {}, + "internal/goroot": {}, + "internal/goversion": {}, + "internal/intern": {}, + "internal/itoa": {}, + "internal/lazyregexp": {}, + "internal/lazytemplate": {}, + "internal/nettrace": {}, + "internal/obscuretestdata": {}, + "internal/oserror": {}, + "internal/pkgbits": {}, + "internal/platform": {}, + "internal/poll": {}, + "internal/pprof": {}, + "internal/pprof/profile": {}, + "internal/profile": {}, + "internal/race": {}, + "internal/reflectlite": {}, + "internal/safefilepath": {}, + "internal/saferio": {}, + "internal/singleflight": {}, + "internal/syscall": {}, + "internal/syscall/execenv": {}, + "internal/syscall/unix": {}, + "internal/syscall/windows": {}, + "internal/syscall/windows/registry": {}, + "internal/syscall/windows/sysdll": {}, + "internal/sysinfo": {}, + "internal/testenv": {}, + "internal/testlog": {}, + "internal/testpty": {}, + "internal/trace": {}, + "internal/txtar": {}, + "internal/types": {}, + "internal/types/errors": {}, + "internal/unsafeheader": {}, + "internal/x": {}, + "internal/x/crypto": {}, + "internal/x/crypto/chacha20poly1305": {}, + "internal/x/crypto/cryptobyte": {}, + "internal/x/crypto/cryptobyte/asn1": {}, + "internal/x/crypto/curve25519": {}, + "internal/x/crypto/hkdf": {}, + "internal/x/crypto/internal": {}, + "internal/x/crypto/internal/chacha20": {}, + "internal/x/crypto/poly1305": {}, + "internal/x/net": {}, + "internal/x/net/dns": {}, + "internal/x/net/dns/dnsmessage": {}, + "internal/x/net/http": {}, + "internal/x/net/http/httpguts": {}, + "internal/x/net/http/httpproxy": {}, + "internal/x/net/http2": {}, + "internal/x/net/http2/hpack": {}, + "internal/x/net/idna": {}, + "internal/x/net/internal": {}, + "internal/x/net/internal/nettest": {}, + "internal/x/net/lif": {}, + "internal/x/net/nettest": {}, + "internal/x/net/route": {}, + "internal/x/text": {}, + "internal/x/text/secure": {}, + "internal/x/text/secure/bidirule": {}, + "internal/x/text/transform": {}, + "internal/x/text/unicode": {}, + "internal/x/text/unicode/bidi": {}, + "internal/x/text/unicode/norm": {}, + "internal/xcoff": {}, + "internal/zstd": {}, + "io": {}, + "io/fs": {}, + "io/ioutil": {}, + "lib9": {}, + "lib9/fmt": {}, + "lib9/utf": {}, + "libbio": {}, + "liblink": {}, + "libmach": {}, + "log": {}, + "log/internal": {}, + "log/slog": {}, + "log/slog/internal": {}, + "log/slog/internal/benchmarks": {}, + "log/slog/internal/buffer": {}, + "log/slog/internal/slogtest": {}, + "log/syslog": {}, + "maps": {}, + "math": {}, + "math/big": {}, + "math/bits": {}, + "math/cmplx": {}, + "math/rand": {}, + "mime": {}, + "mime/multipart": {}, + "mime/quotedprintable": {}, + "net": {}, + "net/http": {}, + "net/http/cgi": {}, + "net/http/cookiejar": {}, + "net/http/fcgi": {}, + "net/http/httptest": {}, + "net/http/httptrace": {}, + "net/http/httputil": {}, + "net/http/internal": {}, + "net/http/internal/ascii": {}, + "net/http/internal/testcert": {}, + "net/http/pprof": {}, + "net/internal": {}, + "net/internal/socktest": {}, + "net/mail": {}, + "net/netip": {}, + "net/rpc": {}, + "net/rpc/jsonrpc": {}, + "net/smtp": {}, + "net/textproto": {}, + "net/url": {}, + "os": {}, + "os/exec": {}, + "os/exec/internal": {}, + "os/exec/internal/fdtest": {}, + "os/signal": {}, + "os/signal/internal": {}, + "os/signal/internal/pty": {}, + "os/user": {}, + "path": {}, + "path/filepath": {}, + "pkg": {}, + "pkg/archive": {}, + "pkg/archive/tar": {}, + "pkg/archive/zip": {}, + "pkg/bufio": {}, + "pkg/builtin": {}, + "pkg/bytes": {}, + "pkg/compress": {}, + "pkg/compress/bzip2": {}, + "pkg/compress/flate": {}, + "pkg/compress/gzip": {}, + "pkg/compress/lzw": {}, + "pkg/compress/zlib": {}, + "pkg/container": {}, + "pkg/container/heap": {}, + "pkg/container/list": {}, + "pkg/container/ring": {}, + "pkg/crypto": {}, + "pkg/crypto/aes": {}, + "pkg/crypto/cipher": {}, + "pkg/crypto/des": {}, + "pkg/crypto/dsa": {}, + "pkg/crypto/ecdsa": {}, + "pkg/crypto/elliptic": {}, + "pkg/crypto/hmac": {}, + "pkg/crypto/md5": {}, + "pkg/crypto/rand": {}, + "pkg/crypto/rc4": {}, + "pkg/crypto/rsa": {}, + "pkg/crypto/sha1": {}, + "pkg/crypto/sha256": {}, + "pkg/crypto/sha512": {}, + "pkg/crypto/subtle": {}, + "pkg/crypto/tls": {}, + "pkg/crypto/x509": {}, + "pkg/crypto/x509/pkix": {}, + "pkg/database": {}, + "pkg/database/sql": {}, + "pkg/database/sql/driver": {}, + "pkg/debug": {}, + "pkg/debug/dwarf": {}, + "pkg/debug/elf": {}, + "pkg/debug/gosym": {}, + "pkg/debug/macho": {}, + "pkg/debug/pe": {}, + "pkg/debug/plan9obj": {}, + "pkg/encoding": {}, + "pkg/encoding/ascii85": {}, + "pkg/encoding/asn1": {}, + "pkg/encoding/base32": {}, + "pkg/encoding/base64": {}, + "pkg/encoding/binary": {}, + "pkg/encoding/csv": {}, + "pkg/encoding/gob": {}, + "pkg/encoding/hex": {}, + "pkg/encoding/json": {}, + "pkg/encoding/pem": {}, + "pkg/encoding/xml": {}, + "pkg/errors": {}, + "pkg/expvar": {}, + "pkg/flag": {}, + "pkg/fmt": {}, + "pkg/go": {}, + "pkg/go/ast": {}, + "pkg/go/build": {}, + "pkg/go/doc": {}, + "pkg/go/format": {}, + "pkg/go/parser": {}, + "pkg/go/printer": {}, + "pkg/go/scanner": {}, + "pkg/go/token": {}, + "pkg/hash": {}, + "pkg/hash/adler32": {}, + "pkg/hash/crc32": {}, + "pkg/hash/crc64": {}, + "pkg/hash/fnv": {}, + "pkg/html": {}, + "pkg/html/template": {}, + "pkg/image": {}, + "pkg/image/color": {}, + "pkg/image/color/palette": {}, + "pkg/image/draw": {}, + "pkg/image/gif": {}, + "pkg/image/jpeg": {}, + "pkg/image/png": {}, + "pkg/index": {}, + "pkg/index/suffixarray": {}, + "pkg/io": {}, + "pkg/io/ioutil": {}, + "pkg/log": {}, + "pkg/log/syslog": {}, + "pkg/math": {}, + "pkg/math/big": {}, + "pkg/math/cmplx": {}, + "pkg/math/rand": {}, + "pkg/mime": {}, + "pkg/mime/multipart": {}, + "pkg/net": {}, + "pkg/net/http": {}, + "pkg/net/http/cgi": {}, + "pkg/net/http/cookiejar": {}, + "pkg/net/http/fcgi": {}, + "pkg/net/http/httptest": {}, + "pkg/net/http/httputil": {}, + "pkg/net/http/pprof": {}, + "pkg/net/mail": {}, + "pkg/net/rpc": {}, + "pkg/net/rpc/jsonrpc": {}, + "pkg/net/smtp": {}, + "pkg/net/textproto": {}, + "pkg/net/url": {}, + "pkg/os": {}, + "pkg/os/exec": {}, + "pkg/os/signal": {}, + "pkg/os/user": {}, + "pkg/path": {}, + "pkg/path/filepath": {}, + "pkg/reflect": {}, + "pkg/regexp": {}, + "pkg/regexp/syntax": {}, + "pkg/runtime": {}, + "pkg/runtime/cgo": {}, + "pkg/runtime/debug": {}, + "pkg/runtime/pprof": {}, + "pkg/runtime/race": {}, + "pkg/sort": {}, + "pkg/strconv": {}, + "pkg/strings": {}, + "pkg/sync": {}, + "pkg/sync/atomic": {}, + "pkg/syscall": {}, + "pkg/testing": {}, + "pkg/testing/iotest": {}, + "pkg/testing/quick": {}, + "pkg/text": {}, + "pkg/text/scanner": {}, + "pkg/text/tabwriter": {}, + "pkg/text/template": {}, + "pkg/text/template/parse": {}, + "pkg/time": {}, + "pkg/unicode": {}, + "pkg/unicode/utf16": {}, + "pkg/unicode/utf8": {}, + "pkg/unsafe": {}, + "plugin": {}, + "reflect": {}, + "reflect/internal": {}, + "reflect/internal/example1": {}, + "reflect/internal/example2": {}, + "regexp": {}, + "regexp/syntax": {}, + "runtime": {}, + "runtime/asan": {}, + "runtime/cgo": {}, + "runtime/coverage": {}, + "runtime/debug": {}, + "runtime/internal": {}, + "runtime/internal/atomic": {}, + "runtime/internal/math": {}, + "runtime/internal/startlinetest": {}, + "runtime/internal/sys": {}, + "runtime/internal/syscall": {}, + "runtime/internal/wasitest": {}, + "runtime/metrics": {}, + "runtime/msan": {}, + "runtime/pprof": {}, + "runtime/pprof/internal": {}, + "runtime/pprof/internal/profile": {}, + "runtime/pprof/internal/protopprof": {}, + "runtime/race": {}, + "runtime/race/internal": {}, + "runtime/race/internal/amd64v1": {}, + "runtime/race/internal/amd64v3": {}, + "runtime/trace": {}, + "slices": {}, + "sort": {}, + "strconv": {}, + "strings": {}, + "sync": {}, + "sync/atomic": {}, + "syscall": {}, + "syscall/js": {}, + "testing": {}, + "testing/fstest": {}, + "testing/internal": {}, + "testing/internal/testdeps": {}, + "testing/iotest": {}, + "testing/quick": {}, + "testing/slogtest": {}, + "text": {}, + "text/scanner": {}, + "text/tabwriter": {}, + "text/template": {}, + "text/template/parse": {}, + "time": {}, + "time/tzdata": {}, + "unicode": {}, + "unicode/utf16": {}, + "unicode/utf8": {}, + "unsafe": {}, + "vendor": {}, + "vendor/golang.org": {}, + "vendor/golang.org/x": {}, + "vendor/golang.org/x/crypto": {}, + "vendor/golang.org/x/crypto/chacha20": {}, + "vendor/golang.org/x/crypto/chacha20poly1305": {}, + "vendor/golang.org/x/crypto/cryptobyte": {}, + "vendor/golang.org/x/crypto/cryptobyte/asn1": {}, + "vendor/golang.org/x/crypto/curve25519": {}, + "vendor/golang.org/x/crypto/curve25519/internal": {}, + "vendor/golang.org/x/crypto/curve25519/internal/field": {}, + "vendor/golang.org/x/crypto/hkdf": {}, + "vendor/golang.org/x/crypto/internal": {}, + "vendor/golang.org/x/crypto/internal/alias": {}, + "vendor/golang.org/x/crypto/internal/chacha20": {}, + "vendor/golang.org/x/crypto/internal/poly1305": {}, + "vendor/golang.org/x/crypto/internal/subtle": {}, + "vendor/golang.org/x/crypto/poly1305": {}, + "vendor/golang.org/x/net": {}, + "vendor/golang.org/x/net/dns": {}, + "vendor/golang.org/x/net/dns/dnsmessage": {}, + "vendor/golang.org/x/net/http": {}, + "vendor/golang.org/x/net/http/httpguts": {}, + "vendor/golang.org/x/net/http/httpproxy": {}, + "vendor/golang.org/x/net/http2": {}, + "vendor/golang.org/x/net/http2/hpack": {}, + "vendor/golang.org/x/net/idna": {}, + "vendor/golang.org/x/net/lif": {}, + "vendor/golang.org/x/net/nettest": {}, + "vendor/golang.org/x/net/route": {}, + "vendor/golang.org/x/sys": {}, + "vendor/golang.org/x/sys/cpu": {}, + "vendor/golang.org/x/text": {}, + "vendor/golang.org/x/text/secure": {}, + "vendor/golang.org/x/text/secure/bidirule": {}, + "vendor/golang.org/x/text/transform": {}, + "vendor/golang.org/x/text/unicode": {}, + "vendor/golang.org/x/text/unicode/bidi": {}, + "vendor/golang.org/x/text/unicode/norm": {}, + "vendor/golang_org": {}, + "vendor/golang_org/x": {}, + "vendor/golang_org/x/crypto": {}, + "vendor/golang_org/x/crypto/chacha20poly1305": {}, + "vendor/golang_org/x/crypto/chacha20poly1305/internal": {}, + "vendor/golang_org/x/crypto/chacha20poly1305/internal/chacha20": {}, + "vendor/golang_org/x/crypto/cryptobyte": {}, + "vendor/golang_org/x/crypto/cryptobyte/asn1": {}, + "vendor/golang_org/x/crypto/curve25519": {}, + "vendor/golang_org/x/crypto/internal": {}, + "vendor/golang_org/x/crypto/internal/chacha20": {}, + "vendor/golang_org/x/crypto/poly1305": {}, + "vendor/golang_org/x/net": {}, + "vendor/golang_org/x/net/dns": {}, + "vendor/golang_org/x/net/dns/dnsmessage": {}, + "vendor/golang_org/x/net/http": {}, + "vendor/golang_org/x/net/http/httpguts": {}, + "vendor/golang_org/x/net/http/httpproxy": {}, + "vendor/golang_org/x/net/http2": {}, + "vendor/golang_org/x/net/http2/hpack": {}, + "vendor/golang_org/x/net/idna": {}, + "vendor/golang_org/x/net/internal": {}, + "vendor/golang_org/x/net/internal/nettest": {}, + "vendor/golang_org/x/net/lex": {}, + "vendor/golang_org/x/net/lex/httplex": {}, + "vendor/golang_org/x/net/lif": {}, + "vendor/golang_org/x/net/nettest": {}, + "vendor/golang_org/x/net/proxy": {}, + "vendor/golang_org/x/net/route": {}, + "vendor/golang_org/x/text": {}, + "vendor/golang_org/x/text/secure": {}, + "vendor/golang_org/x/text/secure/bidirule": {}, + "vendor/golang_org/x/text/transform": {}, + "vendor/golang_org/x/text/unicode": {}, + "vendor/golang_org/x/text/unicode/bidi": {}, + "vendor/golang_org/x/text/unicode/norm": {}, + "vendor/golang_org/x/text/width": {}, } From 705690329550fc0104539c6e63c0bc8ebc33db5e Mon Sep 17 00:00:00 2001 From: Zxilly Date: Thu, 1 Feb 2024 23:05:42 +0800 Subject: [PATCH 06/12] test: update error test cases --- package_test.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/package_test.go b/package_test.go index 744ccd0..e9f49f8 100644 --- a/package_test.go +++ b/package_test.go @@ -308,14 +308,14 @@ func TestClassifyPackage(t *testing.T) { {"type..hash.text/template/parse", "C:/Go/src/text/template/parse", ClassGenerated}, {"unicode", "C:/Go/src/unicode", ClassSTD}, {"unicode/utf8", "C:/Go/src/unicode/utf8", ClassSTD}, - {"vendor/golang_org/x/net/http2/hpack", "c:/go/src/vendor/golang_org/x/net/http2/hpack", ClassVendor}, - {"vendor/golang_org/x/text/unicode/norm", "c:/go/src/vendor/golang_org/x/text/unicode/norm", ClassVendor}, - {"vendor/golang_org/x/net/dns/dnsmessage", ".", ClassVendor}, - {"vendor/golang_org/x/text/unicode/bidi", "c:/go/src/vendor/golang_org/x/text/unicode/bidi", ClassVendor}, + {"vendor/golang_org/x/net/http2/hpack", "c:/go/src/vendor/golang_org/x/net/http2/hpack", ClassSTD}, + {"vendor/golang_org/x/text/unicode/norm", "c:/go/src/vendor/golang_org/x/text/unicode/norm", ClassSTD}, + {"vendor/golang_org/x/net/dns/dnsmessage", ".", ClassSTD}, + {"vendor/golang_org/x/text/unicode/bidi", "c:/go/src/vendor/golang_org/x/text/unicode/bidi", ClassSTD}, {"github.com/go-ole/go-ole", "c:/go/src/github.com/go-ole/go-ole", ClassVendor}, - {"vendor/golang_org/x/text/secure/bidirule", "c:/go/src/vendor/golang_org/x/text/secure/bidirule", ClassVendor}, - {"vendor/golang_org/x/crypto/poly1305", "c:/go/src/vendor/golang_org/x/crypto/poly1305", ClassVendor}, - {"vendor/golang_org/x/crypto/curve25519", "c:/go/src/vendor/golang_org/x/crypto/curve25519", ClassVendor}, + {"vendor/golang_org/x/text/secure/bidirule", "c:/go/src/vendor/golang_org/x/text/secure/bidirule", ClassSTD}, + {"vendor/golang_org/x/crypto/poly1305", "c:/go/src/vendor/golang_org/x/crypto/poly1305", ClassSTD}, + {"vendor/golang_org/x/crypto/curve25519", "c:/go/src/vendor/golang_org/x/crypto/curve25519", ClassSTD}, {"github.com/kbinani/screenshot", "c:/go/src/github.com/kbinani/screenshot", ClassVendor}, {"github.com/go-ole/go-ole/oleutil", "c:/go/src/github.com/go-ole/go-ole/oleutil", ClassVendor}, {"github.com/shirou/gopsutil/net", ".", ClassUnknown}, @@ -325,22 +325,22 @@ func TestClassifyPackage(t *testing.T) { {"github.com/shirou/gopsutil/cpu", "c:/go/src/github.com/shirou/gopsutil/cpu", ClassVendor}, {"github.com/StackExchange/wmi", "c:/go/src/github.com/StackExchange/wmi", ClassVendor}, {"github.com/shirou/gopsutil/internal/common", "c:/go/src/github.com/shirou/gopsutil/internal/common", ClassVendor}, - {"vendor/golang_org/x/net/idna", "c:/go/src/vendor/golang_org/x/net/idna", ClassVendor}, + {"vendor/golang_org/x/net/idna", "c:/go/src/vendor/golang_org/x/net/idna", ClassSTD}, {"github.com/lxn/win", "c:/go/src/github.com/lxn/win", ClassVendor}, {"github.com/shirou/gopsutil/host", "c:/go/src/github.com/shirou/gopsutil/host", ClassVendor}, {"golang.org/x/sys/windows", "c:/go/src/golang.org/x/sys/windows", ClassVendor}, {"", "c:/go/src/internal/bytealg", ClassUnknown}, - {"vendor/golang_org/x/net/http/httpguts", "c:/go/src/vendor/golang_org/x/net/http/httpguts", ClassVendor}, - {"vendor/golang_org/x/crypto/internal/chacha20", "c:/go/src/vendor/golang_org/x/crypto/internal/chacha20", ClassVendor}, - {"vendor/golang_org/x/crypto/cryptobyte", "c:/go/src/vendor/golang_org/x/crypto/cryptobyte", ClassVendor}, - {"vendor/golang_org/x/crypto/chacha20poly1305", "c:/go/src/vendor/golang_org/x/crypto/chacha20poly1305", ClassVendor}, + {"vendor/golang_org/x/net/http/httpguts", "c:/go/src/vendor/golang_org/x/net/http/httpguts", ClassSTD}, + {"vendor/golang_org/x/crypto/internal/chacha20", "c:/go/src/vendor/golang_org/x/crypto/internal/chacha20", ClassSTD}, + {"vendor/golang_org/x/crypto/cryptobyte", "c:/go/src/vendor/golang_org/x/crypto/cryptobyte", ClassSTD}, + {"vendor/golang_org/x/crypto/chacha20poly1305", "c:/go/src/vendor/golang_org/x/crypto/chacha20poly1305", ClassSTD}, {"golang.org/x/sys/windows/registry", "c:/go/src/golang.org/x/sys/windows/registry", ClassVendor}, - {"vendor/golang_org/x/text/transform", ".", ClassVendor}, + {"vendor/golang_org/x/text/transform", ".", ClassSTD}, {"golang.org/x/sys/windows/svc/mgr", ".", ClassUnknown}, {"github.com/shirou/gopsutil/mem", ".", ClassUnknown}, {"github.com/shirou/gopsutil/process", "c:/go/src/github.com/shirou/gopsutil/process", ClassVendor}, {"github.com/iamacarpet/go-win64api/shared", "c:/go/src/github.com/iamacarpet/go-win64api/shared", ClassVendor}, - {"vendor/golang_org/x/net/http/httpproxy", "c:/go/src/vendor/golang_org/x/net/http/httpproxy", ClassVendor}, + {"vendor/golang_org/x/net/http/httpproxy", "c:/go/src/vendor/golang_org/x/net/http/httpproxy", ClassSTD}, {"github.com/shirou/w32", "c:/go/src/github.com/shirou/w32", ClassVendor}, } From 53ba31fe0455b139439ce65b7e10dc562ffd137c Mon Sep 17 00:00:00 2001 From: Zxilly Date: Fri, 2 Feb 2024 06:00:03 +0800 Subject: [PATCH 07/12] refactor: rewrite moduledata generate --- gen/moduledata.go | 496 +++++++------- gen/static.go | 2 + moduledata.go | 57 +- moduledata_gen.go | 1619 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 1744 insertions(+), 430 deletions(-) diff --git a/gen/moduledata.go b/gen/moduledata.go index d6c1b30..2dca22d 100644 --- a/gen/moduledata.go +++ b/gen/moduledata.go @@ -19,293 +19,299 @@ package main import ( "bytes" + "context" "fmt" + "github.com/google/go-github/v58/github" + "go/ast" "go/format" + "go/parser" + "golang.org/x/mod/semver" "os" - "reflect" + "regexp" + "sort" + "strconv" "strings" ) -func typeDef(b *bytes.Buffer, st reflect.Type, bits int) { - typeName := "uint64" - if bits == 32 { - typeName = "uint32" +var moduleDataMatcher = regexp.MustCompile(`(?m:type moduledata struct {[^}]+})`) + +// generateModuleDataSources +// returns a map of moduledata sources for each go version, from 1.5 to the latest we know so far. +func getModuleDataSources() (map[int]string, error) { + ret := make(map[int]string) + + f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) + if err != nil { + return nil, fmt.Errorf("error when opening goversions.csv: %w", err) + } + knownVersion, err := getCsvStoredGoversions(f) + if err != nil { + return nil, fmt.Errorf("error when getting stored go versions: %w", err) } - _, _ = fmt.Fprintf(b, "type %s%d struct {\n", st.Name(), bits) - - for i := 0; i < st.NumField(); i++ { - field := st.Field(i) - fieldName := strings.ToUpper(field.Name[:1]) + field.Name[1:] - t := field.Type.Kind() - switch t { - case reflect.Uintptr: - _, _ = fmt.Fprintf(b, "%s %s\n", fieldName, typeName) - case reflect.String: - _, _ = fmt.Fprintf(b, "%s, %[1]slen %s\n", fieldName, typeName) - case reflect.Pointer: - _, _ = fmt.Fprintf(b, "%s %s\n", fieldName, typeName) - case reflect.Slice: - _, _ = fmt.Fprintf(b, "%s, %[1]slen, %[1]scap %s\n", fieldName, typeName) - - default: - panic(fmt.Sprintf("unhandled type: %+v", t)) + knownVersionSlice := make([]string, 0, len(knownVersion)) + + matcher := regexp.MustCompile(`[a-zA-Z]`) + for ver := range knownVersion { + // rc/beta version not in consideration + if matcher.MatchString(ver[2:]) { + continue } + + knownVersionSlice = append(knownVersionSlice, semver.MajorMinor("v"+strings.TrimPrefix(ver, "go"))) } + semver.Sort(knownVersionSlice) - _, _ = fmt.Fprint(b, "}\n\n") -} + latest := knownVersionSlice[len(knownVersionSlice)-1] -func toModuledata(b *bytes.Buffer, st reflect.Type, bits int) { - _, _ = fmt.Fprintf(b, "func (md %s%d) toModuledata() moduledata {\n", st.Name(), bits) - _, _ = fmt.Fprint(b, "return moduledata{\n") - - for _, names := range [][2]string{ - {"Text", "Text"}, - {"NoPtrData", "Noptrdata"}, - {"Data", "Data"}, - {"Bss", "Bss"}, - {"NoPtrBss", "Noptrbss"}, - {"Types", "Types"}, - } { - modFieldE(b, st, bits, names[0], names[1]) + maxMinor, err := strconv.Atoi(strings.Split(latest, ".")[1]) + if err != nil { + return nil, fmt.Errorf("error when getting latest go version: %w, %s", err, latest) } - for _, names := range [][2]string{ - {"Typelink", "Typelinks"}, - {"ITabLink", "Itablinks"}, - {"FuncTab", "Ftab"}, - {"PCLNTab", "Pclntable"}, - } { - modFieldLen(b, st, bits, names[0], names[1]) - } + for i := 5; i <= maxMinor; i++ { + fmt.Println("Fetching moduledata for go1." + strconv.Itoa(i) + "...") + branch := fmt.Sprintf("release-branch.go1.%d", i) + contents, _, _, err := githubClient.Repositories.GetContents( + context.Background(), + "golang", "go", + "src/runtime/symtab.go", + &github.RepositoryContentGetOptions{Ref: branch}) + if err != nil { + return nil, err + } - modFieldVal(b, st, bits, "GoFunc", "Gofunc") + content, err := contents.GetContent() + if err != nil { + return nil, err + } - _, _ = fmt.Fprint(b, "}\n}\n\n") -} + structStr := moduleDataMatcher.FindString(content) + if structStr == "" { + return nil, fmt.Errorf("moduledata struct not found in symtab.go") + } -func modFieldE(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { - endName := "E" + strings.ToLower(parsedName) - if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { - return - } - if bits == 32 { - _, _ = fmt.Fprintf(b, "%sAddr: uint64(md.%[3]s),\n%[1]sLen: uint64(md.%s - md.%s),\n", modName, endName, parsedName) - } else { - _, _ = fmt.Fprintf(b, "%sAddr: md.%[3]s,\n%[1]sLen: md.%s - md.%s,\n", modName, endName, parsedName) + // make it an expression for further parse + structStr = strings.TrimPrefix(structStr, "type moduledata ") + + ret[i] = structStr } + + return ret, nil } -func modFieldLen(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { - lenName := parsedName + "len" - if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { - return - } - if bits == 32 { - _, _ = fmt.Fprintf(b, "%sAddr: uint64(md.%s),\n%[1]sLen: uint64(md.%[3]s),\n", modName, parsedName, lenName) - } else { - _, _ = fmt.Fprintf(b, "%sAddr: md.%s,\n%[1]sLen: md.%[3]s,\n", modName, parsedName, lenName) - } +type moduleDataGenerator struct { + buf *bytes.Buffer + + knownVersions []int } -func modFieldVal(b *bytes.Buffer, st reflect.Type, bits int, modName, parsedName string) { - if _, ok := st.FieldByName(strings.ToLower(parsedName)); !ok { - return - } - if bits == 32 { - _, _ = fmt.Fprintf(b, "%sVal: uint64(md.%s),\n", modName, parsedName) - } else { - _, _ = fmt.Fprintf(b, "%sVal: md.%s,\n", modName, parsedName) - } +func (g *moduleDataGenerator) init() { + g.buf = &bytes.Buffer{} + g.buf.WriteString(moduleDataHeader) } -func generateModuleData() { - b := &bytes.Buffer{} - b.WriteString(moduleDataHeader) - - for _, iface := range []any{ - moduledata20{}, - moduledata18{}, - moduledata16{}, - moduledata8{}, - moduledata7{}, - moduledata5{}, - } { - o := reflect.TypeOf(iface) - typeDef(b, o, 64) - toModuledata(b, o, 64) - typeDef(b, o, 32) - toModuledata(b, o, 32) - } +func (g *moduleDataGenerator) add(versionCode int, code string) error { + g.knownVersions = append(g.knownVersions, versionCode) - out, err := format.Source(b.Bytes()) + err := g.writeVersionedModuleData(versionCode, code) if err != nil { - panic(err) + return err } - err = os.WriteFile(moduleDataOutputFile, out, 0o666) - if err != nil { - panic(err) - } + return nil } -/* - Internal module structures from Go's runtime. - TODO: auto extract from golang source runtime package. -*/ - -// Moduledata structure for Go 1.20 and newer (at least up to the last field covered here) - -type moduledata20 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - covctrs, ecovctrs uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - rodata uintptr - gofunc uintptr // go.func.* - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab +func (g *moduleDataGenerator) writeSelector() { + g.writeln("func selectModuleData(v int, bits int) modulable {") + g.writeln("switch {") + + for _, versionCode := range g.knownVersions { + for _, bits := range []int{32, 64} { + g.writeln("case v == %d && bits == %d:", versionCode, bits) + g.writeln("return &%s{}", g.generateTypeName(versionCode, bits)) + } + } + g.writeln("default:") + g.writeln(`panic(fmt.Sprintf("unsupported go version %%d", v))`) + + g.writeln("}\n}\n") + } -// Moduledata structure for Go 1.18 and Go 1.19 - -type moduledata18 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - rodata uintptr - gofunc uintptr // go.func.* - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab +func (*moduleDataGenerator) generateTypeName(versionCode int, bits int) string { + return fmt.Sprintf("moduledata_1_%d_%d", versionCode, bits) } -// Moduledata structure for Go 1.16 to 1.17 - -type moduledata16 struct { - pcHeader *pcHeader - funcnametab []byte - cutab []uint32 - filetab []byte - pctab []byte - pclntable []byte - ftab []functab - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab +func (*moduleDataGenerator) wrapValue(name string, bits int) string { + if bits == 32 { + return fmt.Sprintf("uint64(%s)", name) + } + return name } -// Moduledata structure for Go 1.8 to 1.15 - -type moduledata8 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - textsectmap []textsect - typelinks []int32 // offsets from types - itablinks []*itab +func (*moduleDataGenerator) title(s string) string { + return strings.ToUpper(s[:1]) + s[1:] } -// Moduledata structure for Go 1.7 - -type moduledata7 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr - - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr - types, etypes uintptr - - typelinks []int32 // offsets from types - itablinks []*itab +func (g *moduleDataGenerator) writeln(format string, a ...interface{}) { + _, _ = fmt.Fprintf(g.buf, format+"\n", a...) } -// Moduledata structure for Go 1.5 to 1.6 +func (g *moduleDataGenerator) writeVersionedModuleData(versionCode int, code string) error { + expr, err := parser.ParseExpr(code) + if err != nil { + return fmt.Errorf("failed to parse moduledata expression: %w", err) + } -type moduledata5 struct { - pclntable []byte - ftab []functab - filetab []uint32 - findfunctab uintptr - minpc, maxpc uintptr + writeCode := func(bits int) { + g.writeln("type %s struct {\n", g.generateTypeName(versionCode, bits)) + + fields := make(map[string]struct{}) + expr := expr.(*ast.StructType) + search: + for _, field := range expr.Fields.List { + if len(field.Names) == 0 { + // skip anonymous field + // currently only sys.NotInHeap + continue + } + + for _, name := range field.Names { + if name.Name == "modulename" { + // no more data needed + break search + } + fields[name.Name] = struct{}{} + + switch t := field.Type.(type) { + case *ast.StarExpr: + g.writeln("%s uint%d", g.title(name.Name), bits) + case *ast.ArrayType: + g.writeln("%s, %[1]slen, %[1]scap uint%d", g.title(name.Name), bits) + case *ast.Ident: + switch t.Name { + case "uintptr": + g.writeln("%s uint%d", g.title(name.Name), bits) + case "string": + g.writeln("%s, %[1]slen uint%d", g.title(name.Name), bits) + case "uint8": + g.writeln("%s uint8", g.title(name.Name)) + default: + panic(fmt.Sprintf("unhandled type: %+v", t)) + } + default: + panic(fmt.Sprintf("unhandled type: %+v", t)) + } + } + } + + g.writeln("}\n\n") - text, etext uintptr - noptrdata, enoptrdata uintptr - data, edata uintptr - bss, ebss uintptr - noptrbss, enoptrbss uintptr - end, gcdata, gcbss uintptr + // generate toModuledata method + exist := func(name string) bool { + _, ok := fields[name] + return ok + } - typelinks []*_type + g.writeln("func (md %s) toModuledata() moduledata {", g.generateTypeName(versionCode, bits)) + g.writeln("return moduledata{") + + if exist("text") && exist("etext") { + g.writeln("TextAddr: %s,", g.wrapValue("md.Text", bits)) + g.writeln("TextLen: %s,", g.wrapValue("md.Etext - md.Text", bits)) + } + + if exist("noptrdata") && exist("enoptrdata") { + g.writeln("NoPtrDataAddr: %s,", g.wrapValue("md.Noptrdata", bits)) + g.writeln("NoPtrDataLen: %s,", g.wrapValue("md.Enoptrdata - md.Noptrdata", bits)) + } + + if exist("data") && exist("edata") { + g.writeln("DataAddr: %s,", g.wrapValue("md.Data", bits)) + g.writeln("DataLen: %s,", g.wrapValue("md.Edata - md.Data", bits)) + } + + if exist("bss") && exist("ebss") { + g.writeln("BssAddr: %s,", g.wrapValue("md.Bss", bits)) + g.writeln("BssLen: %s,", g.wrapValue("md.Ebss - md.Bss", bits)) + } + + if exist("noptrbss") && exist("enoptrbss") { + g.writeln("NoPtrBssAddr: %s,", g.wrapValue("md.Noptrbss", bits)) + g.writeln("NoPtrBssLen: %s,", g.wrapValue("md.Enoptrbss - md.Noptrbss", bits)) + } + + if exist("types") && exist("etypes") { + g.writeln("TypesAddr: %s,", g.wrapValue("md.Types", bits)) + g.writeln("TypesLen: %s,", g.wrapValue("md.Etypes - md.Types", bits)) + } + + if exist("typelinks") { + g.writeln("TypelinkAddr: %s,", g.wrapValue("md.Typelinks", bits)) + g.writeln("TypelinkLen: %s,", g.wrapValue("md.Typelinkslen", bits)) + } + + if exist("itablinks") { + g.writeln("ITabLinkAddr: %s,", g.wrapValue("md.Itablinks", bits)) + g.writeln("ITabLinkLen: %s,", g.wrapValue("md.Itablinkslen", bits)) + } + + if exist("ftab") { + g.writeln("FuncTabAddr: %s,", g.wrapValue("md.Ftab", bits)) + g.writeln("FuncTabLen: %s,", g.wrapValue("md.Ftablen", bits)) + } + + if exist("pclntable") { + g.writeln("PCLNTabAddr: %s,", g.wrapValue("md.Pclntable", bits)) + g.writeln("PCLNTabLen: %s,", g.wrapValue("md.Pclntablelen", bits)) + } + + if exist("gofunc") { + g.writeln("GoFuncVal: %s,", g.wrapValue("md.Gofunc", bits)) + } + + g.writeln("}\n}\n") + } + + writeCode(32) + writeCode(64) + + return nil } -// dummy definitions -type initTask struct{} -type pcHeader struct{} -type functab struct{} -type textsect struct{} -type itab struct{} -type ptabEntry struct{} -type modulehash struct{} -type _type struct{} +func generateModuleData() { + sources, err := getModuleDataSources() + if err != nil { + panic(err) + } + + g := moduleDataGenerator{} + g.init() + + versionCodes := make([]int, 0, len(sources)) + for versionCode := range sources { + versionCodes = append(versionCodes, versionCode) + } + + sort.Ints(versionCodes) + + for _, versionCode := range versionCodes { + err = g.add(versionCode, sources[versionCode]) + if err != nil { + panic(err) + } + } + + g.writeSelector() + + out, err := format.Source(g.buf.Bytes()) + if err != nil { + panic(err) + } + + err = os.WriteFile(moduleDataOutputFile, out, 0o666) + if err != nil { + panic(err) + } +} diff --git a/gen/static.go b/gen/static.go index 225d8e7..aebc26b 100644 --- a/gen/static.go +++ b/gen/static.go @@ -104,6 +104,8 @@ const moduleDataHeader = ` package gore +import "fmt" + ` var ( diff --git a/moduledata.go b/moduledata.go index 21731ba..9e11ea0 100644 --- a/moduledata.go +++ b/moduledata.go @@ -24,7 +24,10 @@ import ( "encoding/binary" "errors" "fmt" + "golang.org/x/mod/semver" "io" + "strconv" + "strings" ) // Moduledata extracts the file's moduledata. @@ -256,49 +259,21 @@ func parseModuledata(fileInfo *FileInfo, f fileHandler) (moduledata, error) { return moduledata{}, err } - // buf will hold the struct type that represents the data in the file we are processing. - var buf modulable - is32bit := fileInfo.WordSize == intSize32 - - // Determine what kind of struct we need to extract the module data from the file. - - if GoVersionCompare("go1.20rc1", fileInfo.goversion.Name) <= 0 { - if is32bit { - buf = &moduledata2032{} - } else { - buf = &moduledata2064{} - } - } else if GoVersionCompare("go1.18beta1", fileInfo.goversion.Name) <= 0 { - if is32bit { - buf = &moduledata1832{} - } else { - buf = &moduledata1864{} - } - } else if GoVersionCompare("go1.16beta1", fileInfo.goversion.Name) <= 0 { - if is32bit { - buf = &moduledata1632{} - } else { - buf = &moduledata1664{} - } - } else if GoVersionCompare("go1.8beta1", fileInfo.goversion.Name) <= 0 { - if is32bit { - buf = &moduledata832{} - } else { - buf = &moduledata864{} - } - } else if GoVersionCompare("go1.7beta1", fileInfo.goversion.Name) <= 0 { - if is32bit { - buf = &moduledata732{} - } else { - buf = &moduledata764{} - } + var bits int + if fileInfo.WordSize == intSize32 { + bits = 32 } else { - if is32bit { - buf = &moduledata532{} - } else { - buf = &moduledata564{} - } + bits = 64 + } + + ver := buildSemVerString(fileInfo.goversion.Name) + m := semver.MajorMinor(ver) + verBit, err := strconv.Atoi(strings.Split(m, ".")[1]) + if err != nil { + return moduledata{}, fmt.Errorf("error when parsing the Go version: %w", err) } + // buf will hold the struct type that represents the data in the file we are processing. + buf := selectModuleData(verBit, bits) // Read the module struct from the file. r := bytes.NewReader(data) diff --git a/moduledata_gen.go b/moduledata_gen.go index 0dc96fc..b97782c 100644 --- a/moduledata_gen.go +++ b/moduledata_gen.go @@ -19,7 +19,1226 @@ package gore -type moduledata2064 struct { +import "fmt" + +type moduledata_1_5_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 +} + +func (md moduledata_1_5_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_5_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 +} + +func (md moduledata_1_5_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_6_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 +} + +func (md moduledata_1_6_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_6_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 +} + +func (md moduledata_1_6_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_7_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 +} + +func (md moduledata_1_7_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_7_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 +} + +func (md moduledata_1_7_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_8_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_8_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_8_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 +} + +func (md moduledata_1_8_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_9_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_9_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_9_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 +} + +func (md moduledata_1_9_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_10_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_10_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_10_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 +} + +func (md moduledata_1_10_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_11_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_11_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_11_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 +} + +func (md moduledata_1_11_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_12_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_12_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_12_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 +} + +func (md moduledata_1_12_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_13_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_13_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_13_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 +} + +func (md moduledata_1_13_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_14_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_14_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_14_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 +} + +func (md moduledata_1_14_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_15_32 struct { + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_15_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_15_64 struct { + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 +} + +func (md moduledata_1_15_64) toModuledata() moduledata { + return moduledata{ + TextAddr: md.Text, + TextLen: md.Etext - md.Text, + NoPtrDataAddr: md.Noptrdata, + NoPtrDataLen: md.Enoptrdata - md.Noptrdata, + DataAddr: md.Data, + DataLen: md.Edata - md.Data, + BssAddr: md.Bss, + BssLen: md.Ebss - md.Bss, + NoPtrBssAddr: md.Noptrbss, + NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, + TypelinkAddr: md.Typelinks, + TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, + FuncTabAddr: md.Ftab, + FuncTabLen: md.Ftablen, + PCLNTabAddr: md.Pclntable, + PCLNTabLen: md.Pclntablelen, + } +} + +type moduledata_1_16_32 struct { + PcHeader uint32 + Funcnametab, Funcnametablen, Funcnametabcap uint32 + Cutab, Cutablen, Cutabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Pctab, Pctablen, Pctabcap uint32 + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 +} + +func (md moduledata_1_16_32) toModuledata() moduledata { + return moduledata{ + TextAddr: uint64(md.Text), + TextLen: uint64(md.Etext - md.Text), + NoPtrDataAddr: uint64(md.Noptrdata), + NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), + DataAddr: uint64(md.Data), + DataLen: uint64(md.Edata - md.Data), + BssAddr: uint64(md.Bss), + BssLen: uint64(md.Ebss - md.Bss), + NoPtrBssAddr: uint64(md.Noptrbss), + NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), + TypesAddr: uint64(md.Types), + TypesLen: uint64(md.Etypes - md.Types), + TypelinkAddr: uint64(md.Typelinks), + TypelinkLen: uint64(md.Typelinkslen), + ITabLinkAddr: uint64(md.Itablinks), + ITabLinkLen: uint64(md.Itablinkslen), + FuncTabAddr: uint64(md.Ftab), + FuncTabLen: uint64(md.Ftablen), + PCLNTabAddr: uint64(md.Pclntable), + PCLNTabLen: uint64(md.Pclntablelen), + } +} + +type moduledata_1_16_64 struct { PcHeader uint64 Funcnametab, Funcnametablen, Funcnametabcap uint64 Cutab, Cutablen, Cutabcap uint64 @@ -40,21 +1259,20 @@ type moduledata2064 struct { Ebss uint64 Noptrbss uint64 Enoptrbss uint64 - Covctrs uint64 - Ecovctrs uint64 End uint64 Gcdata uint64 Gcbss uint64 Types uint64 Etypes uint64 - Rodata uint64 - Gofunc uint64 Textsectmap, Textsectmaplen, Textsectmapcap uint64 Typelinks, Typelinkslen, Typelinkscap uint64 Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 } -func (md moduledata2064) toModuledata() moduledata { +func (md moduledata_1_16_64) toModuledata() moduledata { return moduledata{ TextAddr: md.Text, TextLen: md.Etext - md.Text, @@ -76,11 +1294,10 @@ func (md moduledata2064) toModuledata() moduledata { FuncTabLen: md.Ftablen, PCLNTabAddr: md.Pclntable, PCLNTabLen: md.Pclntablelen, - GoFuncVal: md.Gofunc, } } -type moduledata2032 struct { +type moduledata_1_17_32 struct { PcHeader uint32 Funcnametab, Funcnametablen, Funcnametabcap uint32 Cutab, Cutablen, Cutabcap uint32 @@ -101,21 +1318,20 @@ type moduledata2032 struct { Ebss uint32 Noptrbss uint32 Enoptrbss uint32 - Covctrs uint32 - Ecovctrs uint32 End uint32 Gcdata uint32 Gcbss uint32 Types uint32 Etypes uint32 - Rodata uint32 - Gofunc uint32 Textsectmap, Textsectmaplen, Textsectmapcap uint32 Typelinks, Typelinkslen, Typelinkscap uint32 Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 } -func (md moduledata2032) toModuledata() moduledata { +func (md moduledata_1_17_32) toModuledata() moduledata { return moduledata{ TextAddr: uint64(md.Text), TextLen: uint64(md.Etext - md.Text), @@ -137,11 +1353,10 @@ func (md moduledata2032) toModuledata() moduledata { FuncTabLen: uint64(md.Ftablen), PCLNTabAddr: uint64(md.Pclntable), PCLNTabLen: uint64(md.Pclntablelen), - GoFuncVal: uint64(md.Gofunc), } } -type moduledata1864 struct { +type moduledata_1_17_64 struct { PcHeader uint64 Funcnametab, Funcnametablen, Funcnametabcap uint64 Cutab, Cutablen, Cutabcap uint64 @@ -167,14 +1382,15 @@ type moduledata1864 struct { Gcbss uint64 Types uint64 Etypes uint64 - Rodata uint64 - Gofunc uint64 Textsectmap, Textsectmaplen, Textsectmapcap uint64 Typelinks, Typelinkslen, Typelinkscap uint64 Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 } -func (md moduledata1864) toModuledata() moduledata { +func (md moduledata_1_17_64) toModuledata() moduledata { return moduledata{ TextAddr: md.Text, TextLen: md.Etext - md.Text, @@ -196,11 +1412,10 @@ func (md moduledata1864) toModuledata() moduledata { FuncTabLen: md.Ftablen, PCLNTabAddr: md.Pclntable, PCLNTabLen: md.Pclntablelen, - GoFuncVal: md.Gofunc, } } -type moduledata1832 struct { +type moduledata_1_18_32 struct { PcHeader uint32 Funcnametab, Funcnametablen, Funcnametabcap uint32 Cutab, Cutablen, Cutabcap uint32 @@ -231,9 +1446,12 @@ type moduledata1832 struct { Textsectmap, Textsectmaplen, Textsectmapcap uint32 Typelinks, Typelinkslen, Typelinkscap uint32 Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 } -func (md moduledata1832) toModuledata() moduledata { +func (md moduledata_1_18_32) toModuledata() moduledata { return moduledata{ TextAddr: uint64(md.Text), TextLen: uint64(md.Etext - md.Text), @@ -259,7 +1477,7 @@ func (md moduledata1832) toModuledata() moduledata { } } -type moduledata1664 struct { +type moduledata_1_18_64 struct { PcHeader uint64 Funcnametab, Funcnametablen, Funcnametabcap uint64 Cutab, Cutablen, Cutabcap uint64 @@ -285,12 +1503,17 @@ type moduledata1664 struct { Gcbss uint64 Types uint64 Etypes uint64 + Rodata uint64 + Gofunc uint64 Textsectmap, Textsectmaplen, Textsectmapcap uint64 Typelinks, Typelinkslen, Typelinkscap uint64 Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 } -func (md moduledata1664) toModuledata() moduledata { +func (md moduledata_1_18_64) toModuledata() moduledata { return moduledata{ TextAddr: md.Text, TextLen: md.Etext - md.Text, @@ -312,10 +1535,11 @@ func (md moduledata1664) toModuledata() moduledata { FuncTabLen: md.Ftablen, PCLNTabAddr: md.Pclntable, PCLNTabLen: md.Pclntablelen, + GoFuncVal: md.Gofunc, } } -type moduledata1632 struct { +type moduledata_1_19_32 struct { PcHeader uint32 Funcnametab, Funcnametablen, Funcnametabcap uint32 Cutab, Cutablen, Cutabcap uint32 @@ -341,12 +1565,17 @@ type moduledata1632 struct { Gcbss uint32 Types uint32 Etypes uint32 + Rodata uint32 + Gofunc uint32 Textsectmap, Textsectmaplen, Textsectmapcap uint32 Typelinks, Typelinkslen, Typelinkscap uint32 Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 } -func (md moduledata1632) toModuledata() moduledata { +func (md moduledata_1_19_32) toModuledata() moduledata { return moduledata{ TextAddr: uint64(md.Text), TextLen: uint64(md.Etext - md.Text), @@ -368,13 +1597,18 @@ func (md moduledata1632) toModuledata() moduledata { FuncTabLen: uint64(md.Ftablen), PCLNTabAddr: uint64(md.Pclntable), PCLNTabLen: uint64(md.Pclntablelen), + GoFuncVal: uint64(md.Gofunc), } } -type moduledata864 struct { +type moduledata_1_19_64 struct { + PcHeader uint64 + Funcnametab, Funcnametablen, Funcnametabcap uint64 + Cutab, Cutablen, Cutabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Pctab, Pctablen, Pctabcap uint64 Pclntable, Pclntablelen, Pclntablecap uint64 Ftab, Ftablen, Ftabcap uint64 - Filetab, Filetablen, Filetabcap uint64 Findfunctab uint64 Minpc uint64 Maxpc uint64 @@ -393,12 +1627,17 @@ type moduledata864 struct { Gcbss uint64 Types uint64 Etypes uint64 + Rodata uint64 + Gofunc uint64 Textsectmap, Textsectmaplen, Textsectmapcap uint64 Typelinks, Typelinkslen, Typelinkscap uint64 Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 } -func (md moduledata864) toModuledata() moduledata { +func (md moduledata_1_19_64) toModuledata() moduledata { return moduledata{ TextAddr: md.Text, TextLen: md.Etext - md.Text, @@ -420,13 +1659,18 @@ func (md moduledata864) toModuledata() moduledata { FuncTabLen: md.Ftablen, PCLNTabAddr: md.Pclntable, PCLNTabLen: md.Pclntablelen, + GoFuncVal: md.Gofunc, } } -type moduledata832 struct { +type moduledata_1_20_32 struct { + PcHeader uint32 + Funcnametab, Funcnametablen, Funcnametabcap uint32 + Cutab, Cutablen, Cutabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Pctab, Pctablen, Pctabcap uint32 Pclntable, Pclntablelen, Pclntablecap uint32 Ftab, Ftablen, Ftabcap uint32 - Filetab, Filetablen, Filetabcap uint32 Findfunctab uint32 Minpc uint32 Maxpc uint32 @@ -440,17 +1684,24 @@ type moduledata832 struct { Ebss uint32 Noptrbss uint32 Enoptrbss uint32 + Covctrs uint32 + Ecovctrs uint32 End uint32 Gcdata uint32 Gcbss uint32 Types uint32 Etypes uint32 + Rodata uint32 + Gofunc uint32 Textsectmap, Textsectmaplen, Textsectmapcap uint32 Typelinks, Typelinkslen, Typelinkscap uint32 Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 } -func (md moduledata832) toModuledata() moduledata { +func (md moduledata_1_20_32) toModuledata() moduledata { return moduledata{ TextAddr: uint64(md.Text), TextLen: uint64(md.Etext - md.Text), @@ -472,36 +1723,49 @@ func (md moduledata832) toModuledata() moduledata { FuncTabLen: uint64(md.Ftablen), PCLNTabAddr: uint64(md.Pclntable), PCLNTabLen: uint64(md.Pclntablelen), + GoFuncVal: uint64(md.Gofunc), } } -type moduledata764 struct { - Pclntable, Pclntablelen, Pclntablecap uint64 - Ftab, Ftablen, Ftabcap uint64 - Filetab, Filetablen, Filetabcap uint64 - Findfunctab uint64 - Minpc uint64 - Maxpc uint64 - Text uint64 - Etext uint64 - Noptrdata uint64 - Enoptrdata uint64 - Data uint64 - Edata uint64 - Bss uint64 - Ebss uint64 - Noptrbss uint64 - Enoptrbss uint64 - End uint64 - Gcdata uint64 - Gcbss uint64 - Types uint64 - Etypes uint64 - Typelinks, Typelinkslen, Typelinkscap uint64 - Itablinks, Itablinkslen, Itablinkscap uint64 +type moduledata_1_20_64 struct { + PcHeader uint64 + Funcnametab, Funcnametablen, Funcnametabcap uint64 + Cutab, Cutablen, Cutabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Pctab, Pctablen, Pctabcap uint64 + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + Covctrs uint64 + Ecovctrs uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Rodata uint64 + Gofunc uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 } -func (md moduledata764) toModuledata() moduledata { +func (md moduledata_1_20_64) toModuledata() moduledata { return moduledata{ TextAddr: md.Text, TextLen: md.Etext - md.Text, @@ -523,36 +1787,50 @@ func (md moduledata764) toModuledata() moduledata { FuncTabLen: md.Ftablen, PCLNTabAddr: md.Pclntable, PCLNTabLen: md.Pclntablelen, + GoFuncVal: md.Gofunc, } } -type moduledata732 struct { - Pclntable, Pclntablelen, Pclntablecap uint32 - Ftab, Ftablen, Ftabcap uint32 - Filetab, Filetablen, Filetabcap uint32 - Findfunctab uint32 - Minpc uint32 - Maxpc uint32 - Text uint32 - Etext uint32 - Noptrdata uint32 - Enoptrdata uint32 - Data uint32 - Edata uint32 - Bss uint32 - Ebss uint32 - Noptrbss uint32 - Enoptrbss uint32 - End uint32 - Gcdata uint32 - Gcbss uint32 - Types uint32 - Etypes uint32 - Typelinks, Typelinkslen, Typelinkscap uint32 - Itablinks, Itablinkslen, Itablinkscap uint32 +type moduledata_1_21_32 struct { + PcHeader uint32 + Funcnametab, Funcnametablen, Funcnametabcap uint32 + Cutab, Cutablen, Cutabcap uint32 + Filetab, Filetablen, Filetabcap uint32 + Pctab, Pctablen, Pctabcap uint32 + Pclntable, Pclntablelen, Pclntablecap uint32 + Ftab, Ftablen, Ftabcap uint32 + Findfunctab uint32 + Minpc uint32 + Maxpc uint32 + Text uint32 + Etext uint32 + Noptrdata uint32 + Enoptrdata uint32 + Data uint32 + Edata uint32 + Bss uint32 + Ebss uint32 + Noptrbss uint32 + Enoptrbss uint32 + Covctrs uint32 + Ecovctrs uint32 + End uint32 + Gcdata uint32 + Gcbss uint32 + Types uint32 + Etypes uint32 + Rodata uint32 + Gofunc uint32 + Textsectmap, Textsectmaplen, Textsectmapcap uint32 + Typelinks, Typelinkslen, Typelinkscap uint32 + Itablinks, Itablinkslen, Itablinkscap uint32 + Ptab, Ptablen, Ptabcap uint32 + Pluginpath, Pluginpathlen uint32 + Pkghashes, Pkghasheslen, Pkghashescap uint32 + Inittasks, Inittaskslen, Inittaskscap uint32 } -func (md moduledata732) toModuledata() moduledata { +func (md moduledata_1_21_32) toModuledata() moduledata { return moduledata{ TextAddr: uint64(md.Text), TextLen: uint64(md.Etext - md.Text), @@ -574,33 +1852,50 @@ func (md moduledata732) toModuledata() moduledata { FuncTabLen: uint64(md.Ftablen), PCLNTabAddr: uint64(md.Pclntable), PCLNTabLen: uint64(md.Pclntablelen), + GoFuncVal: uint64(md.Gofunc), } } -type moduledata564 struct { - Pclntable, Pclntablelen, Pclntablecap uint64 - Ftab, Ftablen, Ftabcap uint64 - Filetab, Filetablen, Filetabcap uint64 - Findfunctab uint64 - Minpc uint64 - Maxpc uint64 - Text uint64 - Etext uint64 - Noptrdata uint64 - Enoptrdata uint64 - Data uint64 - Edata uint64 - Bss uint64 - Ebss uint64 - Noptrbss uint64 - Enoptrbss uint64 - End uint64 - Gcdata uint64 - Gcbss uint64 - Typelinks, Typelinkslen, Typelinkscap uint64 +type moduledata_1_21_64 struct { + PcHeader uint64 + Funcnametab, Funcnametablen, Funcnametabcap uint64 + Cutab, Cutablen, Cutabcap uint64 + Filetab, Filetablen, Filetabcap uint64 + Pctab, Pctablen, Pctabcap uint64 + Pclntable, Pclntablelen, Pclntablecap uint64 + Ftab, Ftablen, Ftabcap uint64 + Findfunctab uint64 + Minpc uint64 + Maxpc uint64 + Text uint64 + Etext uint64 + Noptrdata uint64 + Enoptrdata uint64 + Data uint64 + Edata uint64 + Bss uint64 + Ebss uint64 + Noptrbss uint64 + Enoptrbss uint64 + Covctrs uint64 + Ecovctrs uint64 + End uint64 + Gcdata uint64 + Gcbss uint64 + Types uint64 + Etypes uint64 + Rodata uint64 + Gofunc uint64 + Textsectmap, Textsectmaplen, Textsectmapcap uint64 + Typelinks, Typelinkslen, Typelinkscap uint64 + Itablinks, Itablinkslen, Itablinkscap uint64 + Ptab, Ptablen, Ptabcap uint64 + Pluginpath, Pluginpathlen uint64 + Pkghashes, Pkghasheslen, Pkghashescap uint64 + Inittasks, Inittaskslen, Inittaskscap uint64 } -func (md moduledata564) toModuledata() moduledata { +func (md moduledata_1_21_64) toModuledata() moduledata { return moduledata{ TextAddr: md.Text, TextLen: md.Etext - md.Text, @@ -612,55 +1907,91 @@ func (md moduledata564) toModuledata() moduledata { BssLen: md.Ebss - md.Bss, NoPtrBssAddr: md.Noptrbss, NoPtrBssLen: md.Enoptrbss - md.Noptrbss, + TypesAddr: md.Types, + TypesLen: md.Etypes - md.Types, TypelinkAddr: md.Typelinks, TypelinkLen: md.Typelinkslen, + ITabLinkAddr: md.Itablinks, + ITabLinkLen: md.Itablinkslen, FuncTabAddr: md.Ftab, FuncTabLen: md.Ftablen, PCLNTabAddr: md.Pclntable, PCLNTabLen: md.Pclntablelen, + GoFuncVal: md.Gofunc, } } -type moduledata532 struct { - Pclntable, Pclntablelen, Pclntablecap uint32 - Ftab, Ftablen, Ftabcap uint32 - Filetab, Filetablen, Filetabcap uint32 - Findfunctab uint32 - Minpc uint32 - Maxpc uint32 - Text uint32 - Etext uint32 - Noptrdata uint32 - Enoptrdata uint32 - Data uint32 - Edata uint32 - Bss uint32 - Ebss uint32 - Noptrbss uint32 - Enoptrbss uint32 - End uint32 - Gcdata uint32 - Gcbss uint32 - Typelinks, Typelinkslen, Typelinkscap uint32 -} - -func (md moduledata532) toModuledata() moduledata { - return moduledata{ - TextAddr: uint64(md.Text), - TextLen: uint64(md.Etext - md.Text), - NoPtrDataAddr: uint64(md.Noptrdata), - NoPtrDataLen: uint64(md.Enoptrdata - md.Noptrdata), - DataAddr: uint64(md.Data), - DataLen: uint64(md.Edata - md.Data), - BssAddr: uint64(md.Bss), - BssLen: uint64(md.Ebss - md.Bss), - NoPtrBssAddr: uint64(md.Noptrbss), - NoPtrBssLen: uint64(md.Enoptrbss - md.Noptrbss), - TypelinkAddr: uint64(md.Typelinks), - TypelinkLen: uint64(md.Typelinkslen), - FuncTabAddr: uint64(md.Ftab), - FuncTabLen: uint64(md.Ftablen), - PCLNTabAddr: uint64(md.Pclntable), - PCLNTabLen: uint64(md.Pclntablelen), +func selectModuleData(v int, bits int) modulable { + switch { + case v == 5 && bits == 32: + return &moduledata_1_5_32{} + case v == 5 && bits == 64: + return &moduledata_1_5_64{} + case v == 6 && bits == 32: + return &moduledata_1_6_32{} + case v == 6 && bits == 64: + return &moduledata_1_6_64{} + case v == 7 && bits == 32: + return &moduledata_1_7_32{} + case v == 7 && bits == 64: + return &moduledata_1_7_64{} + case v == 8 && bits == 32: + return &moduledata_1_8_32{} + case v == 8 && bits == 64: + return &moduledata_1_8_64{} + case v == 9 && bits == 32: + return &moduledata_1_9_32{} + case v == 9 && bits == 64: + return &moduledata_1_9_64{} + case v == 10 && bits == 32: + return &moduledata_1_10_32{} + case v == 10 && bits == 64: + return &moduledata_1_10_64{} + case v == 11 && bits == 32: + return &moduledata_1_11_32{} + case v == 11 && bits == 64: + return &moduledata_1_11_64{} + case v == 12 && bits == 32: + return &moduledata_1_12_32{} + case v == 12 && bits == 64: + return &moduledata_1_12_64{} + case v == 13 && bits == 32: + return &moduledata_1_13_32{} + case v == 13 && bits == 64: + return &moduledata_1_13_64{} + case v == 14 && bits == 32: + return &moduledata_1_14_32{} + case v == 14 && bits == 64: + return &moduledata_1_14_64{} + case v == 15 && bits == 32: + return &moduledata_1_15_32{} + case v == 15 && bits == 64: + return &moduledata_1_15_64{} + case v == 16 && bits == 32: + return &moduledata_1_16_32{} + case v == 16 && bits == 64: + return &moduledata_1_16_64{} + case v == 17 && bits == 32: + return &moduledata_1_17_32{} + case v == 17 && bits == 64: + return &moduledata_1_17_64{} + case v == 18 && bits == 32: + return &moduledata_1_18_32{} + case v == 18 && bits == 64: + return &moduledata_1_18_64{} + case v == 19 && bits == 32: + return &moduledata_1_19_32{} + case v == 19 && bits == 64: + return &moduledata_1_19_64{} + case v == 20 && bits == 32: + return &moduledata_1_20_32{} + case v == 20 && bits == 64: + return &moduledata_1_20_64{} + case v == 21 && bits == 32: + return &moduledata_1_21_32{} + case v == 21 && bits == 64: + return &moduledata_1_21_64{} + default: + panic(fmt.Sprintf("unsupported go version %d", v)) } } From 811fd08250cc67c54af2b74c455d13993f84ddce Mon Sep 17 00:00:00 2001 From: Zxilly Date: Fri, 2 Feb 2024 19:54:07 +0800 Subject: [PATCH 08/12] chore: update exist style --- gen/moduledata.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gen/moduledata.go b/gen/moduledata.go index 2dca22d..f108667 100644 --- a/gen/moduledata.go +++ b/gen/moduledata.go @@ -209,40 +209,44 @@ func (g *moduleDataGenerator) writeVersionedModuleData(versionCode int, code str g.writeln("}\n\n") // generate toModuledata method - exist := func(name string) bool { - _, ok := fields[name] - return ok + exist := func(name ...string) bool { + for _, n := range name { + if _, ok := fields[n]; !ok { + return false + } + } + return true } g.writeln("func (md %s) toModuledata() moduledata {", g.generateTypeName(versionCode, bits)) g.writeln("return moduledata{") - if exist("text") && exist("etext") { + if exist("text", "etext") { g.writeln("TextAddr: %s,", g.wrapValue("md.Text", bits)) g.writeln("TextLen: %s,", g.wrapValue("md.Etext - md.Text", bits)) } - if exist("noptrdata") && exist("enoptrdata") { + if exist("noptrdata", "enoptrdata") { g.writeln("NoPtrDataAddr: %s,", g.wrapValue("md.Noptrdata", bits)) g.writeln("NoPtrDataLen: %s,", g.wrapValue("md.Enoptrdata - md.Noptrdata", bits)) } - if exist("data") && exist("edata") { + if exist("data", "edata") { g.writeln("DataAddr: %s,", g.wrapValue("md.Data", bits)) g.writeln("DataLen: %s,", g.wrapValue("md.Edata - md.Data", bits)) } - if exist("bss") && exist("ebss") { + if exist("bss", "ebss") { g.writeln("BssAddr: %s,", g.wrapValue("md.Bss", bits)) g.writeln("BssLen: %s,", g.wrapValue("md.Ebss - md.Bss", bits)) } - if exist("noptrbss") && exist("enoptrbss") { + if exist("noptrbss", "enoptrbss") { g.writeln("NoPtrBssAddr: %s,", g.wrapValue("md.Noptrbss", bits)) g.writeln("NoPtrBssLen: %s,", g.wrapValue("md.Enoptrbss - md.Noptrbss", bits)) } - if exist("types") && exist("etypes") { + if exist("types", "etypes") { g.writeln("TypesAddr: %s,", g.wrapValue("md.Types", bits)) g.writeln("TypesLen: %s,", g.wrapValue("md.Etypes - md.Types", bits)) } From 743f2cd56ff12901472ef84143329fe71c0c1dab Mon Sep 17 00:00:00 2001 From: Zxilly Date: Fri, 2 Feb 2024 23:16:17 +0800 Subject: [PATCH 09/12] feat: add moduledata validation --- elf.go | 10 +++-- file.go | 2 +- file_test.go | 2 +- gen/moduledata.go | 19 +++++---- goversion.go | 17 ++++---- macho.go | 7 ++-- moduledata.go | 97 +++++++++++++++++++++++++++++++--------------- moduledata_gen.go | 72 +++++++++++++++++----------------- moduledata_test.go | 4 +- pe.go | 9 +++-- type.go | 4 +- 11 files changed, 144 insertions(+), 99 deletions(-) diff --git a/elf.go b/elf.go index 7993251..f3dbd81 100644 --- a/elf.go +++ b/elf.go @@ -88,12 +88,16 @@ func (e *elfFile) getRData() ([]byte, error) { return section.Data() } -func (e *elfFile) getCodeSection() ([]byte, error) { +func (e *elfFile) getCodeSection() (uint64, []byte, error) { section := e.file.Section(".text") if section == nil { - return nil, ErrSectionDoesNotExist + return 0, nil, ErrSectionDoesNotExist } - return section.Data() + data, err := section.Data() + if err != nil { + return 0, nil, fmt.Errorf("error when getting the code section: %w", err) + } + return section.Addr, data, nil } func (e *elfFile) getPCLNTABData() (uint64, []byte, error) { diff --git a/file.go b/file.go index cbf2796..37fcf22 100644 --- a/file.go +++ b/file.go @@ -377,7 +377,7 @@ type fileHandler interface { io.Closer getPCLNTab() (*gosym.Table, error) getRData() ([]byte, error) - getCodeSection() ([]byte, error) + getCodeSection() (uint64, []byte, error) getSectionDataFromOffset(uint64) (uint64, []byte, error) getSectionData(string) (uint64, []byte, error) getFileInfo() *FileInfo diff --git a/file_test.go b/file_test.go index 7d228fb..23ad598 100644 --- a/file_test.go +++ b/file_test.go @@ -194,7 +194,7 @@ func (m *mockFileHandler) getRData() ([]byte, error) { panic("not implemented") } -func (m *mockFileHandler) getCodeSection() ([]byte, error) { +func (m *mockFileHandler) getCodeSection() (uint64, []byte, error) { panic("not implemented") } diff --git a/gen/moduledata.go b/gen/moduledata.go index f108667..f5244b3 100644 --- a/gen/moduledata.go +++ b/gen/moduledata.go @@ -123,17 +123,17 @@ func (g *moduleDataGenerator) add(versionCode int, code string) error { } func (g *moduleDataGenerator) writeSelector() { - g.writeln("func selectModuleData(v int, bits int) modulable {") + g.writeln("func selectModuleData(v int, bits int) (modulable,error) {") g.writeln("switch {") for _, versionCode := range g.knownVersions { for _, bits := range []int{32, 64} { g.writeln("case v == %d && bits == %d:", versionCode, bits) - g.writeln("return &%s{}", g.generateTypeName(versionCode, bits)) + g.writeln("return &%s{}, nil", g.generateTypeName(versionCode, bits)) } } g.writeln("default:") - g.writeln(`panic(fmt.Sprintf("unsupported go version %%d", v))`) + g.writeln(`return nil, fmt.Errorf("unsupported version %%d and bits %%d", v, bits)`) g.writeln("}\n}\n") @@ -163,14 +163,17 @@ func (g *moduleDataGenerator) writeVersionedModuleData(versionCode int, code str if err != nil { return fmt.Errorf("failed to parse moduledata expression: %w", err) } + structExpr, ok := expr.(*ast.StructType) + if !ok { + return fmt.Errorf("failed to parse moduledata expression") + } writeCode := func(bits int) { g.writeln("type %s struct {\n", g.generateTypeName(versionCode, bits)) - fields := make(map[string]struct{}) - expr := expr.(*ast.StructType) + knownFields := make(map[string]struct{}) search: - for _, field := range expr.Fields.List { + for _, field := range structExpr.Fields.List { if len(field.Names) == 0 { // skip anonymous field // currently only sys.NotInHeap @@ -182,7 +185,7 @@ func (g *moduleDataGenerator) writeVersionedModuleData(versionCode int, code str // no more data needed break search } - fields[name.Name] = struct{}{} + knownFields[name.Name] = struct{}{} switch t := field.Type.(type) { case *ast.StarExpr: @@ -211,7 +214,7 @@ func (g *moduleDataGenerator) writeVersionedModuleData(versionCode int, code str // generate toModuledata method exist := func(name ...string) bool { for _, n := range name { - if _, ok := fields[n]; !ok { + if _, ok := knownFields[n]; !ok { return false } } diff --git a/goversion.go b/goversion.go index f3e4295..a11d5bd 100644 --- a/goversion.go +++ b/goversion.go @@ -21,6 +21,7 @@ package gore import ( "bytes" + "errors" "regexp" "strings" @@ -28,7 +29,7 @@ import ( "golang.org/x/mod/semver" ) -var goVersionMatcher = regexp.MustCompile(`(go[\d+\.]*(beta|rc)?[\d*])`) +var goVersionMatcher = regexp.MustCompile(`(go[\d+.]*(beta|rc)?[\d*])`) // GoVersion holds information about the compiler version. type GoVersion struct { @@ -87,21 +88,21 @@ func findGoCompilerVersion(f *GoFile) (*GoVersion, error) { // version string. data, err := f.fh.getRData() - // If read only data section does not exist, try text. - if err == ErrSectionDoesNotExist { - data, err = f.fh.getCodeSection() + // If a read-only data section does not exist, try text. + if errors.Is(err, ErrSectionDoesNotExist) { + _, data, err = f.fh.getCodeSection() } if err != nil { return nil, err } - notfound := false - for !notfound { + + for { version := matchGoVersionString(data) if version == "" { return nil, ErrNoGoVersionFound } ver := ResolveGoVersion(version) - // Go before 1.4 does not have the version string so if we have found + // Go before 1.4 does not have the version string, so if we have found // a version string below 1.4beta1 it is a false positive. if ver == nil || GoVersionCompare(ver.Name, "go1.4beta1") < 0 { off := bytes.Index(data, []byte(version)) @@ -122,7 +123,7 @@ func findGoCompilerVersion(f *GoFile) (*GoVersion, error) { // used to identify the version. // The function returns nil if no version is found. func tryFromSchedInit(f *GoFile) *GoVersion { - // Check for non supported architectures. + // Check for non-supported architectures. if f.FileInfo.Arch != Arch386 && f.FileInfo.Arch != ArchAMD64 { return nil } diff --git a/macho.go b/macho.go index 7f6f899..da5b327 100644 --- a/macho.go +++ b/macho.go @@ -78,9 +78,8 @@ func (m *machoFile) getRData() ([]byte, error) { return data, err } -func (m *machoFile) getCodeSection() ([]byte, error) { - _, data, err := m.getSectionData("__text") - return data, err +func (m *machoFile) getCodeSection() (uint64, []byte, error) { + return m.getSectionData("__text") } func (m *machoFile) getSectionDataFromOffset(off uint64) (uint64, []byte, error) { @@ -137,7 +136,7 @@ func (m *machoFile) moduledataSection() string { } func (m *machoFile) getBuildID() (string, error) { - data, err := m.getCodeSection() + _, data, err := m.getCodeSection() if err != nil { return "", fmt.Errorf("failed to get code section: %w", err) } diff --git a/moduledata.go b/moduledata.go index 9e11ea0..830e75e 100644 --- a/moduledata.go +++ b/moduledata.go @@ -39,7 +39,7 @@ func (f *GoFile) Moduledata() (Moduledata, error) { } f.FileInfo.goversion = ver - md, err := parseModuledata(f.FileInfo, f.fh) + md, err := extractModuledata(f.FileInfo, f.fh) if err != nil { return nil, fmt.Errorf("error when parsing the moduledata: %w", err) } @@ -202,7 +202,7 @@ func (m moduledata) GoFuncValue() uint64 { // ModuleDataSection is a section defined in the Moduledata structure. type ModuleDataSection struct { - // Address is the virtual address where the section start. + // Address is the virtual address where the section starts. Address uint64 // Length is the byte length for the data in this section. Length uint64 @@ -228,67 +228,102 @@ func (m ModuleDataSection) Data() ([]byte, error) { return buf, nil } -func findModuledata(f fileHandler) ([]byte, error) { - _, secData, err := f.getSectionData(f.moduledataSection()) +func buildPclnTabAddrBinary(addr uint64) ([]byte, error) { + buf := new(bytes.Buffer) + err := binary.Write(buf, binary.LittleEndian, &addr) if err != nil { return nil, err } - tabAddr, _, err := f.getPCLNTABData() - if err != nil { - return nil, err + return buf.Bytes()[:intSize32], nil +} + +func pickVersionedModuleData(info FileInfo) (modulable, error) { + var bits int + if info.WordSize == intSize32 { + bits = 32 + } else { + bits = 64 } - // Search for moduledata - buf := new(bytes.Buffer) - err = binary.Write(buf, binary.LittleEndian, &tabAddr) + ver := buildSemVerString(info.goversion.Name) + m := semver.MajorMinor(ver) + verBit, err := strconv.Atoi(strings.Split(m, ".")[1]) if err != nil { - return nil, err + return nil, fmt.Errorf("error when parsing the Go version: %w", err) } - off := bytes.Index(secData, buf.Bytes()[:intSize32]) - if off == -1 { - return nil, errors.New("could not find moduledata") + // buf will hold the struct type that represents the data in the file we are processing. + buf, err := selectModuleData(verBit, bits) + if err != nil { + return nil, fmt.Errorf("error when selecting the module data: %w", err) } - // TODO: Verify that hit is correct. - return secData[off : off+0x300], nil + return buf, nil } -func parseModuledata(fileInfo *FileInfo, f fileHandler) (moduledata, error) { - data, err := findModuledata(f) +func extractModuledata(fileInfo *FileInfo, f fileHandler) (moduledata, error) { + vmd, err := pickVersionedModuleData(*fileInfo) if err != nil { return moduledata{}, err } - var bits int - if fileInfo.WordSize == intSize32 { - bits = 32 - } else { - bits = 64 + vmdSize := binary.Size(vmd) + + _, secData, err := f.getSectionData(f.moduledataSection()) + if err != nil { + return moduledata{}, err + } + tabAddr, _, err := f.getPCLNTABData() + if err != nil { + return moduledata{}, err } - ver := buildSemVerString(fileInfo.goversion.Name) - m := semver.MajorMinor(ver) - verBit, err := strconv.Atoi(strings.Split(m, ".")[1]) + magic, err := buildPclnTabAddrBinary(tabAddr) if err != nil { - return moduledata{}, fmt.Errorf("error when parsing the Go version: %w", err) + return moduledata{}, err } - // buf will hold the struct type that represents the data in the file we are processing. - buf := selectModuleData(verBit, bits) + +search: + off := bytes.Index(secData, magic) + if off == -1 || len(secData) < off+vmdSize { + return moduledata{}, errors.New("could not find moduledata") + } + + data := secData[off : off+vmdSize] // Read the module struct from the file. r := bytes.NewReader(data) - err = binary.Read(r, fileInfo.ByteOrder, buf) + err = binary.Read(r, fileInfo.ByteOrder, vmd) if err != nil { return moduledata{}, fmt.Errorf("error when reading module data from file: %w", err) } // Convert the read struct to the type we return to the caller. - md := buf.toModuledata() + md := vmd.toModuledata() + + // Take a simple validation step to ensure that the moduledata is valid. + text := md.TextAddr + etext := md.TextAddr + md.TextLen + + textSectAddr, textSect, err := f.getCodeSection() + if err != nil { + return moduledata{}, err + } + if text > etext { + goto invalidMD + } + + if !(textSectAddr <= text && text < textSectAddr+uint64(len(textSect))) { + goto invalidMD + } // Add the file handler. md.fh = f return md, nil + +invalidMD: + secData = secData[off+1:] + goto search } func readUIntTo64(r io.Reader, byteOrder binary.ByteOrder, is32bit bool) (addr uint64, err error) { diff --git a/moduledata_gen.go b/moduledata_gen.go index b97782c..fbb08cb 100644 --- a/moduledata_gen.go +++ b/moduledata_gen.go @@ -1921,77 +1921,77 @@ func (md moduledata_1_21_64) toModuledata() moduledata { } } -func selectModuleData(v int, bits int) modulable { +func selectModuleData(v int, bits int) (modulable, error) { switch { case v == 5 && bits == 32: - return &moduledata_1_5_32{} + return &moduledata_1_5_32{}, nil case v == 5 && bits == 64: - return &moduledata_1_5_64{} + return &moduledata_1_5_64{}, nil case v == 6 && bits == 32: - return &moduledata_1_6_32{} + return &moduledata_1_6_32{}, nil case v == 6 && bits == 64: - return &moduledata_1_6_64{} + return &moduledata_1_6_64{}, nil case v == 7 && bits == 32: - return &moduledata_1_7_32{} + return &moduledata_1_7_32{}, nil case v == 7 && bits == 64: - return &moduledata_1_7_64{} + return &moduledata_1_7_64{}, nil case v == 8 && bits == 32: - return &moduledata_1_8_32{} + return &moduledata_1_8_32{}, nil case v == 8 && bits == 64: - return &moduledata_1_8_64{} + return &moduledata_1_8_64{}, nil case v == 9 && bits == 32: - return &moduledata_1_9_32{} + return &moduledata_1_9_32{}, nil case v == 9 && bits == 64: - return &moduledata_1_9_64{} + return &moduledata_1_9_64{}, nil case v == 10 && bits == 32: - return &moduledata_1_10_32{} + return &moduledata_1_10_32{}, nil case v == 10 && bits == 64: - return &moduledata_1_10_64{} + return &moduledata_1_10_64{}, nil case v == 11 && bits == 32: - return &moduledata_1_11_32{} + return &moduledata_1_11_32{}, nil case v == 11 && bits == 64: - return &moduledata_1_11_64{} + return &moduledata_1_11_64{}, nil case v == 12 && bits == 32: - return &moduledata_1_12_32{} + return &moduledata_1_12_32{}, nil case v == 12 && bits == 64: - return &moduledata_1_12_64{} + return &moduledata_1_12_64{}, nil case v == 13 && bits == 32: - return &moduledata_1_13_32{} + return &moduledata_1_13_32{}, nil case v == 13 && bits == 64: - return &moduledata_1_13_64{} + return &moduledata_1_13_64{}, nil case v == 14 && bits == 32: - return &moduledata_1_14_32{} + return &moduledata_1_14_32{}, nil case v == 14 && bits == 64: - return &moduledata_1_14_64{} + return &moduledata_1_14_64{}, nil case v == 15 && bits == 32: - return &moduledata_1_15_32{} + return &moduledata_1_15_32{}, nil case v == 15 && bits == 64: - return &moduledata_1_15_64{} + return &moduledata_1_15_64{}, nil case v == 16 && bits == 32: - return &moduledata_1_16_32{} + return &moduledata_1_16_32{}, nil case v == 16 && bits == 64: - return &moduledata_1_16_64{} + return &moduledata_1_16_64{}, nil case v == 17 && bits == 32: - return &moduledata_1_17_32{} + return &moduledata_1_17_32{}, nil case v == 17 && bits == 64: - return &moduledata_1_17_64{} + return &moduledata_1_17_64{}, nil case v == 18 && bits == 32: - return &moduledata_1_18_32{} + return &moduledata_1_18_32{}, nil case v == 18 && bits == 64: - return &moduledata_1_18_64{} + return &moduledata_1_18_64{}, nil case v == 19 && bits == 32: - return &moduledata_1_19_32{} + return &moduledata_1_19_32{}, nil case v == 19 && bits == 64: - return &moduledata_1_19_64{} + return &moduledata_1_19_64{}, nil case v == 20 && bits == 32: - return &moduledata_1_20_32{} + return &moduledata_1_20_32{}, nil case v == 20 && bits == 64: - return &moduledata_1_20_64{} + return &moduledata_1_20_64{}, nil case v == 21 && bits == 32: - return &moduledata_1_21_32{} + return &moduledata_1_21_32{}, nil case v == 21 && bits == 64: - return &moduledata_1_21_64{} + return &moduledata_1_21_64{}, nil default: - panic(fmt.Sprintf("unsupported go version %d", v)) + return nil, fmt.Errorf("unsupported version %d and bits %d", v, bits) } } diff --git a/moduledata_test.go b/moduledata_test.go index 62b48af..c5e8add 100644 --- a/moduledata_test.go +++ b/moduledata_test.go @@ -48,7 +48,9 @@ func TestModuledata(t *testing.T) { t.Run("moduledata-"+test.file, func(t *testing.T) { f, err := Open(filepath.Join("testdata", "gold", test.file)) r.NoError(err) - defer f.Close() + defer func(f *GoFile) { + _ = f.Close() + }(f) md, err := f.Moduledata() r.NoError(err) diff --git a/pe.go b/pe.go index 04e662e..090c559 100644 --- a/pe.go +++ b/pe.go @@ -93,12 +93,13 @@ func (p *peFile) getRData() ([]byte, error) { return section.Data() } -func (p *peFile) getCodeSection() ([]byte, error) { +func (p *peFile) getCodeSection() (uint64, []byte, error) { section := p.file.Section(".text") if section == nil { - return nil, ErrSectionDoesNotExist + return 0, nil, ErrSectionDoesNotExist } - return section.Data() + data, err := section.Data() + return p.imageBase + uint64(section.VirtualAddress), data, err } func (p *peFile) moduledataSection() string { @@ -151,7 +152,7 @@ func (p *peFile) getFileInfo() *FileInfo { } func (p *peFile) getBuildID() (string, error) { - data, err := p.getCodeSection() + _, data, err := p.getCodeSection() if err != nil { return "", fmt.Errorf("failed to get code section: %w", err) } diff --git a/type.go b/type.go index 6e518d6..e4795bc 100644 --- a/type.go +++ b/type.go @@ -60,7 +60,7 @@ func getTypes(fileInfo *FileInfo, f fileHandler) (map[uint64]*GoType, error) { return getLegacyTypes(fileInfo, f) } - md, err := parseModuledata(fileInfo, f) + md, err := extractModuledata(fileInfo, f) if err != nil { return nil, fmt.Errorf("failed to parse the module data: %w", err) } @@ -87,7 +87,7 @@ func getTypes(fileInfo *FileInfo, f fileHandler) (map[uint64]*GoType, error) { } func getLegacyTypes(fileInfo *FileInfo, f fileHandler) (map[uint64]*GoType, error) { - md, err := parseModuledata(fileInfo, f) + md, err := extractModuledata(fileInfo, f) if err != nil { return nil, err } From e7e8fb4f28387c402c2d67ed999fc814ea4337f2 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Sat, 3 Feb 2024 01:53:42 +0800 Subject: [PATCH 10/12] feat: add cache for moduledata and goversion --- elf.go | 4 +- file.go | 146 ++++++++++++++++++++++++++++++++++---------------- file_test.go | 4 +- goroot.go | 4 +- macho.go | 4 +- modinfo.go | 2 +- moduledata.go | 17 ------ pe.go | 4 +- 8 files changed, 111 insertions(+), 74 deletions(-) diff --git a/elf.go b/elf.go index f3dbd81..cf285d8 100644 --- a/elf.go +++ b/elf.go @@ -45,11 +45,11 @@ type elfFile struct { osFile *os.File } -func (e *elfFile) GetParsedFile() any { +func (e *elfFile) getParsedFile() any { return e.file } -func (e *elfFile) GetFile() *os.File { +func (e *elfFile) getFile() *os.File { return e.osFile } diff --git a/file.go b/file.go index 37fcf22..0efb75e 100644 --- a/file.go +++ b/file.go @@ -54,7 +54,7 @@ func Open(filePath string) (*GoFile, error) { buf := make([]byte, maxMagicBufLen) n, err := f.Read(buf) - f.Close() + _ = f.Close() if err != nil { return nil, err } @@ -94,8 +94,9 @@ func Open(filePath string) (*GoFile, error) { // Try to extract build information. if bi, err := gofile.extractBuildInfo(); err == nil { - // This error is a minor failure, it just means we don't have - // this information. So if fails we just ignores it. + // This error is a minor failure; it just means we don't have + // this information. + // So if fails, we just ignore it. gofile.BuildInfo = bi if bi.Compiler != nil { gofile.FileInfo.goversion = bi.Compiler @@ -107,40 +108,72 @@ func Open(filePath string) (*GoFile, error) { // GoFile is a structure representing a go binary file. type GoFile struct { - // BuildInfo holds the data from the buildinf structure. This can be nil - // because it's not always available. + // BuildInfo holds the data from the buildinfo structure. + // This can be a nil because it's not always available. BuildInfo *BuildInfo // FileInfo holds information about the file. FileInfo *FileInfo // BuildID is the Go build ID hash extracted from the binary. - BuildID string - fh fileHandler - stdPkgs []*Package - generated []*Package - pkgs []*Package - vendors []*Package - unknown []*Package - pclntab *gosym.Table - initPackages sync.Once + BuildID string + + fh fileHandler + + stdPkgs []*Package + generated []*Package + pkgs []*Package + vendors []*Package + unknown []*Package + + pclntab *gosym.Table + + initPackagesOnce sync.Once + initPackagesError error + + moduledata moduledata + + versionError error + + initModuleDataOnce sync.Once + initModuleDataError error } -func (f *GoFile) init() error { - var returnVal error - f.initPackages.Do(func() { +func (f *GoFile) initModuleData() error { + f.initModuleDataOnce.Do(func() { + err := f.ensureCompilerVersion() + if err != nil { + f.initModuleDataError = err + return + } + f.moduledata, f.initModuleDataError = extractModuledata(f.FileInfo, f.fh) + }) + return f.initModuleDataError +} + +// Moduledata extracts the file's moduledata. +func (f *GoFile) Moduledata() (Moduledata, error) { + err := f.initModuleData() + if err != nil { + return moduledata{}, err + } + return f.moduledata, nil +} + +func (f *GoFile) initPackages() error { + f.initPackagesOnce.Do(func() { tab, err := f.PCLNTab() if err != nil { - returnVal = err + f.initPackagesError = err return } f.pclntab = tab - returnVal = f.enumPackages() + f.initPackagesError = f.enumPackages() }) - return returnVal + return f.initPackagesError } // GetFile returns the raw file opened by the library. func (f *GoFile) GetFile() *os.File { - return f.fh.GetFile() + return f.fh.getFile() } // GetParsedFile returns the parsed file, should be cast based on the file type. @@ -151,13 +184,38 @@ func (f *GoFile) GetFile() *os.File { // // all from the debug package. func (f *GoFile) GetParsedFile() any { - return f.fh.GetParsedFile() + return f.fh.getParsedFile() } // GetCompilerVersion returns the Go compiler version of the compiler // that was used to compile the binary. func (f *GoFile) GetCompilerVersion() (*GoVersion, error) { - return findGoCompilerVersion(f) + err := f.ensureCompilerVersion() + if err != nil { + return nil, err + } + return f.FileInfo.goversion, nil +} + +func (f *GoFile) ensureCompilerVersion() error { + if f.FileInfo.goversion == nil { + f.tryExtractCompilerVersion() + } + return f.versionError +} + +// tryExtractCompilerVersion tries to extract the compiler version from the binary. +// should only be called if FileInfo.goversion is nil. +func (f *GoFile) tryExtractCompilerVersion() { + if f.FileInfo.goversion != nil { + return + } + v, err := findGoCompilerVersion(f) + if err != nil { + f.versionError = err + } else { + f.FileInfo.goversion = v + } } // SourceInfo returns the source code filename, starting line number @@ -168,10 +226,9 @@ func (f *GoFile) SourceInfo(fn *Function) (string, int, int) { return srcFile, start, end } -// GetGoRoot returns the Go Root path -// that was used to compile the binary. +// GetGoRoot returns the Go Root path used to compile the binary. func (f *GoFile) GetGoRoot() (string, error) { - err := f.init() + err := f.initPackages() if err != nil { return "", err } @@ -181,7 +238,7 @@ func (f *GoFile) GetGoRoot() (string, error) { // SetGoVersion sets the assumed compiler version that was used. This // can be used to force a version if gore is not able to determine the // compiler version used. The version string must match one of the strings -// normally extracted from the binary. For example to set the version to +// normally extracted from the binary. For example, to set the version to // go 1.12.0, use "go1.12". For 1.7.2, use "go1.7.2". // If an incorrect version string or version not known to the library, // ErrInvalidGoVersion is returned. @@ -194,35 +251,35 @@ func (f *GoFile) SetGoVersion(version string) error { return nil } -// GetPackages returns the go packages that has been classified as part of the main +// GetPackages returns the go packages that have been classified as part of the main // project. func (f *GoFile) GetPackages() ([]*Package, error) { - err := f.init() + err := f.initPackages() return f.pkgs, err } -// GetVendors returns the 3rd party packages used by the binary. +// GetVendors returns the third party packages used by the binary. func (f *GoFile) GetVendors() ([]*Package, error) { - err := f.init() + err := f.initPackages() return f.vendors, err } // GetSTDLib returns the standard library packages used by the binary. func (f *GoFile) GetSTDLib() ([]*Package, error) { - err := f.init() + err := f.initPackages() return f.stdPkgs, err } // GetGeneratedPackages returns the compiler generated packages used by the binary. func (f *GoFile) GetGeneratedPackages() ([]*Package, error) { - err := f.init() + err := f.initPackages() return f.generated, err } -// GetUnknown returns unclassified packages used by the binary. This is a catch all -// category when the classification could not be determined. +// GetUnknown returns unclassified packages used by the binary. +// This is a catch-all category when the classification could not be determined. func (f *GoFile) GetUnknown() ([]*Package, error) { - err := f.init() + err := f.initPackages() return f.unknown, err } @@ -325,24 +382,21 @@ func (f *GoFile) PCLNTab() (*gosym.Table, error) { // GetTypes returns a map of all types found in the binary file. func (f *GoFile) GetTypes() ([]*GoType, error) { - if f.FileInfo.goversion == nil { - ver, err := f.GetCompilerVersion() - if err != nil { - return nil, err - } - f.FileInfo.goversion = ver + err := f.ensureCompilerVersion() + if err != nil { + return nil, err } t, err := getTypes(f.FileInfo, f.fh) if err != nil { return nil, err } - if err = f.init(); err != nil { + if err = f.initPackages(); err != nil { return nil, err } return sortTypes(t), nil } -// Bytes returns a slice of raw bytes with the length in the file from the address. +// Bytes return a slice of raw bytes with the length in the file from the address. func (f *GoFile) Bytes(address uint64, length uint64) ([]byte, error) { base, section, err := f.fh.getSectionDataFromOffset(address) if err != nil { @@ -384,8 +438,8 @@ type fileHandler interface { getPCLNTABData() (uint64, []byte, error) moduledataSection() string getBuildID() (string, error) - GetFile() *os.File - GetParsedFile() any + getFile() *os.File + getParsedFile() any } func fileMagicMatch(buf, magic []byte) bool { diff --git a/file_test.go b/file_test.go index 23ad598..df817a1 100644 --- a/file_test.go +++ b/file_test.go @@ -174,11 +174,11 @@ type mockFileHandler struct { mGetSectionDataFromOffset func(uint64) (uint64, []byte, error) } -func (m *mockFileHandler) GetFile() *os.File { +func (m *mockFileHandler) getFile() *os.File { panic("not implemented") } -func (m *mockFileHandler) GetParsedFile() any { +func (m *mockFileHandler) getParsedFile() any { panic("not implemented") } diff --git a/goroot.go b/goroot.go index 63107e9..6d5efde 100644 --- a/goroot.go +++ b/goroot.go @@ -219,7 +219,7 @@ func tryFromTimeInit(f *GoFile) (string, error) { is32 = true } - // Find time.init function. + // Find time.initPackages function. var fcn *Function std, err := f.GetSTDLib() if err != nil { @@ -232,7 +232,7 @@ pkgLoop: continue } for _, vv := range v.Functions { - if vv.Name != "init" { + if vv.Name != "initPackages" { continue } fcn = vv diff --git a/macho.go b/macho.go index da5b327..5337b7f 100644 --- a/macho.go +++ b/macho.go @@ -44,11 +44,11 @@ type machoFile struct { osFile *os.File } -func (m *machoFile) GetParsedFile() any { +func (m *machoFile) getParsedFile() any { return m.file } -func (m *machoFile) GetFile() *os.File { +func (m *machoFile) getFile() *os.File { return m.osFile } diff --git a/modinfo.go b/modinfo.go index 98f8f59..7668841 100644 --- a/modinfo.go +++ b/modinfo.go @@ -39,7 +39,7 @@ type BuildInfo struct { } func (f *GoFile) extractBuildInfo() (*BuildInfo, error) { - info, err := buildinfo.Read(f.fh.GetFile()) + info, err := buildinfo.Read(f.fh.getFile()) if err != nil { return nil, fmt.Errorf("error when extracting build information: %w", err) } diff --git a/moduledata.go b/moduledata.go index 830e75e..ab1b901 100644 --- a/moduledata.go +++ b/moduledata.go @@ -30,23 +30,6 @@ import ( "strings" ) -// Moduledata extracts the file's moduledata. -func (f *GoFile) Moduledata() (Moduledata, error) { - // We need the Go version to be defined to find the module data. - ver, err := f.GetCompilerVersion() - if err != nil { - return nil, fmt.Errorf("could not get the Go version for the moduledata extraction: %w", err) - } - f.FileInfo.goversion = ver - - md, err := extractModuledata(f.FileInfo, f.fh) - if err != nil { - return nil, fmt.Errorf("error when parsing the moduledata: %w", err) - } - - return md, nil -} - // Moduledata holds information about the layout of the executable image in memory. type Moduledata interface { // Text returns the text secion. diff --git a/pe.go b/pe.go index 090c559..df0a919 100644 --- a/pe.go +++ b/pe.go @@ -59,11 +59,11 @@ type peFile struct { imageBase uint64 } -func (p *peFile) GetParsedFile() any { +func (p *peFile) getParsedFile() any { return p.file } -func (p *peFile) GetFile() *os.File { +func (p *peFile) getFile() *os.File { return p.osFile } From fb688ca98bfaaa619ecf94de56f8a42e222c2da7 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Sat, 3 Feb 2024 22:03:30 +0800 Subject: [PATCH 11/12] fix: check each tag package --- gen/stdpkgs.go | 52 +-- stdpkg_gen.go | 970 +++++++++++++++++++++++++------------------------ 2 files changed, 524 insertions(+), 498 deletions(-) diff --git a/gen/stdpkgs.go b/gen/stdpkgs.go index b8860c9..acc7a63 100644 --- a/gen/stdpkgs.go +++ b/gen/stdpkgs.go @@ -21,22 +21,30 @@ import ( "bytes" "context" "fmt" - "golang.org/x/mod/semver" "os" "sort" "strings" + "sync" "time" ) func generateStdPkgs() { - collect := func(ver string) ([]string, error) { - ctx := context.Background() - tree, _, err := githubClient.Git.GetTree(ctx, "golang", "go", ver, true) + wg := &sync.WaitGroup{} + collect := func(ctx context.Context, cause context.CancelCauseFunc, tag string, result chan []string) { + tree, _, err := githubClient.Git.GetTree(ctx, "golang", "go", tag, true) if err != nil { - return nil, err + cause(fmt.Errorf("error when getting tree for tag %s: %w", tag, err)) + return + } + + fmt.Println("Fetched std pkgs for tag:", tag) + + if len(tree.Entries) == 100000 { + fmt.Printf("Warning: tree %s has 100000 entries, this may be limited by api, some might be missing", tag) } var stdPkgs []string + for _, entry := range tree.Entries { if *entry.Type != "tree" { continue @@ -51,7 +59,8 @@ func generateStdPkgs() { stdPkgs = append(stdPkgs, strings.TrimPrefix(entry.GetPath(), "src/")) } - return stdPkgs, nil + result <- stdPkgs + wg.Done() } f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) @@ -63,30 +72,23 @@ func generateStdPkgs() { _ = f.Close() }(f) knownVersions, err := getCsvStoredGoversions(f) + wg.Add(len(knownVersions)) - branchs := map[string]struct{}{} - for ver := range knownVersions { - rawver := "v" + strings.TrimPrefix(ver, "go") - sver := semver.MajorMinor(rawver) - if sver != "" { - sver = "go" + strings.TrimPrefix(sver, "v") - if sver == "go1.0" { - sver = "go1" - } + stdpkgsSet := map[string]struct{}{} - branchs["release-branch."+sver] = struct{}{} - } + ctx, cause := context.WithCancelCause(context.Background()) + pkgsChan := make(chan []string) + + for tag := range knownVersions { + go collect(ctx, cause, tag, pkgsChan) } - stdpkgsSet := map[string]struct{}{} + go func() { + wg.Wait() + close(pkgsChan) + }() - for branch := range branchs { - fmt.Println("Fetching std pkgs for branch:", branch) - pkgs, err := collect(branch) - if err != nil { - fmt.Println("Error when fetching std pkgs:", err) - return - } + for pkgs := range pkgsChan { for _, pkg := range pkgs { stdpkgsSet[pkg] = struct{}{} } diff --git a/stdpkg_gen.go b/stdpkg_gen.go index 2326608..19f6afb 100644 --- a/stdpkg_gen.go +++ b/stdpkg_gen.go @@ -17,7 +17,7 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated at -// 2024-02-01 14:41:54.4508801 +0000 UTC +// 2024-02-03 13:33:47.6214248 +0000 UTC package gore @@ -36,6 +36,7 @@ var stdPkgs = map[string]struct{}{ "compress/gzip": {}, "compress/lzw": {}, "compress/zlib": {}, + "constraints": {}, "container": {}, "container/heap": {}, "container/list": {}, @@ -53,478 +54,499 @@ var stdPkgs = map[string]struct{}{ "crypto/ed25519/internal": {}, "crypto/ed25519/internal/edwards25519": {}, "crypto/ed25519/internal/edwards25519/field": {}, - "crypto/elliptic": {}, - "crypto/elliptic/internal": {}, - "crypto/elliptic/internal/fiat": {}, - "crypto/elliptic/internal/nistec": {}, - "crypto/hmac": {}, - "crypto/internal": {}, - "crypto/internal/alias": {}, - "crypto/internal/bigmod": {}, - "crypto/internal/boring": {}, - "crypto/internal/boring/bbig": {}, - "crypto/internal/boring/bcache": {}, - "crypto/internal/boring/fipstls": {}, - "crypto/internal/boring/sig": {}, - "crypto/internal/boring/syso": {}, - "crypto/internal/cipherhw": {}, - "crypto/internal/edwards25519": {}, - "crypto/internal/edwards25519/field": {}, - "crypto/internal/nistec": {}, - "crypto/internal/nistec/fiat": {}, - "crypto/internal/randutil": {}, - "crypto/internal/subtle": {}, - "crypto/md5": {}, - "crypto/rand": {}, - "crypto/rc4": {}, - "crypto/rsa": {}, - "crypto/sha1": {}, - "crypto/sha256": {}, - "crypto/sha512": {}, - "crypto/subtle": {}, - "crypto/tls": {}, - "crypto/tls/fipsonly": {}, - "crypto/x509": {}, - "crypto/x509/internal": {}, - "crypto/x509/internal/macos": {}, - "crypto/x509/pkix": {}, - "database": {}, - "database/sql": {}, - "database/sql/driver": {}, - "debug": {}, - "debug/buildinfo": {}, - "debug/dwarf": {}, - "debug/elf": {}, - "debug/gosym": {}, - "debug/macho": {}, - "debug/pe": {}, - "debug/plan9obj": {}, - "embed": {}, - "embed/internal": {}, - "embed/internal/embedtest": {}, - "encoding": {}, - "encoding/ascii85": {}, - "encoding/asn1": {}, - "encoding/base32": {}, - "encoding/base64": {}, - "encoding/binary": {}, - "encoding/csv": {}, - "encoding/gob": {}, - "encoding/hex": {}, - "encoding/json": {}, - "encoding/pem": {}, - "encoding/xml": {}, - "errors": {}, - "expvar": {}, - "flag": {}, - "fmt": {}, - "go": {}, - "go/ast": {}, - "go/build": {}, - "go/build/constraint": {}, - "go/constant": {}, - "go/doc": {}, - "go/doc/comment": {}, - "go/format": {}, - "go/importer": {}, - "go/internal": {}, - "go/internal/gccgoimporter": {}, - "go/internal/gcimporter": {}, - "go/internal/srcimporter": {}, - "go/internal/typeparams": {}, - "go/parser": {}, - "go/printer": {}, - "go/scanner": {}, - "go/token": {}, - "go/types": {}, - "go/types/fixedbugs": {}, - "hash": {}, - "hash/adler32": {}, - "hash/crc32": {}, - "hash/crc64": {}, - "hash/fnv": {}, - "hash/maphash": {}, - "html": {}, - "html/template": {}, - "image": {}, - "image/color": {}, - "image/color/palette": {}, - "image/draw": {}, - "image/gif": {}, - "image/internal": {}, - "image/internal/imageutil": {}, - "image/jpeg": {}, - "image/png": {}, - "index": {}, - "index/suffixarray": {}, - "internal": {}, - "internal/abi": {}, - "internal/bisect": {}, - "internal/buildcfg": {}, - "internal/bytealg": {}, - "internal/cfg": {}, - "internal/coverage": {}, - "internal/coverage/calloc": {}, - "internal/coverage/cformat": {}, - "internal/coverage/cmerge": {}, - "internal/coverage/decodecounter": {}, - "internal/coverage/decodemeta": {}, - "internal/coverage/encodecounter": {}, - "internal/coverage/encodemeta": {}, - "internal/coverage/pods": {}, - "internal/coverage/rtcov": {}, - "internal/coverage/slicereader": {}, - "internal/coverage/slicewriter": {}, - "internal/coverage/stringtab": {}, - "internal/coverage/test": {}, - "internal/coverage/uleb128": {}, - "internal/cpu": {}, - "internal/dag": {}, - "internal/diff": {}, - "internal/execabs": {}, - "internal/fmtsort": {}, - "internal/format": {}, - "internal/fuzz": {}, - "internal/goarch": {}, - "internal/godebug": {}, - "internal/godebugs": {}, - "internal/goexperiment": {}, - "internal/golang.org": {}, - "internal/golang.org/x": {}, - "internal/golang.org/x/net": {}, - "internal/golang.org/x/net/http2": {}, - "internal/golang.org/x/net/http2/hpack": {}, - "internal/goos": {}, - "internal/goroot": {}, - "internal/goversion": {}, - "internal/intern": {}, - "internal/itoa": {}, - "internal/lazyregexp": {}, - "internal/lazytemplate": {}, - "internal/nettrace": {}, - "internal/obscuretestdata": {}, - "internal/oserror": {}, - "internal/pkgbits": {}, - "internal/platform": {}, - "internal/poll": {}, - "internal/pprof": {}, - "internal/pprof/profile": {}, - "internal/profile": {}, - "internal/race": {}, - "internal/reflectlite": {}, - "internal/safefilepath": {}, - "internal/saferio": {}, - "internal/singleflight": {}, - "internal/syscall": {}, - "internal/syscall/execenv": {}, - "internal/syscall/unix": {}, - "internal/syscall/windows": {}, - "internal/syscall/windows/registry": {}, - "internal/syscall/windows/sysdll": {}, - "internal/sysinfo": {}, - "internal/testenv": {}, - "internal/testlog": {}, - "internal/testpty": {}, - "internal/trace": {}, - "internal/txtar": {}, - "internal/types": {}, - "internal/types/errors": {}, - "internal/unsafeheader": {}, - "internal/x": {}, - "internal/x/crypto": {}, - "internal/x/crypto/chacha20poly1305": {}, - "internal/x/crypto/cryptobyte": {}, - "internal/x/crypto/cryptobyte/asn1": {}, - "internal/x/crypto/curve25519": {}, - "internal/x/crypto/hkdf": {}, - "internal/x/crypto/internal": {}, - "internal/x/crypto/internal/chacha20": {}, - "internal/x/crypto/poly1305": {}, - "internal/x/net": {}, - "internal/x/net/dns": {}, - "internal/x/net/dns/dnsmessage": {}, - "internal/x/net/http": {}, - "internal/x/net/http/httpguts": {}, - "internal/x/net/http/httpproxy": {}, - "internal/x/net/http2": {}, - "internal/x/net/http2/hpack": {}, - "internal/x/net/idna": {}, - "internal/x/net/internal": {}, - "internal/x/net/internal/nettest": {}, - "internal/x/net/lif": {}, - "internal/x/net/nettest": {}, - "internal/x/net/route": {}, - "internal/x/text": {}, - "internal/x/text/secure": {}, - "internal/x/text/secure/bidirule": {}, - "internal/x/text/transform": {}, - "internal/x/text/unicode": {}, - "internal/x/text/unicode/bidi": {}, - "internal/x/text/unicode/norm": {}, - "internal/xcoff": {}, - "internal/zstd": {}, - "io": {}, - "io/fs": {}, - "io/ioutil": {}, - "lib9": {}, - "lib9/fmt": {}, - "lib9/utf": {}, - "libbio": {}, - "liblink": {}, - "libmach": {}, - "log": {}, - "log/internal": {}, - "log/slog": {}, - "log/slog/internal": {}, - "log/slog/internal/benchmarks": {}, - "log/slog/internal/buffer": {}, - "log/slog/internal/slogtest": {}, - "log/syslog": {}, - "maps": {}, - "math": {}, - "math/big": {}, - "math/bits": {}, - "math/cmplx": {}, - "math/rand": {}, - "mime": {}, - "mime/multipart": {}, - "mime/quotedprintable": {}, - "net": {}, - "net/http": {}, - "net/http/cgi": {}, - "net/http/cookiejar": {}, - "net/http/fcgi": {}, - "net/http/httptest": {}, - "net/http/httptrace": {}, - "net/http/httputil": {}, - "net/http/internal": {}, - "net/http/internal/ascii": {}, - "net/http/internal/testcert": {}, - "net/http/pprof": {}, - "net/internal": {}, - "net/internal/socktest": {}, - "net/mail": {}, - "net/netip": {}, - "net/rpc": {}, - "net/rpc/jsonrpc": {}, - "net/smtp": {}, - "net/textproto": {}, - "net/url": {}, - "os": {}, - "os/exec": {}, - "os/exec/internal": {}, - "os/exec/internal/fdtest": {}, - "os/signal": {}, - "os/signal/internal": {}, - "os/signal/internal/pty": {}, - "os/user": {}, - "path": {}, - "path/filepath": {}, - "pkg": {}, - "pkg/archive": {}, - "pkg/archive/tar": {}, - "pkg/archive/zip": {}, - "pkg/bufio": {}, - "pkg/builtin": {}, - "pkg/bytes": {}, - "pkg/compress": {}, - "pkg/compress/bzip2": {}, - "pkg/compress/flate": {}, - "pkg/compress/gzip": {}, - "pkg/compress/lzw": {}, - "pkg/compress/zlib": {}, - "pkg/container": {}, - "pkg/container/heap": {}, - "pkg/container/list": {}, - "pkg/container/ring": {}, - "pkg/crypto": {}, - "pkg/crypto/aes": {}, - "pkg/crypto/cipher": {}, - "pkg/crypto/des": {}, - "pkg/crypto/dsa": {}, - "pkg/crypto/ecdsa": {}, - "pkg/crypto/elliptic": {}, - "pkg/crypto/hmac": {}, - "pkg/crypto/md5": {}, - "pkg/crypto/rand": {}, - "pkg/crypto/rc4": {}, - "pkg/crypto/rsa": {}, - "pkg/crypto/sha1": {}, - "pkg/crypto/sha256": {}, - "pkg/crypto/sha512": {}, - "pkg/crypto/subtle": {}, - "pkg/crypto/tls": {}, - "pkg/crypto/x509": {}, - "pkg/crypto/x509/pkix": {}, - "pkg/database": {}, - "pkg/database/sql": {}, - "pkg/database/sql/driver": {}, - "pkg/debug": {}, - "pkg/debug/dwarf": {}, - "pkg/debug/elf": {}, - "pkg/debug/gosym": {}, - "pkg/debug/macho": {}, - "pkg/debug/pe": {}, - "pkg/debug/plan9obj": {}, - "pkg/encoding": {}, - "pkg/encoding/ascii85": {}, - "pkg/encoding/asn1": {}, - "pkg/encoding/base32": {}, - "pkg/encoding/base64": {}, - "pkg/encoding/binary": {}, - "pkg/encoding/csv": {}, - "pkg/encoding/gob": {}, - "pkg/encoding/hex": {}, - "pkg/encoding/json": {}, - "pkg/encoding/pem": {}, - "pkg/encoding/xml": {}, - "pkg/errors": {}, - "pkg/expvar": {}, - "pkg/flag": {}, - "pkg/fmt": {}, - "pkg/go": {}, - "pkg/go/ast": {}, - "pkg/go/build": {}, - "pkg/go/doc": {}, - "pkg/go/format": {}, - "pkg/go/parser": {}, - "pkg/go/printer": {}, - "pkg/go/scanner": {}, - "pkg/go/token": {}, - "pkg/hash": {}, - "pkg/hash/adler32": {}, - "pkg/hash/crc32": {}, - "pkg/hash/crc64": {}, - "pkg/hash/fnv": {}, - "pkg/html": {}, - "pkg/html/template": {}, - "pkg/image": {}, - "pkg/image/color": {}, - "pkg/image/color/palette": {}, - "pkg/image/draw": {}, - "pkg/image/gif": {}, - "pkg/image/jpeg": {}, - "pkg/image/png": {}, - "pkg/index": {}, - "pkg/index/suffixarray": {}, - "pkg/io": {}, - "pkg/io/ioutil": {}, - "pkg/log": {}, - "pkg/log/syslog": {}, - "pkg/math": {}, - "pkg/math/big": {}, - "pkg/math/cmplx": {}, - "pkg/math/rand": {}, - "pkg/mime": {}, - "pkg/mime/multipart": {}, - "pkg/net": {}, - "pkg/net/http": {}, - "pkg/net/http/cgi": {}, - "pkg/net/http/cookiejar": {}, - "pkg/net/http/fcgi": {}, - "pkg/net/http/httptest": {}, - "pkg/net/http/httputil": {}, - "pkg/net/http/pprof": {}, - "pkg/net/mail": {}, - "pkg/net/rpc": {}, - "pkg/net/rpc/jsonrpc": {}, - "pkg/net/smtp": {}, - "pkg/net/textproto": {}, - "pkg/net/url": {}, - "pkg/os": {}, - "pkg/os/exec": {}, - "pkg/os/signal": {}, - "pkg/os/user": {}, - "pkg/path": {}, - "pkg/path/filepath": {}, - "pkg/reflect": {}, - "pkg/regexp": {}, - "pkg/regexp/syntax": {}, - "pkg/runtime": {}, - "pkg/runtime/cgo": {}, - "pkg/runtime/debug": {}, - "pkg/runtime/pprof": {}, - "pkg/runtime/race": {}, - "pkg/sort": {}, - "pkg/strconv": {}, - "pkg/strings": {}, - "pkg/sync": {}, - "pkg/sync/atomic": {}, - "pkg/syscall": {}, - "pkg/testing": {}, - "pkg/testing/iotest": {}, - "pkg/testing/quick": {}, - "pkg/text": {}, - "pkg/text/scanner": {}, - "pkg/text/tabwriter": {}, - "pkg/text/template": {}, - "pkg/text/template/parse": {}, - "pkg/time": {}, - "pkg/unicode": {}, - "pkg/unicode/utf16": {}, - "pkg/unicode/utf8": {}, - "pkg/unsafe": {}, - "plugin": {}, - "reflect": {}, - "reflect/internal": {}, - "reflect/internal/example1": {}, - "reflect/internal/example2": {}, - "regexp": {}, - "regexp/syntax": {}, - "runtime": {}, - "runtime/asan": {}, - "runtime/cgo": {}, - "runtime/coverage": {}, - "runtime/debug": {}, - "runtime/internal": {}, - "runtime/internal/atomic": {}, - "runtime/internal/math": {}, - "runtime/internal/startlinetest": {}, - "runtime/internal/sys": {}, - "runtime/internal/syscall": {}, - "runtime/internal/wasitest": {}, - "runtime/metrics": {}, - "runtime/msan": {}, - "runtime/pprof": {}, - "runtime/pprof/internal": {}, - "runtime/pprof/internal/profile": {}, - "runtime/pprof/internal/protopprof": {}, - "runtime/race": {}, - "runtime/race/internal": {}, - "runtime/race/internal/amd64v1": {}, - "runtime/race/internal/amd64v3": {}, - "runtime/trace": {}, - "slices": {}, - "sort": {}, - "strconv": {}, - "strings": {}, - "sync": {}, - "sync/atomic": {}, - "syscall": {}, - "syscall/js": {}, - "testing": {}, - "testing/fstest": {}, - "testing/internal": {}, - "testing/internal/testdeps": {}, - "testing/iotest": {}, - "testing/quick": {}, - "testing/slogtest": {}, - "text": {}, - "text/scanner": {}, - "text/tabwriter": {}, - "text/template": {}, - "text/template/parse": {}, - "time": {}, - "time/tzdata": {}, - "unicode": {}, - "unicode/utf16": {}, - "unicode/utf8": {}, - "unsafe": {}, - "vendor": {}, - "vendor/golang.org": {}, - "vendor/golang.org/x": {}, - "vendor/golang.org/x/crypto": {}, - "vendor/golang.org/x/crypto/chacha20": {}, + "crypto/elliptic": {}, + "crypto/elliptic/internal": {}, + "crypto/elliptic/internal/fiat": {}, + "crypto/elliptic/internal/nistec": {}, + "crypto/hmac": {}, + "crypto/internal": {}, + "crypto/internal/alias": {}, + "crypto/internal/bigmod": {}, + "crypto/internal/boring": {}, + "crypto/internal/boring/bbig": {}, + "crypto/internal/boring/bcache": {}, + "crypto/internal/boring/fipstls": {}, + "crypto/internal/boring/sig": {}, + "crypto/internal/boring/syso": {}, + "crypto/internal/cipherhw": {}, + "crypto/internal/edwards25519": {}, + "crypto/internal/edwards25519/field": {}, + "crypto/internal/nistec": {}, + "crypto/internal/nistec/fiat": {}, + "crypto/internal/randutil": {}, + "crypto/internal/subtle": {}, + "crypto/md5": {}, + "crypto/rand": {}, + "crypto/rc4": {}, + "crypto/rsa": {}, + "crypto/sha1": {}, + "crypto/sha256": {}, + "crypto/sha512": {}, + "crypto/subtle": {}, + "crypto/tls": {}, + "crypto/tls/fipsonly": {}, + "crypto/x509": {}, + "crypto/x509/internal": {}, + "crypto/x509/internal/macOS": {}, + "crypto/x509/internal/macos": {}, + "crypto/x509/pkix": {}, + "database": {}, + "database/sql": {}, + "database/sql/driver": {}, + "database/sql/internal": {}, + "debug": {}, + "debug/buildinfo": {}, + "debug/dwarf": {}, + "debug/elf": {}, + "debug/goobj": {}, + "debug/gosym": {}, + "debug/macho": {}, + "debug/pe": {}, + "debug/plan9obj": {}, + "embed": {}, + "embed/internal": {}, + "embed/internal/embedtest": {}, + "encoding": {}, + "encoding/ascii85": {}, + "encoding/asn1": {}, + "encoding/base32": {}, + "encoding/base64": {}, + "encoding/binary": {}, + "encoding/csv": {}, + "encoding/gob": {}, + "encoding/hex": {}, + "encoding/json": {}, + "encoding/pem": {}, + "encoding/xml": {}, + "errors": {}, + "expvar": {}, + "flag": {}, + "fmt": {}, + "go": {}, + "go/ast": {}, + "go/build": {}, + "go/build/constraint": {}, + "go/constant": {}, + "go/doc": {}, + "go/doc/comment": {}, + "go/format": {}, + "go/importer": {}, + "go/internal": {}, + "go/internal/gccgoimporter": {}, + "go/internal/gcimporter": {}, + "go/internal/srcimporter": {}, + "go/internal/typeparams": {}, + "go/parser": {}, + "go/printer": {}, + "go/scanner": {}, + "go/token": {}, + "go/types": {}, + "go/types/fixedbugs": {}, + "go/version": {}, + "hash": {}, + "hash/adler32": {}, + "hash/crc32": {}, + "hash/crc64": {}, + "hash/fnv": {}, + "hash/maphash": {}, + "html": {}, + "html/template": {}, + "image": {}, + "image/color": {}, + "image/color/palette": {}, + "image/draw": {}, + "image/gif": {}, + "image/internal": {}, + "image/internal/imageutil": {}, + "image/jpeg": {}, + "image/png": {}, + "index": {}, + "index/suffixarray": {}, + "internal": {}, + "internal/abi": {}, + "internal/bisect": {}, + "internal/buildcfg": {}, + "internal/bytealg": {}, + "internal/cfg": {}, + "internal/chacha8rand": {}, + "internal/coverage": {}, + "internal/coverage/calloc": {}, + "internal/coverage/cformat": {}, + "internal/coverage/cmerge": {}, + "internal/coverage/decodecounter": {}, + "internal/coverage/decodemeta": {}, + "internal/coverage/encodecounter": {}, + "internal/coverage/encodemeta": {}, + "internal/coverage/pods": {}, + "internal/coverage/rtcov": {}, + "internal/coverage/slicereader": {}, + "internal/coverage/slicewriter": {}, + "internal/coverage/stringtab": {}, + "internal/coverage/test": {}, + "internal/coverage/uleb128": {}, + "internal/cpu": {}, + "internal/dag": {}, + "internal/diff": {}, + "internal/execabs": {}, + "internal/fmtsort": {}, + "internal/format": {}, + "internal/fuzz": {}, + "internal/goarch": {}, + "internal/godebug": {}, + "internal/godebugs": {}, + "internal/goexperiment": {}, + "internal/golang.org": {}, + "internal/golang.org/x": {}, + "internal/golang.org/x/net": {}, + "internal/golang.org/x/net/http2": {}, + "internal/golang.org/x/net/http2/hpack": {}, + "internal/goos": {}, + "internal/goroot": {}, + "internal/gover": {}, + "internal/goversion": {}, + "internal/intern": {}, + "internal/itoa": {}, + "internal/lazyregexp": {}, + "internal/lazytemplate": {}, + "internal/nettrace": {}, + "internal/obscuretestdata": {}, + "internal/oserror": {}, + "internal/pkgbits": {}, + "internal/platform": {}, + "internal/poll": {}, + "internal/pprof": {}, + "internal/pprof/profile": {}, + "internal/profile": {}, + "internal/race": {}, + "internal/reflectlite": {}, + "internal/safefilepath": {}, + "internal/saferio": {}, + "internal/singleflight": {}, + "internal/syscall": {}, + "internal/syscall/execenv": {}, + "internal/syscall/unix": {}, + "internal/syscall/windows": {}, + "internal/syscall/windows/registry": {}, + "internal/syscall/windows/sysdll": {}, + "internal/sysinfo": {}, + "internal/testenv": {}, + "internal/testlog": {}, + "internal/testpty": {}, + "internal/trace": {}, + "internal/trace/traceviewer": {}, + "internal/trace/traceviewer/format": {}, + "internal/trace/traceviewer/static": {}, + "internal/trace/v2": {}, + "internal/trace/v2/event": {}, + "internal/trace/v2/event/go122": {}, + "internal/trace/v2/internal": {}, + "internal/trace/v2/internal/testgen": {}, + "internal/trace/v2/internal/testgen/go122": {}, + "internal/trace/v2/raw": {}, + "internal/trace/v2/testtrace": {}, + "internal/trace/v2/version": {}, + "internal/txtar": {}, + "internal/types": {}, + "internal/types/errors": {}, + "internal/unsafeheader": {}, + "internal/x": {}, + "internal/x/crypto": {}, + "internal/x/crypto/chacha20poly1305": {}, + "internal/x/crypto/cryptobyte": {}, + "internal/x/crypto/cryptobyte/asn1": {}, + "internal/x/crypto/curve25519": {}, + "internal/x/crypto/hkdf": {}, + "internal/x/crypto/internal": {}, + "internal/x/crypto/internal/chacha20": {}, + "internal/x/crypto/poly1305": {}, + "internal/x/net": {}, + "internal/x/net/dns": {}, + "internal/x/net/dns/dnsmessage": {}, + "internal/x/net/http": {}, + "internal/x/net/http/httpguts": {}, + "internal/x/net/http/httpproxy": {}, + "internal/x/net/http2": {}, + "internal/x/net/http2/hpack": {}, + "internal/x/net/idna": {}, + "internal/x/net/internal": {}, + "internal/x/net/internal/nettest": {}, + "internal/x/net/lif": {}, + "internal/x/net/nettest": {}, + "internal/x/net/route": {}, + "internal/x/text": {}, + "internal/x/text/secure": {}, + "internal/x/text/secure/bidirule": {}, + "internal/x/text/transform": {}, + "internal/x/text/unicode": {}, + "internal/x/text/unicode/bidi": {}, + "internal/x/text/unicode/norm": {}, + "internal/xcoff": {}, + "internal/zstd": {}, + "io": {}, + "io/fs": {}, + "io/ioutil": {}, + "iter": {}, + "lib9": {}, + "lib9/fmt": {}, + "lib9/utf": {}, + "libbio": {}, + "liblink": {}, + "libmach": {}, + "log": {}, + "log/internal": {}, + "log/slog": {}, + "log/slog/internal": {}, + "log/slog/internal/benchmarks": {}, + "log/slog/internal/buffer": {}, + "log/slog/internal/slogtest": {}, + "log/syslog": {}, + "maps": {}, + "math": {}, + "math/big": {}, + "math/bits": {}, + "math/cmplx": {}, + "math/rand": {}, + "math/rand/v2": {}, + "mime": {}, + "mime/multipart": {}, + "mime/quotedprintable": {}, + "net": {}, + "net/http": {}, + "net/http/cgi": {}, + "net/http/cookiejar": {}, + "net/http/fcgi": {}, + "net/http/httptest": {}, + "net/http/httptrace": {}, + "net/http/httputil": {}, + "net/http/internal": {}, + "net/http/internal/ascii": {}, + "net/http/internal/testcert": {}, + "net/http/pprof": {}, + "net/internal": {}, + "net/internal/socktest": {}, + "net/mail": {}, + "net/netip": {}, + "net/rpc": {}, + "net/rpc/jsonrpc": {}, + "net/smtp": {}, + "net/textproto": {}, + "net/url": {}, + "os": {}, + "os/exec": {}, + "os/exec/internal": {}, + "os/exec/internal/fdtest": {}, + "os/signal": {}, + "os/signal/internal": {}, + "os/signal/internal/pty": {}, + "os/user": {}, + "path": {}, + "path/filepath": {}, + "pkg": {}, + "pkg/archive": {}, + "pkg/archive/tar": {}, + "pkg/archive/zip": {}, + "pkg/bufio": {}, + "pkg/builtin": {}, + "pkg/bytes": {}, + "pkg/compress": {}, + "pkg/compress/bzip2": {}, + "pkg/compress/flate": {}, + "pkg/compress/gzip": {}, + "pkg/compress/lzw": {}, + "pkg/compress/zlib": {}, + "pkg/container": {}, + "pkg/container/heap": {}, + "pkg/container/list": {}, + "pkg/container/ring": {}, + "pkg/crypto": {}, + "pkg/crypto/aes": {}, + "pkg/crypto/cipher": {}, + "pkg/crypto/des": {}, + "pkg/crypto/dsa": {}, + "pkg/crypto/ecdsa": {}, + "pkg/crypto/elliptic": {}, + "pkg/crypto/hmac": {}, + "pkg/crypto/md5": {}, + "pkg/crypto/rand": {}, + "pkg/crypto/rc4": {}, + "pkg/crypto/rsa": {}, + "pkg/crypto/sha1": {}, + "pkg/crypto/sha256": {}, + "pkg/crypto/sha512": {}, + "pkg/crypto/subtle": {}, + "pkg/crypto/tls": {}, + "pkg/crypto/x509": {}, + "pkg/crypto/x509/pkix": {}, + "pkg/database": {}, + "pkg/database/sql": {}, + "pkg/database/sql/driver": {}, + "pkg/debug": {}, + "pkg/debug/dwarf": {}, + "pkg/debug/elf": {}, + "pkg/debug/goobj": {}, + "pkg/debug/gosym": {}, + "pkg/debug/macho": {}, + "pkg/debug/pe": {}, + "pkg/debug/plan9obj": {}, + "pkg/encoding": {}, + "pkg/encoding/ascii85": {}, + "pkg/encoding/asn1": {}, + "pkg/encoding/base32": {}, + "pkg/encoding/base64": {}, + "pkg/encoding/binary": {}, + "pkg/encoding/csv": {}, + "pkg/encoding/gob": {}, + "pkg/encoding/hex": {}, + "pkg/encoding/json": {}, + "pkg/encoding/pem": {}, + "pkg/encoding/xml": {}, + "pkg/errors": {}, + "pkg/expvar": {}, + "pkg/flag": {}, + "pkg/fmt": {}, + "pkg/go": {}, + "pkg/go/ast": {}, + "pkg/go/build": {}, + "pkg/go/doc": {}, + "pkg/go/format": {}, + "pkg/go/parser": {}, + "pkg/go/printer": {}, + "pkg/go/scanner": {}, + "pkg/go/token": {}, + "pkg/hash": {}, + "pkg/hash/adler32": {}, + "pkg/hash/crc32": {}, + "pkg/hash/crc64": {}, + "pkg/hash/fnv": {}, + "pkg/html": {}, + "pkg/html/template": {}, + "pkg/image": {}, + "pkg/image/color": {}, + "pkg/image/color/palette": {}, + "pkg/image/draw": {}, + "pkg/image/gif": {}, + "pkg/image/jpeg": {}, + "pkg/image/png": {}, + "pkg/index": {}, + "pkg/index/suffixarray": {}, + "pkg/io": {}, + "pkg/io/ioutil": {}, + "pkg/log": {}, + "pkg/log/syslog": {}, + "pkg/math": {}, + "pkg/math/big": {}, + "pkg/math/cmplx": {}, + "pkg/math/rand": {}, + "pkg/mime": {}, + "pkg/mime/multipart": {}, + "pkg/net": {}, + "pkg/net/http": {}, + "pkg/net/http/cgi": {}, + "pkg/net/http/cookiejar": {}, + "pkg/net/http/fcgi": {}, + "pkg/net/http/httptest": {}, + "pkg/net/http/httputil": {}, + "pkg/net/http/pprof": {}, + "pkg/net/mail": {}, + "pkg/net/rpc": {}, + "pkg/net/rpc/jsonrpc": {}, + "pkg/net/smtp": {}, + "pkg/net/textproto": {}, + "pkg/net/url": {}, + "pkg/os": {}, + "pkg/os/exec": {}, + "pkg/os/signal": {}, + "pkg/os/user": {}, + "pkg/path": {}, + "pkg/path/filepath": {}, + "pkg/reflect": {}, + "pkg/regexp": {}, + "pkg/regexp/syntax": {}, + "pkg/runtime": {}, + "pkg/runtime/cgo": {}, + "pkg/runtime/debug": {}, + "pkg/runtime/pprof": {}, + "pkg/runtime/race": {}, + "pkg/sort": {}, + "pkg/strconv": {}, + "pkg/strings": {}, + "pkg/sync": {}, + "pkg/sync/atomic": {}, + "pkg/syscall": {}, + "pkg/testing": {}, + "pkg/testing/iotest": {}, + "pkg/testing/quick": {}, + "pkg/text": {}, + "pkg/text/scanner": {}, + "pkg/text/tabwriter": {}, + "pkg/text/template": {}, + "pkg/text/template/parse": {}, + "pkg/time": {}, + "pkg/unicode": {}, + "pkg/unicode/utf16": {}, + "pkg/unicode/utf8": {}, + "pkg/unsafe": {}, + "plugin": {}, + "reflect": {}, + "reflect/internal": {}, + "reflect/internal/example1": {}, + "reflect/internal/example2": {}, + "regexp": {}, + "regexp/syntax": {}, + "runtime": {}, + "runtime/asan": {}, + "runtime/cgo": {}, + "runtime/coverage": {}, + "runtime/debug": {}, + "runtime/internal": {}, + "runtime/internal/atomic": {}, + "runtime/internal/math": {}, + "runtime/internal/startlinetest": {}, + "runtime/internal/sys": {}, + "runtime/internal/syscall": {}, + "runtime/internal/wasitest": {}, + "runtime/metrics": {}, + "runtime/msan": {}, + "runtime/pprof": {}, + "runtime/pprof/internal": {}, + "runtime/pprof/internal/profile": {}, + "runtime/pprof/internal/protopprof": {}, + "runtime/race": {}, + "runtime/race/internal": {}, + "runtime/race/internal/amd64v1": {}, + "runtime/race/internal/amd64v3": {}, + "runtime/trace": {}, + "slices": {}, + "sort": {}, + "strconv": {}, + "strings": {}, + "sync": {}, + "sync/atomic": {}, + "syscall": {}, + "syscall/js": {}, + "testing": {}, + "testing/fstest": {}, + "testing/internal": {}, + "testing/internal/testdeps": {}, + "testing/iotest": {}, + "testing/quick": {}, + "testing/slogtest": {}, + "text": {}, + "text/scanner": {}, + "text/tabwriter": {}, + "text/template": {}, + "text/template/parse": {}, + "time": {}, + "time/tzdata": {}, + "unicode": {}, + "unicode/utf16": {}, + "unicode/utf8": {}, + "unsafe": {}, + "vendor": {}, + "vendor/golang.org": {}, + "vendor/golang.org/x": {}, + "vendor/golang.org/x/crypto": {}, + "vendor/golang.org/x/crypto/chacha20": {}, "vendor/golang.org/x/crypto/chacha20poly1305": {}, "vendor/golang.org/x/crypto/cryptobyte": {}, "vendor/golang.org/x/crypto/cryptobyte/asn1": {}, @@ -547,6 +569,8 @@ var stdPkgs = map[string]struct{}{ "vendor/golang.org/x/net/http2": {}, "vendor/golang.org/x/net/http2/hpack": {}, "vendor/golang.org/x/net/idna": {}, + "vendor/golang.org/x/net/lex": {}, + "vendor/golang.org/x/net/lex/httplex": {}, "vendor/golang.org/x/net/lif": {}, "vendor/golang.org/x/net/nettest": {}, "vendor/golang.org/x/net/route": {}, From e2fa922c9dec3d3ab516d901bfd9083954ca405b Mon Sep 17 00:00:00 2001 From: Zxilly Date: Sun, 4 Feb 2024 00:17:13 +0800 Subject: [PATCH 12/12] chore: resolve conflict --- gen/goversion.go | 59 +++++++++++++++++++++++++++++++++++------------- gen/utils.go | 30 ++++++------------------ 2 files changed, 50 insertions(+), 39 deletions(-) diff --git a/gen/goversion.go b/gen/goversion.go index fd89ef8..46362c9 100644 --- a/gen/goversion.go +++ b/gen/goversion.go @@ -20,9 +20,12 @@ package main import ( "bytes" "context" + "encoding/csv" "fmt" "github.com/google/go-github/v58/github" + "io" "os" + "sort" "strings" "time" ) @@ -45,8 +48,6 @@ func generateGoVersions() { opts.Page = resp.NextPage } - // Get mode commit info for new tags - f, err := os.OpenFile(goversionCsv, os.O_CREATE|os.O_RDWR, 0664) if err != nil { fmt.Println("Error when opening goversions.csv:", err) @@ -55,24 +56,18 @@ func generateGoVersions() { defer func(f *os.File) { _ = f.Close() }(f) + knownVersions, err := getCsvStoredGoversions(f) if err != nil { fmt.Println("Error when getting stored go versions:", err) return } - _, err = fmt.Fprintln(f, "version,sha,date") - if err != nil { - fmt.Println("Error when writing csv header:", err) - return - } - for _, tag := range allTags { if strings.HasPrefix(tag.GetName(), "weekly") || strings.HasPrefix(tag.GetName(), "release") { continue } - if v, known := knownVersions[tag.GetName()]; known { - _, _ = fmt.Fprintf(f, "%s,%s,%s\n", v.Name, v.Sha, v.Date) + if _, known := knownVersions[tag.GetName()]; known { continue } @@ -81,20 +76,52 @@ func generateGoVersions() { fmt.Println("Error when getting commit info:", err) return } - _, _ = fmt.Fprintf(f, "%s,%s,%s\n", tag.GetName(), commit.GetSHA(), commit.GetCommitter().GetCreatedAt().String()) - fmt.Println("New tag found:", tag.Name) - knownVersions[tag.GetName()] = &goversion{Name: tag.GetName(), Sha: commit.GetSHA(), Date: commit.GetCommitter().GetCreatedAt().String()} + + fmt.Println("New tag found:", tag.GetName()) + knownVersions[tag.GetName()] = &goversion{Name: tag.GetName(), Sha: commit.GetSHA(), Date: commit.GetCommit().GetCommitter().GetDate().Format(time.RFC3339)} + } + + sortedVersion := make([]*goversion, 0, len(knownVersions)) + for _, ver := range knownVersions { + sortedVersion = append(sortedVersion, ver) } + sort.Slice(sortedVersion, func(i, j int) bool { + time1, err := time.Parse(time.RFC3339, sortedVersion[i].Date) + if err != nil { + fmt.Println("Error when parsing time:", err) + return false + } + time2, err := time.Parse(time.RFC3339, sortedVersion[j].Date) + if err != nil { + fmt.Println("Error when parsing time:", err) + return false + } + return time1.Before(time2) + }) + // Generate the code. - buf := bytes.NewBuffer(nil) + err = f.Truncate(0) + if err != nil { + fmt.Println("Error when truncating the file:", err) + return + } + _, _ = f.Seek(0, io.SeekStart) + + cw := csv.NewWriter(f) + for _, ver := range sortedVersion { + _ = cw.Write([]string{ver.Name, ver.Sha, ver.Date}) + } + cw.Flush() + + buf := bytes.NewBuffer(nil) err = goversionTemplate.Execute(buf, struct { Timestamp time.Time - GoVersions map[string]*goversion + GoVersions []*goversion }{ Timestamp: time.Now().UTC(), - GoVersions: knownVersions, + GoVersions: sortedVersion, }) if err != nil { fmt.Println("Error when generating the code:", err) diff --git a/gen/utils.go b/gen/utils.go index 2bc97bd..8dca033 100644 --- a/gen/utils.go +++ b/gen/utils.go @@ -18,8 +18,7 @@ package main import ( - "bufio" - "errors" + "encoding/csv" "fmt" "go/format" "os" @@ -90,28 +89,13 @@ func getSourceDir() string { func getCsvStoredGoversions(f *os.File) (map[string]*goversion, error) { vers := make(map[string]*goversion) - r := bufio.NewScanner(f) - // Read header - if !r.Scan() { - return nil, errors.New("empty file") + c, err := csv.NewReader(f).ReadAll() + if err != nil { + return nil, err } - r.Text() - - for r.Scan() { - row := r.Text() - if row == "" { - continue - } - data := strings.Split(row, ",") - if data[0] == "" { - // No version - continue - } - version := strings.TrimSpace(data[0]) - sha := strings.TrimSpace(data[1]) - date := strings.TrimSpace(data[2]) - vers[version] = &goversion{Name: version, Sha: sha, Date: date} + for _, line := range c { + vers[line[0]] = &goversion{Name: line[0], Sha: line[1], Date: line[2]} } - _, err := f.Seek(0, 0) + return vers, err }