Hello everyone, I am Pi Zi Heng, a serious technical guy. Today, I will talk about disassembly files in embedded development (.s, .lst, .dump).
In the fourth, fifth, and sixth lessons, I introduced three types of output files generated by the compiler/linker (relocatable, map, executable files). These three files focus on how the compiled/linked code is distributed in binary data storage. If you want to know what the machine code corresponding to the binary data means, what should you do? The disassembly files I will introduce today will give you the answer.
1. Standard Assembly Source File
When compiling with IAR, a .s file will be generated in D:\myProject\bsp\builds\demo\Release\List, and each relocatable file corresponds to a .s file, which is the assembly file obtained after the compiler assembles the C source file. Taking task.c as an example, the assembly generated is task.s:
The task.s file is a line-by-line assembly translation of the task.c file using assembly language. Below is just the assembly code of the normal_task() function. If you wish, you can directly replace task.c with this task.s file in your project; the functionality will be the same.
SECTION `.text`:CODE:NOROOT(1)
CFI Block cfiBlock0 Using cfiCommon0
CFI Function normal_task
CFI NoCalls
THUMB
// 17 void normal_task(void)
// 18 {
// 19 s_variable0 *= 2;
normal_task:
LDR R0,??DataTable1
LDR R0,[R0, #+0]
MOVS R1,#+2
MULS R0,R1,R0
LDR R1,??DataTable1
STR R0,[R1, #+0]
// 20 }
BX LR ;; return
CFI EndBlock cfiBlock0
// 21
The task.s file will also provide the total size of the objects in each section.
// 20 bytes in section .bss
// 4 bytes in section .data
// 4 bytes in section .noinit
// 86 bytes in section .text
// 16 bytes in section .textrw
//
// 102 bytes of CODE memory
// 28 bytes of DATA memory
2. Intermediate Assembly List File
When compiling with IAR, a .lst file will be generated in D:\myProject\bsp\builds\demo\Release\List, and each relocatable file corresponds to a .lst file, which is a supplementary information file for the assembly file obtained after the compiler assembles the C source file. Continuing with the task.c assembly generated task.lst as an example:
The task.lst file adds machine code translation information for the assembly instructions based on task.s, where 0x…. indicates that the file has not undergone global linking, so the machine code cannot be determined.
\ In section .text, align 2, keep-with-next
17 void normal_task(void)
18 {
19 s_variable0 *= 2;
\ normal_task: (+1)
\ 00000000 0x.... LDR R0,??DataTable1
\ 00000002 0x6800 LDR R0,[R0, #+0]
\ 00000004 0x2102 MOVS R1,#+2
\ 00000006 0x4348 MULS R0,R1,R0
\ 00000008 0x.... LDR R1,??DataTable1
\ 0000000A 0x6008 STR R0,[R1, #+0]
20 }
\ 0000000C 0x4770 BX LR ;; return
21
The task.lst file also provides an analysis of the maximum stack usage and the specific size of each object.
Maximum stack usage in bytes:
.cstack Function
------- --------
24 heap_task
24 -> __aeabi_memcpy
24 -> __aeabi_memset
24 -> free
24 -> malloc
0 normal_task
0 ram_task
Section sizes:
Bytes Function/Label
----- --------------
4 ??DataTable1
4 ??DataTable1_1
4 ??DataTable1_2
60 heap_task
4 n_variable1
14 normal_task
16 ram_task
16 s_array
4 s_variable0
4 s_variable2
3. Complete Assembly Dump File
The dump file is a collection of all list files and is a line-by-line assembly translation of the entire image file’s machine code data. Still taking normal_task() in task.c as an example, in the list file we see some unknown machine code 0x…., while in the dump file, this part of the machine code is filled with the actual machine code. With the dump file, we can interpret and analyze the entire project from an assembly perspective.
// s_variable0 *= 2;
$t:
`.text12`:
normal_task:
0xcc: 0x4812 LDR.N R0, `.text_8` ; `.data$$Limit`
0xce: 0x6800 LDR R0, [R0]
0xd0: 0x2102 MOVS R1, #2
0xd2: 0x4348 MULS R0, R1, R0
0xd4: 0x4910 LDR.N R1, `.text_8` ; `.data$$Limit`
0xd6: 0x6008 STR R0, [R1]
// }
0xd8: 0x4770 BX LR
4. Generating Dump Files Using ielfdumparm.exe
Dump files are not generated by default, but IAR provides a tool to help us generate dump files, called ielfdumparm.exe.
Location: \IAR Systems\Embedded Workbench xxx\arm\bin\ielfdumparm.exe
Usage: ielfdumparm.exe --source --code demo.elf -o demo.dump
Thus, I have introduced the disassembly files in embedded development (.s, .lst, .dump). Where’s the applause~~~