Google Summer of Code | malloc_info() changes the state of the heap (#41)
Anshika Gupta (@anshika_gupta)
gitlab at rtems.org
Fri Feb 13 05:18:37 UTC 2026
Anshika Gupta commented: https://gitlab.rtems.org/rtems/programs/gsoc/-/issues/41#note_142685
@gedare @chris
I checked malloc_info() output in sparc/erc32 board and aarch64/zynqmp_qemu by doing two concurrent malloc_info() calls and printing heap statistics in both the cases, it seems that it is not affecting the state of the heap in either of the case. Moreover, definition of malloc_info contains no calls which can possibly modify heap state.
I also ran the dl09 testcase from testsuites/libtests on the zynqmp_qemu and none of the runs moved the call address.
Since there is no issue in the above two cases, should i now try running EPICS on zynqmp_qemu BSP to see where exactly the call gets locked up?
I used the following code my hello.c app to test it.
```
#include <rtems.h>
#include <stdlib.h>
#include <stdio.h>
#include <rtems/confdefs.h>
#include <rtems/malloc.h>
#include <rtems/libcsupport.h>
#include <rtems/score/heapinfo.h>
rtems_task Init(rtems_task_argument ignored)
{
void *a = malloc(1024);
Heap_Information_block before;
Heap_Information_block after;
malloc_info(&before);
void *b = malloc(1024);
malloc_info(&after);
printf("Heap Information\n");
printf(" Number of blocks : %zu\n", before.Free.number);
printf(" Largest block : %zu bytes\n", before.Free.largest);
printf(" Total size : %zu bytes\n", before.Free.total);
printf(" Number of blocks : %zu\n", before.Used.number);
printf(" Largest block : %zu bytes\n", before.Used.largest);
printf(" Total size : %zu bytes\n", before.Used.total);
printf("Heap Statistics:\n");
printf(" Lifetime allocated : %llu bytes\n", before.Stats.lifetime_allocated);
printf(" Lifetime freed : %llu bytes\n", before.Stats.lifetime_freed);
printf(" Current heap size : %zu bytes\n", before.Stats.size);
printf(" Current free size : %zu bytes\n", before.Stats.free_size);
printf(" Minimum free size : %zu bytes\n", before.Stats.min_free_size);
printf(" Free blocks : %u\n", before.Stats.free_blocks);
printf(" Max free blocks : %u\n", before.Stats.max_free_blocks);
printf(" Used blocks : %u\n", before.Stats.used_blocks);
printf(" Max blocks searched: %u\n", before.Stats.max_search);
printf(" Total searches : %u\n", before.Stats.searches);
printf(" Allocations : %u\n", before.Stats.allocs);
printf(" Failed allocations : %u\n", before.Stats.failed_allocs);
printf(" Frees : %u\n", before.Stats.frees);
printf(" Resizes : %u\n", before.Stats.resizes);
printf("Heap Information\n");
printf(" Number of blocks : %zu\n", after.Free.number);
printf(" Largest block : %zu bytes\n", after.Free.largest);
printf(" Total size : %zu bytes\n", after.Free.total);
printf(" Number of blocks : %zu\n", after.Used.number);
printf(" Largest block : %zu bytes\n", after.Used.largest);
printf(" Total size : %zu bytes\n", after.Used.total);
printf("Heap Statistics:\n");
printf(" Lifetime allocated : %llu bytes\n", after.Stats.lifetime_allocated);
printf(" Lifetime freed : %llu bytes\n", after.Stats.lifetime_freed);
printf(" Current heap size : %zu bytes\n", after.Stats.size);
printf(" Current free size : %zu bytes\n", after.Stats.free_size);
printf(" Minimum free size : %zu bytes\n", after.Stats.min_free_size);
printf(" Free blocks : %u\n", after.Stats.free_blocks);
printf(" Max free blocks : %u\n", after.Stats.max_free_blocks);
printf(" Used blocks : %u\n", after.Stats.used_blocks);
printf(" Max blocks searched: %u\n", after.Stats.max_search);
printf(" Total searches : %u\n", after.Stats.searches);
printf(" Allocations : %u\n", after.Stats.allocs);
printf(" Failed allocations : %u\n", after.Stats.failed_allocs);
printf(" Frees : %u\n", after.Stats.frees);
printf(" Resizes : %u\n", after.Stats.resizes);
free(a);
free(b);
exit(0);
}
```
and the output of my hello.exe
```
anshikagupta at Anshikas-MacBook-Pro hello % qemu-system-aarch64 -no-reboot -nographic -serial mon:stdio \
-machine xlnx-zcu102 -m 4096 \
-kernel build/aarch64-rtems7-zynqmp_qemu/hello.exe
Heap Information
Number of blocks : 1
Largest block : 1071311008 bytes
Total size : 1071311008 bytes
Number of blocks : 13
Largest block : 8320 bytes
Total size : 18752 bytes
Heap Statistics:
Lifetime allocated : 18752 bytes
Lifetime freed : 0 bytes
Current heap size : 1071329760 bytes
Current free size : 1071311008 bytes
Minimum free size : 1071311008 bytes
Free blocks : 1
Max free blocks : 1
Used blocks : 13
Max blocks searched: 1
Total searches : 13
Allocations : 13
Failed allocations : 0
Frees : 0
Resizes : 0
Heap Information
Number of blocks : 1
Largest block : 1071311008 bytes
Total size : 1071311008 bytes
Number of blocks : 13
Largest block : 8320 bytes
Total size : 18752 bytes
Heap Statistics:
Lifetime allocated : 18752 bytes
Lifetime freed : 0 bytes
Current heap size : 1071329760 bytes
Current free size : 1071311008 bytes
Minimum free size : 1071311008 bytes
Free blocks : 1
Max free blocks : 1
Used blocks : 13
Max blocks searched: 1
Total searches : 13
Allocations : 13
Failed allocations : 0
Frees : 0
Resizes : 0
[ RTEMS shutdown ]
RTEMS version: 7.0.0.e5eaa824202a3760d508012b13b9df45c43e670c
RTEMS tools: 15.2.0 20250808 (RTEMS 7, RSB 424f142d70c97ca4e498e58d666d798c9de4a264, Newlib 038afec1)
executing thread ID: 0x0a010001
executing thread name: UI1
```
I also ran the dl09 testcase from testsuites/libtests on the zynqmp_qemu and none of the runs moved the call address.
```
*** BEGIN OF TEST libdl (RTL) 9 ***
*** TEST VERSION: 7.0.0.e5eaa824202a3760d508012b13b9df45c43e670c
*** TEST STATE: EXPECTED_PASS
*** TEST BUILD:
*** TEST TOOLS: 15.2.0 20250808 (RTEMS 7, RSB 424f142d70c97ca4e498e58d666d798c9de4a264, Newlib 038afec1)
--------------------------------------------------
Run: 0
Test source (link in strstr): testsuites/libtests/dl09/dl-load.c
Allocation size: 33554432
load: /dl09-o1.o
handle: 0x117df0: unresolved externals
handle: 0x117df0 loaded
space alloc: /dl09-o1.o: 33554432: 0x1193b0
load: /dl09-o2.o
handle: 0x21193c0: unresolved externals
handle: 0x21193c0 loaded
space alloc: /dl09-o2.o: 33554432: 0x211a4a0
load: /dl09-o3.o
handle: 0x411a4b0: unresolved externals
handle: 0x411a4b0 loaded
space alloc: /dl09-o3.o: 33554432: 0x411b2a0
load: /dl09-o4.o
handle: 0x611b2b0: unresolved externals
handle: 0x611b2b0 loaded
space alloc: /dl09-o4.o: 33554432: 0x611c730
load: /dl09-o5.o
handle: 0x811c740: no unresolved externals
handle: 0x811c740 loaded
handle: 0x811c740: no unresolved externals
Check is any unresolved externals exist:
handle: RTL_SELF: no unresolved externals
Running rtems_main_o1:
dlo1: module: testsuites/libtests/dl09/dl09-o1.c @ 0x119210
dlo1: dl01_bss1: 4: 0x118fc8: 0
dlo1: dl01_bss2: 4: 0x118f50: %f
dlo1: dl01_bss3: 1: 0x118f40: 00
dlo1: dl01_data1: 4: 0x118f24: 1
dlo1: dl01_data2: 4: 0x118f20: %f
dlo1: dl01_const1: 4: 0x1191d0: 3
dlo1: dl01_const2: 4: 0x1191cc: %f
dlo1: dl01_func1: 1: 0x119200
dlo1: rtems_main_o2: 0x211a2c0
dlo2: module: testsuites/libtests/dl09/dl09-o2.c @ 0x211a2c0
dlo2: dl02_bss1: 4: 0x211a13c: 0
dlo2: dl02_bss2: 4: 0x211a120: %f
dlo2: dl02_bss3: 1: 0x211a100: 00
dlo2: dl02_data1: 4: 0x211a0d0: 12345678
dlo2: dl02_data2: 4: 0x211a0f0: %f
dlo3: module: testsuites/libtests/dl09/dl09-o3.c : 0x411b010
dlo3: dl04_unresolv_1: 4: 0x611c364: 12345
dlo3: dl04_unresolv_2: 4: 0x611c380: %f
dlo3: dl04_unresolv_3: 1: 0x611c360: 7a
dlo3: dl04_unresolv_4: 8: 0x611c358: 0x611c510
dlo3: dl04_unresolv_5: 4: 0x611c518: 4
dlo3: dl04_unresolv_6: 8: 0x611c350: dl-O4
dlo3: dl05_unresolv_1: 8: 0x811d518: 0
dlo3: dl05_unresolv_2: 2: 0x811d510: 0
dlo3: dl05_unresolv_3: 4: 0x811d50c: 0
dlo3: dl05_unresolv_4: 1: 0x811d508: 0
dlo3: dl05_unresolv_5: 8: 0x811d500: 0
dlo4: module: testsuites/libtests/dl09/dl09-o4.c @ 0x611c540
dlo4: dl04_unresolv_1: 4: 0x611c364: 12345
dlo4: dl04_unresolv_2: 4: 0x611c380: %f
dlo4: dl04_unresolv_3: 1: 0x611c360: 7a
dlo4: dl04_unresolv_4: 8: 0x611c358: aBcDeF
dlo4: dl04_unresolv_5: 4: 0x611c518: 4
dlo4: dl04_unresolv_6: 8: 0x611c350: dl-O4
dlo5: module: testsuites/libtests/dl09/dl09-o5.c @ 0x811d6a0
dlo5: dl05_unresolv_1: 8: 0x811d518: 0
dlo5: dl05_unresolv_2: 2: 0x811d510: 0
dlo5: dl05_unresolv_3: 4: 0x811d50c: 0
dlo5: dl05_unresolv_4: 1: 0x811d508: 0
dlo5: dl05_unresolv_5: 8: 0x811d500: 0
handle: 0x117df0 closing
space dealloc: 0x1193b0
handle: 0x21193c0 closing
space dealloc: 0x211a4a0
handle: 0x411a4b0 closing
space dealloc: 0x411b2a0
handle: 0x611b2b0 closing
space dealloc: 0x611c730
handle: 0x811c740 closing
space dealloc: 0
--------------------------------------------------
Run: 1
Test source (link in strstr): testsuites/libtests/dl09/dl-load.c
Allocation size: 33554432
load: /dl09-o1.o
handle: 0x117df0: unresolved externals
handle: 0x117df0 loaded
space alloc: /dl09-o1.o: 33554432: 0x1193b0
load: /dl09-o2.o
handle: 0x21193c0: unresolved externals
handle: 0x21193c0 loaded
space alloc: /dl09-o2.o: 33554432: 0x211a4a0
load: /dl09-o3.o
handle: 0x411a4b0: unresolved externals
handle: 0x411a4b0 loaded
space alloc: /dl09-o3.o: 33554432: 0x411b2a0
load: /dl09-o4.o
handle: 0x611b2b0: unresolved externals
handle: 0x611b2b0 loaded
space alloc: /dl09-o4.o: 33554432: 0x611c730
load: /dl09-o5.o
handle: 0x811c740: no unresolved externals
handle: 0x811c740 loaded
handle: 0x811c740: no unresolved externals
Check is any unresolved externals exist:
handle: RTL_SELF: no unresolved externals
Running rtems_main_o1:
dlo1: module: testsuites/libtests/dl09/dl09-o1.c @ 0x119210
dlo1: dl01_bss1: 4: 0x118fc8: 0
dlo1: dl01_bss2: 4: 0x118f50: %f
dlo1: dl01_bss3: 1: 0x118f40: 00
dlo1: dl01_data1: 4: 0x118f24: 1
dlo1: dl01_data2: 4: 0x118f20: %f
dlo1: dl01_const1: 4: 0x1191d0: 3
dlo1: dl01_const2: 4: 0x1191cc: %f
dlo1: dl01_func1: 1: 0x119200
dlo1: rtems_main_o2: 0x211a2c0
dlo2: module: testsuites/libtests/dl09/dl09-o2.c @ 0x211a2c0
dlo2: dl02_bss1: 4: 0x211a13c: 0
dlo2: dl02_bss2: 4: 0x211a120: %f
dlo2: dl02_bss3: 1: 0x211a100: 00
dlo2: dl02_data1: 4: 0x211a0d0: 12345678
dlo2: dl02_data2: 4: 0x211a0f0: %f
dlo3: module: testsuites/libtests/dl09/dl09-o3.c : 0x411b010
dlo3: dl04_unresolv_1: 4: 0x611c364: 12345
dlo3: dl04_unresolv_2: 4: 0x611c380: %f
dlo3: dl04_unresolv_3: 1: 0x611c360: 7a
dlo3: dl04_unresolv_4: 8: 0x611c358: 0x611c510
dlo3: dl04_unresolv_5: 4: 0x611c518: 4
dlo3: dl04_unresolv_6: 8: 0x611c350: dl-O4
dlo3: dl05_unresolv_1: 8: 0x811d518: 0
dlo3: dl05_unresolv_2: 2: 0x811d510: 0
dlo3: dl05_unresolv_3: 4: 0x811d50c: 0
dlo3: dl05_unresolv_4: 1: 0x811d508: 0
dlo3: dl05_unresolv_5: 8: 0x811d500: 0
dlo4: module: testsuites/libtests/dl09/dl09-o4.c @ 0x611c540
dlo4: dl04_unresolv_1: 4: 0x611c364: 12345
dlo4: dl04_unresolv_2: 4: 0x611c380: %f
dlo4: dl04_unresolv_3: 1: 0x611c360: 7a
dlo4: dl04_unresolv_4: 8: 0x611c358: aBcDeF
dlo4: dl04_unresolv_5: 4: 0x611c518: 4
dlo4: dl04_unresolv_6: 8: 0x611c350: dl-O4
dlo5: module: testsuites/libtests/dl09/dl09-o5.c @ 0x811d6a0
dlo5: dl05_unresolv_1: 8: 0x811d518: 0
dlo5: dl05_unresolv_2: 2: 0x811d510: 0
dlo5: dl05_unresolv_3: 4: 0x811d50c: 0
dlo5: dl05_unresolv_4: 1: 0x811d508: 0
dlo5: dl05_unresolv_5: 8: 0x811d500: 0
handle: 0x117df0 closing
space dealloc: 0x1193b0
handle: 0x21193c0 closing
space dealloc: 0x211a4a0
handle: 0x411a4b0 closing
space dealloc: 0x411b2a0
handle: 0x611b2b0 closing
space dealloc: 0x611c730
handle: 0x811c740 closing
space dealloc: 0
--------------------------------------------------
Run: 2
Test source (link in strstr): testsuites/libtests/dl09/dl-load.c
Allocation size: 33554432
load: /dl09-o1.o
handle: 0x117df0: unresolved externals
handle: 0x117df0 loaded
space alloc: /dl09-o1.o: 33554432: 0x1193b0
load: /dl09-o2.o
handle: 0x21193c0: unresolved externals
handle: 0x21193c0 loaded
space alloc: /dl09-o2.o: 33554432: 0x211a4a0
load: /dl09-o3.o
handle: 0x411a4b0: unresolved externals
handle: 0x411a4b0 loaded
space alloc: /dl09-o3.o: 33554432: 0x411b2a0
load: /dl09-o4.o
handle: 0x611b2b0: unresolved externals
handle: 0x611b2b0 loaded
space alloc: /dl09-o4.o: 33554432: 0x611c730
load: /dl09-o5.o
handle: 0x811c740: no unresolved externals
handle: 0x811c740 loaded
handle: 0x811c740: no unresolved externals
Check is any unresolved externals exist:
handle: RTL_SELF: no unresolved externals
Running rtems_main_o1:
dlo1: module: testsuites/libtests/dl09/dl09-o1.c @ 0x119210
dlo1: dl01_bss1: 4: 0x118fc8: 0
dlo1: dl01_bss2: 4: 0x118f50: %f
dlo1: dl01_bss3: 1: 0x118f40: 00
dlo1: dl01_data1: 4: 0x118f24: 1
dlo1: dl01_data2: 4: 0x118f20: %f
dlo1: dl01_const1: 4: 0x1191d0: 3
dlo1: dl01_const2: 4: 0x1191cc: %f
dlo1: dl01_func1: 1: 0x119200
dlo1: rtems_main_o2: 0x211a2c0
dlo2: module: testsuites/libtests/dl09/dl09-o2.c @ 0x211a2c0
dlo2: dl02_bss1: 4: 0x211a13c: 0
dlo2: dl02_bss2: 4: 0x211a120: %f
dlo2: dl02_bss3: 1: 0x211a100: 00
dlo2: dl02_data1: 4: 0x211a0d0: 12345678
dlo2: dl02_data2: 4: 0x211a0f0: %f
dlo3: module: testsuites/libtests/dl09/dl09-o3.c : 0x411b010
dlo3: dl04_unresolv_1: 4: 0x611c364: 12345
dlo3: dl04_unresolv_2: 4: 0x611c380: %f
dlo3: dl04_unresolv_3: 1: 0x611c360: 7a
dlo3: dl04_unresolv_4: 8: 0x611c358: 0x611c510
dlo3: dl04_unresolv_5: 4: 0x611c518: 4
dlo3: dl04_unresolv_6: 8: 0x611c350: dl-O4
dlo3: dl05_unresolv_1: 8: 0x811d518: 0
dlo3: dl05_unresolv_2: 2: 0x811d510: 0
dlo3: dl05_unresolv_3: 4: 0x811d50c: 0
dlo3: dl05_unresolv_4: 1: 0x811d508: 0
dlo3: dl05_unresolv_5: 8: 0x811d500: 0
dlo4: module: testsuites/libtests/dl09/dl09-o4.c @ 0x611c540
dlo4: dl04_unresolv_1: 4: 0x611c364: 12345
dlo4: dl04_unresolv_2: 4: 0x611c380: %f
dlo4: dl04_unresolv_3: 1: 0x611c360: 7a
dlo4: dl04_unresolv_4: 8: 0x611c358: aBcDeF
dlo4: dl04_unresolv_5: 4: 0x611c518: 4
dlo4: dl04_unresolv_6: 8: 0x611c350: dl-O4
dlo5: module: testsuites/libtests/dl09/dl09-o5.c @ 0x811d6a0
dlo5: dl05_unresolv_1: 8: 0x811d518: 0
dlo5: dl05_unresolv_2: 2: 0x811d510: 0
dlo5: dl05_unresolv_3: 4: 0x811d50c: 0
dlo5: dl05_unresolv_4: 1: 0x811d508: 0
dlo5: dl05_unresolv_5: 8: 0x811d500: 0
handle: 0x117df0 closing
space dealloc: 0x1193b0
handle: 0x21193c0 closing
space dealloc: 0x211a4a0
handle: 0x411a4b0 closing
space dealloc: 0x411b2a0
handle: 0x611b2b0 closing
space dealloc: 0x611c730
handle: 0x811c740 closing
space dealloc: 0
--------------------------------------------------
Run: 3
Test source (link in strstr): testsuites/libtests/dl09/dl-load.c
Allocation size: 33554432
load: /dl09-o1.o
handle: 0x117df0: unresolved externals
handle: 0x117df0 loaded
space alloc: /dl09-o1.o: 33554432: 0x1193b0
load: /dl09-o2.o
handle: 0x21193c0: unresolved externals
handle: 0x21193c0 loaded
space alloc: /dl09-o2.o: 33554432: 0x211a4a0
load: /dl09-o3.o
handle: 0x411a4b0: unresolved externals
handle: 0x411a4b0 loaded
space alloc: /dl09-o3.o: 33554432: 0x411b2a0
load: /dl09-o4.o
handle: 0x611b2b0: unresolved externals
handle: 0x611b2b0 loaded
space alloc: /dl09-o4.o: 33554432: 0x611c730
load: /dl09-o5.o
handle: 0x811c740: no unresolved externals
handle: 0x811c740 loaded
handle: 0x811c740: no unresolved externals
Check is any unresolved externals exist:
handle: RTL_SELF: no unresolved externals
Running rtems_main_o1:
dlo1: module: testsuites/libtests/dl09/dl09-o1.c @ 0x119210
dlo1: dl01_bss1: 4: 0x118fc8: 0
dlo1: dl01_bss2: 4: 0x118f50: %f
dlo1: dl01_bss3: 1: 0x118f40: 00
dlo1: dl01_data1: 4: 0x118f24: 1
dlo1: dl01_data2: 4: 0x118f20: %f
dlo1: dl01_const1: 4: 0x1191d0: 3
dlo1: dl01_const2: 4: 0x1191cc: %f
dlo1: dl01_func1: 1: 0x119200
dlo1: rtems_main_o2: 0x211a2c0
dlo2: module: testsuites/libtests/dl09/dl09-o2.c @ 0x211a2c0
dlo2: dl02_bss1: 4: 0x211a13c: 0
dlo2: dl02_bss2: 4: 0x211a120: %f
dlo2: dl02_bss3: 1: 0x211a100: 00
dlo2: dl02_data1: 4: 0x211a0d0: 12345678
dlo2: dl02_data2: 4: 0x211a0f0: %f
dlo3: module: testsuites/libtests/dl09/dl09-o3.c : 0x411b010
dlo3: dl04_unresolv_1: 4: 0x611c364: 12345
dlo3: dl04_unresolv_2: 4: 0x611c380: %f
dlo3: dl04_unresolv_3: 1: 0x611c360: 7a
dlo3: dl04_unresolv_4: 8: 0x611c358: 0x611c510
dlo3: dl04_unresolv_5: 4: 0x611c518: 4
dlo3: dl04_unresolv_6: 8: 0x611c350: dl-O4
dlo3: dl05_unresolv_1: 8: 0x811d518: 0
dlo3: dl05_unresolv_2: 2: 0x811d510: 0
dlo3: dl05_unresolv_3: 4: 0x811d50c: 0
dlo3: dl05_unresolv_4: 1: 0x811d508: 0
dlo3: dl05_unresolv_5: 8: 0x811d500: 0
dlo4: module: testsuites/libtests/dl09/dl09-o4.c @ 0x611c540
dlo4: dl04_unresolv_1: 4: 0x611c364: 12345
dlo4: dl04_unresolv_2: 4: 0x611c380: %f
dlo4: dl04_unresolv_3: 1: 0x611c360: 7a
dlo4: dl04_unresolv_4: 8: 0x611c358: aBcDeF
dlo4: dl04_unresolv_5: 4: 0x611c518: 4
dlo4: dl04_unresolv_6: 8: 0x611c350: dl-O4
dlo5: module: testsuites/libtests/dl09/dl09-o5.c @ 0x811d6a0
dlo5: dl05_unresolv_1: 8: 0x811d518: 0
dlo5: dl05_unresolv_2: 2: 0x811d510: 0
dlo5: dl05_unresolv_3: 4: 0x811d50c: 0
dlo5: dl05_unresolv_4: 1: 0x811d508: 0
dlo5: dl05_unresolv_5: 8: 0x811d500: 0
handle: 0x117df0 closing
space dealloc: 0x1193b0
handle: 0x21193c0 closing
space dealloc: 0x211a4a0
handle: 0x411a4b0 closing
space dealloc: 0x411b2a0
handle: 0x611b2b0 closing
space dealloc: 0x611c730
handle: 0x811c740 closing
space dealloc: 0
*** END OF TEST libdl (RTL) 9 ***
```
--
View it on GitLab: https://gitlab.rtems.org/rtems/programs/gsoc/-/issues/41#note_142685
You're receiving this email because of your account on gitlab.rtems.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20260213/37e10edb/attachment-0001.htm>
More information about the bugs
mailing list