Open ghost opened 2 years ago
This is something I experienced too, but after debugging a bit it seemed that it was due to some unnamed static symbols (read-only) that were defined in the code but were not reported by nm
. In my case I had some nested array in Rust defined as static ARR: ... = &[ &[...], &[...] ]
, so ARR
was reported to have just 8 bytes, and the inner arrays were not included in size. I believe this is a limitation of the tools and is not easy to fix. You would probably have to parse map files generated by linker.
But maybe it's not the above problem and you are just missing some relevant sections. You can find sections to use by running elf-size-analyze -P ...
(running with -vv
outputs which sections are being used). Then you can use -S
to select the sections explicitly.
Anyway, it's better to assume that output of elf-size-analyze
may not be 100% correct. It helps to check which symbols take what amount of space, but it might be the case that some symbols are missing.
=========================================== SECTIONS ============================================
N Name Type Addr Size Flags
=================================================================================================
1 rom_start PROGBITS 0xc200 256.0 B WRITE,ALLOC,EXECUTE
2 text PROGBITS 0xc300 773.8 KiB ALLOC,EXECUTE
3 .ARM.exidx ARM_EXIDX 0xcda0c 8.0 B ALLOC,LINK_ORDER
4 initlevel PROGBITS 0xcda14 240.0 B ALLOC
5 devices PROGBITS 0xcdb04 264.0 B ALLOC
6 ctors PROGBITS 0xcdc0c 8.0 B WRITE,ALLOC
7 init_array INIT_ARRAY 0xcdc14 108.0 B WRITE,ALLOC
8 net_socket_register_area PROGBITS 0xcdc80 12.0 B ALLOC
9 bt_l2cap_fixed_chan_area PROGBITS 0xcdc8c 36.0 B ALLOC
10 bt_gatt_service_static_area PROGBITS 0xcdcb0 16.0 B ALLOC
11 settings_handler_static_area PROGBITS 0xcdcc0 20.0 B ALLOC
12 log_const_sections PROGBITS 0xcdcd4 432.0 B ALLOC
13 shell_area PROGBITS 0xcde84 48.0 B ALLOC
14 shell_root_cmds_sections PROGBITS 0xcdeb4 192.0 B ALLOC
15 zephyr_dbg_info PROGBITS 0xcdf74 60.0 B WRITE,ALLOC
16 device_handles PROGBITS 0xcdfb0 66.0 B ALLOC
17 rodata PROGBITS 0xce000 117.0 KiB ALLOC
18 .ramfunc PROGBITS 0x20000000 0.0 B WRITE
19 datas PROGBITS 0x20000000 4.4 KiB WRITE,ALLOC
20 sw_isr_table PROGBITS 0x200011b0 384.0 B WRITE,ALLOC
21 device_states PROGBITS 0x20001330 44.0 B WRITE,ALLOC
22 k_timer_area PROGBITS 0x20001360 168.0 B WRITE,ALLOC
23 k_mem_slab_area PROGBITS 0x20001408 160.0 B WRITE,ALLOC
24 k_heap_area PROGBITS 0x200014a8 24.0 B WRITE,ALLOC
25 k_mutex_area PROGBITS 0x200014c0 220.0 B WRITE,ALLOC
26 k_msgq_area PROGBITS 0x2000159c 52.0 B WRITE,ALLOC
27 k_sem_area PROGBITS 0x200015d0 72.0 B WRITE,ALLOC
28 k_queue_area PROGBITS 0x20001618 84.0 B WRITE,ALLOC
29 _net_buf_pool_area PROGBITS 0x2000166c 468.0 B WRITE,ALLOC
30 net_if_area PROGBITS 0x20001840 8.0 B WRITE,ALLOC
31 net_if_dev_area PROGBITS 0x20001848 28.0 B WRITE,ALLOC
32 net_l2_area PROGBITS 0x20001864 16.0 B ALLOC
33 bss NOBITS 0x20001880 142.1 KiB WRITE,ALLOC
34 noinit NOBITS 0x20025100 81.4 KiB WRITE,ALLOC
35 .comment PROGBITS 0x0 212.1 KiB
36 .debug_aranges PROGBITS 0x0 124.3 KiB
37 .debug_info PROGBITS 0x0 55.0 MiB
38 .debug_abbrev PROGBITS 0x0 1.9 MiB
39 .debug_line PROGBITS 0x0 4.4 MiB
40 .debug_frame PROGBITS 0x0 400.5 KiB
41 .debug_str PROGBITS 0x0 3.7 MiB MERGE,STRINGS
42 .debug_loc PROGBITS 0x0 3.7 MiB
43 .debug_ranges PROGBITS 0x0 730.1 KiB
44 .ARM.attributes ARM_ATTRIBUTES 0x0 54.0 B
45 .symtab SYMTAB 0x0 495.7 KiB
46 .strtab STRTAB 0x0 574.0 KiB
47 .shstrtab STRTAB 0x0 617.0 B
=================================================================================================
So I don't know if I do the correct math but judging form the section output I would assume the following: rodata + rodata_size - rom_start
which would be 913920
. That's at least close to what the linker reports.
The -vv output would be:
[INFO] Considering sections: rom_start, ctors, init_array, zephyr_dbg_info, datas, sw_isr_table, device_states, k_timer_area, k_mem_slab_area, k_heap_area, k_mutex_area, k_msgq_area, k_sem_area, k_queue_area, _net_buf_pool_area, net_if_area, net_if_dev_area, bss, noinit
The -vv output would be:
Is this actually the output for --rom
? This would be strange because the output includes bss
and noinit
, which have NOBITS
so should be filtered out by this line.
Anyway the whole rom/ram guessing algorithm is not reliable, and I think in general it cannot be (as noted here). To get best results just use the -S
/--use-sections
flag and specify section numbers that you got from -P
. From the output it looks like you have two memory areas in the system: 0xc200-0x20000000
and 0x20000000-...
. So you would e.g. use -S
with numbers 1-17.
If elf-size-analyze
still reports too small size, then you could analyze the raw data from readelf --wide --syms your.elf
and nm --portability --line-numbers your.elf
(use binutils for your target, e.g. arm-none-eabi-readelf
). You can find out how these are parsed by elf-size-analyze
here and here.
Is this actually the output for --rom? This would be strange because the output includes bss and noinit, which have NOBITS so should be filtered out by this line.
You are right that was the output for RAM. Sorry my bad.
This here is the output for ROM.
[INFO] Using readelf symbols regex: ^\s*(?P<num>\d+):\s+(?P<value>[0-9a-fA-F]+)\s+(?P<size>(0x)?[0-9A-Fa-f][0-9A-Fa-f]*)\s+(?P<type>\S+)\s+(?P<bind>\S+)\s+(?P<visibility>\S+)\s+(?P<section>\S+)\s+(?P<name>.*)$
[INFO] ignored 20185/31726 symbols
[INFO] Using nm symbols regex: ^(?P<name>\S+)\s+(?P<type>\S+)\s+(?P<value>[0-9a-fA-F]+)\s+(?P<size>[0-9a-fA-F]+)(?P<fileinfo>.*)$
[INFO] Using readelf sections regex: ^\s*\[\s*(?P<num>\d+)\]\s+(?P<name>\S+)\s+(?P<type>\S+)\s+(?P<address>[0-9a-fA-F]+)\s+(?P<offset>[0-9a-fA-F]+)\s+(?P<size>[0-9a-fA-F]+)\s+(?P<entry_size>[0-9a-fA-F]+)\s+(?P<flags>\S*)\s+(?P<link>[0-9a-fA-F]+)\s+(?P<info>[0-9a-fA-F]+)\s+(?P<alignment>[0-9a-fA-F]+)\s*$
[INFO] Considering sections: rom_start, text, .ARM.exidx, initlevel, devices, ctors, init_array, net_socket_register_area, bt_l2cap_fixed_chan_area, bt_gatt_service_static_area, settings_handler_static_area, log_const_sections, shell_area, shell_root_cmds_sections, zephyr_dbg_info, device_handles, rodata, datas, sw_isr_table, device_states, k_timer_area, k_mem_slab_area, k_heap_area, k_mutex_area, k_msgq_area, k_sem_area, k_queue_area, _net_buf_pool_area, net_if_area, net_if_dev_area, net_l2_area
[INFO] Considering sections: rom_start, ctors, init_array, zephyr_dbg_info, datas, sw_isr_table, device_states, k_timer_area, k_mem_slab_area, k_heap_area, k_mutex_area, k_msgq_area, k_sem_area, k_queue_area, _net_buf_pool_area, net_if_area, net_if_dev_area, bss, noinit
I don't know your system, neither I know zephyr well enough, but as I said, you probably want sections 1-17 as your flash memory. The script takes 1-32, which seems wrong looking at memory addresses (the script cannot know about your memory layout). You can use -S 1 2 3 [...] 16 17
to target exactly these sections. And I would guess that the final size mismatch is due to some unnamed symbols that take up space but are not listed by readelf
/nm
.
yep, I do see some unnamed symbols via:
arm-none-eabi-nm --format=sysv zephyr.elf --radix=d -C
Name Value Class Type Size Line Section
|00123684| t | FUNC|00000022| |text
|00107678| t | FUNC|00000004| |text
|00107682| t | FUNC|00000500| |text
|00108182| t | FUNC|00000016| |text
|00108198| t | FUNC|00000048| |text
|00108246| t | FUNC|00000056| |text
|00054036| t | FUNC|00000084| |text
|00108302| t | FUNC|00000052| |text
|00054128| t | FUNC|00000022| |text
|00108354| t | FUNC|00000010| |text
|00054348| t | FUNC|00000110| |text
|00054468| t | FUNC|00000732| |text
|00055228| t | FUNC|00000246| |text
|00055484| t | FUNC|00001278| |text
|00056780| t | FUNC|00000410| |text
|00057204| t | FUNC|00000088| |text
|00057300| t | FUNC|00000192| |text
|00057508| t | FUNC|00000100| |text
|00057624| t | FUNC|00000088| |text
|00057720| t | FUNC|00000374| |text
|00063952| t | FUNC|00000088| |text
|00108700| t | FUNC|00000026| |text
|00108726| t | FUNC|00000034| |text
|00066004| t | FUNC|00000030| |text
|00066040| t | FUNC|00000048| |text
|00066092| t | FUNC|00000080| |text
|00066176| t | FUNC|00000190| |text
|00066376| t | FUNC|00000376| |text
|00108832| t | FUNC|00000010| |text
|00108842| t | FUNC|00000028| |text
|00067524| t | FUNC|00000034| |text
|00108950| t | FUNC|00000026| |text
|00108976| t | FUNC|00000034| |text
|00067572| t | FUNC|00000026| |text
|00067628| t | FUNC|00000028| |text
|00067660| t | FUNC|00000030| |text
|00109038| t | FUNC|00000026| |text
|00109838| t | FUNC|00000008| |text
|00109846| t | FUNC|00000004| |text
|00109850| t | FUNC|00000004| |text
|00109854| t | FUNC|00000004| |text
|00109858| t | FUNC|00000012| |text
|00068448| t | FUNC|00000038| |text
|00068880| t | FUNC|00000192| |text
|00069084| t | FUNC|00000138| |text
|00069228| t | FUNC|00000012| |text
|00069244| t | FUNC|00000096| |text
|00069348| t | FUNC|00000062| |text
|00069420| t | FUNC|00000046| |text
|00109930| t | FUNC|00000006| |text
|00109936| t | FUNC|00000004| |text
|00109940| t | FUNC|00000004| |text
|00109944| t | FUNC|00000006| |text
|00109950| t | FUNC|00000002| |text
|00109952| t | FUNC|00000002| |text
|00109954| t | FUNC|00000004| |text
|00109958| t | FUNC|00000006| |text
|00109964| t | FUNC|00000006| |text
|00109970| t | FUNC|00000006| |text
|00109976| t | FUNC|00000006| |text
|00109982| t | FUNC|00000006| |text
|00109988| t | FUNC|00000004| |text
|00099300| t | FUNC|00000126| |text
|00099432| t | FUNC|00000018| |text
|00099456| t | FUNC|00000038| |text
|00099500| t | FUNC|00000042| |text
|00099548| t | FUNC|00000042| |text
|00099596| t | FUNC|00000044| |text
|00099644| t | FUNC|00000042| |text
|00099692| t | FUNC|00000018| |text
|00099716| t | FUNC|00000038| |text
|00099760| t | FUNC|00000042| |text
|00099808| t | FUNC|00000034| |text
|00099848| t | FUNC|00000032| |text
|00099884| t | FUNC|00000032| |text
|00099920| t | FUNC|00000110| |text
|00100036| t | FUNC|00000034| |text
|00100076| t | FUNC|00000084| |text
|00100164| t | FUNC|00000088| |text
|00100256| t | FUNC|00000034| |text
|00100296| t | FUNC|00000360| |text
|00100660| t | FUNC|00000182| |text
|00120890| t | FUNC|00000020| |text
|00120910| t | FUNC|00000014| |text
|00123644| t | FUNC|00000020| |text
|00123664| t | FUNC|00000020| |text
|00123706| t | FUNC|00000048| |text
|00123754| t | FUNC|00000036| |text
|00123790| t | FUNC|00000072| |text
|00123862| t | FUNC|00000076| |text
|00123938| t | FUNC|00000154| |text
|00124092| t | FUNC|00000022| |text
|00101348| t | FUNC|00000222| |text
|00124114| t | FUNC|00000020| |text
|00124134| t | FUNC|00000028| |text
|00124162| t | FUNC|00000108| |text
|00124270| t | FUNC|00000064| |text
|00124334| t | FUNC|00000062| |text
|00124396| t | FUNC|00000012| |text
|00124408| t | FUNC|00000006| |text
|00124414| t | FUNC|00000040| |text
|00124454| t | FUNC|00000046| |text
|00124500| t | FUNC|00000014| |text
|00124514| t | FUNC|00000076| |text
|00101988| t | FUNC|00000264| |text
|00124590| t | FUNC|00000046| |text
|00124636| t | FUNC|00000074| |text
|00124710| t | FUNC|00000058| |text
|00102252| t | FUNC|00000050| |text
|00102504| t | FUNC|00000024| |text
|00124794| t | FUNC|00000036| |text
|00124830| t | FUNC|00000018| |text
|00124848| t | FUNC|00000034| |text
|00102532| t | FUNC|00000040| |text
|00124882| t | FUNC|00000024| |text
|00102936| t | FUNC|00000022| |text
|00102964| t | FUNC|00000024| |text
|00102992| t | FUNC|00000018| |text
|00103692| t | FUNC|00000008| |text
|00103784| t | FUNC|00000018| |text
|00125152| t | FUNC|00000026| |text
|00125178| t | FUNC|00000034| |text
|00106224| t | FUNC|00000050| |text
|00106280| t | FUNC|00000088| |text
|00106376| t | FUNC|00000076| |text
|00106456| t | FUNC|00000016| |text
|00106476| t | FUNC|00000022| |text
|00106504| t | FUNC|00000030| |text
|00106540| t | FUNC|00000098| |text
|00106656| t | FUNC|00000036| |text
|00106696| t | FUNC|00000030| |text
|00106732| t | FUNC|00000218| |text
|00106968| t | FUNC|00000038| |text
|00107012| t | FUNC|00000108| |text
|00107128| t | FUNC|00000022| |text
|00107156| t | FUNC|00000020| |text
|00107184| t | FUNC|00000032| |text
|00107220| t | FUNC|00000016| |text
|00125276| t | FUNC|00000048| |text
|00107244| t | FUNC|00000012| |text
|00107260| t | FUNC|00000024| |text
|00107288| t | FUNC|00000078| |text
|00107372| t | FUNC|00000046| |text
|00125324| t | FUNC|00000010| |text
|00125334| t | FUNC|00000010| |text
|00107518| t | FUNC|00000160| |text
|00075828| t | FUNC|00000094| |text
|00109992| t | FUNC|00000096| |text
|00110088| t | FUNC|00000096| |text
|00076836| t | FUNC|00000126| |text
|00110264| t | FUNC|00000040| |text
|00076972| t | FUNC|00000092| |text
|00112010| t | FUNC|00000066| |text
|00112076| t | FUNC|00000032| |text
|00113548| t | FUNC|00000012| |text
|00077772| t | FUNC|00000106| |text
|00077888| t | FUNC|00000028| |text
|00077920| t | FUNC|00000096| |text
|00078020| t | FUNC|00000016| |text
|00113634| t | FUNC|00000020| |text
|00078040| t | FUNC|00000014| |text
|00113654| t | FUNC|00000002| |text
|00113684| t | FUNC|00000018| |text
|00113702| t | FUNC|00000018| |text
|00113720| t | FUNC|00000050| |text
|00113770| t | FUNC|00000026| |text
|00113796| t | FUNC|00000092| |text
|00078568| t | FUNC|00000122| |text
|00113888| t | FUNC|00000044| |text
|00113932| t | FUNC|00000028| |text
|00078956| t | FUNC|00000036| |text
|00079004| t | FUNC|00000092| |text
|00079096| t | FUNC|00000090| |text
|00114292| t | FUNC|00000026| |text
|00114318| t | FUNC|00000010| |text
|00079928| t | FUNC|00000022| |text
|00114516| t | FUNC|00000020| |text
|00114536| t | FUNC|00000028| |text
|00080972| t | FUNC|00000012| |text
|00080988| t | FUNC|00000006| |text
|00081000| t | FUNC|00000008| |text
|00081012| t | FUNC|00000008| |text
|00081024| t | FUNC|00000072| |text
|00081100| t | FUNC|00000084| |text
|00081188| t | FUNC|00000034| |text
|00081228| t | FUNC|00000102| |text
|00081336| t | FUNC|00000362| |text
|00081708| t | FUNC|00000180| |text
|00081896| t | FUNC|00000062| |text
|00081968| t | FUNC|00000034| |text
|00082012| t | FUNC|00000052| |text
|00082068| t | FUNC|00000118| |text
|00082192| t | FUNC|00000130| |text
|00082328| t | FUNC|00000014| |text
|00114564| t | FUNC|00000020| |text
|00082348| t | FUNC|00000112| |text
|00082472| t | FUNC|00000378| |text
|00114584| t | FUNC|00000004| |text
|00083720| t | FUNC|00000040| |text
|00083768| t | FUNC|00000034| |text
|00083808| t | FUNC|00000050| |text
|00083864| t | FUNC|00000062| |text
|00083932| t | FUNC|00000072| |text
|00084008| t | FUNC|00000138| |text
|00084152| t | FUNC|00000022| |text
|00084376| t | FUNC|00000088| |text
|00084640| t | FUNC|00000134| |text
|00115778| t | FUNC|00000130| |text
|00116658| t | FUNC|00000142| |text
|00084988| t | FUNC|00000168| |text
|00085432| t | FUNC|00000106| |text
|00085548| t | FUNC|00000182| |text
|00085736| t | FUNC|00000310| |text
|00116804| t | FUNC|00000092| |text
|00086052| t | FUNC|00000020| |text
|00117344| t | FUNC|00000018| |text
|00117362| t | FUNC|00000010| |text
|00117372| t | FUNC|00000016| |text
|00117388| t | FUNC|00000016| |text
|00117404| t | FUNC|00000014| |text
|00117418| t | FUNC|00000070| |text
|00117514| t | FUNC|00000018| |text
|00117532| t | FUNC|00000022| |text
|00117554| t | FUNC|00000016| |text
|00117996| t | FUNC|00000038| |text
|00087088| t | FUNC|00000266| |text
|00087364| t | FUNC|00000192| |text
|00087564| t | FUNC|00000036| |text
|00087604| t | FUNC|00000038| |text
|00118034| t | FUNC|00000006| |text
|00087652| t | FUNC|00000074| |text
|00087736| t | FUNC|00000076| |text
|00118040| t | FUNC|00000006| |text
|00087820| t | FUNC|00000032| |text
|00088236| t | FUNC|00000032| |text
|00088272| t | FUNC|00000044| |text
|00088324| t | FUNC|00000162| |text
|00088496| t | FUNC|00000122| |text
|00088624| t | FUNC|00000222| |text
|00118046| t | FUNC|00000082| |text
|00088856| t | FUNC|00000082| |text
|00088944| t | FUNC|00000240| |text
|00089188| t | FUNC|00000170| |text
|00089368| t | FUNC|00000106| |text
|00089484| t | FUNC|00000070| |text
|00118128| t | FUNC|00000120| |text
|00089560| t | FUNC|00000010| |text
|00118248| t | FUNC|00000022| |text
|00118270| t | FUNC|00000022| |text
|00089576| t | FUNC|00000138| |text
|00089720| t | FUNC|00000030| |text
|00118292| t | FUNC|00000018| |text
|00089776| t | OBJECT|00000004| |text
|00089780| t | OBJECT|00000008| |text
|00089788| t | OBJECT|00000004| |text
|00118498| t | FUNC|00000034| |text
|00118532| t | FUNC|00000048| |text
|00118580| t | FUNC|00000018| |text
|00090576| t | FUNC|00000024| |text
|00119040| t | FUNC|00000004| |text
|00119044| t | FUNC|00000182| |text
|00119226| t | FUNC|00000018| |text
|00119244| t | FUNC|00000012| |text
|00119256| t | FUNC|00000070| |text
|00090604| t | FUNC|00000098| |text
|00090708| t | FUNC|00000222| |text
|00119326| t | FUNC|00000028| |text
|00119354| t | FUNC|00000014| |text
|00119368| t | FUNC|00000182| |text
|00119550| t | FUNC|00000036| |text
|00119586| t | FUNC|00000004| |text
|00119590| t | FUNC|00000056| |text
|00119646| t | FUNC|00000114| |text
|00119760| t | FUNC|00000026| |text
|00119786| t | FUNC|00000148| |text
|00090936| t | FUNC|00000078| |text
|00091020| t | FUNC|00001042| |text
|00092068| t | FUNC|00000014| |text
|00119934| t | FUNC|00000020| |text
|00119954| t | FUNC|00000160| |text
|00120114| t | FUNC|00000200| |text
|00120314| t | FUNC|00000026| |text
|00092088| t | FUNC|00000104| |text
|00120340| t | FUNC|00000280| |text
|00120644| t | FUNC|00000020| |text
|00120800| t | FUNC|00000016| |text
|00120816| t | FUNC|00000022| |text
|00120838| t | FUNC|00000028| |text
|00120866| t | FUNC|00000024| |text
|00093668| t | FUNC|00000064| |text
|00093736| t | FUNC|00000018| |text
|00093760| t | FUNC|00000032| |text
|00093796| t | FUNC|00000108| |text
|00093908| t | FUNC|00000226| |text
|00094140| t | FUNC|00000078| |text
|00094224| t | FUNC|00000102| |text
|00094332| t | FUNC|00000052| |text
|00094388| t | FUNC|00000246| |text
|00094640| t | FUNC|00000042| |text
|00094688| t | FUNC|00000150| |text
|00094848| t | FUNC|00000172| |text
|00095028| t | FUNC|00000138| |text
|00095172| t | FUNC|00000432| |text
|00095608| t | FUNC|00000546| |text
|00096160| t | FUNC|00000354| |text
|00096520| t | FUNC|00000054| |text
|00096580| t | FUNC|00000106| |text
|00096692| t | FUNC|00000174| |text
|00096872| t | FUNC|00000150| |text
|00097028| t | FUNC|00000066| |text
|00097100| t | FUNC|00000088| |text
|00097192| t | FUNC|00000168| |text
|00097364| t | FUNC|00000168| |text
|00097536| t | FUNC|00000078| |text
|00097620| t | FUNC|00000042| |text
|00097668| t | FUNC|00000214| |text
|00097888| t | FUNC|00000106| |text
|00098000| t | FUNC|00000038| |text
|00098044| t | FUNC|00000040| |text
|00098088| t | FUNC|00000064| |text
|00098156| t | FUNC|00000026| |text
|00098188| t | FUNC|00000210| |text
|00098404| t | FUNC|00000320| |text
|00098728| t | FUNC|00000044| |text
|00098776| t | FUNC|00000010| |text
|00098792| t | FUNC|00000034| |text
|00098832| t | FUNC|00000046| |text
|00098884| t | FUNC|00000226| |text
|00099116| t | FUNC|00000180| |text
according to my "awk" expression awk -F'|' '{sum+=$5;}END{print sum;}'
this are 27646
bytes. Anyway I guess I would also need to spend more time to understand all that.
Hi,
first of all thanks for the great alternative to size_report. But it seems that the reported size is not correct. For my elf file I have the following data points:
Linker output:
The size_report --rom version reports me
920047
and your tool prints816200
. Unfortunately I cannot share the reports and don't really know how to help further to pin down the problem.