overwrite a function (or just anything). Target doesn't need to be exported. Go doesn't support overloading. Can't be done multiple times (i.e. trying to overwrite time.Sleep()
fails as it's actually the unexported runtime.timeSleep()
).
package main
import (
"fmt"
_ "unsafe" // required to enable go:linkname
"log"
)
//go:linkname boom log.Print
func boom(v ...any) {
_ = v
fmt.Println("boom")
}
func main() {
log.Print("hi") // prints "boom", not "hi"
}