[compiler-rt] 34e2f4f - [sanitizer] Do not mmap FlagParser::flags_

Leonard Chan via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 12:09:11 PDT 2023


Author: Leonard Chan
Date: 2023-08-29T19:08:16Z
New Revision: 34e2f4f2e28a464b127d878979efbc87bc148db5

URL: https://github.com/llvm/llvm-project/commit/34e2f4f2e28a464b127d878979efbc87bc148db5
DIFF: https://github.com/llvm/llvm-project/commit/34e2f4f2e28a464b127d878979efbc87bc148db5.diff

LOG: [sanitizer] Do not mmap FlagParser::flags_

Instead, make it a static array that's part of the FlagParser. The advantage
this has is helping reduce fragmentation from needing to anonymously mmap
this array via the LowLevelAllocator. This will instead place the array on
the stack. Functionally, the only difference is that the array will not be
zero-initialized, but all used elements are explicitly initialized via the
flag handlers.

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

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.cpp
index ca37df348580ae..83e080c3149c14 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.cpp
@@ -182,9 +182,6 @@ void FlagParser::RegisterHandler(const char *name, FlagHandlerBase *handler,
   ++n_flags_;
 }
 
-FlagParser::FlagParser() : n_flags_(0), buf_(nullptr), pos_(0) {
-  flags_ =
-      (Flag *)GetGlobalLowLevelAllocator().Allocate(sizeof(Flag) * kMaxFlags);
-}
+FlagParser::FlagParser() : n_flags_(0), buf_(nullptr), pos_(0) {}
 
 }  // namespace __sanitizer

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h b/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h
index dccdee4da2bd02..9b8c106ec07205 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h
@@ -163,7 +163,7 @@ class FlagParser {
     const char *name;
     const char *desc;
     FlagHandlerBase *handler;
-  } *flags_;
+  } flags_[kMaxFlags];
   int n_flags_;
 
   const char *buf_;


        


More information about the llvm-commits mailing list