Home | Projects | Notes > ARM Cortex-M3/M4 Processor > ELF File Analysis
ELF stands for Executable and Linkable Format.
It is important to be able to analyze the final ELF file to understand various resource allocations.
ELF file is essentially a collection of all necessary sections; .text, .data, .bss, etc.
When doing bare-metal programming, you need to check if all the sections are placed at appropriate absolute addresses.
There are many ways in which you can analyze an ELF file such as using tools like objdump, readelf, etc.
You can also instruct the linker to create a special file called the memory map file (a.k.a. map file). A map file is useful in analyzing various resource allocations and placements in memory.
To create a map file, you need to add the linker flag -Map=<filename>.map when running arm-none-eabi-gcc or arm-none-eabi-ld.
Sometimes, linker specific flags may not be recognized when running arm-none-eabi-gcc. For such case, prepend -Wl, to -Map=<filename>.map. (i.e., -Wl,-Map=<filename>.map)
Map file example:
xxxxxxxxxx631
2Memory Configuration3
4Name Origin Length Attributes5FLASH 0x0000000008000000 0x0000000000100000 xr6SRAM 0x0000000020000000 0x0000000000020000 xrw 7*default* 0x0000000000000000 0xffffffffffffffff8
9Linker script and memory map 10
11LOAD main.o12LOAD led.o13LOAD stm32_startup.o14
15.text 0x0000000008000000 0x76616 *(.isr_vector)17 .isr_vector 0x0000000008000000 0x188 stm32_startup.o18 0x0000000008000000 vectors19 *(.text)20 .text 0x0000000008000188 0x4d0 main.o21 0x0000000008000188 main22 0x00000000080001b4 idle_task23 0x00000000080001ba task1_handler24 0x00000000080001dc task2_handler25 0x00000000080001fe task3_handler26 0x000000000800021c task4_handler27 0x000000000800023a init_systick_timer28 0x00000000080002a8 init_scheduler_stack29 0x00000000080002b2 init_tasks_stack30 0x00000000080003cc update_next_task31 0x0000000008000454 get_psp_value32 0x0000000008000474 save_psp_value33 0x000000000800049c switch_sp_to_psp34 0x00000000080004b6 enable_processor_faults35 0x00000000080004f4 schedule36 0x0000000008000518 task_delay37 0x0000000008000578 PendSV_Handler38 0x000000000800059e update_global_tick_count39 0x00000000080005b8 unblock_tasks40 0x0000000008000618 SysTick_Handler41 0x0000000008000644 HardFault_Handler42 0x000000000800064a MemManage_Handler43 0x0000000008000650 BusFault_Handler44 .text 0x0000000008000658 0xfc led.o45 0x0000000008000658 delay46 0x0000000008000680 led_init_all47 0x00000000080006f4 led_on48 0x0000000008000724 led_off49 .text 0x0000000008000754 0x12 stm32_startup.o50 0x0000000008000754 RTC_Alarm_IRQHandler51 0x0000000008000754 HASH_RNG_IRQHandler52 0x0000000008000754 EXTI2_IRQHandler53 0x0000000008000754 TIM8_CC_IRQHandler54
55...56
57 0x0000000008000754 DMA2_Stream6_IRQHandler58 0x0000000008000754 DMA1_Stream3_IRQHandler59 0x000000000800075a Reset_Handler60 *(.rodata)61 0x0000000008000766 _etext = .62
63
L15:
.textsection begins at 0x08000000correct! L17: The first object placed in the
.textsection is the vector table and it comes from the file "stm32_startup.o".correct! L20: Next up is the
.textsection of the "main.o" file and its size is 0x4d0.L44: Next up is the
.textsection of the "led.o"L60:
.rodatasection is empty since we don't have any constant data in our project.L61: End of
.textsection is the start of.datasection. (i.e.,_etext=_sdata)Padding will be introduced by the linker if necessary when the section start address is not word-aligned and will be marked with something like
*fill*. However, the linker does not care about the word-alignment of the section ending. To make sure that we word-align the end of each section for the section that will come immediately after the current section, useALIGNcommand.xxxxxxxxxx121SECTIONS2{3.text :4{5*(.isr_vector)6*(.text)7*(.rodata)8. = ALIGN(4); /* assigning 4-byte word-aligned address to the location counter */9_etext = .;10}> FLASH11...12}ALIGN(4) forces 4-byte word boundary alignment.
Nayak, K. (2022). Embedded Systems Programming on ARM Cortex-M3/M4 Processor [Video file]. Retrieved from https://www.udemy.com/course/embedded-system-programming-on-arm-cortex-m3m4/