This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] MIPS/GAS: Correct file option settings with `.insn'
- From: "Maciej W. Rozycki" <macro at codesourcery dot com>
- To: <binutils at sourceware dot org>
- Date: Sun, 12 Oct 2014 01:05:03 +0100
- Subject: [PATCH] MIPS/GAS: Correct file option settings with `.insn'
- Authentication-results: sourceware.org; auth=none
Hi,
Noticed in fixing some GDB DWARF-2 tests for the MIPS target -- if the
`.insn' directive is used at the beginning of a source file before any
instructions have been produced, then any symbols it affects will have the
MIPS16 flag set. This is because we don't call `file_mips_check_options'
from `s_insn' and as a result the initial value of -1 of
`mips_opts.mips16' is taken as true because all the checks throughout GAS
merely compare it against zero, e.g. `HAVE_CODE_COMPRESSION'. The result
is seen in the dump below, where `foo' has the 0xf0 aka `STO_MIPS16' flag
set.
In fixing this bug additionally I noticed the `EF_MIPS_ARCH_ASE_M16' or
`EF_MIPS_ARCH_ASE_MICROMIPS' flag isn't set as appropriate if only `.insn'
directives have been used to produce code, typically from handcoded
instruction words. This is because `file_ase_mips16' and
`file_ase_micromips' are only set in `append_insn'. They need to be set
as appropriate in `s_insn', because `.insn' is meant as an assembly
instruction equivalent and any data that follows is supposed to be
interpreted as machine code for the ISA mode currently selected. The
problem is seen in the dump below where disassembly of `bar' shows the
standard MIPS ISA hexadecimal instruction encoding.
This is fixed with the change below and a corresponding test case is
provided the source of which has been used to produce this incorrect dump
too:
insn-opts.o: file format elf32-tradbigmips
SYMBOL TABLE:
00000000 l d .text 00000000 .text
00000000 g F .text 00000004 0xf0 foo
00000004 g F .text 00000004 0x80 bar
00000008 g O .text 00000004 baz
Disassembly of section .text:
00000000 <foo> 0000 addiu s0,sp,0
00000002 <foo+0x2> 0000 addiu s0,sp,0
00000004 <bar> 00000000 nop
00000008 <baz> 00000000 00000000 ........
Regression-tested against the usual MIPS targets. OK to apply?
2014-10-12 Maciej W. Rozycki <macro@codesourcery.com>
gas/
* config/tc-mips.c (s_insn): Set file options.
gas/testsuite/
* gas/mips/insn-opts.d: New test.
* gas/mips/insn-opts.s: New test source.
* gas/mips/mips.exp: Run the new test.
Maciej
binutils-gas-mips-insn-check-options.diff
Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c 2014-08-21 13:05:39.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c 2014-10-11 23:15:09.817805607 +0100
@@ -16003,6 +16003,10 @@ s_cpadd (int ignore ATTRIBUTE_UNUSED)
static void
s_insn (int ignore ATTRIBUTE_UNUSED)
{
+ file_mips_check_options ();
+ file_ase_mips16 |= mips_opts.mips16;
+ file_ase_micromips |= mips_opts.micromips;
+
mips_mark_labels ();
demand_empty_rest_of_line ();
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/insn-opts.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/insn-opts.d 2014-10-12 00:07:31.157624404 +0100
@@ -0,0 +1,18 @@
+#objdump: -dtz -j .text --prefix-addresses --show-raw-insn
+#name: MIPS .insn default file options
+
+# Check that .insn at the beginning of assembly sees default file options
+# such as the ISA mode right.
+
+.*: +file format .*mips.*
+
+SYMBOL TABLE:
+0+000000 l d \.text 0+000000 \.text
+0+000000 g F \.text 0+000004 foo
+0+000004 g F \.text 0+000004 0x80 bar
+0+000008 g O \.text 0+000004 baz
+
+Disassembly of section \.text:
+0+000000 <foo> 00000000 nop
+0+000004 <bar> 0000 0000 nop
+0+000008 <baz> .*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/insn-opts.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/insn-opts.s 2014-10-11 22:49:24.147986735 +0100
@@ -0,0 +1,23 @@
+ .text
+
+ .globl foo
+ .type foo, @function
+foo:
+ .insn
+ .dc.l 0
+ .size foo, . - foo
+
+ .set micromips
+
+ .globl bar
+ .type bar, @function
+bar:
+ .insn
+ .dc.l 0
+ .size bar, . - bar
+
+ .globl baz
+ .type baz, @object
+baz:
+ .dc.l 0
+ .size baz, . - baz
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/mips.exp 2014-08-21 13:00:22.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp 2014-10-11 23:02:15.228926461 +0100
@@ -1097,6 +1097,7 @@ if { [istarget mips*-*-vxworks*] } {
run_dump_test "align3"
run_dump_test "odd-float"
run_dump_test "ehword"
+ run_dump_test "insn-opts"
run_list_test_arches "mips-macro-ill-sfp" "-32 -msingle-float" \
[mips_arch_list_matching mips2]