/* tc-mmix.c -- Assembler for Don Knuth's MMIX.
- Copyright (C) 2001, 2002 Free Software Foundation.
+ Copyright (C) 2001, 2002, 2003 Free Software Foundation.
This file is part of GAS, the GNU Assembler.
static void mmix_discard_rest_of_line PARAMS ((void));
static void mmix_byte PARAMS ((void));
static void mmix_cons PARAMS ((int));
-static void mmix_frob_local_reloc PARAMS ((bfd *, asection *, PTR));
/* Continue the tradition of symbols.c; use control characters to enforce
magic. These are used when replacing e.g. 8F and 8B so we can handle
/* Support " .local $45" syntax. */
{"local", mmix_s_local, 1},
- /* Support DWARF2 debugging info. */
- {"file", (void (*) PARAMS ((int))) dwarf2_directive_file, 0},
- {"loc", dwarf2_directive_loc, 0},
-
{NULL, 0, 0}
};
input_line_pointer = p;
+ /* Initialize both possible operands to error state, in case we never
+ get further. */
+ exp[0].X_op = O_illegal;
+ exp[1].X_op = O_illegal;
+
if (insn->operands == mmix_operands_get)
{
expp_reg = &exp[0];
expp_sreg = &exp[0];
expp_reg = &exp[1];
- /* Initialize to error state in case we'll never call expression on
- this operand. */
- expp_reg->X_op = O_illegal;
-
sregp = p;
c = get_symbol_end ();
sregend = p = input_line_pointer;
case STATE_GREG_DEF:
if (fragP->tc_frag_data == NULL)
{
+ /* We must initialize data that's supposed to be "fixed up" to
+ avoid emitting garbage, because md_apply_fix3 won't do
+ anything for undefined symbols. */
+ md_number_to_chars (var_partp, 0, 8);
tmpfixP
= fix_new (fragP, var_partp - fragP->fr_literal, 8,
fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_64);
&& symsec != absolute_section
&& ((fixP->fx_r_type != BFD_RELOC_MMIX_REG
&& fixP->fx_r_type != BFD_RELOC_MMIX_REG_OR_BYTE)
- || (symsec != reg_section
- && symsec != real_reg_section)))))
+ || symsec != reg_section))))
{
fixP->fx_done = 0;
return;
case BFD_RELOC_MMIX_REG_OR_BYTE:
if (fixP->fx_addsy != NULL
- && (S_GET_SEGMENT (fixP->fx_addsy) != real_reg_section
+ && (S_GET_SEGMENT (fixP->fx_addsy) != reg_section
|| S_GET_VALUE (fixP->fx_addsy) > 255)
&& S_GET_SEGMENT (fixP->fx_addsy) != absolute_section)
- as_bad_where (fixP->fx_file, fixP->fx_line,
- _("invalid operands"));
+ {
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("invalid operands"));
+ /* We don't want this "symbol" appearing in output, because
+ that will fail. */
+ fixP->fx_done = 1;
+ }
+
buf[0] = val;
/* If this reloc is for a Z field, we need to adjust
&& (fixP->fx_addsy == NULL
|| S_GET_SEGMENT (fixP->fx_addsy) == absolute_section))
buf[-3] |= IMM_OFFSET_BIT;
-
- /* We don't want this "symbol" appearing in output, because that
- will fail. */
- if (fixP->fx_addsy
- && S_GET_SEGMENT (fixP->fx_addsy) == real_reg_section)
- symbol_clear_used_in_reloc (fixP->fx_addsy);
break;
case BFD_RELOC_MMIX_REG:
if (fixP->fx_addsy == NULL
- || S_GET_SEGMENT (fixP->fx_addsy) != real_reg_section
+ || S_GET_SEGMENT (fixP->fx_addsy) != reg_section
|| S_GET_VALUE (fixP->fx_addsy) > 255)
- as_bad_where (fixP->fx_file, fixP->fx_line,
- _("invalid operands"));
- *buf = val;
+ {
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("invalid operands"));
+ fixP->fx_done = 1;
+ }
- if (fixP->fx_addsy
- && S_GET_SEGMENT (fixP->fx_addsy) == real_reg_section)
- symbol_clear_used_in_reloc (fixP->fx_addsy);
+ *buf = val;
break;
case BFD_RELOC_MMIX_BASE_PLUS_OFFSET:
/* Unmark this symbol as used in a reloc, so we don't bump into a BFD
assert when trying to output reg_section. FIXME: A gas bug. */
- if (addsy)
- symbol_clear_used_in_reloc (addsy);
+ fixP->fx_addsy = NULL;
return NULL;
}
fixS *fixP;
{
if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
- || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
- || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
|| fixP->fx_r_type == BFD_RELOC_MMIX_BASE_PLUS_OFFSET)
return 1;
- /* FIXME: This is dubious. Handling of weak symbols should have been
- caught before we get here. */
- if ((fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy)))
- return 1;
-
if (linkrelax)
return 1;
if (fixP->fx_pcrel)
return 1;
- return 0;
+ return generic_force_reloc (fixP);
}
/* The location from which a PC relative jump should be calculated,
}
/* Adjust the symbol table. We make reg_section relative to the real
- register section.
-
- FIXME: There's a gas bug; should be fixed when the reg_section symbol
- is "accidentally" saved for relocs which are really fixups that will be
- fixed up. */
+ register section. */
void
mmix_adjust_symtab ()
{
symbolS *sym;
- symbolS *prevsym;
symbolS *regsec = section_symbol (reg_section);
- segT realregsec = NULL;
- for (prevsym = sym = symbol_rootP;
- sym != NULL;
- prevsym = sym, sym = symbol_next (sym))
+ for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
if (S_GET_SEGMENT (sym) == reg_section)
{
- if (sym == regsec
- || (!S_IS_EXTERN (sym) && !symbol_used_in_reloc_p (sym)))
+ if (sym == regsec)
{
+ if (S_IS_EXTERN (sym) || symbol_used_in_reloc_p (sym))
+ abort ();
symbol_remove (sym, &symbol_rootP, &symbol_lastP);
-
- /* We make one extra turn, or we'll lose the next symbol. We
- assume that the symbol we remove is not the symbol root
- (.text normally is). */
- sym = prevsym;
}
else
- {
- /* Change section to the *real* register section, so it gets
- proper treatment when writing it out. Only do this for
- global symbols. This also means we don't have to check for
- $0..$255. */
- if (realregsec == NULL)
- realregsec
- = bfd_make_section_old_way (stdoutput, MMIX_REG_SECTION_NAME);
-
- S_SET_SEGMENT (sym, realregsec);
- }
+ /* Change section to the *real* register section, so it gets
+ proper treatment when writing it out. Only do this for
+ global symbols. This also means we don't have to check for
+ $0..$255. */
+ S_SET_SEGMENT (sym, real_reg_section);
}
}
return 1;
}
-/* Worker for mmix_frob_file_before_adjust. */
-
-static void
-mmix_frob_local_reloc (abfd, sec, xxx)
- bfd *abfd ATTRIBUTE_UNUSED;
- asection *sec;
- PTR xxx ATTRIBUTE_UNUSED;
-{
- segment_info_type *seginfo = seg_info (sec);
- fixS *fixp;
-
- if (seginfo == NULL)
- return;
-
- for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
- if (! fixp->fx_done && fixp->fx_addsy != NULL)
- {
- symbolS *sym = fixp->fx_addsy;
- asection *section = S_GET_SEGMENT (sym);
-
- if (section == reg_section
- && fixp->fx_r_type == BFD_RELOC_MMIX_LOCAL)
- {
- /* If the register is marked global, we don't need to replace
- with the *real* register section since that will be done
- when the symbol is changed. */
- if (! S_IS_EXTERNAL (sym))
- /* If it's a local symbol, we replace it with an anonymous
- one with the same constant value. */
- fixp->fx_addsy = expr_build_uconstant (S_GET_VALUE (sym));
- }
- }
-}
-
-/* Change fixups for register symbols for BFD_MMIX_LOCAL to be for an
- absolute symbol. */
-
-void
-mmix_frob_file_before_adjust ()
-{
- return;
- bfd_map_over_sections (stdoutput, mmix_frob_local_reloc, (char *) 0);
-}
-
/* Just check that we don't have a BSPEC/ESPEC pair active when changing
sections "normally", and get knowledge about alignment from the new
section. */