microsoft / llvm-mctoll

llvm-mctoll
Other
816 stars 125 forks source link

[X86-64] If SymbSize < MemAccessSizeInBytes, set MemAccessSize to SymbSize #146

Closed martin-fink closed 3 years ago

martin-fink commented 3 years ago

This fixes a crash when a move instruction moves an address of a global int variable into a 64-bit register, as a MemAccessSize of 8 bytes was assumed.

The following code triggers this issue:

int x = 4;

test(&x);

The &x is compiled to

movabs rdi, 2111952
call test

Since no memory access size was set for MOV64ri, the code used the destination registers size to calculate MemAccessSizeInBytes. Since this is greater than SymbSize, this assertion failed.

We now set MemAccessSize to SymbSize if SymbSize is less than MemAccessSize.