Skip to content

cmd/link: issues with Apple's new linker in Xcode 15 beta [1.20 backport] #62597

Closed
@gopherbot

Description

@gopherbot

@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.

Activity

added this to the Go1.20.9 milestone on Sep 12, 2023
cherrymui

cherrymui commented on Sep 12, 2023

@cherrymui
Member

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:

gopherbot

gopherbot commented on Sep 12, 2023

@gopherbot
ContributorAuthor

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

gopherbot commented on Sep 12, 2023

@gopherbot
ContributorAuthor

Change https://go.dev/cl/527818 mentions this issue: [release-branch.go1.20] cmd/link: force old Apple linker in plugin mode

gopherbot

gopherbot commented on Sep 12, 2023

@gopherbot
ContributorAuthor

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

gopherbot

gopherbot commented on Sep 21, 2023

@gopherbot
ContributorAuthor

Closed by merging 071f03a to release-branch.go1.20.

gopherbot

gopherbot commented on Sep 21, 2023

@gopherbot
ContributorAuthor

Closed by merging 08c544d to release-branch.go1.20.

gopherbot

gopherbot commented on Sep 21, 2023

@gopherbot
ContributorAuthor

Closed by merging 83dce45 to release-branch.go1.20.

lespea

lespea commented on Sep 22, 2023

@lespea

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

cherrymui commented on Sep 25, 2023

@cherrymui
Member

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 or release-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 variable CGO_LDFLAGS=-Wl,-ld_classic to choose the old Apple linker.

578559967

578559967 commented on Nov 16, 2023

@578559967

-Wl,-force_load flag need to be ignored when check ld_classic is supported in linkerFlagSupported.

cherrymui

cherrymui commented on Nov 16, 2023

@cherrymui
Member

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

578559967 commented on Nov 17, 2023

@578559967

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.

We pass -Wl,-force_load myclib.a -lotherlibA -lotherlibB in CGO_LDFLAGS to link some C libs. But linkerFlagSupported 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

cherrymui commented on Nov 17, 2023

@cherrymui
Member

So you suggest adding -Wl,-force_load to trimLinkerArgv 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 to trimLinkerArgv. Try updating to Go 1.21.4.

locked and limited conversation to collaborators on Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CherryPickApprovedUsed during the release process for point releasesFrozenDueToAgecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lespea@578559967@gopherbot@cherrymui@joedian

        Issue actions

          cmd/link: issues with Apple's new linker in Xcode 15 beta [1.20 backport] · Issue #62597 · golang/go