This is an archive of the discontinued LLVM Phabricator instance.

[MCDwarf] Respect -fdebug-prefix-map= for generated assembly debug info (DWARF v5)
ClosedPublic

Authored by MaskRay on Aug 11 2022, 11:17 PM.

Details

Summary

For generated assembly debug info, MCDwarfLineTableHeader::CompilationDir is an
unmapped path set in MCContext::setGenDwarfRootFile. Remap it.

A relative destination path of -fdebug-prefix-map= exposes a llvm-dwarfdump bug
which joins directories[0] into DW_AT_comp_dir.

Fix https://github.com/llvm/llvm-project/issues/56609

Diff Detail

Event Timeline

MaskRay created this revision.Aug 11 2022, 11:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2022, 11:17 PM
MaskRay requested review of this revision.Aug 11 2022, 11:17 PM
Herald added a project: Restricted Project. · View Herald Transcript

I am getting a compiler error on clang-15, can you confirm if this will work with clang-15 too

I am seeing

| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/ADT/Optional.h: In instantiation of ‘llvm::optional_d
etail::OptionalStorage<T, <anonymous> >& llvm::optional_detail::OptionalStorage<T, <anonymous> >::operator=(T&&) [with T = llvm::MCDwarfLineStr; bo
ol <anonymous> = false]’:
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/ADT/Optional.h:281:13:   required from ‘llvm::Optiona
l<T>& llvm::Optional<T>::operator=(T&&) [with T = llvm::MCDwarfLineStr]’
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/lib/MC/MCDwarf.cpp:269:37:   required from here
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/ADT/Optional.h:139:11: error: use of deleted function
 ‘llvm::MCDwarfLineStr& llvm::MCDwarfLineStr::operator=(llvm::MCDwarfLineStr&&)’
|   139 |       val = std::move(y);
|       |       ~~~~^~~~~~~~~~~~~~                                                                                                                 | /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/MC/MCDwarf.h:51:7: note: ‘llvm::MCDwarfLineStr& llvm:
:MCDwarfLineStr::operator=(llvm::MCDwarfLineStr&&)’ is implicitly deleted because the default definition would be ill-formed:                      |    51 | class MCDwarfLineStr {
|       |       ^~~~~~~~~~~~~~
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/MC/MCDwarf.h:51:7: error: use of deleted function ‘ll
vm::StringSaver& llvm::StringSaver::operator=(llvm::StringSaver&&)’
| In file included from /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/MC/MCDwarf.h:25:
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/Support/StringSaver.h:21:7: note: ‘llvm::StringSaver&
 llvm::StringSaver::operator=(llvm::StringSaver&&)’ is implicitly deleted because the default definition would be ill-formed:                      |    21 | class StringSaver final {
|       |       ^~~~~~~~~~~
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/Support/StringSaver.h:21:7: error: non-static referen
ce member ‘llvm::BumpPtrAllocator& llvm::StringSaver::Alloc’, cannot use default assignment operator

I am getting a compiler error on clang-15, can you confirm if this will work with clang-15 too

I am seeing

| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/ADT/Optional.h: In instantiation of ‘llvm::optional_d
etail::OptionalStorage<T, <anonymous> >& llvm::optional_detail::OptionalStorage<T, <anonymous> >::operator=(T&&) [with T = llvm::MCDwarfLineStr; bo
ol <anonymous> = false]’:
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/ADT/Optional.h:281:13:   required from ‘llvm::Optiona
l<T>& llvm::Optional<T>::operator=(T&&) [with T = llvm::MCDwarfLineStr]’
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/lib/MC/MCDwarf.cpp:269:37:   required from here
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/ADT/Optional.h:139:11: error: use of deleted function
 ‘llvm::MCDwarfLineStr& llvm::MCDwarfLineStr::operator=(llvm::MCDwarfLineStr&&)’
|   139 |       val = std::move(y);
|       |       ~~~~^~~~~~~~~~~~~~                                                                                                                 | /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/MC/MCDwarf.h:51:7: note: ‘llvm::MCDwarfLineStr& llvm:
:MCDwarfLineStr::operator=(llvm::MCDwarfLineStr&&)’ is implicitly deleted because the default definition would be ill-formed:                      |    51 | class MCDwarfLineStr {
|       |       ^~~~~~~~~~~~~~
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/MC/MCDwarf.h:51:7: error: use of deleted function ‘ll
vm::StringSaver& llvm::StringSaver::operator=(llvm::StringSaver&&)’
| In file included from /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/MC/MCDwarf.h:25:
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/Support/StringSaver.h:21:7: note: ‘llvm::StringSaver&
 llvm::StringSaver::operator=(llvm::StringSaver&&)’ is implicitly deleted because the default definition would be ill-formed:                      |    21 | class StringSaver final {
|       |       ^~~~~~~~~~~
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-15.0.0-r0/git/llvm/include/llvm/Support/StringSaver.h:21:7: error: non-static referen
ce member ‘llvm::BumpPtrAllocator& llvm::StringSaver::Alloc’, cannot use default assignment operator

You need to rebase after b0c4cd35df89479ec152c1f79e18d0264dd276cc which avoids move assignment.

dblaikie added inline comments.Aug 12 2022, 11:10 AM
llvm/test/MC/ELF/debug-prefix-map.s
36–40

I'm not sure this comment is correct (perhaps there's a bug in llvm-dwarfdump if both include_directories[0] and DW_AT_comp_dir are both being joined together). From the DWARFv5 spec:

The first entry is the current directory of the compilation. Each additional path entry is either a full path name or is relative to the current directory of the compilation.
The line number program assigns a number (index) to each of the directory entries in order, beginning with 0.
Prior to DWARF Version 5, the current directory was not represented in the directories field and a directory index of 0 implicitly referred to that directory as found in the DW_AT_comp_dir attribute of the compilation unit debugging information entry. In DWARF Version 5, the current directory is explicitly present in the directories field.

So maybe llvm-dwarfdump is incorrectly joining DW_AT_comp_dir to include_directories[0]?

I'm not sure the suggestion that -fdebug-prefix-map= is meant to be absolute is the case in practice - I think Chromium folks implemented it so they could have relative debug info that could be built on a build farm and shared between multiple developers with different source tree locations. So I /think/ it's probably usually relative (the same as Google's use of -fdebug-compilation-dir=/proc/self/cwd (which, is, admittedly, technically, an absolute path - but I don't think that's the case for Chromium)... huh, maybe chromium doesn't use prefix map anymore? https://chromium.googlesource.com/chromium/src/+/71df8872b86b4d8260230742cfd3b2e4756f62b5%5E%21/#F0 )

MaskRay updated this revision to Diff 452250.Aug 12 2022, 11:39 AM
MaskRay edited the summary of this revision. (Show Details)

Update comment that src_root/src_root/file is a llvm-dwarfdump bug.

MaskRay marked an inline comment as done.Aug 12 2022, 11:40 AM
MaskRay added inline comments.
llvm/test/MC/ELF/debug-prefix-map.s
36–40

Groups appear to migrate to -fdebug-compilation-dir=. which is more convenient. -fdebug-prefix-map= is used less.

I'll see about fixing llvm-dwarfdump. Thanks for noticing the bug (which appears in dwarfdump, too).

MaskRay marked an inline comment as done.Aug 12 2022, 11:41 AM
dblaikie accepted this revision.Aug 12 2022, 11:46 AM

Generally seems good to me, thanks!

llvm/test/MC/ELF/debug-prefix-map.s
36–40

Groups appear to migrate to -fdebug-compilation-dir=. which is more convenient. -fdebug-prefix-map= is used less.

Hmm, yeah, seems generally better - though I guess GCC also has -fdebug-prefix-map= so maybe it's got enough use we won't be removing it any time soon. Ah well.

I'll see about fixing llvm-dwarfdump. Thanks for noticing the bug (which appears in dwarfdump, too).

Thanks!

This revision is now accepted and ready to land.Aug 12 2022, 11:46 AM
MaskRay added inline comments.Aug 12 2022, 11:54 AM
llvm/test/MC/ELF/debug-prefix-map.s
36–40

Amend to why -fdebug-compilation-dir=. is preferred: when two distributed build harm users check out the build in different local working directories, the build can be shared because the compiler options are exactly the same (local determinism).

With -fdebug-prefix-map, the two builds will need different options.

This revision was landed with ongoing or failed builds.Aug 12 2022, 12:52 PM
This revision was automatically updated to reflect the committed changes.
MaskRay added inline comments.Aug 12 2022, 1:36 PM
llvm/test/MC/ELF/debug-prefix-map.s
36–40

Sent D131804 to fix llvm-dwarfdump

srj added a subscriber: srj.Aug 17 2022, 10:08 AM

This change has injected a build breakage for MSVC builds:

MCContext.cpp(859): error C2429: language feature 'structured bindings' requires compiler flag '/std:c++17'

MaskRay added a comment.EditedAug 17 2022, 10:43 AM

This change has injected a build breakage for MSVC builds:

MCContext.cpp(859): error C2429: language feature 'structured bindings' requires compiler flag '/std:c++17'

This turns out to be a backport issue. The patch was back ported to release/15.x However, release/15.x (https://github.com/llvm/llvm-project/tree/release/15.x) uses C++14 and structured bindings trigger warnings in GCC/Clang and errors in MSVC.
My bad that I did not think of the difference when crafting the patch.
Pushed a trivial commit to release/15.x to avoid structured bindings.