-
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
Absolute paths are embedded in produced binaries #1000
Comments
That's non-hermetic, and prevents any cross-user caching of the results. All the paths embedded into outputs should be relative; if that's not happening, that's a bug. |
Certainly for genfile sources, at least, absolute paths into the working tree are clearly visible by running |
Any update here? This is breaking build caching for us. |
Hi James, do you mean the absolute paths in the binaries? Could you open a new issue for that, maybe with a concrete repro instructions, so we can give it the attention it deserves? Thanks! |
I've renamed this bug, as relative paths would fix both the original issue and any extant caching issues. |
How does caching work at all without this? I guess all the machines that things are being built on have the same directory structure? This is definitely not the case for most users :). |
I have a prototype of this working now, it did require a small change to bazel though:
Then, I added this into my CROSSTOOL:
|
I concur with @ulfjack : Unfortunately, the trivial fix, |
I believe the wrapper script wouldn't be sufficient, as it would still need something similar to the execution root to be able to send into the |
Why do you need something like the execution root? If we map whatever the workspace root is to, say |
Indeed, it might be best to have Bazel add the appropriate flag value automatically, thus avoiding the need to expose the variable. If there is a need to disable this functionality, a field can be added to the CROSSTOOL proto. |
@lberki ah, okay. I think I misunderstood. Agreed, if we have bazel remap the workspace root automatically, that would be ideal. |
I did some research to find out how we can fix this, and it does not look good. I checked ccache and distcc, and apparently they are rewriting the output files after compilation to remove the absolute paths: The tricky part about -fdebug-prefix-map is that we don't know the absolute path ahead of time in the case of remote execution. We can't use the local path, because then remote caching doesn't work. We could conceivably make it so remote execution runs in a fixed path, but then we can't cache between local and remote execution, unless we can (somehow) make local execution also use a fixed path, which isn't possible in all cases. Sandboxing locally helps, because we control the file system, but we can't rely on that at this point in time. A wrapper script could rewrite the command line to pass the correct absolute path to -fdebug-prefix-map. Not nice, but I don't really see any other option. Am I missing something? |
An alternative would be post-processing object files instead in a separate action? I just told @mhlopko that I'd prefer post-processing because that doesn't assume that there is a bash shell wherever the compiler runs, but then again, post-processing has to know the format of the .o files, which is a bigger deal. I guess a wrapper script is okay as long as we can come up with a way not to mandate it e.g. for Windows. |
Note that this mainly affects MacOS right now, where we already use a wrapper script. Extending that to also handle -fdebug-prefix-map doesn't sound too bad. On Linux, we set PWD=/proc/self/cwd, which makes the outputs deterministic. On Windows, we need to check whether MSVC is even writing absolute paths, and whether it has options to suppress that. Or are you concerned about gcc / clang on Windows? We could also ask whether upstream Clang could provide an option for this. It seems weird that multiple projects are working around it instead of getting a fix into upstream. |
That's correct, I think. |
I've opened a similar issue at #5031. We have a patch incoming for OSX binaries built on OSX (we patched That said, this doesn't fix Android builds since this doesn't call While |
hey guys, I'm just picking up on this, how do you see Bazel automatically adding |
This is still a problem for Android builds on OSX.
The first one is fixed by adding Also, it's preventing debugging from working on Android Studio + OSX. |
Encountered an issue recently with The relevant command is like:
So instead of fix the prefix to be |
Hi there! We're doing a clean up of old issues and will be closing this one. Please reopen if you’d like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so. |
I am having the same issue when using Boost stacktrce. The backtrace library prints I'd also appreciate a CLI option that allows configuring this. |
It would be useful to allow
-fdebug-prefix-map
to be used to create debug info that references a workspace's source files (e.g./home/<user>/workspace/foo/bar.cc
) rather than symlinked working tree sources (e.g./private/var/tmp/<_bazel_<user>/4dfa01e59a69e8a99b4743b0270c4ad8/workspace/foo/bar.cc
). This may require aCROSSTOOL
substitution that referenced the current working tree, such that one could write:compiler_flag: "-fdebug-prefix-map=%working_tree%=%workspace%"
Alternatively, Bazel could unconditionally add
-fdebug-prefix-map
to the list of compile options via its own special magic, since it seems a good idea to always reference the original sources in debug info.Rationale
Even when invoked with relative paths, Clang's debug information will contain absolute paths to sources deep within the working tree, as above, even though those sources are, in fact, just symlinks back into the workspace. This confuses some tools, such as CLion, which attempt, and fail, to set breakpoints in lldb using workspace paths, not working tree paths. lldb only knows about the working tree sources, and doesn't recognize that these paths actually reference the same files, and thus ignores the breakpoint.
Newer versions of clang appear to support GCC's
-fdebug-prefix-map
, which will presumably solve this problem.The text was updated successfully, but these errors were encountered: