LoongArch: fix .got.plt dislocation in static PDE
Fixes an issue in LoongArch's ELF linker where .got.plt entries are misaligned in static Position-Dependent Executables (PDE).
This patch addresses a bug in the LoongArch ELF linker where the calculation of .got.plt entry addresses was incorrect for static Position-Dependent Executables (PDE). The code incorrectly assumed the presence of two .got.plt entries reserved for ld.so, which do not exist in static PDE, leading to a two-slot dislocation of all .got.plt entries. This error, latent in earlier releases, became exploitable in 2.47.
- proposer
Submits a patch to correct the calculation of .got.plt entry addresses for static Position-Dependent Executables (PDE) in LoongArch, resolving a dislocation issue.
“The code path handling R_LARCH_GOT{64*,{,_PC}_LO12} miscalculated the address of the .got.plt entry: it always counted the two .got.plt entries reserved for ld.so, but in static PDE those two entries do not exist (as in static PDE the PLT is solely for ifunc). Thus all .got.plt entries dislocated for two slots. Fix the issue by factoring out the correct .got.plt entry addressing logic handling…”
In Details
The LoongArch ELF linker has a bug in calculating addresses for .got.plt entries when generating static Position-Dependent Executables (PDE). Specifically, the code incorrectly accounts for reserved ld.so entries in .got.plt, causing a shift. This patch corrects the addressing logic by factoring out common code for R_LARCH_GOT and R_LARCH_GOT_HI20 relocations.
- .got.plt
- A section in ELF executables that holds addresses for Procedure Linkage Table (PLT) entries, used for dynamic linking.
- PDE
- Position-Dependent Executable, a type of executable that is linked at a fixed base address and may not be safely relocated.
- static PDE
- A statically linked executable that is position-dependent. In this context, it implies the absence of runtime dynamic linking components like ld.so's .got.plt entries.
- ifunc
- Indirect function, a mechanism in ELF for resolving function symbols at runtime, often used for optimized or hardware-specific implementations.
- R_LARCH_GOT_PC_HI20
- A LoongArch relocation type used to address global offset table (GOT) entries relative to the program counter.