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

bazel coverage link error for C targets on macOS #5128

Closed
jayconrod opened this issue May 1, 2018 · 5 comments
Closed

bazel coverage link error for C targets on macOS #5128

jayconrod opened this issue May 1, 2018 · 5 comments

Comments

@jayconrod
Copy link
Contributor

Description of the problem / feature request:

When building any cc_test target or cc_binary target with coverage instrumentation on macOS, bazel coverage fails with an error like this:

>>>>>>>>> # //:hello_lib [action 'Linking libhello_lib.so']
(cd /private/var/tmp/_bazel_jayconrod/dc23ec2471431a08def1a3ea88cf8238/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM='' \
    APPLE_SDK_VERSION_OVERRIDE='' \
    XCODE_VERSION_OVERRIDE=8.3.3 \
  external/local_config_cc/cc_wrapper.sh -fobjc-link-runtime -Wl,-S -shared -o bazel-out/darwin-fastbuild/bin/libhello_lib.so bazel-out/darwin-fastbuild/bin/_objs/hello_lib/hello.o -lgcov -headerpad_max_install_names -lc++ -no-canonical-prefixes -undefined dynamic_lookup)
ERROR: /Users/jayconrod/go/src/example.com/repo/BUILD.bazel:6:1: Linking of rule '//:hello_lib' failed (Exit 1).
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

// hello.c
int main() {return 0;}
# BUILD.bazel
cc_test(
    name = "hello",
    deps = [":hello_lib"],
)

cc_library(
    name = "hello_lib",
    srcs = ["hello.c"],
)
$ bazel coverage //:hello

What operating system are you running Bazel on?

macOS High Sierra 10.13.4

What's the output of bazel info release?

release 0.13.0

Any other information, logs, or outputs that you want to share?

It looks like -lgcov is being passed on the command line to the linker. macOS doesn't seem to have this library. Maybe passing --coverage would be better? That works for me in small examples on both macOS and Linux, both gcc and clang.

@iirina
Copy link
Contributor

iirina commented May 2, 2018

-lgcov was replaced with --coverage in d6f706d, so this should be fixed with the next release. There are a few more places that use -lgcov which should be changed as well.

@zaycev
Copy link

zaycev commented Jun 14, 2018

Looks like it is still broken in 0.14.1:

$ bazel info release
release 0.14.1-homebrew
$ bazel coverage -s ...

ERROR: /private/var/tmp/_bazel_zaytsev/031680ef6cb503622683e0f635fcc447/external/com_google_grpc/BUILD:1089:1: Linking of rule '@com_google_grpc//:grpc_server_load_reporting' failed (Exit 1)
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //cli/cmds:go_default_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.737s, Critical Path: 0.39s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

iirina added a commit that referenced this issue Jun 15, 2018
`-lgcov` is not supported on macOS. See #5128
bazel-io pushed a commit that referenced this issue Jun 15, 2018
in Bazel osx CROSSTOOL. -lgcov is not supported on macOS. See #5128.

RELNOTES: None.
PiperOrigin-RevId: 200691758
ArielleA pushed a commit to ArielleA/bazel that referenced this issue Jun 19, 2018
in Bazel osx CROSSTOOL. -lgcov is not supported on macOS. See bazelbuild#5128.

RELNOTES: None.
PiperOrigin-RevId: 200691758
@iirina
Copy link
Contributor

iirina commented Jul 24, 2018

Can someone verify if this is still happening with the latest Bazel release?

@jayconrod
Copy link
Contributor Author

This is still happening in 0.15.2, but I can't reproduce anymore in 0.16.0-rc3. Thanks for fixing it!

@iirina
Copy link
Contributor

iirina commented Jul 24, 2018

Thanks for checking!

@iirina iirina closed this as completed Jul 24, 2018
werkt pushed a commit to werkt/bazel that referenced this issue Aug 2, 2018
in Bazel osx CROSSTOOL. -lgcov is not supported on macOS. See bazelbuild#5128.

RELNOTES: None.
PiperOrigin-RevId: 200691758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants