This is an archive of the discontinued LLVM Phabricator instance.

[MCContext] Reverse order of DebugPrefixMap sort for generated assembly debug info
ClosedPublic

Authored by dankm on Aug 22 2022, 9:25 AM.

Details

Summary

Match Clang's sorting, so that longer (more specific) prefix paths
will match before less specific paths.

Diff Detail

Event Timeline

dankm created this revision.Aug 22 2022, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2022, 9:25 AM
dankm requested review of this revision.Aug 22 2022, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2022, 9:25 AM
dankm added a comment.Aug 22 2022, 9:36 AM

I'm thinking about changing all the definitions of DebugPrefixMap like structures to just one named type, so that this is consistent everywhere.

dankm updated this revision to Diff 454601.Aug 22 2022, 1:04 PM

Run clang-format

dankm added a comment.Aug 22 2022, 2:19 PM

Test case?

Hah. Just finished writing a basic test case. Incoming.

dankm updated this revision to Diff 454609.Aug 22 2022, 2:22 PM

Updated debug-prefix-map.s test cases to detect this.

The test doesn't help. %t=... does not match the path component %t.foo. A nested directory is needed to test the situation.
You probably want to swap the order of the two -fdebug-prefix-map= for -dwarf-version=5 to get some variance.

dankm added a comment.Aug 23 2022, 8:54 AM

The test doesn't help. %t=... does not match the path component %t.foo. A nested directory is needed to test the situation.

Sure it does. It's somewhat undocumented, and arguably a bug in its own right (I was torn when I implemented the original prefix mapping stuff), but it's a simple prefix substitution. /t=/lu turns /tmp into /lump happily.
In this case without the header change, that unit test turns the file path into /broken_root.foo/src.s.

You probably want to swap the order of the two -fdebug-prefix-map= for -dwarf-version=5 to get some variance.

I like this suggestion. The order of the parameters, so let's ensure that both work.

dankm added a comment.Aug 23 2022, 9:19 AM

Sure it does. It's somewhat undocumented, and arguably a bug in its own right (I was torn when I implemented the original prefix mapping stuff), but it's a simple prefix substitution. /t=/lu turns /tmp into /lump happily.

Hmm. While this is true, it depends on how replace_path_prefix is called, and that seems inconsistent. That *is* a bug. Clang gives me multiple file names when I try that there. In llvm-mc, though it's always the string prefix.
I'll use subdirectories, since I now believe it *should* fail in the /t=/lu changing /tmp to /lump.

dankm updated this revision to Diff 455004.Aug 23 2022, 4:21 PM

Use subdirectory rather than substring prefix matching in unit test.

MaskRay accepted this revision.Aug 23 2022, 8:59 PM
MaskRay added inline comments.
llvm/test/MC/ELF/debug-prefix-map.s
1–2

mkdir -p %t.foo/bar

This revision is now accepted and ready to land.Aug 23 2022, 8:59 PM
raj.khem accepted this revision.Aug 23 2022, 9:55 PM

My local testing on clang-15 shows no problems with this patch so lgtm

dankm added inline comments.Aug 24 2022, 6:40 AM
llvm/test/MC/ELF/debug-prefix-map.s
1–2

I thought about that, but I also think doing it separately makes it more clear to readers that both paths will be used.

MaskRay added inline comments.Aug 24 2022, 8:41 AM
llvm/test/MC/ELF/debug-prefix-map.s
1–2

You may keep em, then it should still be clear

dankm updated this revision to Diff 455244.Aug 24 2022, 8:56 AM

Attempt to fix the test case on Windows.

dankm updated this revision to Diff 455380.Aug 24 2022, 2:37 PM

One more attemt to fix Windows tests before I actually install a
Windows VM to work on it..

dankm added a comment.Aug 24 2022, 7:08 PM

Since I don't have commit access, can one of you commit this for me, please?

Assuming you're happy with the test updates.

MaskRay retitled this revision from [MCContext] reverse order of DebugPrefixMap sort to [MCContext] Reverse order of DebugPrefixMap sort for generated assembly debug info.Aug 24 2022, 9:48 PM
dankm added a comment.Aug 29 2022, 6:12 PM

Is it possible to get this into 15? Or do we need to wait for 16 at this point?

llvm/include/llvm/MC/MCContext.h
193

What happened to the const qualifier here?

MaskRay added inline comments.Aug 29 2022, 6:45 PM
llvm/include/llvm/MC/MCContext.h
193

const key is very uncommon and constness usually doesn't matter (value_type adds const to the key type anyway).

Is it possible to get this into 15? Or do we need to wait for 16 at this point?

I've created https://github.com/llvm/llvm-project/issues/57437 for 15.0.0 backport. If it is too late, we can request 15.0.1 backport.

dankm marked an inline comment as done.Aug 31 2022, 10:41 AM

I've created https://github.com/llvm/llvm-project/issues/57437 for 15.0.0 backport. If it is too late, we can request 15.0.1 backport.

Thanks!

llvm/include/llvm/MC/MCContext.h
193

Ah, missed that in the std::map spec. It makes sense that keys are always const, just didn't know it was guaranteed. Thanks.