diff --git a/compiler-rt/lib/dfsan/dfsan.cpp b/compiler-rt/lib/dfsan/dfsan.cpp --- a/compiler-rt/lib/dfsan/dfsan.cpp +++ b/compiler-rt/lib/dfsan/dfsan.cpp @@ -437,6 +437,12 @@ Die(); } +static void set_shadow_region_flags(uptr addr, uptr length) { + SetShadowRegionHugePageMode(addr, length); + if (common_flags()->use_madv_dontdump) + DontDumpShadowMemory(addr, length); +} + static void dfsan_init(int argc, char **argv, char **envp) { InitializeFlags(); @@ -444,6 +450,7 @@ if (!MmapFixedNoReserve(ShadowAddr(), UnusedAddr() - ShadowAddr())) Die(); + set_shadow_region_flags(ShadowAddr(), UnusedAddr() - ShadowAddr()); // Protect the region of memory we don't use, to preserve the one-to-one // mapping from application to shadow memory. But if ASLR is disabled, Linux @@ -451,8 +458,10 @@ // works so long as the program doesn't use too much memory. We support this // case by disabling memory protection when ASLR is disabled. uptr init_addr = (uptr)&dfsan_init; - if (!(init_addr >= UnusedAddr() && init_addr < AppAddr())) + if (!(init_addr >= UnusedAddr() && init_addr < AppAddr())) { MmapFixedNoAccess(UnusedAddr(), AppAddr() - UnusedAddr()); + set_shadow_region_flags(UnusedAddr(), AppAddr() - UnusedAddr()); + } InitializeInterceptors(); diff --git a/compiler-rt/test/dfsan/release_shadow_space.c b/compiler-rt/test/dfsan/release_shadow_space.c --- a/compiler-rt/test/dfsan/release_shadow_space.c +++ b/compiler-rt/test/dfsan/release_shadow_space.c @@ -1,4 +1,5 @@ -// RUN: %clang_dfsan %s -o %t && %run %t +// DFSAN_OPTIONS=no_huge_pages_for_shadow=false RUN: %clang_dfsan %s -o %t && %run %t +// DFSAN_OPTIONS=no_huge_pages_for_shadow=true RUN: %clang_dfsan %s -o %t && %run %t #include #include