binutils Newspaper
JULY 29, 2026
avr Proposed

AVR: Sort .text.* input sections by their name.

Patch to sort AVR .text.* input sections by name to improve code locality.

This patch modifies the AVR linker script to sort .text.* input sections by their name. The goal is to increase code locality, specifically to prevent functions from libgcc and AVR-LibC that are related and residing in separate .text.* sections from being placed far apart in the final executable. This ordering aims to improve performance by keeping related code closer together.

In Details

This patch adds the SORT(.text.*) directive to the linker script for the AVR target. This ensures that sections like .text.libgcc.mul are grouped together, improving instruction cache utilization and potentially reducing instruction fetch overhead by minimizing the distance between related code blocks.

For Context
.text section
A section in an object file or executable that contains the executable code of a program.
Input section
A section from an input object file that is being processed by the linker.
Code locality
The principle that program instructions that are close to each other in memory are likely to be executed close to each other in time. Improving code locality can lead to better cache performance.
libgcc
The GCC runtime library, which provides support functions for the GCC compiler, such as functions for arithmetic operations that cannot be efficiently implemented in machine code.
AVR-LibC
A C library specifically designed for the AVR microcontroller architecture.
Linker script
A script used by the linker to control how sections from input object files are combined into sections in the output file and where they are placed in memory.
Filed Under: avrlinkeroptimizationcode locality