Closed
Description
@cherrymui requested issue #61229 to be considered for backport to the next 1.20 minor release.
@gopherbot please backport this to Go 1.20 and 1.21 releases. I'll fill in the details in the corresponding issues. Thanks.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
cherrymui commentedon Sep 12, 2023
Xcode 15 (to be released some time soon) will include Apple's new linker, enabled by default. There are a number of issues with running Go 1.20 with the new Apple linker, from linker warnings to program fail to run. There are a number of fixes/workarounds included in Go 1.21 and tip, but I think they are too many to backport. So for 1.20, I propose we force to use the old Apple linker. I'm pretty sure the old Apple linker will be around for long enough time to cover the lifetime of Go 1.20.
We also want to backport CL https://go.dev/cl/527415, to disable DWARF by default for c-shared mode (otherwise the new Apple linker doesn't accept the c-shared object). We need this because the user may link the c-shared object with C code without going through the Go toolchain, so can't force old linker for this.
We also want to backport CL https://go.dev/cl/508696, which suppresses a warning. Apparently, although the old linker doesn't emit the warning and we pass a flag to force the old linker, it still emits the warning, probably because the new linker parses flags before exec'ing the old linker.
Specifically, CLs to be included in Go 1.20 branch:
-ld_classic
to force the old linkergopherbot commentedon Sep 12, 2023
Change https://go.dev/cl/527798 mentions this issue:
[release-branch.go1.20] cmd/link: suppress -bind_at_load deprecation warning for ld-prime
gopherbot commentedon Sep 12, 2023
Change https://go.dev/cl/527818 mentions this issue:
[release-branch.go1.20] cmd/link: force old Apple linker in plugin mode
gopherbot commentedon Sep 12, 2023
Change https://go.dev/cl/527819 mentions this issue:
[release-branch.go1.20] cmd/link: disable DWARF by default in c-shared mode on darwin
[release-branch.go1.20] cmd/link: force old Apple linker in plugin mode
[release-branch.go1.20] cmd/link: disable DWARF by default in c-share…
[release-branch.go1.20] cmd/link: suppress -bind_at_load deprecation …
gopherbot commentedon Sep 21, 2023
Closed by merging 071f03a to release-branch.go1.20.
gopherbot commentedon Sep 21, 2023
Closed by merging 08c544d to release-branch.go1.20.
gopherbot commentedon Sep 21, 2023
Closed by merging 83dce45 to release-branch.go1.20.
lespea commentedon Sep 22, 2023
This is a major issue for us... do you think it's going to be a while before a patch release with this fix?
cherrymui commentedon Sep 25, 2023
The next Go 1.20.9 release will likely be available next week.
In the mean time, you can build Go from source using the
release-branch.go1.20
orrelease-branch.go1.21
branch (which has the same content as the next minor release), or from tip. Or you can work around this by passing command line flag-ldflags=-extldflags=-Wl,-ld_classic
or environment variableCGO_LDFLAGS=-Wl,-ld_classic
to choose the old Apple linker.578559967 commentedon Nov 16, 2023
-Wl,-force_load flag need to be ignored when check ld_classic is supported in linkerFlagSupported.
cherrymui commentedon Nov 16, 2023
Where is
-Wl,-force_load
from? I don't think the go toolchain pass it. If you pass it on the command line, usually we don't filter user-passed flags. And as you already pass flags, you probably can just pass-ld_classic
or-ld_new
yourself.578559967 commentedon Nov 17, 2023
We pass
-Wl,-force_load myclib.a -lotherlibA -lotherlibB
in CGO_LDFLAGS to link some C libs. ButlinkerFlagSupported
ignored-lotherlibA -lotherlibB
and keeps the-Wl,-force_load myclib.a
and fails the test due to some undefined symbol errors instead of-ld_classic
not supported by the linker.As the
-ld_classic
is only supported in the newer linker, I need to pass this flag on demand. I don't want to do the repeated job as the compiler already did.cherrymui commentedon Nov 17, 2023
So you suggest adding
-Wl,-force_load
totrimLinkerArgv
https://cs.opensource.google/go/go/+/master:src/cmd/link/internal/ld/lib.go;l=2082 ? That seems reasonable.On the other hand, we don't test
-ld_classic
on tip, and for most cases in Go 1.21.4. I don't think we want to backport a change totrimLinkerArgv
. Try updating to Go 1.21.4.