Skip to content

Commit

Permalink
Merge pull request #70 from derekparker/add-gofunc-support
Browse files Browse the repository at this point in the history
Add support for parsing and returning GoFunc value
  • Loading branch information
TcM1911 authored Nov 10, 2023
2 parents 3009b39 + 9712683 commit 8de0e40
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 11 additions & 0 deletions moduledata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -80,6 +82,8 @@ type moduledata struct {
FuncTabAddr, FuncTabLen uint64
PCLNTabAddr, PCLNTabLen uint64

GoFuncVal uint64

fh fileHandler
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -378,6 +387,8 @@ func processModuledata(data interface{}) (moduledata, error) {
md.TypesLen = md.TypesLen - md.TypesAddr
}

extractModFieldValue(&md, "GoFuncVal", val, "GoFunc")

return md, nil
}

Expand Down
14 changes: 9 additions & 5 deletions moduledata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
})
}
}

0 comments on commit 8de0e40

Please sign in to comment.