+
+ free (sfile.buffer);
+}
+
+static void
+disassemble_section (bfd *abfd, asection *section, void *info)
+{
+ struct disassemble_info * pinfo = (struct disassemble_info *) info;
+ struct objdump_disasm_info * paux;
+ unsigned int opb = pinfo->octets_per_byte;
+ bfd_byte * data = NULL;
+ bfd_size_type datasize = 0;
+ arelent ** rel_pp = NULL;
+ arelent ** rel_ppstart = NULL;
+ arelent ** rel_ppend;
+ unsigned long stop_offset;
+ asymbol * sym = NULL;
+ long place = 0;
+ long rel_count;
+ bfd_vma rel_offset;
+ unsigned long addr_offset;
+
+ /* Sections that do not contain machine
+ code are not normally disassembled. */
+ if (! disassemble_all
+ && only == NULL
+ && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
+ != (SEC_CODE | SEC_HAS_CONTENTS)))
+ return;
+
+ if (! process_section_p (section))
+ return;
+
+ datasize = bfd_get_section_size (section);
+ if (datasize == 0)
+ return;
+
+ /* Decide which set of relocs to use. Load them if necessary. */
+ paux = (struct objdump_disasm_info *) pinfo->application_data;
+ if (paux->dynrelbuf)
+ {
+ rel_pp = paux->dynrelbuf;
+ rel_count = paux->dynrelcount;
+ /* Dynamic reloc addresses are absolute, non-dynamic are section
+ relative. REL_OFFSET specifies the reloc address corresponding
+ to the start of this section. */
+ rel_offset = section->vma;
+ }
+ else
+ {
+ rel_count = 0;
+ rel_pp = NULL;
+ rel_offset = 0;
+
+ 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);