mirror of
https://github.com/yasm/yasm
synced 2026-08-26 22:26:05 -04:00
Overrides and dummy value finalization for bin
- Added support for overriding certain functions - Override value_finalize with dummy function for the bin objfmt
This commit is contained in:
parent
662fa69efc
commit
8da658af79
4 changed files with 38 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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() */
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue