This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
better m68k assembler errors
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: binutils at sources dot redhat dot com, Ben Elliston <bje at au1 dot ibm dot com>
- Date: Wed, 16 May 2007 14:49:46 +0100
- Subject: better m68k assembler errors
I was tracking down an out-of-range displacement error, and the assembler's
error message is useless, for it doesn't tell you what the out of range value
was, and points you to the end of the source file ... which is no help.
This patch fixes things so that the value is printed and the location
information is propagated to the fixup.
I also noticed the merge tests were now failing, because the message is an
error, rather than a warning.
... now to persuade the compiler to not generate out of range displacements :)
ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2007-05-16 Nathan Sidwell <nathan@codesourcery.com>
ld/testsuite/
* ld-m68k-merge-error-1a.d: Mismatch is an error.
* ld-m68k-merge-error-1b.d: Likewise.
* ld-m68k-merge-error-1c.d: Likewise.
* ld-m68k-merge-error-1d.d: Likewise.
* ld-m68k-merge-error-1e.d: Likewise.
gas/
* config/tc-m68k.c (md_apply_fix): Show value of out of range
fixups in error message.
(md_conver_frag_1): Propagate the fix source location and use
as_bad_where rather than fatal, for better error messages.
Index: ld/testsuite/ld-m68k/merge-error-1a.d
===================================================================
--- ld/testsuite/ld-m68k/merge-error-1a.d (revision 171055)
+++ ld/testsuite/ld-m68k/merge-error-1a.d (working copy)
@@ -1,4 +1,4 @@
#source: merge-error-1a.s -mcpu=cpu32
#source: merge-error-1b.s -mcpu=68000
#ld: -r
-#warning: .*
+#error: ^[^\n]* m68k:68000 [^\n]* incompatible with m68k:cpu32 [^\n]*$
Index: ld/testsuite/ld-m68k/merge-error-1b.d
===================================================================
--- ld/testsuite/ld-m68k/merge-error-1b.d (revision 171055)
+++ ld/testsuite/ld-m68k/merge-error-1b.d (working copy)
@@ -1,4 +1,4 @@
#source: merge-error-1a.s -mcpu=cpu32
#source: merge-error-1b.s -mcpu=5207
#ld: -r
-#warning: .*
+#error: ^[^\n]* m68k:isa-aplus:emac [^\n]* incompatible with m68k:cpu32 [^\n]*$
Index: ld/testsuite/ld-m68k/merge-error-1c.d
===================================================================
--- ld/testsuite/ld-m68k/merge-error-1c.d (revision 171055)
+++ ld/testsuite/ld-m68k/merge-error-1c.d (working copy)
@@ -1,4 +1,4 @@
#source: merge-error-1a.s -march=isaaplus
#source: merge-error-1b.s -march=isab
#ld: -r
-#warning: .*
+#error: ^[^\n]* m68k:isa-b [^\n]* incompatible with m68k:isa-aplus [^\n]*$
Index: ld/testsuite/ld-m68k/merge-error-1d.d
===================================================================
--- ld/testsuite/ld-m68k/merge-error-1d.d (revision 171055)
+++ ld/testsuite/ld-m68k/merge-error-1d.d (working copy)
@@ -1,4 +1,4 @@
#source: merge-error-1a.s -march=isaa -mmac
#source: merge-error-1b.s -march=isaa -memac
#ld: -r
-#warning: .*
+#error: ^[^\n]* m68k:isa-a:emac [^\n]* incompatible with m68k:isa-a:mac [^\n]*$
Index: ld/testsuite/ld-m68k/merge-error-1e.d
===================================================================
--- ld/testsuite/ld-m68k/merge-error-1e.d (revision 171055)
+++ ld/testsuite/ld-m68k/merge-error-1e.d (working copy)
@@ -1,4 +1,4 @@
#source: merge-error-1a.s -march=isaa -mno-div -mmac
#source: merge-error-1b.s -march=isaa -mno-div -memac
#ld: -r
-#warning: .*
+#error: ^[^\n]* m68k:isa-a:emac [^\n]* is incompatible with m68k:isa-a:mac [^\n]*$
Index: gas/config/tc-m68k.c
===================================================================
--- gas/config/tc-m68k.c (revision 171055)
+++ gas/config/tc-m68k.c (working copy)
@@ -4758,7 +4758,8 @@ md_apply_fix (fixS *fixP, valueT *valP,
if ((addressT) val > upper_limit
&& (val > 0 || val < lower_limit))
- as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("value %ld out of range"), (long)val);
/* A one byte PC-relative reloc means a short branch. We can't use
a short branch with a value of 0 or -1, because those indicate
@@ -4771,7 +4772,8 @@ md_apply_fix (fixS *fixP, valueT *valP,
&& (fixP->fx_addsy == NULL
|| S_IS_DEFINED (fixP->fx_addsy))
&& (val == 0 || val == -1))
- as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("invalid byte branch offset"));
}
/* *fragP has been relaxed to its final size, and now needs to have
@@ -4782,7 +4784,7 @@ static void
md_convert_frag_1 (fragS *fragP)
{
long disp;
- fixS *fixP;
+ fixS *fixP = NULL;
/* Address in object code of the displacement. */
register int object_address = fragP->fr_fix + fragP->fr_address;
@@ -4817,35 +4819,37 @@ md_convert_frag_1 (fragS *fragP)
case TAB (BRABSJCOND, SHORT):
case TAB (BRANCHBW, SHORT):
fragP->fr_opcode[1] = 0x00;
- fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
- 1, RELAX_RELOC_PC16);
+ fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
+ fragP->fr_offset, 1, RELAX_RELOC_PC16);
fragP->fr_fix += 2;
break;
case TAB (BRANCHBWL, LONG):
fragP->fr_opcode[1] = (char) 0xFF;
- fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
- 1, RELAX_RELOC_PC32);
+ fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
+ fragP->fr_offset, 1, RELAX_RELOC_PC32);
fragP->fr_fix += 4;
break;
case TAB (BRABSJUNC, LONG):
if (fragP->fr_opcode[0] == 0x61) /* jbsr */
{
if (flag_keep_pcrel)
- as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
+ as_bad_where (fragP->fr_file, fragP->fr_line,
+ _("Conversion of PC relative BSR to absolute JSR"));
fragP->fr_opcode[0] = 0x4E;
fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
- fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
- 0, RELAX_RELOC_ABS32);
+ fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
+ fragP->fr_offset, 0, RELAX_RELOC_ABS32);
fragP->fr_fix += 4;
}
else if (fragP->fr_opcode[0] == 0x60) /* jbra */
{
if (flag_keep_pcrel)
- as_fatal (_("Tried to convert PC relative branch to absolute jump"));
+ as_bad_where (fragP->fr_file, fragP->fr_line,
+ _("Conversion of PC relative branch to absolute jump"));
fragP->fr_opcode[0] = 0x4E;
fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
- fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
- 0, RELAX_RELOC_ABS32);
+ fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
+ fragP->fr_offset, 0, RELAX_RELOC_ABS32);
fragP->fr_fix += 4;
}
else
@@ -4857,7 +4861,8 @@ md_convert_frag_1 (fragS *fragP)
break;
case TAB (BRABSJCOND, LONG):
if (flag_keep_pcrel)
- as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
+ as_bad_where (fragP->fr_file, fragP->fr_line,
+ _("Conversion of PC relative conditional branch to absolute jump"));
/* Only Bcc 68000 instructions can come here
Change bcc into b!cc/jmp absl long. */
@@ -4870,26 +4875,26 @@ md_convert_frag_1 (fragS *fragP)
*buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
*buffer_address++ = (char) 0xf9;
fragP->fr_fix += 2; /* Account for jmp instruction. */
- fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
- fragP->fr_offset, 0, RELAX_RELOC_ABS32);
+ fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
+ fragP->fr_offset, 0, RELAX_RELOC_ABS32);
fragP->fr_fix += 4;
break;
case TAB (FBRANCH, SHORT):
know ((fragP->fr_opcode[1] & 0x40) == 0);
- fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
- 1, RELAX_RELOC_PC16);
+ fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
+ fragP->fr_offset, 1, RELAX_RELOC_PC16);
fragP->fr_fix += 2;
break;
case TAB (FBRANCH, LONG):
fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit. */
- fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
- 1, RELAX_RELOC_PC32);
+ fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
+ fragP->fr_offset, 1, RELAX_RELOC_PC32);
fragP->fr_fix += 4;
break;
case TAB (DBCCLBR, SHORT):
case TAB (DBCCABSJ, SHORT):
- fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
- 1, RELAX_RELOC_PC16);
+ fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
+ fragP->fr_offset, 1, RELAX_RELOC_PC16);
fragP->fr_fix += 2;
break;
case TAB (DBCCLBR, LONG):
@@ -4897,7 +4902,8 @@ md_convert_frag_1 (fragS *fragP)
Change dbcc into dbcc/bral.
JF: these used to be fr_opcode[2-7], but that's wrong. */
if (flag_keep_pcrel)
- as_fatal (_("Tried to convert DBcc to absolute jump"));
+ as_bad_where (fragP->fr_file, fragP->fr_line,
+ _("Conversion of DBcc to absolute jump"));
*buffer_address++ = 0x00; /* Branch offset = 4. */
*buffer_address++ = 0x04;
@@ -4907,8 +4913,8 @@ md_convert_frag_1 (fragS *fragP)
*buffer_address++ = (char) 0xff;
fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
- fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 1,
- RELAX_RELOC_PC32);
+ fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
+ fragP->fr_offset, 1, RELAX_RELOC_PC32);
fragP->fr_fix += 4;
break;
case TAB (DBCCABSJ, LONG):
@@ -4916,7 +4922,8 @@ md_convert_frag_1 (fragS *fragP)
Change dbcc into dbcc/jmp.
JF: these used to be fr_opcode[2-7], but that's wrong. */
if (flag_keep_pcrel)
- as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
+ as_bad_where (fragP->fr_file, fragP->fr_line,
+ _("Conversion of PC relative conditional branch to absolute jump"));
*buffer_address++ = 0x00; /* Branch offset = 4. */
*buffer_address++ = 0x04;
@@ -4926,15 +4933,15 @@ md_convert_frag_1 (fragS *fragP)
*buffer_address++ = (char) 0xf9;
fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
- fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 0,
- RELAX_RELOC_ABS32);
+ fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
+ fragP->fr_offset, 0, RELAX_RELOC_ABS32);
fragP->fr_fix += 4;
break;
case TAB (PCREL1632, SHORT):
fragP->fr_opcode[1] &= ~0x3F;
fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
- fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
- fragP->fr_offset, 1, RELAX_RELOC_PC16);
+ fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
+ fragP->fr_offset, 1, RELAX_RELOC_PC16);
fragP->fr_fix += 2;
break;
case TAB (PCREL1632, LONG):
@@ -4974,24 +4981,29 @@ md_convert_frag_1 (fragS *fragP)
fragP->fr_fix += 4;
break;
case TAB (ABSTOPCREL, SHORT):
- fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
- 1, RELAX_RELOC_PC16);
+ fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
+ fragP->fr_offset, 1, RELAX_RELOC_PC16);
fragP->fr_fix += 2;
break;
case TAB (ABSTOPCREL, LONG):
if (flag_keep_pcrel)
- as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
+ as_fatal (_("Conversion of PC relative displacement to absolute"));
/* The thing to do here is force it to ABSOLUTE LONG, since
ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
abort ();
fragP->fr_opcode[1] &= ~0x3F;
fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
- fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
- 0, RELAX_RELOC_ABS32);
+ fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
+ fragP->fr_offset, 0, RELAX_RELOC_ABS32);
fragP->fr_fix += 4;
break;
}
+ if (fixP)
+ {
+ fixP->fx_file = fragP->fr_file;
+ fixP->fx_line = fragP->fr_line;
+ }
}
void