This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer][asan][msvc] Teach GetInstructionSize about many instructions that appear in MSVC generated code.
AcceptedPublic

Authored by barcharcraz on May 19 2023, 5:10 PM.

Details

Summary

MSVC can sometimes generate instructions in function prologues that asan previously didn't know the size of. This teaches asan those sizes. This isn't super useful for using ASAN with non-msvc compilers, but it does stand alone.

Diff Detail

Event Timeline

barcharcraz created this revision.May 19 2023, 5:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2023, 5:10 PM
Herald added a subscriber: Enna1. · View Herald Transcript
barcharcraz requested review of this revision.May 19 2023, 5:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2023, 5:10 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
barcharcraz edited the summary of this revision. (Show Details)May 19 2023, 5:15 PM
barcharcraz edited the summary of this revision. (Show Details)
rnk accepted this revision.May 22 2023, 11:08 AM

We are growing a full x86 instruction decoder. :(

lgtm

This revision is now accepted and ready to land.May 22 2023, 11:08 AM
strega-nil requested changes to this revision.May 24 2023, 3:30 PM
strega-nil added a subscriber: strega-nil.
strega-nil added inline comments.
compiler-rt/lib/interception/interception_win.cpp
533

This is an incorrect machine code instruction; according to my disassembler, EC 8B results in:

in al, dx
.byte 8B

which is clearly nonsense; additionally, I notice that it's a reverse of the "correct" two bytes, which says to me that someone got confused by byte to little-endian conversions.

535

These, OTOH, are correct; however, the constants should be capitalised and the formatting should be made closer to the other cases (same below).

546

I've not yet taken a look at these, and I need to go home; I'd appreciate if you'd just double check that these are correct (and also fix the formatting).

This revision now requires changes to proceed.May 24 2023, 3:30 PM
strega-nil added inline comments.May 24 2023, 7:24 PM
compiler-rt/lib/interception/interception_win.cpp
546

These again look to be reversed:

1 00000000 83E4F8                  and esp, 0xFFFFFFF8
2 00000003 83EC64                  sub esp, 64h
560

These are correct, otoh.

602
615
618
740

These are correct.

758

This is correct.

strega-nil added inline comments.May 25 2023, 10:18 AM
compiler-rt/lib/interception/interception_win.cpp
626
674
688
691

Style edits (please make the same edits below)

701–702
703

Please actually write out the opcode and operation (same below).

709

(side note, I really dislike cmp DWORD PTR rather than just cmd DWORD, but no change requested because that's the existing style)
(make the same P => PTR change below)

  • correct instruction encodings
  • prevent clang-format from wrapping some lines
This comment was removed by strega-nil.
strega-nil accepted this revision.May 31 2023, 4:35 PM

We can go back and do a formatting pass later, all the actual code looks correct to me though.

This revision is now accepted and ready to land.May 31 2023, 4:35 PM
barcharcraz marked 4 inline comments as done.
  • correct a few more comments
barcharcraz accepted this revision.Jun 7 2023, 4:47 PM
barcharcraz marked 10 inline comments as done.
barcharcraz requested review of this revision.Jun 7 2023, 4:49 PM
vitalybuka resigned from this revision.Jun 7 2023, 6:16 PM
strega-nil accepted this revision.Jun 14 2023, 11:09 AM
This revision is now accepted and ready to land.Jun 14 2023, 11:09 AM