--- /dev/null
+#PROG: objcopy
+#source: out-of-order.s
+#ld: -e v1 -Ttext-segment=0x400000
+#objdump: -d
+#name: Check if disassembler can handle sections in default order
+
+.*: +file format .*aarch64.*
+
+Disassembly of section \.func1:
+
+0000000000400000 <v1>:
+ 400000: 8b010000 add x0, x0, x1
+ 400004: 00000000 \.word 0x00000000
+
+Disassembly of section .func2:
+
+0000000000400008 <\.func2>:
+ 400008: 8b010000 add x0, x0, x1
+
+Disassembly of section \.func3:
+
+000000000040000c <\.func3>:
+ 40000c: 8b010000 add x0, x0, x1
+ 400010: 8b010000 add x0, x0, x1
+ 400014: 8b010000 add x0, x0, x1
+ 400018: 8b010000 add x0, x0, x1
+ 40001c: 8b010000 add x0, x0, x1
+ 400020: 00000000 \.word 0x00000000
#PROG: objcopy
#ld: -T out-of-order.T
-#objdump: -d
+#objdump: -D
#name: Check if disassembler can handle sections in different order than header
.*: +file format .*aarch64.*
+Disassembly of section \.global:
+
+00000000ffe00000 <\.global>:
+ ffe00000: 00000001 \.word 0x00000001
+ ffe00004: 00000000 \.word 0x00000000
+ ffe00008: 00000001 \.word 0x00000001
+ ffe0000c: 00000000 \.word 0x00000000
+ ffe00010: 00000001 \.word 0x00000001
+ ffe00014: 00000000 \.word 0x00000000
+
Disassembly of section \.func2:
0000000004018280 <\.func2>:
401500c: 8b010000 add x0, x0, x1
4015010: 8b010000 add x0, x0, x1
4015014: 00000000 \.word 0x00000000
+
+Disassembly of section \.rodata:
+
+0000000004015018 <\.rodata>:
+ 4015018: 00000004 \.word 0x00000004
/* Aarch64 instructions are always little-endian */
info->endian_code = BFD_ENDIAN_LITTLE;
+ /* Default to DATA. A text section is required by the ABI to contain an
+ INSN mapping symbol at the start. A data section has no such
+ requirement, hence if no mapping symbol is found the section must
+ contain only data. This however isn't very useful if the user has
+ fully stripped the binaries. If this is the case use the section
+ attributes to determine the default. If we have no section default to
+ INSN as well, as we may be disassembling some raw bytes on a baremetal
+ HEX file or similar. */
+ enum map_type type = MAP_DATA;
+ if ((info->section && info->section->flags & SEC_CODE) || !info->section)
+ type = MAP_INSN;
+
/* First check the full symtab for a mapping symbol, even if there
are no usable non-mapping symbols for this address. */
if (info->symtab_size != 0
&& bfd_asymbol_flavour (*info->symtab) == bfd_target_elf_flavour)
{
- enum map_type type = MAP_INSN;
int last_sym = -1;
- bfd_vma addr;
+ bfd_vma addr, section_vma = 0;
+ bfd_boolean can_use_search_opt_p;
int n;
if (pc <= last_mapping_addr)
/* Start scanning at the start of the function, or wherever
we finished last time. */
n = info->symtab_pos + 1;
+
/* If the last stop offset is different from the current one it means we
are disassembling a different glob of bytes. As such the optimization
would not be safe and we should start over. */
- if (n < last_mapping_sym && info->stop_offset == last_stop_offset)
+ can_use_search_opt_p = last_mapping_sym >= 0
+ && info->stop_offset == last_stop_offset;
+
+ if (n >= last_mapping_sym && can_use_search_opt_p)
n = last_mapping_sym;
- /* Scan up to the location being disassembled. */
+ /* Look down while we haven't passed the location being disassembled.
+ The reason for this is that there's no defined order between a symbol
+ and an mapping symbol that may be at the same address. We may have to
+ look at least one position ahead. */
for (; n < info->symtab_size; n++)
{
addr = bfd_asymbol_value (info->symtab[n]);
if (!found)
{
n = info->symtab_pos;
- if (n < last_mapping_sym)
+ if (n >= last_mapping_sym && can_use_search_opt_p)
n = last_mapping_sym;
/* No mapping symbol found at this address. Look backwards
- for a preceeding one. */
+ for a preceeding one, but don't go pass the section start
+ otherwise a data section with no mapping symbol can pick up
+ a text mapping symbol of a preceeding section. The documentation
+ says section can be NULL, in which case we will seek up all the
+ way to the top. */
+ if (info->section)
+ section_vma = info->section->vma;
+
for (; n >= 0; n--)
{
+ addr = bfd_asymbol_value (info->symtab[n]);
+ if (addr < section_vma)
+ break;
+
if (get_sym_code_type (info, n, &type))
{
last_sym = n;
size = (pc & 1) ? 1 : 2;
}
}
+ else
+ last_type = type;
if (last_type == MAP_DATA)
{