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

cc_library warning: file has no symbols #4057

Closed
jayconrod opened this issue Nov 8, 2017 · 7 comments
Closed

cc_library warning: file has no symbols #4057

jayconrod opened this issue Nov 8, 2017 · 7 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug

Comments

@jayconrod
Copy link
Contributor

Description of the problem / feature request / question:

On macOS, if a source file in a static cc_library doesn't define any global symbols, we see a warning like the one below:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: bazel-out/darwin_x86_64-fastbuild/bin/libempty.a(empty.o) has no symbols

This is a problem in rules_go. We use a tool in the Go toolchain (cgo) that generates some .c files that get compiled with cc_library. One of the generated files in each library frequently has no symbols, but it's hard to know ahead of time whether that's the case (the file is not empty).

It would be nice to suppress these warnings altogether. There may be a lot of libraries with cgo in a Go project, so our users may see a lot of warnings.

It looks like ranlib on macOS supports a flag -no_warnings_for_no_symbols. ar does not support this flag. The actual command that's emitting this warning looks like this:

external/local_config_cc/wrapped_ar rcs bazel-out/darwin_x86_64-fastbuild/bin/libempty.a bazel-out/darwin_x86_64-fastbuild/bin/_objs/empty/empty.o

Maybe this flag can be added in wrapped_ar.tpl?

If possible, provide a minimal example to reproduce the problem:

cc_library(
    name = "empty",
    srcs = ["empty.c"],
    linkstatic = 1,
)

empty.c is an empty file. Note that there are additional warnings if the entire library has no symbols. Those warnings don't affect rules_go, but they should probably be suppressed, too.

Environment info

  • Operating System: macOS Sierra 10.12.6

  • Bazel version (output of bazel info release): release 0.7.0

@damienmg damienmg added category: rules > C++ P3 We're not considering working on this, but happy to review a PR. (No assignee) type: bug labels Nov 10, 2017
@hlopko hlopko added team-Rules-CPP Issues for C++ rules and removed category: rules > C++ labels Oct 11, 2018
@robbertvanginkel
Copy link
Contributor

Was this fixed with #5981 / 81b59f0 ?

@cpsauer
Copy link
Contributor

cpsauer commented Apr 20, 2022

It looks to me like there's still an issue outstanding here somewhere. Not sure if it's a regression since #5981/81b59f0, or an edge case that's slipping through.

[I'm seeing this warning when building a .mm (Obj-C++) file using an objc_library.]

@tetromino, I'm hoping it's okay if I tag you, since you wrote the original fix--and I don't (quickly) see where thie invocation is slipping through without -no_warning_for_no_symbols. I can see that the flag has since been moved to //tool/osx/crosstool/cc_toolchain_config.bzl, I assume as part of the general migration to toolchains.

@cpsauer
Copy link
Contributor

cpsauer commented Apr 20, 2022

@keith, here's the repro, per #5981:
empty_warning.zip
bazel clean && bazel build :all

Output should show the warning in all valid cases with {cc_library, objc_library}x{C, C++, Obj-C, and Objc-++}.
That is, 6 instances of
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: archive library: bazel-out/applebin_macos-darwin_x86_64-fastbuild-ST-cfb676c6944e/bin/<whatever>.a the table of contents is empty (no object file members in the library define global symbols)

@keith
Copy link
Member

keith commented Apr 20, 2022

This warning is actually slightly different, and there doesn't appear to be a way to disable it:

https://github.com/keith/cctools/blob/bab7d4a19d480751ea4cba85d4c92b07991f2356/misc/libtool.c#L2915-L2925

@keith
Copy link
Member

keith commented Apr 22, 2022

This original issue can def be closed, but we could track that one separately, or not. Theoretically we could filter the output to just ignore that, IMO it's rarely going to indicate a real issue

cpsauer added a commit to cpsauer/bazel that referenced this issue Apr 23, 2022
The warning is unlikely to indicate a real issue, and Bazel already silences parallel warnings with `-no_warning_for_no_symbols`.

For more context, see bazelbuild#4057
@cpsauer
Copy link
Contributor

cpsauer commented Apr 23, 2022

Good call. Figured I'd PR it up while we were discussing. How about something like #15325?

@cpsauer
Copy link
Contributor

cpsauer commented Apr 23, 2022

(Have tested, and it fixes all the repro cases above and the instances in my own codebase that initially brought me to this issue.)

ckolli5 added a commit that referenced this issue May 10, 2022
The warning is unlikely to indicate a real issue, and Bazel already silences parallel warnings with `-no_warning_for_no_symbols`.

For more context, see #4057

Fixes #4057

Closes #15325.

PiperOrigin-RevId: 446659148

Co-authored-by: Christopher Sauer <cpsauer@users.noreply.github.com>
meteorcloudy pushed a commit that referenced this issue May 10, 2022
The warning is unlikely to indicate a real issue, and Bazel already silences parallel warnings with `-no_warning_for_no_symbols`.

For more context, see #4057

Fixes #4057

Closes #15325.

PiperOrigin-RevId: 446659148

Co-authored-by: Christopher Sauer <cpsauer@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants