[committed] MIPS/GAS: Correct branch relaxation for weak symbols
Maciej W. Rozycki
macro@imgtec.com
Wed Apr 13 12:42:00 GMT 2016
More information about the Binutils mailing list
Wed Apr 13 12:42:00 GMT 2016
- Previous message (by thread): [PATCH] make a few variables static
- Next message (by thread): [PATCH] Update x86-64 tests for --as-needed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Weak symbols can be preempted at link time so always choose the longer sequence in branch relaxation, according to the relaxation level chosen, so that any symbol finally used as the branch target is reachable. 2016-04-13 Maciej W. Rozycki <macro@imgtec.com> Andrew Bennett <andrew.bennett@imgtec.com> gas/ * config/tc-mips.c (relaxed_branch_length): Use the long sequence where the target is a weak symbol. (relaxed_micromips_32bit_branch_length): Likewise. (relaxed_micromips_16bit_branch_length): Likewise. * testsuite/gas/mips/branch-weak-1.d: New test. * testsuite/gas/mips/branch-weak-2.d: New test. * testsuite/gas/mips/branch-weak-3.d: New test. * testsuite/gas/mips/branch-weak-4.d: New test. * testsuite/gas/mips/branch-weak-5.d: New test. * testsuite/gas/mips/branch-weak.l: New stderr output. * testsuite/gas/mips/branch-weak.s: New test source. * testsuite/gas/mips/mips.exp: Run the new tests. --- I have committed this change. Maciej binutils-mips-gas-branch-relax-weak.diff Index: binutils/gas/config/tc-mips.c =================================================================== --- binutils.orig/gas/config/tc-mips.c 2016-04-08 20:45:32.316129627 +0100 +++ binutils/gas/config/tc-mips.c 2016-04-09 00:04:57.375976880 +0100 @@ -16796,6 +16796,7 @@ relaxed_branch_length (fragS *fragp, ase if (fragp && S_IS_DEFINED (fragp->fr_symbol) + && !S_IS_WEAK (fragp->fr_symbol) && sec == S_GET_SEGMENT (fragp->fr_symbol)) { addressT addr; @@ -16859,6 +16860,7 @@ relaxed_micromips_32bit_branch_length (f if (fragp && S_IS_DEFINED (fragp->fr_symbol) + && !S_IS_WEAK (fragp->fr_symbol) && sec == S_GET_SEGMENT (fragp->fr_symbol)) { addressT addr; @@ -16950,6 +16952,7 @@ relaxed_micromips_16bit_branch_length (f if (fragp && S_IS_DEFINED (fragp->fr_symbol) + && !S_IS_WEAK (fragp->fr_symbol) && sec == S_GET_SEGMENT (fragp->fr_symbol)) { addressT addr; Index: binutils/gas/testsuite/gas/mips/branch-weak-1.d =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ binutils/gas/testsuite/gas/mips/branch-weak-1.d 2016-04-09 00:04:57.473685573 +0100 @@ -0,0 +1,15 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS branch to a weak symbol +#as: -32 --defsym align=12 +#source: branch-weak.s + +.*: +file format .*mips.* + +Disassembly of section \.text: +[0-9a-f]+ <[^>]*> 1000ffff b 00000000 <foo> +[ ]*[0-9a-f]+: R_MIPS_PC16 bar +[0-9a-f]+ <[^>]*> 00000000 nop + \.\.\. +[0-9a-f]+ <[^>]*> 03e00008 jr ra +[0-9a-f]+ <[^>]*> 00000000 nop + \.\.\. Index: binutils/gas/testsuite/gas/mips/branch-weak-2.d =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ binutils/gas/testsuite/gas/mips/branch-weak-2.d 2016-04-09 00:04:57.520445434 +0100 @@ -0,0 +1,15 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: microMIPS branch to a weak symbol +#as: -32 -mmicromips --defsym align=12 +#source: branch-weak.s + +.*: +file format .*mips.* + +Disassembly of section \.text: +[0-9a-f]+ <[^>]*> 9400 fffe b 00000000 <foo> +[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 bar +[0-9a-f]+ <[^>]*> 0c00 nop + \.\.\. +[0-9a-f]+ <[^>]*> 459f jr ra +[0-9a-f]+ <[^>]*> 0c00 nop + \.\.\. Index: binutils/gas/testsuite/gas/mips/branch-weak-3.d =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ binutils/gas/testsuite/gas/mips/branch-weak-3.d 2016-04-09 00:04:57.529841492 +0100 @@ -0,0 +1,16 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS relaxed branch to a weak symbol +#as: -32 --relax-branch --defsym align=12 +#source: branch-weak.s +#stderr: branch-weak.l + +.*: +file format .*mips.* + +Disassembly of section \.text: +[0-9a-f]+ <[^>]*> 08000000 j 00000000 <foo> +[ ]*[0-9a-f]+: R_MIPS_26 bar +[0-9a-f]+ <[^>]*> 00000000 nop + \.\.\. +[0-9a-f]+ <[^>]*> 03e00008 jr ra +[0-9a-f]+ <[^>]*> 00000000 nop + \.\.\. Index: binutils/gas/testsuite/gas/mips/branch-weak-4.d =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ binutils/gas/testsuite/gas/mips/branch-weak-4.d 2016-04-09 00:04:57.553233691 +0100 @@ -0,0 +1,16 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: microMIPS relaxed branch to a weak symbol +#as: -32 -mmicromips --relax-branch --defsym align=12 +#source: branch-weak.s +#stderr: branch-weak.l + +.*: +file format .*mips.* + +Disassembly of section \.text: +[0-9a-f]+ <[^>]*> d400 0000 j 00000000 <foo> +[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 bar +[0-9a-f]+ <[^>]*> 0c00 nop + \.\.\. +[0-9a-f]+ <[^>]*> 459f jr ra +[0-9a-f]+ <[^>]*> 0c00 nop + \.\.\. Index: binutils/gas/testsuite/gas/mips/branch-weak-5.d =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ binutils/gas/testsuite/gas/mips/branch-weak-5.d 2016-04-09 00:04:57.566606951 +0100 @@ -0,0 +1,15 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: microMIPS short branch to a weak symbol +#as: -32 -mmicromips --defsym align=4 +#source: branch-weak.s + +.*: +file format .*mips.* + +Disassembly of section \.text: +[0-9a-f]+ <[^>]*> 9400 fffe b 00000000 <foo> +[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 bar +[0-9a-f]+ <[^>]*> 0c00 nop + \.\.\. +[0-9a-f]+ <[^>]*> 459f jr ra +[0-9a-f]+ <[^>]*> 0c00 nop + \.\.\. Index: binutils/gas/testsuite/gas/mips/branch-weak.l =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ binutils/gas/testsuite/gas/mips/branch-weak.l 2016-04-09 00:04:57.665927349 +0100 @@ -0,0 +1,2 @@ +.*: Assembler messages: +.*:6: Warning: relaxed out-of-range branch into a jump Index: binutils/gas/testsuite/gas/mips/branch-weak.s =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ binutils/gas/testsuite/gas/mips/branch-weak.s 2016-04-09 00:04:57.709838646 +0100 @@ -0,0 +1,19 @@ + .text + .align 4, 0 + .globl foo + .ent foo +foo: + b bar + .end foo + + .align align, 0 + .globl bar + .weak bar + .ent bar +bar: + jr $ra + .end bar + +# Force some (non-delay-slot) zero bytes, to make 'objdump' print ... + .align 4, 0 + .space 16 Index: binutils/gas/testsuite/gas/mips/mips.exp =================================================================== --- binutils.orig/gas/testsuite/gas/mips/mips.exp 2016-04-08 20:46:10.480257638 +0100 +++ binutils/gas/testsuite/gas/mips/mips.exp 2016-04-09 00:04:57.722222289 +0100 @@ -578,6 +578,11 @@ if { [istarget mips*-*-vxworks*] } { run_dump_test "branch-extern-2" run_dump_test "branch-extern-3" run_dump_test "branch-extern-4" + run_dump_test "branch-weak-1" + run_dump_test "branch-weak-2" + run_dump_test "branch-weak-3" + run_dump_test "branch-weak-4" + run_dump_test "branch-weak-5" run_dump_test "compact-eh-eb-1" run_dump_test "compact-eh-eb-2"
- Previous message (by thread): [PATCH] make a few variables static
- Next message (by thread): [PATCH] Update x86-64 tests for --as-needed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list