]> granicus.if.org Git - yasm/commitdiff
Add offset parameter to output_expr functions (needed for relocation support).
authorPeter Johnson <peter@tortall.net>
Sun, 20 Oct 2002 20:39:29 +0000 (20:39 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 20 Oct 2002 20:39:29 +0000 (20:39 -0000)
svn path=/trunk/yasm/; revision=767

libyasm/bytecode.c
libyasm/coretype.h
modules/arch/x86/x86bc.c
modules/objfmts/bin/bin-objfmt.c
src/arch/x86/x86bc.c
src/bytecode.c
src/coretype.h
src/objfmts/bin/bin-objfmt.c

index 4c3bae7fc4e351e89712c65ec7276a8fd21501d3..5f74ccd4d2ed4f87933f6ebf17d773d670365772 100644 (file)
@@ -662,14 +662,15 @@ bc_tobytes_data(bytecode_data *bc_data, unsigned char **bufp,
     dataval *dv;
     size_t slen;
     size_t i;
+    unsigned char *bufp_orig = *bufp;
 
     STAILQ_FOREACH(dv, &bc_data->datahead, link) {
        switch (dv->type) {
            case DV_EMPTY:
                break;
            case DV_EXPR:
-               if (output_expr(&dv->data.expn, bufp, bc_data->size, sect, bc,
-                               0, d))
+               if (output_expr(&dv->data.expn, bufp, bc_data->size,
+                               *bufp-bufp_orig, sect, bc, 0, d))
                    return 1;
                break;
            case DV_STRING:
index e73a8a0cbd5e858488ef64d622a7813e4a91646d..9c342469f81baafdda2d032b4bf5ef9696085e62 100644 (file)
@@ -98,14 +98,15 @@ typedef /*@null@*/ intnum * (*calc_bc_dist_func) (section *sect,
  *  ep      - (double) pointer to the expression to output
  *  bufp    - (double) pointer to buffer to contain byte representation
  *  valsize - the size (in bytes) to be used for the byte rep
+ *  offset  - the offset (in bytes) of the expr contents from the bc start
  *  sect    - current section (usually passed into higher-level calling fct)
- *  bc      - current bytecode (usually passed into higher-level callign fct)
+ *  bc      - current bytecode (usually passed into higher-level calling fct)
  *  rel     - should the expr be treated as PC/IP-relative? (nonzero=yes)
  *  d       - objfmt-specific data (passed into higher-level calling fct)
  * Returns nonzero if an error occurred, 0 otherwise
  */
 typedef int (*output_expr_func) (expr **ep, unsigned char **bufp,
-                                unsigned long valsize,
+                                unsigned long valsize, unsigned long offset,
                                 /*@observer@*/ const section *sect,
                                 /*@observer@*/ const bytecode *bc, int rel,
                                 /*@null@*/ void *d)
index 1901c62d4cb35b68819dc826bef6bea744ff21a2..0661711ecf1cad2df3eed3d355233df47f2dac9e 100644 (file)
@@ -811,6 +811,7 @@ x86_bc_tobytes_insn(x86_insn *insn, unsigned char **bufp, const section *sect,
     /*@null@*/ effaddr *ea = &x86_ea->ea;
     immval *imm = insn->imm;
     unsigned int i;
+    unsigned char *bufp_orig = *bufp;
 
     /* Prefixes */
     if (insn->lockrep_pre != 0)
@@ -866,7 +867,8 @@ x86_bc_tobytes_insn(x86_insn *insn, unsigned char **bufp, const section *sect,
                InternalError(_("checkea failed"));
 
            if (ea->disp) {
-               if (output_expr(&ea->disp, bufp, ea->len, sect, bc, 0, d))
+               if (output_expr(&ea->disp, bufp, ea->len, *bufp-bufp_orig,
+                               sect, bc, 0, d))
                    return 1;
            } else {
                /* 0 displacement, but we didn't know it before, so we have to
@@ -881,7 +883,8 @@ x86_bc_tobytes_insn(x86_insn *insn, unsigned char **bufp, const section *sect,
     /* Immediate (if required) */
     if (imm && imm->val) {
        /* TODO: check imm->len vs. sized len from expr? */
-       if (output_expr(&imm->val, bufp, imm->len, sect, bc, 0, d))
+       if (output_expr(&imm->val, bufp, imm->len, *bufp-bufp_orig, sect, bc,
+                       0, d))
            return 1;
     }
 
@@ -895,6 +898,7 @@ x86_bc_tobytes_jmprel(x86_jmprel *jmprel, unsigned char **bufp,
 {
     unsigned char opersize;
     unsigned int i;
+    unsigned char *bufp_orig = *bufp;
 
     /* Prefixes */
     if (jmprel->lockrep_pre != 0)
@@ -922,7 +926,8 @@ x86_bc_tobytes_jmprel(x86_jmprel *jmprel, unsigned char **bufp,
                WRITE_8(*bufp, jmprel->shortop.opcode[i]);
 
            /* Relative displacement */
-           if (output_expr(&jmprel->target, bufp, 1, sect, bc, 1, d))
+           if (output_expr(&jmprel->target, bufp, 1, *bufp-bufp_orig, sect,
+                           bc, 1, d))
                return 1;
            break;
        case JR_NEAR_FORCED:
@@ -939,7 +944,8 @@ x86_bc_tobytes_jmprel(x86_jmprel *jmprel, unsigned char **bufp,
 
            /* Relative displacement */
            if (output_expr(&jmprel->target, bufp,
-                           (opersize == 32) ? 4UL : 2UL, sect, bc, 1, d))
+                           (opersize == 32) ? 4UL : 2UL, *bufp-bufp_orig,
+                           sect, bc, 1, d))
                return 1;
            break;
        default:
index b6ed9b404af27618761741fd4515a25b1774838b..14120d4ad918765c3c58a9077393be606126e655 100644 (file)
@@ -130,6 +130,7 @@ bin_objfmt_expr_xform(/*@returned@*/ /*@only@*/ expr *e,
 
 static int
 bin_objfmt_output_expr(expr **ep, unsigned char **bufp, unsigned long valsize,
+                      /*@unused@*/ unsigned long offset,
                       /*@observer@*/ const section *sect,
                       /*@observer@*/ const bytecode *bc, int rel,
                       /*@unused@*/ /*@null@*/ void *d)
index 1901c62d4cb35b68819dc826bef6bea744ff21a2..0661711ecf1cad2df3eed3d355233df47f2dac9e 100644 (file)
@@ -811,6 +811,7 @@ x86_bc_tobytes_insn(x86_insn *insn, unsigned char **bufp, const section *sect,
     /*@null@*/ effaddr *ea = &x86_ea->ea;
     immval *imm = insn->imm;
     unsigned int i;
+    unsigned char *bufp_orig = *bufp;
 
     /* Prefixes */
     if (insn->lockrep_pre != 0)
@@ -866,7 +867,8 @@ x86_bc_tobytes_insn(x86_insn *insn, unsigned char **bufp, const section *sect,
                InternalError(_("checkea failed"));
 
            if (ea->disp) {
-               if (output_expr(&ea->disp, bufp, ea->len, sect, bc, 0, d))
+               if (output_expr(&ea->disp, bufp, ea->len, *bufp-bufp_orig,
+                               sect, bc, 0, d))
                    return 1;
            } else {
                /* 0 displacement, but we didn't know it before, so we have to
@@ -881,7 +883,8 @@ x86_bc_tobytes_insn(x86_insn *insn, unsigned char **bufp, const section *sect,
     /* Immediate (if required) */
     if (imm && imm->val) {
        /* TODO: check imm->len vs. sized len from expr? */
-       if (output_expr(&imm->val, bufp, imm->len, sect, bc, 0, d))
+       if (output_expr(&imm->val, bufp, imm->len, *bufp-bufp_orig, sect, bc,
+                       0, d))
            return 1;
     }
 
@@ -895,6 +898,7 @@ x86_bc_tobytes_jmprel(x86_jmprel *jmprel, unsigned char **bufp,
 {
     unsigned char opersize;
     unsigned int i;
+    unsigned char *bufp_orig = *bufp;
 
     /* Prefixes */
     if (jmprel->lockrep_pre != 0)
@@ -922,7 +926,8 @@ x86_bc_tobytes_jmprel(x86_jmprel *jmprel, unsigned char **bufp,
                WRITE_8(*bufp, jmprel->shortop.opcode[i]);
 
            /* Relative displacement */
-           if (output_expr(&jmprel->target, bufp, 1, sect, bc, 1, d))
+           if (output_expr(&jmprel->target, bufp, 1, *bufp-bufp_orig, sect,
+                           bc, 1, d))
                return 1;
            break;
        case JR_NEAR_FORCED:
@@ -939,7 +944,8 @@ x86_bc_tobytes_jmprel(x86_jmprel *jmprel, unsigned char **bufp,
 
            /* Relative displacement */
            if (output_expr(&jmprel->target, bufp,
-                           (opersize == 32) ? 4UL : 2UL, sect, bc, 1, d))
+                           (opersize == 32) ? 4UL : 2UL, *bufp-bufp_orig,
+                           sect, bc, 1, d))
                return 1;
            break;
        default:
index 4c3bae7fc4e351e89712c65ec7276a8fd21501d3..5f74ccd4d2ed4f87933f6ebf17d773d670365772 100644 (file)
@@ -662,14 +662,15 @@ bc_tobytes_data(bytecode_data *bc_data, unsigned char **bufp,
     dataval *dv;
     size_t slen;
     size_t i;
+    unsigned char *bufp_orig = *bufp;
 
     STAILQ_FOREACH(dv, &bc_data->datahead, link) {
        switch (dv->type) {
            case DV_EMPTY:
                break;
            case DV_EXPR:
-               if (output_expr(&dv->data.expn, bufp, bc_data->size, sect, bc,
-                               0, d))
+               if (output_expr(&dv->data.expn, bufp, bc_data->size,
+                               *bufp-bufp_orig, sect, bc, 0, d))
                    return 1;
                break;
            case DV_STRING:
index e73a8a0cbd5e858488ef64d622a7813e4a91646d..9c342469f81baafdda2d032b4bf5ef9696085e62 100644 (file)
@@ -98,14 +98,15 @@ typedef /*@null@*/ intnum * (*calc_bc_dist_func) (section *sect,
  *  ep      - (double) pointer to the expression to output
  *  bufp    - (double) pointer to buffer to contain byte representation
  *  valsize - the size (in bytes) to be used for the byte rep
+ *  offset  - the offset (in bytes) of the expr contents from the bc start
  *  sect    - current section (usually passed into higher-level calling fct)
- *  bc      - current bytecode (usually passed into higher-level callign fct)
+ *  bc      - current bytecode (usually passed into higher-level calling fct)
  *  rel     - should the expr be treated as PC/IP-relative? (nonzero=yes)
  *  d       - objfmt-specific data (passed into higher-level calling fct)
  * Returns nonzero if an error occurred, 0 otherwise
  */
 typedef int (*output_expr_func) (expr **ep, unsigned char **bufp,
-                                unsigned long valsize,
+                                unsigned long valsize, unsigned long offset,
                                 /*@observer@*/ const section *sect,
                                 /*@observer@*/ const bytecode *bc, int rel,
                                 /*@null@*/ void *d)
index b6ed9b404af27618761741fd4515a25b1774838b..14120d4ad918765c3c58a9077393be606126e655 100644 (file)
@@ -130,6 +130,7 @@ bin_objfmt_expr_xform(/*@returned@*/ /*@only@*/ expr *e,
 
 static int
 bin_objfmt_output_expr(expr **ep, unsigned char **bufp, unsigned long valsize,
+                      /*@unused@*/ unsigned long offset,
                       /*@observer@*/ const section *sect,
                       /*@observer@*/ const bytecode *bc, int rel,
                       /*@unused@*/ /*@null@*/ void *d)