diff --git a/libyasm/value.c b/libyasm/value.c index 067684e2..94726d13 100644 --- a/libyasm/value.c +++ b/libyasm/value.c @@ -494,33 +494,31 @@ yasm_value_get_intnum(yasm_value *value, yasm_bytecode *bc, int calc_bc_dist) } if (value->rel) { - /* Get the relative portion's offset. */ + /* If relative portion is not in bc section, return NULL. + * Otherwise get the relative portion's offset. + */ /*@dependent@*/ yasm_bytecode *rel_prevbc; unsigned long dist; - if (!calc_bc_dist) - return NULL; /* Don't calculate BC distance */ + if (!bc) + return NULL; /* Can't calculate relative value */ sym_local = yasm_symrec_get_label(value->rel, &rel_prevbc); if (value->wrt || value->seg_of || value->section_rel || !sym_local) return NULL; /* we can't handle SEG, WRT, or external symbols */ + if (rel_prevbc->section != bc->section) + return NULL; /* not in this section */ + if (!value->curpos_rel) + return NULL; /* not PC-relative */ - /* Calculate relative value as integer */ + /* Calculate value relative to current assembly position */ dist = rel_prevbc->offset + rel_prevbc->len; - if (value->curpos_rel) { - /* PC-relative */ - if (!bc) - return NULL; /* Can't calculate PC-relative value */ - if (rel_prevbc->section != bc->section) - return NULL; /* not in this section */ - - if (dist < bc->offset) { - outval = yasm_intnum_create_uint(bc->offset - dist); - yasm_intnum_calc(outval, YASM_EXPR_NEG, NULL); - } else { - dist -= bc->offset; - outval = yasm_intnum_create_uint(dist); - } + if (dist < bc->offset) { + outval = yasm_intnum_create_uint(bc->offset - dist); + yasm_intnum_calc(outval, YASM_EXPR_NEG, NULL); + } else { + dist -= bc->offset; + outval = yasm_intnum_create_uint(dist); } if (value->rshift > 0) { diff --git a/libyasm/value.h b/libyasm/value.h index 0517f189..89a93aa8 100644 --- a/libyasm/value.h +++ b/libyasm/value.h @@ -100,15 +100,15 @@ int yasm_value_finalize_expr(/*@out@*/ yasm_value *value, /*@null@*/ /*@kept@*/ yasm_expr *e, unsigned int size); -/** Get value if absolute, pure relative, or PC-relative section-local - * relative. Returns NULL otherwise. +/** Get value if absolute or PC-relative section-local relative. Returns NULL + * otherwise. * \param value value * \param bc current bytecode (for PC-relative calculation); if * NULL, NULL is returned for PC-relative values. * \param calc_bc_dist if nonzero, calculates bytecode distances in absolute * portion of value * \note Adds in value.rel (correctly) if PC-relative and in the same section - * as bc (and there is no WRT or SEG), or if value is pure-relative. + * as bc (and there is no WRT or SEG). * \return Intnum if can be resolved to integer value, otherwise NULL. */ /*@null@*/ /*@only@*/ yasm_intnum *yasm_value_get_intnum