Provide means for opting out of having "_virtual_includes" mentioned in C/C++ binaries
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the problem / feature request:
Whenever `include_prefix` or `strip_include_prefix` are provided to `cc_library`, bazel creates a hierarchy in the execution root that starts with something like this:
```
path/to/$PACKAGE/_virtual_includes/$TARGET
```
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](https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#index-fdebug-prefix-map) or [-ffile-prefix-map](https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#index-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 3f46dd0f6d5a042fc28d265411a6014f666a40c1 adds a feature for the macOS CROSSTOOL that uses -fdebug-prefix-map. It, however, is only really useful for macOS builds.
- #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.
- #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](https://docs.bazel.build/versions/master/cc-toolchain-config-reference.html#cctoolchainconfiginfo-build-variables) 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.
Contributor guide
Research direction
Start by reviewing commit 3f46dd0f6d5a042fc28d265411a6014f666a40f1 and the CcToolchainConfigInfo build-variable documentation, then compare the proposed gcc -fdebug-prefix-map and -ffile-prefix-map approaches. Done means providing an opt-out path-mapping capability for _virtual_includes that works for the affected debug information and related coverage or compilation-database workflows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100