Skip to content

Commit ad5aa91

Browse files
committed
fix: enhance wasm function size handling for Go 1.25+
1 parent 6895f4e commit ad5aa91

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

internal/knowninfo/dependencies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (m *Dependencies) AddFromPclntab(gp *gore.Package, typ entity.PackageType,
119119
return f.End - f.Offset
120120
}
121121

122-
return w.GetFunctionSize(f.Offset)
122+
return w.GetFunctionSize(f.Offset, m.k.VersionFlag.Meq125)
123123
}
124124

125125
p := entity.NewPackageWithGorePackage(gp, name, typ, pclntab, getCodeSize, isWasm)

internal/knowninfo/knowninfo.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
type VersionFlag struct {
1313
Leq118 bool
1414
Meq120 bool
15+
Meq125 bool // Go 1.25+ changed wasm pclntab to store PC_F instead of full PC
1516
}
1617

1718
type KnownInfo struct {
@@ -35,14 +36,16 @@ type KnownInfo struct {
3536
}
3637

3738
func (k *KnownInfo) LoadGoreInfo(f *gore.GoFile, isWasm bool) error {
39+
slog.Info("Loading version flag")
40+
k.VersionFlag = UpdateVersionFlag(f)
41+
slog.Info("Loaded version flag")
42+
3843
err := k.LoadPackages(f, isWasm)
3944
if err != nil {
4045
return err
4146
}
4247

43-
slog.Info("Loading version flag and meta info...")
44-
k.VersionFlag = UpdateVersionFlag(f)
45-
slog.Info("Loaded version flag")
48+
slog.Info("Loading meta info...")
4649
k.PClnTabAddr = f.GetPCLNTableAddr()
4750
slog.Info("Loaded meta info")
4851

@@ -62,6 +65,7 @@ func UpdateVersionFlag(f *gore.GoFile) VersionFlag {
6265
return VersionFlag{
6366
Leq118: gore.GoVersionCompare(ver.Name, "go1.18.10") <= 0,
6467
Meq120: gore.GoVersionCompare(ver.Name, "go1.20rc1") >= 0,
68+
Meq125: gore.GoVersionCompare(ver.Name, "go1.25rc1") >= 0,
6569
}
6670
}
6771

internal/wrapper/wasm.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ var _ RawFileWrapper = (*WasmWrapper)(nil)
2323

2424
const funcValueOffset = 0x1000
2525

26-
func (w *WasmWrapper) GetFunctionSize(idx uint64) uint64 {
27-
// get PC_F from PC
28-
idx = idx >> 16
26+
func (w *WasmWrapper) GetFunctionSize(idx uint64, meq125 bool) uint64 {
27+
// Go 1.25+ stores PC_F directly in pclntab, older versions store full PC (PC_F << 16)
28+
if !meq125 {
29+
idx = idx >> 16
30+
}
2931
idx = idx - funcValueOffset
3032

3133
return uint64(len(w.module.CodeSection[idx].Body))

0 commit comments

Comments
 (0)