Meaning
Alignment directive in a configuration file that forces a memory address to land on a specific multiple. Any implementation of linker script memory alignment ensures that a variable or a code section starts at a boundary required by the hardware. This is common for interrupt vector tables that must be placed on a 128-byte or 256-byte boundary.
Without this directive, the linker might place the data at the next available byte, causing the processor to ignore the table.
Performance Efficiency
Optimization that reduces the number of bus cycles required to access a data structure. When linker script memory alignment places a 32-bit variable on a four-byte boundary, the processor can fetch the entire value in a single transaction. Accessing unaligned data often requires two bus cycles and additional logic to combine the fragments.
This efficiency is especially noticeable in high-speed communication loops where every clock cycle affects the total throughput.
Hardware Requirement
Strict boundary condition imposed by memory protection units or peripheral controllers. Many direct memory access controllers require that the source and destination buffers use a linker script memory alignment of at least four or eight bytes. If the buffer is not aligned, the hardware may trigger a bus fault or perform an incorrect data transfer.
Engineers use specific alignment keywords like ALIGN in the script to satisfy these physical constraints.
Padding Impact
Consequence of forcing data to specific addresses within the memory map. When linker script memory alignment moves a section to a new boundary, the gap between the end of the previous section and the new start is filled with padding bytes. These bytes consume space in both flash and ram without performing any function.
In memory-constrained systems, excessive use of large alignments can lead to significant waste. This waste is often called internal fragmentation. It occurs because the linker cannot place other data into the gap created by the alignment requirement.
If a system has many small sections each requiring 256-byte alignment, the total size of the binary can grow much faster than the actual code size. Monitoring the map file generated by the linker helps to identify these gaps and minimize their effect on the final product.