[compiler-rt] 771e9cd - [msan] Intercept mallinfo2 only on GLIBC 2.33+

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 12:15:36 PST 2023


Author: Vitaly Buka
Date: 2023-11-29T12:15:14-08:00
New Revision: 771e9cda239c12ebc3aec65d8a6fd861b2c9e4dc

URL: https://github.com/llvm/llvm-project/commit/771e9cda239c12ebc3aec65d8a6fd861b2c9e4dc
DIFF: https://github.com/llvm/llvm-project/commit/771e9cda239c12ebc3aec65d8a6fd861b2c9e4dc.diff

LOG: [msan] Intercept mallinfo2 only on GLIBC 2.33+

Followup to #73729

Added: 
    compiler-rt/test/msan/Linux/mallinfo2.cpp

Modified: 
    compiler-rt/lib/msan/msan_interceptors.cpp
    compiler-rt/test/lit.common.cfg.py
    compiler-rt/test/msan/Linux/mallinfo.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index b883c5b2a24deb6..c2d740e7762b4bf 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -243,15 +243,16 @@ INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
 #define MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE
 #endif
 
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-
+#if (!SANITIZER_FREEBSD && !SANITIZER_NETBSD) || __GLIBC_PREREQ(2, 33)
 template <class T>
 static NOINLINE void clear_mallinfo(T *sret) {
   ENSURE_MSAN_INITED();
   internal_memset(sret, 0, sizeof(*sret));
   __msan_unpoison(sret, sizeof(*sret));
 }
+#endif
 
+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
 // Interceptors use NRVO and assume that sret will be pre-allocated in
 // caller frame.
 INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
@@ -259,16 +260,19 @@ INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
   clear_mallinfo(&sret);
   return sret;
 }
+#  define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
+#else
+#  define MSAN_MAYBE_INTERCEPT_MALLINFO
+#endif
 
+#if __GLIBC_PREREQ(2, 33)
 INTERCEPTOR(__sanitizer_struct_mallinfo2, mallinfo2) {
   __sanitizer_struct_mallinfo2 sret;
   clear_mallinfo(&sret);
   return sret;
 }
-#  define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
 #  define MSAN_MAYBE_INTERCEPT_MALLINFO2 INTERCEPT_FUNCTION(mallinfo2)
 #else
-#define MSAN_MAYBE_INTERCEPT_MALLINFO
 #  define MSAN_MAYBE_INTERCEPT_MALLINFO2
 #endif
 

diff  --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 7a91558d515420f..1753a55508c7cff 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -629,7 +629,7 @@ def add_glibc_versions(ver_string):
 
         ver = LooseVersion(ver_string)
         any_glibc = False
-        for required in ["2.19", "2.27", "2.30", "2.34", "2.37"]:
+        for required in ["2.19", "2.27", "2.30", "2.33", "2.34", "2.37"]:
             if ver >= LooseVersion(required):
                 config.available_features.add("glibc-" + required)
                 any_glibc = True

diff  --git a/compiler-rt/test/msan/Linux/mallinfo.cpp b/compiler-rt/test/msan/Linux/mallinfo.cpp
index f061218c615a3a9..3c3692969852f9b 100644
--- a/compiler-rt/test/msan/Linux/mallinfo.cpp
+++ b/compiler-rt/test/msan/Linux/mallinfo.cpp
@@ -8,8 +8,5 @@
 int main(void) {
   struct mallinfo mi = mallinfo();
   assert(__msan_test_shadow(&mi, sizeof(mi)) == -1);
-
-  struct mallinfo2 mi2 = mallinfo2();
-  assert(__msan_test_shadow(&mi2, sizeof(mi2)) == -1);
   return 0;
 }

diff  --git a/compiler-rt/test/msan/Linux/mallinfo2.cpp b/compiler-rt/test/msan/Linux/mallinfo2.cpp
new file mode 100644
index 000000000000000..5e6e5d952ff1bc9
--- /dev/null
+++ b/compiler-rt/test/msan/Linux/mallinfo2.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
+// REQUIRES: glibc-2.33
+
+#include <assert.h>
+#include <malloc.h>
+
+#include <sanitizer/msan_interface.h>
+
+int main(void) {
+  struct mallinfo2 mi2 = mallinfo2();
+  assert(__msan_test_shadow(&mi2, sizeof(mi2)) == -1);
+  return 0;
+}


        


More information about the llvm-commits mailing list