From 9bbc4a49265bd75341dec890502a2061811bbd80 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 28 Jan 2007 00:47:16 +0000 Subject: [PATCH] Fix #97: Support right-shifted symbols in binary output (the root cause). Also fix the symptom by checking for non-NULL value->rel. svn path=/trunk/yasm/; revision=1744 --- modules/objfmts/bin/bin-objfmt.c | 16 +- modules/objfmts/bin/tests/Makefile.inc | 2 + modules/objfmts/bin/tests/shr.asm | 3 + modules/objfmts/bin/tests/shr.hex | 260 +++++++++++++++++++++++++ 4 files changed, 277 insertions(+), 4 deletions(-) create mode 100644 modules/objfmts/bin/tests/shr.asm create mode 100644 modules/objfmts/bin/tests/shr.hex diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c index 454d35d7..c010bfa8 100644 --- a/modules/objfmts/bin/bin-objfmt.c +++ b/modules/objfmts/bin/bin-objfmt.c @@ -143,14 +143,22 @@ bin_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, if (value->rel && !value->curpos_rel && yasm_symrec_get_label(value->rel, &precbc) && (sect = yasm_bc_get_section(precbc))) { + unsigned int rshift = (unsigned int)value->rshift; + yasm_expr *syme; + if (value->rshift > 0) + syme = yasm_expr_create(YASM_EXPR_SHR, yasm_expr_sym(value->rel), + yasm_expr_int(yasm_intnum_create_uint(rshift)), bc->line); + else + syme = yasm_expr_create_ident(yasm_expr_sym(value->rel), bc->line); + if (!value->abs) - value->abs = yasm_expr_create_ident(yasm_expr_sym(value->rel), - bc->line); + value->abs = syme; else value->abs = yasm_expr_create(YASM_EXPR_ADD, yasm_expr_expr(value->abs), - yasm_expr_sym(value->rel), bc->line); + yasm_expr_expr(syme), bc->line); value->rel = NULL; + value->rshift = 0; } /* Simplify absolute portion of value, transforming symrecs */ @@ -170,7 +178,7 @@ bin_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, } /* Absolute value; handle it here as output_basic won't understand it */ - if (yasm_symrec_is_abs(value->rel)) { + if (value->rel && yasm_symrec_is_abs(value->rel)) { if (value->curpos_rel) { /* Calculate value relative to current assembly position */ /*@only@*/ yasm_intnum *outval; diff --git a/modules/objfmts/bin/tests/Makefile.inc b/modules/objfmts/bin/tests/Makefile.inc index 1251308c..368831df 100644 --- a/modules/objfmts/bin/tests/Makefile.inc +++ b/modules/objfmts/bin/tests/Makefile.inc @@ -28,3 +28,5 @@ EXTRA_DIST += modules/objfmts/bin/tests/reserve.hex EXTRA_DIST += modules/objfmts/bin/tests/reserve.errwarn EXTRA_DIST += modules/objfmts/bin/tests/reserve-err.asm EXTRA_DIST += modules/objfmts/bin/tests/reserve-err.errwarn +EXTRA_DIST += modules/objfmts/bin/tests/shr.asm +EXTRA_DIST += modules/objfmts/bin/tests/shr.hex diff --git a/modules/objfmts/bin/tests/shr.asm b/modules/objfmts/bin/tests/shr.asm new file mode 100644 index 00000000..66ade16c --- /dev/null +++ b/modules/objfmts/bin/tests/shr.asm @@ -0,0 +1,3 @@ +x: mov al, x>>8 +times 256 db 0 +y: mov ah, y>>8 diff --git a/modules/objfmts/bin/tests/shr.hex b/modules/objfmts/bin/tests/shr.hex new file mode 100644 index 00000000..9ce7eee7 --- /dev/null +++ b/modules/objfmts/bin/tests/shr.hex @@ -0,0 +1,260 @@ +b0 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +b4 +01