Skip to content

Latest commit

 

History

547 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reflectx

Golang reflect package hack tools

Build Status

Go Version

  • Go 1.21 ~ 1.27

Compilers

Platforms

  • macOS
  • Linux
  • Windows
  • WebAssembly

Go ABI

Field

  • reflectx.CanSet
  • reflectx.Field
  • reflectx.FieldByIndex
  • reflectx.FieldByName
  • reflectx.FieldByNameFunc

Named

  • reflectx.StructOf
  • reflectx.NamedTypeOf
  • reflectx.SetUnderlying
  • reflectx.SetTypeName

Method

  • reflectx.Method

  • reflectx.MakeMethod

  • reflectx.NewMethodSet

  • reflectx.SetMethodSet

  • reflectx.StructToMethodSet

Interface

  • reflectx.InterfaceOf
  • reflectx.NamedInterfaceOf
  • reflectx.NewInterfaceType
  • reflectx.SetInterfaceType

Context

  • reflectx.NewContext

Method allocs (icall)

Default gc path: each installed method needs a unique ifn stub.

  • allocs
import _ "github.com/goplus/reflectx/icall/icall[N]"
  • install icall_gen
go install github.com/goplus/reflectx/cmd/icall_gen@latest
icall_gen -o icall1024.go -pkg main -size 1024

ifacefuncval (optional)

Alternative to icall: methods share makeFuncStub instead of an icall stub table. reflectx stores an untagged *makeFuncImpl in addReflectOff and sets tflagIfaceFuncval (1<<6). A patched runtime tags itab.Fun (makeFuncImpl*|1) so interface calls unwrap.

Needs a patched Go 1.25.x, 1.26.x, or 1.27.x and an explicit tag. Supported GOARCH: wasm, arm64, amd64, 386.

  • install iface_patch
go install github.com/goplus/reflectx/cmd/iface_patch@latest
iface_patch /path/to/go   # 1.25.x, 1.26.x, or 1.27.x
cd /path/to/go/src && ./make.bash
export GOROOT=/path/to/go
export PATH="$GOROOT/bin:$PATH"
go test -tags goplus.ifacefuncval .
# wasip1: GOOS=wasip1 GOARCH=wasm go test -exec wasmtime -tags goplus.ifacefuncval .

Without the tag, a patched compiler matches official gc. An unpatched compiler still accepts the tag; interface method calls then trap.

You can export GOFLAGS='-tags=goplus.ifacefuncval', or prefix a command: GOFLAGS='-tags=goplus.ifacefuncval' go build (also go run / go test).

See cmd/iface_patch/README.md.

build linkname mode

go build -tags linknamefix -ldflags="-checklinkname=0"

About

Golang reflect package hack tools

Resources

Stars

35 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages