+ }
+ else if (sub_symbol_segment == absolute_section
+ && !S_FORCE_RELOC (fixP->fx_subsy, 0)
+ && !TC_FORCE_RELOCATION_SUB_ABS (fixP, add_symbol_segment))
+ {
+ add_number -= S_GET_VALUE (fixP->fx_subsy);
+ fixP->fx_offset = add_number;
+ fixP->fx_subsy = NULL;
+ }
+ else if (sub_symbol_segment == this_segment
+ && !S_FORCE_RELOC (fixP->fx_subsy, 0)
+ && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP, add_symbol_segment))
+ {
+ add_number -= S_GET_VALUE (fixP->fx_subsy);
+ fixP->fx_offset = (add_number + fixP->fx_dot_value
+ + fixP->fx_dot_frag->fr_address);
+
+ /* Make it pc-relative. If the back-end code has not
+ selected a pc-relative reloc, cancel the adjustment
+ we do later on all pc-relative relocs. */
+ if (0
+#ifdef TC_M68K
+ /* Do this for m68k even if it's already described
+ as pc-relative. On the m68k, an operand of
+ "pc@(foo-.-2)" should address "foo" in a
+ pc-relative mode. */
+ || 1
+#endif
+ || !fixP->fx_pcrel)
+ add_number += MD_PCREL_FROM_SECTION (fixP, this_segment);
+ fixP->fx_subsy = NULL;
+ fixP->fx_pcrel = 1;
+ }
+ else if (!TC_VALIDATE_FIX_SUB (fixP, add_symbol_segment))
+ {
+ if (!md_register_arithmetic
+ && (add_symbol_segment == reg_section
+ || sub_symbol_segment == reg_section))
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("register value used as expression"));
+ else
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("can't resolve `%s' {%s section} - `%s' {%s section}"),
+ fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0",
+ segment_name (add_symbol_segment),
+ S_GET_NAME (fixP->fx_subsy),
+ segment_name (sub_symbol_segment));
+ }
+ else if (sub_symbol_segment != undefined_section
+ && ! bfd_is_com_section (sub_symbol_segment)
+ && MD_APPLY_SYM_VALUE (fixP))
+ add_number -= S_GET_VALUE (fixP->fx_subsy);
+ }
+
+ if (fixP->fx_addsy)
+ {
+ if (add_symbol_segment == this_segment
+ && !S_FORCE_RELOC (fixP->fx_addsy, 0)
+ && !TC_FORCE_RELOCATION_LOCAL (fixP))
+ {
+ /* This fixup was made when the symbol's segment was
+ SEG_UNKNOWN, but it is now in the local segment.
+ So we know how to do the address without relocation. */
+ add_number += S_GET_VALUE (fixP->fx_addsy);
+ fixP->fx_offset = add_number;
+ if (fixP->fx_pcrel)
+ add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment);
+ fixP->fx_addsy = NULL;
+ fixP->fx_pcrel = 0;
+ }
+ else if (add_symbol_segment == absolute_section
+ && !S_FORCE_RELOC (fixP->fx_addsy, 0)
+ && !TC_FORCE_RELOCATION_ABS (fixP))
+ {
+ add_number += S_GET_VALUE (fixP->fx_addsy);
+ fixP->fx_offset = add_number;
+ fixP->fx_addsy = NULL;
+ }
+ else if (add_symbol_segment != undefined_section
+ && ! bfd_is_com_section (add_symbol_segment)
+ && MD_APPLY_SYM_VALUE (fixP))
+ add_number += S_GET_VALUE (fixP->fx_addsy);
+ }
+
+ if (fixP->fx_pcrel)
+ {
+ add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment);
+ if (!fixP->fx_done && fixP->fx_addsy == NULL)
+ {
+ /* There was no symbol required by this relocation.
+ However, BFD doesn't really handle relocations
+ without symbols well. So fake up a local symbol in
+ the absolute section. */
+ fixP->fx_addsy = abs_section_sym;
+ }
+ }
+
+ if (!fixP->fx_done)
+ md_apply_fix (fixP, &add_number, this_segment);
+
+ if (!fixP->fx_done)
+ {
+ if (fixP->fx_addsy == NULL)
+ fixP->fx_addsy = abs_section_sym;
+ symbol_mark_used_in_reloc (fixP->fx_addsy);
+ if (fixP->fx_subsy != NULL)
+ symbol_mark_used_in_reloc (fixP->fx_subsy);
+ }
+
+ if (!fixP->fx_no_overflow && fixP->fx_size != 0)
+ {
+ if (fixP->fx_size < sizeof (valueT))
+ {
+ valueT mask;
+
+ mask = 0;
+ mask--; /* Set all bits to one. */
+ mask <<= fixP->fx_size * 8 - (fixP->fx_signed ? 1 : 0);
+ if ((add_number & mask) != 0 && (add_number & mask) != mask)
+ {
+ char buf[50], buf2[50];
+ sprint_value (buf, fragP->fr_address + fixP->fx_where);
+ if (add_number > 1000)
+ sprint_value (buf2, add_number);
+ else
+ sprintf (buf2, "%ld", (long) add_number);
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ ngettext ("value of %s too large for field "
+ "of %d byte at %s",
+ "value of %s too large for field "
+ "of %d bytes at %s",
+ fixP->fx_size),
+ buf2, fixP->fx_size, buf);
+ } /* Generic error checking. */
+ }
+#ifdef WARN_SIGNED_OVERFLOW_WORD
+ /* Warn if a .word value is too large when treated as a signed
+ number. We already know it is not too negative. This is to
+ catch over-large switches generated by gcc on the 68k. */
+ if (!flag_signed_overflow_ok
+ && fixP->fx_size == 2
+ && add_number > 0x7fff)
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("signed .word overflow; switch may be too large; %ld at 0x%lx"),
+ (long) add_number,
+ (long) (fragP->fr_address + fixP->fx_where));
+#endif
+ }
+
+#ifdef TC_VALIDATE_FIX
+ skip: ATTRIBUTE_UNUSED_LABEL
+ ;
+#endif
+#ifdef DEBUG5
+ fprintf (stderr, "result:\n");
+ print_fixup (fixP);
+#endif
+ } /* For each fixS in this segment. */
+}
+
+static void
+fix_segment (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *sec,
+ void *xxx ATTRIBUTE_UNUSED)
+{
+ segment_info_type *seginfo = seg_info (sec);
+
+ fixup_segment (seginfo->fix_root, sec);
+}
+
+static void
+install_reloc (asection *sec, arelent *reloc, fragS *fragp,
+ const char *file, unsigned int line)
+{
+ char *err;
+ bfd_reloc_status_type s;
+ asymbol *sym;
+
+ if (reloc->sym_ptr_ptr != NULL
+ && (sym = *reloc->sym_ptr_ptr) != NULL
+ && (sym->flags & BSF_KEEP) == 0
+ && ((sym->flags & BSF_SECTION_SYM) == 0
+ || (EMIT_SECTION_SYMBOLS
+ && !bfd_is_abs_section (sym->section))))
+ as_bad_where (file, line, _("redefined symbol cannot be used on reloc"));
+
+ s = bfd_install_relocation (stdoutput, reloc,
+ fragp->fr_literal, fragp->fr_address,
+ sec, &err);
+ switch (s)
+ {
+ case bfd_reloc_ok:
+ break;
+ case bfd_reloc_overflow:
+ as_bad_where (file, line, _("relocation overflow"));
+ break;
+ case bfd_reloc_outofrange:
+ as_bad_where (file, line, _("relocation out of range"));
+ break;
+ default:
+ as_fatal (_("%s:%u: bad return from bfd_install_relocation: %x"),
+ file, line, s);
+ }
+}
+
+static fragS *
+get_frag_for_reloc (fragS *last_frag,
+ const segment_info_type *seginfo,
+ const struct reloc_list *r)
+{
+ fragS *f;
+
+ for (f = last_frag; f != NULL; f = f->fr_next)
+ if (f->fr_address <= r->u.b.r.address
+ && r->u.b.r.address < f->fr_address + f->fr_fix)
+ return f;
+
+ for (f = seginfo->frchainP->frch_root; f != NULL; f = f->fr_next)
+ if (f->fr_address <= r->u.b.r.address
+ && r->u.b.r.address < f->fr_address + f->fr_fix)
+ return f;
+
+ for (f = seginfo->frchainP->frch_root; f != NULL; f = f->fr_next)
+ if (f->fr_address <= r->u.b.r.address
+ && r->u.b.r.address <= f->fr_address + f->fr_fix)
+ return f;
+
+ as_bad_where (r->file, r->line,
+ _("reloc not within (fixed part of) section"));
+ return NULL;
+}
+
+static void
+write_relocs (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
+ void *xxx ATTRIBUTE_UNUSED)
+{
+ segment_info_type *seginfo = seg_info (sec);
+ unsigned int n;
+ struct reloc_list *my_reloc_list, **rp, *r;
+ arelent **relocs;
+ fixS *fixp;
+ fragS *last_frag;
+
+ /* If seginfo is NULL, we did not create this section; don't do
+ anything with it. */
+ if (seginfo == NULL)
+ return;
+
+ n = 0;
+ for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
+ if (!fixp->fx_done)
+ n++;
+
+#ifdef RELOC_EXPANSION_POSSIBLE
+ n *= MAX_RELOC_EXPANSION;
+#endif
+
+ /* Extract relocs for this section from reloc_list. */
+ rp = &reloc_list;
+
+ my_reloc_list = NULL;
+ while ((r = *rp) != NULL)
+ {
+ if (r->u.b.sec == sec)
+ {
+ *rp = r->next;
+ r->next = my_reloc_list;
+ my_reloc_list = r;
+ n++;
+ }
+ else
+ rp = &r->next;
+ }
+
+ relocs = XCNEWVEC (arelent *, n);
+
+ n = 0;
+ r = my_reloc_list;
+ last_frag = NULL;
+ for (fixp = seginfo->fix_root; fixp != (fixS *) NULL; fixp = fixp->fx_next)
+ {
+ int fx_size, slack;
+ valueT loc;
+ arelent **reloc;
+#ifndef RELOC_EXPANSION_POSSIBLE
+ arelent *rel;
+
+ reloc = &rel;
+#endif
+
+ if (fixp->fx_done)
+ continue;
+
+ fx_size = fixp->fx_size;
+ slack = TC_FX_SIZE_SLACK (fixp);
+ if (slack > 0)
+ fx_size = fx_size > slack ? fx_size - slack : 0;
+ loc = fixp->fx_where + fx_size;
+ if (slack >= 0 && loc > fixp->fx_frag->fr_fix)
+ as_bad_where (fixp->fx_file, fixp->fx_line,
+ _("internal error: fixup not contained within frag"));
+
+#ifndef RELOC_EXPANSION_POSSIBLE
+ *reloc = tc_gen_reloc (sec, fixp);
+#else
+ reloc = tc_gen_reloc (sec, fixp);
+#endif
+
+ while (*reloc)
+ {
+ while (r != NULL && r->u.b.r.address < (*reloc)->address)
+ {
+ fragS *f = get_frag_for_reloc (last_frag, seginfo, r);
+ if (f != NULL)
+ {
+ last_frag = f;
+ relocs[n++] = &r->u.b.r;
+ install_reloc (sec, &r->u.b.r, f, r->file, r->line);
+ }
+ r = r->next;
+ }
+ relocs[n++] = *reloc;
+ install_reloc (sec, *reloc, fixp->fx_frag,
+ fixp->fx_file, fixp->fx_line);
+#ifndef RELOC_EXPANSION_POSSIBLE
+ break;
+#else
+ reloc++;
+#endif
+ }
+ }
+
+ while (r != NULL)
+ {
+ fragS *f = get_frag_for_reloc (last_frag, seginfo, r);
+ if (f != NULL)
+ {
+ last_frag = f;
+ relocs[n++] = &r->u.b.r;
+ install_reloc (sec, &r->u.b.r, f, r->file, r->line);
+ }
+ r = r->next;
+ }
+
+#ifdef DEBUG4
+ {
+ unsigned int k, j, nsyms;
+ asymbol **sympp;
+ sympp = bfd_get_outsymbols (stdoutput);
+ nsyms = bfd_get_symcount (stdoutput);
+ for (k = 0; k < n; k++)
+ if (((*relocs[k]->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)