Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Milica Matic <milicamatic05@gmail.com>
To: gdb-patches@sourceware.org
Cc: milica.matic@htecgroup.com, simark@simark.ca, cfu@wavecomp.com,
	aburgess@redhat.com, kevinb@redhat.com, macro@orcam.me.uk,
	djordje.todorovic@htecgroup.com,
	Matthew Fortune <matthew.fortune@mips.com>,
	Faraz Shahbazker <fshahbazker@wavecomp.com>
Subject: [PATCH 20/21] Workaround for line info in compressed MIPS func
Date: Fri, 13 Dec 2024 16:53:27 +0100	[thread overview]
Message-ID: <20241213155328.406003-22-milica.matic@htecgroup.com> (raw)
In-Reply-To: <20241213155328.406003-1-milica.matic@htecgroup.com>

From: Matthew Fortune <matthew.fortune@mips.com>

This fix allows the first address of a MIPS16/microMIPS function to
be used to get the filename/line and function that it belongs to
whereas it has previously needed the ISA bit to be set in the address
for the first instruction to match up correctly.

Note: we should really be checking the output of addr2line, but the
binutils test-framework doesn't have that capability yet.
Expected addr2line output for both new tests is:

$ addr2line -a 0x400000 0x400004 0x40000c -p -e <elf>
0x00400000: .*-lineno.c:1
0x00400004: .*-lineno.c:2
0x0040000c: .*-lineno.c:3

Cherry-picked 2279503
from https://github.com/MIPS/binutils-gdb

Signed-off-by: Faraz Shahbazker <fshahbazker@wavecomp.com>
Signed-off-by: Milica Matic <milica.matic@htecgroup.com>

Changelog:

bfd/
	* elfxx-mips.c (_bfd_mips_elf_find_nearest_line): If no matching
	line is found for an address, retry with the ISA bit set in case
	searching at the beginning of a MIPS16/microMIPS section.

ld/testsuite/
	* ld-mips-elf/mips16-lineno.s: New test source.
	* ld-mips-elf/micromips-lineno.s: New test source.
	* ld-mips-elf/mips16-lineno.d: New test.
	* ld-mips-elf/micromips-lineno.d: New test.
	* ld-mips-elf/mips-elf.exp: Run the new tests
---
 bfd/elfxx-mips.c                            | 19 +++++++--
 ld/testsuite/ld-mips-elf/micromips-lineno.d | 33 +++++++++++++++
 ld/testsuite/ld-mips-elf/micromips-lineno.s | 44 ++++++++++++++++++++
 ld/testsuite/ld-mips-elf/mips16-lineno.d    | 32 ++++++++++++++
 ld/testsuite/ld-mips-elf/mips16-lineno.s    | 46 +++++++++++++++++++++
 5 files changed, 171 insertions(+), 3 deletions(-)
 create mode 100644 ld/testsuite/ld-mips-elf/micromips-lineno.d
 create mode 100644 ld/testsuite/ld-mips-elf/micromips-lineno.s
 create mode 100644 ld/testsuite/ld-mips-elf/mips16-lineno.d
 create mode 100644 ld/testsuite/ld-mips-elf/mips16-lineno.s

diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 68b439c456a..f0c5e7ae6cd 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -13423,6 +13423,7 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols,
 				 unsigned int *discriminator_ptr)
 {
   asection *msec;
+  bool found = false;
 
   if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
 				     filename_ptr, functionname_ptr,
@@ -13513,9 +13514,21 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols,
 
   /* Fall back on the generic ELF find_nearest_line routine.  */
 
-  return _bfd_elf_find_nearest_line (abfd, symbols, section, offset,
-				     filename_ptr, functionname_ptr,
-				     line_ptr, discriminator_ptr);
+  found = _bfd_elf_find_nearest_line (abfd, symbols, section, offset,
+				       filename_ptr, functionname_ptr,
+				       line_ptr, discriminator_ptr);
+
+  /* The bfd_find_nearest_line_discriminator may not be able to find filename
+     and line if pc points to start of a MIPS compressed function.  This is
+     because ISA bit is set in the line number entries.  For example, if start
+     of a function is 0x80200750 then line number entries start from 0x80200751
+     (31st bit is set).  Set ISA bit of the pc and search again.  
+  if (found && *filename_ptr == NULL && *line_ptr == 0 && (offset & 1) == 0)
+    found = _bfd_elf_find_nearest_line (abfd, symbols, section,
+					offset | 1,
+					filename_ptr, functionname_ptr,
+					line_ptr, discriminator_ptr);  */
+  return found;
 }
 
 bool
diff --git a/ld/testsuite/ld-mips-elf/micromips-lineno.d b/ld/testsuite/ld-mips-elf/micromips-lineno.d
new file mode 100644
index 00000000000..09d8008580d
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/micromips-lineno.d
@@ -0,0 +1,33 @@
+#name: MICROMIPS address mapping to debug line information
+#ld: -Ttext 0x400020
+#objdump: -dlr
+#source: micromips-lineno.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+
+00400020 <__start>:
+__start\(\):
+  400020:	00000000 	nop
+
+00400024 <foo>:
+foo\(\):
+  400024:	0c00      	nop
+.*micromips-lineno.c:1
+  400026:	47e3      	jrc	ra
+
+00400028 <bar>:
+.*micromips-lineno.c:2
+  400028:	03e00009 	jr	ra
+bar\(\):
+.*micromips-lineno.c:2
+  40002c:	00000000 	nop
+
+00400030 <baz>:
+baz\(\):
+  400030:	0c00      	nop
+.*micromips-lineno.c:3
+  400032:	47e3      	jrc	ra
+
+#pass
diff --git a/ld/testsuite/ld-mips-elf/micromips-lineno.s b/ld/testsuite/ld-mips-elf/micromips-lineno.s
new file mode 100644
index 00000000000..0dced268360
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/micromips-lineno.s
@@ -0,0 +1,44 @@
+	# Dummy file name
+	.file 1 "micromips-lineno.c"
+	.section .text.foo,"ax",@progbits
+	.globl foo
+	.globl main
+	.globl start
+	.globl _start
+	.globl __start
+	# Dummy line number 1
+	.loc 1 1 0
+	.set	micromips
+	.set	nomips16
+	.ent	foo
+foo:
+	nop
+	jr	$ra
+	.end	foo
+	.section .text.bar,"ax",@progbits
+	.globl	bar
+	# Dummy line number 2
+	.loc 1 2 0
+	.set	nomicromips
+	.ent	bar
+bar:
+	nop
+	jr	$ra
+	.end	bar
+	.section .text.baz,"ax",@progbits
+	.globl	baz
+	# Dummy line number 3
+	.loc 1 3 0
+	.set	micromips
+	.ent	baz
+baz:
+	nop
+	jr	$ra
+	.end	baz
+
+	.text
+main:
+start:
+_start:
+__start:
+	.byte 0
diff --git a/ld/testsuite/ld-mips-elf/mips16-lineno.d b/ld/testsuite/ld-mips-elf/mips16-lineno.d
new file mode 100644
index 00000000000..05dde9348a4
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/mips16-lineno.d
@@ -0,0 +1,32 @@
+#name: MIPS16 address mapping to debug line information
+#as: -march=mips2 -mabi=32
+#ld: -Ttext 0x400020
+#objdump: -dlr
+#source: mips16-lineno.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+
+00400020 <\_\_start>:
+\_\_start\(\):
+  400020:	00000000 	nop
+
+00400024 <foo>:
+foo\(\):
+  400024:	e820      	jr	ra
+.*mips16-lineno.c:1
+  400026:	6500      	nop
+
+00400028 <bar>:
+.*mips16-lineno.c:2
+  400028:	03e00008 	jr	ra
+bar\(\):
+.*mips16-lineno.c:2
+  40002c:	00000000 	nop
+
+00400030 <baz>:
+baz\(\):
+  400030:	e820      	jr	ra
+.*mips16-lineno.c:3
+  400032:	6500      	nop
diff --git a/ld/testsuite/ld-mips-elf/mips16-lineno.s b/ld/testsuite/ld-mips-elf/mips16-lineno.s
new file mode 100644
index 00000000000..48c2baa4948
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/mips16-lineno.s
@@ -0,0 +1,46 @@
+	# Dummy file name
+	.file 1 "mips16-lineno.c"
+	.section .text.foo,"ax",@progbits
+	.globl foo
+	.globl main
+	.globl start
+	.globl _start
+	.globl __start
+	# Dummy line number 1
+	.loc 1 1 0
+	.set	mips16
+	.set	nomicromips
+	.ent	foo
+foo:
+	nop
+	jr	$ra
+	.end	foo
+	.section .text.bar,"ax",@progbits
+	.globl	bar
+	# Dummy line number 2
+	.loc 1 2 0
+	.set	nomips16
+	.ent	bar
+bar:
+	nop
+	jr	$ra
+	.end	bar
+	.section .text.baz,"ax",@progbits
+	.globl	baz
+	# Dummy line number 3
+	.loc 1 3 0
+	.set	mips16
+	.ent	baz
+baz:
+	nop
+	jr	$ra
+	.end	baz
+
+
+	.text
+main:
+start:
+_start:
+__start:
+	.byte 0
+
-- 
2.34.1


  parent reply	other threads:[~2024-12-13 16:07 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-13 15:53 [PATCH 0/21] Integrate MIPS-Specific Support into Official binutils-gdb Milica Matic
2024-12-13 15:53 ` [PATCH 00/21] " Milica Matic
2024-12-13 15:53 ` [PATCH 01/21] Don't adjust microMIPS HI/LO rel section-relative Milica Matic
2024-12-13 15:53 ` [PATCH 02/21] Add new relocations for microMIPSR6 Milica Matic
2024-12-13 15:53 ` [PATCH 03/21] Improve WARN for $0 constraint on MIPSR6 branches Milica Matic
2024-12-13 15:53 ` [PATCH 04/21] Instruction mapping support (pre-R6 to R6) Milica Matic
2024-12-13 15:53 ` [PATCH 05/21] Add microMIPSR6 support Milica Matic
2024-12-13 15:53 ` [PATCH 06/21] Update branch relaxation Milica Matic
2024-12-13 15:53 ` [PATCH 07/21] Add --user-defined-sdata-sections Milica Matic
2024-12-13 15:53 ` [PATCH 08/21] Disassembler fix Milica Matic
2024-12-13 15:53 ` [PATCH 09/21] MIPS: Add CRYPTO ASE support Milica Matic
2024-12-13 15:53 ` [PATCH 10/21] Add the m6201 architecture Milica Matic
2024-12-13 15:53 ` [PATCH 11/21] Add GINV(+VIRT) ASE for MIPSr6/microMIPS6 Milica Matic
2024-12-13 15:53 ` [PATCH 12/21] Implement the XBurst MXU extensions Milica Matic
2024-12-13 15:53 ` [PATCH 13/21] MIPS: Update encoding of d16mule MXU instruction Milica Matic
2024-12-13 15:53 ` [PATCH 14/21] Re-arrange MXU code blocks and add comments Milica Matic
2024-12-13 15:53 ` [PATCH 15/21] Accept MCU mapped string operands as constants Milica Matic
2024-12-13 15:53 ` [PATCH 16/21] Fix addr2line mapping - garbage collected modules Milica Matic
2024-12-13 15:53 ` [PATCH 17/21] Extend trap macros to handle immediate zero Milica Matic
2024-12-13 15:53 ` [PATCH 18/21] Fix failing test cases for linux and 64-bit target Milica Matic
2024-12-13 15:53 ` [PATCH 19/21] Remove exec permission tc-mips.c Milica Matic
2024-12-13 15:53 ` Milica Matic [this message]
2024-12-13 15:53 ` [PATCH 21/21] Fix gold linker build issues for mingw Milica Matic
2025-01-07 21:18 ` [PATCH 0/21] Integrate MIPS-Specific Support into Official binutils-gdb Kevin Buettner
2025-01-09  1:11   ` [EXTERNAL]Re: " Chao-ying Fu
2025-01-07 21:31 ` Kevin Buettner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241213155328.406003-22-milica.matic@htecgroup.com \
    --to=milicamatic05@gmail.com \
    --cc=aburgess@redhat.com \
    --cc=cfu@wavecomp.com \
    --cc=djordje.todorovic@htecgroup.com \
    --cc=fshahbazker@wavecomp.com \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.com \
    --cc=macro@orcam.me.uk \
    --cc=matthew.fortune@mips.com \
    --cc=milica.matic@htecgroup.com \
    --cc=simark@simark.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox