pkujhd / goloader

load and run golang code at runtime.
Apache License 2.0
497 stars 58 forks source link

Can't get example to run using Go 1.20 #69

Closed mbertschler closed 1 year ago

mbertschler commented 1 year ago

I tried to follow the examples using Go 1.20, but when it came to running a built object with the loader it failed:

./loader -o schedule.o -run main.main -times 10
Load error: unknown reloc type:41 sym:os.Stdout

My Go version:

go version go1.20.1 darwin/arm64

Steps to reproduce

I had to adjust the steps mentioned in the example a little bit, since I don't use the $GOROOT and $GOPATH environment variables and use go modules, but I am pretty sure that the equivalents I used should do the same thing. What I ran:

cp -r $(go env GOROOT)/src/cmd/internal $(go env GOROOT)/src/cmd/objfile
go list -export -f '{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}' std `go list -f {{.Imports}} ./examples/schedule/schedule.go | awk '{sub(/^\[/, ""); print }' | awk '{sub(/\]$/, ""); print }'` > importcfg
go tool compile -importcfg importcfg ./examples/schedule/schedule.go

Building the loader first failed:

go build ./examples/loader 
# github.com/pkujhd/goloader/mmap
/var/folders/hz/zg7qtlwx48577swvbw11jl0c0000gn/T/go-build3589589142/b081/_cgo_gotypes.go:24:6: type aliases requires go1.9 or later (-lang was set to go1.8; check go.mod)

So I changed to go.mod file to go 1.20. After this building it worked.

But actually running the loader with the schedule example failed:

./loader -o schedule.o -run main.main -times 10
Load error: unknown reloc type:41 sym:os.Stdout

Please let me know if I misunderstood the example instructions, or if there might be a bug. Thank you!

pkujhd commented 1 year ago

@mbertschler ,it is a bug, new relocate type is not support. I will fix it when I have time

mbertschler commented 1 year ago

That is good to know, thanks for checking it

mbertschler commented 1 year ago

Thank you very much for the fix @pkujhd, with this we could upgrade our application to Go 1.20 🎉