Skip to content

Commit

Permalink
[efi] Ignore new LoongArch PC-relative relocations and relaxations
Browse files Browse the repository at this point in the history
Several new relocations types have been added in LoongArch ABI version
2.10.  In particular:

- R_LARCH_B16 (18-bit PC-relative jump)
- R_LARCH_B21 (23-bit PC-relative jump)
- R_LARCH_PCREL20_S2 (22-bit PC-relative offset)

Also relocation relaxations have been introduced.  Recent GCC (13.2)
and binutils 2.41+ use these types of relocations, which confuses
elf2efi tool.  As a result, iPXE EFI images for LoongArch fail to
build with the following error:

  Unrecognised relocation type 103

Fix by ignoring R_LARCH_B{16,21} and R_LARCH_PCREL20_S2 (as with other
PC-relative relocations), and by ignoring relaxations (R_LARCH_RELAX).
Relocation relaxations are basically optimizations: ignoring them
results in a correct binary (although it might be suboptimal).

This mirrors iPXE commit ee6185d ("[efi] Ignore new LoongArch
PC-relative relocations and relaxations").

Modified-by: Michael Brown <[email protected]>
Signed-off-by: Michael Brown <[email protected]>
  • Loading branch information
asheplyakov authored and mcb30 committed Feb 22, 2024
1 parent 47f6298 commit 7f57dc3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/elf2efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@
#ifndef R_LARCH_64
#define R_LARCH_64 2
#endif
#ifndef R_LARCH_B16
#define R_LARCH_B16 64
#endif
#ifndef R_LARCH_B21
#define R_LARCH_B21 65
#endif
#ifndef R_LARCH_B26
#define R_LARCH_B26 66
#endif
Expand All @@ -155,6 +161,12 @@
#ifndef R_LARCH_GOT_PC_LO12
#define R_LARCH_GOT_PC_LO12 76
#endif
#ifndef R_LARCH_RELAX
#define R_LARCH_RELAX 100
#endif
#ifndef R_LARCH_PCREL20_S2
#define R_LARCH_PCREL20_S2 103
#endif
#ifndef R_X86_64_GOTPCRELX
#define R_X86_64_GOTPCRELX 41
#endif
Expand Down Expand Up @@ -849,16 +861,24 @@ static void process_reloc ( struct elf_file *elf, const Elf_Shdr *shdr,
case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST32_ABS_LO12_NC ) :
case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST64_ABS_LO12_NC ) :
case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST128_ABS_LO12_NC ) :
case ELF_MREL ( EM_LOONGARCH, R_LARCH_B16):
case ELF_MREL ( EM_LOONGARCH, R_LARCH_B21):
case ELF_MREL ( EM_LOONGARCH, R_LARCH_B26):
case ELF_MREL ( EM_LOONGARCH, R_LARCH_PCALA_HI20 ):
case ELF_MREL ( EM_LOONGARCH, R_LARCH_PCALA_LO12 ):
case ELF_MREL ( EM_LOONGARCH, R_LARCH_GOT_PC_HI20 ):
case ELF_MREL ( EM_LOONGARCH, R_LARCH_GOT_PC_LO12 ):
case ELF_MREL ( EM_LOONGARCH, R_LARCH_PCREL20_S2 ):
/* Skip PC-relative relocations; all relative
* offsets remain unaltered when the object is
* loaded.
*/
break;
case ELF_MREL ( EM_LOONGARCH, R_LARCH_RELAX ):
/* Relocation can be relaxed (optimized out).
* Ignore it for now.
*/
break;
case ELF_MREL ( EM_X86_64, R_X86_64_32 ) :
/* Ignore 32-bit relocations in a hybrid
* 32-bit BIOS and 64-bit UEFI binary,
Expand Down

0 comments on commit 7f57dc3

Please sign in to comment.