Files
clang-p2996/llvm/test/CodeGen/X86/nocfivalue.ll
Sami Tolvanen 5dc8aaac39 [llvm][IR] Add no_cfi constant
With Control-Flow Integrity (CFI), the LowerTypeTests pass replaces
function references with CFI jump table references, which is a problem
for low-level code that needs the address of the actual function body.

For example, in the Linux kernel, the code that sets up interrupt
handlers needs to take the address of the interrupt handler function
instead of the CFI jump table, as the jump table may not even be mapped
into memory when an interrupt is triggered.

This change adds the no_cfi constant type, which wraps function
references in a value that LowerTypeTestsModule::replaceCfiUses does not
replace.

Link: https://github.com/ClangBuiltLinux/linux/issues/1353

Reviewed By: nickdesaulniers, pcc

Differential Revision: https://reviews.llvm.org/D108478
2021-12-20 12:55:32 -08:00

38 lines
932 B
LLVM

; RUN: opt -S -lowertypetests %s | llc -asm-verbose=false | FileCheck %s
target datalayout = "e-p:64:64"
target triple = "x86_64-unknown-linux-gnu"
; CHECK: a:
; CHECK-NEXT: .quad f1
; CHECK-NEXT: .quad .L.cfi.jumptable
; CHECK-NEXT: .quad .L.cfi.jumptable
; CHECK-NEXT: .quad f2
; CHECK-NEXT: .quad f3
; CHECK-NEXT: .quad f3.cfi
@a = global [6 x void ()*] [void ()* no_cfi @f1, void ()* @f1, void ()* @f2, void ()* no_cfi @f2, void ()* @f3, void ()* no_cfi @f3]
declare !type !0 void @f1()
define internal void @f2() !type !0 {
ret void
}
define void @f3() #0 !type !0 {
ret void
}
declare i1 @llvm.type.test(i8* %ptr, metadata %bitset) nounwind readnone
define i1 @foo(i8* %p) {
%x = call i1 @llvm.type.test(i8* %p, metadata !"typeid1")
ret i1 %x
}
!llvm.module.flags = !{!1}
attributes #0 = { "cfi-canonical-jump-table" }
!0 = !{i32 0, !"typeid1"}
!1 = !{i32 4, !"CFI Canonical Jump Tables", i32 0}