From: Peter Johnson Date: Sat, 12 Aug 2006 18:27:04 +0000 (-0000) Subject: Fix #58 and a more basic form of this bug (all EAs that needed non-zero X-Git-Tag: v0.6.0~165 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96036ed184cefac7a73598d031c5d00634ad4ef7;p=yasm Fix #58 and a more basic form of this bug (all EAs that needed non-zero displacement length and required optimization would end up with 0 displacement length, causing an internal error). svn path=/trunk/yasm/; revision=1606 --- diff --git a/libyasm/section.c b/libyasm/section.c index 8ca23dbf..78f79ece 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -853,10 +853,11 @@ span_create_terms(yasm_span *span) span->items[i].data.intn = yasm_intnum_create_int(0); /* Check for circular references */ - if ((span->bc->bc_index > span->terms[i].precbc->bc_index && - span->bc->bc_index <= span->terms[i].precbc2->bc_index) || - (span->bc->bc_index > span->terms[i].precbc2->bc_index && - span->bc->bc_index <= span->terms[i].precbc->bc_index)) + if (span->id == 0 && + ((span->bc->bc_index > span->terms[i].precbc->bc_index && + span->bc->bc_index <= span->terms[i].precbc2->bc_index) || + (span->bc->bc_index > span->terms[i].precbc2->bc_index && + span->bc->bc_index <= span->terms[i].precbc->bc_index))) yasm_error_set(YASM_ERROR_VALUE, N_("circular reference detected")); } diff --git a/modules/arch/x86/tests/Makefile.inc b/modules/arch/x86/tests/Makefile.inc index c2c79ccb..eab5961b 100644 --- a/modules/arch/x86/tests/Makefile.inc +++ b/modules/arch/x86/tests/Makefile.inc @@ -27,6 +27,9 @@ EXTRA_DIST += modules/arch/x86/tests/cpubasic-err.asm EXTRA_DIST += modules/arch/x86/tests/cpubasic-err.errwarn EXTRA_DIST += modules/arch/x86/tests/div-err.asm EXTRA_DIST += modules/arch/x86/tests/div-err.errwarn +EXTRA_DIST += modules/arch/x86/tests/ea-nonzero.asm +EXTRA_DIST += modules/arch/x86/tests/ea-nonzero.errwarn +EXTRA_DIST += modules/arch/x86/tests/ea-nonzero.hex EXTRA_DIST += modules/arch/x86/tests/ea-over.asm EXTRA_DIST += modules/arch/x86/tests/ea-over.errwarn EXTRA_DIST += modules/arch/x86/tests/ea-over.hex diff --git a/modules/arch/x86/tests/ea-nonzero.asm b/modules/arch/x86/tests/ea-nonzero.asm new file mode 100644 index 00000000..27d36bd0 --- /dev/null +++ b/modules/arch/x86/tests/ea-nonzero.asm @@ -0,0 +1,6 @@ +; Ticket #58 +; Also tests that this isn't seen as a circular reference. +[bits 64] +a: +lea rbp,[rsi+rbp*1+(b-a)] +b: diff --git a/modules/arch/x86/tests/ea-nonzero.errwarn b/modules/arch/x86/tests/ea-nonzero.errwarn new file mode 100644 index 00000000..e69de29b diff --git a/modules/arch/x86/tests/ea-nonzero.hex b/modules/arch/x86/tests/ea-nonzero.hex new file mode 100644 index 00000000..dd2b57ec --- /dev/null +++ b/modules/arch/x86/tests/ea-nonzero.hex @@ -0,0 +1,5 @@ +48 +8d +6c +2e +05 diff --git a/modules/arch/x86/x86bc.c b/modules/arch/x86/x86bc.c index b2f01d04..e587d36d 100644 --- a/modules/arch/x86/x86bc.c +++ b/modules/arch/x86/x86bc.c @@ -533,10 +533,10 @@ x86_bc_insn_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, /* Handle unknown case, default to byte-sized and set as * critical expression. */ - bc->len += 1; + x86_ea->ea.disp.size = 8; add_span(add_span_data, bc, 1, &x86_ea->ea.disp, -128, 127); - } else - bc->len += x86_ea->ea.disp.size/8; + } + bc->len += x86_ea->ea.disp.size/8; /* Handle address16 postop case */ if (insn->postop == X86_POSTOP_ADDRESS16) @@ -608,7 +608,7 @@ x86_bc_insn_expand(yasm_bytecode *bc, int span, long old_val, long new_val, if (ea && span == 1) { /* Change displacement length into word-sized */ - if (ea->disp.size == 0) { + if (ea->disp.size == 8) { ea->disp.size = (insn->common.addrsize == 16) ? 16 : 32; x86_ea->modrm &= ~0300; x86_ea->modrm |= 0200;