GNU Binutils with patches for OS216
修訂 | 76a493ab99d9276180db6e791f95d1d6d86d2954 (tree) |
---|---|
時間 | 2017-11-28 08:14:48 |
作者 | Max Filippov <jcmvbkbc@gmai...> |
Commiter | Max Filippov |
gas: xtensa: reuse trampoline placement code
There's almost exact copy of the trampoline placement code in the
search_trampolines function that is used for jumps generated for relaxed
branch instructions. Get rid of the duplication and reuse
xg_find_best_trampoline function for that.
gas/
2017-11-27 Max Filippov <jcmvbkbc@gmail.com>
* config/tc-xtensa.c (search_trampolines, get_best_trampoline):
Remove definitions.
(xg_find_best_trampoline_for_tinsn): New function.
(relax_frag_immed): Replace call to get_best_trampoline with a
call to xg_find_best_trampoline_for_tinsn.
* testsuite/gas/xtensa/trampoline.d: Adjust absolute addresses
as the placement of trampolines for relaxed branches has been
changed.
@@ -1,5 +1,16 @@ | ||
1 | 1 | 2017-11-27 Max Filippov <jcmvbkbc@gmail.com> |
2 | 2 | |
3 | + * config/tc-xtensa.c (search_trampolines, get_best_trampoline): | |
4 | + Remove definitions. | |
5 | + (xg_find_best_trampoline_for_tinsn): New function. | |
6 | + (relax_frag_immed): Replace call to get_best_trampoline with a | |
7 | + call to xg_find_best_trampoline_for_tinsn. | |
8 | + * testsuite/gas/xtensa/trampoline.d: Adjust absolute addresses | |
9 | + as the placement of trampolines for relaxed branches has been | |
10 | + changed. | |
11 | + | |
12 | +2017-11-27 Max Filippov <jcmvbkbc@gmail.com> | |
13 | + | |
3 | 14 | * config/tc-xtensa.c (trampoline_index): New structure. |
4 | 15 | (trampoline_seg): Replace trampoline list with trampoline index. |
5 | 16 | (xg_find_trampoline, xg_add_trampoline_to_index) |
@@ -9806,99 +9806,20 @@ bytes_to_stretch (fragS *this_frag, | ||
9806 | 9806 | |
9807 | 9807 | |
9808 | 9808 | static fragS * |
9809 | -search_trampolines (TInsn *tinsn, fragS *fragP, bfd_boolean unreachable_only) | |
9809 | +xg_find_best_trampoline_for_tinsn (TInsn *tinsn, fragS *fragP) | |
9810 | 9810 | { |
9811 | + symbolS *sym = tinsn->tok[0].X_add_symbol; | |
9812 | + addressT source = fragP->fr_address; | |
9813 | + addressT target = S_GET_VALUE (sym) + tinsn->tok[0].X_add_number; | |
9811 | 9814 | struct trampoline_seg *ts = find_trampoline_seg (now_seg); |
9812 | - fragS *tf = NULL; | |
9813 | 9815 | size_t i; |
9814 | - fragS *best_tf = NULL; | |
9815 | - offsetT best_delta = 0; | |
9816 | - offsetT best_addr = 0; | |
9817 | - symbolS *sym = tinsn->tok[0].X_add_symbol; | |
9818 | - offsetT target = S_GET_VALUE (sym) + tinsn->tok[0].X_add_number; | |
9819 | - offsetT addr = fragP->fr_address; | |
9820 | - offsetT lower = (addr < target) ? addr : target; | |
9821 | - offsetT upper = (addr > target) ? addr : target; | |
9822 | - offsetT delta = upper - lower; | |
9823 | - offsetT midpoint = lower + delta / 2; | |
9824 | - offsetT this_delta = -1; | |
9825 | - offsetT this_addr = -1; | |
9826 | - | |
9827 | - if (!ts) | |
9828 | - return NULL; | |
9829 | - | |
9830 | - if (delta > 2 * J_RANGE) | |
9831 | - { | |
9832 | - /* One trampoline won't do; we need multiple. | |
9833 | - Choose the farthest trampoline that's still in range of the original | |
9834 | - and let a later pass finish the job. */ | |
9835 | - for (i = 0; i < ts->index.n_entries; ++i) | |
9836 | - { | |
9837 | - tf = ts->index.entry[i]; | |
9838 | - this_addr = tf->fr_address + tf->fr_fix; | |
9839 | - if (upper == addr) | |
9840 | - { | |
9841 | - /* Backward jump. */ | |
9842 | - if (addr - this_addr < J_RANGE) | |
9843 | - break; | |
9844 | - } | |
9845 | - else if (i + 1 < ts->index.n_entries) | |
9846 | - { | |
9847 | - /* Forward jump. */ | |
9848 | - fragS *next = ts->index.entry[i + 1]; | |
9849 | - offsetT next_addr = next->fr_address + next->fr_fix; | |
9850 | - | |
9851 | - if (next_addr - addr > J_RANGE) | |
9852 | - break; | |
9853 | - } | |
9854 | - else | |
9855 | - { | |
9856 | - break; | |
9857 | - } | |
9858 | - } | |
9859 | - if (i < ts->index.n_entries && | |
9860 | - labs (addr - this_addr) < J_RANGE) | |
9861 | - return tf; | |
9862 | - | |
9863 | - return NULL; | |
9864 | - } | |
9865 | - | |
9866 | - for (i = 0; i < ts->index.n_entries; ++i) | |
9867 | - { | |
9868 | - tf = ts->index.entry[i]; | |
9869 | - this_addr = tf->fr_address + tf->fr_fix; | |
9870 | - this_delta = labs (this_addr - midpoint); | |
9871 | - if (unreachable_only && tf->tc_frag_data.needs_jump_around) | |
9872 | - continue; | |
9873 | - if (!best_tf || this_delta < best_delta) | |
9874 | - { | |
9875 | - best_tf = tf; | |
9876 | - best_delta = this_delta; | |
9877 | - best_addr = this_addr; | |
9878 | - } | |
9879 | - } | |
9880 | - | |
9881 | - if (best_tf && | |
9882 | - best_delta < J_RANGE && | |
9883 | - labs(best_addr - lower) < J_RANGE && | |
9884 | - labs(best_addr - upper) < J_RANGE) | |
9885 | - return best_tf; | |
9886 | - | |
9887 | - return NULL; /* No suitable trampoline found. */ | |
9888 | -} | |
9889 | - | |
9890 | 9816 | |
9891 | -static fragS * | |
9892 | -get_best_trampoline (TInsn *tinsn, fragS *fragP) | |
9893 | -{ | |
9894 | - fragS *tf = NULL; | |
9895 | - | |
9896 | - tf = search_trampolines (tinsn, fragP, TRUE); /* Try unreachable first. */ | |
9817 | + if (!ts || !ts->index.n_entries) | |
9818 | + return NULL; | |
9897 | 9819 | |
9898 | - if (tf == NULL) | |
9899 | - tf = search_trampolines (tinsn, fragP, FALSE); /* Try ones needing a jump-around, too. */ | |
9820 | + i = xg_find_best_trampoline (&ts->index, source, target); | |
9900 | 9821 | |
9901 | - return tf; | |
9822 | + return ts->index.entry[i]; | |
9902 | 9823 | } |
9903 | 9824 | |
9904 | 9825 |
@@ -10154,7 +10075,7 @@ relax_frag_immed (segT segP, | ||
10154 | 10075 | |
10155 | 10076 | if (!xg_symbolic_immeds_fit (jinsn, segP, fragP, fragP->fr_offset, total_text_diff)) |
10156 | 10077 | { |
10157 | - fragS *tf = get_best_trampoline (jinsn, fragP); | |
10078 | + fragS *tf = xg_find_best_trampoline_for_tinsn (jinsn, fragP); | |
10158 | 10079 | |
10159 | 10080 | if (tf) |
10160 | 10081 | { |
@@ -23,11 +23,11 @@ | ||
23 | 23 | #... |
24 | 24 | .*49404:.*j.0x49404 |
25 | 25 | .*49407:.*beqz.n.a2,.0x4940c |
26 | -.*49409:.*j.0x693ce | |
26 | +.*49409:.*j.0x61aa2 | |
27 | 27 | #... |
28 | -.*693ce:.*j.0x7ddd1 | |
28 | +.*61aa2:.*j.0x7a13b | |
29 | 29 | #... |
30 | -.*7ddd1:.*j.0x927f5 | |
30 | +.*7a13b:.*j.0x927f5 | |
31 | 31 | #... |
32 | 32 | .*927f5:.*j.0x927f5 |
33 | 33 | #... |