+ if ((section->flags & SEC_RELOC) != 0
+#ifndef DISASSEMBLER_NEEDS_RELOCS
+ && dump_reloc_info
+#endif
+ )
+ {
+ long relsize;
+
+ relsize = bfd_get_reloc_upper_bound (abfd, section);
+ if (relsize < 0)
+ bfd_fatal (bfd_get_filename (abfd));
+
+ if (relsize > 0)
+ {
+ rel_ppstart = rel_pp = xmalloc (relsize);
+ rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms);
+ if (rel_count < 0)
+ bfd_fatal (bfd_get_filename (abfd));
+
+ /* Sort the relocs by address. */
+ qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs);
+ }
+ }
+
+ }
+ rel_ppend = rel_pp + rel_count;
+
+ data = xmalloc (datasize);
+
+ bfd_get_section_contents (abfd, section, data, 0, datasize);
+
+ paux->sec = section;
+ pinfo->buffer = data;
+ pinfo->buffer_vma = section->vma;
+ pinfo->buffer_length = datasize;
+ pinfo->section = section;
+
+ if (start_address == (bfd_vma) -1
+ || start_address < pinfo->buffer_vma)
+ addr_offset = 0;
+ else
+ addr_offset = start_address - pinfo->buffer_vma;
+
+ if (stop_address == (bfd_vma) -1)
+ stop_offset = datasize / opb;
+ else
+ {
+ if (stop_address < pinfo->buffer_vma)
+ stop_offset = 0;
+ else
+ stop_offset = stop_address - pinfo->buffer_vma;
+ if (stop_offset > pinfo->buffer_length / opb)
+ stop_offset = pinfo->buffer_length / opb;
+ }
+
+ /* Skip over the relocs belonging to addresses below the
+ start address. */
+ while (rel_pp < rel_ppend
+ && (*rel_pp)->address < rel_offset + addr_offset)
+ ++rel_pp;
+
+ printf (_("Disassembly of section %s:\n"), section->name);
+
+ /* Find the nearest symbol forwards from our current position. */
+ paux->require_sec = TRUE;
+ sym = find_symbol_for_address (section->vma + addr_offset, info, &place);
+ paux->require_sec = FALSE;
+
+ /* Disassemble a block of instructions up to the address associated with
+ the symbol we have just found. Then print the symbol and find the
+ next symbol on. Repeat until we have disassembled the entire section
+ or we have reached the end of the address range we are interested in. */
+ while (addr_offset < stop_offset)
+ {
+ bfd_vma addr;
+ asymbol *nextsym;
+ unsigned long nextstop_offset;
+ bfd_boolean insns;
+
+ addr = section->vma + addr_offset;
+
+ if (sym != NULL && bfd_asymbol_value (sym) <= addr)
+ {
+ int x;
+
+ for (x = place;
+ (x < sorted_symcount
+ && (bfd_asymbol_value (sorted_syms[x]) <= addr));
+ ++x)
+ continue;
+
+ pinfo->symbols = sorted_syms + place;
+ pinfo->num_symbols = x - place;
+ }
+ else
+ {
+ pinfo->symbols = NULL;
+ pinfo->num_symbols = 0;
+ }
+
+ if (! prefix_addresses)
+ {
+ pinfo->fprintf_func (pinfo->stream, "\n");
+ objdump_print_addr_with_sym (abfd, section, sym, addr,
+ pinfo, FALSE);
+ pinfo->fprintf_func (pinfo->stream, ":\n");
+ }
+
+ if (sym != NULL && bfd_asymbol_value (sym) > addr)
+ nextsym = sym;
+ else if (sym == NULL)
+ nextsym = NULL;
+ else
+ {
+#define is_valid_next_sym(SYM) \
+ ((SYM)->section == section \
+ && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
+ && pinfo->symbol_is_valid (SYM, pinfo))
+
+ /* Search forward for the next appropriate symbol in
+ SECTION. Note that all the symbols are sorted
+ together into one big array, and that some sections
+ may have overlapping addresses. */
+ while (place < sorted_symcount
+ && ! is_valid_next_sym (sorted_syms [place]))
+ ++place;
+
+ if (place >= sorted_symcount)
+ nextsym = NULL;
+ else
+ nextsym = sorted_syms[place];
+ }
+
+ if (sym != NULL && bfd_asymbol_value (sym) > addr)
+ nextstop_offset = bfd_asymbol_value (sym) - section->vma;
+ else if (nextsym == NULL)
+ nextstop_offset = stop_offset;
+ else
+ nextstop_offset = bfd_asymbol_value (nextsym) - section->vma;
+
+ if (nextstop_offset > stop_offset)
+ nextstop_offset = stop_offset;
+
+ /* If a symbol is explicitly marked as being an object
+ rather than a function, just dump the bytes without
+ disassembling them. */
+ if (disassemble_all
+ || sym == NULL
+ || bfd_asymbol_value (sym) > addr
+ || ((sym->flags & BSF_OBJECT) == 0
+ && (strstr (bfd_asymbol_name (sym), "gnu_compiled")
+ == NULL)
+ && (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
+ == NULL))
+ || (sym->flags & BSF_FUNCTION) != 0)
+ insns = TRUE;
+ else
+ insns = FALSE;
+
+ disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
+ addr_offset, nextstop_offset,
+ rel_offset, &rel_pp, rel_ppend);
+
+ addr_offset = nextstop_offset;
+ sym = nextsym;
+ }
+
+ free (data);
+
+ if (rel_ppstart != NULL)
+ free (rel_ppstart);
+}
+
+/* Disassemble the contents of an object file. */
+
+static void
+disassemble_data (bfd *abfd)
+{
+ struct disassemble_info disasm_info;
+ struct objdump_disasm_info aux;
+ long i;
+
+ print_files = NULL;
+ prev_functionname = NULL;
+ prev_line = -1;
+
+ /* We make a copy of syms to sort. We don't want to sort syms
+ because that will screw up the relocs. */
+ sorted_symcount = symcount ? symcount : dynsymcount;
+ sorted_syms = xmalloc ((sorted_symcount + synthcount) * sizeof (asymbol *));
+ memcpy (sorted_syms, symcount ? syms : dynsyms,
+ sorted_symcount * sizeof (asymbol *));
+
+ sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
+
+ for (i = 0; i < synthcount; ++i)
+ {
+ sorted_syms[sorted_symcount] = synthsyms + i;
+ ++sorted_symcount;
+ }
+
+ /* Sort the symbols into section and symbol order. */
+ qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
+
+ init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf);
+
+ disasm_info.application_data = (void *) &aux;