Weining Lu 14ce567fa2 [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
2022-12-29 11:37:47 +08:00

30 lines
809 B
LLVM

; RUN: opt < %s -passes=dfsan -dfsan-reaches-function-callbacks=1 -S | FileCheck %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
declare i32 @f()
define void @load(i32) {
; CHECK-LABEL: define void @load.dfsan
; CHECK: call{{.*}}@__dfsan_reaches_function_callback
%i = alloca i32
store i32 %0, ptr %i
ret void
}
define void @store(ptr) {
; CHECK-LABEL: define void @store.dfsan
; CHECK: call{{.*}}@__dfsan_reaches_function_callback
%load = load i32, ptr %0
ret void
}
define void @call() {
; CHECK-LABEL: define void @call.dfsan
; CHECK: call{{.*}}@__dfsan_reaches_function_callback
%ret = call i32 @f()
ret void
}
; CHECK-LABEL: @__dfsan_reaches_function_callback(i8 zeroext, ptr, i32, ptr)