49 lines · cpp
1// Check that cross-DSO diagnostics print the names of both modules2 3// RUN: mkdir -p %t.dir && cd %t.dir4// RUN: %clangxx_cfi_diag -g -DSHARED_LIB -fPIC -shared -o %dynamiclib %s %ld_flags_rpath_so5// RUN: %clangxx_cfi_diag -g -o %t.dir/file_exe_suffix %s %ld_flags_rpath_exe6// RUN: %t.dir/file_exe_suffix 2>&1 | FileCheck -DDSONAME=%xdynamiclib_namespec %s7 8// UNSUPPORTED: target={{.*windows-msvc.*}}9// REQUIRES: cxxabi10 11#include <dlfcn.h>12#include <stdio.h>13 14struct S1 {15 virtual void f1();16};17 18#ifdef SHARED_LIB19 20void S1::f1() {}21 22__attribute__((visibility("default"))) extern "C"23void* dso_symbol() { return new S1(); }24 25#else26 27int main() {28 void* (*fp)(void) =29 reinterpret_cast<void*(*)(void)>(dlsym(RTLD_DEFAULT, "dso_symbol"));30 if (!fp) {31 perror("failed to resolve dso_symbol");32 return 1;33 }34 35 // CHECK: runtime error: control flow integrity check for type 'void *()' failed during indirect function call36 // CHECK: dso_symbol defined here37 // CHECK: check failed in {{.*}}_exe_suffix, destination function located in {{.*}}[[DSONAME]]38 void *S = fp(); // trigger cfi-icall failure39 40 // CHECK: runtime error: control flow integrity check for type 'S1' failed during cast to unrelated type41 // CHECK: invalid vtable42 // CHECK: check failed in {{.*}}_exe_suffix, vtable located in {{.*}}[[DSONAME]]43 S1 *Scast = reinterpret_cast<S1*>(S); // trigger cfi-unrelated-cast failure44 45 return 0;46}47 48#endif // SHARED_LIB49