[dfsan] Rename and fix an internal test issue for mmap+calloc
authorJianzhou Zhao <jianzhouzh@google.com>
Fri, 30 Apr 2021 17:18:05 +0000 (17:18 +0000)
committerJianzhou Zhao <jianzhouzh@google.com>
Fri, 7 May 2021 00:57:21 +0000 (00:57 +0000)
The linker suggests using -Wl,-z,notext.

Replaced assert by exit also fixed this.

After renaming, interceptor.c would be used to test interceptors in general by D101204.

Reviewed By: morehouse

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

compiler-rt/test/dfsan/mmap_at_init.c [moved from compiler-rt/test/dfsan/interceptors.c with 86% similarity]

similarity index 86%
rename from compiler-rt/test/dfsan/interceptors.c
rename to compiler-rt/test/dfsan/mmap_at_init.c
index d096138..913602e 100644 (file)
@@ -6,9 +6,7 @@
 //
 // Tests that calling mmap() during during dfsan initialization works.
 
-#include <assert.h>
 #include <sanitizer/dfsan_interface.h>
-#include <string.h>
 #include <sys/mman.h>
 #include <unistd.h>
 
@@ -23,7 +21,9 @@ void *calloc(size_t Num, size_t Size) {
   Size = (Size + PageSize - 1) & ~(PageSize - 1); // Round up to PageSize.
   void *Ret = mmap(NULL, Size, PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-  assert(Ret != MAP_FAILED);
+  // Use assert may cause link errors that require -Wl,-z,notext.
+  // Do not know the root cause yet.
+  if (Ret == MAP_FAILED) exit(-1);
   return Ret;
 }