]> granicus.if.org Git - yasm/commitdiff
Fix free-before-use case in x86 finalize code. Bytecode transformation
authorPeter Johnson <peter@tortall.net>
Fri, 3 Dec 2004 06:09:30 +0000 (06:09 -0000)
committerPeter Johnson <peter@tortall.net>
Fri, 3 Dec 2004 06:09:30 +0000 (06:09 -0000)
deletes the old bytecode, so it's not safe to use anything from the old
bytecode after this point (such as the prefixes array passed to arch
finalize).

 * x86bc.c (yasm_x86__bc_apply_prefixes): Take x86_common as parameter
rather than bytecode; add line parameter instead of referencing bc->line.
 * x86arch.h (yasm_x86__bc_apply_prefixes): Likewise.
 * x86id.re (x86_finalize_jmpfar, x86_finalize_jmp)
(yasm_x86__finalize_insn): Apply prefixes before bytecode transform.

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

modules/arch/x86/x86arch.h
modules/arch/x86/x86bc.c
modules/arch/x86/x86id.re

index 1d712525954eed63b3f17a35dbe97b92d9355f55..b89b3b193e9d5244a81c6879a89a2bf42f84c2bc 100644 (file)
@@ -231,7 +231,8 @@ void yasm_x86__bc_transform_jmp(yasm_bytecode *bc, x86_jmp *jmp);
 void yasm_x86__bc_transform_jmpfar(yasm_bytecode *bc, x86_jmpfar *jmpfar);
 
 void yasm_x86__bc_apply_prefixes
-    (yasm_bytecode *bc, int num_prefixes, unsigned long **prefixes);
+    (x86_common *common, int num_prefixes, unsigned long **prefixes,
+     unsigned long line);
 
 void yasm_x86__ea_init(yasm_effaddr *ea, unsigned int spare,
                       /*@null@*/ yasm_symrec *origin);
index 2d1d4fd30d5ba0b05713e1c346dc72dc7dc3828d..cce71e7131d0ff6ff5c7919c75b4c73837b56008 100644 (file)
@@ -270,17 +270,16 @@ yasm_x86__ea_create_imm(yasm_expr *imm, unsigned int im_len)
 /*@=compmempass@*/
 
 void
-yasm_x86__bc_apply_prefixes(yasm_bytecode *bc, int num_prefixes,
-                           unsigned long **prefixes)
+yasm_x86__bc_apply_prefixes(x86_common *common, int num_prefixes,
+                           unsigned long **prefixes, unsigned long line)
 {
-    x86_common *common = (x86_common *)bc->contents;
     int i;
 
     for (i=0; i<num_prefixes; i++) {
        switch ((x86_parse_insn_prefix)prefixes[i][0]) {
            case X86_LOCKREP:
                if (common->lockrep_pre != 0)
-                   yasm__warning(YASM_WARN_GENERAL, bc->line,
+                   yasm__warning(YASM_WARN_GENERAL, line,
                        N_("multiple LOCK or REP prefixes, using leftmost"));
                common->lockrep_pre = (unsigned char)prefixes[i][1];
                break;
index d96aeef6c35024acf6f14df050b8063a0c117276..e4e7fe6f6f030058d2074d1e1557a224546df7fb 100644 (file)
@@ -1754,9 +1754,11 @@ x86_finalize_jmpfar(yasm_arch *arch, yasm_bytecode *bc,
            yasm_internal_error(N_("didn't get FAR expression in jmpfar"));
     }
 
+    yasm_x86__bc_apply_prefixes((x86_common *)jmpfar, num_prefixes, prefixes,
+                               bc->line);
+
     /* Transform the bytecode */
     yasm_x86__bc_transform_jmpfar(bc, jmpfar);
-    yasm_x86__bc_apply_prefixes(bc, num_prefixes, prefixes);
 }
 
 static void
@@ -1856,9 +1858,11 @@ x86_finalize_jmp(yasm_arch *arch, yasm_bytecode *bc, yasm_bytecode *prev_bc,
        yasm__error(bc->line,
                    N_("no NEAR form of that jump instruction exists"));
 
+    yasm_x86__bc_apply_prefixes((x86_common *)jmp, num_prefixes, prefixes,
+                               bc->line);
+
     /* Transform the bytecode */
     yasm_x86__bc_transform_jmp(bc, jmp);
-    yasm_x86__bc_apply_prefixes(bc, num_prefixes, prefixes);
 }
 
 void
@@ -2420,9 +2424,11 @@ yasm_x86__finalize_insn(yasm_arch *arch, yasm_bytecode *bc,
     } else
        insn->imm = NULL;
 
+    yasm_x86__bc_apply_prefixes((x86_common *)insn, num_prefixes, prefixes,
+                               bc->line);
+
     /* Transform the bytecode */
     yasm_x86__bc_transform_insn(bc, insn);
-    yasm_x86__bc_apply_prefixes(bc, num_prefixes, prefixes);
 }