On 11/29/19 12:47 PM, Jakub Jelinek wrote:
__ubsan_handle_function_type_mismatch* is something we don't use (Martin,
should we add such sanitizer?  We have gimple_call_fntype vs. actual decl
types, but it would need some inspection on what the sanitizer really does),
but still e.g. clang compiled binaries could and could be (at least in
theory) be linked against gcc libubsan.

Yes, we can add it for GCC 11. The sanitizer is about:

$ cat indirect.C
int foo(int a)
{
  return a;
}

void bar(int (*fn) (void))
{
  fn();
}

int main()
{
  bar(reinterpret_cast<int (*)(void)> (foo));
}

$ clang++ indirect.C -fsanitize=function && ./a.out
indirect.C:8:3: runtime error: call to function foo(int) through pointer to 
incorrect function type 'int (*)()'
(/tmp/a.out+0x424c60): note: foo(int) defined here
    #0 0x424cfb in bar(int (*)()) (/tmp/a.out+0x424cfb)
    #1 0x424d2d in main (/tmp/a.out+0x424d2d)
    #2 0x7f2e8bbfee0a in __libc_start_main 
/usr/src/debug/glibc-2.30-1.2.x86_64/csu/../csu/libc-start.c:308:16
    #3 0x403309 in _start 
/home/abuild/rpmbuild/BUILD/glibc-2.30/csu/../sysdeps/x86_64/start.S:120

static bool handleFunctionTypeMismatch(FunctionTypeMismatchData *Data,
                                       ValueHandle Function,
                                       ValueHandle calleeRTTI,
                                       ValueHandle fnRTTI, ReportOptions Opts) {
  if (checkTypeInfoEquality(reinterpret_cast<void *>(calleeRTTI),
                            reinterpret_cast<void *>(fnRTTI)))
    return false;

So it should be quite trivial as we're already using checkTypeInfoEquality in
bool __ubsan::checkDynamicType(void *Object, void *Type, HashValue Hash) {

Martin




Reply via email to