Skip to content
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

Gazelle fails on macOS when using apple_support and go version 1.22+ #1793

Open
redsun82 opened this issue Apr 29, 2024 · 8 comments
Open

Gazelle fails on macOS when using apple_support and go version 1.22+ #1793

redsun82 opened this issue Apr 29, 2024 · 8 comments

Comments

@redsun82
Copy link

When defining this minimal MODULE.bazel:

module(name="foo", version="0.0")

bazel_dep(name = "apple_support", version = "1.15.1")
bazel_dep(name = "gazelle", version = "0.36.0")
bazel_dep(name = "rules_go", version = "0.47.0")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.0")  # also with versions 1.22.1 and 1.22.2

and creating the usual BUILD.bazel:

load("@gazelle//:def.bzl", "gazelle")

gazelle(name = "gazelle")

then when I bazel run //:gazelle I get

runtime/cgo(__TEXT/__text): relocation target pthread_sigmask not defined
runtime/cgo(__TEXT/__text): relocation target pthread_self not defined
runtime/cgo(__TEXT/__text): relocation target pthread_get_stacksize_np not defined
runtime/cgo(__TEXT/__text): relocation target pthread_attr_init not defined
runtime/cgo(__TEXT/__text): relocation target pthread_attr_setstacksize not defined
runtime/cgo(__TEXT/__text): relocation target free not defined
runtime/cgo(__TEXT/__text): relocation target __stderrp not defined
runtime/cgo(__TEXT/__text): relocation target strerror not defined
runtime/cgo(__TEXT/__text): relocation target fprintf not defined
runtime/cgo(__TEXT/__text): relocation target abort not defined
runtime/cgo(__TEXT/__text): relocation target pthread_create not defined
runtime/cgo(__TEXT/__text): relocation target nanosleep not defined
runtime/cgo(__TEXT/__text): relocation target pthread_detach not defined
runtime/cgo(__TEXT/__text): relocation target pthread_mutex_lock not defined
runtime/cgo(__TEXT/__text): relocation target pthread_cond_wait not defined
runtime/cgo(__TEXT/__text): relocation target pthread_key_create not defined
runtime/cgo(__TEXT/__text): relocation target pthread_mutex_unlock not defined
runtime/cgo(__TEXT/__text): relocation target __stderrp not defined
runtime/cgo(__TEXT/__text): relocation target fprintf not defined
runtime/cgo(__TEXT/__text): relocation target abort not defined
runtime/cgo(__TEXT/__text): relocation target pthread_setspecific not defined
external/rules_go~~go_sdk~foo__download_0/pkg/tool/darwin_arm64/link: too many errors
link: error running subcommand external/rules_go~~go_sdk~foo__download_0/pkg/tool/darwin_arm64/link: exit status 2
Target //:gazelle failed to build

Commenting out either the apple_support dependency or using a lower go version works ok.

If it helps, I'm running this on an M1 macOS, with bazel version 7.1.1. Funnily enough, bazel build @gazelle//cmd/gazelle builds ok, so it seems this is only happening when building it [for tool].

@redsun82
Copy link
Author

Also, running with --@rules_go//go/config:pure is a workaround, but it's not ideal as I have the feeling it then runs quite slower.

redsun82 added a commit to github/codeql that referenced this issue Apr 29, 2024
@redsun82
Copy link
Author

See github/codeql@b0758fd for a workaround based on using the 1.21.9 go toolchain just for gazelle on macOS.

@aaronsky
Copy link
Contributor

I've been running into this for weeks now as well. I'm in a codebase where we must include apple_support in order to drive rules_apple, but also have some custom Gazelle functionality to support other kinds of programs. We are stuck on Go 1.21 until this is corrected, workarounds notwithstanding.

The only research I've managed to do with my limited knowledge of rules_go and the Go linker is that the output from --subcommands between Go 1.21 and 1.22 is identical. As far as I know, there is more behavior within the builder wrapper that occurs before or as part of the linker being invoked, so this is probably not very illuminating.

@fmeum
Copy link
Member

fmeum commented Apr 30, 2024

Which version of Xcode are you on? I think I saw similar error messages on Slack and this was resolved by just updating to the latest version.

@aaronsky
Copy link
Contributor

aaronsky commented Apr 30, 2024

I am on the latest stable release, Xcode 15.3. Using --xcode_version_config to aid in discovery.

Which Slack messages are you referring to? I am here via this.

@ewhauser
Copy link

ewhauser commented May 4, 2024

Seems like this may be an upstream problem: uber/hermetic_cc_toolchain#171

@ewhauser
Copy link

ewhauser commented May 8, 2024

This caused by the -dead-strip flag in rules_apple_support. See this PR: bazelbuild/apple_support#309

and this Slack thread: https://bazelbuild.slack.com/archives/CDBP88Z0D/p1715173028271439

@aaronsky
Copy link
Contributor

aaronsky commented Jul 4, 2024

Discovered yesterday while experimenting with Go 1.22.5 that this does not occur for me anymore. Xcode 15.4, apple_support 1.15.1, rules_go 0.48.1 and latest gazelle. Not sure it will make a difference for y'all, but maybe something upstream changed that's working for me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants