]> granicus.if.org Git - yasm/commitdiff
Fix #124: Fully simplify out sym-sym in values (e.g. a symbol minus itself).
authorPeter Johnson <peter@tortall.net>
Tue, 4 Dec 2007 05:58:54 +0000 (05:58 -0000)
committerPeter Johnson <peter@tortall.net>
Tue, 4 Dec 2007 05:58:54 +0000 (05:58 -0000)
This could particularly cause false errors if sym is external.

svn path=/trunk/yasm/; revision=2018

libyasm/tests/Makefile.inc
libyasm/tests/value-samesym.asm [new file with mode: 0644]
libyasm/tests/value-samesym.errwarn [new file with mode: 0644]
libyasm/tests/value-samesym.hex [new file with mode: 0644]
libyasm/value.c

index e0e3d951e8afa87d65ee378abc4f84df79ad633c..4b9eb1d62d0644053fd366958a0c27f75c72b165 100644 (file)
@@ -75,6 +75,9 @@ EXTRA_DIST += libyasm/tests/unary.asm
 EXTRA_DIST += libyasm/tests/unary.hex
 EXTRA_DIST += libyasm/tests/value-err.asm
 EXTRA_DIST += libyasm/tests/value-err.errwarn
+EXTRA_DIST += libyasm/tests/value-samesym.asm
+EXTRA_DIST += libyasm/tests/value-samesym.errwarn
+EXTRA_DIST += libyasm/tests/value-samesym.hex
 
 check_PROGRAMS += bitvect_test
 check_PROGRAMS += floatnum_test
diff --git a/libyasm/tests/value-samesym.asm b/libyasm/tests/value-samesym.asm
new file mode 100644 (file)
index 0000000..da32599
--- /dev/null
@@ -0,0 +1,2 @@
+extern RW
+mov [eax + (RW + 22032) - (RW + 23056)], eax
diff --git a/libyasm/tests/value-samesym.errwarn b/libyasm/tests/value-samesym.errwarn
new file mode 100644 (file)
index 0000000..58c850b
--- /dev/null
@@ -0,0 +1 @@
+-:1: warning: binary object format does not support extern variables
diff --git a/libyasm/tests/value-samesym.hex b/libyasm/tests/value-samesym.hex
new file mode 100644 (file)
index 0000000..4bab16b
--- /dev/null
@@ -0,0 +1,8 @@
+67 
+66 
+89 
+80 
+00 
+fc 
+ff 
+ff 
index e3eda5fd6739a1fbdefc769d893f00f967d3ea66..74b793bcd61be1d4f2820039ddf8d274fcba7e60 100644 (file)
@@ -208,6 +208,29 @@ value_finalize_scan(yasm_value *value, yasm_expr *e,
                     continue;
                 }
 
+                /* Look for the same symrec term; even if both are external,
+                 * they should cancel out.
+                 */
+                for (j=0; j<e->numterms; j++) {
+                    if (e->terms[j].type == YASM_EXPR_SYM
+                        && e->terms[j].data.sym == sym
+                        && (used & (1<<j)) == 0) {
+                        /* Mark as used */
+                        used |= 1<<j;
+
+                        /* Replace both symrec portions with 0 */
+                        yasm_expr_destroy(sube);
+                        e->terms[i].type = YASM_EXPR_INT;
+                        e->terms[i].data.intn = yasm_intnum_create_uint(0);
+                        e->terms[j].type = YASM_EXPR_INT;
+                        e->terms[j].data.intn = yasm_intnum_create_uint(0);
+
+                        break;  /* stop looking */
+                    }
+                }
+                if (j != e->numterms)
+                    continue;
+
                 if (!yasm_symrec_get_label(sym, &precbc)) {
                     if (value_finalize_scan(value, sube, expr_precbc,
                                             ssym_not_ok))