[PATCH] Runtime support for the indirect function call checker.

Peter Collingbourne peter at pcc.me.uk
Fri Aug 9 01:30:45 PDT 2013


Hi rsmith,

http://llvm-reviews.chandlerc.com/D1339

Files:
  lib/ubsan/ubsan_handlers.cc
  lib/ubsan/ubsan_handlers.h

Index: lib/ubsan/ubsan_handlers.cc
===================================================================
--- lib/ubsan/ubsan_handlers.cc
+++ lib/ubsan/ubsan_handlers.cc
@@ -15,6 +15,7 @@
 #include "ubsan_diag.h"
 
 #include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_symbolizer.h"
 
 using namespace __sanitizer;
 using namespace __ubsan;
@@ -258,3 +259,30 @@
     << Value(Data->Type, Val) << Data->Type;
   Die();
 }
+
+void __ubsan::__ubsan_handle_function_type_mismatch(
+    FunctionTypeMismatchData *Data,
+    ValueHandle Function) {
+  Location Loc;
+
+  AddressInfo Info;
+  if (!SymbolizeCode(Function, &Info, 1))
+    Info.file = Info.function = 0;
+
+  const char *FName = Info.function ? Info.function : "(unknown)";
+  Diag(Data->Loc, DL_Error,
+       "call to function %0 through pointer to incorrect function type %1")
+    << FName << Data->Type;
+  if (Info.file) {
+    Diag(SourceLocation(Info.file, Info.line, Info.column), DL_Note,
+         "%0 defined here")
+      << (Info.function ? Info.function : "(unknown)") << Data->Type;
+  }
+}
+
+void __ubsan::__ubsan_handle_function_type_mismatch_abort(
+    FunctionTypeMismatchData *Data,
+    ValueHandle Function) {
+  __ubsan_handle_function_type_mismatch(Data, Function);
+  Die();
+}
Index: lib/ubsan/ubsan_handlers.h
===================================================================
--- lib/ubsan/ubsan_handlers.h
+++ lib/ubsan/ubsan_handlers.h
@@ -112,6 +112,15 @@
 /// \brief Handle a load of an invalid value for the type.
 RECOVERABLE(load_invalid_value, InvalidValueData *Data, ValueHandle Val)
 
+struct FunctionTypeMismatchData {
+  SourceLocation Loc;
+  const TypeDescriptor &Type;
+};
+
+RECOVERABLE(function_type_mismatch,
+            FunctionTypeMismatchData *Data,
+            ValueHandle Val)
+
 }
 
 #endif // UBSAN_HANDLERS_H
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1339.1.patch
Type: text/x-patch
Size: 1856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130809/92a874ea/attachment.bin>


More information about the llvm-commits mailing list