Add cg_profile directive and .llvm.call-graph-profile section in COFF.
The assembly format and binary are the same as ELF.
Details
- Reviewers
jhenderson MaskRay Bigcheese hans
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/MC/MCParser/COFFAsmParser.cpp | ||
---|---|---|
336 | Only store non-temporary symbols pairs. In ELF, temporary symbols are also stored. I don't get the point of doing that. As I know, temporary symbols will not show up in object file. So, there is no reason to store temporary symbols. | |
llvm/tools/llvm-readobj/llvm-readobj.cpp | ||
349–352 ↗ | (On Diff #270540) | Probably, these two should be combined into one option --cg-profile. |
I'd expect a dedicated test for the new llvm-readobj dumping behaviour in "test/tools/llvm-readobj/COFF", probably using yaml as input if the format is supported or the binary content isn't ridiculous. We need to be careful not to create circular testing to ensure that llvm-readobj doesn't share the same bug as MC.
It probably makes sense to split the llvm-readobj dumping changes into a separate patch, that can be done separately, probably in addition to a third patch as mentioned inline for the option.
llvm/tools/llvm-readobj/COFFDumper.cpp | ||
---|---|---|
1974 ↗ | (On Diff #270540) | I've not looked into whether this is possible, but if it is, it might be nice to share at least some of the COFF and ELF code, since presumably the section format is identical in both cases. |
llvm/tools/llvm-readobj/llvm-readobj.cpp | ||
349–352 ↗ | (On Diff #270540) | Yeah, rather than adding a coff-specific option, I'd add --cg-profile and make --elf-cg-profile an alias for backwards compatibility (or possibly even delete it, but I'd be somewhat reluctant to do that). You can do that in a separate patch before this one. Also, the new option, in whatever form it takes, needs adding to the CommandGuide doc for llvm-readobj and llvm-readelf (the latter only for the generic --cg-profile option, and only if applicable). |
509 ↗ | (On Diff #270540) | By using the new name, you can avoid this code change. |
- Split llvm-readobj part to another patch.
- Write .llvm-call-graph-profile section data in the same format as ELF.
llvm/lib/MC/MCParser/COFFAsmParser.cpp | ||
---|---|---|
307 | Not exactly the same. See the comment below. | |
llvm/tools/llvm-readobj/COFFDumper.cpp | ||
1974 ↗ | (On Diff #270540) | COFF.h lack some functionalities to do the same parsing as ELF.h. I think this is also why the parsing of Addrsig section in COFF doesn't share any code with ELF, even if the section format is identical in both cases. |
llvm/lib/MC/MCParser/COFFAsmParser.cpp | ||
---|---|---|
336 | Temporary symbols are a subcategory of local symbols. I think in ELF, it does not really matter whether a profile edge references a local symbol or not, a temporary symbol or not. A temporary symbol can also encode a profile edge. Is there any particular reason you want to exclude temporary symbols from COFF? | |
llvm/lib/MC/MCWinCOFFStreamer.cpp | ||
342 | Why setIsWeakExternal? |
llvm/lib/MC/MCParser/COFFAsmParser.cpp | ||
---|---|---|
336 | From my understanding, since temporary symbols doesn't show up in final binary and the purpose of .llvm.call-graph-profile is to be used to optimize section layouts of final binary, storing temporary symbols doesn't help. | |
llvm/lib/MC/MCWinCOFFStreamer.cpp | ||
342 | Doing the same as finalizeCGProfileEntry in ELF, https://github.com/llvm/llvm-project/blob/master/llvm/lib/MC/MCELFStreamer.cpp#L483. |
llvm/lib/MC/MCParser/COFFAsmParser.cpp | ||
---|---|---|
336 | Please drop isTemporary. For temporary symbols (.L prefixed), the streamer can use a symbol representing the defined section. In ELF, this can cause creation of STT_SECTION. See D51047 for a COFF example. | |
llvm/lib/MC/MCWinCOFFStreamer.cpp | ||
342 | OK. http://llvm.org/docs/Extensions.html#sht-llvm-call-graph-profile-section-call-graph-profile says that the undefined symbol is weak. It does not have to be specified that way... |
llvm/lib/MC/MCParser/COFFAsmParser.cpp | ||
---|---|---|
336 | Okay. I want to do so, but there is a problem. https://reviews.llvm.org/D44965#1115454 says, temporary symbols should get null symbol index. And it is doing so by setting temporary symbol to Begin symbol of its section, https://github.com/llvm/llvm-project/blob/master/llvm/lib/MC/MCELFStreamer.cpp#L473, which will later update to null symbol index in computeSymbolTable (e.g. 4 in the test case). So, the .L.local temporary symbol will not show up when reading with llvm-readobj --cg-profile, https://github.com/llvm/llvm-project/blob/master/llvm/test/MC/ELF/cgprofile.s#L96. In order to do the same, we need temporary symbols get null symbol indexes (or similar thing) in COFF. Is there a way to do that in COFF? |
llvm/lib/MC/MCParser/COFFAsmParser.cpp | ||
---|---|---|
336 | I don't know enough about COFF to suggest a solution, but I believe you can leave out temporary for now
|
- Move ParseDirectiveCGProfile to MCAsmParserExtension.
- Ignore temporary symbols in MCWinCOFFStreamer::emitCGProfileEntry.
This was landed, but I accidentally wrote wrong diff ID (D83597) in the commit message: https://github.com/llvm/llvm-project/commit/0f0c5af3db9b0159d9b1a89faff3bd047510b628
If the code duplicates ELFAsmParser, please move it to AsmParser::