* [PATCH 4/4] MIPS/GAS: Actual o32 SVR4 PIC JAL macro delay slot fix
@ 2010-07-20 11:44 Maciej W. Rozycki
2010-07-21 19:19 ` Richard Sandiford
0 siblings, 1 reply; 2+ messages in thread
From: Maciej W. Rozycki @ 2010-07-20 11:44 UTC (permalink / raw)
To: binutils; +Cc: Richard Sandiford, Catherine Moore, gnu-mips-sgxx
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 4/4] MIPS/GAS: Actual o32 SVR4 PIC JAL macro delay slot fix
2010-07-20 11:44 [PATCH 4/4] MIPS/GAS: Actual o32 SVR4 PIC JAL macro delay slot fix Maciej W. Rozycki
@ 2010-07-21 19:19 ` Richard Sandiford
0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2010-07-21 19:19 UTC (permalink / raw)
To: Maciej W. Rozycki; +Cc: binutils, Catherine Moore, gnu-mips-sgxx
"Maciej W. Rozycki" <macro@codesourcery.com> writes:
> 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, thanks.
Richard
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-07-21 19:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-20 11:44 [PATCH 4/4] MIPS/GAS: Actual o32 SVR4 PIC JAL macro delay slot fix Maciej W. Rozycki
2010-07-21 19:19 ` Richard Sandiford
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).