Skip to content

[llvm-readobj][COFF] Consistent PDBGUID Formatting #94256

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

Merged
merged 1 commit into from
Jun 4, 2024
Merged

Conversation

mayanez
Copy link
Contributor

@mayanez mayanez commented Jun 3, 2024

Consistent PDB GUID in llvm-readobj

Currently, the PDB GUID is shown as a byte array:
PDBGUID: (D8 4C 88 D9 26 15 1F 11 4C 4C 44 20 50 44 42 2E)

This is inconsistent with llvm-pdbutil (e.g. llvm-pdbutil dump --summary) which shows it as a hexadecimal string.
Additionally, yaml2obj uses the same hexadecimal string format.

In general, the hexadecimal string is the common representation for PDB GUIDs on Windows.

This PR changes it to be consistent as shown below:
PDBGUID: {D9884CD8-1526-111F-4C4C-44205044422E}

Copy link

github-actions bot commented Jun 3, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2024

@llvm/pr-subscribers-platform-windows
@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-lld
@llvm/pr-subscribers-lld-coff

@llvm/pr-subscribers-llvm-binary-utilities

Author: Miguel A. Arroyo (mayanez)

Changes

Consistent PDB GUID in llvm-readobj

Currently, the PDB GUID is shown as a byte array:
PDBGUID: (D8 4C 88 D9 26 15 1F 11 4C 4C 44 20 50 44 42 2E)

This is inconsistent with llvm-pdbutil (e.g. llvm-pdbutil dump --summary) which shows it as a hexadecimal string.
Additionally, llvm-yaml2obj uses the same hexadecimal string format.

In general, the hexadecimal string is the common representation for PDB GUIDs on Windows.

This PR changes it to be consistent as shown below:
PDBGUID: {D9884CD8-1526-111F-4C4C-44205044422E}


Full diff: https://github.com/llvm/llvm-project/pull/94256.diff

2 Files Affected:

  • (modified) llvm/test/tools/llvm-readobj/COFF/debug-directory.test (+1-1)
  • (modified) llvm/tools/llvm-readobj/COFFDumper.cpp (+5-1)
diff --git a/llvm/test/tools/llvm-readobj/COFF/debug-directory.test b/llvm/test/tools/llvm-readobj/COFF/debug-directory.test
index f67eb70d82095..88295679a290a 100644
--- a/llvm/test/tools/llvm-readobj/COFF/debug-directory.test
+++ b/llvm/test/tools/llvm-readobj/COFF/debug-directory.test
@@ -12,7 +12,7 @@ CHECK:     AddressOfRawData: 0x5B068
 CHECK:     PointerToRawData: 0x5A268
 CHECK:     PDBInfo {
 CHECK:       PDBSignature: 0x53445352
-CHECK:       PDBGUID: (96 83 40 42 81 07 9D 40 90 1B 4A 3C 0D 4F 56 32)
+CHECK:       PDBGUID: {42408396-0781-409D-901B-4A3C0D4F5632}
 CHECK:       PDBAge: 3
 CHECK:       PDBFileName: D:\src\llvm\build\has_pdb.pdb
 CHECK:     }
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 32b1d6a2089ca..b2939f7826393 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -27,6 +27,7 @@
 #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
 #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
 #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
+#include "llvm/DebugInfo/CodeView/Formatters.h"
 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
 #include "llvm/DebugInfo/CodeView/Line.h"
 #include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
@@ -793,7 +794,10 @@ void COFFDumper::printCOFFDebugDirectory() {
       DictScope PDBScope(W, "PDBInfo");
       W.printHex("PDBSignature", DebugInfo->Signature.CVSignature);
       if (DebugInfo->Signature.CVSignature == OMF::Signature::PDB70) {
-        W.printBinary("PDBGUID", ArrayRef(DebugInfo->PDB70.Signature));
+        SmallString<38> FormattedGUIDStr;
+        raw_svector_ostream OS(FormattedGUIDStr);
+        fmt_guid(DebugInfo->PDB70.Signature).format(OS, "" /*Style=unused*/);
+        W.printString("PDBGUID", FormattedGUIDStr);
         W.printNumber("PDBAge", DebugInfo->PDB70.Age);
         W.printString("PDBFileName", PDBFileName);
       }

@mayanez mayanez changed the title [llvm-readobj] Consistent PDBGUID Formatting [llvm-readobj][COFF] Consistent PDBGUID Formatting Jun 3, 2024
@mayanez
Copy link
Contributor Author

mayanez commented Jun 3, 2024

@MaskRay @jh7370
Based on the commit history for similar changes your names came up frequently. If this doesn't seem appropriate, I apologize in advance.

Cheers!

Copy link
Collaborator

@rnk rnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch, I have a minor suggestion

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me, but you should probably wait for @rnk to approve before this gets landed, as I'm not a regular COFF maintainer (I tend to focus on the ELF side of things).

One description nit: there's no such tool as "llvm-yaml2obj" - the tool is simply called "yaml2obj".

Copy link
Collaborator

@rnk rnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, sorry to bother with the nits, I just want to get it to a state that I can merge from the web UI.

@mayanez
Copy link
Contributor Author

mayanez commented Jun 4, 2024

Looks good, sorry to bother with the nits, I just want to get it to a state that I can merge from the web UI.

Not a problem. I've rebased the changes to the original commit to keep the history tidy.

@rnk rnk merged commit 0cb66a7 into llvm:main Jun 4, 2024
3 of 5 checks passed
Copy link

github-actions bot commented Jun 4, 2024

@mayanez Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants