-fsanitize=function: fix alignment fault on Arm targets.
authorSimon Tatham <simon.tatham@arm.com>
Wed, 24 May 2023 08:28:33 +0000 (09:28 +0100)
committerSimon Tatham <simon.tatham@arm.com>
Thu, 25 May 2023 08:22:45 +0000 (09:22 +0100)
commit20d6dee40d507d467d3312d5e7dfdf088f106d31
tree44fa8e35d6ee272a1495c9fec30b07ad52c423e4
parentd2502eb091fabc36463e491b066bb002b47ba521
-fsanitize=function: fix alignment fault on Arm targets.

Function pointers are checked by loading a prefix structure from just
before the function's entry point. However, on Arm, the function
pointer is not always exactly equal to the address of the entry point,
because Thumb function pointers have the low bit set to tell the BX
instruction to enter them in Thumb state. So the generated code loads
from an odd address and suffers an alignment fault.

Fixed by clearing the low bit of the function pointer before
subtracting 8.

Differential Revision: https://reviews.llvm.org/D151308
clang/lib/CodeGen/CGExpr.cpp
clang/test/CodeGen/ubsan-function.cpp