This is an archive of the discontinued LLVM Phabricator instance.

COFF: add beginnings of debug directory creation
ClosedPublic

Authored by compnerd on Aug 12 2016, 4:35 PM.

Details

Reviewers
ruiu
Summary

The IMAGE_FILE_HEADER structure contains a (RVA, size) to an array of
COFF_DEBUG_DIRECTORY records. Each one of these records contains an RVA to a
OMF Debug Directory. These OMF debug directories are derived into newer types
such as PDB70, PDB20, etc. This constructs a PDB70 structure which will allow
us to associate a GUID with a build to actually tie debug information.

Diff Detail

Repository
rL LLVM

Event Timeline

compnerd updated this revision to Diff 67936.Aug 12 2016, 4:35 PM
compnerd retitled this revision from to COFF: add beginnings of debug directory creation.
compnerd updated this object.
compnerd added a reviewer: ruiu.
compnerd set the repository for this revision to rL LLVM.
compnerd added a subscriber: llvm-commits.

This is obviously a very preliminary patch. I wanted to get some consensus on how to handle the GUID associated with the binary and an overall structure (whether to merge the content into a different file or keep it separate).

ruiu added inline comments.Aug 15 2016, 1:24 PM
COFF/Debug.cpp
41 ↗(On Diff #67936)

Move.

79 ↗(On Diff #67936)

chunks -> Chunks

COFF/Debug.h
21 ↗(On Diff #67936)

This class is a container of chunks, but only one element is currently added to this vector, so we don't actually need this class (you could add a member of type std::unique_ptr<CVDebugRecordChunk> to the Writer instead of this class.) Are you planning to do more complex thing with this class? If not, I'd remove this class.

21–22 ↗(On Diff #67936)

Move this after all public members for consistency with other class declarations.

COFF/Writer.cpp
291

I'd name this Rdata.

compnerd added inline comments.Aug 15 2016, 5:47 PM
COFF/Debug.h
21 ↗(On Diff #67936)

Well, it should add a coffgrp record by default unless CV is present. Furthermore, we should at some point emit the features record as well. Ideally, at some point, this would also integrate into the PDB handling to retrieve the GUID and Age so that rather than re-generating it on every build, we could just increment the age.

I don't think that all of this will happen immediately, but is something that we will need, so I was tempted to create the class. I don't think that Im really tied to that idea and i you think going with the simpler route for now is better, I can merge this into the writer.

ruiu edited edge metadata.Aug 17 2016, 2:34 PM

Then I'd merge them to the write to keep it small.

compnerd updated this revision to Diff 68877.Aug 22 2016, 9:54 AM
compnerd edited edge metadata.
compnerd removed rL LLVM as the repository for this revision.

Refactor the addition based on @ruiu's comments. This is still missing a test, but should be functional for stubbing out the section otherwise. We should still figure out the best way to generate the GUID for the RSDS record.

compnerd updated this revision to Diff 69519.Aug 28 2016, 2:05 PM
compnerd set the repository for this revision to rL LLVM.

This adds a test as well. Right now the only thing which is missing is the GUID generation. Its unclear whether we want to use the random generation on each build (bad for reproducible builds) or hash the contents. Im not sure how to best do the latter. But, I think beyond that point, this is ready.

ruiu accepted this revision.Aug 29 2016, 11:09 AM
ruiu edited edge metadata.

LGTM with a few nits.

COFF/Writer.cpp
58

auto -> std::unique_ptr<Chunk>

74

Why don't you use ArrayRef?

This revision is now accepted and ready to land.Aug 29 2016, 11:09 AM
compnerd closed this revision.Aug 29 2016, 2:42 PM

SVN r280012 with the NIT addressed.