Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / dfsan / mmap_at_init.c
bloba8d7535df4a6c4e2a3bdbe9c590d5448d83cd44c
1 // RUN: %clang_dfsan -fno-sanitize=dataflow -DCALLOC -c %s -o %t-calloc.o
2 // RUN: %clang_dfsan %s %t-calloc.o -o %t
3 // RUN: %run %t
4 //
5 // Tests that calling mmap() during during dfsan initialization works.
7 #include <sanitizer/dfsan_interface.h>
8 #include <sys/mman.h>
9 #include <unistd.h>
11 #ifdef CALLOC
13 extern void exit(int) __attribute__((noreturn));
15 // dfsan_init() installs interceptors via dlysm(), which calls calloc().
16 // Calling mmap() from here should work even if interceptors haven't been fully
17 // set up yet.
18 void *calloc(size_t Num, size_t Size) {
19 size_t PageSize = getpagesize();
20 Size = Size * Num;
21 Size = (Size + PageSize - 1) & ~(PageSize - 1); // Round up to PageSize.
22 void *Ret = mmap(NULL, Size, PROT_READ | PROT_WRITE,
23 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
24 // Use assert may cause link errors that require -Wl,-z,notext.
25 // Do not know the root cause yet.
26 if (Ret == MAP_FAILED) exit(-1);
27 return Ret;
30 #else
32 int main() { return 0; }
34 #endif // CALLOC