Skip to content

Commit c8a93c0

Browse files
committed
Add magic bytes and moduledata struct for 1.20
1 parent d31997e commit c8a93c0

File tree

2 files changed

+112
-4
lines changed

2 files changed

+112
-4
lines changed

moduledata.go

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,13 @@ func parseModuledata(fileInfo *FileInfo, f fileHandler) (moduledata, error) {
252252

253253
// Determine what kind of struct we need to extract the module data from the file.
254254

255-
if GoVersionCompare("go1.18beta1", fileInfo.goversion.Name) <= 0 {
255+
if GoVersionCompare("go1.20rc1", fileInfo.goversion.Name) <= 0 {
256+
if is32bit {
257+
buf = &moduledata2032{}
258+
} else {
259+
buf = &moduledata2064{}
260+
}
261+
} else if GoVersionCompare("go1.18beta1", fileInfo.goversion.Name) <= 0 {
256262
if is32bit {
257263
buf = &moduledata1832{}
258264
} else {
@@ -402,7 +408,105 @@ func extractModFieldValue(md *moduledata, dst string, val reflect.Value, src str
402408
Internal module structures from Go's runtime.
403409
*/
404410

405-
// Moduledata structure for Go 1.18 and newer
411+
// Moduledata structure for Go 1.20 and newer
412+
413+
type moduledata2064 struct {
414+
PcHeader uint64
415+
Funcnametab, Funcnametablen, Funcnametabcap uint64
416+
Cutab, Cutablen, Cutabcap uint64
417+
Filetab, Filetablen, Filetabcap uint64
418+
Pctab, Pctablen, Pctabcap uint64
419+
Pclntable, Pclntablelen, Pclntablecap uint64
420+
Ftab, Ftablen, Ftabcap uint64
421+
Findfunctab uint64
422+
Minpc, Maxpc uint64
423+
424+
Text, Etext uint64
425+
Noptrdata, Enoptrdata uint64
426+
Data, Edata uint64
427+
Bss, Ebss uint64
428+
Noptrbss, Enoptrbss uint64
429+
Covctrs, Ecovctrs uint64
430+
End, Gcdata, Gcbss uint64
431+
Types, Etypes uint64
432+
RData uint64
433+
GoFunc uint64
434+
435+
Textsectmap, Textsectmaplen, Textsectmapcap uint64
436+
Typelinks, Typelinkslen, Typelinkscap uint64 // offsets from types
437+
Itablinks, Itablinkslen, Itablinkscap uint64
438+
439+
Ptab, Ptablen, Ptabcap uint64
440+
441+
Pluginpath, Pluginpathlen uint64
442+
Pkghashes, Pkghasheslen, Pkghashescap uint64
443+
444+
Modulename, Modulenamelen uint64
445+
Modulehashes, Modulehasheslen, Modulehashescap uint64
446+
447+
/* These fields we are not planning to use so skipping the parsing of them.
448+
449+
hasmain uint8 // 1 if module contains the main function, 0 otherwise
450+
451+
gcdatamask, gcbssmask bitvector
452+
453+
typemap map[typeOff]*_type // offset to *_rtype in previous module
454+
455+
bad bool // module failed to load and should be ignored
456+
457+
next *moduledata
458+
*/
459+
}
460+
461+
type moduledata2032 struct {
462+
PcHeader uint32
463+
Funcnametab, Funcnametablen, Funcnametabcap uint32
464+
Cutab, Cutablen, Cutabcap uint32
465+
Filetab, Filetablen, Filetabcap uint32
466+
Pctab, Pctablen, Pctabcap uint32
467+
Pclntable, Pclntablelen, Pclntablecap uint32
468+
Ftab, Ftablen, Ftabcap uint32
469+
Findfunctab uint32
470+
Minpc, Maxpc uint32
471+
472+
Text, Etext uint32
473+
Noptrdata, Enoptrdata uint32
474+
Data, Edata uint32
475+
Bss, Ebss uint32
476+
Noptrbss, Enoptrbss uint32
477+
Covctrs, Ecovctrs uint32
478+
End, Gcdata, Gcbss uint32
479+
Types, Etypes uint32
480+
RData uint32
481+
GoFunc uint32
482+
483+
Textsectmap, Textsectmaplen, Textsectmapcap uint32
484+
Typelinks, Typelinkslen, Typelinkscap uint32 // offsets from types
485+
Itablinks, Itablinkslen, Itablinkscap uint32
486+
487+
Ptab, Ptablen, Ptabcap uint32
488+
489+
Pluginpath, Pluginpathlen uint32
490+
Pkghashes, Pkghasheslen, Pkghashescap uint32
491+
492+
Modulename, Modulenamelen uint32
493+
Modulehashes, Modulehasheslen, Modulehashescap uint32
494+
495+
/* These fields we are not planning to use so skipping the parsing of them.
496+
497+
hasmain uint8 // 1 if module contains the main function, 0 otherwise
498+
499+
gcdatamask, gcbssmask bitvector
500+
501+
typemap map[typeOff]*_type // offset to *_rtype in previous module
502+
503+
bad bool // module failed to load and should be ignored
504+
505+
next *moduledata
506+
*/
507+
}
508+
509+
// Moduledata structure for Go 1.18 and Go 1.19
406510

407511
type moduledata1864 struct {
408512
PcHeader uint64

pclntab.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ var pclntab12magic = []byte{0xfb, 0xff, 0xff, 0xff, 0x0, 0x0}
3131
var pclntab116magic = []byte{0xfa, 0xff, 0xff, 0xff, 0x0, 0x0}
3232

3333
// pclntab118magic is the magic bytes used for binaries compiled with
34-
// Go 1.18 and onwards.
34+
// Go 1.18 and Go 1.19.
3535
var pclntab118magic = []byte{0xf0, 0xff, 0xff, 0xff, 0x0, 0x0}
3636

37+
// pclntab120magic is the magic bytes used for binaries compiled with
38+
// Go 1.20 and onwards.
39+
var pclntab120magic = []byte{0xf1, 0xff, 0xff, 0xff, 0x0, 0x0}
40+
3741
// searchFileForPCLNTab will search the .rdata and .text section for the
3842
// PCLN table. Note!! The address returned by this function needs to be
3943
// adjusted by adding the image base address!!!
@@ -63,7 +67,7 @@ func searchSectionForTab(secData []byte) ([]byte, error) {
6367
// First check for the current magic used. If this fails, it could be
6468
// an older version. So check for the old header.
6569
MAGIC_LOOP:
66-
for _, magic := range [][]byte{pclntab118magic, pclntab116magic, pclntab12magic} {
70+
for _, magic := range [][]byte{pclntab120magic, pclntab118magic, pclntab116magic, pclntab12magic} {
6771
off := bytes.LastIndex(secData, magic)
6872
if off == -1 {
6973
continue // Try other magic.

0 commit comments

Comments
 (0)