Fix some bugs in step 2. Actually pass len_diff to expand_term and don't

expand inactive spans (per the algorithm documentation).

In the interval tree addition, sanity check inputs so high is always higher
than low.

Add a sanity check to x86_bc_jmp_expand() to detect trying to expand an
already-expanded jump.

svn path=/branches/new-optimizer/; revision=1581
0.6.0
Peter Johnson 19 years ago
parent 61ff7870c9
commit 4169dbca50
  1. 9
      libyasm/inttree.c
  2. 10
      libyasm/section.c
  3. 3
      modules/arch/x86/x86bc.c

@ -58,8 +58,13 @@ ITN_create(long low, long high, void *data)
{
IntervalTreeNode *itn = yasm_xmalloc(sizeof(IntervalTreeNode));
itn->data = data;
itn->low = low;
itn->high = high;
if (low < high) {
itn->low = low;
itn->high = high;
} else {
itn->low = high;
itn->high = low;
}
itn->maxHigh = high;
return itn;
}

@ -966,6 +966,10 @@ optimize_term_expand(IntervalTreeNode *node, void *d)
yasm_span *span = term->span;
unsigned long len_diff = optd->len_diff;
/* Don't expand inactive spans */
if (!span->active)
return;
/* Update term length */
if (term->precbc2) {
if (term->precbc->bc_index > term->precbc2->bc_index)
@ -1193,7 +1197,7 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch,
/* Step 2 */
while (!STAILQ_EMPTY(&optd.Q)) {
unsigned long orig_len, len_diff;
unsigned long orig_len;
span = STAILQ_FIRST(&optd.Q);
STAILQ_REMOVE_HEAD(&optd.Q, linkq);
orig_len = span->bc->len;
@ -1215,8 +1219,8 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch,
span->active = 0;
if (orig_len > span->bc->len)
yasm_internal_error(N_("length decreased during an expansion"));
len_diff = span->bc->len - orig_len;
if (len_diff == 0)
optd.len_diff = span->bc->len - orig_len;
if (optd.len_diff == 0)
continue; /* didn't increase in size; unusual! */
IT_enumerate(optd.itree, (long)span->bc->bc_index,
(long)span->bc->bc_index, &optd, optimize_term_expand);

@ -726,6 +726,9 @@ x86_bc_jmp_expand(yasm_bytecode *bc, int span, long old_val, long new_val,
return -1;
}
if (jmp->op_sel == JMP_NEAR)
yasm_internal_error(N_("trying to expand an already-near jump"));
/* Upgrade to a near jump */
jmp->op_sel = JMP_NEAR;
bc->len -= jmp->shortop.len + 1;

Loading…
Cancel
Save