This is an archive of the discontinued LLVM Phabricator instance.

Emit function IDs table for Control Flow Guard
ClosedPublic

Authored by amccarth on Nov 27 2017, 4:53 PM.

Event Timeline

amccarth created this revision.Nov 27 2017, 4:53 PM
amccarth added a subscriber: llvm-commits.
rnk edited edge metadata.Nov 29 2017, 2:08 PM

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
35

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.

amccarth marked 5 inline comments as done.Dec 1 2017, 3:34 PM
In D40531#939683, @rnk wrote:

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.

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
35

Done, but now I'm wondering if there was value in adding the cfguard flag to the module at all...

amccarth updated this revision to Diff 125236.Dec 1 2017, 3:36 PM
amccarth marked an inline comment as done.

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.

rnk added a comment.Dec 18 2017, 9:12 AM
In D40531#939683, @rnk wrote:

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.

I've added the directive, but I'm not clear on what to do in the test.

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.

amccarth updated this revision to Diff 127408.Dec 18 2017, 1:56 PM

Adds tests for .symidx directive.

Any other issues here?

I'm hoping to land this before leaving for vacation.

rnk accepted this revision.Dec 20 2017, 2:09 PM

Nope, looks good to me!

This revision is now accepted and ready to land.Dec 20 2017, 2:09 PM
This revision was automatically updated to reflect the committed changes.