[PATCH v1] LoongArch: Fix incorrect display of FDEs address ranges when using objdump -Wf

Lulu Cai cailulu@loongson.cn
Wed Aug 27 02:15:16 GMT 2025


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                      |  4 ++--
 gas/testsuite/gas/loongarch/dwarf-regnum.d |  2 +-
 gas/testsuite/gas/loongarch/frame_pc.d     | 22 ++++++++++++++++++++++
 gas/testsuite/gas/loongarch/frame_pc.s     | 20 ++++++++++++++++++++
 4 files changed, 45 insertions(+), 3 deletions(-)
 create mode 100644 gas/testsuite/gas/loongarch/frame_pc.d
 create mode 100644 gas/testsuite/gas/loongarch/frame_pc.s

diff --git a/bfd/elfxx-loongarch.c b/bfd/elfxx-loongarch.c
index 6268c477feb..0b030d39aa9 100644
--- a/bfd/elfxx-loongarch.c
+++ b/bfd/elfxx-loongarch.c
@@ -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 */
diff --git a/gas/testsuite/gas/loongarch/dwarf-regnum.d b/gas/testsuite/gas/loongarch/dwarf-regnum.d
index 41956b13d27..bb8baccceb7 100644
--- a/gas/testsuite/gas/loongarch/dwarf-regnum.d
+++ b/gas/testsuite/gas/loongarch/dwarf-regnum.d
@@ -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
index 00000000000..7bd862ba527
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/frame_pc.d
@@ -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
index 00000000000..8344d7375cc
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/frame_pc.s
@@ -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
-- 
2.38.1



More information about the Binutils mailing list