[llvm-ml] Improve indirect call parsing
authorAlan Zhao <ayzhao@google.com>
Thu, 28 Apr 2022 17:01:10 +0000 (13:01 -0400)
committerEric Astor <epastor@google.com>
Thu, 28 Apr 2022 17:17:19 +0000 (13:17 -0400)
commit3333c28fc0dc0485e0e08b9d7039e0a501884b7a
treeae34e8f7a4fc75e1b6d8e18dd023db0150f3dfcb
parenta9215ed9cc904f05d02dc75f9f4680bf0b33965f
[llvm-ml] Improve indirect call parsing

In MASM, if a QWORD symbol is passed to a jmp or call instruction in
64-bit mode or a DWORD or WORD symbol is passed in 32-bit mode, then
MSVC's assembler recognizes that as an indirect call. Additionally, if
the operand is qualified as a ptr, then that should also be an indirect
call.

Furthermore, in 64-bit mode, such operands are implicitly rip-relative
(in fact, MSVC's assembler ml64.exe does not allow explicitly specifying
rip as a base register.)

To keep this patch managable, this patch does not include:
* error messages for wrong operand types (e.g. passing a QWORD in 32-bit
  mode)
* resolving indirect calls if the symbol is declared after it's first
  use (llvm-ml currently only runs a single pass).
* imlementing the extern keyword (required to resolve
  https://crbug.com/762167.)

This patch is likely missing a bunch of edge cases, so please do point
them out in the review.

Reviewed By: epastor, hans, MaskRay

Committed By: epastor (on behalf of ayzhao)

Differential Revision: https://reviews.llvm.org/D124413
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/lib/Target/X86/AsmParser/X86Operand.h
llvm/test/tools/llvm-ml/indirect_branch.asm [new file with mode: 0644]