RFR: 8349623: [ASAN] Gtest os_linux.glibc_mallinfo_wrapper_vm fails

SendaoYan syan at openjdk.org
Fri Mar 7 09:18:01 UTC 2025


On Fri, 7 Mar 2025 09:00:32 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> 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
>
> Good

Thanks @tstuefe

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23510#issuecomment-2705921065


More information about the hotspot-runtime-dev mailing list