binutils Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
binutils/ld

LoongArch: Fix linker relaxation alignment

LoongArch linker correctly updates section output offsets during relaxation to maintain alignment.

This commit resolves alignment issues in the LoongArch linker related to relaxation. Previously, the output_offset of a section was updated during relaxation without considering alignment requirements. The fix ensures that the output_offset is correctly updated by the align_power function, thus preserving section alignment.

In Details

The bfd/elfnn-loongarch.c file is updated to fix how linker relaxation affects section alignment. The problematic lines that unconditionally updated sec->output_offset without accounting for alignment have been removed. Instead, the align_power function (or similar alignment logic) is implicitly or explicitly relied upon to manage the output_offset correctly, ensuring that sections remain properly aligned after relaxation, even when linking multiple objects.

For Context
LoongArch
A RISC-based instruction set architecture developed in China.
linker relaxation
A linker optimization technique where the linker adjusts instruction offsets for branches and calls after the initial pass, potentially improving code density or enabling features like Position-Independent Code (PIC).
output_offset
The offset of a section within its output section in the final linked object or executable.
align_power
A function or mechanism within the linker that ensures a memory address or section is aligned to a power of two boundary.
Filed Under: binutilsldloongarchlinkeralignment