bfd: Delete R_LARCH_NONE from dyn info of LoongArch.
authorliuzhensong <liuzhensong@loongson.cn>
Wed, 20 Jul 2022 11:55:27 +0000 (19:55 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Mon, 25 Jul 2022 01:59:08 +0000 (09:59 +0800)
  Some R_LARCH_64 in section .eh_frame will to generate
  R_LARCH_NONE, we change relocation to R_LARCH_32_PCREL
  from R_LARCH_64 in setction .eh_frame and not generate
  dynamic relocation for R_LARCH_32_PCREL.

  Add New relocate type R_LARCH_32_PCREL for .eh_frame.

  include/elf/
    loongarch.h

  bfd/
    bfd/bfd-in2.h
    libbfd.h
    reloc.c
    elfxx-loongarch.c
    elfnn-loongarch.c

  gas/config/
    tc-loongarch.c

  binutils/
    readelf.c

  ld/testsuite/ld-elf/
    eh5.d

bfd/bfd-in2.h
bfd/elfnn-loongarch.c
bfd/elfxx-loongarch.c
bfd/libbfd.h
bfd/reloc.c
binutils/readelf.c
include/elf/loongarch.h
ld/testsuite/ld-elf/eh5.d

index 91e6ad76b9a3825371f6aa5ead9843c4bbf33b60..2d6e1bbc0b0531d32a284583ce9fa1aad5921767 100644 (file)
@@ -6309,6 +6309,7 @@ assembler and not (currently) written to any object files.  */
   BFD_RELOC_LARCH_TLS_LD_HI20,
   BFD_RELOC_LARCH_TLS_GD_PC_HI20,
   BFD_RELOC_LARCH_TLS_GD_HI20,
+  BFD_RELOC_LARCH_32_PCREL,
   BFD_RELOC_LARCH_RELAX,
   BFD_RELOC_UNUSED };
 
index 3d86e1422af0a0d21c6acd0e0454ee02b63480c5..4efe3d9370c93b8b55b6f4ca9ff56c778cad3026 100644 (file)
@@ -2010,6 +2010,17 @@ perform_relocation (const Elf_Internal_Rela *rel, asection *input_section,
       bfd_put (bits, input_bfd, opr1 - value, contents + rel->r_offset);
       break;
 
+    /* For eh_frame and debug info.  */
+    case R_LARCH_32_PCREL:
+      value -= sec_addr (input_section) + rel->r_offset;
+      value += rel->r_addend;
+      bfd_vma word = bfd_get (howto->bitsize, input_bfd,
+                             contents + rel->r_offset);
+      word = (word & ~howto->dst_mask) | (value & howto->dst_mask);
+      bfd_put (howto->bitsize, input_bfd, word, contents + rel->r_offset);
+      r = bfd_reloc_ok;
+      break;
+
     /* New reloc type.
        R_LARCH_B16 ~ R_LARCH_TLS_GD_HI20.  */
     case R_LARCH_B16:
index f059f1a0c05687981aa3d680c42baf5952fc0274..0b00df556b74984a084eb016ca3947856e59984c 100644 (file)
@@ -1327,7 +1327,24 @@ static loongarch_reloc_howto_type loongarch_howto_table[] =
         reloc_bits,                            /* adjust_reloc_bits */
         "gd_hi20"),                            /* larch_reloc_type_name */
 
-  LOONGARCH_HOWTO (R_LARCH_RELAX,              /* type (99).  */
+  LOONGARCH_HOWTO (R_LARCH_32_PCREL,           /* type (99).  */
+        0,                                     /* rightshift.  */
+        4,                                     /* size.  */
+        32,                                    /* bitsize.  */
+        true,                                  /* pc_relative.  */
+        0,                                     /* bitpos.  */
+        complain_overflow_dont,                /* complain_on_overflow.  */
+        bfd_elf_generic_reloc,                 /* special_function.  */
+        "R_LARCH_32_PCREL",                    /* name.  */
+        false,                                 /* partial_inplace.  */
+        0,                                     /* src_mask */
+        0xffffffff,                            /* dst_mask */
+        false,                                 /* pcrel_offset */
+        BFD_RELOC_LARCH_32_PCREL,              /* bfd_reloc_code_real_type */
+        NULL,                                  /* adjust_reloc_bits */
+        NULL),                                 /* larch_reloc_type_name */
+
+  LOONGARCH_HOWTO (R_LARCH_RELAX,              /* type (100).  */
         0,                                     /* rightshift */
         1,                                     /* size */
         0,                                     /* bitsize */
index 7eaa75ad11e54a7cbecd732f22e4967bd6e532d0..c766722efb0e08d430b95696a2b1f3102c0078ed 100644 (file)
@@ -3492,6 +3492,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_LARCH_TLS_LD_HI20",
   "BFD_RELOC_LARCH_TLS_GD_PC_HI20",
   "BFD_RELOC_LARCH_TLS_GD_HI20",
+  "BFD_RELOC_LARCH_32_PCREL",
   "BFD_RELOC_LARCH_RELAX",
  "@@overflow: BFD_RELOC_UNUSED@@",
 };
index 59c2aaa0d316aa2a8422c0be4874eaee4d56eee3..268e4b13049d7695c20e56618cc7bc8435f6b6e7 100644 (file)
@@ -8304,6 +8304,9 @@ ENUMX
 ENUMX
   BFD_RELOC_LARCH_TLS_GD_HI20
 
+ENUMX
+  BFD_RELOC_LARCH_32_PCREL
+
 ENUMX
   BFD_RELOC_LARCH_RELAX
 
index 6b7692d9dd5eabf9b2372c0fd1a7d5e4bfa288d8..4a3e448e30d1ced4f887f307747365f9e286bd0c 100644 (file)
@@ -14389,6 +14389,8 @@ is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
     case EM_AVR_OLD:
     case EM_AVR:
       return reloc_type == 36; /* R_AVR_32_PCREL.  */
+    case EM_LOONGARCH:
+      return reloc_type == 99;  /* R_LARCH_32_PCREL.  */
     case EM_MICROBLAZE:
       return reloc_type == 2;  /* R_MICROBLAZE_32_PCREL.  */
     case EM_OR1K:
index 2d2bb6a51612311fb90f36213a7b9e56ac1adae3..74757b82ca8c05fc81240e96c601547fe0e45726 100644 (file)
@@ -223,8 +223,11 @@ RELOC_NUMBER (R_LARCH_TLS_GD_PC_HI20, 97)
    %gd_hi20 (sym).  */
 RELOC_NUMBER (R_LARCH_TLS_GD_HI20, 98)
 
+/* For eh_frame and debug info.  */
+RELOC_NUMBER (R_LARCH_32_PCREL, 99)
+
 /* RELAX.  */
-RELOC_NUMBER (R_LARCH_RELAX, 99)
+RELOC_NUMBER (R_LARCH_RELAX, 100)
 
 END_RELOC_NUMBERS (R_LARCH_count)
 
index d614251587c10efce06eeea97b9c5450cbcaa7eb..4a69748235587f5484aeec6f2d56eaa59f2e64bb 100644 (file)
@@ -4,7 +4,7 @@
 #ld:
 #readelf: -wf
 #target: [check_as_cfi]
-#xfail: alpha-*-*ecoff hppa64-*-* tile*-*-* visium-*-* loongarch64-*-*
+#xfail: alpha-*-*ecoff hppa64-*-* tile*-*-* visium-*-*
 
 Contents of the .eh_frame section: