Skip to content

Change in macOS CROSSTOOL breaks rules_go #6283

Closed

Description

@katre

The commit 19a401c has caused an error during the build for rules_go. Logs are available here: https://buildkite.com/bazel/bazel-with-downstream-projects-bazel/builds/472#f9e3ac01-fa0a-4903-b10d-09a2f5550c88

(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in libversion.a(cxx_version.o)
--
  | Dwarf Exception Unwind Info (__eh_frame) in libversion.a(cxx_version.o)
  | ld: symbol(s) not found for architecture x86_64
  | clang: error: linker command failed with exit code 1 (use -v to see invocation)
  |  
  | GoLink: error running subcommand: exit status 2
  | ERROR: /Users/buildkite/builds/buildkite-imacpro-5-1/bazel-downstream-projects/rules_go/tests/legacy/examples/cgo/BUILD.bazel:38:1: Couldn't build file tests/legacy/examples/cgo/darwin_amd64_stripped/cgo_lib_test: GoLink tests/legacy/examples/cgo/darwin_amd64_stripped/cgo_lib_test failed (Exit 1) link failed: error executing command bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/darwin_amd64_stripped/link -sdk external/go_sdk -installsuffix darwin_amd64 -arc ... (remaining 18 argument(s) skipped)
  |  
  | Use --sandbox_debug to see verbose messages from the sandbox
  | external/go_sdk/pkg/tool/darwin_amd64/link: running external/local_config_cc/cc_wrapper.sh failed: exit status 1
  | Undefined symbols for architecture x86_64:

Commit 19a401c was identified by bisecting the Bazel source.

Activity

  1. added
    P1
    z-team-Apple
    on Oct 1, 2018
  2. katre commented on Oct 1, 2018

    @katre
    CollaboratorAuthor

    CC @jayconrod for rules_go. This looks to be bazel-internal, but please let me know if you have any ideas.

    Specifically, I'd like to know if this is a release blocker for 0.19.0 (#6116).

  3. aragos commented on Oct 1, 2018

    @aragos
    Contributor

    From a colleague who took a look:

    https://github.com/bazelbuild/rules_go/blob/6915510b32e2d61702ae8208b0e64070e52056d2/go/private/context.bzl#L336
    probs this?
    it looks like -lc++ was coming from linker_flags
    possibly mostly_static_link_options does not include the new feature configured flag

  4. jayconrod commented on Oct 1, 2018

    @jayconrod
    Contributor

    I reproduced this and poked around a bit. I can confirm what @aragos said: the only flags I'm getting from mostly_static_link_options are:

    -headerpad_max_install_names -no-canonical-prefixes
    
  5. trybka commented on Oct 1, 2018

    @trybka
    Contributor

    mostly_static_link_options fall into the legacy CROSSTOOL fields, I think:
    https://docs.bazel.build/versions/master/skylark/backward-compatibility.html#disable-legacy-c-toolchain-api

    There are potentially other link flags that are missing at this point?

  6. tburgin commented on Oct 1, 2018

    @tburgin

    Actually there is already special handling for the c++ linking flags in the go_rules. The rules know if there is c++ source, adding the linker flag here seems like a good fit.

    diff --git a/go/private/rules/cgo.bzl b/go/private/rules/cgo.bzl
    index 631facc..9c34200 100644
    --- a/go/private/rules/cgo.bzl
    +++ b/go/private/rules/cgo.bzl
    @@ -207,6 +207,8 @@ def _cgo_codegen_impl(ctx):
         have_cc = len(source.cxx) + len(source.objc) + len(ctx.attr.deps) > 0
         if not have_cc:
             linkopts = [o for o in linkopts if o not in ("-lstdc++", "-lc++")]
    +    else:
    +        linkopts.append("-lc++")
    
         tool_args.add_all(["-objdir", out_dir])
    

    The failing tests passes with this patch. Running all go_rules tests now.

  7. tburgin commented on Oct 1, 2018

    @tburgin

    Running on macOS all tests pass with the ^^ patch. One downside to changing the go rules is all platforms are effected and should be thoroughly tested.

  8. jayconrod commented on Oct 1, 2018

    @jayconrod
    Contributor

    @tburgin I'm not sure rules_go can figure that out in general. The C++ standard library name varies by toolchain, and there are even multiple implementations that can be used with the same compiler. It would be better for that flag to come from the toolchain.

    I'm not entirely comfortable with the code above because I don't have a full list of C++ library names. We needed that hack though for Go programs that run in containers where libstdc++.so isn't available.

  9. tburgin commented on Oct 1, 2018

    @tburgin

    Gotcha, I am really only familiar with darwin ;) The darwin toolchain prior to 19a401c was unconditionally adding -lc++ to all link actions.
    Adding Go's linking action to the link_libc++ feature would get the darwin toolchain back to where it was. I am not super familiar with the go rules, is there a c++-link-* equivalent for go (go-link-executable etc.)?

    I don't fully understand @trybka's comment, but that may also be another way forward.

  10. 21 remaining items

  11. hlopko commented on Oct 6, 2018

    @hlopko
    Member

    Thanks John!

  12. jayconrod commented on Oct 17, 2018

    @jayconrod
    Contributor

    @katre @mhlopko I released a change yesterday in rules_go which gathers flags from cc_common instead of CcToolchainInfo. I believe we are no longer accessing the deprecated fields of CcToolchainInfo. I built Bazel at 19a401c and ran the rules_go tests at 0.16.0, 0.15.5, and 0.14.3 (the newly released versions) on macOS. Everything passes.

    Hopefully, it should be safe to roll this change forward.

  13. hlopko commented on Oct 18, 2018

    @hlopko
    Member

    Awesome! thanks!

  14. katre commented on Oct 18, 2018

    @katre
    CollaboratorAuthor

    I think we still need to make sure downstream projects of rules_go update before I can roll forward the change. I'll take care of coordinating and testing that, I have a list of projects available.

  15. katre commented on Oct 18, 2018

    @katre
    CollaboratorAuthor

    Actually, wait, I was thinking of a different change in rules_go. :)

    I will roll this forward with tests regardless.

  16. katre commented on Oct 18, 2018

    @katre
    CollaboratorAuthor

    @jayconrod After testing the rollfoward, I see this error:

    Information about the C++ toolchain API is not accessible anymore through ctx.fragments.cpp (see --incompatible_disable_legacy_cpp_toolchain_skylark_api on http://docs.bazel.build/versions/master/skylark/backward-compatibility.html#disable-legacy-c-configuration-api for migration notes). Use CcToolchainInfo instead.
    

    (From https://buildkite.com/bazel/bazel-with-downstream-projects-bazel/builds/514#916b75fd-9952-47dc-b399-b4f89dad8799).

    Does this mean we do need to update projects to use the latest rules_go release before this CL goes in?

    Affected projects in Bazel CI:

    • buildtools
    • rules_docker
    • rules_k8s
    • rules_typescript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1platform: appletype: bugz-team-Apple

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions