This post explores how GNU Assembler and LLVM integrated assembler generate relocations, an important step to generate a relocatable file. Relocations identify parts of instructions or data that canno| MaskRay
Problem statement I recently came across a situation in a project where I had the following code: 1 2 3 4 5 6 7 8 9 10 struct FaultInfo final { uint32_t r0; uint32_t r1; // And all the other register state of a Cortex-M0+ processor // ... uint32_t crc; }; [[gnu::section(".uninit")]] volatile FaultInfo fault_data; I was using this static region of data to persist some fault information across reboots, to log it on the next boot after recovering from the fault.| AllThingsEmbedded
Updated in 2022-09. Background: -fno-pic can only be used by executables. On most platforms and architectures, direct access relocations are used to reference external data symbols. -fpic can be used| MaskRay
Updated in 2024-01. Branch target Many architectures encode a branch/jump/call instruction with PC-relative addressing, i.e. the distance to the target is encoded in the instruction. In an executable| MaskRay
Updated in 2025-05. Symbol address In an executable or shared object (called a component in ELF), a text section may need the absolute virtual address of a symbol (e.g. a function or a variable). The| MaskRay
Updated in 2025-02. Thread-local storage (TLS) provides a mechanism allocating distinct objects for different threads. It is the usual implementation for GCC extension __thread, C11 _Thread_local, and| MaskRay
GNU ld's output section layout is determined by a linker script, which can be either internal (default) or external (specified with -T or -dT). Within the linker script, SECTIONS commands define how i| MaskRay
Updated in 2024-02. (In celebration of my 2800th llvm-project commit) Happy Halloween! This article describes relative relocations and how the RELR format can greatly decrease file sizes. An ELF linke| MaskRay
Updated in 2024-04. GNU indirect function (ifunc) is a mechanism making a direct function call resolve to an implementation picked by a resolver. It is mainly used in glibc but has adoption in FreeBSD| MaskRay
This article describes SHF_ALLOC|SHF_COMPRESSED sections in ELF and lld's linker option --compress-sections to compress arbitrary sections.| MaskRay