Adds option /guard:cf to clang-cl and -cfguard to cc1 to emit function IDs
of functions that have their address taken into a section named .gfids$y for
compatibility with Microsoft's Control Flow Guard feature.
Details
- Reviewers
rnk - Commits
- rGdb2736ddd864: Reland "Emit Function IDs table for Control Flow Guard"
rGcf6e6c82c1ca: Emit Function IDs table for Control Flow Guard
rL322136: Reland "Emit Function IDs table for Control Flow Guard"
rC322136: Reland "Emit Function IDs table for Control Flow Guard"
rC322005: Emit Function IDs table for Control Flow Guard
rL322005: Emit Function IDs table for Control Flow Guard
Diff Detail
Event Timeline
Take a look at llvm/lib/MC/MCParser/COFFAsmParser.cpp and add the .symidx directive following the example of ParseDirectiveSecIdx. You can test it in test/MC/COFF/symidx.s with llvm-readobj.
llvm/include/llvm/MC/MCStreamer.h | ||
---|---|---|
484–485 | I think what we really want is a new directive that emits the symbol table index of the given symbol. I'd suggest calling it ".symidx" since it's kind of similar to the other COFF-specific .secidx and .secrel32 directives that we already have. With that in mind, I'd rename this to EmitCOFFSymbolIndex and update the comment to say it emits the 32-bit symbol table index of the given symbol to the current section. | |
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
384–385 | DWARFGroupName? | |
llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp | ||
36 | I think we can remove this check. If this was added to the AsmPrinterHandler list, then we've already done this check. | |
llvm/lib/MC/MCAsmStreamer.cpp | ||
631 | This is where you'll want to emit our new assembler directive. Something like: OS << "\t.symidx "; Symbol->print(OS, MAI); EmitEOL(); | |
llvm/lib/MC/MCWinCOFFStreamer.cpp | ||
196 | This will ultimately be named EmitCOFFSymbolIndex and it'll then make sense that it makes an MCSymbolIdFragment. | |
197 | I'd just call this variable Sec or something not specific to control flow guard. |
I've added the directive, but I'm not clear on what to do in the test.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
384–385 | Yeah, I don't really know what those parameters do, so I copied what EH (including WinSEH) was doing just a few lines above. | |
llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp | ||
36 | Done, but now I'm wondering if there was value in adding the cfguard flag to the module at all... |
Addressed most review comments.
Added .symidx directed. (Still needs test.)
Revised the tests to include a virtual method to make sure those also get
added to the Control Flow Guard IDs table.
I think we discussed this, right? You can use the secidx.s test as an example for how to right a symidx.s test, something like:
// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s | llvm-readobj -symbols -sections -section-data | FileCheck %s .text foo: ret bar: ret .data .symidx foo .symidx bar
Then you can have CHECK lines for the foo and bar symbol table entires, and that the .data section has two numbers with the appropriate indices.
I think what we really want is a new directive that emits the symbol table index of the given symbol. I'd suggest calling it ".symidx" since it's kind of similar to the other COFF-specific .secidx and .secrel32 directives that we already have. With that in mind, I'd rename this to EmitCOFFSymbolIndex and update the comment to say it emits the 32-bit symbol table index of the given symbol to the current section.