Skip to content

Commit 771e9cd

Browse files
committed
[msan] Intercept mallinfo2 only on GLIBC 2.33+
Followup to #73729
1 parent e947f95 commit 771e9cd

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,32 +243,36 @@ INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
243243
#define MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE
244244
#endif
245245

246-
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
247-
246+
#if (!SANITIZER_FREEBSD && !SANITIZER_NETBSD) || __GLIBC_PREREQ(2, 33)
248247
template <class T>
249248
static NOINLINE void clear_mallinfo(T *sret) {
250249
ENSURE_MSAN_INITED();
251250
internal_memset(sret, 0, sizeof(*sret));
252251
__msan_unpoison(sret, sizeof(*sret));
253252
}
253+
#endif
254254

255+
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
255256
// Interceptors use NRVO and assume that sret will be pre-allocated in
256257
// caller frame.
257258
INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
258259
__sanitizer_struct_mallinfo sret;
259260
clear_mallinfo(&sret);
260261
return sret;
261262
}
263+
# define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
264+
#else
265+
# define MSAN_MAYBE_INTERCEPT_MALLINFO
266+
#endif
262267

268+
#if __GLIBC_PREREQ(2, 33)
263269
INTERCEPTOR(__sanitizer_struct_mallinfo2, mallinfo2) {
264270
__sanitizer_struct_mallinfo2 sret;
265271
clear_mallinfo(&sret);
266272
return sret;
267273
}
268-
# define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
269274
# define MSAN_MAYBE_INTERCEPT_MALLINFO2 INTERCEPT_FUNCTION(mallinfo2)
270275
#else
271-
#define MSAN_MAYBE_INTERCEPT_MALLINFO
272276
# define MSAN_MAYBE_INTERCEPT_MALLINFO2
273277
#endif
274278

compiler-rt/test/lit.common.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def add_glibc_versions(ver_string):
629629

630630
ver = LooseVersion(ver_string)
631631
any_glibc = False
632-
for required in ["2.19", "2.27", "2.30", "2.34", "2.37"]:
632+
for required in ["2.19", "2.27", "2.30", "2.33", "2.34", "2.37"]:
633633
if ver >= LooseVersion(required):
634634
config.available_features.add("glibc-" + required)
635635
any_glibc = True

compiler-rt/test/msan/Linux/mallinfo.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@
88
int main(void) {
99
struct mallinfo mi = mallinfo();
1010
assert(__msan_test_shadow(&mi, sizeof(mi)) == -1);
11-
12-
struct mallinfo2 mi2 = mallinfo2();
13-
assert(__msan_test_shadow(&mi2, sizeof(mi2)) == -1);
1411
return 0;
1512
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
2+
// REQUIRES: glibc-2.33
3+
4+
#include <assert.h>
5+
#include <malloc.h>
6+
7+
#include <sanitizer/msan_interface.h>
8+
9+
int main(void) {
10+
struct mallinfo2 mi2 = mallinfo2();
11+
assert(__msan_test_shadow(&mi2, sizeof(mi2)) == -1);
12+
return 0;
13+
}

0 commit comments

Comments
 (0)