+ case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
+ {
+ /* We need to handle relaxation type ourselves, since relax_frag
+ doesn't update fr_subtype if there's no size increase in the
+ current section; when going from plain PUSHJ to a stub. This
+ is otherwise functionally the same as relax_frag in write.c,
+ simplified for this case. */
+ offsetT aim;
+ addressT target;
+ addressT address;
+ symbolS *symbolP;
+ target = fragP->fr_offset;
+ address = fragP->fr_address;
+ symbolP = fragP->fr_symbol;
+
+ if (symbolP)
+ {
+ fragS *sym_frag;
+
+ sym_frag = symbol_get_frag (symbolP);
+ know (S_GET_SEGMENT (symbolP) != absolute_section
+ || sym_frag == &zero_address_frag);
+ target += S_GET_VALUE (symbolP);
+
+ /* If frag has yet to be reached on this pass, assume it will
+ move by STRETCH just as we did. If this is not so, it will
+ be because some frag between grows, and that will force
+ another pass. */
+
+ if (stretch != 0
+ && sym_frag->relax_marker != fragP->relax_marker
+ && S_GET_SEGMENT (symbolP) == seg)
+ target += stretch;
+ }
+
+ aim = target - address - fragP->fr_fix;
+ if (aim >= PUSHJ_0B && aim <= PUSHJ_0F)
+ {
+ /* Target is reachable with a PUSHJ. */
+ segment_info_type *seginfo = seg_info (seg);
+
+ /* If we're at the end of a relaxation round, clear the stub
+ counter as initialization for the next round. */
+ if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
+ seginfo->tc_segment_info_data.nstubs = 0;
+ return 0;
+ }
+
+ /* Not reachable. Try a stub. */
+ fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO);
+ }
+ /* FALLTHROUGH. */
+
+ /* See if this PUSHJ is redirectable to a stub. */
+ case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
+ {
+ segment_info_type *seginfo = seg_info (seg);
+ fragS *lastfrag = seginfo->frchainP->frch_last;
+ relax_substateT prev_type = fragP->fr_subtype;
+
+ /* The last frag is always an empty frag, so it suffices to look
+ at its address to know the ending address of this section. */
+ know (lastfrag->fr_type == rs_fill
+ && lastfrag->fr_fix == 0
+ && lastfrag->fr_var == 0);
+
+ /* For this PUSHJ to be relaxable into a call to a stub, the
+ distance must be no longer than 256k bytes from the PUSHJ to
+ the end of the section plus the maximum size of stubs so far. */
+ if ((lastfrag->fr_address
+ + stretch
+ + PUSHJ_MAX_LEN * seginfo->tc_segment_info_data.nstubs)
+ - (fragP->fr_address + fragP->fr_fix)
+ > GETA_0F
+ || !pushj_stubs)
+ fragP->fr_subtype = mmix_relax_table[prev_type].rlx_more;
+ else
+ seginfo->tc_segment_info_data.nstubs++;
+
+ /* If we're at the end of a relaxation round, clear the stub
+ counter as initialization for the next round. */
+ if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
+ seginfo->tc_segment_info_data.nstubs = 0;
+
+ return
+ (mmix_relax_table[fragP->fr_subtype].rlx_length
+ - mmix_relax_table[prev_type].rlx_length);
+ }
+
+ case ENCODE_RELAX (STATE_PUSHJ, STATE_MAX):
+ {
+ segment_info_type *seginfo = seg_info (seg);
+
+ /* Need to cover all STATE_PUSHJ states to act on the last stub
+ frag (the end of this relax round; initialization for the
+ next). */
+ if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
+ seginfo->tc_segment_info_data.nstubs = 0;
+
+ return 0;
+ }
+
+ default:
+ return relax_frag (seg, fragP, stretch);
+
+ case STATE_GREG_UNDF:
+ BAD_CASE (fragP->fr_subtype);
+ }