This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Minimal serialization support for precompiled types records
ClosedPublic

Authored by aganea on Apr 4 2018, 1:27 PM.

Details

Summary

This change adds support for the LF_PRECOMP and LF_ENDPRECOMP records required
to read/write Microsoft precompiled types .objs.
See https://en.wikipedia.org/wiki/Precompiled_header#Microsoft_Visual_C_and_C++

This also adds handling for the .debug$P section, which is actually a .debug$T
section in disguise, found only in precompiled .objs.

Side-note: the LF_PRECOMP and LF_ENDPRECOMP records are only used in .obj; they
are subsequently dropped during the PDB type merging phase. In the same way,
the .debug$P section is merged with the other .debug$T sections in the PDB.

Diff Detail

Repository
rL LLVM

Event Timeline

aganea created this revision.Apr 4 2018, 1:27 PM
rnk accepted this revision.Apr 4 2018, 2:49 PM

Looks good to me, but let's ask @zturner too.

include/llvm/DebugInfo/CodeView/TypeRecord.h
910 ↗(On Diff #141031)

That sounds like it'll be fun to implement in type merging. =/

This revision is now accepted and ready to land.Apr 4 2018, 2:49 PM
aganea marked an inline comment as done.Apr 5 2018, 8:28 AM
aganea added inline comments.
include/llvm/DebugInfo/CodeView/TypeRecord.h
910 ↗(On Diff #141031)

Well in practice, it is not as bad as it seems. It boils down to replacing the LF_PRECOMP record with a copy of precomp.obj, up to LF_ENDRECORD.

Consider a.obj, which has a reference to precomp.obj:

0x1000 | LF_PRECOMP [size = 60] start index = 4096, types count = 1031, signature = 0x1116980E, precomp path = f:\svn\lld\test\coff\precomp\precomp.obj
0x1407 | LF_ARGLIST [size = 12]
         0x0070 (char): `char`
0x1408 | LF_PROCEDURE [size = 16]
         return type = 0x0074 (int), # args = 1, param list = 0x1407
         calling conv = cdecl, options = None
0x1409 | LF_FUNC_ID [size = 20]
         name = main, type = 0x1029, parent scope = <no type>

and precomp.obj:

0x1000 | LF_STRUCTURE [size = 64] `_s__CatchableType`
         unique name: `.?AU_s__CatchableType@@`
         vtable: <no type>, base list: <no type>, field list: <no type>
         options: forward ref | has unique name
0x1001 | LF_MODIFIER [size = 12]
         referent = 0x1000, modifiers = const
...
0x1406 | LF_UDT_SRC_LINE [size = 16]
         udt = 0x1405, file = 4180, line = 759
0x1407 | LF_ENDPRECOMP [size = 8] signature = 0x1116980E

Prior to merging a.obj, you simply append the contents of precomp.obj into LF_PRECOMP, up to LF_ENDPRECOMP (but not including it)
As you can see the type records IDs jump after LF_PRECOMP from 0x1000 to 0x1407. The data is just here for back-reference, so a.obj can be remapped properly. We only merge/remap precomp.obj once.

Currently, llvm-pdbutil does not jump from 0x1000 to 0x1407 after printing LF_PRECOMP, I will fix that in a subsequent change as it doesn't seem like a trivial change.

I'm going to look at this today.

test/DebugInfo/precomp.test
15 ↗(On Diff #141031)

Can you put some spaces here to line it up?

I was trying to play around with some precompiled header object files to make sure I understand how it all works, and I noticed our tools don't handle dumping types in .debug$P sections. So I added this in r329326. Just fyi.

zturner added inline comments.Apr 5 2018, 11:48 AM
test/DebugInfo/precomp.test
10–11 ↗(On Diff #141031)

Can you change this to just dump -types instead of dump -all?

29–33 ↗(On Diff #141031)

You can delete all of this Cross Module Exports stuff as it confuses the user (I originally thought these were XME records). In a recent patch I added a new header for types that appear in object files, so you can change this to something like:

PDB-PRECOMP:         Precompiled Types (.debug$P)
PDB-PRECOMP-NEXT: ============================================================
PDB-PRECOMP-NEXT: Showing 0 records
PDB-PRECOMP-NEXT: 0x1000 | LF_PRECOMP [size = 60] start index = 4096, types count = 1031, signature = 0x1116980E, precomp path = f:\svn\lld\test\coff\precomp\precomp.obj
zturner added inline comments.Apr 5 2018, 12:46 PM
include/llvm/DebugInfo/CodeView/TypeRecord.h
910 ↗(On Diff #141031)

Currently, llvm-pdbutil does not jump from 0x1000 to 0x1407 after printing LF_PRECOMP, I will fix that in a subsequent change as it doesn't seem like a trivial change.

It seems like we could do a similar thing to what we do for LF_TYPESERVER records. But you're right it might not be trivial.

aganea updated this revision to Diff 141359.Apr 6 2018, 8:50 AM
aganea marked an inline comment as done.

I rebased on latest trunk. Adressed issues raised by @zturner.
Also, add CodeViewTypes.def which I forgot previously. Changed LF_PRECOMP record .StartIndex and .Count to print out in hex format.

zturner accepted this revision.Apr 6 2018, 10:48 AM
zturner added inline comments.
tools/llvm-pdbutil/MinimalTypeDumper.cpp
475–478 ↗(On Diff #141359)

You can do {0:X+} instead of converting each of them manually. The X means print uppercase hex digits, and the + means print the 0x prefix.

This revision was automatically updated to reflect the committed changes.