]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: ld:Report an error when seeing an unrecognized relocation
authorLulu Cai <cailulu@loongson.cn>
Thu, 21 Mar 2024 07:16:05 +0000 (15:16 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Mon, 11 Nov 2024 03:46:20 +0000 (11:46 +0800)
If we generate an object file using an assembler with the new
relocations added, and then linking those files with an older
linker, the link will still complete and the linked file will
be generated.
In this case we should report an error instead of continuing
the linking process.

(cherry picked from commit 5966e2eb3fed61ebe5c091a074b368b9238a68c1)

bfd/elfnn-loongarch.c

index b0f9b6ec69e01a1b5ec8129b303138eb00663d5a..25c0ac988743cc45985e02489e9be2e6887de6c6 100644 (file)
@@ -2304,9 +2304,14 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
       bfd_vma relocation, off, ie_off;
       int i, j;
 
+      /* When an unrecognized relocation is encountered, which usually
+        occurs when using a newer assembler but an older linker, an error
+        should be reported instead of continuing to the next relocation.  */
       howto = loongarch_elf_rtype_to_howto (input_bfd, r_type);
-      if (howto == NULL || r_type == R_LARCH_GNU_VTINHERIT
-         || r_type == R_LARCH_GNU_VTENTRY)
+      if (howto == NULL)
+       return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
+
+      if (r_type == R_LARCH_GNU_VTINHERIT || r_type == R_LARCH_GNU_VTENTRY)
        continue;
 
       /* This is a final link.  */