From 9f00292e69635d48623372c7a3e390dc5d159a8f Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Sat, 1 Jul 2017 00:42:19 +0100 Subject: [PATCH] MIPS/GAS: Use non-zero frag offset directly in PIC branch relaxation Use frag symbols with a non-zero offset directly in `fix_new_exp' calls made in PIC branch relaxation. There is no need here to make a helper symbol to hold the result of a `symbol+offset' calculation requested as only branches to local symbols are relaxed and in this case the LO16 part of the PIC address load sequence will have the offset accounted for in calculation against the local GOT entry retrieved as the GOT16 high part. Consequently actual code produed is identical whether a helper symbol is used or the original `symbol+offset' expression used directly. Verify that this is indeed the case with GAS and LD tests. gas/ * config/tc-mips.c (md_convert_frag): Don't make a helper expression symbol for `fix_new_exp' called with a non-zero offset. * testsuite/gas/mips/relax-offset.d: New test. * testsuite/gas/mips/mips1@relax-offset.d: New test. * testsuite/gas/mips/r3000@relax-offset.d: New test. * testsuite/gas/mips/r3900@relax-offset.d: New test. * testsuite/gas/mips/micromips@relax-offset.d: New test. * testsuite/gas/mips/relax-offset.l: New stderr output. * testsuite/gas/mips/relax-offset.s: New test source. * testsuite/gas/mips/mips.exp: Run the new tests. ld/ * testsuite/ld-mips-elf/relax-offset.dd: New test. * testsuite/ld-mips-elf/relax-offset.gd: New test. * testsuite/ld-mips-elf/relax-offset-umips.dd: New test. * testsuite/ld-mips-elf/relax-offset-umips.gd: New test. * testsuite/ld-mips-elf/relax-offset.ld: New test linker script. * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests. (prune_warnings): New temporary procedure. --- gas/ChangeLog | 14 ++++++++ gas/config/tc-mips.c | 12 ------- .../gas/mips/micromips@relax-offset.d | 26 ++++++++++++++ gas/testsuite/gas/mips/mips.exp | 2 ++ gas/testsuite/gas/mips/mips1@relax-offset.d | 30 ++++++++++++++++ gas/testsuite/gas/mips/r3000@relax-offset.d | 6 ++++ gas/testsuite/gas/mips/r3900@relax-offset.d | 6 ++++ gas/testsuite/gas/mips/relax-offset.d | 28 +++++++++++++++ gas/testsuite/gas/mips/relax-offset.l | 2 ++ gas/testsuite/gas/mips/relax-offset.s | 23 +++++++++++++ ld/ChangeLog | 10 ++++++ ld/testsuite/ld-mips-elf/mips-elf.exp | 34 +++++++++++++++++++ .../ld-mips-elf/relax-offset-umips.dd | 15 ++++++++ .../ld-mips-elf/relax-offset-umips.gd | 11 ++++++ ld/testsuite/ld-mips-elf/relax-offset.dd | 19 +++++++++++ ld/testsuite/ld-mips-elf/relax-offset.gd | 11 ++++++ ld/testsuite/ld-mips-elf/relax-offset.ld | 16 +++++++++ 17 files changed, 253 insertions(+), 12 deletions(-) create mode 100644 gas/testsuite/gas/mips/micromips@relax-offset.d create mode 100644 gas/testsuite/gas/mips/mips1@relax-offset.d create mode 100644 gas/testsuite/gas/mips/r3000@relax-offset.d create mode 100644 gas/testsuite/gas/mips/r3900@relax-offset.d create mode 100644 gas/testsuite/gas/mips/relax-offset.d create mode 100644 gas/testsuite/gas/mips/relax-offset.l create mode 100644 gas/testsuite/gas/mips/relax-offset.s create mode 100644 ld/testsuite/ld-mips-elf/relax-offset-umips.dd create mode 100644 ld/testsuite/ld-mips-elf/relax-offset-umips.gd create mode 100644 ld/testsuite/ld-mips-elf/relax-offset.dd create mode 100644 ld/testsuite/ld-mips-elf/relax-offset.gd create mode 100644 ld/testsuite/ld-mips-elf/relax-offset.ld diff --git a/gas/ChangeLog b/gas/ChangeLog index 9989f313c6..7dad3418c7 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,17 @@ +2017-06-30 Maciej W. Rozycki + + * config/tc-mips.c (md_convert_frag): Don't make a helper + expression symbol for `fix_new_exp' called with a non-zero + offset. + * testsuite/gas/mips/relax-offset.d: New test. + * testsuite/gas/mips/mips1@relax-offset.d: New test. + * testsuite/gas/mips/r3000@relax-offset.d: New test. + * testsuite/gas/mips/r3900@relax-offset.d: New test. + * testsuite/gas/mips/micromips@relax-offset.d: New test. + * testsuite/gas/mips/relax-offset.l: New stderr output. + * testsuite/gas/mips/relax-offset.s: New test source. + * testsuite/gas/mips/mips.exp: Run the new tests. + 2017-06-30 Georg-Johann Lay PR gas/21683 diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index 1d477a1134..3682cd5b0d 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -18289,12 +18289,6 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp) exp.X_add_symbol = fragp->fr_symbol; exp.X_add_number = fragp->fr_offset; - if (fragp->fr_offset) - { - exp.X_add_symbol = make_expr_symbol (&exp); - exp.X_add_number = 0; - } - fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE, BFD_RELOC_MIPS_GOT16); fixp->fx_file = fragp->fr_file; @@ -18548,12 +18542,6 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp) insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000; insn |= at << MICROMIPSOP_SH_RT; - if (exp.X_add_number) - { - exp.X_add_symbol = make_expr_symbol (&exp); - exp.X_add_number = 0; - } - fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE, BFD_RELOC_MICROMIPS_GOT16); fixp->fx_file = fragp->fr_file; diff --git a/gas/testsuite/gas/mips/micromips@relax-offset.d b/gas/testsuite/gas/mips/micromips@relax-offset.d new file mode 100644 index 0000000000..95fbf119cf --- /dev/null +++ b/gas/testsuite/gas/mips/micromips@relax-offset.d @@ -0,0 +1,26 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS PIC branch relaxation with offset +#as: -32 -relax-branch +#stderr: relax-offset.l +#source: relax-offset.s + +.*: +file format .*mips.* + +Disassembly of section \.text: +[0-9a-f]+ <[^>]*> 41bc 0000 lui gp,0x0 +[ ]*[0-9a-f]+: R_MICROMIPS_HI16 _gp_disp +[0-9a-f]+ <[^>]*> 339c 0000 addiu gp,gp,0 +[ ]*[0-9a-f]+: R_MICROMIPS_LO16 _gp_disp +[0-9a-f]+ <[^>]*> 033c e150 addu gp,gp,t9 +[0-9a-f]+ <[^>]*> 40a4 fffe bnezc a0,0000000c +[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .* +[0-9a-f]+ <[^>]*> fc3c 0002 lw at,2\(gp\) +[ ]*[0-9a-f]+: R_MICROMIPS_GOT16 \.text +[0-9a-f]+ <[^>]*> 3021 0025 addiu at,at,37 +[ ]*[0-9a-f]+: R_MICROMIPS_LO16 \.text +[0-9a-f]+ <[^>]*> 45a1 jrc at +[0-9a-f]+ <[^>]*> 45bf jrc ra + \.\.\. +[0-9a-f]+ <[^>]*> 0000 8b7c syscall +[0-9a-f]+ <[^>]*> 45bf jrc ra + \.\.\. diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp index 81dfd34293..0ea9f61b96 100644 --- a/gas/testsuite/gas/mips/mips.exp +++ b/gas/testsuite/gas/mips/mips.exp @@ -1069,6 +1069,8 @@ if { [istarget mips*-*-vxworks*] } { run_dump_test_arches "relax" [mips_arch_list_matching mips2 !mips32r6] run_dump_test_arches "relax-at" [mips_arch_list_matching mips2 !mips32r6] + run_dump_test_arches "relax-offset" [mips_arch_list_matching mips1 \ + !mips32r6] run_dump_test "relax-swap1-mips1" run_dump_test "relax-swap1-mips2" run_dump_test "relax-swap2" diff --git a/gas/testsuite/gas/mips/mips1@relax-offset.d b/gas/testsuite/gas/mips/mips1@relax-offset.d new file mode 100644 index 0000000000..bd384100a0 --- /dev/null +++ b/gas/testsuite/gas/mips/mips1@relax-offset.d @@ -0,0 +1,30 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS PIC branch relaxation with offset +#as: -32 -relax-branch +#stderr: relax-offset.l +#source: relax-offset.s + +.*: +file format .*mips.* + +Disassembly of section \.text: +[0-9a-f]+ <[^>]*> 3c1c0000 lui gp,0x0 +[ ]*[0-9a-f]+: R_MIPS_HI16 _gp_disp +[0-9a-f]+ <[^>]*> 279c0000 addiu gp,gp,0 +[ ]*[0-9a-f]+: R_MIPS_LO16 _gp_disp +[0-9a-f]+ <[^>]*> 0399e021 addu gp,gp,t9 +[0-9a-f]+ <[^>]*> 14800005 bnez a0,00000024 +[0-9a-f]+ <[^>]*> 00000000 nop +[0-9a-f]+ <[^>]*> 8f810002 lw at,2\(gp\) +[ ]*[0-9a-f]+: R_MIPS_GOT16 \.text +[0-9a-f]+ <[^>]*> 00000000 nop +[0-9a-f]+ <[^>]*> 24210034 addiu at,at,52 +[ ]*[0-9a-f]+: R_MIPS_LO16 \.text +[0-9a-f]+ <[^>]*> 00200008 jr at +[0-9a-f]+ <[^>]*> 00000000 nop +[0-9a-f]+ <[^>]*> 03e00008 jr ra +[0-9a-f]+ <[^>]*> 00000000 nop + \.\.\. +[0-9a-f]+ <[^>]*> 0000000c syscall +[0-9a-f]+ <[^>]*> 03e00008 jr ra +[0-9a-f]+ <[^>]*> 00000000 nop + \.\.\. diff --git a/gas/testsuite/gas/mips/r3000@relax-offset.d b/gas/testsuite/gas/mips/r3000@relax-offset.d new file mode 100644 index 0000000000..d726d324a1 --- /dev/null +++ b/gas/testsuite/gas/mips/r3000@relax-offset.d @@ -0,0 +1,6 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS PIC branch relaxation with offset +#as: -32 -relax-branch +#stderr: relax-offset.l +#source: relax-offset.s +#dump: mips1@relax-offset.d diff --git a/gas/testsuite/gas/mips/r3900@relax-offset.d b/gas/testsuite/gas/mips/r3900@relax-offset.d new file mode 100644 index 0000000000..d726d324a1 --- /dev/null +++ b/gas/testsuite/gas/mips/r3900@relax-offset.d @@ -0,0 +1,6 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS PIC branch relaxation with offset +#as: -32 -relax-branch +#stderr: relax-offset.l +#source: relax-offset.s +#dump: mips1@relax-offset.d diff --git a/gas/testsuite/gas/mips/relax-offset.d b/gas/testsuite/gas/mips/relax-offset.d new file mode 100644 index 0000000000..e7f36e2878 --- /dev/null +++ b/gas/testsuite/gas/mips/relax-offset.d @@ -0,0 +1,28 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS PIC branch relaxation with offset +#as: -32 -relax-branch +#stderr: relax-offset.l + +.*: +file format .*mips.* + +Disassembly of section \.text: +[0-9a-f]+ <[^>]*> 3c1c0000 lui gp,0x0 +[ ]*[0-9a-f]+: R_MIPS_HI16 _gp_disp +[0-9a-f]+ <[^>]*> 279c0000 addiu gp,gp,0 +[ ]*[0-9a-f]+: R_MIPS_LO16 _gp_disp +[0-9a-f]+ <[^>]*> 0399e021 addu gp,gp,t9 +[0-9a-f]+ <[^>]*> 14800004 bnez a0,00000020 +[0-9a-f]+ <[^>]*> 00000000 nop +[0-9a-f]+ <[^>]*> 8f810002 lw at,2\(gp\) +[ ]*[0-9a-f]+: R_MIPS_GOT16 \.text +[0-9a-f]+ <[^>]*> 24210034 addiu at,at,52 +[ ]*[0-9a-f]+: R_MIPS_LO16 \.text +[0-9a-f]+ <[^>]*> 00200008 jr at +[0-9a-f]+ <[^>]*> 00000000 nop +[0-9a-f]+ <[^>]*> 03e00008 jr ra +[0-9a-f]+ <[^>]*> 00000000 nop + \.\.\. +[0-9a-f]+ <[^>]*> 0000000c syscall +[0-9a-f]+ <[^>]*> 03e00008 jr ra +[0-9a-f]+ <[^>]*> 00000000 nop + \.\.\. diff --git a/gas/testsuite/gas/mips/relax-offset.l b/gas/testsuite/gas/mips/relax-offset.l new file mode 100644 index 0000000000..570a78339b --- /dev/null +++ b/gas/testsuite/gas/mips/relax-offset.l @@ -0,0 +1,2 @@ +.*: Assembler messages: +.*:10: Warning: relaxed out-of-range branch into a jump diff --git a/gas/testsuite/gas/mips/relax-offset.s b/gas/testsuite/gas/mips/relax-offset.s new file mode 100644 index 0000000000..62553225de --- /dev/null +++ b/gas/testsuite/gas/mips/relax-offset.s @@ -0,0 +1,23 @@ + .abicalls + + .align 4, 0 + .globl foo + .ent foo +foo: + .set noreorder + .cpload $25 + .set reorder + beq $4, $0, bar + 4 + jr $31 + + .space 131072 + + .align 4, 0 +bar: + syscall + jr $31 + .end foo + +# Force some (non-delay-slot) zero bytes, to make 'objdump' print ... + .space 16 + .align 4, 0 diff --git a/ld/ChangeLog b/ld/ChangeLog index 8c80daf2f3..33fda8ba7d 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,13 @@ +2017-06-30 Maciej W. Rozycki + + * testsuite/ld-mips-elf/relax-offset.dd: New test. + * testsuite/ld-mips-elf/relax-offset.gd: New test. + * testsuite/ld-mips-elf/relax-offset-umips.dd: New test. + * testsuite/ld-mips-elf/relax-offset-umips.gd: New test. + * testsuite/ld-mips-elf/relax-offset.ld: New test linker script. + * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests. + (prune_warnings): New temporary procedure. + 2017-06-28 Maciej W. Rozycki * testsuite/ld-mips-elf/mips-elf-flags.exp: Add interAptiv MR2 diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp index 66b2ae4677..4360b83e2b 100644 --- a/ld/testsuite/ld-mips-elf/mips-elf.exp +++ b/ld/testsuite/ld-mips-elf/mips-elf.exp @@ -1179,3 +1179,37 @@ run_ld_link_tests [list \ # Check that the ISA level is consistently II for the LSI 4010. run_dump_test "lsi-4010-isa" [list [list ld $abi_ldflags(o32)]] + +# PIC branch relaxation with offset tests. We need to use our version +# of `prune_warnings' to get rid of GAS branch relaxation noise. +rename prune_warnings mips_old_prune_warnings +proc prune_warnings { msg } { + set msg1 "Assembler messages:" + set msg2 "Warning: relaxed out-of-range branch into a jump" + set msgx "(?:$msg1|$msg2)" + regsub -all "(^|\[\n\r\]*)\[^\n\r\]*: $msgx\[\n\r\]*" $msg "\\1" msg + return [mips_old_prune_warnings $msg] +} +run_ld_link_tests [list \ + [list \ + "MIPS link PIC branch relaxation with offset" \ + "$abi_ldflags(o32) -shared -T relax-offset.ld" "" \ + "$abi_asflags(o32) -relax-branch -mips2" \ + {../../../gas/testsuite/gas/mips/relax-offset.s} \ + {{objdump \ + {-d --prefix-addresses --show-raw-insn} \ + relax-offset.dd} \ + {readelf -A relax-offset.gd}} \ + "relax-offset"] \ + [list \ + "microMIPS link PIC branch relaxation with offset" \ + "$abi_ldflags(o32) -shared -T relax-offset.ld" "" \ + "$abi_asflags(o32) -relax-branch -mmicromips" \ + {../../../gas/testsuite/gas/mips/relax-offset.s} \ + {{objdump \ + {-d --prefix-addresses --show-raw-insn} \ + relax-offset-umips.dd} \ + {readelf -A relax-offset-umips.gd}} \ + "relax-offset-umips"]] +rename prune_warnings "" +rename mips_old_prune_warnings prune_warnings diff --git a/ld/testsuite/ld-mips-elf/relax-offset-umips.dd b/ld/testsuite/ld-mips-elf/relax-offset-umips.dd new file mode 100644 index 0000000000..8e23931856 --- /dev/null +++ b/ld/testsuite/ld-mips-elf/relax-offset-umips.dd @@ -0,0 +1,15 @@ +.*: +file format .*mips.* + +Disassembly of section \.text: +00000000 <.*> 41bc 0003 lui gp,0x3 +00000004 <.*> 339c 802f addiu gp,gp,-32721 +00000008 <.*> 033c e150 addu gp,gp,t9 +0000000c <.*> 40a4 0005 bnezc a0,0000001a <.*> +00000010 <.*> fc3c 8018 lw at,-32744\(gp\) +00000014 <.*> 3021 0025 addiu at,at,37 +00000018 <.*> 45a1 jrc at +0000001a <.*> 45bf jrc ra + \.\.\. +00020020 <.*> 0000 8b7c syscall +00020024 <.*> 45bf jrc ra + \.\.\. diff --git a/ld/testsuite/ld-mips-elf/relax-offset-umips.gd b/ld/testsuite/ld-mips-elf/relax-offset-umips.gd new file mode 100644 index 0000000000..119667fcbe --- /dev/null +++ b/ld/testsuite/ld-mips-elf/relax-offset-umips.gd @@ -0,0 +1,11 @@ +Primary GOT: + Canonical gp value: 00028030 + + Reserved entries: + Address Access Initial Purpose + 00020040 -32752\(gp\) 00000000 Lazy resolver + 00020044 -32748\(gp\) 80000000 Module pointer \(GNU extension\) + + Local entries: + Address Access Initial + 00020048 -32744\(gp\) 00020000 diff --git a/ld/testsuite/ld-mips-elf/relax-offset.dd b/ld/testsuite/ld-mips-elf/relax-offset.dd new file mode 100644 index 0000000000..322a0c9bab --- /dev/null +++ b/ld/testsuite/ld-mips-elf/relax-offset.dd @@ -0,0 +1,19 @@ +.*: +file format .*mips.* + +Disassembly of section \.text: +00000000 <.*> 3c1c0003 lui gp,0x3 +00000004 <.*> 279c8040 addiu gp,gp,-32704 +00000008 <.*> 0399e021 addu gp,gp,t9 +0000000c <.*> 14800004 bnez a0,00000020 <.*> +00000010 <.*> 00000000 nop +00000014 <.*> 8f818018 lw at,-32744\(gp\) +00000018 <.*> 24210034 addiu at,at,52 +0000001c <.*> 00200008 jr at +00000020 <.*> 00000000 nop +00000024 <.*> 03e00008 jr ra +00000028 <.*> 00000000 nop + \.\.\. +00020030 <.*> 0000000c syscall +00020034 <.*> 03e00008 jr ra +00020038 <.*> 00000000 nop + \.\.\. diff --git a/ld/testsuite/ld-mips-elf/relax-offset.gd b/ld/testsuite/ld-mips-elf/relax-offset.gd new file mode 100644 index 0000000000..41f4af9216 --- /dev/null +++ b/ld/testsuite/ld-mips-elf/relax-offset.gd @@ -0,0 +1,11 @@ +Primary GOT: + Canonical gp value: 00028040 + + Reserved entries: + Address Access Initial Purpose + 00020050 -32752\(gp\) 00000000 Lazy resolver + 00020054 -32748\(gp\) 80000000 Module pointer \(GNU extension\) + + Local entries: + Address Access Initial + 00020058 -32744\(gp\) 00020000 diff --git a/ld/testsuite/ld-mips-elf/relax-offset.ld b/ld/testsuite/ld-mips-elf/relax-offset.ld new file mode 100644 index 0000000000..39f6367b50 --- /dev/null +++ b/ld/testsuite/ld-mips-elf/relax-offset.ld @@ -0,0 +1,16 @@ +ENTRY (foo); +SECTIONS +{ + .text : { *(.text) } + HIDDEN (_gp = ALIGN(16) + 0x7ff0); + .got : { *(.got) } + .dynamic : { *(.dynamic) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .pdr : { *(.pdr) } + .shstrtab : { *(.shstrtab) } + .symtab : { *(.symtab) } + .strtab : { *(.strtab) } + /DISCARD/ : { *(*) } +} -- 2.34.1