[DFSan] Add `zeroext` attribute for callbacks with 8bit shadow variable arguments
authorWeining Lu <luweining@loongson.cn>
Thu, 29 Dec 2022 03:37:46 +0000 (11:37 +0800)
committerWeining Lu <luweining@loongson.cn>
Thu, 29 Dec 2022 03:37:47 +0000 (11:37 +0800)
commit14ce567fa267cce9466354bed1549a83286866b1
treeca653329d839c7ff9a3557b70a0a655a5ff661aa
parent2468b3f57218458dc6b9aea13682533a74c52ce6
[DFSan] Add `zeroext` attribute for callbacks with 8bit shadow variable arguments

Add `zeroext` attribute for below callbacks' first parameter
(8bit shadow variable arguments) to conform to many platforms'
ABI calling convention and some compiler behavior.
- __dfsan_load_callback
- __dfsan_store_callback
- __dfsan_cmp_callback
- __dfsan_conditional_callback
- __dfsan_conditional_callback_origin
- __dfsan_reaches_function_callback
- __dfsan_reaches_function_callback_origin

The type of these callbacks' first parameter is u8 (see the
definition of `dfsan_label`). First, many platforms' ABI
requires unsigned integer data types (except unsigned int)
are zero-extended when stored in general-purpose register.
Second, the problem is that compiler optimization may assume
the arguments are zero-extended and, if not, misbehave, e.g.
it uses an `i8` argument to index into a jump table. If the
argument has non-zero high bits, the output executable may
crash at run-time. So we need to add the `zeroext` attribute
when declaring and calling them.

Reviewed By: browneee, MaskRay

Differential Revision: https://reviews.llvm.org/D140689
llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
llvm/test/Instrumentation/DataFlowSanitizer/array.ll
llvm/test/Instrumentation/DataFlowSanitizer/basic.ll
llvm/test/Instrumentation/DataFlowSanitizer/callback.ll
llvm/test/Instrumentation/DataFlowSanitizer/reaches_function.ll
llvm/test/Instrumentation/DataFlowSanitizer/struct.ll