]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: Fix incorrect display of FDEs address ranges when using objdump -Wf
authorLulu Cai <cailulu@loongson.cn>
Tue, 26 Aug 2025 09:19:47 +0000 (17:19 +0800)
committercailulu <cailulu@loongson.cn>
Tue, 2 Sep 2025 03:02:33 +0000 (11:02 +0800)
When parsing FDEs in `.eh_frame` using `objdump -Wf`, it is necessary to
resolve `BFD_RELOC_LARCH_32_PCREL` to determine the address ranges of
the FDEs. Set the `pcrel_offset` field of `BFD_RELOC_LARCH_32_PCREL` to
help `objdump` correctly compute the address ranges of the FDEs.

Apply the same modification to BFD_RELOC_LARCH_64_PCREL.

bfd/elfxx-loongarch.c
gas/testsuite/gas/loongarch/dwarf-regnum.d
gas/testsuite/gas/loongarch/frame_pc.d [new file with mode: 0644]
gas/testsuite/gas/loongarch/frame_pc.s [new file with mode: 0644]

index 6268c477feb176d0442407efe7625c356424f3a1..0b030d39aa9dd8e01d6ea846abe1dbeae8b6c5f9 100644 (file)
@@ -1388,7 +1388,7 @@ static loongarch_reloc_howto_type loongarch_howto_table[] =
         false,                                 /* partial_inplace.  */
         0,                                     /* src_mask */
         0xffffffff,                            /* dst_mask */
-        false,                                 /* pcrel_offset */
+        true,                                  /* pcrel_offset */
         BFD_RELOC_LARCH_32_PCREL,              /* bfd_reloc_code_real_type */
         reloc_sign_bits,                       /* adjust_reloc_bits */
         NULL),                                 /* larch_reloc_type_name */
@@ -1580,7 +1580,7 @@ static loongarch_reloc_howto_type loongarch_howto_table[] =
         false,                                 /* partial_inplace.  */
         0,                                     /* src_mask */
         0xffffffffffffffff,                    /* dst_mask */
-        false,                                 /* pcrel_offset */
+        true,                                  /* pcrel_offset */
         BFD_RELOC_LARCH_64_PCREL,              /* bfd_reloc_code_real_type */
         NULL,                                  /* adjust_reloc_bits */
         NULL),                                 /* larch_reloc_type_name */
index 41956b13d279723a56ed2d88fdc11721242a9fbe..bb8baccceb716a01fc2850f59f6465d02001a5d6 100644 (file)
@@ -14,7 +14,7 @@ Contents of the .*:
   Augmentation data:     .*
 #...
 [a-zA-Z0-9]+ [a-zA-Z0-9]+ [a-zA-Z0-9]+ FDE cie=0+ pc=[a-zA-Z0-9]+\.\.[a-zA-Z0-9]+
-  DW_CFA_advance_loc: 4 to 0+20
+  DW_CFA_advance_loc: 4 to 0+4
   DW_CFA_offset_extended_sf: r0 \(\$zero\) at cfa\+8
   DW_CFA_offset_extended_sf: r1 \(\$ra\) at cfa\+16
   DW_CFA_offset_extended_sf: r2 \(\$tp\) at cfa\+24
diff --git a/gas/testsuite/gas/loongarch/frame_pc.d b/gas/testsuite/gas/loongarch/frame_pc.d
new file mode 100644 (file)
index 0000000..7bd862b
--- /dev/null
@@ -0,0 +1,22 @@
+#objdump: -Wf -d -M no-aliases
+#skip: loongarch32-*-*
+
+.*:     file format .*
+
+Contents of the .eh_frame section:
+#...
+00000014 0000000000000020 00000018 FDE cie=00000000 pc=0000000000000000..0000000000000020
+  DW_CFA_advance_loc: 4 to 0000000000000004
+#...
+
+Disassembly of section .text:
+
+0+0 <_start>:
+   0:  02ffc063        addi.d          \$sp, \$sp, -16
+   4:  29c02076        st.d            \$fp, \$sp, 8
+   8:  02c04076        addi.d          \$fp, \$sp, 16
+   c:  0015000c        or              \$t0, \$zero, \$zero
+  10:  00150184        or              \$a0, \$t0, \$zero
+  14:  28c02076        ld.d            \$fp, \$sp, 8
+  18:  02c04063        addi.d          \$sp, \$sp, 16
+  1c:  4c000020        jirl            \$zero, \$ra, 0
diff --git a/gas/testsuite/gas/loongarch/frame_pc.s b/gas/testsuite/gas/loongarch/frame_pc.s
new file mode 100644 (file)
index 0000000..8344d73
--- /dev/null
@@ -0,0 +1,20 @@
+       .align  2
+       .globl  _start
+       .type   _start, @function
+_start:
+       .cfi_startproc
+       addi.d  $sp,$sp,-16
+       .cfi_def_cfa_offset 16
+       st.d    $fp,$sp,8
+       .cfi_offset 22, -8
+       addi.d  $fp,$sp,16
+       .cfi_def_cfa 22, 0
+       or      $t0,$zero,$zero
+       or      $a0,$t0,$zero
+       ld.d    $fp,$sp,8
+       .cfi_restore 22
+       addi.d  $sp,$sp,16
+       .cfi_def_cfa_register 3
+       jr      $ra
+       .cfi_endproc
+       .size   _start, .-_start