This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Binutils][Objdump]Check symbol section information while search a mapping symbol backward.
- From: Renlin Li <renlin dot li at foss dot arm dot com>
- To: "binutils at sourceware dot org" <binutils at sourceware dot org>, Nicholas Clifton <nickc at redhat dot com>, Ramana Radhakrishnan <Ramana dot Radhakrishnan at arm dot com>, Richard Earnshaw <Richard dot Earnshaw at arm dot com>
- Date: Mon, 11 Dec 2017 15:19:31 +0000
- Subject: [Binutils][Objdump]Check symbol section information while search a mapping symbol backward.
- Authentication-results: sourceware.org; auth=none
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.
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;