gccgo: compile cgo got error in aarch64, clang, gold (or lld) #54367
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I didn't test golang/go master branch, but there should be.
What operating system and processor architecture are you using (
go env
)?go env
OutputLinux kernel 4.19.90 aarch64
What did you do?
A simple cgo code:
export GCCGO="/usr/gcc-12.1.0-install/bin/gccgo"
export CC="/usr/llvm/bin/clang"
export CXX="/usr/llvm/bin/clang++"
(LD_LIBRARY_PATH also needs to be set)
(1) If not use gccgo, these commands all work properly.
(2) If use gccgo, but use ld linker (default is ld) , these commands also work properly.
go build -a -compiler=gccgo cgo.go go build -a -compiler=gccgo -gccgoflags="-fuse-ld=bfd" cgo.go
(3) If use gccgo, but use gold or lld linker, got some error:
I found some split-stack checks in the code.
Position 1:
In src/cmd/go/internal/work/exec.go#L2816 :
The
BuildToolchain.compiler()
is/usr/gcc-12.1.0-install/bin/gccgo
, so here is check whethergccgo
support-fsplit-stack
.# /usr/gcc-12.1.0-install/bin/gccgo -fsplit-stack -c -x c - -o /dev/null cc1: error: ‘-fsplit-stack’ is not supported by this compiler configuration
So,
gccgo
does not support-fsplit-stack
in my env.Position 2:
In src/cmd/go/internal/work/gccgo.go#L569:
The variable
compiler[0]
is${CC}
, in my env, it was/usr/llvm/bin/clang
. so here is check whetherclang
support-fsplit-stack
.# /usr/llvm/bin/clang -fsplit-stack -c -x c - -o /dev/null
No errors, which means that
clang
supports-fsplit-stack
in my env.Therefore, from the above results, I guess:
The gccgo compile go code in non-split-stack mode.
And the clang compile c code in split-stack mode.
Finally, the gold or lld linker reports an error when linking the two object files.
I see the comments in gollvm :
The preceding test results comply with the description here.
So, in aarch64, I can't use gccgo with clang and gold (or lld).
I have two ideas for a fix.
① If it is detected that the
gccgo
does not supportsplit-stack
,${CC}
does not check whether it supports split-stack and directly uses the non-split-stack mode. On the other hand, if it is checked that${CC}
does not support split-stack, thengccgo
is also directly in non-split-stack mode.② Modify the current split-stack checking method, which does not take the linker into account.
If a linker is used,
${CC}
may detect that split-stack is not supported so that it is consistent withgccgo
.What do you think?
What did you expect to see?
When use clang, gold (or lld) in aarch64, gccgo compile and run cgo successfully in split-stack or non-split-stack mode.
What did you see instead?
gold or lld reports an error.
The text was updated successfully, but these errors were encountered: