LoongArch: Fix Relaxation Alignment with ld -r
This patch fixes an alignment issue in LoongArch when using `ld -r` by adding an align section and relocation.
This patch fixes an issue in LoongArch where section alignment could be incorrect when using ld -r (partial linking). The problem occurs because section alignment can’t be adjusted for objects generated by ld -r, and if previous sections are relaxed, subsequent sections may be misaligned. The fix involves adding an align section and an align relocation before each section when ld -r is used and disabling the default section start address calculation. This approach mirrors a fix already implemented in ld.lld.
In Details
This patch addresses a relaxation alignment issue in the LoongArch port of the GNU linker (ld) when performing relocatable linking (ld -r). Relaxation refers to the linker's ability to optimize instruction sequences by replacing them with shorter or more efficient ones. The problem arises because the alignment of sections is not correctly maintained during relaxation when using ld -r, leading to potential misalignment issues in the final linked object. The solution involves inserting alignment sections and relocations to ensure proper section alignment.
For Context
This patch fixes a bug in the Binutils linker (ld) for the LoongArch architecture. The bug occurs when using a feature called "relaxation" during a partial linking process (ld -r). Relaxation is an optimization technique where the linker modifies instructions to improve performance or reduce code size. The bug can cause the alignment of code and data within the program to be incorrect, which can lead to crashes or unexpected behavior. The patch ensures that the alignment is correct, preventing these issues.