llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.53k stars 11.79k forks source link

[ms] clang-cl and MSVC differ on some inline assembly manipulating function pointers #43848

Open ericastor opened 4 years ago

ericastor commented 4 years ago
Bugzilla Link 44503
Version trunk
OS All
Attachments Examples of differing behavior
CC @dwblaikie,@zygoloid

Extended Description

While investigating llvm/llvm-project#43617 , I've found many cases where inline assembly that manipulates function pointers compiles to different results with cl.exe and clang.

Specifically, mov and lea behave badly when addressing most function pointer values. lea is sometimes functionally equivalent on x86, but breaks if used on x86-64.

Also, branching instructions (call, jmp, jcc, etc.) differ in handling any case involving arithmetic on a function pointer.

The attachment contains specific examples.

llvmbot commented 4 years ago

All conditional moves also have differing behavior which are not in the different behavior list. I'm considering making a list of differences I can find soon to help out.

ericastor commented 4 years ago

This is going to be somewhat tricky on x86-64; the introduction of PC-relative addressing means we need to figure out how that needs to be handled for references to symbols in the surrounding C/C++, and the fact that MSVC does not support inline assembly on x86-64 at all means we don't have a proven model to reverse-engineer.

I suspect this will take quite a bit of trial-and-error.