This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH 4/4] MIPS/GAS: Actual o32 SVR4 PIC JAL macro delay slot fix
- From: "Maciej W. Rozycki" <macro at codesourcery dot com>
- To: binutils at sourceware dot org
- Cc: Richard Sandiford <rdsandiford at googlemail dot com>, Catherine Moore <clm at codesourcery dot com>, gnu-mips-sgxx at codesourcery dot com
- Date: Tue, 20 Jul 2010 12:43:53 +0100 (BST)
- Subject: [PATCH 4/4] MIPS/GAS: Actual o32 SVR4 PIC JAL macro delay slot fix
Hi,
This is a change that fixes a problem when code like this:
.set noreorder
jal $25
.set reorder
is assembled to a piece like this with the o32 ABI:
jalr $25
lw $gp, 0($sp)
rather than the expected:
jalr $25
nop
lw $gp, 0($sp)
making the reload of the GOT pointer to happen before the function call
rather than afterwards. Since it's within a macro rather than between
macros/instructions, noreorder shouldn't place the LW into the delay slot
breaking the macro irrecoverably.
A similar JAL macro expanded with the use of a symbol rather than a
register:
.set noreorder
jal foo
.set reorder
works correctly already by scheduling an extra NOP between the JALR and
the LW in the noreorder mode.
Both macros are covered by the included test case, trivially derived from
jal-svr4pic.
2010-07-20 Maciej W. Rozycki <macro@codesourcery.com>
gas/
* config/tc-mips.c (macro)[M_JAL_1, M_JAL_2]: Handle the JALR
delay slot in the noreorder mode with the o32 ABI.
gas/testsuite/
* gas/mips/jal-svr4pic-noreorder.d: New test case.
* gas/mips/mips1@jal-svr4pic-noreorder.d: New test
subarchitecture.
* gas/mips/r3000@jal-svr4pic-noreorder.d: Likewise.
* gas/mips/jal-svr4pic-noreorder.s: Source for the new test
case.
* gas/mips/mips.exp: Run the new test case.
OK to commit?
Maciej
binutils-jal-svr4pic-noreorder.diff
Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c 2010-07-20 00:35:37.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c 2010-07-20 00:48:16.000000000 +0100
@@ -6219,6 +6219,8 @@
/* Quiet this warning. */
mips_cprestore_valid = 1;
}
+ if (mips_opts.noreorder)
+ macro_build (NULL, "nop", "");
expr1.X_add_number = mips_cprestore_offset;
macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
mips_gp_register,
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/jal-svr4pic-noreorder.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/jal-svr4pic-noreorder.d 2010-07-20 00:48:16.000000000 +0100
@@ -0,0 +1,45 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS jal-svr4pic noreorder
+#as: -32 -KPIC
+#source: jal-svr4pic-noreorder.s
+
+# Test the jal macro with -KPIC and `.set noreorder'.
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> 3c1c0000 lui gp,0x0
+[ ]*0: R_MIPS_HI16 _gp_disp
+[0-9a-f]+ <[^>]*> 279c0000 addiu gp,gp,0
+[ ]*4: R_MIPS_LO16 _gp_disp
+[0-9a-f]+ <[^>]*> 0399e021 addu gp,gp,t9
+[0-9a-f]+ <[^>]*> afbc0000 sw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 03202009 jalr a0,t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 8f990000 lw t9,0\(gp\)
+[ ]*28: R_MIPS_GOT16 .text
+[0-9a-f]+ <[^>]*> 27390000 addiu t9,t9,0
+[ ]*2c: R_MIPS_LO16 .text
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*30: R_MIPS_JALR text_label
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 8f990000 lw t9,0\(gp\)
+[ ]*3c: R_MIPS_CALL16 weak_text_label
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*40: R_MIPS_JALR weak_text_label
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 8f990000 lw t9,0\(gp\)
+[ ]*4c: R_MIPS_CALL16 external_text_label
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*50: R_MIPS_JALR external_text_label
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 1000ffe8 b 0+0000 <text_label>
+[0-9a-f]+ <[^>]*> 00000000 nop
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/jal-svr4pic-noreorder.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/jal-svr4pic-noreorder.s 2010-07-20 02:37:29.000000000 +0100
@@ -0,0 +1,27 @@
+# Source file used to test the jal macro with -KPIC code.
+
+ .weak weak_text_label
+
+ .ent text_label
+text_label:
+ .frame $sp, 0, $31
+ .set noreorder
+ .cpload $25
+ .cprestore 0
+ jal $25
+ jal $4, $25
+ jal text_label
+ jal weak_text_label
+ jal external_text_label
+
+# Test j as well.
+ j text_label
+ .set reorder
+ nop
+
+ .end text_label
+ .size text_label, . - text_label
+
+# Force at least 8 (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 2
+ .space 8
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/mips.exp 2010-07-20 00:48:14.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp 2010-07-20 00:48:16.000000000 +0100
@@ -465,6 +465,8 @@
if $elf {
run_dump_test_arches "jal-svr4pic" \
[mips_arch_list_matching mips1]
+ run_dump_test_arches "jal-svr4pic-noreorder" \
+ [mips_arch_list_matching mips1]
}
if $elf { run_dump_test "jal-xgot" }
run_list_test_arches "jal-range" "-32" [mips_arch_list_matching mips1]
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips1@jal-svr4pic-noreorder.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips1@jal-svr4pic-noreorder.d 2010-07-20 00:48:16.000000000 +0100
@@ -0,0 +1,48 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS jal-svr4pic noreorder
+#as: -32 -KPIC
+#source: jal-svr4pic-noreorder.s
+
+# Test the jal macro with -KPIC and `.set noreorder' (MIPS1).
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> 3c1c0000 lui gp,0x0
+[ ]*0: R_MIPS_HI16 _gp_disp
+[0-9a-f]+ <[^>]*> 279c0000 addiu gp,gp,0
+[ ]*4: R_MIPS_LO16 _gp_disp
+[0-9a-f]+ <[^>]*> 0399e021 addu gp,gp,t9
+[0-9a-f]+ <[^>]*> afbc0000 sw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 03202009 jalr a0,t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 8f990000 lw t9,0\(gp\)
+[ ]*28: R_MIPS_GOT16 .text
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 27390000 addiu t9,t9,0
+[ ]*30: R_MIPS_LO16 .text
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*34: R_MIPS_JALR text_label
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 8f990000 lw t9,0\(gp\)
+[ ]*40: R_MIPS_CALL16 weak_text_label
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*48: R_MIPS_JALR weak_text_label
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 8f990000 lw t9,0\(gp\)
+[ ]*54: R_MIPS_CALL16 external_text_label
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*5c: R_MIPS_JALR external_text_label
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 8fbc0000 lw gp,0\(sp\)
+[0-9a-f]+ <[^>]*> 1000ffe5 b 0+0000 <text_label>
+[0-9a-f]+ <[^>]*> 00000000 nop
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/r3000@jal-svr4pic-noreorder.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/r3000@jal-svr4pic-noreorder.d 2010-07-20 00:48:16.000000000 +0100
@@ -0,0 +1,5 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS jal-svr4pic noreorder
+#as: -32 -KPIC
+#source: jal-svr4pic-noreorder.s
+#dump: mips1@jal-svr4pic-noreorder.d