[compiler-rt] 50a08e2 - [DFSan] Fix flakey release_shadow_space.c accounting for Origin chains.

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 11 00:35:26 PDT 2021


Author: Andrew Browne
Date: 2021-10-11T00:35:12-07:00
New Revision: 50a08e2c6d4185df6a5b0a5b41c7ef8849aad269

URL: https://github.com/llvm/llvm-project/commit/50a08e2c6d4185df6a5b0a5b41c7ef8849aad269
DIFF: https://github.com/llvm/llvm-project/commit/50a08e2c6d4185df6a5b0a5b41c7ef8849aad269.diff

LOG: [DFSan] Fix flakey release_shadow_space.c accounting for Origin chains.

Test sometimes fails on buildbot (after two non-Origins executions):

/usr/bin/ld: warning: Cannot export local symbol 'dfsan_flush'
RSS at start: 4620, after mmap: 107020, after mmap+set label: 209424, after fixed map: 4624, after another mmap+set label: 209424, after munmap: 4624
/usr/bin/ld: warning: Cannot export local symbol 'dfsan_flush'
RSS at start: 4620, after mmap: 107020, after mmap+set label: 209424, after fixed map: 4624, after another mmap+set label: 209424, after munmap: 4624
/usr/bin/ld: warning: Cannot export local symbol 'dfsan_flush'
RSS at start: 4620, after mmap: 107020, after mmap+set label: 317992, after fixed map: 10792, after another mmap+set label: 317992, after munmap: 10792
release_shadow_space.c.tmp: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/dfsan/release_shadow_space.c:91: int main(int, char **): Assertion `after_fixed_mmap <= before + delta' failed.

Reviewed By: vitalybuka

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

Added: 
    

Modified: 
    compiler-rt/test/dfsan/release_shadow_space.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/dfsan/release_shadow_space.c b/compiler-rt/test/dfsan/release_shadow_space.c
index 01a21daec933c..4cd770d2330a7 100644
--- a/compiler-rt/test/dfsan/release_shadow_space.c
+++ b/compiler-rt/test/dfsan/release_shadow_space.c
@@ -73,8 +73,10 @@ int main(int argc, char **argv) {
       after_mmap_and_set_label2, after_munmap);
 
   const size_t mmap_cost_kb = map_size >> 10;
+  // Shadow space (1:1 with application memory)
   const size_t mmap_shadow_cost_kb = sizeof(dfsan_label) * mmap_cost_kb;
 #ifdef ORIGIN_TRACKING
+  // Origin space (1:1 with application memory)
   const size_t mmap_origin_cost_kb = mmap_cost_kb;
 #else
   const size_t mmap_origin_cost_kb = 0;
@@ -85,11 +87,21 @@ int main(int argc, char **argv) {
   assert(after_mmap_and_set_label2 >=
          before + mmap_cost_kb + mmap_shadow_cost_kb + mmap_origin_cost_kb);
 
+#ifdef ORIGIN_TRACKING
+  // Origin chain (sanitizer PersistentAllocator, never freed).
+  // This value is chosen based on observed 
diff erence.
+  const size_t mmap_origin_chain_kb = 4000;
+#else
+  const size_t mmap_origin_chain_kb = 0;
+#endif
+
   // RSS may not change memory amount after munmap to the same level as the
   // start of the program. The assert checks the memory up to a delta.
   const size_t delta = 5000;
-  assert(after_fixed_mmap <= before + delta);
-  assert(after_munmap <= before + delta);
+  // Origin chains are not freed, even when the origin space which refers to
+  // them is freed, so mmap_origin_chain_kb is added to account for this.
+  assert(after_fixed_mmap <= before + delta + mmap_origin_chain_kb);
+  assert(after_munmap <= before + delta + mmap_origin_chain_kb);
 
   return 0;
 }


        


More information about the llvm-commits mailing list