Skip to content

Commit

Permalink
Overrides and dummy value finalization for bin
Browse files Browse the repository at this point in the history
- Added support for overriding certain functions
- Override value_finalize with dummy function for the bin objfmt
  • Loading branch information
jix committed Jul 31, 2012
1 parent 662fa69 commit 8da658a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libyasm/section.c
Expand Up @@ -241,6 +241,11 @@ yasm_object_create(const char *src_filename, const char *obj_filename,
/* Initialize things to NULL in case of error */
object->dbgfmt = NULL;

/* Initialize override structure */
object->overrides = yasm_xmalloc(sizeof(yasm_overrides));

object->overrides->value_finalize = NULL;

/* Initialize the object format */
object->objfmt = yasm_objfmt_create(objfmt_module, object);
if (!object->objfmt) {
Expand Down Expand Up @@ -485,6 +490,8 @@ yasm_object_destroy(yasm_object *object)
if (object->arch)
yasm_arch_destroy(object->arch);

yasm_xfree(object->overrides);

yasm_xfree(object);
}

Expand Down
10 changes: 10 additions & 0 deletions libyasm/section.h
Expand Up @@ -45,6 +45,15 @@ struct yasm_reloc {
/*@dependent@*/ yasm_symrec *sym; /**< Relocated symbol */
};

/** Structure of functions that can be overridden
*/
typedef struct yasm_overrides {
/** TODO: documentation
*/
int
(*value_finalize)(yasm_value *value, yasm_bytecode *precbc);
} yasm_overrides;

/** An object. This is the internal representation of an object file. */
struct yasm_object {
/*@owned@*/ char *src_filename; /**< Source filename */
Expand All @@ -54,6 +63,7 @@ struct yasm_object {
/*@owned@*/ yasm_arch *arch; /**< Target architecture */
/*@owned@*/ yasm_objfmt *objfmt; /**< Object format */
/*@owned@*/ yasm_dbgfmt *dbgfmt; /**< Debug format */
/*@owned@*/ yasm_overrides *overrides; /**< Function overrides */

/** Currently active section. Used by some directives. NULL if no
* section active.
Expand Down
11 changes: 11 additions & 0 deletions libyasm/value.c
Expand Up @@ -459,9 +459,20 @@ yasm_value_finalize_expr(yasm_value *value, yasm_expr *e,
int
yasm_value_finalize(yasm_value *value, yasm_bytecode *precbc)
{
yasm_object *object = NULL;
if (!value->abs)
return 0;

if (precbc != NULL)
object = yasm_section_get_object(precbc->section);

if (object && object->overrides->value_finalize) {
int result;
result = object->overrides->value_finalize(value, precbc);
if (result != -1)
return result;
}

value->abs = yasm_expr__level_tree(value->abs, 1, 1, 0, 0, NULL, NULL);

/* quit early if there was an issue in simplify() */
Expand Down
10 changes: 10 additions & 0 deletions modules/objfmts/bin/bin-objfmt.c
Expand Up @@ -104,6 +104,7 @@ static const yasm_assoc_data_callback bin_symrec_data_cb = {

yasm_objfmt_module yasm_bin_LTX_objfmt;

static int bin_objfmt_value_finalize(yasm_value *value, yasm_bytecode *precbc);

static yasm_objfmt *
bin_objfmt_create(yasm_object *object)
Expand All @@ -115,6 +116,8 @@ bin_objfmt_create(yasm_object *object)
objfmt_bin->map_filename = NULL;
objfmt_bin->org = NULL;

object->overrides->value_finalize = bin_objfmt_value_finalize;

return (yasm_objfmt *)objfmt_bin;
}

Expand Down Expand Up @@ -935,6 +938,13 @@ check_lma_overlap(yasm_section *sect, /*@null@*/ void *d)
return 0;
}

static int
bin_objfmt_value_finalize(yasm_value *value, yasm_bytecode *precbc)
{
/* TODO do some finalization to avoid breaking stuff that depends on it */
return 0;
}

static int
bin_objfmt_output_value(yasm_value *value, unsigned char *buf,
unsigned int destsize,
Expand Down

0 comments on commit 8da658a

Please sign in to comment.