cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
4.9k stars 473 forks source link

Incompatible with Go 1.23 due to locking down `linkname` using #1146

Open HeRaNO opened 2 weeks ago

HeRaNO commented 2 weeks ago

Describe the bug

Upstream JSON lib sonic is suffering from linkname usage locking down. And it affects hertz according to reports.

          got the same issue from `cloudwego/hertz`.

Originally posted by @xin-hao-awx in https://github.com/bytedance/sonic/issues/660#issuecomment-2190483847

Also can find more information at https://github.com/bytedance/sonic/issues/637

BTW, linkname is used in hertz, too. So maybe we need an investigation.

To Reproduce

  1. Download Go 1.23 RC1
  2. Build a naive Hertz project
  3. See errors in building phase

Expected behavior

No error should be presented.

Hertz version:

On develop branch

Environment:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/test/.cache/go-build'
GOENV='/home/test/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/test/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/test/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23rc1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/test/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/home/test/xcpc-team-reg-main/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2791510403=/tmp/go-build -gno-record-gcc-switches'

Additional context

We have an update PR (#1106 ) but idle for a time. I can compile a naive hertz project with Go 1.21, and it runs OK. Please consider bumping the PR status.

li-jin-gou commented 2 weeks ago

refer to https://www.cloudwego.io/zh/docs/hertz/tutorials/basic-feature/json/

image

HeRaNO commented 2 weeks ago

refer to https://www.cloudwego.io/zh/docs/hertz/tutorials/basic-feature/json/

For the following code:

package main

import (
    "context"

    "github.com/cloudwego/hertz/pkg/app"
    "github.com/cloudwego/hertz/pkg/app/server"
    "github.com/cloudwego/hertz/pkg/common/utils"
    "github.com/cloudwego/hertz/pkg/protocol/consts"
)

func main() {
    h := server.Default(server.WithHostPorts(":12345"))

    h.GET("/ping", func(c context.Context, ctx *app.RequestContext) {
        ctx.JSON(consts.StatusOK, utils.H{"ping": "pong"})
    })

    h.Spin()
}

Compiling with Go 1.23-rc1:

go build -tags stdjson

and the error message is:

# github.com/bytedance/sonic/loader
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/funcdata.go:37:32: undefined: _func
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/funcdata.go:74:12: undefined: moduledata
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/funcdata.go:77:18: undefined: moduledata
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/funcdata.go:188:28: undefined: compilationUnit
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/stubs.go:27:22: undefined: moduledata
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/stubs.go:29:26: undefined: moduledata
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/stubs.go:34:27: undefined: moduledata
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/stubs.go:36:36: undefined: moduledata
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/stubs.go:46:21: undefined: moduledata
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/stubs.go:50:22: undefined: moduledata
../go/pkg/mod/github.com/bytedance/sonic@v1.11.3/loader/stubs.go:50:22: too many errors

In addition, hertz also has linkname used in protobuf codegen. I'm afraid it cannot compile under Go 1.23 even if we bypass sonic issue.

HeRaNO commented 2 weeks ago

I found that we used sonic https://github.com/cloudwego/hertz/blob/develop/pkg/app/server/binding/internal/decoder/sonic_required.go here, but with a wrong(?) gjson tag. Not sure whether we should change it to stdjson.

HeRaNO commented 1 week ago

@li-jin-gou Hi. The code above cannot be compiled under Go 1.23-rc1. Could you please take a look?