This is an archive of the discontinued LLVM Phabricator instance.

[ProfileData] Support coverage for PE binaries
ClosedPublic

Authored by davidxl on Apr 13 2017, 9:31 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

davidxl created this revision.Apr 13 2017, 9:31 AM
vsk added inline comments.Apr 13 2017, 11:18 AM
lib/ProfileData/Coverage/CoverageMappingReader.cpp
651 ↗(On Diff #95141)

It doesn't look like getInstrProfNameSectionName() returns the correct section name for COFF files here. With the exception of the ELF-specific change in TargetLoweringObjectFileImpl.cpp, this comment applies everywhere else in this patch where a module is not passed in to the get*SectionName helper.

Do you think we need a mandatory way to tell the get*SectionName functions which file format we're working with?

lib/ProfileData/InstrProf.cpp
257 ↗(On Diff #95141)

These get*SectionName functions are getting a bit unwieldy. Wdyt of consolidating them? There are two inputs: ObjectFileKind ({MachO, COFF, Other}), and ProfInfoKind ({Counters, Names, Data, Values, Vnodes, Coverage}). We just need one function: StringRef getInstrProfSectionName(ObjectFileKind, ProfInfoKind).

davidxl added inline comments.Apr 13 2017, 11:25 AM
lib/ProfileData/Coverage/CoverageMappingReader.cpp
651 ↗(On Diff #95141)

You are right here.

However this patch is about cross compilation support, not about host tool support for other platforms. I can add a comment and TODO here that the binary format is assumed to be the native format on the host platform.

lib/ProfileData/InstrProf.cpp
257 ↗(On Diff #95141)

True. I will see if a refactoring is doable.

davidxl updated this revision to Diff 95234.Apr 13 2017, 4:07 PM

Addressed review feedbacks.

vsk accepted this revision.Apr 13 2017, 4:16 PM

LGTM with a few minor changes.

lib/ProfileData/InstrProf.cpp
172 ↗(On Diff #95234)

We can simplify this function with an early return: if (!M) return InstrProfSectName[Kind];. One less null check.

lib/Transforms/Instrumentation/ThreadSanitizer.cpp
284 ↗(On Diff #95234)

nit, clang-format

tools/llvm-cov/TestingSupport.cpp
54 ↗(On Diff #95234)

Could you replicate your TODO comment here? ( 'to support Win->ELF cross compilation with coverage properly'...)

This revision is now accepted and ready to land.Apr 13 2017, 4:16 PM
davidxl marked 3 inline comments as done.Apr 13 2017, 4:30 PM
This revision was automatically updated to reflect the committed changes.

Fixed in r300289.

llvm/trunk/include/llvm/ProfileData/InstrProf.h
94

It causes requiring LLVMProfileData for its users, for example, LLVMCodeGen.

rnk added a subscriber: rnk.Apr 14 2017, 9:43 AM
rnk added inline comments.
llvm/trunk/include/llvm/ProfileData/InstrProfData.inc
666

This ifdef breaks cross compiling. In particular, llvm/test/Instrumentation/InstrProfiling/X86/alloc.ll is failing on Windows since this change. LLVM should choose the section name at runtime based on the target triple, not the host defines.

rnk added inline comments.Apr 14 2017, 9:53 AM
llvm/trunk/include/llvm/ProfileData/InstrProfData.inc
666

Oops, I think I spoke too soon. I don't think I understand why the test is failing yet.

rnk added inline comments.Apr 14 2017, 10:59 AM
llvm/trunk/include/llvm/ProfileData/InstrProfData.inc
666

Yeah, it's not the ifdef (sorry), it's the TODOs in llvm-cov that highlight all the points where cross-running llvm-cov on a binary with a different object format from the host will fail. I wrote https://reviews.llvm.org/D32090 to try to address that, but I'm open to other ideas.