In computing, the Executable and Linkable Format is a common standard file format for executable files, object code, shared libraries, and core dumps.

The final step in creating an ELF file is linking. The cross compiling GCC groups all the object files together and resolves the dependencies among symbols. The linker, invoked with a custom script, replaces the default memory layout with the specified script. This script - a linker script - defines memory sections in the target and guides the placement of symbols in the correct sections. Linker scripts are identifiable by their .ld extensions; the ultimate goal is to organise symbols from compiled objects into sections within the final executable image.

Creating custom sections

The linker ensures a single instance of each symbol in the final executable, often without attributes. This facilitates including different object files, allowing varied implementations of the same functionality for writing portable code across targets. Custom sections in ELF descriptions can store symbols at fixed addresses, useful for scenarios like storing data at the start of a flash page, uploaded separately from the software—common for target-specific settings. It is simple to add a section attribute when defining a symbol:

const uint8_t
__attribute__((section(".keys")))
private_key[KEY_SIZE] = {0};

Note that keys requires its own entry in the linker script.

Tags: Scheduling