This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] Add --pcrel sanity checks
- From: Bernardo Innocenti <bernie at develer dot com>
- To: binutils at sources dot redhat dot com
- Date: Sun, 12 Oct 2003 03:37:25 +0200
- Subject: [PATCH] Add --pcrel sanity checks
- Organization: Develer S.r.l.
Hello,
this patch has been in use on uClinux for a very long time,
so it's well tested.
I don't have CVS write access on sources.redhat.com,
please apply it for me if it looks OK.
2003-10-12 Paul Dale <pauli@snapgear.com>
Bernardo Innocenti <bernie@develer.com>
* config/tc-m68k.c (make_pcrel_absolute): Enforce
PC-relative jumps with --pcrel.
(md_convert_frag_1): Likewise.
(md_create_long_jump): Likewise.
diff -Nrup binutils-2.14.90.0.4.orig/gas/config/tc-m68k.c binutils-2.14.90.0.4/gas/config/tc-m68k.c
--- binutils-2.14.90.0.4.orig/gas/config/tc-m68k.c 2003-08-03 03:30:38.000000000 +0200
+++ binutils-2.14.90.0.4/gas/config/tc-m68k.c 2003-08-04 02:05:13.000000000 +0200
@@ -681,11 +681,15 @@ make_pcrel_absolute(fixP, add_number)
*/
if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP */
{
+ if (flag_keep_pcrel)
+ as_fatal(_("Tried to convert PC relative branch to absolute jump"));
opcode[0] = 0x4e;
opcode[1] = 0xf9;
}
else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR */
{
+ if (flag_keep_pcrel)
+ as_fatal(_("Tried to convert PC relative BSR to absolute JSR"));
opcode[0] = 0x4e;
opcode[1] = 0xb9;
}
@@ -4553,6 +4581,8 @@ md_convert_frag_1 (fragP)
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"));
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,
@@ -4561,6 +4591,8 @@ md_convert_frag_1 (fragP)
}
else if (fragP->fr_opcode[0] == 0x60) /* jbra */
{
+ if (flag_keep_pcrel)
+ as_fatal(_("Tried to convert 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,
@@ -4575,6 +4607,8 @@ md_convert_frag_1 (fragP)
}
break;
case TAB (BRABSJCOND, LONG):
+ if (flag_keep_pcrel)
+ as_fatal(_("Tried to convert PC relative conditional branch to absolute jump"));
/* Only Bcc 68000 instructions can come here. */
/* Change bcc into b!cc/jmp absl long. */
@@ -4614,6 +4648,8 @@ md_convert_frag_1 (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"));
*buffer_address++ = 0x00; /* branch offset = 4 */
*buffer_address++ = 0x04;
*buffer_address++ = 0x60; /* put in bra pc+6 */
@@ -4627,6 +4663,8 @@ md_convert_frag_1 (fragP)
fragP->fr_fix += 4;
break;
case TAB (DBCCABSJ, LONG):
+ if (flag_keep_pcrel)
+ as_fatal(_("Tried to convert PC relative conditional branch to absolute jump"));
/* only DBcc instructions can come here */
/* Change dbcc into dbcc/jmp. */
@@ -4692,6 +4730,8 @@ md_convert_frag_1 (fragP)
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"));
/* 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)
@@ -4953,6 +4993,8 @@ md_create_long_jump (ptr, from_addr, to_
if (!HAVE_LONG_BRANCH(current_architecture))
{
+ if (flag_keep_pcrel)
+ as_fatal(_("Tried to convert PC relative branch to absolute jump"));
offset = to_addr - S_GET_VALUE (to_symbol);
md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
md_number_to_chars (ptr + 2, (valueT) offset, 4);
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/
Please don't send Word attachments - http://www.gnu.org/philosophy/no-word-attachments.html