Skip to content

Bazel 0.15.0 breaks C++ linking on MacOS #5468

Closed

Description

@jmillikin-stripe

Description of the problem / feature request:

After updating to Bazel 0.15.0, C++ binaries are being linked with the flag -Wl,-no-as-needed which does not exist in the MacOS linker.

$ bazel-0.15.0 build //:hello
ERROR: /Users/jmillikin/src/test-bazel-gcc/BUILD:1:1: Linking of rule '//:hello' failed (Exit 1)
ld: unknown option: -no-as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //:hello failed to build
Use --verbose_failures to see the command lines of failed build steps.
$ cc --version
Apple LLVM version 10.0.0 (clang-1000.10.25.5)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ ld -v
@(#)PROGRAM:ld  PROJECT:ld64-408.1.1
BUILD 05:18:43 May 25 2018
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 10.0.0, (clang-1000.10.25.5) (static support for 21, runtime is 21)
TAPI support using: Apple TAPI version 10.0.0 (tapi-1000.0.7.3)

What operating system are you running Bazel on?

MacOS

What's the output of bazel info release?

release 0.15.0

Activity

  1. jmillikin-stripe commented on Jun 26, 2018

    @jmillikin-stripe
    ContributorAuthor

    It looks like the implementation of _is_linker_option_supported() is broken for Apple's Clang:

    diff --git a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl
    index 3141b0bc25..4bee5743c9 100644
    --- a/tools/cpp/unix_cc_configure.bzl
    +++ b/tools/cpp/unix_cc_configure.bzl
    @@ -171,6 +171,7 @@ def _is_linker_option_supported(repository_ctx, cc, option):
             "/dev/null",
             str(repository_ctx.path("tools/cpp/empty.cc")),
         ])
    +    print("_is_linker_option_supported(option=%r): %r" % (option, result.stderr))
         return result.stderr.find(option) == -1
     
     def _is_gold_supported(repository_ctx, cc):
    
    $ ~/src/bazel/bazel-bin/src/bazel_with_jdk build //:hello
    Extracting Bazel installation...
    Starting local Bazel server and connecting to it...
    ...................
    DEBUG: /private/var/tmp/_bazel_jmillikin/e6f0c92ab1a4f1ce77362e0f9e692d78/external/bazel_tools/tools/cpp/unix_cc_configure.bzl:174:5: _is_linker_option_supported(option="-Wl,-no-as-needed"): "ld: unknown option: -no-as-needed\nclang: error: linker command failed with exit code 1 (use -v to see invocation)\n"
    DEBUG: /private/var/tmp/_bazel_jmillikin/e6f0c92ab1a4f1ce77362e0f9e692d78/external/bazel_tools/tools/cpp/unix_cc_configure.bzl:174:5: _is_linker_option_supported(option="-Wl,-z,relro,-z,now"): "ld: unknown option: -z\nclang: error: linker command failed with exit code 1 (use -v to see invocation)\n"
    

    Note that the stderr reports the flag as -no-as-needed, but the configuration logic is looking for the -Wl, prefixed version.

  2. jin commented on Jun 26, 2018

    @jin
    Member

    cc @laurentlb (RM)

  3. soonho-tri commented on Jun 27, 2018

    @soonho-tri

    I've hit the same issue, ld: unknown option: -no-as-needed. FYI,

    • On OSX-10.13.5 (with clang-902.0.39.2), I don't have this problem.
    • On OSX-10.12.6 (with clang-900.0.39.2), I can reproduce the problem.
    • On OSX-10.11.6 (with clang-800.0.42.1), I can reproduce the problem.
  4. RNabel commented on Jun 27, 2018

    @RNabel
    Contributor

    Can confirm, 0.15.0 working with clang-902.0.39.2.

  5. hlopko commented on Jun 27, 2018

    @hlopko
    Member

    @laurentlb Can/Should we have a patch release for this? I'll work on the fix.

  6. added
    P1
    on Jun 27, 2018
  7. yuikns commented on Jun 28, 2018

    @yuikns

    I am on OSX-10.13.5 (with clang-902.0.39.2), but still get a broken.

  8. hectim commented on Jun 29, 2018

    @hectim

    Same thing happened to me, brew didn't have the versions I wanted to try so I removed it and installed from source like described here.
    protocolbuffers/protobuf#4841

    Downgrading to bazel 0.14.1 fixed it

  9. hlopko commented on Jul 5, 2018

    @hlopko
    Member

    @laurentlb FYI: this is now fixed.

  10. oferb commented on Jul 5, 2018

    @oferb

    @mhlopko In which version of Bazel is it fixed?

  11. hlopko commented on Jul 5, 2018

    @hlopko
    Member

    @oferb only at HEAD. That's why I pinged Laurent, to consider a patch release. But since we're cutting 0.16 soon, maybe it's not needed.

    @buchgr (release manager for 0.16) Can you make sure the fix makes it into 0.16?

  12. 16 remaining items

  13. laurentlb commented on Jul 13, 2018

    @laurentlb
    Contributor

    See #5591

  14. added 4 commits that reference this issue on Jul 13, 2018
    d731007
    ca456ef
    94b7830
    4e190ba
  15. added 2 commits that reference this issue on Jul 24, 2018
    3e50c02
    97fcacf
  16. added 2 commits that reference this issue on Aug 2, 2018
    f99d2f4
    f14777b
  17. added 2 commits that reference this issue on Aug 8, 2018
    d922563
    4fb92d7
  18. added 2 commits that reference this issue on Aug 9, 2018
    58d0d09
    685e0aa
  19. added 2 commits that reference this issue on Sep 12, 2018
    696389e
    74c9f1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1bazel.build

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions