When -fexperimental-call-graph-section flag is set, it adds type metadata to all the functions whose addresses are taken and does not have local linkage. When this flag is set along with CFI, the type metadata is added to all the vtable functions including destructors. This changes which functions are to be treated as CFI functions and includes such vtable entries to become part of the CFI check jumptables. To disambiguate intentions of CFI and callgraph mechanisms, this patch renames metadata set by callgraph mechanism to !callgraph (MD_callgraph). This prevents inflating the list of CFI functions when callgraph section is enabled along with CFI.
31 lines
963 B
C++
31 lines
963 B
C++
// Tests that callback function whose address is taken is attached Type ID metadata
|
|
// as it is a potential indirect call target.
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fexperimental-call-graph-section \
|
|
// RUN: -emit-llvm -o %t %s
|
|
// RUN: FileCheck %s < %t
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
typedef void (*CallbackFn)(int);
|
|
|
|
// Callback function with "internal" linkage.
|
|
// CHECK-LABEL: define internal void @_ZL10myCallbacki(
|
|
// CHECK-SAME: {{.*}} !callgraph [[F_CALLBACK:![0-9]+]]
|
|
static void myCallback(int value)
|
|
{
|
|
volatile int sink = value;
|
|
(void)sink;
|
|
}
|
|
|
|
int takeCallbackAddress() {
|
|
// Take the address of the callback explicitly (address-taken function)
|
|
CallbackFn cb = &myCallback;
|
|
// Store the address in a volatile pointer to keep it observable
|
|
volatile void* addr = (void*)cb;
|
|
(void)addr;
|
|
|
|
return 0;
|
|
}
|
|
|
|
// CHECK: [[F_CALLBACK]] = !{!"_ZTSFviE.generalized"}
|