objdump: Fix relocations objdumping for specific symbol

Message ID 20230122180736.55917-1-och95@yandex.ru
State Accepted
Headers
Series objdump: Fix relocations objdumping for specific symbol |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Vladislav Khmelevsky Jan. 22, 2023, 6:07 p.m. UTC
  If objdump is used with both --disassemble=symbol and --reloc options
skip relocations that are belonging to the addresses below the symbol address.
---
 binutils/objdump.c | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Alan Modra Jan. 23, 2023, 2:40 a.m. UTC | #1
On Sun, Jan 22, 2023 at 10:07:36PM +0400, Vladislav Khmelevsky wrote:
> If objdump is used with both --disassemble=symbol and --reloc options
> skip relocations that are belonging to the addresses below the symbol address.

Thanks, pushed.
  

Patch

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 61a18746fde..155461fc3cd 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -3909,6 +3909,13 @@  disassemble_section (bfd *abfd, asection *section, void *inf)
 		{
 		  do_print = true;
 
+		  /* Skip over the relocs belonging to addresses below the
+		     symbol address.  */
+		  const bfd_vma sym_offset = bfd_asymbol_value (sym) - section->vma;
+		  while (rel_pp < rel_ppend &&
+		   (*rel_pp)->address - rel_offset < sym_offset)
+			  ++rel_pp;
+
 		  if (sym->flags & BSF_FUNCTION)
 		    {
 		      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour