gccgo: go compile got error in aarch64, lld #54790
Labels
arch-arm64
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 aarch64
What did you do?
A simple helloworld.go:
export GCCGO="/usr/gcc-12.1.0-install/bin/gccgo"
(LD_LIBRARY_PATH also needs to be set)
Test results:
collect2: error: ld returned 1 exit status
And then I have some analysis, which may not be correct.
First, in aarch64, gccgo doesn't support
-fsplit-stack
.# gccgo -fsplit-stack helloworld.go go1: error: ‘-fsplit-stack’ is not supported by this compiler configuration
I found go command create and compile a
_buildid.s
. Rungo build -a -x -work -compiler=gccgo -gccgoflags="-fuse-ld=lld" helloworld.go
I see:
I see
_buildid.s
contains a special section.note.GNU-split-stack
, it was added at cmd/go/internal/work/buildid.go:335.See below:
In lld/ELF/InputFiles.cpp:994 of llvm-project
main
branch , if it detected a name.note.GNU-split-stack
, it will set variablesplitStack
astrue
.See below:
In lld/ELF/InputSection.cpp:654 , the variable
splitStack
is true, it will call functionadjustSplitStackFunctionPrologues
.See below:
In function adjustSplitStackFunctionPrologues , in aarch64, the variable
needsMoreStackNonSplit
is alway true, so it always call functionswitchMorestackCallsToMorestackNonSplit
.See below:
In function switchMorestackCallsToMorestackNonSplit, it cannot found
__morestack_non_split
symbol, so it throws a error ofmixing split-stack objects requires a definition of __morestack_non_split
.See below:
When the
split-stack
mode is not supported, it still write section.note.GNU-split-stack
into_buildid.s
. I think, this led to the problem.If
split-stack
is not supported, is it a correct fix to not write section.note.GNU-split-stack
into_buildid.s
?Note: The cause of this problem is not the same as another cgo compilation problem.
What did you expect to see?
In aarch64, run
go build -a -compiler=gccgo -gccgoflags="-fuse-ld=lld" helloworld.go
success.What did you see instead?
lld reports an error:
The text was updated successfully, but these errors were encountered: