1// Check that cross-DSO diagnostics print the names of both modules
2
3// RUN: %clangxx_cfi_diag -g -DSHARED_LIB -fPIC -shared -o %dynamiclib %s %ld_flags_rpath_so
4// RUN: %clangxx_cfi_diag -g -o %t_exe_suffix %s %ld_flags_rpath_exe
5// RUN: %t_exe_suffix 2>&1 | FileCheck -DDSONAME=%xdynamiclib_namespec %s
6
7// UNSUPPORTED: target={{.*windows-msvc.*}}
8// REQUIRES: cxxabi
9
10#include <dlfcn.h>
11#include <stdio.h>
12
13struct S1 {
14 virtual void f1();
15};
16
17#ifdef SHARED_LIB
18
19void S1::f1() {}
20
21__attribute__((visibility("default"))) extern "C"
22void* dso_symbol() { return new S1(); }
23
24#else
25
26int main() {
27 void* (*fp)(void) =
28 reinterpret_cast<void*(*)(void)>(dlsym(RTLD_DEFAULT, name: "dso_symbol"));
29 if (!fp) {
30 perror(s: "failed to resolve dso_symbol");
31 return 1;
32 }
33
34 // CHECK: runtime error: control flow integrity check for type 'void *()' failed during indirect function call
35 // CHECK: dso_symbol defined here
36 // CHECK: check failed in {{.*}}_exe_suffix, destination function located in {{.*}}[[DSONAME]]
37 void *S = fp(); // trigger cfi-icall failure
38
39 // CHECK: runtime error: control flow integrity check for type 'S1' failed during cast to unrelated type
40 // CHECK: invalid vtable
41 // CHECK: check failed in {{.*}}_exe_suffix, vtable located in {{.*}}[[DSONAME]]
42 S1 *Scast = reinterpret_cast<S1*>(S); // trigger cfi-unrelated-cast failure
43
44 return 0;
45}
46
47#endif // SHARED_LIB
48

source code of compiler-rt/test/cfi/cross-dso-diagnostic.cpp