]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Ignore new LoongArch PC-relative relocations and relaxations 1160/head
authorAlexey Sheplyakov <asheplyakov@basealt.ru>
Wed, 21 Feb 2024 09:07:21 +0000 (13:07 +0400)
committerMichael Brown <mcb30@ipxe.org>
Thu, 22 Feb 2024 14:40:53 +0000 (14:40 +0000)
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).

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/util/elf2efi.c

index 88713b6636f15e2230557e889ebf2dcde84164e6..4af587d876031ebea7c8d8f58bca26995aa98cf5 100644 (file)
 #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
 #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
@@ -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,