public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Binutils][Objdump]Check symbol section information while search a mapping symbol backward.
@ 2017-12-11 15:19 Renlin Li
  2017-12-11 15:24 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Renlin Li @ 2017-12-11 15:19 UTC (permalink / raw)
  To: binutils, Nicholas Clifton, Ramana Radhakrishnan, Richard Earnshaw

[-- Attachment #1: Type: text/plain, Size: 1646 bytes --]

Hi all,

For the following test case:

.text
l1:
   nop
l2:
   nop
.word 0xc0ffee

.section .fini, "x"
.word 0xdead

The objdump could not properly dump the nop instruction at l2 label. It treats
it as data. This is because the mapping symbol it found is a data mapping
symbol. However, this $d symbol is defined in a different section. So it
shouldn't be used in a different section.

Symbol table '.symtab' contains 10 entries:
    Num:    Value          Size Type    Bind   Vis      Ndx Name
      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
      1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1
      2: 0000000000000000     0 SECTION LOCAL  DEFAULT    2
      3: 0000000000000000     0 SECTION LOCAL  DEFAULT    3
      4: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    1 l1
      5: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    1 $x
      6: 0000000000000004     0 NOTYPE  LOCAL  DEFAULT    1 l2
      7: 0000000000000008     0 NOTYPE  LOCAL  DEFAULT    1 $d
      8: 0000000000000000     0 SECTION LOCAL  DEFAULT    4
      9: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    4 $d

This patch fixes this bug and add a new test case. The change is tested in
aarch64-none-elf cross environment. No regression.

Okay to check in?

Regards,
Renlin

opcodes/ChangeLog:

2017-12-11  Petr Pavlu  <petr.pavlu@arm.com>
2017-12-11  Renlin Li  <renlin.li@arm.com>

	* aarch64-dis.c (print_insn_aarch64): Move symbol section check ...
	(get_sym_code_type): Here.

binutils/ChangeLog:

2017-12-11  Renlin Li  <renlin.li@arm.com>

	* testsuite/binutils-all/aarch64/objdump.d: New.
	* testsuite/binutils-all/aarch64/objdump.s: New.

[-- Attachment #2: change.patch --]
[-- Type: text/x-patch, Size: 2031 bytes --]

diff --git a/binutils/testsuite/binutils-all/aarch64/objdump.d b/binutils/testsuite/binutils-all/aarch64/objdump.d
new file mode 100644
index 0000000000000000000000000000000000000000..4aca57bae4df9b45cef404c5f3ae2c33cc4572ae
--- /dev/null
+++ b/binutils/testsuite/binutils-all/aarch64/objdump.d
@@ -0,0 +1,19 @@
+#PROG: objcopy
+#objdump: -d
+#name: Check that the disassembler properly dump instruction and data.
+
+.*: +file format .*aarch64.*
+
+Disassembly of section \.text:
+
+0+000 <l1>:
+   0:	d503201f 	nop
+
+0+004 <l2>:
+   4:	d503201f 	nop
+   8:	00c0ffee 	\.word	0x00c0ffee
+
+Disassembly of section .fini:
+
+0+000 <\.fini>:
+   0:	0000dead 	\.word	0x0000dead
diff --git a/binutils/testsuite/binutils-all/aarch64/objdump.s b/binutils/testsuite/binutils-all/aarch64/objdump.s
new file mode 100644
index 0000000000000000000000000000000000000000..68de7037f77b6fc157b68ead32a024dc56b0ca3b
--- /dev/null
+++ b/binutils/testsuite/binutils-all/aarch64/objdump.s
@@ -0,0 +1,9 @@
+.text
+l1:
+  nop
+l2:
+  nop
+.word 0xc0ffee
+
+.section .fini, "x"
+.word 0xdead
diff --git a/opcodes/aarch64-dis.c b/opcodes/aarch64-dis.c
index df67a066fdd8c6475b3920db5e222b183a31bfb6..8fd1ecfc920a4970104422a6444503102fadf526 100644
--- a/opcodes/aarch64-dis.c
+++ b/opcodes/aarch64-dis.c
@@ -3097,6 +3097,10 @@ get_sym_code_type (struct disassemble_info *info, int n,
   unsigned int type;
   const char *name;
 
+  /* If the symbol is in a different section, ignore it.  */
+  if (info->section != NULL && info->section != info->symtab[n]->section)
+    return FALSE;
+
   es = *(elf_symbol_type **)(info->symtab + n);
   type = ELF_ST_TYPE (es->internal_elf_sym.st_info);
 
@@ -3171,9 +3175,7 @@ print_insn_aarch64 (bfd_vma pc,
 	  addr = bfd_asymbol_value (info->symtab[n]);
 	  if (addr > pc)
 	    break;
-	  if ((info->section == NULL
-	       || info->section == info->symtab[n]->section)
-	      && get_sym_code_type (info, n, &type))
+	  if (get_sym_code_type (info, n, &type))
 	    {
 	      last_sym = n;
 	      found = TRUE;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Binutils][Objdump]Check symbol section information while search a mapping symbol backward.
  2017-12-11 15:19 [Binutils][Objdump]Check symbol section information while search a mapping symbol backward Renlin Li
@ 2017-12-11 15:24 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2017-12-11 15:24 UTC (permalink / raw)
  To: Renlin Li, binutils, Ramana Radhakrishnan, Richard Earnshaw

Hi Renlin,

> opcodes/ChangeLog:
> 
> 2017-12-11  Petr Pavlu  <petr.pavlu@arm.com>
> 2017-12-11  Renlin Li  <renlin.li@arm.com>
> 
>     * aarch64-dis.c (print_insn_aarch64): Move symbol section check ...
>     (get_sym_code_type): Here.
> 
> binutils/ChangeLog:
> 
> 2017-12-11  Renlin Li  <renlin.li@arm.com>
> 
>     * testsuite/binutils-all/aarch64/objdump.d: New.
>     * testsuite/binutils-all/aarch64/objdump.s: New.

Approved - please apply.

Cheers
  Nick

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-11 15:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-11 15:19 [Binutils][Objdump]Check symbol section information while search a mapping symbol backward Renlin Li
2017-12-11 15:24 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).