-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Provide means for opting out of having "_virtual_includes" mentioned in C/C++ binaries #11874
Comments
For our company it is also a big problem that even if you have all source code you cannot use the debug information without actually building the binaries your self. We have very much the same use case as stated in the request with engineers that do debugging of coredumps provided by customers. |
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 2+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team ( |
Hi @nacl and @burkpojken, I jus discovered this issue because I have the same situation for me. Is there some solution for this? |
We stopped using strip_include_prefix and use includes instead, https://bazel.build/reference/be/c-cpp#cc_library.includes |
This should really be reopened: afaict there is still no good way to generate a compile_commands.json that does not contain non-existing virtual_include paths to third-party dependency headers. |
@bazelbuild/triage gentle ping |
To be clear, the immediately prior message shows a solution for |
Sorry for the high latency -- the problem I was seeing turns out to be a bit more convoluted (more details here) and it is not strictly the fault of About using |
^ indeed, not every _virtual_includes has an includes equivalent, sadly. Consider the case with just an include_prefix. |
One drawback with For another, suppose the following:
I can either use Given that, @nacl whipped up a patch for this that we've been using for a few years, and I'm currently rebasing it against Bazel 7. I'd be happy to turn this into a PR. |
…lchain subsystem Whenever `prefix` and/or `strip_include_prefix` is passed into `cc_library` rules, Bazel copies the headers into a special "_virtual_includes" directory that allows for such path transformations to occur. Unfortunately, this also has the side-effect of changing how source files are designated within the source binaries: they will refer to the file in the `_virtual_includes` sandbox directory instead of the actual files in the build tree. This change allows us to work around this problem by providing a mapping between the "virtual" and where they are in the filesystem as a [CcToolchainConfigInfo variable][1], `virtual_to_original_dirs`, which ends up being a list of `<virtual>=<original>` mappings that can be used in rules_cc toolchain features, specifically using [-ffile-prefix-map][2]. Questions ========= - Is `<virtual>=<original>` okay, or do we need a more sophisticated lazy expansion involving subvariables like what `libraries_to_link` has? E.g., do we imagine another compiler command-line flag format that'd require `A:B` instead of `A=B`? (Then again, considering MSVC's ASan is implemented w/ `/fsanitize=address`, maybe they're on the `A=B` train now?) Notes ===== - We mostly mimicked coverage's `virtual_to_original_headers`. Fixes upstream bazelbuild#11874. [1]: https://docs.bazel.build/versions/master/cc-toolchain-config-reference.html#cctoolchainconfiginfo-build-variables [2]: https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#index-ffile-prefix-map Co-authored-by: Andrew Psaltis <apsaltis@vmware.com>
Whenever `prefix` and/or `strip_include_prefix` is passed into `cc_library` rules, Bazel copies the headers into a special "_virtual_includes" directory that allows for such path transformations to occur. Unfortunately, this also has the side-effect of changing how source files are designated within the source binaries: they will refer to the file in the `_virtual_includes` sandbox directory instead of the actual files in the build tree. This change allows us to work around this problem by providing a mapping between the "virtual" and where they are in the filesystem as a [CcToolchainConfigInfo variable][1], `virtual_to_original_dirs`, which ends up being a list of `<virtual>=<original>` mappings that can be used in rules_cc toolchain features, specifically using [-ffile-prefix-map][2]. Questions ========= - Is `<virtual>=<original>` okay, or do we need a more sophisticated lazy expansion involving subvariables like what `libraries_to_link` has? E.g., do we imagine another compiler command-line flag format that'd require `A:B` instead of `A=B`? (Then again, considering MSVC's ASan is implemented w/ `/fsanitize=address`, maybe they're on the `A=B` train now?) Notes ===== - We mostly mimicked coverage's `virtual_to_original_headers`. Fixes upstream bazelbuild#11874. [1]: https://docs.bazel.build/versions/master/cc-toolchain-config-reference.html#cctoolchainconfiginfo-build-variables [2]: https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#index-ffile-prefix-map Co-authored-by: Andrew Psaltis <apsaltis@vmware.com>
Whenever `prefix` and/or `strip_include_prefix` is passed into `cc_library` rules, Bazel copies the headers into a special "_virtual_includes" directory that allows for such path transformations to occur. Unfortunately, this also has the side-effect of changing how source files are designated within the source binaries: they will refer to the file in the `_virtual_includes` sandbox directory instead of the actual files in the build tree. This change allows us to work around this problem by providing a mapping between the "virtual" and where they are in the filesystem as a [CcToolchainConfigInfo variable][1], `virtual_to_original_dirs`, which ends up being a list of `<virtual>=<original>` mappings that can be used in rules_cc toolchain features, specifically using [-ffile-prefix-map][2]. Questions ========= - Is `<virtual>=<original>` okay, or do we need a more sophisticated lazy expansion involving subvariables like what `libraries_to_link` has? E.g., do we imagine another compiler command-line flag format that'd require `A:B` instead of `A=B`? (Then again, considering MSVC's ASan is implemented w/ `/fsanitize=address`, maybe they're on the `A=B` train now?) Notes ===== - We mostly mimicked coverage's `virtual_to_original_headers`. Fixes upstream bazelbuild#11874. [1]: https://docs.bazel.build/versions/master/cc-toolchain-config-reference.html#cctoolchainconfiginfo-build-variables [2]: https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#index-ffile-prefix-map Co-authored-by: Andrew Psaltis <apsaltis@vmware.com>
@bazelbuild/triage does it make sense to re-open this, as there is an active PR trying to fix it? |
Description of the problem / feature request:
Whenever
include_prefix
orstrip_include_prefix
are provided tocc_library
, bazel creates a hierarchy in the execution root that starts with something like this:Which are passed in to the C/C++ compiler via
-I
. This results in the debuginfo values in the compiled files specifying that said headers can be found entirely under execution root, which is only valid if Bazel has been run before. Further, the_virtual_includes
path hides exactly where the files in question are located, and requires additional steps to be performed to determine the location the actual header file for editing purposes.We have a workflow in which engineers do debugging of coredumps provided by customers and they must (at least initially) be able to operate in environments where a build was not necessarily done previously. It is understood and expected that debugging generated code or external repositories will require interaction with the build system.
Our current thoughts on this is that it should be possible to create a toolchain feature that can create this mapping using compiler flags like gcc's -fdebug-prefix-map or -ffile-prefix-map.
See also our post on this on bazel-discuss: https://groups.google.com/forum/#!topic/bazel-discuss/prVSDuifmHY
Feature requests: what underlying problem are you trying to solve with this feature?
Debuginfos generated by gcc in Bazel may specify headers relative to a
_virtual_includes
path instead of where they actually may be found in the source repository. An option should be available to allow users to opt-out of this feature.This problem, in one form or another, impacts things like emitting coverage instrumentation (
bazel build --collect-code-coverage ...
) and potentially compilation databases.What operating system are you running Bazel on?
CentOS Linux release 7.7.1908 (Core)
What's the output of
bazel info release
?release 3.3.0-vmware
If
bazel info release
returns "development version" or "(@non-git)", tell us how you built Bazel.N/A
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?N/A
Have you found anything relevant by searching the web?
Similar issues/commits found:
Commit 3f46dd0 adds a feature for the macOS CROSSTOOL that uses -fdebug-prefix-map. It, however, is only really useful for macOS builds.
Absolute paths are embedded in produced binaries #1000 is similar to this issue, but is mostly related to macOS and the embedding of absolute paths within the binaries. This ticket is more interested in remapping paths from within the macOS sandbox; the Linux sandboxes all seem to use paths relative to the WORKSPACE root.
Output the actual path of virtual include headers in the coverage report #6254 fixes a similar problem was encountered by coverage builds (as run via
bazel coverage
). Unfortunately, while we could use the dataset that is assembled there, it, unfortunately, is far too large to be used on compiler command lines, nearing 6000+ entries in some cases.Any other information, logs, or outputs that you want to share?
We have written a internal change to bazel that creates a CcToolchainConfigInfo build variable containing the necessary mapping information that can be used to write a toolchain feature that can solve this problem by using
gcc
's-fdebug-prefix-map
. We can look into publishing it here, but it needs a little more refinement before it would be ready.The text was updated successfully, but these errors were encountered: