RFR: 8349623: [ASAN] Gtest os_linux.glibc_mallinfo_wrapper_vm fails
SendaoYan
syan at openjdk.org
Fri Feb 7 07:06:20 UTC 2025
Hi all,
The glibc function `mallinfo()` do do not work with -fsanitize=adddress, maybe it's [limitation or bug](https://github.com/google/sanitizers/issues/1845) of address sanitizer . Should we disable the gtest 'os_linux.glibc_mallinfo_wrapper_vm' when configure and build with address sanitizer. The macro `ADDRESS_SANITIZER` will always pass to gcc/clang/microsoft compiler when enable address sanitizer. So this PR check the macro `ADDRESS_SANITIZER` to enable the test or not.
On the other hand, this test get malloc usage information by call `os::Linux::get_mallinfo` and check "total allocation values" greater than `2K` before allocate the memort by `malloc(2K)`. Call `os::Linux::get_mallinfo` should after `malloc(2K)`.
Below code snippet can demonstrate the glibc function `mallinfo()` do do not work with -fsanitize=adddress.
#include <stdio.h>
#include <malloc.h>
int main() {
struct mallinfo info;
info = mallinfo();
printf("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", info.arena, info.ordblks, info.smblks, info.hblks, info.hblkhd, info.usmblks, info.fsmblks, info.uordblks, info.fordblks, info.keepcost);
char* ptr = malloc(0x10000);
info = mallinfo();
printf("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", info.arena, info.ordblks, info.smblks, info.hblks, info.hblkhd, info.usmblks, info.fsmblks, info.uordblks, info.fordblks, info.keepcost);
free(ptr);
return 0;
}
- Without -fsanitize=address, mallinfo() works normally.
gcc mallinfo.c && ./a.out
0, 1, 0, 0, 0, 0, 0, 0, 0, 0
135168, 1, 0, 0, 0, 0, 0, 67248, 67920, 67920
- With -fsanitize=address, mallinfo() works abnormally.
gcc -fsanitize=address mallinfo.c && ./a.out
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-------------
Commit messages:
- 8349623: [ASAN] Gtest os_linux.glibc_mallinfo_wrapper_vm fails
Changes: https://git.openjdk.org/jdk/pull/23510/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23510&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8349623
Stats: 7 lines in 1 file changed: 4 ins; 2 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/23510.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/23510/head:pull/23510
PR: https://git.openjdk.org/jdk/pull/23510
More information about the hotspot-runtime-dev
mailing list