[compiler-rt] r347088 - Add new interceptor for mi_vector_hash(3)

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 16 11:54:14 PST 2018


Author: kamil
Date: Fri Nov 16 11:54:13 2018
New Revision: 347088

URL: http://llvm.org/viewvc/llvm-project?rev=347088&view=rev
Log:
Add new interceptor for mi_vector_hash(3)

Summary:
mi_vector_hash(3) provides fast 32bit hash functions.

Add a test for this interface.

Enable the API for NetBSD.

Based on original work by Yang Zheng.

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: tomsun.0.7, kubamracek, llvm-commits, mgorny, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D54530

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/mi_vector_hash.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=347088&r1=347087&r2=347088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Nov 16 11:54:13 2018
@@ -7282,6 +7282,22 @@ INTERCEPTOR(int, getmntinfo, void **mntb
 #define INIT_GETMNTINFO
 #endif
 
+#if SANITIZER_INTERCEPT_MI_VECTOR_HASH
+INTERCEPTOR(void, mi_vector_hash, const void *key, SIZE_T len, u32 seed,
+            u32 hashes[3]) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, mi_vector_hash, key, len, seed, hashes);
+  if (key)
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, key, len);
+  REAL(mi_vector_hash)(key, len, seed, hashes);
+  if (hashes)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, hashes, sizeof(hashes[0]) * 3);
+}
+#define INIT_MI_VECTOR_HASH COMMON_INTERCEPT_FUNCTION(mi_vector_hash)
+#else
+#define INIT_MI_VECTOR_HASH
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7536,6 +7552,7 @@ static void InitializeCommonInterceptors
   INIT_PROTOENT;
   INIT_NETENT;
   INIT_GETMNTINFO;
+  INIT_MI_VECTOR_HASH;
 
   INIT___PRINTF_CHK;
 }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=347088&r1=347087&r2=347088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Nov 16 11:54:13 2018
@@ -517,5 +517,6 @@
 #define SANITIZER_INTERCEPT_PROTOENT SI_NETBSD
 #define SANITIZER_INTERCEPT_NETENT SI_NETBSD
 #define SANITIZER_INTERCEPT_GETMNTINFO SI_NETBSD
+#define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/mi_vector_hash.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/mi_vector_hash.cc?rev=347088&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/mi_vector_hash.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/mi_vector_hash.cc Fri Nov 16 11:54:13 2018
@@ -0,0 +1,19 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+  unsigned char key[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99};
+  uint32_t hashes[3];
+  mi_vector_hash(key, __arraycount(key), 0, hashes);
+  for (size_t i = 0; i < __arraycount(hashes); i++)
+    printf("hashes[%zu]='%" PRIx32 "'\n", i, hashes[i]);
+
+  // CHECK: hashes[0]='{{.*}}'
+  // CHECK: hashes[1]='{{.*}}'
+  // CHECK: hashes[2]='{{.*}}'
+
+  return 0;
+}




More information about the llvm-commits mailing list