From 9712683971422dd2baeee0c393addced5b6c8afd Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Thu, 2 Nov 2023 15:08:19 -0700 Subject: [PATCH] Add support for parsing and returning GoFunc value --- moduledata.go | 11 +++++++++++ moduledata_test.go | 14 +++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/moduledata.go b/moduledata.go index 61f1e56..8f00952 100644 --- a/moduledata.go +++ b/moduledata.go @@ -65,6 +65,8 @@ type Moduledata interface { ITabLinks() ModuleDataSection // TypeLink returns the typelink section. TypeLink() ([]int32, error) + // GoFuncValue returns the value of the 'go:func.*' symbol. + GoFuncValue() uint64 } type moduledata struct { @@ -80,6 +82,8 @@ type moduledata struct { FuncTabAddr, FuncTabLen uint64 PCLNTabAddr, PCLNTabLen uint64 + GoFuncVal uint64 + fh fileHandler } @@ -187,6 +191,11 @@ func (m moduledata) TypeLink() ([]int32, error) { return a, nil } +// GoFuncValue returns the value of the "go:func.*" symbol. +func (m moduledata) GoFuncValue() uint64 { + return m.GoFuncVal +} + // ModuleDataSection is a section defined in the Moduledata structure. type ModuleDataSection struct { // Address is the virtual address where the section start. @@ -378,6 +387,8 @@ func processModuledata(data interface{}) (moduledata, error) { md.TypesLen = md.TypesLen - md.TypesAddr } + extractModFieldValue(&md, "GoFuncVal", val, "GoFunc") + return md, nil } diff --git a/moduledata_test.go b/moduledata_test.go index 5055567..62b48af 100644 --- a/moduledata_test.go +++ b/moduledata_test.go @@ -34,12 +34,14 @@ func TestModuledata(t *testing.T) { data, dataLen uint64 bss, bssLen uint64 noptrbss, noptrbssLen uint64 + gofunc uint64 }{ - {"gold-linux-amd64-1.16.0", 0x00401000, 0x98277, 0x00538020, 0xe2c4, 0x00546300, 0x7790, 0x0054daa0, 0x2d750, 0x0057b200, 0x5310}, - {"gold-linux-amd64-1.8.0", 0x00401000, 0x7c7d0, 0x004f9000, 0x24c8, 0x004fb4e0, 0x1d10, 0x004fd200, 0x1a908, 0x00517b20, 0x46a0}, - {"gold-linux-amd64-1.7.0", 0x00401000, 0x7d2a0, 0x004f8000, 0x2048, 0x004fa060, 0x1d70, 0x004fbde0, 0x1a910, 0x00516700, 0x4e80}, - {"gold-linux-amd64-1.5.0", 0x00401000, 0xb15f0, 0x00590000, 0x1bc8, 0x00591be0, 0x2550, 0x00594140, 0x23bd8, 0x005b7d20, 0x4e40}, - {"gold-linux-386-1.16.0", 0x08049000, 0x846d9, 0x0815a020, 0xdda4, 0x08167de0, 0x3c28, 0x0816ba20, 0x11cfc, 0x0817d720, 0x45e0}, + {"gold-linux-amd64-1.20.0", 0x00401000, 0x80f84, 0x515180, 0x105c0, 0x525740, 0x78f0, 0x52d040, 0x2dd60, 0x55ada0, 0x39d0, 0x4a1e88}, + {"gold-linux-amd64-1.16.0", 0x00401000, 0x98277, 0x00538020, 0xe2c4, 0x00546300, 0x7790, 0x0054daa0, 0x2d750, 0x0057b200, 0x5310, 0}, + {"gold-linux-amd64-1.8.0", 0x00401000, 0x7c7d0, 0x004f9000, 0x24c8, 0x004fb4e0, 0x1d10, 0x004fd200, 0x1a908, 0x00517b20, 0x46a0, 0}, + {"gold-linux-amd64-1.7.0", 0x00401000, 0x7d2a0, 0x004f8000, 0x2048, 0x004fa060, 0x1d70, 0x004fbde0, 0x1a910, 0x00516700, 0x4e80, 0}, + {"gold-linux-amd64-1.5.0", 0x00401000, 0xb15f0, 0x00590000, 0x1bc8, 0x00591be0, 0x2550, 0x00594140, 0x23bd8, 0x005b7d20, 0x4e40, 0}, + {"gold-linux-386-1.16.0", 0x08049000, 0x846d9, 0x0815a020, 0xdda4, 0x08167de0, 0x3c28, 0x0816ba20, 0x11cfc, 0x0817d720, 0x45e0, 0}, } for _, test := range cases { @@ -82,6 +84,8 @@ func TestModuledata(t *testing.T) { mdSec = md.FuncTab() r.NotEqual(0, mdSec.Address) r.NotEqual(0, mdSec.Length) + + r.Equal(test.gofunc, md.GoFuncValue()) }) } }