Skip to content

cmd/go: allow -mlsx -mlasx cgo flags for loong64 #71597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ideal opened this issue Feb 7, 2025 · 6 comments
Closed

cmd/go: allow -mlsx -mlasx cgo flags for loong64 #71597

ideal opened this issue Feb 7, 2025 · 6 comments
Labels
arch-loong64 Issues solely affecting the loongson architecture. BugReport Issues describing a possible bug in the Go implementation. FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ideal
Copy link

ideal commented Feb 7, 2025

Go version

go version go1.23.4 linux/loong64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='loong64'
GOBIN=''
GOCACHE='/home/ideal/.cache/go-build'
GOENV='/home/ideal/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='loong64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ideal/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ideal/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/home/ideal/go/pkg/mod/golang.org/[email protected]'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/ideal/go/pkg/mod/golang.org/[email protected]/pkg/tool/linux_loong64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/ideal/.config/go/telemetry'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ideal/project/ollama2/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 -mabi=lp64d -pthread -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2938728940=/tmp/go-build -gno-record-gcc-switches'

What did you do?

With:

// #cgo linux,loong64 CFLAGS: -mlasx
// #cgo linux,loong64 CPPFLAGS: -mlasx

What did you see happen?

Running go build will show: invalid flag in #cgo CPPFLAGS: -mlasx.

But these are valid flags on loongarch64:

-mlasx
-mno-lasx
-mlsx
-mno-lsx

What did you expect to see?

go build succeeds.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 7, 2025
@seankhliao seankhliao changed the title cgo: invalid flags on loongarch64 cmd/cgo: allow lsx lasx flags for loong64 Feb 7, 2025
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 7, 2025
@seankhliao seankhliao added the arch-loong64 Issues solely affecting the loongson architecture. label Feb 7, 2025
@seankhliao
Copy link
Member

cc @golang/loong64

@cherrymui cherrymui added this to the Backlog milestone Feb 7, 2025
@cherrymui cherrymui changed the title cmd/cgo: allow lsx lasx flags for loong64 cmd/go: allow -mlsx -mlasx cgo flags for loong64 Feb 7, 2025
@cherrymui cherrymui removed the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 7, 2025
@cherrymui
Copy link
Member

Seems reasonable. Feel free to send a CL (see the contribution guide). Thanks.

@cherrymui cherrymui added the NeedsFix The path to resolution is known, but the work has not been done. label Feb 7, 2025
@xen0n
Copy link
Member

xen0n commented Feb 7, 2025

There are more arch-specific flags described in the LoongArch Toolchain Conventions spec, so we would probably include all of them. Would you prepare a patch or leave it to the loong64 port team? Just in case you already have some CL prepared.

@ianlancetaylor
Copy link
Contributor

FYI, the list of accepted flags is in the file $GOROOT/src/cmd/go/internal/work/security.go.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/647956 mentions this issue: cmd/go/internal/work: allow a bunch of loong64-specific flags

@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Feb 10, 2025
@dmitshur dmitshur modified the milestones: Backlog, Go1.25 Feb 10, 2025
@dmitshur dmitshur added the GoCommand cmd/go label Feb 10, 2025
MingcongBai pushed a commit to AOSC-Tracking/go that referenced this issue Feb 17, 2025
Recognize and allow all LoongArch-specific CFLAGS as standardized
in the LoongArch Toolchain Conventions v1.1, and implemented in current
versions of GCC and Clang, to enable advanced cgo use cases on loong64.
These flags are also allowed for linker invocations in case of possible
LTO.

See: https://github.com/loongson/la-toolchain-conventions/blob/releases/v1.1/LoongArch-toolchain-conventions-EN.adoc#list

While at it, also add support for -mtls-dialect as some C programs
may benefit performance-wise from the optional TLSDESC usage. This flag
is not specific to loong64 though; it is available for amd64, arm,
arm64, loong64, riscv64 and x86.

Fixes golang#71597.

Change-Id: I35d2507edb71fa324ae429a3ae3c739644a9cac1
Reviewed-on: https://go-review.googlesource.com/c/go/+/647956
LUCI-TryBot-Result: Go LUCI <[email protected]>
Commit-Queue: Ian Lance Taylor <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: abner chenc <[email protected]>
Reviewed-by: Meidan Li <[email protected]>

Link: https://go-review.googlesource.com/c/go/+/647956
Signed-off-by: Mingcong Bai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-loong64 Issues solely affecting the loongson architecture. BugReport Issues describing a possible bug in the Go implementation. FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants