This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] MIPS/GAS: Correct ISA bit handling in backreferences
- From: "Maciej W. Rozycki" <macro at codesourcery dot com>
- To: <binutils at sourceware dot org>
- Cc: Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Fri, 21 Sep 2012 17:19:00 +0100
- Subject: [PATCH] MIPS/GAS: Correct ISA bit handling in backreferences
Hi,
While working on a test case for a bug fix I am going to send next I
noticed he ISA bit is not set correctly in references to labels applied to
the instruction being assembled, for example in this calculation:
.set micromips
0:
nop
1:
li $2, 1b - 0b
the value loaded to $2 will be 1 rather than expected 2. This is because
at the point the subtraction is evaluated the internal symbol associated
with the 0 label has the ISA bit set and the symbol used for 1 has the ISA
bit clear. This happens because the ISA bit is only calculated for labels
once the respective instructions they have been applied to have been
completely assembled each. This affects both MIPS16 and microMIPS code
and looks like a long-standing bug.
The change below adds a call to mips_mark_labels at the beginning of
instruction processing so that the ISA bit is updated on the internal
symbol straight away. The function is called in several places already
and further auditing may be desirable to move or remove some of the other
ones that may have become redundant with this change. This is however not
strictly necessary.
An update to a test case source complements the change -- it inadvertenly
relied on the bug and escaped the case where the argument to the first ORI
is 0x3fffffff owing to the difference calculated coming out as -1. This
is fixed by ensuring the ISA bit is clear on the label used for the
subtraction. No other test regressions were observed.
I made no separate test case for this change, it is covered by the test
case referred above that I'll be sending shortly.
OK to apply?
2012-09-21 Maciej W. Rozycki <macro@codesourcery.com>
gas/
* config/tc-mips.c (md_assemble): Add a call to mips_mark_labels.
gas/testsuite/
* gas/mips/branch-swap-2.s: Make sure the ISA bit is clear in
the label used for calculation.
Maciej
binutils-gas-mips-mark-labels.diff
Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c 2012-09-18 17:46:57.251764230 +0100
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c 2012-09-18 17:47:14.691764019 +0100
@@ -2555,6 +2555,8 @@ md_assemble (char *str)
offset_reloc[1] = BFD_RELOC_UNUSED;
offset_reloc[2] = BFD_RELOC_UNUSED;
+ mips_mark_labels ();
+
if (mips_opts.mips16)
mips16_ip (str, &insn);
else
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/branch-swap-2.s
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/branch-swap-2.s 2012-09-18 17:46:57.251764230 +0100
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/branch-swap-2.s 2012-09-18 17:47:14.691764019 +0100
@@ -1,8 +1,11 @@
.set micromips
.text
foo:
+ .insn # Keep the ISA bit set on foo.
+bar:
+ .fill 0 # Keep the ISA bit clear on bar.
.rept count
- ori $2, $3, (. - foo) >> 2
+ ori $2, $3, (. - bar) >> 2
.endr
addu $2, $3, $4
j ext