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
Trouble including .a and .so in sandbox with linkopts #818
Comments
Is there some reason you have |
From linkopts doc: Each element of this list that does not start with $ or - is assumed to be the label of a target in deps. The list of files generated by that target is appended to the linker options. An error is reported if the label is invalid, or is not declared in deps. |
I can see how that's confusing, but Bazel-built libraries which should get linked into another |
@bsilver8192 adding in only deps seems to do the right thing here. What is the usecase of specifying a cc_library in a linkopt? Is it to control order of '-l's? I'm still pretty sure it's not working as intended with sandboxing. |
I don't think there is a use case for doing putting a For ordering the libraries during the final link, Bazel handles it based on the dependency edges established by |
Sorry that I didn't reply earlier. I'm currently overwhelmed with other issues that I have to work on. I can't comment on what the right thing to do is regarding the files of a |
For tcmalloc and other malloc libraries specifically, you should use the --custom_malloc flag or set cc_binary.malloc. |
Thanks for the suggestions. I like @bsilver8192's suggestion because if I define the tcmalloc cc_library with alwayslink = 1 and set it as a dependency of my "base" library, all binaries that directly or indirectly depend on base (read all binaries :) will use tcmalloc. One question is unanswered though. The docs for cc_library.linkopts says:
This leads me to believe that at some point in time someone thought it was a good idea to specify cc_libraries in linkopts as opposed to just in dependencies. The open question is, what is the usecase for that? Also this feature appears to be broken by sandboxing since the .a and .so are not included in the build sandbox. |
Occasionally, one wants to insert It could be argued that one should use a
That said, by default a |
@kchodorow I don't think this is a sandbox bug actually. If one replace that "@gperftools//:tcmalloc" to "external/gperftools/libtcmalloc.a" one should actually be able to build it. So the problem seems to be the labels being replaced with wrong paths, instead of sandbox problem. Also notice that @mikedanese included the same thing in |
@hermione521 Yue, could you try to find a good owner for this bug? I don't think it's about sandboxing and I don't know anything about linkopts / C++ rules... |
Done. Not sure if I'm right.. |
Our internal cc_library rules actually allow individual files in deps, not just cc_library rules, and this is used to refer to linker scripts. We should either allow linker scripts in srcs, or something, and also allow linkopts to refer to those. I think there's also a case to be made to support --start-group --end-group in linkopts, with the .a files in srcs (?), or maybe in a special cc_import rule, except we'd need to make sure that cc_library doesn't also put the .a files on the link command line. |
Feel free to read and comment on cc_*_library_import proposal: https://docs.google.com/document/d/1hK2mWl3TYNL9oJYX_S020TKkXZvBw1aBoYERvTHVyfg/edit |
Slightly unrelated to this thread, but is there a good way of using gperftools/tcmalloc with bazel? I could not find a good up to date BUILD file for gperftools, and reverse engineering their make process is hacky. |
@siddharthab I'm afraid this is not the right place to ask this question. Maybe somebody on bazel-discuss will know? |
Thank you for the reply. I saw it being used in the example above and I was tempted. I will take my question to the Google group. |
This is recommended here: bazelbuild/bazel#818 (comment) But more importantly, this fixes issues when trying to include eventuals in targets that are built as shared libraries. Fixes #470.
This is recommended here: bazelbuild/bazel#818 (comment) But more importantly, this fixes issues when trying to include eventuals in targets that are built as shared libraries. Fixes #470.
This is recommended here: bazelbuild/bazel#818 (comment) But more importantly, this fixes issues when trying to include eventuals in targets that are built as shared libraries. Fixes #470.
This is recommended here: bazelbuild/bazel#818 (comment) But more importantly, this fixes issues when trying to include eventuals in targets that are built as shared libraries. Fixes #470.
I have a rule:
When I build:
It looks like everything worked. But when I run:
It looks like those files are not included in the sandbox. I checked and those paths exist on the host.
This is my tcmalloc BUILD:
How do I link tcmalloc to another cc library?
The text was updated successfully, but these errors were encountered: