diff --git a/configure.ac b/configure.ac index 68ccae99..7e44b42b 100644 --- a/configure.ac +++ b/configure.ac @@ -180,8 +180,8 @@ if test "$USE_MAINTAINER_MODE" = "yes"; then MORE_CFLAGS="$MORE_CFLAGS -Wswitch" MORE_CFLAGS="$MORE_CFLAGS -Wwrite-strings" MORE_CFLAGS="$MORE_CFLAGS -Wno-undef" - MORE_CFLAGS="$MORE_CFLAGS -Wno-unused" -# MORE_CFLAGS="$MORE_CFLAGS -Wno-unused-parameter" +# MORE_CFLAGS="$MORE_CFLAGS -Wno-unused" + MORE_CFLAGS="$MORE_CFLAGS -Wno-unused-parameter" fi fi diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index d49fce04..4a315bda 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -56,10 +56,8 @@ static int special_options = 0; /*@null@*/ /*@dependent@*/ static const yasm_preproc_module * cur_preproc_module = NULL; /*@null@*/ static char *objfmt_keyword = NULL; -/*@null@*/ /*@dependent@*/ static yasm_objfmt *cur_objfmt = NULL; /*@null@*/ /*@dependent@*/ static const yasm_objfmt_module * cur_objfmt_module = NULL; -/*@null@*/ /*@dependent@*/ static yasm_dbgfmt *cur_dbgfmt = NULL; /*@null@*/ /*@dependent@*/ static const yasm_dbgfmt_module * cur_dbgfmt_module = NULL; /*@null@*/ /*@dependent@*/ static yasm_listfmt *cur_listfmt = NULL; @@ -79,7 +77,8 @@ static enum { /*@null@*/ /*@dependent@*/ static FILE *open_file(const char *filename, const char *mode); static void check_errors(/*@only@*/ yasm_errwarns *errwarns, - /*@only@*/ yasm_object *object); + /*@only@*/ yasm_object *object, + /*@only@*/ yasm_linemap *linemap); static void cleanup(/*@null@*/ /*@only@*/ yasm_object *object); /* Forward declarations: cmd line parser handlers */ @@ -226,7 +225,7 @@ do_preproc_only(FILE *in) FILE *out = NULL; yasm_errwarns *errwarns = yasm_errwarns_create(); - /* Initialize line manager */ + /* Initialize line map */ linemap = yasm_linemap_create(); yasm_linemap_set(linemap, in_filename, 1, 1); @@ -321,13 +320,17 @@ static int do_assemble(FILE *in) { yasm_object *object; - yasm_section *def_sect; const char *base_filename; /*@null@*/ FILE *obj = NULL; yasm_arch_create_error arch_error; + yasm_linemap *linemap; yasm_errwarns *errwarns = yasm_errwarns_create(); int i, matched; + /* Initialize line map */ + linemap = yasm_linemap_create(); + yasm_linemap_set(linemap, in_filename, 1, 1); + /* determine the object filename if not specified */ if (!obj_filename) { if (in == stdin) @@ -383,16 +386,18 @@ do_assemble(FILE *in) } /* Create object */ - object = yasm_object_create(in_filename, obj_filename); - yasm_linemap_set(yasm_object_get_linemap(object), in_filename, 1, 1); + object = yasm_object_create(in_filename, obj_filename, cur_arch, + cur_objfmt_module, cur_dbgfmt_module); + if (!object) { + yasm_error_class eclass; + unsigned long xrefline; + /*@only@*/ /*@null@*/ char *estr, *xrefstr; + + yasm_error_fetch(&eclass, &estr, &xrefline, &xrefstr); + print_error("%s: %s", _("FATAL"), estr); + yasm_xfree(estr); + yasm_xfree(xrefstr); - /* Initialize the object format */ - cur_objfmt = yasm_objfmt_create(cur_objfmt_module, object, cur_arch); - if (!cur_objfmt) { - print_error( - _("%s: object format `%s' does not support architecture `%s' machine `%s'"), - _("FATAL"), cur_objfmt_module->keyword, cur_arch_module->keyword, - machine_name); if (in != stdin) fclose(in); cleanup(object); @@ -400,41 +405,7 @@ do_assemble(FILE *in) } /* Get a fresh copy of objfmt_module as it may have changed. */ - cur_objfmt_module = ((yasm_objfmt_base *)cur_objfmt)->module; - - /* Add an initial "default" section to object */ - def_sect = yasm_objfmt_add_default_section(cur_objfmt); - - /* Check to see if the requested debug format is in the allowed list - * for the active object format. - */ - matched = 0; - for (i=0; cur_objfmt_module->dbgfmt_keywords[i]; i++) - if (yasm__strcasecmp(cur_objfmt_module->dbgfmt_keywords[i], - cur_dbgfmt_module->keyword) == 0) - matched = 1; - if (!matched) { - print_error(_("%s: `%s' is not a valid %s for %s `%s'"), - _("FATAL"), cur_dbgfmt_module->keyword, _("debug format"), - _("object format"), cur_objfmt_module->keyword); - if (in != stdin) - fclose(in); - cleanup(object); - return EXIT_FAILURE; - } - - /* Initialize the debug format */ - cur_dbgfmt = yasm_dbgfmt_create(cur_dbgfmt_module, object, cur_objfmt, - cur_arch); - if (!cur_dbgfmt) { - print_error( - _("%s: debug format `%s' does not work with object format `%s'"), - _("FATAL"), cur_dbgfmt_module->keyword, - cur_objfmt_module->keyword); - if (in != stdin) - fclose(in); - return EXIT_FAILURE; - } + cur_objfmt_module = ((yasm_objfmt_base *)object->objfmt)->module; /* Check to see if the requested preprocessor is in the allowed list * for the active parser. @@ -454,8 +425,7 @@ do_assemble(FILE *in) return EXIT_FAILURE; } - cur_preproc = cur_preproc_module->create(in, in_filename, - yasm_object_get_linemap(object), + cur_preproc = cur_preproc_module->create(in, in_filename, linemap, errwarns); apply_preproc_builtins(); @@ -470,34 +440,33 @@ do_assemble(FILE *in) yasm_arch_set_var(cur_arch, "force_strict", force_strict); /* Parse! */ - cur_parser_module->do_parse(object, cur_preproc, cur_arch, cur_objfmt, - cur_dbgfmt, in, in_filename, - list_filename != NULL, def_sect, errwarns); + cur_parser_module->do_parse(object, cur_preproc, in, list_filename != NULL, + linemap, errwarns); /* Close input file */ if (in != stdin) fclose(in); - check_errors(errwarns, object); + check_errors(errwarns, object, linemap); /* Check for undefined symbols */ - yasm_symtab_parser_finalize(yasm_object_get_symtab(object), + yasm_symtab_parser_finalize(object->symtab, strcmp(cur_parser_module->keyword, "gas")==0 || strcmp(cur_parser_module->keyword, "gnu")==0, - cur_objfmt, errwarns); - check_errors(errwarns, object); + object, errwarns); + check_errors(errwarns, object, linemap); /* Finalize parse */ yasm_object_finalize(object, errwarns); - check_errors(errwarns, object); + check_errors(errwarns, object, linemap); /* Optimize */ - yasm_object_optimize(object, cur_arch, errwarns); - check_errors(errwarns, object); + yasm_object_optimize(object, errwarns); + check_errors(errwarns, object, linemap); /* generate any debugging information */ - yasm_dbgfmt_generate(cur_dbgfmt, errwarns); - check_errors(errwarns, object); + yasm_dbgfmt_generate(object, linemap, errwarns); + check_errors(errwarns, object, linemap); /* open the object file for output (if not already opened by dbg objfmt) */ if (!obj && strcmp(cur_objfmt_module->keyword, "dbg") != 0) { @@ -509,9 +478,8 @@ do_assemble(FILE *in) } /* Write the object file */ - yasm_objfmt_output(cur_objfmt, obj?obj:stderr, - strcmp(cur_dbgfmt_module->keyword, "null"), cur_dbgfmt, - errwarns); + yasm_objfmt_output(object, obj?obj:stderr, + strcmp(cur_dbgfmt_module->keyword, "null"), errwarns); /* Close object file */ if (obj) @@ -522,7 +490,7 @@ do_assemble(FILE *in) */ if (yasm_errwarns_num_errors(errwarns, warning_error) > 0) remove(obj_filename); - check_errors(errwarns, object); + check_errors(errwarns, object, linemap); /* Open and write the list file */ if (list_filename) { @@ -534,15 +502,14 @@ do_assemble(FILE *in) /* Initialize the list format */ cur_listfmt = yasm_listfmt_create(cur_listfmt_module, in_filename, obj_filename); - yasm_listfmt_output(cur_listfmt, list, - yasm_object_get_linemap(object), cur_arch); + yasm_listfmt_output(cur_listfmt, list, linemap, cur_arch); fclose(list); } - yasm_errwarns_output_all(errwarns, yasm_object_get_linemap(object), - warning_error, print_yasm_error, - print_yasm_warning); + yasm_errwarns_output_all(errwarns, linemap, warning_error, + print_yasm_error, print_yasm_warning); + yasm_linemap_destroy(linemap); yasm_errwarns_destroy(errwarns); cleanup(object); return EXIT_SUCCESS; @@ -734,12 +701,13 @@ open_file(const char *filename, const char *mode) } static void -check_errors(yasm_errwarns *errwarns, yasm_object *object) +check_errors(yasm_errwarns *errwarns, yasm_object *object, + yasm_linemap *linemap) { if (yasm_errwarns_num_errors(errwarns, warning_error) > 0) { - yasm_errwarns_output_all(errwarns, yasm_object_get_linemap(object), - warning_error, print_yasm_error, - print_yasm_warning); + yasm_errwarns_output_all(errwarns, linemap, warning_error, + print_yasm_error, print_yasm_warning); + yasm_linemap_destroy(linemap); yasm_errwarns_destroy(errwarns); cleanup(object); exit(EXIT_FAILURE); @@ -757,18 +725,12 @@ static void cleanup(yasm_object *object) { if (DO_FREE) { - if (cur_objfmt) - yasm_objfmt_destroy(cur_objfmt); - if (cur_dbgfmt) - yasm_dbgfmt_destroy(cur_dbgfmt); if (cur_listfmt) yasm_listfmt_destroy(cur_listfmt); if (cur_preproc) yasm_preproc_destroy(cur_preproc); if (object) yasm_object_destroy(object); - if (cur_arch) - yasm_arch_destroy(cur_arch); yasm_floatnum_cleanup(); yasm_intnum_cleanup(); diff --git a/libyasm/coretype.h b/libyasm/coretype.h index a6b92b04..3f5e3a79 100644 --- a/libyasm/coretype.h +++ b/libyasm/coretype.h @@ -47,6 +47,11 @@ typedef struct yasm_dbgfmt yasm_dbgfmt; /** List format interface. \see listfmt.h for details. */ typedef struct yasm_listfmt yasm_listfmt; +/** Object format module interface. \see objfmt.h for details. */ +typedef struct yasm_objfmt_module yasm_objfmt_module; +/** Debug format module interface. \see dbgfmt.h for details. */ +typedef struct yasm_dbgfmt_module yasm_dbgfmt_module; + /** YASM associated data callback structure. Many data structures can have * arbitrary data associated with them. */ @@ -75,7 +80,7 @@ typedef struct yasm_errwarns yasm_errwarns; */ typedef struct yasm_bytecode yasm_bytecode; -/** Object (opaque type). \see section.h for related functions. */ +/** Object. \see section.h for details and related functions. */ typedef struct yasm_object yasm_object; /** Section (opaque type). \see section.h for related functions. */ diff --git a/libyasm/dbgfmt.h b/libyasm/dbgfmt.h index cae3568d..8a416348 100644 --- a/libyasm/dbgfmt.h +++ b/libyasm/dbgfmt.h @@ -44,8 +44,8 @@ typedef struct yasm_dbgfmt_base { } yasm_dbgfmt_base; #endif -/** YASM debug format module interface. */ -typedef struct yasm_dbgfmt_module { +/** Debug format module interface. */ +struct yasm_dbgfmt_module { /** One-line description of the debug format. */ const char *name; @@ -56,12 +56,9 @@ typedef struct yasm_dbgfmt_module { * Module-level implementation of yasm_dbgfmt_create(). * The filenames are provided solely for informational purposes. * \param object object - * \param of object format in use - * \param a architecture in use * \return NULL if object format does not provide needed support. */ - /*@null@*/ /*@only@*/ yasm_dbgfmt * (*create) - (yasm_object *object, yasm_objfmt *of, yasm_arch *a); + /*@null@*/ /*@only@*/ yasm_dbgfmt * (*create) (yasm_object *object); /** Module-level implementation of yasm_dbgfmt_destroy(). * Call yasm_dbgfmt_destroy() instead of calling this function. @@ -71,16 +68,16 @@ typedef struct yasm_dbgfmt_module { /** Module-level implementation of yasm_dbgfmt_directive(). * Call yasm_dbgfmt_directive() instead of calling this function. */ - int (*directive) (yasm_dbgfmt *dbgfmt, const char *name, - yasm_section *sect, + int (*directive) (yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, unsigned long line); /** Module-level implementation of yasm_dbgfmt_generate(). * Call yasm_dbgfmt_generate() instead of calling this function. */ - void (*generate) (yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns); -} yasm_dbgfmt_module; + void (*generate) (yasm_object *object, yasm_linemap *linemap, + yasm_errwarns *errwarns); +}; /** Get the keyword used to select a debug format. * \param dbgfmt debug format @@ -98,8 +95,7 @@ const char *yasm_dbgfmt_keyword(const yasm_dbgfmt *dbgfmt); * \return NULL if object format does not provide needed support. */ /*@null@*/ /*@only@*/ yasm_dbgfmt *yasm_dbgfmt_create - (const yasm_dbgfmt_module *module, yasm_object *object, yasm_objfmt *of, - yasm_arch *a); + (const yasm_dbgfmt_module *module, yasm_object *object); /** Cleans up any allocated debug format memory. * \param dbgfmt debug format @@ -107,25 +103,25 @@ const char *yasm_dbgfmt_keyword(const yasm_dbgfmt *dbgfmt); void yasm_dbgfmt_destroy(/*@only@*/ yasm_dbgfmt *dbgfmt); /** DEBUG directive support. - * \param dbgfmt debug format + * \param object object * \param name directive name - * \param sect current active section * \param valparams value/parameters * \param line virtual line (from yasm_linemap) * \return Nonzero if directive was not recognized; 0 if directive was * recognized even if it wasn't valid. */ -int yasm_dbgfmt_directive(yasm_dbgfmt *dbgfmt, const char *name, - yasm_section *sect, +int yasm_dbgfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, unsigned long line); /** Generate debugging information bytecodes. - * \param dbgfmt debug format + * \param object object + * \param linemap virtual/physical line mapping * \param errwarns error/warning set * \note Errors and warnings are stored into errwarns. */ -void yasm_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns); +void yasm_dbgfmt_generate(yasm_object *object, yasm_linemap *linemap, + yasm_errwarns *errwarns); #ifndef YASM_DOXYGEN @@ -134,16 +130,17 @@ void yasm_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns); #define yasm_dbgfmt_keyword(dbgfmt) \ (((yasm_dbgfmt_base *)dbgfmt)->module->keyword) -#define yasm_dbgfmt_create(module, object, of, a) \ - module->create(object, of, a) +#define yasm_dbgfmt_create(module, object) \ + module->create(object) #define yasm_dbgfmt_destroy(dbgfmt) \ ((yasm_dbgfmt_base *)dbgfmt)->module->destroy(dbgfmt) -#define yasm_dbgfmt_directive(dbgfmt, name, sect, valparams, line) \ - ((yasm_dbgfmt_base *)dbgfmt)->module->directive(dbgfmt, name, sect, \ - valparams, line) -#define yasm_dbgfmt_generate(dbgfmt, ews) \ - ((yasm_dbgfmt_base *)dbgfmt)->module->generate(dbgfmt, ews) +#define yasm_dbgfmt_directive(object, name, valparams, line) \ + ((yasm_dbgfmt_base *)((object)->dbgfmt))->module->directive \ + (object, name, valparams, line) +#define yasm_dbgfmt_generate(object, linemap, ews) \ + ((yasm_dbgfmt_base *)((object)->dbgfmt))->module->generate \ + (object, linemap, ews) #endif diff --git a/libyasm/objfmt.h b/libyasm/objfmt.h index 129803dc..9ada7d2c 100644 --- a/libyasm/objfmt.h +++ b/libyasm/objfmt.h @@ -44,8 +44,8 @@ typedef struct yasm_objfmt_base { } yasm_objfmt_base; #endif -/** YASM object format module interface. */ -typedef struct yasm_objfmt_module { +/** Object format module interface. */ +struct yasm_objfmt_module { /** One-line description of the object format. */ const char *name; @@ -81,13 +81,12 @@ typedef struct yasm_objfmt_module { * \param a architecture in use * \return NULL if architecture/machine combination not supported. */ - /*@null@*/ /*@only@*/ yasm_objfmt * (*create) (yasm_object *object, - yasm_arch *a); + /*@null@*/ /*@only@*/ yasm_objfmt * (*create) (yasm_object *object); /** Module-level implementation of yasm_objfmt_output(). * Call yasm_objfmt_output() instead of calling this function. */ - void (*output) (yasm_objfmt *of, FILE *f, int all_syms, yasm_dbgfmt *df, + void (*output) (yasm_object *o, FILE *f, int all_syms, yasm_errwarns *errwarns); /** Module-level implementation of yasm_objfmt_destroy(). @@ -98,13 +97,13 @@ typedef struct yasm_objfmt_module { /** Module-level implementation of yasm_objfmt_add_default_section(). * Call yasm_objfmt_add_default_section() instead of calling this function. */ - yasm_section * (*add_default_section) (yasm_objfmt *objfmt); + yasm_section * (*add_default_section) (yasm_object *object); /** Module-level implementation of yasm_objfmt_section_switch(). * Call yasm_objfmt_section_switch() instead of calling this function. */ /*@observer@*/ /*@null@*/ yasm_section * - (*section_switch)(yasm_objfmt *objfmt, yasm_valparamhead *valparams, + (*section_switch)(yasm_object *object, yasm_valparamhead *valparams, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); @@ -112,54 +111,52 @@ typedef struct yasm_objfmt_module { * Call yasm_objfmt_extern_declare() instead of calling this function. */ yasm_symrec * (*extern_declare) - (yasm_objfmt *objfmt, const char *name, + (yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); /** Module-level implementation of yasm_objfmt_global_declare(). * Call yasm_objfmt_global_declare() instead of calling this function. */ yasm_symrec * (*global_declare) - (yasm_objfmt *objfmt, const char *name, + (yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); /** Module-level implementation of yasm_objfmt_common_declare(). * Call yasm_objfmt_common_declare() instead of calling this function. */ yasm_symrec * (*common_declare) - (yasm_objfmt *objfmt, const char *name, /*@only@*/ yasm_expr *size, + (yasm_object *object, const char *name, /*@only@*/ yasm_expr *size, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); /** Module-level implementation of yasm_objfmt_directive(). * Call yasm_objfmt_directive() instead of calling this function. */ - int (*directive) (yasm_objfmt *objfmt, const char *name, + int (*directive) (yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); -} yasm_objfmt_module; +}; /** Create object format. * \param module object format module * \param object object - * \param a architecture in use * \return NULL if architecture/machine combination not supported. */ /*@null@*/ /*@only@*/ yasm_objfmt *yasm_objfmt_create - (const yasm_objfmt_module *module, yasm_object *object, yasm_arch *a); + (const yasm_objfmt_module *module, yasm_object *object); /** Write out (post-optimized) sections to the object file. * This function may call yasm_symrec_* functions as necessary (including * yasm_symrec_traverse()) to retrieve symbolic information. - * \param objfmt object format + * \param object object * \param f output object file * \param all_syms if nonzero, all symbols should be included in * the object file - * \param df debug format in use * \param errwarns error/warning set * \note Errors and warnings are stored into errwarns. */ -void yasm_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, - yasm_dbgfmt *df, yasm_errwarns *errwarns); +void yasm_objfmt_output(yasm_object *object, FILE *f, int all_syms, + yasm_errwarns *errwarns); /** Cleans up any allocated object format memory. * \param objfmt object format @@ -167,52 +164,52 @@ void yasm_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, void yasm_objfmt_destroy(/*@only@*/ yasm_objfmt *objfmt); /** Add a default section to an object. - * \param objfmt object format + * \param object object * \return Default section. */ -yasm_section *yasm_objfmt_add_default_section(yasm_objfmt *objfmt); +yasm_section *yasm_objfmt_add_default_section(yasm_object *object); /** Switch object file sections. The first val of the valparams should * be the section name. Calls yasm_object_get_general() to actually get * the section. - * \param objfmt object format + * \param object object * \param valparams value/parameters * \param objext_valparams object format-specific value/parameters * \param line virtual line (from yasm_linemap) * \return NULL on error, otherwise new section. */ /*@observer@*/ /*@null@*/ yasm_section *yasm_objfmt_section_switch - (yasm_objfmt *objfmt, yasm_valparamhead *valparams, + (yasm_object *object, yasm_valparamhead *valparams, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); /** Declare an "extern" (importing from another module) symbol. Should * call yasm_symtab_declare(). - * \param objfmt object format + * \param object object * \param name symbol name * \param objext_valparams object format-specific value/paramaters * \param line virtual line (from yasm_linemap) * \return Declared symbol. */ yasm_symrec *yasm_objfmt_extern_declare - (yasm_objfmt *objfmt, const char *name, + (yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); /** Declare a "global" (exporting to other modules) symbol. Should call * yasm_symtab_declare(). - * \param objfmt object format + * \param object object * \param name symbol name * \param objext_valparams object format-specific value/paramaters * \param line virtual line (from yasm_linemap) * \return Declared symbol. */ yasm_symrec *yasm_objfmt_global_declare - (yasm_objfmt *objfmt, const char *name, + (yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); /** Declare a "common" (shared space with other modules) symbol. Should * call yasm_symtab_declare(). * declaration. - * \param objfmt object format + * \param object object * \param name symbol name * \param size common data size * \param objext_valparams object format-specific value/paramaters @@ -220,11 +217,11 @@ yasm_symrec *yasm_objfmt_global_declare * \return Declared symbol. */ yasm_symrec *yasm_objfmt_common_declare - (yasm_objfmt *objfmt, const char *name, /*@only@*/ yasm_expr *size, + (yasm_object *object, const char *name, /*@only@*/ yasm_expr *size, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); /** Handle object format-specific directives. - * \param objfmt object format + * \param object object * \param name directive name * \param valparams value/parameters * \param objext_valparams object format-specific value/parameters @@ -232,7 +229,7 @@ yasm_symrec *yasm_objfmt_common_declare * \return Nonzero if directive was not recognized; 0 if directive was * recognized, even if it wasn't valid. */ -int yasm_objfmt_directive(yasm_objfmt *objfmt, const char *name, +int yasm_objfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line); @@ -241,29 +238,31 @@ int yasm_objfmt_directive(yasm_objfmt *objfmt, const char *name, /* Inline macro implementations for objfmt functions */ -#define yasm_objfmt_create(module, object, a) module->create(object, a) +#define yasm_objfmt_create(module, object) module->create(object) -#define yasm_objfmt_output(objfmt, f, all_syms, df, ews) \ - ((yasm_objfmt_base *)objfmt)->module->output(objfmt, f, all_syms, df, ews) +#define yasm_objfmt_output(object, f, all_syms, ews) \ + ((yasm_objfmt_base *)((object)->objfmt))->module->output \ + (object, f, all_syms, ews) #define yasm_objfmt_destroy(objfmt) \ ((yasm_objfmt_base *)objfmt)->module->destroy(objfmt) -#define yasm_objfmt_section_switch(objfmt, vpms, oe_vpms, line) \ - ((yasm_objfmt_base *)objfmt)->module->section_switch(objfmt, vpms, \ - oe_vpms, line) -#define yasm_objfmt_extern_declare(objfmt, name, oe_vpms, line) \ - ((yasm_objfmt_base *)objfmt)->module->extern_declare(objfmt, name, \ - oe_vpms, line) -#define yasm_objfmt_global_declare(objfmt, name, oe_vpms, line) \ - ((yasm_objfmt_base *)objfmt)->module->global_declare(objfmt, name, \ - oe_vpms, line) -#define yasm_objfmt_common_declare(objfmt, name, size, oe_vpms, line) \ - ((yasm_objfmt_base *)objfmt)->module->common_declare(objfmt, name, size, \ - oe_vpms, line) -#define yasm_objfmt_directive(objfmt, name, vpms, oe_vpms, line) \ - ((yasm_objfmt_base *)objfmt)->module->directive(objfmt, name, vpms, \ - oe_vpms, line) -#define yasm_objfmt_add_default_section(objfmt) \ - ((yasm_objfmt_base *)objfmt)->module->add_default_section(objfmt) +#define yasm_objfmt_section_switch(object, vpms, oe_vpms, line) \ + ((yasm_objfmt_base *)((object)->objfmt))->module->section_switch \ + (object, vpms, oe_vpms, line) +#define yasm_objfmt_extern_declare(object, name, oe_vpms, line) \ + ((yasm_objfmt_base *)((object)->objfmt))->module->extern_declare \ + (object, name, oe_vpms, line) +#define yasm_objfmt_global_declare(object, name, oe_vpms, line) \ + ((yasm_objfmt_base *)((object)->objfmt))->module->global_declare \ + (object, name, oe_vpms, line) +#define yasm_objfmt_common_declare(object, name, size, oe_vpms, line) \ + ((yasm_objfmt_base *)((object)->objfmt))->module->common_declare \ + (object, name, size, oe_vpms, line) +#define yasm_objfmt_directive(object, name, vpms, oe_vpms, line) \ + ((yasm_objfmt_base *)((object)->objfmt))->module->directive \ + (object, name, vpms, oe_vpms, line) +#define yasm_objfmt_add_default_section(object) \ + ((yasm_objfmt_base *)((object)->objfmt))->module->add_default_section \ + (object) #endif diff --git a/libyasm/parser.h b/libyasm/parser.h index 80b6fcab..e85b217e 100644 --- a/libyasm/parser.h +++ b/libyasm/parser.h @@ -54,23 +54,16 @@ typedef struct yasm_parser_module { /** Parse a source file into an object. * \param object object to parse into (already created) * \param pp preprocessor - * \param a architecture; architecture-specific directives are - * obtained from this. - * \param of object format; objfmt-specific directives and segment - * names are obtained from this. * \param f initial starting file - * \param in_filename initial starting file's filename * \param save_input nonzero if the parser should save the original * lines of source into the object's linemap (via * yasm_linemap_add_data()). - * \param def_sect default (starting) section in the object * \param errwarns error/warning set * \note Parse errors and warnings are stored into errwarns. */ void (*do_parse) - (yasm_object *object, yasm_preproc *pp, yasm_arch *a, yasm_objfmt *of, - yasm_dbgfmt *df, FILE *f, const char *in_filename, int save_input, - yasm_section *def_sect, yasm_errwarns *errwarns); + (yasm_object *object, yasm_preproc *pp, FILE *f, int save_input, + yasm_linemap *linemap, yasm_errwarns *errwarns); } yasm_parser_module; #endif diff --git a/libyasm/section.c b/libyasm/section.c index 357a69d2..812218ac 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -45,6 +45,8 @@ #include "bytecode.h" #include "arch.h" #include "section.h" + +#include "dbgfmt.h" #include "objfmt.h" #include "expr-int.h" @@ -53,16 +55,6 @@ #include "inttree.h" -struct yasm_object { - /*@owned@*/ char *src_filename; - /*@owned@*/ char *obj_filename; - - yasm_symtab *symtab; - yasm_linemap *linemap; - - /*@reldef@*/ STAILQ_HEAD(yasm_sectionhead, yasm_section) sections; -}; - struct yasm_section { /*@reldef@*/ STAILQ_ENTRY(yasm_section) link; @@ -112,21 +104,74 @@ static void yasm_section_destroy(/*@only@*/ yasm_section *sect); /*@-compdestroy@*/ yasm_object * -yasm_object_create(const char *src_filename, const char *obj_filename) +yasm_object_create(const char *src_filename, const char *obj_filename, + /*@kept@*/ yasm_arch *arch, + const yasm_objfmt_module *objfmt_module, + const yasm_dbgfmt_module *dbgfmt_module) { yasm_object *object = yasm_xmalloc(sizeof(yasm_object)); + int matched, i; object->src_filename = yasm__xstrdup(src_filename); object->obj_filename = yasm__xstrdup(obj_filename); - /* Create empty symtab and linemap */ + /* Create empty symbol table */ object->symtab = yasm_symtab_create(); - object->linemap = yasm_linemap_create(); /* Initialize sections linked list */ STAILQ_INIT(&object->sections); + /* Initialize the target architecture */ + object->arch = arch; + + /* Initialize things to NULL in case of error */ + object->dbgfmt = NULL; + + /* Initialize the object format */ + object->objfmt = yasm_objfmt_create(objfmt_module, object); + if (!object->objfmt) { + yasm_error_set(YASM_ERROR_GENERAL, + N_("object format `%s' does not support architecture `%s' machine `%s'"), + objfmt_module->keyword, ((yasm_arch_base *)arch)->module->keyword, + yasm_arch_get_machine(arch)); + goto error; + } + + /* Get a fresh copy of objfmt_module as it may have changed. */ + objfmt_module = ((yasm_objfmt_base *)object->objfmt)->module; + + /* Add an initial "default" section to object */ + object->cur_section = yasm_objfmt_add_default_section(object); + + /* Check to see if the requested debug format is in the allowed list + * for the active object format. + */ + matched = 0; + for (i=0; objfmt_module->dbgfmt_keywords[i]; i++) + if (yasm__strcasecmp(objfmt_module->dbgfmt_keywords[i], + dbgfmt_module->keyword) == 0) + matched = 1; + if (!matched) { + yasm_error_set(YASM_ERROR_GENERAL, + N_("`%s' is not a valid debug format for object format `%s'"), + dbgfmt_module->keyword, objfmt_module->keyword); + goto error; + } + + /* Initialize the debug format */ + object->dbgfmt = yasm_dbgfmt_create(dbgfmt_module, object); + if (!object->dbgfmt) { + yasm_error_set(YASM_ERROR_GENERAL, + N_("debug format `%s' does not work with object format `%s'"), + dbgfmt_module->keyword, objfmt_module->keyword); + goto error; + } + return object; + +error: + yasm_object_destroy(object); + return NULL; } /*@=compdestroy@*/ @@ -236,30 +281,6 @@ yasm_object_set_source_fn(yasm_object *object, const char *src_filename) object->src_filename = yasm__xstrdup(src_filename); } -const char * -yasm_object_get_source_fn(const yasm_object *object) -{ - return object->src_filename; -} - -const char * -yasm_object_get_object_fn(const yasm_object *object) -{ - return object->obj_filename; -} - -yasm_symtab * -yasm_object_get_symtab(const yasm_object *object) -{ - return object->symtab; -} - -yasm_linemap * -yasm_object_get_linemap(const yasm_object *object) -{ - return object->linemap; -} - int yasm_section_is_absolute(yasm_section *sect) { @@ -321,6 +342,14 @@ yasm_object_destroy(yasm_object *object) { yasm_section *cur, *next; + /* Delete object format, debug format, and arch. This can be called + * due to an error in yasm_object_create(), so look out for NULLs. + */ + if (object->objfmt) + yasm_objfmt_destroy(object->objfmt); + if (object->dbgfmt) + yasm_dbgfmt_destroy(object->dbgfmt); + /* Delete sections */ cur = STAILQ_FIRST(&object->sections); while (cur) { @@ -333,9 +362,12 @@ yasm_object_destroy(yasm_object *object) yasm_xfree(object->src_filename); yasm_xfree(object->obj_filename); - /* Delete symbol table and line mappings */ + /* Delete symbol table */ yasm_symtab_destroy(object->symtab); - yasm_linemap_destroy(object->linemap); + + /* Delete architecture */ + if (object->arch) + yasm_arch_destroy(object->arch); yasm_xfree(object); } @@ -1145,8 +1177,7 @@ optimize_term_expand(IntervalTreeNode *node, void *d) } void -yasm_object_optimize(yasm_object *object, yasm_arch *arch, - yasm_errwarns *errwarns) +yasm_object_optimize(yasm_object *object, yasm_errwarns *errwarns) { yasm_section *sect; unsigned long bc_index = 0; diff --git a/libyasm/section.h b/libyasm/section.h index 61b7acdf..9c70e59b 100644 --- a/libyasm/section.h +++ b/libyasm/section.h @@ -47,15 +47,38 @@ struct yasm_reloc { }; #endif +struct yasm_object { + /*@owned@*/ char *src_filename; /**< Source filename */ + /*@owned@*/ char *obj_filename; /**< Object filename */ + + /*@owned@*/ yasm_symtab *symtab; /**< Symbol table */ + /*@owned@*/ yasm_arch *arch; /**< Target architecture */ + /*@owned@*/ yasm_objfmt *objfmt; /**< Object format */ + /*@owned@*/ yasm_dbgfmt *dbgfmt; /**< Debug format */ + + /** Currently active section. Used by some directives. */ + /*@dependent@*/ yasm_section *cur_section; + +#ifdef YASM_LIB_INTERNAL + /*@reldef@*/ STAILQ_HEAD(yasm_sectionhead, yasm_section) sections; +#endif +}; + /** Create a new object. A default section is created as the first section. * An empty symbol table (yasm_symtab) and line mapping (yasm_linemap) are * automatically created. * \param src_filename source filename (e.g. "file.asm") * \param obj_filename object filename (e.g. "file.o") - * \return Newly allocated object. + * \param arch architecture + * \param objfmt_module object format module + * \param dbgfmt_module debug format module + * \return Newly allocated object, or NULL on error. */ -/*@only@*/ yasm_object *yasm_object_create(const char *src_filename, - const char *obj_filename); +/*@null@*/ /*@only@*/ yasm_object *yasm_object_create + (const char *src_filename, const char *obj_filename, + /*@kept@*/ yasm_arch *arch, + const yasm_objfmt_module *objfmt_module, + const yasm_dbgfmt_module *dbgfmt_module); /** Create a new, or continue an existing, general section. The section is * added to the object if there's not already a section by that name. @@ -133,40 +156,13 @@ int yasm_object_sections_traverse */ void yasm_object_set_source_fn(yasm_object *object, const char *src_filename); -/** Get an object's source filename. - * \param object object - * \return Source filename. - */ -const char *yasm_object_get_source_fn(const yasm_object *object); - -/** Get an object's object filename. - * \param object object - * \return Object filename. - */ -const char *yasm_object_get_object_fn(const yasm_object *object); - -/** Get an object's symbol table (#yasm_symtab). - * \param object object - * \return Symbol table. - */ -/*@dependent@*/ yasm_symtab *yasm_object_get_symtab(const yasm_object *object); - -/** Get an object's line mappings (#yasm_linemap). - * \param object object - * \return Line mappings. - */ -/*@dependent@*/ yasm_linemap *yasm_object_get_linemap - (const yasm_object *object); - /** Optimize an object. Takes the unoptimized object and optimizes it. * If successful, the object is ready for output to an object file. * \param object object - * \param arch architecture * \param errwarns error/warning set * \note Optimization failures are stored into errwarns. */ -void yasm_object_optimize(yasm_object *object, yasm_arch *arch, - yasm_errwarns *errwarns); +void yasm_object_optimize(yasm_object *object, yasm_errwarns *errwarns); /** Determine if a section is absolute or general. * \param sect section diff --git a/libyasm/symrec.c b/libyasm/symrec.c index 76ef09ad..1b8e7219 100644 --- a/libyasm/symrec.c +++ b/libyasm/symrec.c @@ -324,7 +324,7 @@ yasm_symrec_declare(yasm_symrec *rec, yasm_sym_vis vis, unsigned long line) typedef struct symtab_finalize_info { unsigned long firstundef_line; int undef_extern; - /*@null@*/ yasm_objfmt *objfmt; + /*@null@*/ yasm_object *object; yasm_errwarns *errwarns; } symtab_finalize_info; @@ -337,8 +337,8 @@ symtab_parser_finalize_checksym(yasm_symrec *sym, /*@null@*/ void *d) /* error if a symbol is used but never defined or extern/common declared */ if ((sym->status & YASM_SYM_USED) && !(sym->status & YASM_SYM_DEFINED) && !(sym->visibility & (YASM_SYM_EXTERN | YASM_SYM_COMMON))) { - if (info->undef_extern && info->objfmt) - yasm_objfmt_extern_declare(info->objfmt, sym->name, NULL, 1); + if (info->undef_extern && info->object) + yasm_objfmt_extern_declare(info->object, sym->name, NULL, 1); else { yasm_error_set(YASM_ERROR_GENERAL, N_("undefined symbol `%s' (first use)"), sym->name); @@ -373,12 +373,12 @@ symtab_parser_finalize_checksym(yasm_symrec *sym, /*@null@*/ void *d) void yasm_symtab_parser_finalize(yasm_symtab *symtab, int undef_extern, - yasm_objfmt *objfmt, yasm_errwarns *errwarns) + yasm_object *object, yasm_errwarns *errwarns) { symtab_finalize_info info; info.firstundef_line = ULONG_MAX; info.undef_extern = undef_extern; - info.objfmt = objfmt; + info.object = object; info.errwarns = errwarns; yasm_symtab_traverse(symtab, &info, symtab_parser_finalize_checksym); if (info.firstundef_line < ULONG_MAX) { diff --git a/libyasm/symrec.h b/libyasm/symrec.h index 5c3edb37..6cf97559 100644 --- a/libyasm/symrec.h +++ b/libyasm/symrec.h @@ -202,13 +202,13 @@ yasm_symrec *yasm_symtab_iter_value(const yasm_symtab_iter *cur); * used but never defined or declared #YASM_SYM_EXTERN or #YASM_SYM_COMMON. * \param symtab symbol table * \param undef_extern if nonzero, all undef syms should be declared extern - * \param objfmt object format to notify about new extern decls + * \param object object to notify about new extern decls * (may be NULL if undef_extern is 0) * \param errwarns error/warning set * \note Errors/warnings are stored into errwarns. */ void yasm_symtab_parser_finalize(yasm_symtab *symtab, int undef_extern, - /*@null@*/ yasm_objfmt *objfmt, + /*@null@*/ yasm_object *object, yasm_errwarns *errwarns); /** Print the symbol table. For debugging purposes. diff --git a/libyasm/value.c b/libyasm/value.c index 1e530e9a..90cfeeb3 100644 --- a/libyasm/value.c +++ b/libyasm/value.c @@ -117,8 +117,8 @@ yasm_value_set_curpos_rel(yasm_value *value, yasm_bytecode *bc, * to a custom absolute symbol. */ if (!value->rel) { - value->rel = yasm_symtab_abs_sym(yasm_object_get_symtab( - yasm_section_get_object(yasm_bc_get_section(bc)))); + yasm_object *object = yasm_section_get_object(yasm_bc_get_section(bc)); + value->rel = yasm_symtab_abs_sym(object->symtab); } } @@ -274,9 +274,9 @@ value_finalize_scan(yasm_value *value, yasm_expr *e, yasm_intnum_create_uint(0); } else { /* Replace positive portion with curpos */ - yasm_symtab *symtab = - yasm_object_get_symtab( - yasm_section_get_object(sect2)); + yasm_object *object = + yasm_section_get_object(sect2); + yasm_symtab *symtab = object->symtab; e->terms[j].data.sym = yasm_symtab_define_curpos (symtab, ".", expr_precbc, e->line); diff --git a/modules/dbgfmts/codeview/cv-dbgfmt.c b/modules/dbgfmts/codeview/cv-dbgfmt.c index d17f6089..1b045fcf 100644 --- a/modules/dbgfmts/codeview/cv-dbgfmt.c +++ b/modules/dbgfmts/codeview/cv-dbgfmt.c @@ -37,19 +37,13 @@ yasm_dbgfmt_module yasm_cv8_LTX_dbgfmt; static /*@null@*/ /*@only@*/ yasm_dbgfmt * -cv_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a, - yasm_dbgfmt_module *module, int version) +cv_dbgfmt_create(yasm_object *object, yasm_dbgfmt_module *module, int version) { yasm_dbgfmt_cv *dbgfmt_cv = yasm_xmalloc(sizeof(yasm_dbgfmt_cv)); size_t i; dbgfmt_cv->dbgfmt.module = module; - dbgfmt_cv->object = object; - dbgfmt_cv->symtab = yasm_object_get_symtab(object); - dbgfmt_cv->linemap = yasm_object_get_linemap(object); - dbgfmt_cv->arch = a; - dbgfmt_cv->filenames_allocated = 32; dbgfmt_cv->filenames_size = 0; dbgfmt_cv->filenames = @@ -67,9 +61,9 @@ cv_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a, } static /*@null@*/ /*@only@*/ yasm_dbgfmt * -cv8_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) +cv8_dbgfmt_create(yasm_object *object) { - return cv_dbgfmt_create(object, of, a, &yasm_cv8_LTX_dbgfmt, 8); + return cv_dbgfmt_create(object, &yasm_cv8_LTX_dbgfmt, 8); } static void @@ -98,19 +92,16 @@ yasm_cv__append_bc(yasm_section *sect, yasm_bytecode *bc) } static void -cv_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) +cv_dbgfmt_generate(yasm_object *object, yasm_linemap *linemap, + yasm_errwarns *errwarns) { - yasm_dbgfmt_cv *dbgfmt_cv = (yasm_dbgfmt_cv *)dbgfmt; - - yasm_cv__generate_symline(dbgfmt_cv, errwarns); - - yasm_cv__generate_type(dbgfmt_cv); + yasm_cv__generate_symline(object, linemap, errwarns); + yasm_cv__generate_type(object); } static int -cv_dbgfmt_directive(yasm_dbgfmt *dbgfmt, const char *name, - yasm_section *sect, yasm_valparamhead *valparams, - unsigned long line) +cv_dbgfmt_directive(yasm_object *object, const char *name, + yasm_valparamhead *valparams, unsigned long line) { return 1; /* TODO */ } diff --git a/modules/dbgfmts/codeview/cv-dbgfmt.h b/modules/dbgfmts/codeview/cv-dbgfmt.h index 246bbdfe..3e8db324 100644 --- a/modules/dbgfmts/codeview/cv-dbgfmt.h +++ b/modules/dbgfmts/codeview/cv-dbgfmt.h @@ -39,11 +39,6 @@ typedef struct { typedef struct yasm_dbgfmt_cv { yasm_dbgfmt_base dbgfmt; /* base structure */ - yasm_object *object; - yasm_symtab *symtab; - yasm_linemap *linemap; - yasm_arch *arch; - cv_filename *filenames; size_t filenames_size; size_t filenames_allocated; @@ -54,10 +49,10 @@ typedef struct yasm_dbgfmt_cv { yasm_bytecode *yasm_cv__append_bc(yasm_section *sect, yasm_bytecode *bc); /* Symbol/Line number functions */ -yasm_section *yasm_cv__generate_symline(yasm_dbgfmt_cv *dbgfmt_cv, - yasm_errwarns *errwarns); +yasm_section *yasm_cv__generate_symline + (yasm_object *object, yasm_linemap *linemap, yasm_errwarns *errwarns); /* Type functions */ -yasm_section *yasm_cv__generate_type(yasm_dbgfmt_cv *dbgfmt_cv); +yasm_section *yasm_cv__generate_type(yasm_object *object); #endif diff --git a/modules/dbgfmts/codeview/cv-symline.c b/modules/dbgfmts/codeview/cv-symline.c index 65dd02a4..068ac566 100644 --- a/modules/dbgfmts/codeview/cv-symline.c +++ b/modules/dbgfmts/codeview/cv-symline.c @@ -107,7 +107,6 @@ enum cv_symtype { }; typedef struct cv8_symhead { - yasm_dbgfmt_cv *dbgfmt_cv; enum cv8_symheadtype type; yasm_bytecode *start_prevbc; yasm_bytecode *end_prevbc; @@ -115,7 +114,6 @@ typedef struct cv8_symhead { } cv8_symhead; typedef struct cv8_fileinfo { - yasm_dbgfmt_cv *dbgfmt_cv; const cv_filename *fn; } cv8_fileinfo; @@ -134,7 +132,6 @@ typedef struct cv8_lineset { typedef struct cv8_lineinfo { STAILQ_ENTRY(cv8_lineinfo) link; - yasm_dbgfmt_cv *dbgfmt_cv; const cv_filename *fn; /* filename associated with line numbers */ yasm_section *sect; /* section line numbers are for */ yasm_symrec *sectsym; /* symbol for beginning of sect */ @@ -153,7 +150,6 @@ typedef struct cv8_lineinfo { * 'Z' : 0-terminated string (pointer) */ typedef struct cv_sym { - yasm_dbgfmt_cv *dbgfmt_cv; enum cv_symtype type; const char *format; union { @@ -243,24 +239,21 @@ static const yasm_bytecode_callback cv_sym_bc_callback = { 0 }; -static cv8_symhead *cv8_add_symhead(yasm_dbgfmt_cv *dbgfmt_cv, - yasm_section *sect, unsigned long type, +static cv8_symhead *cv8_add_symhead(yasm_section *sect, unsigned long type, int first); static void cv8_set_symhead_end(cv8_symhead *head, yasm_bytecode *end_prevbc); static yasm_bytecode *cv8_add_fileinfo - (yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, const cv_filename *fn); + (yasm_section *sect, const cv_filename *fn); static unsigned long cv_sym_size(const cv_sym *cvs); static cv_sym * -cv8_add_sym_objname(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, - /*@keep@*/ char *objname) +cv8_add_sym_objname(yasm_section *sect, /*@keep@*/ char *objname) { yasm_bytecode *bc; cv_sym *cvs = yasm_xmalloc(sizeof(cv_sym)); - cvs->dbgfmt_cv = dbgfmt_cv; cvs->type = CV8_S_OBJNAME; cvs->format = "wZ"; cvs->args[0].i = 0; /* signature (0=asm) */ @@ -273,19 +266,18 @@ cv8_add_sym_objname(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, } static cv_sym * -cv8_add_sym_compile(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, +cv8_add_sym_compile(yasm_object *object, yasm_section *sect, /*@keep@*/ char *creator) { yasm_bytecode *bc; cv_sym *cvs = yasm_xmalloc(sizeof(cv_sym)); - cvs->dbgfmt_cv = dbgfmt_cv; cvs->type = CV8_S_COMPILE; cvs->format = "wwwwZh"; cvs->args[0].i = 3; /* language (3=Masm) */ /* target processor; 0xD0 = AMD64 */ - if (strcmp(yasm_arch_keyword(dbgfmt_cv->arch), "x86") == 0) { - if (strcmp(yasm_arch_get_machine(dbgfmt_cv->arch), "amd64") == 0) + if (strcmp(yasm_arch_keyword(object->arch), "x86") == 0) { + if (strcmp(yasm_arch_get_machine(object->arch), "amd64") == 0) cvs->args[1].i = 0xD0; else cvs->args[1].i = 0x6; /* 686, FIXME */ @@ -304,12 +296,10 @@ cv8_add_sym_compile(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, } static cv_sym * -cv8_add_sym_label(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, - yasm_symrec *sym) +cv8_add_sym_label(yasm_section *sect, yasm_symrec *sym) { yasm_bytecode *bc; cv_sym *cvs = yasm_xmalloc(sizeof(cv_sym)); - cvs->dbgfmt_cv = dbgfmt_cv; cvs->type = CV8_S_LABEL32; cvs->format = "YbZ"; cvs->args[0].p = sym; /* symrec for label */ @@ -323,12 +313,11 @@ cv8_add_sym_label(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, } static cv_sym * -cv8_add_sym_data(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, - unsigned long type, yasm_symrec *sym, int is_global) +cv8_add_sym_data(yasm_section *sect, unsigned long type, yasm_symrec *sym, + int is_global) { yasm_bytecode *bc; cv_sym *cvs = yasm_xmalloc(sizeof(cv_sym)); - cvs->dbgfmt_cv = dbgfmt_cv; cvs->type = is_global ? CV8_S_GDATA32 : CV8_S_LDATA32; cvs->format = "wYZ"; cvs->args[0].i = type; /* type index */ @@ -423,7 +412,9 @@ cv_append_str(yasm_section *sect, const char *str) typedef struct cv_line_info { yasm_section *debug_symline; + yasm_object *object; yasm_dbgfmt_cv *dbgfmt_cv; + yasm_linemap *linemap; yasm_errwarns *errwarns; unsigned int num_lineinfos; STAILQ_HEAD(, cv8_lineinfo) cv8_lineinfos; @@ -445,7 +436,7 @@ cv_generate_line_bc(yasm_bytecode *bc, /*@null@*/ void *d) if (nextbc && bc->offset == nextbc->offset) return 0; - yasm_linemap_lookup(dbgfmt_cv->linemap, bc->line, &filename, &line); + yasm_linemap_lookup(info->linemap, bc->line, &filename, &line); if (!info->cv8_cur_li || strcmp(filename, info->cv8_cur_li->fn->filename) != 0) { @@ -477,7 +468,6 @@ cv_generate_line_bc(yasm_bytecode *bc, /*@null@*/ void *d) /* and create new lineinfo structure */ info->cv8_cur_li = yasm_xmalloc(sizeof(cv8_lineinfo)); - info->cv8_cur_li->dbgfmt_cv = dbgfmt_cv; info->cv8_cur_li->fn = &dbgfmt_cv->filenames[i]; info->cv8_cur_li->sect = sect; sectbc = yasm_section_bcs_first(sect); @@ -486,7 +476,7 @@ cv_generate_line_bc(yasm_bytecode *bc, /*@null@*/ void *d) else { sprintf(symname, ".%06u", info->num_lineinfos++); info->cv8_cur_li->sectsym = - yasm_symtab_define_label(dbgfmt_cv->symtab, symname, sectbc, + yasm_symtab_define_label(info->object->symtab, symname, sectbc, 1, 0); } info->cv8_cur_li->num_linenums = 0; @@ -532,8 +522,7 @@ cv_generate_line_section(yasm_section *sect, /*@null@*/ void *d) static int cv_generate_filename(const char *filename, void *d) { - yasm_dbgfmt_cv *dbgfmt_cv = (yasm_dbgfmt_cv *)d; - cv_dbgfmt_add_file(dbgfmt_cv, 0, filename); + cv_dbgfmt_add_file((yasm_dbgfmt_cv *)d, 0, filename); return 0; } @@ -553,16 +542,18 @@ cv_generate_sym(yasm_symrec *sym, void *d) /* TODO: add data types; until then, just mark everything as UBYTE */ if (yasm_section_is_code(yasm_bc_get_section(precbc))) - cv8_add_sym_label(info->dbgfmt_cv, info->debug_symline, sym); + cv8_add_sym_label(info->debug_symline, sym); else - cv8_add_sym_data(info->dbgfmt_cv, info->debug_symline, 0x20, sym, + cv8_add_sym_data(info->debug_symline, 0x20, sym, yasm_symrec_get_visibility(sym) & YASM_SYM_GLOBAL?1:0); return 0; } yasm_section * -yasm_cv__generate_symline(yasm_dbgfmt_cv *dbgfmt_cv, yasm_errwarns *errwarns) +yasm_cv__generate_symline(yasm_object *object, yasm_linemap *linemap, + yasm_errwarns *errwarns) { + yasm_dbgfmt_cv *dbgfmt_cv = (yasm_dbgfmt_cv *)object->dbgfmt; cv_line_info info; int new; size_t i; @@ -572,21 +563,22 @@ yasm_cv__generate_symline(yasm_dbgfmt_cv *dbgfmt_cv, yasm_errwarns *errwarns) unsigned long off; /* Generate filenames based on linemap */ - yasm_linemap_traverse_filenames(dbgfmt_cv->linemap, dbgfmt_cv, + yasm_linemap_traverse_filenames(linemap, dbgfmt_cv, cv_generate_filename); + info.object = object; info.dbgfmt_cv = dbgfmt_cv; + info.linemap = linemap; info.errwarns = errwarns; - info.debug_symline = yasm_object_get_general(dbgfmt_cv->object, - ".debug$S", 0, 1, 0, 0, &new, - 0); + info.debug_symline = + yasm_object_get_general(object, ".debug$S", 0, 1, 0, 0, &new, 0); info.num_lineinfos = 0; STAILQ_INIT(&info.cv8_lineinfos); info.cv8_cur_li = NULL; info.cv8_cur_ls = NULL; /* source filenames string table */ - head = cv8_add_symhead(dbgfmt_cv, info.debug_symline, CV8_FILE_STRTAB, 1); + head = cv8_add_symhead(info.debug_symline, CV8_FILE_STRTAB, 1); cv_append_str(info.debug_symline, ""); off = 1; for (i=0; ifilenames_size; i++) { @@ -611,13 +603,12 @@ yasm_cv__generate_symline(yasm_dbgfmt_cv *dbgfmt_cv, yasm_errwarns *errwarns) yasm_bc_calc_len(bc, NULL, NULL); /* source file info table */ - head = cv8_add_symhead(dbgfmt_cv, info.debug_symline, CV8_FILE_INFO, 0); + head = cv8_add_symhead(info.debug_symline, CV8_FILE_INFO, 0); off = 0; for (i=0; ifilenames_size; i++) { if (!dbgfmt_cv->filenames[i].pathname) continue; - bc = cv8_add_fileinfo(dbgfmt_cv, info.debug_symline, - &dbgfmt_cv->filenames[i]); + bc = cv8_add_fileinfo(info.debug_symline, &dbgfmt_cv->filenames[i]); dbgfmt_cv->filenames[i].info_off = off; off += bc->len; } @@ -626,13 +617,12 @@ yasm_cv__generate_symline(yasm_dbgfmt_cv *dbgfmt_cv, yasm_errwarns *errwarns) /* Already aligned 4 */ /* Generate line numbers for sections */ - yasm_object_sections_traverse(dbgfmt_cv->object, (void *)&info, + yasm_object_sections_traverse(object, (void *)&info, cv_generate_line_section); /* Output line numbers for sections */ STAILQ_FOREACH(li, &info.cv8_lineinfos, link) { - head = cv8_add_symhead(dbgfmt_cv, info.debug_symline, CV8_LINE_NUMS, - 0); + head = cv8_add_symhead(info.debug_symline, CV8_LINE_NUMS, 0); bc = yasm_bc_create_common(&cv8_lineinfo_bc_callback, li, 0); bc->len = 24+li->num_linenums*8; yasm_cv__append_bc(info.debug_symline, bc); @@ -642,15 +632,15 @@ yasm_cv__generate_symline(yasm_dbgfmt_cv *dbgfmt_cv, yasm_errwarns *errwarns) /* Already aligned 4 */ /* Output debugging symbols */ - head = cv8_add_symhead(dbgfmt_cv, info.debug_symline, CV8_DEBUG_SYMS, 0); + head = cv8_add_symhead(info.debug_symline, CV8_DEBUG_SYMS, 0); /* add object and compile flag first */ - cv8_add_sym_objname(dbgfmt_cv, info.debug_symline, - yasm__abspath(yasm_object_get_object_fn(dbgfmt_cv->object))); - cv8_add_sym_compile(dbgfmt_cv, info.debug_symline, + cv8_add_sym_objname(info.debug_symline, + yasm__abspath(object->obj_filename)); + cv8_add_sym_compile(object, info.debug_symline, yasm__xstrdup(PACKAGE_NAME " " PACKAGE_INTVER "." PACKAGE_BUILD)); /* then iterate through symbol table */ - yasm_symtab_traverse(dbgfmt_cv->symtab, &info, cv_generate_sym); + yasm_symtab_traverse(object->symtab, &info, cv_generate_sym); cv8_set_symhead_end(head, yasm_section_bcs_last(info.debug_symline)); /* Align 4 at end */ @@ -683,14 +673,12 @@ cv_out_sym(yasm_symrec *sym, unsigned long off, yasm_bytecode *bc, } static cv8_symhead * -cv8_add_symhead(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, - unsigned long type, int first) +cv8_add_symhead(yasm_section *sect, unsigned long type, int first) { cv8_symhead *head; yasm_bytecode *bc; head = yasm_xmalloc(sizeof(cv8_symhead)); - head->dbgfmt_cv = dbgfmt_cv; head->type = type; head->first = first; head->start_prevbc = yasm_section_bcs_last(sect); @@ -738,28 +726,28 @@ cv8_symhead_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) { + yasm_object *object = yasm_section_get_object(bc->section); cv8_symhead *head = (cv8_symhead *)bc->contents; - yasm_dbgfmt_cv *dbgfmt_cv = head->dbgfmt_cv; unsigned char *buf = *bufp; yasm_intnum *intn, *cval; cval = yasm_intnum_create_uint(4); /* Output "version" if first */ if (head->first) { - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; } /* Type contained - 4 bytes */ yasm_intnum_set_uint(cval, head->type); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; /* Total length of info (following this field) - 4 bytes */ yasm_intnum_set_uint(cval, bc->len); intn = yasm_calc_bc_dist(head->start_prevbc, head->end_prevbc); yasm_intnum_calc(intn, YASM_EXPR_SUB, cval); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, intn, buf, 4, 32, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, intn, buf, 4, 32, 0, bc, 0); buf += 4; yasm_intnum_destroy(intn); @@ -770,14 +758,12 @@ cv8_symhead_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, } static yasm_bytecode * -cv8_add_fileinfo(yasm_dbgfmt_cv *dbgfmt_cv, yasm_section *sect, - const cv_filename *fn) +cv8_add_fileinfo(yasm_section *sect, const cv_filename *fn) { cv8_fileinfo *fi; yasm_bytecode *bc; fi = yasm_xmalloc(sizeof(cv8_fileinfo)); - fi->dbgfmt_cv = dbgfmt_cv; fi->fn = fn; bc = yasm_bc_create_common(&cv8_fileinfo_bc_callback, fi, 0); @@ -813,20 +799,20 @@ cv8_fileinfo_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) { + yasm_object *object = yasm_section_get_object(bc->section); cv8_fileinfo *fi = (cv8_fileinfo *)bc->contents; - yasm_dbgfmt_cv *dbgfmt_cv = fi->dbgfmt_cv; unsigned char *buf = *bufp; yasm_intnum *cval; int i; /* Offset in filename string table */ cval = yasm_intnum_create_uint(fi->fn->str_off); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; /* Checksum type/length */ yasm_intnum_set_uint(cval, 0x0110); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 2, 16, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 2, 16, 0, bc, 0); buf += 2; /* Checksum */ @@ -880,8 +866,8 @@ cv8_lineinfo_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) { + yasm_object *object = yasm_section_get_object(bc->section); cv8_lineinfo *li = (cv8_lineinfo *)bc->contents; - yasm_dbgfmt_cv *dbgfmt_cv = li->dbgfmt_cv; unsigned char *buf = *bufp; yasm_intnum *cval; unsigned long i; @@ -897,22 +883,22 @@ cv8_lineinfo_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, /* Section length covered by line number info */ cval = yasm_calc_bc_dist(yasm_section_bcs_first(li->sect), yasm_section_bcs_last(li->sect)); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; /* Offset of source file in info table */ yasm_intnum_set_uint(cval, li->fn->info_off); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; /* Number of line number pairs */ yasm_intnum_set_uint(cval, li->num_linenums); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; /* Number of bytes of line number pairs + 12 (no, I don't know why) */ yasm_intnum_set_uint(cval, li->num_linenums*8+12); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; /* Offset / line number pairs */ @@ -922,14 +908,12 @@ cv8_lineinfo_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, for (j=0; inum_linenums && j<126; i++, j++) { /* offset in section */ yasm_intnum_set_uint(cval, ls->pairs[j].offset); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, - 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; /* line number in file */ yasm_intnum_set_uint(cval, ls->pairs[j].line); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, - 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; } } @@ -1037,8 +1021,8 @@ cv_sym_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) { + yasm_object *object = yasm_section_get_object(bc->section); cv_sym *cvs = (cv_sym *)bc->contents; - yasm_dbgfmt_cv *dbgfmt_cv = cvs->dbgfmt_cv; unsigned char *buf = *bufp; yasm_intnum *cval; const char *ch = cvs->format; @@ -1047,12 +1031,12 @@ cv_sym_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, /* Total length of record (following this field) - 2 bytes */ cval = yasm_intnum_create_uint(bc->len-2); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 2, 16, 0, bc, 1); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 2, 16, 0, bc, 1); buf += 2; /* Type contained - 2 bytes */ yasm_intnum_set_uint(cval, cvs->type); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 2, 16, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 2, 16, 0, bc, 0); buf += 2; while (*ch) { @@ -1063,13 +1047,13 @@ cv_sym_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, break; case 'h': yasm_intnum_set_uint(cval, cvs->args[arg++].i); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 2, 16, 0, + yasm_arch_intnum_tobytes(object->arch, cval, buf, 2, 16, 0, bc, 0); buf += 2; break; case 'w': yasm_intnum_set_uint(cval, cvs->args[arg++].i); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; break; @@ -1080,7 +1064,7 @@ cv_sym_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, break; case 'T': yasm_intnum_set_uint(cval, cvs->args[arg++].i); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; /* XXX: will be 2 in CV4 */ break; diff --git a/modules/dbgfmts/codeview/cv-type.c b/modules/dbgfmts/codeview/cv-type.c index 70620a03..ecec7f9b 100644 --- a/modules/dbgfmts/codeview/cv-type.c +++ b/modules/dbgfmts/codeview/cv-type.c @@ -474,7 +474,6 @@ typedef struct cv_leaf { } cv_leaf; typedef struct cv_type { - yasm_dbgfmt_cv *dbgfmt_cv; unsigned long indx; /* type # (must be same as output order) */ size_t num_leaves; /*@null@*/ /*@only@*/ cv_leaf **leaves; @@ -501,7 +500,7 @@ static const yasm_bytecode_callback cv_type_bc_callback = { 0 }; -static cv_type *cv_type_create(yasm_dbgfmt_cv *dbgfmt_cv, unsigned long indx); +static cv_type *cv_type_create(unsigned long indx); static void cv_type_append_leaf(cv_type *type, /*@keep@*/ cv_leaf *leaf); @@ -516,7 +515,7 @@ cv_leaf_create_label(int is_far) } yasm_section * -yasm_cv__generate_type(yasm_dbgfmt_cv *dbgfmt_cv) +yasm_cv__generate_type(yasm_object *object) { int new; unsigned long indx = CV_FIRST_NONPRIM; @@ -524,11 +523,11 @@ yasm_cv__generate_type(yasm_dbgfmt_cv *dbgfmt_cv) yasm_bytecode *bc; cv_type *type; - debug_type = yasm_object_get_general(dbgfmt_cv->object, ".debug$T", 0, 1, - 0, 0, &new, 0); + debug_type = + yasm_object_get_general(object, ".debug$T", 0, 1, 0, 0, &new, 0); /* Add label type */ - type = cv_type_create(dbgfmt_cv, indx++); + type = cv_type_create(indx++); cv_type_append_leaf(type, cv_leaf_create_label(0)); bc = yasm_bc_create_common(&cv_type_bc_callback, type, 0); yasm_bc_finalize(bc, yasm_cv__append_bc(debug_type, bc)); @@ -667,11 +666,10 @@ cv_leaf_tobytes(const cv_leaf *leaf, yasm_bytecode *bc, yasm_arch *arch, } static cv_type * -cv_type_create(yasm_dbgfmt_cv *dbgfmt_cv, unsigned long indx) +cv_type_create(unsigned long indx) { cv_type *type = yasm_xmalloc(sizeof(cv_type)); - type->dbgfmt_cv = dbgfmt_cv; type->indx = indx; type->num_leaves = 0; type->leaves = NULL; @@ -739,8 +737,8 @@ cv_type_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) { + yasm_object *object = yasm_section_get_object(bc->section); cv_type *type = (cv_type *)bc->contents; - yasm_dbgfmt_cv *dbgfmt_cv = type->dbgfmt_cv; unsigned char *buf = *bufp; yasm_intnum *cval; size_t i; @@ -748,19 +746,19 @@ cv_type_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, cval = yasm_intnum_create_uint(4); /* version */ if (type->indx == CV_FIRST_NONPRIM) { - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 1); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 4, 32, 0, bc, 1); buf += 4; reclen -= 4; } /* Total length of record (following this field) - 2 bytes */ yasm_intnum_set_uint(cval, reclen); - yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 2, 16, 0, bc, 1); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 2, 16, 0, bc, 1); buf += 2; /* Leaves */ for (i=0; inum_leaves; i++) - cv_leaf_tobytes(type->leaves[i], bc, dbgfmt_cv->arch, &buf, cval); + cv_leaf_tobytes(type->leaves[i], bc, object->arch, &buf, cval); /* Pad to multiple of 4 */ switch ((buf-(*bufp)) & 0x3) { diff --git a/modules/dbgfmts/dwarf2/dwarf2-aranges.c b/modules/dbgfmts/dwarf2/dwarf2-aranges.c index f78e1d47..e277cdaa 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-aranges.c +++ b/modules/dbgfmts/dwarf2/dwarf2-aranges.c @@ -50,6 +50,7 @@ dwarf2_append_arange(yasm_section *debug_aranges, /*@only@*/ yasm_expr *start, typedef struct dwarf2_aranges_info { yasm_section *debug_aranges; /* section to which address ranges go */ + yasm_object *object; yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2; } dwarf2_aranges_info; @@ -67,7 +68,7 @@ dwarf2_generate_aranges_section(yasm_section *sect, /*@null@*/ void *d) /* Create address range descriptor */ start = yasm_expr_create_ident( - yasm_expr_sym(yasm_dwarf2__bc_sym(dbgfmt_dwarf2->symtab, + yasm_expr_sym(yasm_dwarf2__bc_sym(info->object->symtab, yasm_section_bcs_first(sect))), 0); length = yasm_expr_create_ident( yasm_expr_int(yasm_calc_bc_dist(yasm_section_bcs_first(sect), @@ -79,9 +80,9 @@ dwarf2_generate_aranges_section(yasm_section *sect, /*@null@*/ void *d) } yasm_section * -yasm_dwarf2__generate_aranges(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, - yasm_section *debug_info) +yasm_dwarf2__generate_aranges(yasm_object *object, yasm_section *debug_info) { + yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)object->dbgfmt; int new; yasm_section *debug_aranges; yasm_bytecode *bc; @@ -89,7 +90,7 @@ yasm_dwarf2__generate_aranges(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, dwarf2_aranges_info info; debug_aranges = - yasm_object_get_general(dbgfmt_dwarf2->object, ".debug_aranges", 0, + yasm_object_get_general(object, ".debug_aranges", 0, 2*dbgfmt_dwarf2->sizeof_address, 0, 0, &new, 0); @@ -106,9 +107,10 @@ yasm_dwarf2__generate_aranges(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_bc_calc_len(bc, NULL, NULL); info.debug_aranges = debug_aranges; + info.object = object; info.dbgfmt_dwarf2 = dbgfmt_dwarf2; - yasm_object_sections_traverse(dbgfmt_dwarf2->object, (void *)&info, + yasm_object_sections_traverse(object, (void *)&info, dwarf2_generate_aranges_section); /* Terminate with empty address range descriptor */ diff --git a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c index d6ed56ea..eb76fa30 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c +++ b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c @@ -34,7 +34,6 @@ #include "dwarf2-dbgfmt.h" struct dwarf2_head { - yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2; yasm_bytecode *start_prevbc; yasm_bytecode *end_prevbc; /*@null@*/ yasm_section *debug_ptr; @@ -78,7 +77,7 @@ yasm_dbgfmt_module yasm_dwarf2_LTX_dbgfmt; static /*@null@*/ /*@only@*/ yasm_dbgfmt * -dwarf2_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) +dwarf2_dbgfmt_create(yasm_object *object) { yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = yasm_xmalloc(sizeof(yasm_dbgfmt_dwarf2)); @@ -86,11 +85,6 @@ dwarf2_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) dbgfmt_dwarf2->dbgfmt.module = &yasm_dwarf2_LTX_dbgfmt; - dbgfmt_dwarf2->object = object; - dbgfmt_dwarf2->symtab = yasm_object_get_symtab(object); - dbgfmt_dwarf2->linemap = yasm_object_get_linemap(object); - dbgfmt_dwarf2->arch = a; - dbgfmt_dwarf2->dirs_allocated = 32; dbgfmt_dwarf2->dirs_size = 0; dbgfmt_dwarf2->dirs = @@ -108,7 +102,7 @@ dwarf2_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) dbgfmt_dwarf2->format = DWARF2_FORMAT_32BIT; /* TODO: flexible? */ - dbgfmt_dwarf2->sizeof_address = yasm_arch_get_address_size(a)/8; + dbgfmt_dwarf2->sizeof_address = yasm_arch_get_address_size(object->arch)/8; switch (dbgfmt_dwarf2->format) { case DWARF2_FORMAT_32BIT: dbgfmt_dwarf2->sizeof_offset = 4; @@ -117,7 +111,7 @@ dwarf2_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) dbgfmt_dwarf2->sizeof_offset = 8; break; } - dbgfmt_dwarf2->min_insn_len = yasm_arch_min_insn_len(a); + dbgfmt_dwarf2->min_insn_len = yasm_arch_min_insn_len(object->arch); return (yasm_dbgfmt *)dbgfmt_dwarf2; } @@ -154,16 +148,17 @@ yasm_dwarf2__append_bc(yasm_section *sect, yasm_bytecode *bc) } static void -dwarf2_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) +dwarf2_dbgfmt_generate(yasm_object *object, yasm_linemap *linemap, + yasm_errwarns *errwarns) { - yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)dbgfmt; + yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)object->dbgfmt; size_t num_line_sections; /*@null@*/ yasm_section *debug_info, *debug_line, *main_code; /* If we don't have any .file directives, generate line information * based on the asm source. */ - debug_line = yasm_dwarf2__generate_line(dbgfmt_dwarf2, errwarns, + debug_line = yasm_dwarf2__generate_line(object, linemap, errwarns, dbgfmt_dwarf2->filenames_size == 0, &main_code, &num_line_sections); @@ -171,14 +166,13 @@ dwarf2_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) * set of .debug_info, .debug_aranges, and .debug_abbrev so that the * .debug_line we're generating is actually useful. */ - debug_info = yasm_object_find_general(dbgfmt_dwarf2->object, ".debug_info"); + debug_info = yasm_object_find_general(object, ".debug_info"); if (num_line_sections > 0 && (!debug_info || yasm_section_bcs_first(debug_info) == yasm_section_bcs_last(debug_info))) { - debug_info = yasm_dwarf2__generate_info(dbgfmt_dwarf2, debug_line, - main_code); - yasm_dwarf2__generate_aranges(dbgfmt_dwarf2, debug_info); - /*yasm_dwarf2__generate_pubnames(dbgfmt_dwarf2, debug_info);*/ + debug_info = yasm_dwarf2__generate_info(object, debug_line, main_code); + yasm_dwarf2__generate_aranges(object, debug_info); + /*yasm_dwarf2__generate_pubnames(object, debug_info);*/ } } @@ -202,7 +196,6 @@ yasm_dwarf2__add_head yasm_bytecode *bc; head = yasm_xmalloc(sizeof(dwarf2_head)); - head->dbgfmt_dwarf2 = dbgfmt_dwarf2; head->start_prevbc = yasm_section_bcs_last(sect); bc = yasm_bc_create_common(&dwarf2_head_bc_callback, head, 0); @@ -260,8 +253,9 @@ dwarf2_head_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) { + yasm_object *object = yasm_section_get_object(bc->section); + yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)object->dbgfmt; dwarf2_head *head = (dwarf2_head *)bc->contents; - yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = head->dbgfmt_dwarf2; unsigned char *buf = *bufp; yasm_intnum *intn, *cval; @@ -276,7 +270,7 @@ dwarf2_head_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, cval = yasm_intnum_create_uint(dbgfmt_dwarf2->sizeof_offset); intn = yasm_calc_bc_dist(head->start_prevbc, head->end_prevbc); yasm_intnum_calc(intn, YASM_EXPR_SUB, cval); - yasm_arch_intnum_tobytes(dbgfmt_dwarf2->arch, intn, buf, + yasm_arch_intnum_tobytes(object->arch, intn, buf, dbgfmt_dwarf2->sizeof_offset, dbgfmt_dwarf2->sizeof_offset*8, 0, bc, 0); buf += dbgfmt_dwarf2->sizeof_offset; @@ -284,14 +278,14 @@ dwarf2_head_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, /* DWARF version */ yasm_intnum_set_uint(cval, 2); - yasm_arch_intnum_tobytes(dbgfmt_dwarf2->arch, cval, buf, 2, 16, 0, bc, 0); + yasm_arch_intnum_tobytes(object->arch, cval, buf, 2, 16, 0, bc, 0); buf += 2; /* Pointer to another debug section */ if (head->debug_ptr) { yasm_value value; yasm_value_init_sym(&value, - yasm_dwarf2__bc_sym(dbgfmt_dwarf2->symtab, + yasm_dwarf2__bc_sym(object->symtab, yasm_section_bcs_first(head->debug_ptr)), dbgfmt_dwarf2->sizeof_offset*8); output_value(&value, buf, dbgfmt_dwarf2->sizeof_offset, @@ -337,13 +331,10 @@ dwarf2_section_data_print(void *data, FILE *f, int indent_level) } static int -dwarf2_dbgfmt_directive(yasm_dbgfmt *dbgfmt, const char *name, - yasm_section *sect, yasm_valparamhead *valparams, - unsigned long line) +dwarf2_dbgfmt_directive(yasm_object *object, const char *name, + yasm_valparamhead *valparams, unsigned long line) { - yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)dbgfmt; - return yasm_dwarf2__line_directive(dbgfmt_dwarf2, name, sect, valparams, - line); + return yasm_dwarf2__line_directive(object, name, valparams, line); } /* Define dbgfmt structure -- see dbgfmt.h for details */ diff --git a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.h b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.h index c60b8f0e..1c361b0c 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.h +++ b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.h @@ -40,11 +40,6 @@ typedef struct { typedef struct yasm_dbgfmt_dwarf2 { yasm_dbgfmt_base dbgfmt; /* base structure */ - yasm_object *object; - yasm_symtab *symtab; - yasm_linemap *linemap; - yasm_arch *arch; - char **dirs; unsigned long dirs_size; unsigned long dirs_allocated; @@ -109,24 +104,24 @@ void yasm_dwarf2__set_head_end(dwarf2_head *head, yasm_bytecode *end_prevbc); /* Line number functions */ yasm_section *yasm_dwarf2__generate_line - (yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_errwarns *errwarns, + (yasm_object *object, yasm_linemap *linemap, yasm_errwarns *errwarns, int asm_source, /*@out@*/ yasm_section **main_code, /*@out@*/ size_t *num_line_sections); int yasm_dwarf2__line_directive - (yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, const char *name, yasm_section *sect, - yasm_valparamhead *valparams, unsigned long line); + (yasm_object *object, const char *name, yasm_valparamhead *valparams, + unsigned long line); /* Address range table functions */ -yasm_section *yasm_dwarf2__generate_aranges(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, +yasm_section *yasm_dwarf2__generate_aranges(yasm_object *object, yasm_section *debug_info); /* Name lookup table functions */ -yasm_section *yasm_dwarf2__generate_pubnames(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, +yasm_section *yasm_dwarf2__generate_pubnames(yasm_object *object, yasm_section *debug_info); /* Information functions */ yasm_section *yasm_dwarf2__generate_info - (yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_section *debug_line, + (yasm_object *object, yasm_section *debug_line, /*@null@*/ yasm_section *main_code); #endif diff --git a/modules/dbgfmts/dwarf2/dwarf2-info.c b/modules/dbgfmts/dwarf2/dwarf2-info.c index 48923135..f17db488 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-info.c +++ b/modules/dbgfmts/dwarf2/dwarf2-info.c @@ -266,20 +266,19 @@ dwarf2_append_str(yasm_section *sect, const char *str) } yasm_section * -yasm_dwarf2__generate_info(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, - yasm_section *debug_line, yasm_section *main_code) +yasm_dwarf2__generate_info(yasm_object *object, yasm_section *debug_line, + yasm_section *main_code) { + yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)object->dbgfmt; int new; yasm_bytecode *abc; dwarf2_abbrev *abbrev; dwarf2_head *head; char *buf; yasm_section *debug_abbrev = - yasm_object_get_general(dbgfmt_dwarf2->object, ".debug_abbrev", 0, - 4, 0, 0, &new, 0); + yasm_object_get_general(object, ".debug_abbrev", 0, 4, 0, 0, &new, 0); yasm_section *debug_info = - yasm_object_get_general(dbgfmt_dwarf2->object, ".debug_info", 0, 4, 0, - 0, &new, 0); + yasm_object_get_general(object, ".debug_info", 0, 4, 0, 0, &new, 0); yasm_section_set_align(debug_abbrev, 0, 0); yasm_section_set_align(debug_info, 0, 0); @@ -311,13 +310,13 @@ yasm_dwarf2__generate_info(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, abc->len += dwarf2_add_abbrev_attr(abbrev, DW_AT_stmt_list, DW_FORM_data4); dwarf2_append_expr(debug_info, yasm_expr_create_ident(yasm_expr_sym( - yasm_dwarf2__bc_sym(dbgfmt_dwarf2->symtab, + yasm_dwarf2__bc_sym(object->symtab, yasm_section_bcs_first(debug_line))), 0), dbgfmt_dwarf2->sizeof_offset, 0); if (main_code) { yasm_symrec *first; - first = yasm_dwarf2__bc_sym(dbgfmt_dwarf2->symtab, + first = yasm_dwarf2__bc_sym(object->symtab, yasm_section_bcs_first(main_code)); /* All code is contiguous in one section */ abc->len += dwarf2_add_abbrev_attr(abbrev, DW_AT_low_pc, DW_FORM_addr); @@ -336,8 +335,7 @@ yasm_dwarf2__generate_info(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, /* input filename */ abc->len += dwarf2_add_abbrev_attr(abbrev, DW_AT_name, DW_FORM_string); - dwarf2_append_str(debug_info, - yasm_object_get_source_fn(dbgfmt_dwarf2->object)); + dwarf2_append_str(debug_info, object->src_filename); /* compile directory (current working directory) */ abc->len += dwarf2_add_abbrev_attr(abbrev, DW_AT_comp_dir, DW_FORM_string); diff --git a/modules/dbgfmts/dwarf2/dwarf2-line.c b/modules/dbgfmts/dwarf2/dwarf2-line.c index c5718872..c38fda4c 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-line.c +++ b/modules/dbgfmts/dwarf2/dwarf2-line.c @@ -111,7 +111,6 @@ typedef struct dwarf2_line_state { } dwarf2_line_state; typedef struct dwarf2_spp { - yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2; yasm_bytecode *line_start_prevbc; yasm_bytecode *line_end_prevbc; } dwarf2_spp; @@ -445,6 +444,8 @@ dwarf2_dbgfmt_gen_line_op(yasm_section *debug_line, dwarf2_line_state *state, typedef struct dwarf2_line_bc_info { yasm_section *debug_line; + yasm_object *object; + yasm_linemap *linemap; yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2; dwarf2_line_state *state; dwarf2_loc loc; @@ -475,8 +476,7 @@ dwarf2_generate_line_bc(yasm_bytecode *bc, /*@null@*/ void *d) } } - yasm_linemap_lookup(dbgfmt_dwarf2->linemap, bc->line, &filename, - &info->loc.line); + yasm_linemap_lookup(info->linemap, bc->line, &filename, &info->loc.line); /* Find file index; just linear search it unless it was the last used */ if (info->lastfile > 0 && strcmp(filename, dbgfmt_dwarf2->filenames[info->lastfile-1].pathname) @@ -500,6 +500,8 @@ dwarf2_generate_line_bc(yasm_bytecode *bc, /*@null@*/ void *d) typedef struct dwarf2_line_info { yasm_section *debug_line; /* section to which line number info goes */ + yasm_object *object; + yasm_linemap *linemap; yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2; yasm_errwarns *errwarns; @@ -552,6 +554,8 @@ dwarf2_generate_line_section(yasm_section *sect, /*@null@*/ void *d) dwarf2_line_bc_info bcinfo; bcinfo.debug_line = info->debug_line; + bcinfo.object = info->object; + bcinfo.linemap = info->linemap; bcinfo.dbgfmt_dwarf2 = dbgfmt_dwarf2; bcinfo.state = &state; bcinfo.lastfile = 0; @@ -618,11 +622,12 @@ dwarf2_generate_filename(const char *filename, void *d) } yasm_section * -yasm_dwarf2__generate_line(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, +yasm_dwarf2__generate_line(yasm_object *object, yasm_linemap *linemap, yasm_errwarns *errwarns, int asm_source, /*@out@*/ yasm_section **main_code, /*@out@*/ size_t *num_line_sections) { + yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)object->dbgfmt; dwarf2_line_info info; int new; size_t i; @@ -632,17 +637,18 @@ yasm_dwarf2__generate_line(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, if (asm_source) { /* Generate dirs and filenames based on linemap */ - yasm_linemap_traverse_filenames(dbgfmt_dwarf2->linemap, dbgfmt_dwarf2, + yasm_linemap_traverse_filenames(linemap, dbgfmt_dwarf2, dwarf2_generate_filename); } info.num_sections = 0; info.last_code = NULL; info.asm_source = asm_source; + info.object = object; + info.linemap = linemap; info.dbgfmt_dwarf2 = dbgfmt_dwarf2; - info.debug_line = yasm_object_get_general(dbgfmt_dwarf2->object, - ".debug_line", 0, 1, 0, 0, &new, - 0); + info.debug_line = yasm_object_get_general(object, ".debug_line", 0, 1, 0, + 0, &new, 0); last = yasm_section_bcs_last(info.debug_line); /* header */ @@ -650,7 +656,6 @@ yasm_dwarf2__generate_line(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, /* statement program prologue */ spp = yasm_xmalloc(sizeof(dwarf2_spp)); - spp->dbgfmt_dwarf2 = dbgfmt_dwarf2; sppbc = yasm_bc_create_common(&dwarf2_spp_bc_callback, spp, 0); sppbc->len = dbgfmt_dwarf2->sizeof_offset + 5 + NELEMS(line_opcode_num_operands); @@ -676,7 +681,7 @@ yasm_dwarf2__generate_line(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_dwarf2__append_bc(info.debug_line, sppbc); /* statement program */ - yasm_object_sections_traverse(dbgfmt_dwarf2->object, (void *)&info, + yasm_object_sections_traverse(object, (void *)&info, dwarf2_generate_line_section); /* mark end of line information */ @@ -716,8 +721,8 @@ dwarf2_spp_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) { - dwarf2_spp *spp = (dwarf2_spp *)bc->contents; - yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = spp->dbgfmt_dwarf2; + yasm_object *object = yasm_section_get_object(bc->section); + yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)object->dbgfmt; unsigned char *buf = *bufp; yasm_intnum *cval; size_t i, len; @@ -725,7 +730,7 @@ dwarf2_spp_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, /* Prologue length (following this field) */ cval = yasm_intnum_create_uint(bc->len - (unsigned long)(buf-*bufp) - dbgfmt_dwarf2->sizeof_offset); - yasm_arch_intnum_tobytes(dbgfmt_dwarf2->arch, cval, buf, + yasm_arch_intnum_tobytes(object->arch, cval, buf, dbgfmt_dwarf2->sizeof_offset, dbgfmt_dwarf2->sizeof_offset*8, 0, bc, 0); buf += dbgfmt_dwarf2->sizeof_offset; @@ -822,10 +827,10 @@ dwarf2_line_op_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, } int -yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, - const char *name, yasm_section *sect, +yasm_dwarf2__line_directive(yasm_object *object, const char *name, yasm_valparamhead *valparams, unsigned long line) { + yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)object->dbgfmt; yasm_valparam *vp; if (yasm__strcasecmp(name, "loc") == 0) { /*@dependent@*/ /*@null@*/ const yasm_intnum *intn; @@ -870,11 +875,13 @@ yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, loc->line = yasm_intnum_get_uint(intn); /* Generate new section data if it doesn't already exist */ - dsd = yasm_section_get_data(sect, &yasm_dwarf2__section_data_cb); + dsd = yasm_section_get_data(object->cur_section, + &yasm_dwarf2__section_data_cb); if (!dsd) { dsd = yasm_xmalloc(sizeof(dwarf2_section_data)); STAILQ_INIT(&dsd->locs); - yasm_section_add_data(sect, &yasm_dwarf2__section_data_cb, dsd); + yasm_section_add_data(object->cur_section, + &yasm_dwarf2__section_data_cb, dsd); } /* Defaults for optional settings */ @@ -978,7 +985,7 @@ yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, vp = yasm_vps_first(valparams); if (vp->val) { /* Just a bare filename */ - yasm_object_set_source_fn(dbgfmt_dwarf2->object, vp->val); + yasm_object_set_source_fn(object, vp->val); return 0; } diff --git a/modules/dbgfmts/null/null-dbgfmt.c b/modules/dbgfmts/null/null-dbgfmt.c index 0ec4928f..9ddf776d 100644 --- a/modules/dbgfmts/null/null-dbgfmt.c +++ b/modules/dbgfmts/null/null-dbgfmt.c @@ -35,7 +35,7 @@ yasm_dbgfmt_module yasm_null_LTX_dbgfmt; static /*@null@*/ /*@only@*/ yasm_dbgfmt * -null_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) +null_dbgfmt_create(yasm_object *object) { yasm_dbgfmt_base *dbgfmt = yasm_xmalloc(sizeof(yasm_dbgfmt_base)); dbgfmt->module = &yasm_null_LTX_dbgfmt; @@ -49,15 +49,15 @@ null_dbgfmt_destroy(/*@only@*/ yasm_dbgfmt *dbgfmt) } static int -null_dbgfmt_directive(yasm_dbgfmt *dbgfmt, const char *name, - yasm_section *sect, yasm_valparamhead *valparams, - unsigned long line) +null_dbgfmt_directive(yasm_object *object, const char *name, + yasm_valparamhead *valparams, unsigned long line) { return 1; } static void -null_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) +null_dbgfmt_generate(yasm_object *object, yasm_linemap *linemap, + yasm_errwarns *errwarns) { } diff --git a/modules/dbgfmts/stabs/stabs-dbgfmt.c b/modules/dbgfmts/stabs/stabs-dbgfmt.c index 0df12a6c..5bf6b8ad 100644 --- a/modules/dbgfmts/stabs/stabs-dbgfmt.c +++ b/modules/dbgfmts/stabs/stabs-dbgfmt.c @@ -82,11 +82,6 @@ typedef enum { typedef struct yasm_dbgfmt_stabs { yasm_dbgfmt_base dbgfmt; /* base structure */ - - yasm_object *object; - yasm_symtab *symtab; - yasm_linemap *linemap; - yasm_arch *arch; } yasm_dbgfmt_stabs; typedef struct { @@ -103,7 +98,8 @@ typedef struct { yasm_bytecode *basebc; /* base bytecode from which to track SLINEs */ - yasm_dbgfmt_stabs *dbgfmt_stabs; + yasm_object *object; + yasm_linemap *linemap; yasm_errwarns *errwarns; } stabs_info; @@ -165,14 +161,10 @@ yasm_dbgfmt_module yasm_stabs_LTX_dbgfmt; static /*@null@*/ /*@only@*/ yasm_dbgfmt * -stabs_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) +stabs_dbgfmt_create(yasm_object *object) { yasm_dbgfmt_stabs *dbgfmt_stabs = yasm_xmalloc(sizeof(yasm_dbgfmt_stabs)); dbgfmt_stabs->dbgfmt.module = &yasm_stabs_LTX_dbgfmt; - dbgfmt_stabs->object = object; - dbgfmt_stabs->symtab = yasm_object_get_symtab(object); - dbgfmt_stabs->linemap = yasm_object_get_linemap(object); - dbgfmt_stabs->arch = a; return (yasm_dbgfmt *)dbgfmt_stabs; } @@ -263,7 +255,7 @@ static int stabs_dbgfmt_generate_bcs(yasm_bytecode *bc, void *d) { stabs_info *info = (stabs_info *)d; - yasm_linemap_lookup(info->dbgfmt_stabs->linemap, bc->line, &info->curfile, + yasm_linemap_lookup(info->linemap, bc->line, &info->curfile, &info->curline); /* check for new function */ @@ -309,8 +301,8 @@ stabs_dbgfmt_generate_sections(yasm_section *sect, /*@null@*/ void *d) /* Close out last function by appending a null SO stab after last bc */ yasm_bytecode *bc = yasm_section_bcs_last(sect); yasm_symrec *sym = - yasm_symtab_define_label(yasm_object_get_symtab( - yasm_section_get_object(sect)), ".n_so", bc, 1, bc->line); + yasm_symtab_define_label(info->object->symtab, ".n_so", bc, 1, + bc->line); stabs_dbgfmt_append_stab(info, info->stab, 0, N_SO, 0, sym, bc, 0); } @@ -318,9 +310,9 @@ stabs_dbgfmt_generate_sections(yasm_section *sect, /*@null@*/ void *d) } static void -stabs_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) +stabs_dbgfmt_generate(yasm_object *object, yasm_linemap *linemap, + yasm_errwarns *errwarns) { - yasm_dbgfmt_stabs *dbgfmt_stabs = (yasm_dbgfmt_stabs *)dbgfmt; stabs_info info; int new; yasm_bytecode *dbgbc; @@ -330,18 +322,18 @@ stabs_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) yasm_section *stext; /* Stablen is determined by arch/machine */ - if (yasm__strcasecmp(yasm_arch_keyword(dbgfmt_stabs->arch), "x86") == 0) { + if (yasm__strcasecmp(yasm_arch_keyword(object->arch), "x86") == 0) { info.stablen = 12; } else /* unknown machine; generate nothing */ return; - info.dbgfmt_stabs = dbgfmt_stabs; + info.object = object; + info.linemap = linemap; info.errwarns = errwarns; info.lastline = 0; info.stabcount = 0; - info.stab = yasm_object_get_general(dbgfmt_stabs->object, ".stab", 0, 4, 0, - 0, &new, 0); + info.stab = yasm_object_get_general(object, ".stab", 0, 4, 0, 0, &new, 0); if (!new) { yasm_bytecode *last = yasm_section_bcs_last(info.stab); if (last == NULL) { @@ -356,8 +348,8 @@ stabs_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) } } - info.stabstr = yasm_object_get_general(dbgfmt_stabs->object, ".stabstr", 0, - 1, 0, 0, &new, 0); + info.stabstr = + yasm_object_get_general(object, ".stabstr", 0, 1, 0, 0, &new, 0); if (!new) { yasm_bytecode *last = yasm_section_bcs_last(info.stabstr); if (last == NULL) { @@ -381,17 +373,16 @@ stabs_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) /* initial strtab bytecodes */ nullbc = stabs_dbgfmt_append_bcstr(info.stabstr, ""); - filebc = stabs_dbgfmt_append_bcstr(info.stabstr, - yasm_object_get_source_fn(dbgfmt_stabs->object)); + filebc = stabs_dbgfmt_append_bcstr(info.stabstr, object->src_filename); - stext = yasm_object_find_general(dbgfmt_stabs->object, ".text"); - firstsym = yasm_symtab_use(dbgfmt_stabs->symtab, ".text", 0); + stext = yasm_object_find_general(object, ".text"); + firstsym = yasm_symtab_use(object->symtab, ".text", 0); firstbc = yasm_section_bcs_first(stext); /* N_SO file stab */ stabs_dbgfmt_append_stab(&info, info.stab, filebc, N_SO, 0, firstsym, firstbc, 0); - yasm_object_sections_traverse(dbgfmt_stabs->object, (void *)&info, + yasm_object_sections_traverse(object, (void *)&info, stabs_dbgfmt_generate_sections); /* fill initial pseudo-stab's fields */ @@ -509,9 +500,8 @@ stabs_bc_str_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, } static int -stabs_dbgfmt_directive(yasm_dbgfmt *dbgfmt, const char *name, - yasm_section *sect, yasm_valparamhead *valparams, - unsigned long line) +stabs_dbgfmt_directive(yasm_object *object, const char *name, + yasm_valparamhead *valparams, unsigned long line) { return 1; } diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c index e89efaf2..b98ac63a 100644 --- a/modules/objfmts/bin/bin-objfmt.c +++ b/modules/objfmts/bin/bin-objfmt.c @@ -37,23 +37,16 @@ typedef struct yasm_objfmt_bin { yasm_objfmt_base objfmt; /* base structure */ - - yasm_object *object; - yasm_symtab *symtab; - /*@dependent@*/ yasm_arch *arch; } yasm_objfmt_bin; yasm_objfmt_module yasm_bin_LTX_objfmt; static yasm_objfmt * -bin_objfmt_create(yasm_object *object, yasm_arch *a) +bin_objfmt_create(yasm_object *object) { yasm_objfmt_bin *objfmt_bin = yasm_xmalloc(sizeof(yasm_objfmt_bin)); objfmt_bin->objfmt.module = &yasm_bin_LTX_objfmt; - objfmt_bin->object = object; - objfmt_bin->symtab = yasm_object_get_symtab(object); - objfmt_bin->arch = a; return (yasm_objfmt *)objfmt_bin; } @@ -91,7 +84,7 @@ bin_objfmt_align_section(yasm_section *sect, yasm_section *prevsect, } typedef struct bin_objfmt_output_info { - yasm_objfmt_bin *objfmt_bin; + yasm_object *object; /*@dependent@*/ FILE *f; /*@only@*/ unsigned char *buf; /*@observer@*/ const yasm_section *sect; @@ -169,7 +162,7 @@ bin_objfmt_output_value(yasm_value *value, unsigned char *buf, /* Output */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_bin->arch)) { + info->object->arch)) { case -1: return 1; case 0: @@ -200,7 +193,7 @@ bin_objfmt_output_value(yasm_value *value, unsigned char *buf, yasm_intnum_calc(outval, YASM_EXPR_ADD, yasm_expr_get_intnum(&value->abs, 1)); /* Output! */ - if (yasm_arch_intnum_tobytes(info->objfmt_bin->arch, outval, buf, + if (yasm_arch_intnum_tobytes(info->object->arch, outval, buf, destsize, valsize, 0, bc, warn)) retval = 1; yasm_intnum_destroy(outval); @@ -260,10 +253,9 @@ bin_objfmt_output_bytecode(yasm_bytecode *bc, /*@null@*/ void *d) } static void -bin_objfmt_output(yasm_objfmt *objfmt, FILE *f, /*@unused@*/ int all_syms, - /*@unused@*/ yasm_dbgfmt *df, yasm_errwarns *errwarns) +bin_objfmt_output(yasm_object *object, FILE *f, /*@unused@*/ int all_syms, + yasm_errwarns *errwarns) { - yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)objfmt; /*@observer@*/ /*@null@*/ yasm_section *text, *data, *bss, *prevsect; /*@null@*/ yasm_expr *startexpr; /*@dependent@*/ /*@null@*/ const yasm_intnum *startnum; @@ -273,13 +265,13 @@ bin_objfmt_output(yasm_objfmt *objfmt, FILE *f, /*@unused@*/ int all_syms, unsigned long i; bin_objfmt_output_info info; - info.objfmt_bin = objfmt_bin; + info.object = object; info.f = f; info.buf = yasm_xmalloc(REGULAR_OUTBUF_SIZE); - text = yasm_object_find_general(objfmt_bin->object, ".text"); - data = yasm_object_find_general(objfmt_bin->object, ".data"); - bss = yasm_object_find_general(objfmt_bin->object, ".bss"); + text = yasm_object_find_general(object, ".text"); + data = yasm_object_find_general(object, ".data"); + bss = yasm_object_find_general(object, ".bss"); if (!text) yasm_internal_error(N_("No `.text' section in bin objfmt output")); @@ -361,37 +353,33 @@ bin_objfmt_destroy(yasm_objfmt *objfmt) } static void -bin_objfmt_init_new_section(yasm_objfmt_bin *objfmt_bin, yasm_section *sect, +bin_objfmt_init_new_section(yasm_object *object, yasm_section *sect, const char *sectname, unsigned long line) { - yasm_symtab_define_label( - yasm_object_get_symtab(objfmt_bin->object), sectname, - yasm_section_bcs_first(sect), 1, line); + yasm_symtab_define_label(object->symtab, sectname, + yasm_section_bcs_first(sect), 1, line); } static yasm_section * -bin_objfmt_add_default_section(yasm_objfmt *objfmt) +bin_objfmt_add_default_section(yasm_object *object) { - yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)objfmt; yasm_section *retval; int isnew; - retval = yasm_object_get_general(objfmt_bin->object, ".text", 0, 16, 1, 0, - &isnew, 0); + retval = yasm_object_get_general(object, ".text", 0, 16, 1, 0, &isnew, 0); if (isnew) { - bin_objfmt_init_new_section(objfmt_bin, retval, ".text", 0); + bin_objfmt_init_new_section(object, retval, ".text", 0); yasm_section_set_default(retval, 1); } return retval; } static /*@observer@*/ /*@null@*/ yasm_section * -bin_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, +bin_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)objfmt; yasm_valparam *vp; yasm_section *retval; int isnew; @@ -459,13 +447,13 @@ bin_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, } } - retval = yasm_object_get_general(objfmt_bin->object, sectname, + retval = yasm_object_get_general(object, sectname, yasm_expr_create_ident( yasm_expr_int(yasm_intnum_create_uint(start)), line), align, strcmp(sectname, ".text") == 0, resonly, &isnew, line); if (isnew) - bin_objfmt_init_new_section(objfmt_bin, retval, sectname, line); + bin_objfmt_init_new_section(object, retval, sectname, line); if (isnew || yasm_section_is_default(retval)) { yasm_section_set_default(retval, 0); @@ -480,61 +468,57 @@ bin_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, } static yasm_symrec * -bin_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, +bin_objfmt_extern_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)objfmt; yasm_symrec *sym; yasm_warn_set(YASM_WARN_GENERAL, N_("binary object format does not support extern variables")); - sym = yasm_symtab_declare(objfmt_bin->symtab, name, YASM_SYM_EXTERN, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_EXTERN, line); return sym; } static yasm_symrec * -bin_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, +bin_objfmt_global_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)objfmt; yasm_symrec *sym; yasm_warn_set(YASM_WARN_GENERAL, N_("binary object format does not support global variables")); - sym = yasm_symtab_declare(objfmt_bin->symtab, name, YASM_SYM_GLOBAL, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_GLOBAL, line); return sym; } static yasm_symrec * -bin_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, +bin_objfmt_common_declare(yasm_object *object, const char *name, /*@only@*/ yasm_expr *size, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)objfmt; yasm_symrec *sym; yasm_expr_destroy(size); yasm_error_set(YASM_ERROR_TYPE, N_("binary object format does not support common variables")); - sym = yasm_symtab_declare(objfmt_bin->symtab, name, YASM_SYM_COMMON, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_COMMON, line); return sym; } static int -bin_objfmt_directive(yasm_objfmt *objfmt, const char *name, +bin_objfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)objfmt; yasm_section *sect; yasm_valparam *vp; @@ -551,8 +535,7 @@ bin_objfmt_directive(yasm_objfmt *objfmt, const char *name, vp = yasm_vps_first(valparams); if (vp->val) start = yasm_expr_create_ident(yasm_expr_sym(yasm_symtab_use( - yasm_object_get_symtab(objfmt_bin->object), vp->val, line)), - line); + object->symtab, vp->val, line)), line); else if (vp->param) { start = vp->param; vp->param = NULL; /* Don't let valparams delete it */ @@ -565,7 +548,7 @@ bin_objfmt_directive(yasm_objfmt *objfmt, const char *name, } /* ORG changes the start of the .text section */ - sect = yasm_object_find_general(objfmt_bin->object, ".text"); + sect = yasm_object_find_general(object, ".text"); if (!sect) yasm_internal_error( N_("bin objfmt: .text section does not exist before ORG is called?")); diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index efc15c60..feb790af 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -184,18 +184,8 @@ typedef struct yasm_objfmt_coff { unsigned int machine; /* COFF machine to use */ - yasm_object *object; - yasm_symtab *symtab; - /*@dependent@*/ yasm_arch *arch; - coff_symrec_data *filesym_data; /* Data for .file symbol */ - /* Last switched-to section. Used by proc_frame directives to help - * them determine the current assembly position. - * XXX: There should be a better way to do this. - */ - yasm_section *cursect; - /* data for win64 proc_frame and related directives */ unsigned long proc_frame; /* Line number of start of proc, or 0 */ unsigned long done_prolog; /* Line number of end of prologue, or 0 */ @@ -203,6 +193,7 @@ typedef struct yasm_objfmt_coff { } yasm_objfmt_coff; typedef struct coff_objfmt_output_info { + yasm_object *object; yasm_objfmt_coff *objfmt_coff; yasm_errwarns *errwarns; /*@dependent@*/ FILE *f; @@ -258,17 +249,13 @@ coff_objfmt_sym_set_data(yasm_symrec *sym, coff_symrec_sclass sclass, } static yasm_objfmt_coff * -coff_common_create(yasm_object *object, yasm_arch *a) +coff_common_create(yasm_object *object) { yasm_objfmt_coff *objfmt_coff = yasm_xmalloc(sizeof(yasm_objfmt_coff)); yasm_symrec *filesym; - objfmt_coff->object = object; - objfmt_coff->symtab = yasm_object_get_symtab(object); - objfmt_coff->arch = a; - /* Only support x86 arch */ - if (yasm__strcasecmp(yasm_arch_keyword(a), "x86") != 0) { + if (yasm__strcasecmp(yasm_arch_keyword(object->arch), "x86") != 0) { yasm_xfree(objfmt_coff); return NULL; } @@ -276,7 +263,7 @@ coff_common_create(yasm_object *object, yasm_arch *a) objfmt_coff->parse_scnum = 1; /* section numbering starts at 1 */ /* FIXME: misuse of NULL bytecode here; it works, but only barely. */ - filesym = yasm_symtab_define_special(objfmt_coff->symtab, ".file", + filesym = yasm_symtab_define_special(object->symtab, ".file", YASM_SYM_GLOBAL); objfmt_coff->filesym_data = coff_objfmt_sym_set_data(filesym, COFF_SCL_FILE, NULL, 1, @@ -284,8 +271,6 @@ coff_common_create(yasm_object *object, yasm_arch *a) /* Filename is set in coff_objfmt_output */ objfmt_coff->filesym_data->aux[0].fname = NULL; - objfmt_coff->cursect = NULL; - objfmt_coff->proc_frame = 0; objfmt_coff->done_prolog = 0; objfmt_coff->unwind = NULL; @@ -294,17 +279,18 @@ coff_common_create(yasm_object *object, yasm_arch *a) } static yasm_objfmt * -coff_objfmt_create(yasm_object *object, yasm_arch *a) +coff_objfmt_create(yasm_object *object) { - yasm_objfmt_coff *objfmt_coff = coff_common_create(object, a); + yasm_objfmt_coff *objfmt_coff = coff_common_create(object); if (objfmt_coff) { /* Support x86 and amd64 machines of x86 arch */ - if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0) { + if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), "x86") == 0) objfmt_coff->machine = COFF_MACHINE_I386; - } else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) { + else if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), + "amd64") == 0) objfmt_coff->machine = COFF_MACHINE_AMD64; - } else { + else { yasm_xfree(objfmt_coff); return NULL; } @@ -317,18 +303,20 @@ coff_objfmt_create(yasm_object *object, yasm_arch *a) } static yasm_objfmt * -win32_objfmt_create(yasm_object *object, yasm_arch *a) +win32_objfmt_create(yasm_object *object) { - yasm_objfmt_coff *objfmt_coff = coff_common_create(object, a); + yasm_objfmt_coff *objfmt_coff = coff_common_create(object); if (objfmt_coff) { /* Support x86 and amd64 machines of x86 arch. * (amd64 machine supported for backwards compatibility) */ - if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0) { + if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), + "x86") == 0) { objfmt_coff->machine = COFF_MACHINE_I386; objfmt_coff->objfmt.module = &yasm_win32_LTX_objfmt; - } else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) { + } else if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), + "amd64") == 0) { objfmt_coff->machine = COFF_MACHINE_AMD64; objfmt_coff->objfmt.module = &yasm_win64_LTX_objfmt; objfmt_coff->win64 = 1; @@ -343,13 +331,14 @@ win32_objfmt_create(yasm_object *object, yasm_arch *a) } static yasm_objfmt * -win64_objfmt_create(yasm_object *object, yasm_arch *a) +win64_objfmt_create(yasm_object *object) { - yasm_objfmt_coff *objfmt_coff = coff_common_create(object, a); + yasm_objfmt_coff *objfmt_coff = coff_common_create(object); if (objfmt_coff) { /* Support amd64 machine of x86 arch */ - if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) { + if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), + "amd64") == 0) { objfmt_coff->machine = COFF_MACHINE_AMD64; } else { yasm_xfree(objfmt_coff); @@ -364,9 +353,10 @@ win64_objfmt_create(yasm_object *object, yasm_arch *a) } static coff_section_data * -coff_objfmt_init_new_section(yasm_objfmt_coff *objfmt_coff, yasm_section *sect, +coff_objfmt_init_new_section(yasm_object *object, yasm_section *sect, const char *sectname, unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; coff_section_data *data; yasm_symrec *sym; @@ -383,7 +373,7 @@ coff_objfmt_init_new_section(yasm_objfmt_coff *objfmt_coff, yasm_section *sect, data->isdebug = 0; yasm_section_add_data(sect, &coff_section_data_cb, data); - sym = yasm_symtab_define_label(objfmt_coff->symtab, sectname, + sym = yasm_symtab_define_label(object->symtab, sectname, yasm_section_bcs_first(sect), 1, line); yasm_symrec_declare(sym, YASM_SYM_GLOBAL, line); coff_objfmt_sym_set_data(sym, COFF_SCL_STAT, NULL, 1, @@ -407,8 +397,7 @@ coff_objfmt_init_remaining_section(yasm_section *sect, /*@null@*/ void *d) if (!csd) { /* Initialize new one */ const char *sectname = yasm_section_get_name(sect); - csd = coff_objfmt_init_new_section(info->objfmt_coff, sect, sectname, - 0); + csd = coff_objfmt_init_new_section(info->object, sect, sectname, 0); if (yasm__strncasecmp(sectname, ".debug", 6)==0) { csd->flags = COFF_STYP_DATA; if (info->objfmt_coff->win32) @@ -465,7 +454,7 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, * cross-section, or non-PC-relative reference (those are handled below). */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_coff->arch)) { + info->object->arch)) { case -1: return 1; case 0: @@ -695,7 +684,7 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, yasm_intnum_destroy(dist); } - retval = yasm_arch_intnum_tobytes(objfmt_coff->arch, intn, buf, destsize, + retval = yasm_arch_intnum_tobytes(info->object->arch, intn, buf, destsize, valsize, 0, bc, warn); yasm_intnum_destroy(intn); return retval; @@ -1149,10 +1138,10 @@ coff_objfmt_output_str(yasm_symrec *sym, /*@null@*/ void *d) } static void -coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, +coff_objfmt_output(yasm_object *object, FILE *f, int all_syms, yasm_errwarns *errwarns) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; coff_objfmt_output_info info; unsigned char *localbuf; long pos; @@ -1173,7 +1162,7 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, if (objfmt_coff->filesym_data->aux[0].fname) yasm_xfree(objfmt_coff->filesym_data->aux[0].fname); objfmt_coff->filesym_data->aux[0].fname = - yasm__xstrdup(yasm_object_get_source_fn(objfmt_coff->object)); + yasm__xstrdup(object->src_filename); /* Force all syms for win64 because they're needed for relocations. * FIXME: Not *all* syms need to be output, only the ones needed for @@ -1182,6 +1171,7 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, all_syms |= objfmt_coff->win64; info.strtab_offset = 4; + info.object = object; info.objfmt_coff = objfmt_coff; info.errwarns = errwarns; info.f = f; @@ -1190,7 +1180,7 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, /* Initialize section data (and count in parse_scnum) any sections that * we've not initialized so far. */ - yasm_object_sections_traverse(objfmt_coff->object, &info, + yasm_object_sections_traverse(object, &info, coff_objfmt_init_remaining_section); /* Allocate space for headers by seeking forward */ @@ -1203,7 +1193,7 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, /* Finalize symbol table (assign index to each symbol) */ info.indx = 0; info.all_syms = all_syms; - yasm_symtab_traverse(objfmt_coff->symtab, &info, coff_objfmt_count_sym); + yasm_symtab_traverse(object->symtab, &info, coff_objfmt_count_sym); symtab_count = info.indx; /* Section data/relocs */ @@ -1214,12 +1204,12 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, * addends in the generated code. */ info.addr = 0; - if (yasm_object_sections_traverse(objfmt_coff->object, &info, + if (yasm_object_sections_traverse(object, &info, coff_objfmt_set_section_addr)) return; } info.addr = 0; - if (yasm_object_sections_traverse(objfmt_coff->object, &info, + if (yasm_object_sections_traverse(object, &info, coff_objfmt_output_section)) return; @@ -1231,13 +1221,12 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, return; } symtab_pos = (unsigned long)pos; - yasm_symtab_traverse(objfmt_coff->symtab, &info, coff_objfmt_output_sym); + yasm_symtab_traverse(object->symtab, &info, coff_objfmt_output_sym); /* String table */ yasm_fwrite_32_l(info.strtab_offset, f); /* total length */ - yasm_object_sections_traverse(objfmt_coff->object, &info, - coff_objfmt_output_sectstr); - yasm_symtab_traverse(objfmt_coff->symtab, &info, coff_objfmt_output_str); + yasm_object_sections_traverse(object, &info, coff_objfmt_output_sectstr); + yasm_symtab_traverse(object->symtab, &info, coff_objfmt_output_str); /* Write headers */ if (fseek(f, 0, SEEK_SET) < 0) { @@ -1259,7 +1248,7 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, YASM_WRITE_16_L(localbuf, 0); /* size of optional header (none) */ /* flags */ flags = 0; - if (strcmp(yasm_dbgfmt_keyword(df), "null")==0) + if (strcmp(yasm_dbgfmt_keyword(object->dbgfmt), "null")==0) flags = COFF_F_LNNO; if (!all_syms) flags |= COFF_F_LSYMS; @@ -1268,8 +1257,7 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, YASM_WRITE_16_L(localbuf, flags); fwrite(info.buf, 20, 1, f); - yasm_object_sections_traverse(objfmt_coff->object, &info, - coff_objfmt_output_secthead); + yasm_object_sections_traverse(object, &info, coff_objfmt_output_secthead); yasm_xfree(info.buf); } @@ -1286,33 +1274,31 @@ coff_objfmt_destroy(yasm_objfmt *objfmt) } static yasm_section * -coff_objfmt_add_default_section(yasm_objfmt *objfmt) +coff_objfmt_add_default_section(yasm_object *object) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_section *retval; coff_section_data *csd; int isnew; - retval = yasm_object_get_general(objfmt_coff->object, ".text", 0, 16, 1, 0, - &isnew, 0); + retval = yasm_object_get_general(object, ".text", 0, 16, 1, 0, &isnew, 0); if (isnew) { - csd = coff_objfmt_init_new_section(objfmt_coff, retval, ".text", 0); + csd = coff_objfmt_init_new_section(object, retval, ".text", 0); csd->flags = COFF_STYP_TEXT; if (objfmt_coff->win32) csd->flags |= COFF_STYP_EXECUTE | COFF_STYP_READ; yasm_section_set_default(retval, 1); } - objfmt_coff->cursect = retval; return retval; } static /*@observer@*/ /*@null@*/ yasm_section * -coff_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, +coff_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_valparam *vp = yasm_vps_first(valparams); yasm_section *retval; int isnew; @@ -1588,11 +1574,11 @@ coff_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, N_("Standard COFF does not support qualifier `%s'"), vp->val); } - retval = yasm_object_get_general(objfmt_coff->object, sectname, 0, align, - iscode, resonly, &isnew, line); + retval = yasm_object_get_general(object, sectname, 0, align, iscode, + resonly, &isnew, line); if (isnew) - csd = coff_objfmt_init_new_section(objfmt_coff, retval, sectname, line); + csd = coff_objfmt_init_new_section(object, retval, sectname, line); else csd = yasm_section_get_data(retval, &coff_section_data_cb); @@ -1604,7 +1590,6 @@ coff_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, } else if (flags_override) yasm_warn_set(YASM_WARN_GENERAL, N_("section flags ignored on section redeclaration")); - objfmt_coff->cursect = retval; return retval; } @@ -1646,15 +1631,13 @@ coff_section_data_print(void *data, FILE *f, int indent_level) } static yasm_symrec * -coff_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ +coff_objfmt_extern_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; yasm_symrec *sym; - sym = yasm_symtab_declare(objfmt_coff->symtab, name, YASM_SYM_EXTERN, - line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_EXTERN, line); coff_objfmt_sym_set_data(sym, COFF_SCL_EXT, NULL, 0, COFF_SYMTAB_AUX_NONE); @@ -1662,15 +1645,13 @@ coff_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ } static yasm_symrec * -coff_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ +coff_objfmt_global_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; yasm_symrec *sym; - sym = yasm_symtab_declare(objfmt_coff->symtab, name, YASM_SYM_GLOBAL, - line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_GLOBAL, line); coff_objfmt_sym_set_data(sym, COFF_SCL_EXT, NULL, 0, COFF_SYMTAB_AUX_NONE); @@ -1678,16 +1659,14 @@ coff_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ } static yasm_symrec * -coff_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, +coff_objfmt_common_declare(yasm_object *object, const char *name, /*@only@*/ yasm_expr *size, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; yasm_symrec *sym; - sym = yasm_symtab_declare(objfmt_coff->symtab, name, YASM_SYM_COMMON, - line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_COMMON, line); coff_objfmt_sym_set_data(sym, COFF_SCL_EXT, size, 0, COFF_SYMTAB_AUX_NONE); @@ -1719,7 +1698,7 @@ coff_symrec_data_print(void *data, FILE *f, int indent_level) } static void -dir_export(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, +dir_export(yasm_object *object, yasm_valparamhead *valparams, unsigned long line) { yasm_valparam *vp; @@ -1730,7 +1709,7 @@ dir_export(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, /* Reference exported symbol (to generate error if not declared) */ vp = yasm_vps_first(valparams); if (vp->val) - yasm_symtab_use(objfmt_coff->symtab, vp->val, line); + yasm_symtab_use(object->symtab, vp->val, line); else { yasm_error_set(YASM_ERROR_SYNTAX, N_("argument to EXPORT must be symbol name")); @@ -1738,13 +1717,13 @@ dir_export(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, } /* Add to end of linker directives */ - sect = yasm_object_get_general(objfmt_coff->object, ".drectve", 0, 0, 0, - 0, &isnew, line); + sect = yasm_object_get_general(object, ".drectve", 0, 0, 0, 0, &isnew, + line); /* Initialize directive section if needed */ if (isnew) { coff_section_data *csd; - csd = coff_objfmt_init_new_section(objfmt_coff, sect, + csd = coff_objfmt_init_new_section(object, sect, yasm_section_get_name(sect), line); csd->flags = COFF_STYP_INFO | COFF_STYP_DISCARD | COFF_STYP_READ; } @@ -1760,9 +1739,10 @@ dir_export(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, } static void -dir_ident(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, +dir_ident(yasm_object *object, yasm_valparamhead *valparams, unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_valparamhead sect_vps; yasm_datavalhead dvs; yasm_section *comment; @@ -1783,8 +1763,7 @@ dir_ident(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, yasm_vps_initialize(§_vps); vp2 = yasm_vp_create(yasm__xstrdup(sectname), NULL); yasm_vps_append(§_vps, vp2); - comment = coff_objfmt_section_switch((yasm_objfmt *)objfmt_coff, - §_vps, NULL, line); + comment = coff_objfmt_section_switch(object, §_vps, NULL, line); yasm_vps_delete(§_vps); /* To match GAS output, if the comment section is empty, put an @@ -1796,7 +1775,7 @@ dir_ident(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, yasm_expr_create_ident(yasm_expr_int(yasm_intnum_create_uint(0)), line))); yasm_section_bcs_append(comment, - yasm_bc_create_data(&dvs, 1, 0, objfmt_coff->arch, line)); + yasm_bc_create_data(&dvs, 1, 0, object->arch, line)); } yasm_dvs_initialize(&dvs); @@ -1806,41 +1785,39 @@ dir_ident(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, } while ((vp = yasm_vps_next(vp))); yasm_section_bcs_append(comment, - yasm_bc_create_data(&dvs, 1, 1, objfmt_coff->arch, line)); + yasm_bc_create_data(&dvs, 1, 1, object->arch, line)); } static int -coff_objfmt_directive(yasm_objfmt *objfmt, const char *name, +coff_objfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; if (yasm__strcasecmp(name, "IDENT") == 0) { if (!valparams) { yasm_error_set(YASM_ERROR_SYNTAX, N_("[%s] requires an argument"), "IDENT"); return 0; } - dir_ident(objfmt_coff, valparams, line); + dir_ident(object, valparams, line); return 0; } return 1; } static int -win32_objfmt_directive(yasm_objfmt *objfmt, const char *name, +win32_objfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; static const struct { const char *name; int required_arg; - void (*func) (yasm_objfmt_coff *, yasm_valparamhead *, unsigned long); + void (*func) (yasm_object *, yasm_valparamhead *, unsigned long); } dirs[] = { {"EXPORT", 1, dir_export}, {"IDENT", 1, dir_ident} @@ -1854,7 +1831,7 @@ win32_objfmt_directive(yasm_objfmt *objfmt, const char *name, N_("[%s] requires an argument"), dirs[i].name); return 0; } - dirs[i].func(objfmt_coff, valparams, line); + dirs[i].func(object, valparams, line); return 0; } } @@ -1862,9 +1839,10 @@ win32_objfmt_directive(yasm_objfmt *objfmt, const char *name, } static void -dir_proc_frame(yasm_objfmt_coff *objfmt_coff, - /*@null@*/ yasm_valparamhead *valparams, unsigned long line) +dir_proc_frame(yasm_object *object, /*@null@*/ yasm_valparamhead *valparams, + unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_valparam *vp = yasm_vps_first(valparams); if (objfmt_coff->proc_frame) { yasm_error_set_xref(objfmt_coff->proc_frame, @@ -1882,15 +1860,14 @@ dir_proc_frame(yasm_objfmt_coff *objfmt_coff, objfmt_coff->proc_frame = line; objfmt_coff->done_prolog = 0; objfmt_coff->unwind = yasm_win64__uwinfo_create(); - objfmt_coff->unwind->proc = - yasm_symtab_use(objfmt_coff->symtab, vp->val, line); + objfmt_coff->unwind->proc = yasm_symtab_use(object->symtab, vp->val, line); /* Optional error handler */ vp = yasm_vps_next(vp); if (!vp || !vp->val) return; objfmt_coff->unwind->ehandler = - yasm_symtab_use(objfmt_coff->symtab, vp->val, line); + yasm_symtab_use(object->symtab, vp->val, line); } static int @@ -1917,16 +1894,17 @@ procframe_checkstate(yasm_objfmt_coff *objfmt_coff, const char *dirname) * XXX: There should be a better way to do this. */ static yasm_symrec * -get_curpos(yasm_objfmt_coff *objfmt_coff, unsigned long line) +get_curpos(yasm_object *object, unsigned long line) { - return yasm_symtab_define_curpos(objfmt_coff->symtab, "$", - yasm_section_bcs_last(objfmt_coff->cursect), line); + return yasm_symtab_define_curpos(object->symtab, "$", + yasm_section_bcs_last(object->cur_section), line); } static void -dir_pushreg(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, +dir_pushreg(yasm_object *object, yasm_valparamhead *valparams, unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_valparam *vp = yasm_vps_first(valparams); coff_unwind_code *code; const uintptr_t *reg; @@ -1944,7 +1922,7 @@ dir_pushreg(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, /* Generate a PUSH_NONVOL unwind code. */ code = yasm_xmalloc(sizeof(coff_unwind_code)); code->proc = objfmt_coff->unwind->proc; - code->loc = get_curpos(objfmt_coff, line); + code->loc = get_curpos(object, line); code->opcode = UWOP_PUSH_NONVOL; code->info = (unsigned int)(*reg & 0xF); yasm_value_initialize(&code->off, NULL, 0); @@ -1952,9 +1930,10 @@ dir_pushreg(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, } static void -dir_setframe(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, +dir_setframe(yasm_object *object, yasm_valparamhead *valparams, unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_valparam *vp = yasm_vps_first(valparams); coff_unwind_code *code; const uintptr_t *reg; @@ -1983,7 +1962,7 @@ dir_setframe(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, /* Generate a SET_FPREG unwind code */ code = yasm_xmalloc(sizeof(coff_unwind_code)); code->proc = objfmt_coff->unwind->proc; - code->loc = get_curpos(objfmt_coff, line); + code->loc = get_curpos(object, line); code->opcode = UWOP_SET_FPREG; code->info = (unsigned int)(*reg & 0xF); yasm_value_initialize(&code->off, yasm_expr_copy(off), 8); @@ -1991,9 +1970,10 @@ dir_setframe(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, } static void -dir_allocstack(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, +dir_allocstack(yasm_object *object, yasm_valparamhead *valparams, unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_valparam *vp = yasm_vps_first(valparams); coff_unwind_code *code; @@ -2003,7 +1983,7 @@ dir_allocstack(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, /* Transform ID to expression if needed */ if (vp && vp->val && !vp->param) { vp->param = yasm_expr_create_ident(yasm_expr_sym( - yasm_symtab_use(objfmt_coff->symtab, vp->val, line)), line); + yasm_symtab_use(object->symtab, vp->val, line)), line); } if (!vp || !vp->param) { @@ -2017,7 +1997,7 @@ dir_allocstack(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, */ code = yasm_xmalloc(sizeof(coff_unwind_code)); code->proc = objfmt_coff->unwind->proc; - code->loc = get_curpos(objfmt_coff, line); + code->loc = get_curpos(object, line); code->opcode = UWOP_ALLOC_SMALL; code->info = 0; yasm_value_initialize(&code->off, vp->param, 7); @@ -2026,9 +2006,10 @@ dir_allocstack(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, } static void -dir_save_common(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, +dir_save_common(yasm_object *object, yasm_valparamhead *valparams, unsigned long line, const char *name, int op) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_valparam *vp = yasm_vps_first(valparams); coff_unwind_code *code; const uintptr_t *reg; @@ -2048,7 +2029,7 @@ dir_save_common(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, /* Transform ID to expression if needed */ if (vp && vp->val && !vp->param) { vp->param = yasm_expr_create_ident(yasm_expr_sym( - yasm_symtab_use(objfmt_coff->symtab, vp->val, line)), line); + yasm_symtab_use(object->symtab, vp->val, line)), line); } if (!vp || !vp->param) { @@ -2063,7 +2044,7 @@ dir_save_common(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, */ code = yasm_xmalloc(sizeof(coff_unwind_code)); code->proc = objfmt_coff->unwind->proc; - code->loc = get_curpos(objfmt_coff, line); + code->loc = get_curpos(object, line); code->opcode = op; code->info = (unsigned int)(*reg & 0xF); yasm_value_initialize(&code->off, vp->param, 16); @@ -2072,24 +2053,24 @@ dir_save_common(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, } static void -dir_savereg(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, +dir_savereg(yasm_object *object, yasm_valparamhead *valparams, unsigned long line) { - dir_save_common(objfmt_coff, valparams, line, "SAVEREG", UWOP_SAVE_NONVOL); + dir_save_common(object, valparams, line, "SAVEREG", UWOP_SAVE_NONVOL); } static void -dir_savexmm128(yasm_objfmt_coff *objfmt_coff, yasm_valparamhead *valparams, +dir_savexmm128(yasm_object *object, yasm_valparamhead *valparams, unsigned long line) { - dir_save_common(objfmt_coff, valparams, line, "SAVEXMM128", - UWOP_SAVE_XMM128); + dir_save_common(object, valparams, line, "SAVEXMM128", UWOP_SAVE_XMM128); } static void -dir_pushframe(yasm_objfmt_coff *objfmt_coff, - /*@null@*/ yasm_valparamhead *valparams, unsigned long line) +dir_pushframe(yasm_object *object, /*@null@*/ yasm_valparamhead *valparams, + unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_valparam *vp = yasm_vps_first(valparams); coff_unwind_code *code; @@ -2101,7 +2082,7 @@ dir_pushframe(yasm_objfmt_coff *objfmt_coff, */ code = yasm_xmalloc(sizeof(coff_unwind_code)); code->proc = objfmt_coff->unwind->proc; - code->loc = get_curpos(objfmt_coff, line); + code->loc = get_curpos(object, line); code->opcode = UWOP_PUSH_MACHFRAME; code->info = vp && (vp->val || vp->param); yasm_value_initialize(&code->off, NULL, 0); @@ -2109,20 +2090,22 @@ dir_pushframe(yasm_objfmt_coff *objfmt_coff, } static void -dir_endprolog(yasm_objfmt_coff *objfmt_coff, - /*@null@*/ yasm_valparamhead *valparams, unsigned long line) +dir_endprolog(yasm_object *object, /*@null@*/ yasm_valparamhead *valparams, + unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; if (!procframe_checkstate(objfmt_coff, "ENDPROLOG")) return; objfmt_coff->done_prolog = line; - objfmt_coff->unwind->prolog = get_curpos(objfmt_coff, line); + objfmt_coff->unwind->prolog = get_curpos(object, line); } static void -dir_endproc_frame(yasm_objfmt_coff *objfmt_coff, - /*@null@*/ yasm_valparamhead *valparams, unsigned long line) +dir_endproc_frame(yasm_object *object, /*@null@*/ yasm_valparamhead *valparams, + unsigned long line) { + yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; yasm_section *sect; coff_section_data *csd; yasm_datavalhead dvs; @@ -2151,24 +2134,23 @@ dir_endproc_frame(yasm_objfmt_coff *objfmt_coff, proc_sym = objfmt_coff->unwind->proc; - curpos = get_curpos(objfmt_coff, line); + curpos = get_curpos(object, line); /* * Add unwind info to end of .xdata section. */ - sect = yasm_object_get_general(objfmt_coff->object, ".xdata", 0, 0, 0, 0, - &isnew, line); + sect = yasm_object_get_general(object, ".xdata", 0, 0, 0, 0, &isnew, line); /* Initialize xdata section if needed */ if (isnew) { - csd = coff_objfmt_init_new_section(objfmt_coff, sect, ".xdata", line); + csd = coff_objfmt_init_new_section(object, sect, ".xdata", line); csd->flags = COFF_STYP_DATA | COFF_STYP_READ; yasm_section_set_align(sect, 8, line); } /* Get current position in .xdata section */ - unwindpos = yasm_symtab_define_curpos(objfmt_coff->symtab, "$", + unwindpos = yasm_symtab_define_curpos(object->symtab, "$", yasm_section_bcs_last(sect), line); /* Get symbol for .xdata as we'll want to reference it with WRT */ csd = yasm_section_get_data(sect, &coff_section_data_cb); @@ -2183,12 +2165,11 @@ dir_endproc_frame(yasm_objfmt_coff *objfmt_coff, * Add function lookup to end of .pdata section. */ - sect = yasm_object_get_general(objfmt_coff->object, ".pdata", 0, 0, 0, 0, - &isnew, line); + sect = yasm_object_get_general(object, ".pdata", 0, 0, 0, 0, &isnew, line); /* Initialize pdata section if needed */ if (isnew) { - csd = coff_objfmt_init_new_section(objfmt_coff, sect, ".pdata", line); + csd = coff_objfmt_init_new_section(object, sect, ".pdata", line); csd->flags = COFF_STYP_DATA | COFF_STYP_READ; csd->flags2 = COFF_FLAG_NOBASE; yasm_section_set_align(sect, 4, line); @@ -2211,17 +2192,16 @@ dir_endproc_frame(yasm_objfmt_coff *objfmt_coff, } static int -win64_objfmt_directive(yasm_objfmt *objfmt, const char *name, +win64_objfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; static const struct { const char *name; int required_arg; - void (*func) (yasm_objfmt_coff *, yasm_valparamhead *, unsigned long); + void (*func) (yasm_object *, yasm_valparamhead *, unsigned long); } dirs[] = { {"EXPORT", 1, dir_export}, {"IDENT", 1, dir_ident}, @@ -2244,7 +2224,7 @@ win64_objfmt_directive(yasm_objfmt *objfmt, const char *name, N_("[%s] requires an argument"), dirs[i].name); return 0; } - dirs[i].func(objfmt_coff, valparams, line); + dirs[i].func(object, valparams, line); return 0; } } diff --git a/modules/objfmts/dbg/dbg-objfmt.c b/modules/objfmts/dbg/dbg-objfmt.c index c346e20c..e65c2510 100644 --- a/modules/objfmts/dbg/dbg-objfmt.c +++ b/modules/objfmts/dbg/dbg-objfmt.c @@ -34,8 +34,6 @@ typedef struct yasm_objfmt_dbg { yasm_objfmt_base objfmt; /* base structure */ - yasm_object *object; - yasm_symtab *symtab; FILE *dbgfile; } yasm_objfmt_dbg; @@ -43,28 +41,26 @@ yasm_objfmt_module yasm_dbg_LTX_objfmt; static yasm_objfmt * -dbg_objfmt_create(yasm_object *object, yasm_arch *a) +dbg_objfmt_create(yasm_object *object) { yasm_objfmt_dbg *objfmt_dbg = yasm_xmalloc(sizeof(yasm_objfmt_dbg)); objfmt_dbg->objfmt.module = &yasm_dbg_LTX_objfmt; - objfmt_dbg->object = object; - objfmt_dbg->symtab = yasm_object_get_symtab(object); objfmt_dbg->dbgfile = tmpfile(); if (!objfmt_dbg->dbgfile) { fprintf(stderr, N_("could not open temporary file")); return 0; } - fprintf(objfmt_dbg->dbgfile, "create(%s arch)\n", yasm_arch_keyword(a)); + fprintf(objfmt_dbg->dbgfile, "create()\n"); return (yasm_objfmt *)objfmt_dbg; } static void -dbg_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, +dbg_objfmt_output(yasm_object *object, FILE *f, int all_syms, yasm_errwarns *errwarns) { - yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; char buf[1024]; size_t i; @@ -80,12 +76,10 @@ dbg_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, objfmt_dbg->dbgfile = f; fprintf(objfmt_dbg->dbgfile, "output(f, object->\n"); - yasm_object_print(objfmt_dbg->object, objfmt_dbg->dbgfile, 1); - fprintf(objfmt_dbg->dbgfile, "%d, %s dbgfmt)\n", all_syms, - yasm_dbgfmt_keyword(df)); + yasm_object_print(object, objfmt_dbg->dbgfile, 1); + fprintf(objfmt_dbg->dbgfile, "%d)\n", all_syms); fprintf(objfmt_dbg->dbgfile, " Symbol Table:\n"); - yasm_symtab_print(yasm_object_get_symtab(objfmt_dbg->object), - objfmt_dbg->dbgfile, 1); + yasm_symtab_print(object->symtab, objfmt_dbg->dbgfile, 1); } static void @@ -97,19 +91,18 @@ dbg_objfmt_destroy(yasm_objfmt *objfmt) } static yasm_section * -dbg_objfmt_add_default_section(yasm_objfmt *objfmt) +dbg_objfmt_add_default_section(yasm_object *object) { - yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; yasm_section *retval; int isnew; - retval = yasm_object_get_general(objfmt_dbg->object, ".text", + retval = yasm_object_get_general(object, ".text", yasm_expr_create_ident(yasm_expr_int(yasm_intnum_create_uint(200)), 0), 0, 0, 0, &isnew, 0); if (isnew) { fprintf(objfmt_dbg->dbgfile, "(new) "); - yasm_symtab_define_label( - yasm_object_get_symtab(objfmt_dbg->object), ".text", + yasm_symtab_define_label(object->symtab, ".text", yasm_section_bcs_first(retval), 1, 0); yasm_section_set_default(retval, 1); } @@ -117,12 +110,12 @@ dbg_objfmt_add_default_section(yasm_objfmt *objfmt) } static /*@observer@*/ /*@null@*/ yasm_section * -dbg_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, +dbg_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; yasm_valparam *vp; yasm_section *retval; int isnew; @@ -134,13 +127,12 @@ dbg_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, fprintf(objfmt_dbg->dbgfile, ", %lu), returning ", line); if ((vp = yasm_vps_first(valparams)) && !vp->param && vp->val != NULL) { - retval = yasm_object_get_general(objfmt_dbg->object, vp->val, + retval = yasm_object_get_general(object, vp->val, yasm_expr_create_ident(yasm_expr_int(yasm_intnum_create_uint(200)), line), 0, 0, 0, &isnew, line); if (isnew) { fprintf(objfmt_dbg->dbgfile, "(new) "); - yasm_symtab_define_label( - yasm_object_get_symtab(objfmt_dbg->object), vp->val, + yasm_symtab_define_label(object->symtab, vp->val, yasm_section_bcs_first(retval), 1, line); } yasm_section_set_default(retval, 0); @@ -153,47 +145,47 @@ dbg_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, } static yasm_symrec * -dbg_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, +dbg_objfmt_extern_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; yasm_symrec *sym; fprintf(objfmt_dbg->dbgfile, "extern_declare(\"%s\", ", name); yasm_vps_print(objext_valparams, objfmt_dbg->dbgfile); fprintf(objfmt_dbg->dbgfile, ", %lu), returning sym\n", line); - sym = yasm_symtab_declare(objfmt_dbg->symtab, name, YASM_SYM_EXTERN, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_EXTERN, line); return sym; } static yasm_symrec * -dbg_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, +dbg_objfmt_global_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; yasm_symrec *sym; fprintf(objfmt_dbg->dbgfile, "global_declare(\"%s\", ", name); yasm_vps_print(objext_valparams, objfmt_dbg->dbgfile); fprintf(objfmt_dbg->dbgfile, ", %lu), returning sym\n", line); - sym = yasm_symtab_declare(objfmt_dbg->symtab, name, YASM_SYM_GLOBAL, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_GLOBAL, line); return sym; } static yasm_symrec * -dbg_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, +dbg_objfmt_common_declare(yasm_object *object, const char *name, /*@only@*/ yasm_expr *size, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; yasm_symrec *sym; assert(objfmt_dbg->dbgfile != NULL); @@ -205,17 +197,17 @@ dbg_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, yasm_expr_destroy(size); - sym = yasm_symtab_declare(objfmt_dbg->symtab, name, YASM_SYM_COMMON, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_COMMON, line); return sym; } static int -dbg_objfmt_directive(yasm_objfmt *objfmt, const char *name, +dbg_objfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; fprintf(objfmt_dbg->dbgfile, "directive(\"%s\", ", name); yasm_vps_print(valparams, objfmt_dbg->dbgfile); fprintf(objfmt_dbg->dbgfile, ", "); diff --git a/modules/objfmts/elf/elf-objfmt.c b/modules/objfmts/elf/elf-objfmt.c index d239f057..19dc5996 100644 --- a/modules/objfmts/elf/elf-objfmt.c +++ b/modules/objfmts/elf/elf-objfmt.c @@ -59,10 +59,6 @@ typedef struct yasm_objfmt_elf { elf_strtab_head* shstrtab; /* section name strtab */ elf_strtab_head* strtab; /* strtab entries */ - yasm_object *object; - yasm_symtab *symtab; - /*@dependent@*/ yasm_arch *arch; - elf_strtab_entry *file_strtab_entry;/* .file symbol associated string */ yasm_symrec *dotdotsym; /* ..sym symbol */ } yasm_objfmt_elf; @@ -164,8 +160,8 @@ elf_objfmt_append_local_sym(yasm_symrec *sym, /*@null@*/ void *d) } static yasm_objfmt * -elf_objfmt_create_common(yasm_object *object, yasm_arch *a, - yasm_objfmt_module *module, int bits_pref, +elf_objfmt_create_common(yasm_object *object, yasm_objfmt_module *module, + int bits_pref, const elf_machine_handler **elf_march_out) { yasm_objfmt_elf *objfmt_elf = yasm_xmalloc(sizeof(yasm_objfmt_elf)); @@ -174,10 +170,7 @@ elf_objfmt_create_common(yasm_object *object, yasm_arch *a, const elf_machine_handler *elf_march; objfmt_elf->objfmt.module = module; - objfmt_elf->object = object; - objfmt_elf->symtab = yasm_object_get_symtab(object); - objfmt_elf->arch = a; - elf_march = elf_set_arch(a, objfmt_elf->symtab, bits_pref); + elf_march = elf_set_arch(object->arch, object->symtab, bits_pref); if (!elf_march) { yasm_xfree(objfmt_elf); return NULL; @@ -190,12 +183,10 @@ elf_objfmt_create_common(yasm_object *object, yasm_arch *a, objfmt_elf->elf_symtab = elf_symtab_create(); /* FIXME: misuse of NULL bytecode here; it works, but only barely. */ - filesym = yasm_symtab_define_label(objfmt_elf->symtab, ".file", NULL, 0, - 0); + filesym = yasm_symtab_define_label(object->symtab, ".file", NULL, 0, 0); /* Put in current input filename; we'll replace it in output() */ objfmt_elf->file_strtab_entry = - elf_strtab_append_str(objfmt_elf->strtab, - yasm_object_get_source_fn(object)); + elf_strtab_append_str(objfmt_elf->strtab, object->src_filename); entry = elf_symtab_entry_create(objfmt_elf->file_strtab_entry, filesym); yasm_symrec_add_data(filesym, &elf_symrec_data, entry); elf_symtab_set_nonzero(entry, NULL, SHN_ABS, STB_LOCAL, STT_FILE, NULL, @@ -203,20 +194,20 @@ elf_objfmt_create_common(yasm_object *object, yasm_arch *a, elf_symtab_append_entry(objfmt_elf->elf_symtab, entry); /* FIXME: misuse of NULL bytecode */ - objfmt_elf->dotdotsym = yasm_symtab_define_label(objfmt_elf->symtab, - "..sym", NULL, 1, 0); + objfmt_elf->dotdotsym = + yasm_symtab_define_label(object->symtab, "..sym", NULL, 1, 0); return (yasm_objfmt *)objfmt_elf; } static yasm_objfmt * -elf_objfmt_create(yasm_object *object, yasm_arch *a) +elf_objfmt_create(yasm_object *object) { const elf_machine_handler *elf_march; yasm_objfmt *objfmt; yasm_objfmt_elf *objfmt_elf; - objfmt = elf_objfmt_create_common(object, a, &yasm_elf_LTX_objfmt, 0, + objfmt = elf_objfmt_create_common(object, &yasm_elf_LTX_objfmt, 0, &elf_march); if (objfmt) { objfmt_elf = (yasm_objfmt_elf *)objfmt; @@ -230,17 +221,15 @@ elf_objfmt_create(yasm_object *object, yasm_arch *a) } static yasm_objfmt * -elf32_objfmt_create(yasm_object *object, yasm_arch *a) +elf32_objfmt_create(yasm_object *object) { - return elf_objfmt_create_common(object, a, &yasm_elf32_LTX_objfmt, 32, - NULL); + return elf_objfmt_create_common(object, &yasm_elf32_LTX_objfmt, 32, NULL); } static yasm_objfmt * -elf64_objfmt_create(yasm_object *object, yasm_arch *a) +elf64_objfmt_create(yasm_object *object) { - return elf_objfmt_create_common(object, a, &yasm_elf64_LTX_objfmt, 64, - NULL); + return elf_objfmt_create_common(object, &yasm_elf64_LTX_objfmt, 64, NULL); } static long @@ -290,8 +279,8 @@ elf_objfmt_output_reloc(yasm_symrec *sym, yasm_bytecode *bc, zero = yasm_intnum_create_uint(0); elf_handle_reloc_addend(zero, reloc); - retval = yasm_arch_intnum_tobytes(info->objfmt_elf->arch, zero, buf, - destsize, valsize, 0, bc, warn); + retval = yasm_arch_intnum_tobytes(info->object->arch, zero, buf, destsize, + valsize, 0, bc, warn); yasm_intnum_destroy(zero); return retval; } @@ -319,7 +308,7 @@ elf_objfmt_output_value(yasm_value *value, unsigned char *buf, * cross-section, or non-PC-relative reference (those are handled below). */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_elf->arch)) { + info->object->arch)) { case -1: return 1; case 0: @@ -397,8 +386,8 @@ elf_objfmt_output_value(yasm_value *value, unsigned char *buf, if (reloc) elf_handle_reloc_addend(intn, reloc); - retval = yasm_arch_intnum_tobytes(info->objfmt_elf->arch, intn, buf, - destsize, valsize, 0, bc, warn); + retval = yasm_arch_intnum_tobytes(info->object->arch, intn, buf, destsize, + valsize, 0, bc, warn); yasm_intnum_destroy(intn); return retval; } @@ -485,9 +474,8 @@ elf_objfmt_create_dbg_secthead(yasm_section *sect, /*@null@*/ void *d) shead = elf_secthead_create(name, type, 0, 0, 0); elf_secthead_set_entsize(shead, entsize); - sym = yasm_symtab_define_label( - yasm_object_get_symtab(info->objfmt_elf->object), sectname, - yasm_section_bcs_first(sect), 1, 0); + sym = yasm_symtab_define_label(info->object->symtab, sectname, + yasm_section_bcs_first(sect), 1, 0); elf_secthead_set_sym(shead, sym); yasm_section_add_data(sect, &elf_section_data, shead); @@ -595,10 +583,10 @@ elf_objfmt_output_secthead(yasm_section *sect, /*@null@*/ void *d) } static void -elf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, +elf_objfmt_output(yasm_object *object, FILE *f, int all_syms, yasm_errwarns *errwarns) { - yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; + yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; elf_objfmt_output_info info; append_local_sym_info localsym_info; long pos; @@ -609,13 +597,14 @@ elf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, elf_strtab_entry *elf_strtab_name, *elf_shstrtab_name, *elf_symtab_name; unsigned long elf_symtab_nlocal; + info.object = object; info.objfmt_elf = objfmt_elf; info.errwarns = errwarns; info.f = f; /* Update filename strtab */ elf_strtab_entry_set_str(objfmt_elf->file_strtab_entry, - yasm_object_get_source_fn(objfmt_elf->object)); + object->src_filename); /* Allocate space for Ehdr by seeking forward */ if (fseek(f, (long)(elf_proghead_get_size()), SEEK_SET) < 0) { @@ -626,21 +615,21 @@ elf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, /* Create missing section headers */ localsym_info.objfmt_elf = objfmt_elf; - if (yasm_object_sections_traverse(objfmt_elf->object, &info, + if (yasm_object_sections_traverse(object, &info, elf_objfmt_create_dbg_secthead)) return; /* add all (local) syms to symtab because relocation needs a symtab index * if all_syms, register them by name. if not, use strtab entry 0 */ localsym_info.local_names = all_syms; - yasm_symtab_traverse(yasm_object_get_symtab(objfmt_elf->object), - &localsym_info, elf_objfmt_append_local_sym); + yasm_symtab_traverse(object->symtab, &localsym_info, + elf_objfmt_append_local_sym); elf_symtab_nlocal = elf_symtab_assign_indices(objfmt_elf->elf_symtab); /* output known sections - includes reloc sections which aren't in yasm's * list. Assign indices as we go. */ info.sindex = 3; - if (yasm_object_sections_traverse(objfmt_elf->object, &info, + if (yasm_object_sections_traverse(object, &info, elf_objfmt_output_section)) return; @@ -683,11 +672,10 @@ elf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, elf_shead_addr = (unsigned long) pos; /* stabs debugging support */ - if (strcmp(yasm_dbgfmt_keyword(df), "stabs")==0) { - yasm_section *stabsect = yasm_object_find_general(objfmt_elf->object, - ".stab"); + if (strcmp(yasm_dbgfmt_keyword(object->dbgfmt), "stabs")==0) { + yasm_section *stabsect = yasm_object_find_general(object, ".stab"); yasm_section *stabstrsect = - yasm_object_find_general(objfmt_elf->object, ".stabstr"); + yasm_object_find_general(object, ".stabstr"); if (stabsect && stabstrsect) { elf_secthead *stab = yasm_section_get_data(stabsect, &elf_section_data); @@ -731,8 +719,7 @@ elf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df, info.sindex = 3; /* output remaining section headers */ - yasm_object_sections_traverse(objfmt_elf->object, &info, - elf_objfmt_output_secthead); + yasm_object_sections_traverse(object, &info, elf_objfmt_output_secthead); /* output Ehdr */ if (fseek(f, 0, SEEK_SET) < 0) { @@ -755,10 +742,11 @@ elf_objfmt_destroy(yasm_objfmt *objfmt) } static elf_secthead * -elf_objfmt_init_new_section(yasm_objfmt_elf *objfmt_elf, yasm_section *sect, +elf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, const char *sectname, unsigned long type, unsigned long flags, unsigned long line) { + yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; elf_secthead *esd; yasm_symrec *sym; elf_strtab_entry *name = elf_strtab_append_str(objfmt_elf->shstrtab, @@ -766,9 +754,8 @@ elf_objfmt_init_new_section(yasm_objfmt_elf *objfmt_elf, yasm_section *sect, esd = elf_secthead_create(name, type, flags, 0, 0); yasm_section_add_data(sect, &elf_section_data, esd); - sym = yasm_symtab_define_label( - yasm_object_get_symtab(objfmt_elf->object), sectname, - yasm_section_bcs_first(sect), 1, line); + sym = yasm_symtab_define_label(object->symtab, sectname, + yasm_section_bcs_first(sect), 1, line); elf_secthead_set_sym(esd, sym); @@ -776,27 +763,24 @@ elf_objfmt_init_new_section(yasm_objfmt_elf *objfmt_elf, yasm_section *sect, } static yasm_section * -elf_objfmt_add_default_section(yasm_objfmt *objfmt) +elf_objfmt_add_default_section(yasm_object *object) { - yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; yasm_section *retval; int isnew; elf_secthead *esd; - retval = yasm_object_get_general(objfmt_elf->object, ".text", 0, 16, 1, 0, - &isnew, 0); - esd = elf_objfmt_init_new_section(objfmt_elf, retval, ".text", SHT_PROGBITS, + retval = yasm_object_get_general(object, ".text", 0, 16, 1, 0, &isnew, 0); + esd = elf_objfmt_init_new_section(object, retval, ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0); yasm_section_set_default(retval, 1); return retval; } static /*@observer@*/ /*@null@*/ yasm_section * -elf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, +elf_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; yasm_valparam *vp = yasm_vps_first(valparams); yasm_section *retval; int isnew; @@ -953,12 +937,12 @@ elf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, } } - retval = yasm_object_get_general(objfmt_elf->object, sectname, 0, align, + retval = yasm_object_get_general(object, sectname, 0, align, (flags & SHF_EXECINSTR) != 0, resonly, &isnew, line); if (isnew) - esd = elf_objfmt_init_new_section(objfmt_elf, retval, sectname, type, + esd = elf_objfmt_init_new_section(object, retval, sectname, type, flags, line); else esd = yasm_section_get_data(retval, &elf_section_data); @@ -976,14 +960,14 @@ elf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, } static yasm_symrec * -elf_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ +elf_objfmt_extern_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; + yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; yasm_symrec *sym; - sym = yasm_symtab_declare(objfmt_elf->symtab, name, YASM_SYM_EXTERN, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_EXTERN, line); elf_objfmt_symtab_append(objfmt_elf, sym, SHN_UNDEF, STB_GLOBAL, 0, STV_DEFAULT, NULL, NULL); @@ -1000,18 +984,18 @@ elf_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ } static yasm_symrec * -elf_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, +elf_objfmt_global_declare(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; + yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; yasm_symrec *sym; elf_symbol_type type = 0; yasm_expr *size = NULL; elf_symbol_vis vis = STV_DEFAULT; unsigned int vis_overrides = 0; - sym = yasm_symtab_declare(objfmt_elf->symtab, name, YASM_SYM_GLOBAL, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_GLOBAL, line); if (objext_valparams) { yasm_valparam *vp = yasm_vps_first(objext_valparams); @@ -1058,16 +1042,16 @@ elf_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, } static yasm_symrec * -elf_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, +elf_objfmt_common_declare(yasm_object *object, const char *name, /*@only@*/ yasm_expr *size, /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; + yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; yasm_symrec *sym; unsigned long addralign = 0; - sym = yasm_symtab_declare(objfmt_elf->symtab, name, YASM_SYM_COMMON, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_COMMON, line); if (objext_valparams) { yasm_valparam *vp = yasm_vps_first(objext_valparams); @@ -1102,11 +1086,12 @@ elf_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, } static void -dir_type(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) +dir_type(yasm_object *object, yasm_valparam *vp, unsigned long line) { + yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; char *symname = vp->val; /* Get symbol elf data */ - yasm_symrec *sym = yasm_symtab_use(objfmt_elf->symtab, symname, line); + yasm_symrec *sym = yasm_symtab_use(object->symtab, symname, line); elf_symtab_entry *entry = yasm_symrec_get_data(sym, &elf_symrec_data); /* Create entry if necessary */ @@ -1131,11 +1116,12 @@ dir_type(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) } static void -dir_size(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) +dir_size(yasm_object *object, yasm_valparam *vp, unsigned long line) { + yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; char *symname = vp->val; /* Get symbol elf data */ - yasm_symrec *sym = yasm_symtab_use(objfmt_elf->symtab, symname, line); + yasm_symrec *sym = yasm_symtab_use(object->symtab, symname, line); elf_symtab_entry *entry = yasm_symrec_get_data(sym, &elf_symrec_data); /* Create entry if necessary */ @@ -1152,25 +1138,25 @@ dir_size(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) vp->param = NULL; } else if (vp && vp->val) elf_sym_set_size(entry, yasm_expr_create_ident(yasm_expr_sym( - yasm_symtab_use(objfmt_elf->symtab, vp->val, line)), line)); + yasm_symtab_use(object->symtab, vp->val, line)), line)); else yasm_error_set(YASM_ERROR_SYNTAX, N_("no size specified")); } static void -dir_weak(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) +dir_weak(yasm_object *object, yasm_valparam *vp, unsigned long line) { + yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; char *symname = vp->val; - yasm_symrec *sym = yasm_symtab_declare(objfmt_elf->symtab, symname, + yasm_symrec *sym = yasm_symtab_declare(object->symtab, symname, YASM_SYM_GLOBAL, line); elf_objfmt_symtab_append(objfmt_elf, sym, SHN_UNDEF, STB_WEAK, 0, STV_DEFAULT, NULL, NULL); } static void -dir_ident(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) +dir_ident(yasm_object *object, yasm_valparam *vp, unsigned long line) { - char *symname = vp->val; yasm_valparamhead sect_vps; yasm_datavalhead dvs; yasm_section *comment; @@ -1180,8 +1166,7 @@ dir_ident(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) yasm_vps_initialize(§_vps); vp2 = yasm_vp_create(yasm__xstrdup(".comment"), NULL); yasm_vps_append(§_vps, vp2); - comment = elf_objfmt_section_switch((yasm_objfmt *)objfmt_elf, §_vps, - NULL, line); + comment = elf_objfmt_section_switch(object, §_vps, NULL, line); yasm_vps_delete(§_vps); /* To match GAS output, if the comment section is empty, put an @@ -1193,7 +1178,7 @@ dir_ident(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) yasm_expr_create_ident( yasm_expr_int(yasm_intnum_create_uint(0)), line))); yasm_section_bcs_append(comment, - yasm_bc_create_data(&dvs, 1, 0, objfmt_elf->arch, line)); + yasm_bc_create_data(&dvs, 1, 0, object->arch, line)); } yasm_dvs_initialize(&dvs); @@ -1203,20 +1188,19 @@ dir_ident(yasm_objfmt_elf *objfmt_elf, yasm_valparam *vp, unsigned long line) } while ((vp = yasm_vps_next(vp))); yasm_section_bcs_append(comment, - yasm_bc_create_data(&dvs, 1, 1, objfmt_elf->arch, line)); + yasm_bc_create_data(&dvs, 1, 1, object->arch, line)); } static int -elf_objfmt_directive(yasm_objfmt *objfmt, const char *name, +elf_objfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; static const struct { const char *name; - void (*func) (yasm_objfmt_elf *, yasm_valparam *, unsigned long); + void (*func) (yasm_object *, yasm_valparam *, unsigned long); } dirs[] = { {"TYPE", dir_type}, {"SIZE", dir_size}, @@ -1233,7 +1217,7 @@ elf_objfmt_directive(yasm_objfmt *objfmt, const char *name, N_("Symbol name not specified")); return 0; } - dirs[i].func(objfmt_elf, vp, line); + dirs[i].func(object, vp, line); return 0; } } diff --git a/modules/objfmts/macho/macho-objfmt.c b/modules/objfmts/macho/macho-objfmt.c index 68db6adb..ac7eacce 100644 --- a/modules/objfmts/macho/macho-objfmt.c +++ b/modules/objfmts/macho/macho-objfmt.c @@ -306,14 +306,11 @@ typedef struct yasm_objfmt_macho { long parse_scnum; /* sect numbering in parser */ int bits; /* 32 / 64 */ - - yasm_object *object; - yasm_symtab *symtab; - /*@dependent@ */ yasm_arch *arch; } yasm_objfmt_macho; typedef struct macho_objfmt_output_info { + yasm_object *object; yasm_objfmt_macho *objfmt_macho; yasm_errwarns *errwarns; /*@dependent@ */ FILE *f; @@ -360,27 +357,25 @@ yasm_objfmt_module yasm_macho32_LTX_objfmt; yasm_objfmt_module yasm_macho64_LTX_objfmt; static yasm_objfmt * -macho_objfmt_create_common(yasm_object *object, yasm_arch *a, - yasm_objfmt_module *module, int bits_pref) +macho_objfmt_create_common(yasm_object *object, yasm_objfmt_module *module, + int bits_pref) { yasm_objfmt_macho *objfmt_macho = yasm_xmalloc(sizeof(yasm_objfmt_macho)); objfmt_macho->objfmt.module = module; - objfmt_macho->object = object; - objfmt_macho->symtab = yasm_object_get_symtab(object); - objfmt_macho->arch = a; /* Only support x86 arch for now */ - if (yasm__strcasecmp(yasm_arch_keyword(a), "x86") != 0) { + if (yasm__strcasecmp(yasm_arch_keyword(object->arch), "x86") != 0) { yasm_xfree(objfmt_macho); return NULL; } /* Support x86 and amd64 machines of x86 arch */ - if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0 && + if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), "x86") == 0 && (bits_pref == 0 || bits_pref == 32)) objfmt_macho->bits = 32; - else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0 && + else if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), + "amd64") == 0 && (bits_pref == 0 || bits_pref == 64)) objfmt_macho->bits = 64; else { @@ -393,12 +388,12 @@ macho_objfmt_create_common(yasm_object *object, yasm_arch *a, } static yasm_objfmt * -macho_objfmt_create(yasm_object *object, yasm_arch *a) +macho_objfmt_create(yasm_object *object) { yasm_objfmt *objfmt; yasm_objfmt_macho *objfmt_macho; - objfmt = macho_objfmt_create_common(object, a, &yasm_macho_LTX_objfmt, 0); + objfmt = macho_objfmt_create_common(object, &yasm_macho_LTX_objfmt, 0); if (objfmt) { objfmt_macho = (yasm_objfmt_macho *)objfmt; /* Figure out which bitness of object format to use */ @@ -411,15 +406,15 @@ macho_objfmt_create(yasm_object *object, yasm_arch *a) } static yasm_objfmt * -macho32_objfmt_create(yasm_object *object, yasm_arch *a) +macho32_objfmt_create(yasm_object *object) { - return macho_objfmt_create_common(object, a, &yasm_macho32_LTX_objfmt, 32); + return macho_objfmt_create_common(object, &yasm_macho32_LTX_objfmt, 32); } static yasm_objfmt * -macho64_objfmt_create(yasm_object *object, yasm_arch *a) +macho64_objfmt_create(yasm_object *object) { - return macho_objfmt_create_common(object, a, &yasm_macho64_LTX_objfmt, 64); + return macho_objfmt_create_common(object, &yasm_macho64_LTX_objfmt, 64); } static int @@ -446,7 +441,7 @@ macho_objfmt_output_value(yasm_value *value, unsigned char *buf, * cross-section, or non-PC-relative reference (those are handled below). */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_macho->arch)) { + info->object->arch)) { case -1: return 1; case 0: @@ -580,7 +575,7 @@ macho_objfmt_output_value(yasm_value *value, unsigned char *buf, yasm_intnum_calc(intn, YASM_EXPR_ADD, intn2); } - retval = yasm_arch_intnum_tobytes(objfmt_macho->arch, intn, buf, destsize, + retval = yasm_arch_intnum_tobytes(info->object->arch, intn, buf, destsize, valsize, 0, bc, warn); /*printf("val %ld\n",yasm_intnum_get_int(intn));*/ yasm_intnum_destroy(intn); @@ -1046,10 +1041,10 @@ macho_objfmt_calc_sectsize(yasm_section *sect, /*@null@ */ void *d) /* write object */ static void -macho_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, - /*@unused@*/ yasm_dbgfmt *df, yasm_errwarns *errwarns) +macho_objfmt_output(yasm_object *object, FILE *f, int all_syms, + yasm_errwarns *errwarns) { - yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *) objfmt; + yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *)object->objfmt; macho_objfmt_output_info info; unsigned char *localbuf; unsigned long symtab_count = 0; @@ -1062,6 +1057,7 @@ macho_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, unsigned long long_int_bytes; const char pad_data[3] = "\0\0\0"; + info.object = object; info.objfmt_macho = objfmt_macho; info.errwarns = errwarns; info.f = f; @@ -1110,7 +1106,7 @@ macho_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, info.strlength = 1; /* string table starts with a zero byte */ info.all_syms = all_syms || info.is_64; /*info.all_syms = 1; * force all syms into symbol table */ - yasm_symtab_traverse(objfmt_macho->symtab, &info, macho_objfmt_count_sym); + yasm_symtab_traverse(object->symtab, &info, macho_objfmt_count_sym); symtab_count = info.indx; /* write raw section data first */ @@ -1126,12 +1122,10 @@ macho_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, info.vmsize = 0; info.filesize = 0; info.offset = headsize; - yasm_object_sections_traverse(objfmt_macho->object, &info, - macho_objfmt_calc_sectsize); + yasm_object_sections_traverse(object, &info, macho_objfmt_calc_sectsize); /* output sections to file */ - yasm_object_sections_traverse(objfmt_macho->object, &info, - macho_objfmt_output_section); + yasm_object_sections_traverse(object, &info, macho_objfmt_output_section); fileoff_sections = ftell(f); @@ -1227,8 +1221,7 @@ macho_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, /* offset to relocs for first section */ info.rel_base = align32((long)fileoffset + (long)info.filesize); info.s_reloff = 0; /* offset for relocs of following sections */ - yasm_object_sections_traverse(objfmt_macho->object, &info, - macho_objfmt_output_secthead); + yasm_object_sections_traverse(object, &info, macho_objfmt_output_secthead); localbuf = info.buf; /* write out symbol command */ @@ -1260,25 +1253,16 @@ macho_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, } /* relocation data */ - yasm_object_sections_traverse(objfmt_macho->object, &info, - macho_objfmt_output_relocs); + yasm_object_sections_traverse(object, &info, macho_objfmt_output_relocs); /* symbol table (NLIST) */ info.indx = 1; /* restart symbol table indices */ - yasm_symtab_traverse(objfmt_macho->symtab, &info, - macho_objfmt_output_symtable); + yasm_symtab_traverse(object->symtab, &info, macho_objfmt_output_symtable); /* symbol strings */ fwrite(pad_data, 1, 1, f); - yasm_symtab_traverse(objfmt_macho->symtab, &info, - macho_objfmt_output_str); -#if 0 - /* relocation fixup: set internal symbol locations into byte code within - * file. - */ - yasm_object_sections_traverse(objfmt_macho->object, &info, - macho_objfmt_fixup_relocs); -#endif + yasm_symtab_traverse(object->symtab, &info, macho_objfmt_output_str); + yasm_intnum_destroy(val); yasm_xfree(info.buf); } @@ -1290,10 +1274,10 @@ macho_objfmt_destroy(yasm_objfmt *objfmt) } static macho_section_data * -macho_objfmt_init_new_section(yasm_objfmt_macho * objfmt_macho, - yasm_section *sect, const char *sectname, - unsigned long line) +macho_objfmt_init_new_section(yasm_object *object, yasm_section *sect, + const char *sectname, unsigned long line) { + yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *)object->objfmt; macho_section_data *data; yasm_symrec *sym; @@ -1307,25 +1291,22 @@ macho_objfmt_init_new_section(yasm_objfmt_macho * objfmt_macho, data->offset = 0; yasm_section_add_data(sect, &macho_section_data_cb, data); - sym = yasm_symtab_define_label(objfmt_macho->symtab, sectname, + sym = yasm_symtab_define_label(object->symtab, sectname, yasm_section_bcs_first(sect), 1, line); data->sym = sym; return data; } static yasm_section * -macho_objfmt_add_default_section(yasm_objfmt *objfmt) +macho_objfmt_add_default_section(yasm_object *object) { - yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *) objfmt; yasm_section *retval; macho_section_data *msd; int isnew; - retval = - yasm_object_get_general(objfmt_macho->object, ".text", 0, 0, 1, 0, - &isnew, 0); + retval = yasm_object_get_general(object, ".text", 0, 0, 1, 0, &isnew, 0); if (isnew) { - msd = macho_objfmt_init_new_section(objfmt_macho, retval, ".text", 0); + msd = macho_objfmt_init_new_section(object, retval, ".text", 0); msd->segname = "__TEXT"; msd->sectname = "__text"; msd->flags = S_ATTR_PURE_INSTRUCTIONS; @@ -1336,12 +1317,11 @@ macho_objfmt_add_default_section(yasm_objfmt *objfmt) } static /*@observer@*/ /*@null@*/ yasm_section * -macho_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, +macho_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *) objfmt; yasm_valparam *vp = yasm_vps_first(valparams); yasm_section *retval; int isnew; @@ -1480,13 +1460,11 @@ macho_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, N_("Unrecognized qualifier `%s'"), vp->val); } - retval = - yasm_object_get_general(objfmt_macho->object, sectname, 0, align, 1, - resonly, &isnew, line); + retval = yasm_object_get_general(object, sectname, 0, align, 1, resonly, + &isnew, line); if (isnew) - msd = macho_objfmt_init_new_section(objfmt_macho, retval, sectname, - line); + msd = macho_objfmt_init_new_section(object, retval, sectname, line); else msd = yasm_section_get_data(retval, &macho_section_data_cb); @@ -1523,40 +1501,32 @@ macho_section_data_print(void *data, FILE *f, int indent_level) } static yasm_symrec * -macho_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ +macho_objfmt_extern_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *)objfmt; - - return yasm_symtab_declare(objfmt_macho->symtab, name, YASM_SYM_EXTERN, - line); + return yasm_symtab_declare(object->symtab, name, YASM_SYM_EXTERN, line); } static yasm_symrec * -macho_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ +macho_objfmt_global_declare(yasm_object *object, const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *)objfmt; - - return yasm_symtab_declare(objfmt_macho->symtab, name, YASM_SYM_GLOBAL, - line); + return yasm_symtab_declare(object->symtab, name, YASM_SYM_GLOBAL, line); } static yasm_symrec * -macho_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, +macho_objfmt_common_declare(yasm_object *object, const char *name, /*@only@*/ yasm_expr *size, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *)objfmt; yasm_symrec *sym; macho_symrec_data *sym_data; - sym = yasm_symtab_declare(objfmt_macho->symtab, name, YASM_SYM_COMMON, - line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_COMMON, line); sym_data = yasm_xmalloc(sizeof(macho_symrec_data)); @@ -1596,7 +1566,7 @@ macho_symrec_data_print(void *data, FILE *f, int indent_level) static int -macho_objfmt_directive(/*@unused@*/ yasm_objfmt *objfmt, +macho_objfmt_directive(/*@unused@*/ yasm_object *object, /*@unused@*/ const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ diff --git a/modules/objfmts/rdf/rdf-objfmt.c b/modules/objfmts/rdf/rdf-objfmt.c index 7ff400bf..5d7eace7 100644 --- a/modules/objfmts/rdf/rdf-objfmt.c +++ b/modules/objfmts/rdf/rdf-objfmt.c @@ -118,15 +118,12 @@ typedef struct yasm_objfmt_rdf { long parse_scnum; /* sect numbering in parser */ - yasm_object *object; - yasm_symtab *symtab; - /*@dependent@*/ yasm_arch *arch; - /*@owned@*/ xdf_str_head module_names; /*@owned@*/ xdf_str_head library_names; } yasm_objfmt_rdf; typedef struct rdf_objfmt_output_info { + yasm_object *object; yasm_objfmt_rdf *objfmt_rdf; yasm_errwarns *errwarns; /*@dependent@*/ FILE *f; @@ -175,14 +172,10 @@ rdf_objfmt_sym_set_data(yasm_symrec *sym, } static yasm_objfmt * -rdf_objfmt_create(yasm_object *object, yasm_arch *a) +rdf_objfmt_create(yasm_object *object) { yasm_objfmt_rdf *objfmt_rdf = yasm_xmalloc(sizeof(yasm_objfmt_rdf)); - objfmt_rdf->object = object; - objfmt_rdf->symtab = yasm_object_get_symtab(object); - objfmt_rdf->arch = a; - /* We theoretically support all arches, so don't check. * Really we only support byte-addressable ones. */ @@ -221,7 +214,7 @@ rdf_objfmt_output_value(yasm_value *value, unsigned char *buf, * cross-section, or non-PC-relative reference (those are handled below). */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_rdf->arch)) { + info->object->arch)) { case -1: return 1; case 0: @@ -308,7 +301,7 @@ rdf_objfmt_output_value(yasm_value *value, unsigned char *buf, yasm_intnum_calc(intn, YASM_EXPR_ADD, intn2); } - retval = yasm_arch_intnum_tobytes(objfmt_rdf->arch, intn, buf, destsize, + retval = yasm_arch_intnum_tobytes(info->object->arch, intn, buf, destsize, valsize, 0, bc, warn); yasm_intnum_destroy(intn); return retval; @@ -612,16 +605,17 @@ rdf_objfmt_output_sym(yasm_symrec *sym, /*@null@*/ void *d) } static void -rdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, - /*@unused@*/ yasm_dbgfmt *df, yasm_errwarns *errwarns) +rdf_objfmt_output(yasm_object *object, FILE *f, int all_syms, + yasm_errwarns *errwarns) { - yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)objfmt; + yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)object->objfmt; rdf_objfmt_output_info info; unsigned char *localbuf; long headerlen, filelen; xdf_str *cur; size_t len; + info.object = object; info.objfmt_rdf = objfmt_rdf; info.errwarns = errwarns; info.f = f; @@ -660,7 +654,7 @@ rdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, /* Output symbol table */ info.indx = objfmt_rdf->parse_scnum; - yasm_symtab_traverse(objfmt_rdf->symtab, &info, rdf_objfmt_output_sym); + yasm_symtab_traverse(object->symtab, &info, rdf_objfmt_output_sym); /* UGH! Due to the fact the relocs go at the beginning of the file, and * we only know if we have relocs when we output the sections, we have @@ -674,12 +668,12 @@ rdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, * * We also calculate the total size of all BSS sections here. */ - if (yasm_object_sections_traverse(objfmt_rdf->object, &info, + if (yasm_object_sections_traverse(object, &info, rdf_objfmt_output_section_mem)) return; /* Output all relocs */ - if (yasm_object_sections_traverse(objfmt_rdf->object, &info, + if (yasm_object_sections_traverse(object, &info, rdf_objfmt_output_section_reloc)) return; @@ -701,7 +695,7 @@ rdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, } /* Section data (to file) */ - if (yasm_object_sections_traverse(objfmt_rdf->object, &info, + if (yasm_object_sections_traverse(object, &info, rdf_objfmt_output_section_file)) return; @@ -759,9 +753,10 @@ rdf_objfmt_destroy(yasm_objfmt *objfmt) } static rdf_section_data * -rdf_objfmt_init_new_section(yasm_objfmt_rdf *objfmt_rdf, yasm_section *sect, +rdf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, const char *sectname, unsigned long line) { + yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)object->objfmt; rdf_section_data *data; yasm_symrec *sym; @@ -773,24 +768,22 @@ rdf_objfmt_init_new_section(yasm_objfmt_rdf *objfmt_rdf, yasm_section *sect, data->raw_data = NULL; yasm_section_add_data(sect, &rdf_section_data_cb, data); - sym = yasm_symtab_define_label(objfmt_rdf->symtab, sectname, + sym = yasm_symtab_define_label(object->symtab, sectname, yasm_section_bcs_first(sect), 1, line); data->sym = sym; return data; } static yasm_section * -rdf_objfmt_add_default_section(yasm_objfmt *objfmt) +rdf_objfmt_add_default_section(yasm_object *object) { - yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)objfmt; yasm_section *retval; rdf_section_data *rsd; int isnew; - retval = yasm_object_get_general(objfmt_rdf->object, ".text", 0, 0, 1, 0, - &isnew, 0); + retval = yasm_object_get_general(object, ".text", 0, 0, 1, 0, &isnew, 0); if (isnew) { - rsd = rdf_objfmt_init_new_section(objfmt_rdf, retval, ".text", 0); + rsd = rdf_objfmt_init_new_section(object, retval, ".text", 0); rsd->type = RDF_SECT_CODE; rsd->reserved = 0; yasm_section_set_default(retval, 1); @@ -799,12 +792,11 @@ rdf_objfmt_add_default_section(yasm_objfmt *objfmt) } static /*@observer@*/ /*@null@*/ yasm_section * -rdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, - /*@unused@*/ /*@null@*/ - yasm_valparamhead *objext_valparams, - unsigned long line) +rdf_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, + /*@unused@*/ /*@null@*/ + yasm_valparamhead *objext_valparams, + unsigned long line) { - yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)objfmt; yasm_valparam *vp = yasm_vps_first(valparams); yasm_section *retval; int isnew; @@ -885,11 +877,11 @@ rdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, vp->val); } - retval = yasm_object_get_general(objfmt_rdf->object, sectname, 0, 0, 1, + retval = yasm_object_get_general(object, sectname, 0, 0, 1, type == RDF_SECT_BSS, &isnew, line); if (isnew) - rsd = rdf_objfmt_init_new_section(objfmt_rdf, retval, sectname, line); + rsd = rdf_objfmt_init_new_section(object, retval, sectname, line); else rsd = yasm_section_get_data(retval, &rdf_section_data_cb); @@ -926,11 +918,10 @@ rdf_section_data_print(void *data, FILE *f, int indent_level) } static yasm_symrec * -rdf_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ - /*@null@*/ yasm_valparamhead *objext_valparams, - unsigned long line) +rdf_objfmt_extern_declare(yasm_object *object, const char *name, /*@unused@*/ + /*@null@*/ yasm_valparamhead *objext_valparams, + unsigned long line) { - yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)objfmt; yasm_symrec *sym; unsigned int flags = 0; @@ -946,7 +937,7 @@ rdf_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ { "far", SYM_FAR }, }; - sym = yasm_symtab_declare(objfmt_rdf->symtab, name, YASM_SYM_EXTERN, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_EXTERN, line); if (objext_valparams) { yasm_valparam *vp = yasm_vps_first(objext_valparams); @@ -985,11 +976,10 @@ rdf_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ } static yasm_symrec * -rdf_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ - /*@null@*/ yasm_valparamhead *objext_valparams, - unsigned long line) +rdf_objfmt_global_declare(yasm_object *object, const char *name, /*@unused@*/ + /*@null@*/ yasm_valparamhead *objext_valparams, + unsigned long line) { - yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)objfmt; yasm_symrec *sym; unsigned int flags = 0; @@ -1004,7 +994,7 @@ rdf_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ { "export", SYM_GLOBAL }, }; - sym = yasm_symtab_declare(objfmt_rdf->symtab, name, YASM_SYM_GLOBAL, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_GLOBAL, line); if (objext_valparams) { yasm_valparam *vp = yasm_vps_first(objext_valparams); @@ -1037,16 +1027,15 @@ rdf_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ } static yasm_symrec * -rdf_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, - /*@only@*/ yasm_expr *size, - yasm_valparamhead *objext_valparams, - unsigned long line) +rdf_objfmt_common_declare(yasm_object *object, const char *name, + /*@only@*/ yasm_expr *size, + yasm_valparamhead *objext_valparams, + unsigned long line) { - yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)objfmt; yasm_symrec *sym; unsigned long addralign = 0; - sym = yasm_symtab_declare(objfmt_rdf->symtab, name, YASM_SYM_COMMON, line); + sym = yasm_symtab_declare(object->symtab, name, YASM_SYM_COMMON, line); if (objext_valparams) { yasm_valparam *vp = yasm_vps_first(objext_valparams); @@ -1103,12 +1092,12 @@ rdf_symrec_data_print(void *data, FILE *f, int indent_level) } static int -rdf_objfmt_directive(yasm_objfmt *objfmt, const char *name, +rdf_objfmt_directive(yasm_object *object, const char *name, /*@null@*/ yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line) { - yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)objfmt; + yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)object->objfmt; int lib; yasm_valparam *vp; xdf_str *str; diff --git a/modules/objfmts/xdf/xdf-objfmt.c b/modules/objfmts/xdf/xdf-objfmt.c index 5251d525..9e852216 100644 --- a/modules/objfmts/xdf/xdf-objfmt.c +++ b/modules/objfmts/xdf/xdf-objfmt.c @@ -87,13 +87,10 @@ typedef struct yasm_objfmt_xdf { yasm_objfmt_base objfmt; /* base structure */ long parse_scnum; /* sect numbering in parser */ - - yasm_object *object; - yasm_symtab *symtab; - /*@dependent@*/ yasm_arch *arch; } yasm_objfmt_xdf; typedef struct xdf_objfmt_output_info { + yasm_object *object; yasm_objfmt_xdf *objfmt_xdf; yasm_errwarns *errwarns; /*@dependent@*/ FILE *f; @@ -126,23 +123,19 @@ yasm_objfmt_module yasm_xdf_LTX_objfmt; static yasm_objfmt * -xdf_objfmt_create(yasm_object *object, yasm_arch *a) +xdf_objfmt_create(yasm_object *object) { yasm_objfmt_xdf *objfmt_xdf = yasm_xmalloc(sizeof(yasm_objfmt_xdf)); - objfmt_xdf->object = object; - objfmt_xdf->symtab = yasm_object_get_symtab(object); - objfmt_xdf->arch = a; - /* Only support x86 arch */ - if (yasm__strcasecmp(yasm_arch_keyword(a), "x86") != 0) { + if (yasm__strcasecmp(yasm_arch_keyword(object->arch), "x86") != 0) { yasm_xfree(objfmt_xdf); return NULL; } /* Support x86 and amd64 machines of x86 arch */ - if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") && - yasm__strcasecmp(yasm_arch_get_machine(a), "amd64")) { + if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), "x86") && + yasm__strcasecmp(yasm_arch_get_machine(object->arch), "amd64")) { yasm_xfree(objfmt_xdf); return NULL; } @@ -177,7 +170,7 @@ xdf_objfmt_output_value(yasm_value *value, unsigned char *buf, * cross-section, or non-PC-relative reference (those are handled below). */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_xdf->arch)) { + info->object->arch)) { case -1: return 1; case 0: @@ -237,7 +230,7 @@ xdf_objfmt_output_value(yasm_value *value, unsigned char *buf, yasm_intnum_calc(intn, YASM_EXPR_ADD, intn2); } - retval = yasm_arch_intnum_tobytes(objfmt_xdf->arch, intn, buf, destsize, + retval = yasm_arch_intnum_tobytes(info->object->arch, intn, buf, destsize, valsize, 0, bc, warn); yasm_intnum_destroy(intn); return retval; @@ -560,14 +553,15 @@ xdf_objfmt_output_str(yasm_symrec *sym, /*@null@*/ void *d) } static void -xdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, - /*@unused@*/ yasm_dbgfmt *df, yasm_errwarns *errwarns) +xdf_objfmt_output(yasm_object *object, FILE *f, int all_syms, + yasm_errwarns *errwarns) { - yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)objfmt; + yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)object->objfmt; xdf_objfmt_output_info info; unsigned char *localbuf; unsigned long symtab_count = 0; + info.object = object; info.objfmt_xdf = objfmt_xdf; info.errwarns = errwarns; info.f = f; @@ -583,20 +577,20 @@ xdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, /* Get number of symbols */ info.indx = 0; info.all_syms = 1; /* force all syms into symbol table */ - yasm_symtab_traverse(objfmt_xdf->symtab, &info, xdf_objfmt_count_sym); + yasm_symtab_traverse(object->symtab, &info, xdf_objfmt_count_sym); symtab_count = info.indx; /* Get file offset of start of string table */ info.strtab_offset = 16+40*(objfmt_xdf->parse_scnum)+16*symtab_count; /* Output symbol table */ - yasm_symtab_traverse(objfmt_xdf->symtab, &info, xdf_objfmt_output_sym); + yasm_symtab_traverse(object->symtab, &info, xdf_objfmt_output_sym); /* Output string table */ - yasm_symtab_traverse(objfmt_xdf->symtab, &info, xdf_objfmt_output_str); + yasm_symtab_traverse(object->symtab, &info, xdf_objfmt_output_str); /* Section data/relocs */ - if (yasm_object_sections_traverse(objfmt_xdf->object, &info, + if (yasm_object_sections_traverse(object, &info, xdf_objfmt_output_section)) return; @@ -615,8 +609,7 @@ xdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, YASM_WRITE_32_L(localbuf, info.strtab_offset-16); fwrite(info.buf, 16, 1, f); - yasm_object_sections_traverse(objfmt_xdf->object, &info, - xdf_objfmt_output_secthead); + yasm_object_sections_traverse(object, &info, xdf_objfmt_output_secthead); yasm_xfree(info.buf); } @@ -628,9 +621,10 @@ xdf_objfmt_destroy(yasm_objfmt *objfmt) } static xdf_section_data * -xdf_objfmt_init_new_section(yasm_objfmt_xdf *objfmt_xdf, yasm_section *sect, +xdf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, const char *sectname, unsigned long line) { + yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)object->objfmt; xdf_section_data *data; yasm_symrec *sym; @@ -645,36 +639,33 @@ xdf_objfmt_init_new_section(yasm_objfmt_xdf *objfmt_xdf, yasm_section *sect, data->nreloc = 0; yasm_section_add_data(sect, &xdf_section_data_cb, data); - sym = yasm_symtab_define_label(objfmt_xdf->symtab, sectname, + sym = yasm_symtab_define_label(object->symtab, sectname, yasm_section_bcs_first(sect), 1, line); data->sym = sym; return data; } static yasm_section * -xdf_objfmt_add_default_section(yasm_objfmt *objfmt) +xdf_objfmt_add_default_section(yasm_object *object) { - yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)objfmt; yasm_section *retval; xdf_section_data *xsd; int isnew; - retval = yasm_object_get_general(objfmt_xdf->object, ".text", 0, 0, 1, 0, - &isnew, 0); + retval = yasm_object_get_general(object, ".text", 0, 0, 1, 0, &isnew, 0); if (isnew) { - xsd = xdf_objfmt_init_new_section(objfmt_xdf, retval, ".text", 0); + xsd = xdf_objfmt_init_new_section(object, retval, ".text", 0); yasm_section_set_default(retval, 1); } return retval; } static /*@observer@*/ /*@null@*/ yasm_section * -xdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, - /*@unused@*/ /*@null@*/ - yasm_valparamhead *objext_valparams, - unsigned long line) +xdf_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, + /*@unused@*/ /*@null@*/ + yasm_valparamhead *objext_valparams, + unsigned long line) { - yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)objfmt; yasm_valparam *vp = yasm_vps_first(valparams); yasm_section *retval; int isnew; @@ -703,15 +694,15 @@ xdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, if (yasm__strcasecmp(vp->val, "use16") == 0) { flags &= ~(XDF_SECT_USE_32|XDF_SECT_USE_64); flags |= XDF_SECT_USE_16; - yasm_arch_set_var(objfmt_xdf->arch, "mode_bits", 16); + yasm_arch_set_var(object->arch, "mode_bits", 16); } else if (yasm__strcasecmp(vp->val, "use32") == 0) { flags &= ~(XDF_SECT_USE_16|XDF_SECT_USE_64); flags |= XDF_SECT_USE_32; - yasm_arch_set_var(objfmt_xdf->arch, "mode_bits", 32); + yasm_arch_set_var(object->arch, "mode_bits", 32); } else if (yasm__strcasecmp(vp->val, "use64") == 0) { flags &= ~(XDF_SECT_USE_16|XDF_SECT_USE_32); flags |= XDF_SECT_USE_64; - yasm_arch_set_var(objfmt_xdf->arch, "mode_bits", 64); + yasm_arch_set_var(object->arch, "mode_bits", 64); } else if (yasm__strcasecmp(vp->val, "bss") == 0) { flags |= XDF_SECT_BSS; } else if (yasm__strcasecmp(vp->val, "flat") == 0) { @@ -764,11 +755,11 @@ xdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, vp->val); } - retval = yasm_object_get_general(objfmt_xdf->object, sectname, 0, align, 1, - resonly, &isnew, line); + retval = yasm_object_get_general(object, sectname, 0, align, 1, resonly, + &isnew, line); if (isnew) - xsd = xdf_objfmt_init_new_section(objfmt_xdf, retval, sectname, line); + xsd = xdf_objfmt_init_new_section(object, retval, sectname, line); else xsd = yasm_section_get_data(retval, &xdf_section_data_cb); @@ -823,41 +814,32 @@ xdf_section_data_print(void *data, FILE *f, int indent_level) } static yasm_symrec * -xdf_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ - /*@null@*/ yasm_valparamhead *objext_valparams, - unsigned long line) +xdf_objfmt_extern_declare(yasm_object *object, const char *name, /*@unused@*/ + /*@null@*/ yasm_valparamhead *objext_valparams, + unsigned long line) { - yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)objfmt; - - return yasm_symtab_declare(objfmt_xdf->symtab, name, YASM_SYM_EXTERN, - line); + return yasm_symtab_declare(object->symtab, name, YASM_SYM_EXTERN, line); } static yasm_symrec * -xdf_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/ - /*@null@*/ yasm_valparamhead *objext_valparams, - unsigned long line) +xdf_objfmt_global_declare(yasm_object *object, const char *name, /*@unused@*/ + /*@null@*/ yasm_valparamhead *objext_valparams, + unsigned long line) { - yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)objfmt; - - return yasm_symtab_declare(objfmt_xdf->symtab, name, YASM_SYM_GLOBAL, - line); + return yasm_symtab_declare(object->symtab, name, YASM_SYM_GLOBAL, line); } static yasm_symrec * -xdf_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, - /*@only@*/ yasm_expr *size, /*@unused@*/ /*@null@*/ - yasm_valparamhead *objext_valparams, - unsigned long line) +xdf_objfmt_common_declare(yasm_object *object, const char *name, + /*@only@*/ yasm_expr *size, /*@unused@*/ /*@null@*/ + yasm_valparamhead *objext_valparams, + unsigned long line) { - yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)objfmt; - yasm_expr_destroy(size); yasm_error_set(YASM_ERROR_GENERAL, N_("XDF object format does not support common variables")); - return yasm_symtab_declare(objfmt_xdf->symtab, name, YASM_SYM_COMMON, - line); + return yasm_symtab_declare(object->symtab, name, YASM_SYM_COMMON, line); } static void @@ -875,7 +857,7 @@ xdf_symrec_data_print(void *data, FILE *f, int indent_level) } static int -xdf_objfmt_directive(/*@unused@*/ yasm_objfmt *objfmt, +xdf_objfmt_directive(/*@unused@*/ yasm_object *object, /*@unused@*/ const char *name, /*@unused@*/ /*@null@*/ yasm_valparamhead *valparams, /*@unused@*/ /*@null@*/ diff --git a/modules/parsers/gas/gas-parse.c b/modules/parsers/gas/gas-parse.c index a119938c..0ece9747 100644 --- a/modules/parsers/gas/gas-parse.c +++ b/modules/parsers/gas/gas-parse.c @@ -72,10 +72,12 @@ static yasm_bytecode *gas_parser_dir_fill (yasm_parser_gas *parser_gas, /*@only@*/ yasm_expr *repeat, /*@only@*/ /*@null@*/ yasm_expr *size, /*@only@*/ /*@null@*/ yasm_expr *value); +#if 0 static void gas_parser_directive (yasm_parser_gas *parser_gas, const char *name, yasm_valparamhead *valparams, /*@null@*/ yasm_valparamhead *objext_valparams); +#endif #define is_eol_tok(tok) ((tok) == '\n' || (tok) == ';' || (tok) == 0) #define is_eol() is_eol_tok(curtok) @@ -215,7 +217,7 @@ gas_parser_parse(yasm_parser_gas *parser_gas) yasm_errwarn_propagate(parser_gas->errwarns, cur_line); - temp_bc = yasm_section_bcs_append(parser_gas->cur_section, bc); + temp_bc = yasm_section_bcs_append(cursect, bc); if (temp_bc) parser_gas->prev_bc = temp_bc; if (curtok == ';') @@ -377,8 +379,8 @@ parse_line(yasm_parser_gas *parser_gas) } } - return gas_parser_align(parser_gas, parser_gas->cur_section, bound, - fill, maxskip, (int)ival); + return gas_parser_align(parser_gas, cursect, bound, fill, maxskip, + (int)ival); } case DIR_ORG: get_next_token(); /* DIR_ORG */ @@ -393,16 +395,14 @@ parse_line(yasm_parser_gas *parser_gas) case DIR_LOCAL: get_next_token(); /* DIR_LOCAL */ if (!expect(ID)) return NULL; - yasm_symtab_declare(parser_gas->symtab, ID_val, YASM_SYM_DLOCAL, - cur_line); + yasm_symtab_declare(p_symtab, ID_val, YASM_SYM_DLOCAL, cur_line); yasm_xfree(ID_val); get_next_token(); /* ID */ return NULL; case DIR_GLOBAL: get_next_token(); /* DIR_GLOBAL */ if (!expect(ID)) return NULL; - yasm_objfmt_global_declare(parser_gas->objfmt, ID_val, NULL, - cur_line); + yasm_objfmt_global_declare(p_object, ID_val, NULL, cur_line); yasm_xfree(ID_val); get_next_token(); /* ID */ return NULL; @@ -436,7 +436,7 @@ parse_line(yasm_parser_gas *parser_gas) } /* If already explicitly declared local, treat like LCOMM */ if (is_lcomm - || ((sym = yasm_symtab_get(parser_gas->symtab, id)) + || ((sym = yasm_symtab_get(p_symtab, id)) && yasm_symrec_get_visibility(sym) == YASM_SYM_DLOCAL)) { define_lcomm(parser_gas, id, e, align); } else if (align) { @@ -445,14 +445,12 @@ parse_line(yasm_parser_gas *parser_gas) vp = yasm_vp_create(NULL, align); yasm_vps_append(&vps, vp); - yasm_objfmt_common_declare(parser_gas->objfmt, id, e, &vps, - cur_line); + yasm_objfmt_common_declare(p_object, id, e, &vps, cur_line); yasm_vps_delete(&vps); yasm_xfree(id); } else { - yasm_objfmt_common_declare(parser_gas->objfmt, id, e, NULL, - cur_line); + yasm_objfmt_common_declare(p_object, id, e, NULL, cur_line); yasm_xfree(id); } return NULL; @@ -461,8 +459,7 @@ parse_line(yasm_parser_gas *parser_gas) get_next_token(); /* DIR_EXTERN */ if (!expect(ID)) return NULL; /* Go ahead and do it, even though all undef become extern */ - yasm_objfmt_extern_declare(parser_gas->objfmt, ID_val, NULL, - cur_line); + yasm_objfmt_extern_declare(p_object, ID_val, NULL, cur_line); yasm_xfree(ID_val); get_next_token(); /* ID */ return NULL; @@ -475,8 +472,7 @@ parse_line(yasm_parser_gas *parser_gas) yasm_vps_append(&vps, vp); get_next_token(); /* ID */ - yasm_objfmt_directive(parser_gas->objfmt, "weak", &vps, NULL, - cur_line); + yasm_objfmt_directive(p_object, "weak", &vps, NULL, cur_line); yasm_vps_delete(&vps); return NULL; @@ -487,14 +483,14 @@ parse_line(yasm_parser_gas *parser_gas) get_next_token(); /* DIR_ASCII */ if (!parse_strvals(parser_gas, &dvs)) return NULL; - return yasm_bc_create_data(&dvs, 1, (int)ival, parser_gas->arch, + return yasm_bc_create_data(&dvs, 1, (int)ival, p_object->arch, cur_line); case DIR_DATA: ival = DIR_DATA_val; get_next_token(); /* DIR_DATA */ if (!parse_datavals(parser_gas, &dvs)) return NULL; - return yasm_bc_create_data(&dvs, ival, 0, parser_gas->arch, + return yasm_bc_create_data(&dvs, ival, 0, p_object->arch, cur_line); case DIR_LEB128: ival = DIR_LEB128_val; @@ -516,7 +512,7 @@ parse_line(yasm_parser_gas *parser_gas) yasm_dvs_initialize(&dvs); yasm_dvs_append(&dvs, yasm_dv_create_expr( p_expr_new_ident(yasm_expr_int(yasm_intnum_create_uint(0))))); - bc = yasm_bc_create_data(&dvs, 1, 0, parser_gas->arch, cur_line); + bc = yasm_bc_create_data(&dvs, 1, 0, p_object->arch, cur_line); yasm_bc_set_multiple(bc, e); return bc; case DIR_SKIP: @@ -536,7 +532,7 @@ parse_line(yasm_parser_gas *parser_gas) e_val = parse_expr(parser_gas); yasm_dvs_initialize(&dvs); yasm_dvs_append(&dvs, yasm_dv_create_expr(e_val)); - bc = yasm_bc_create_data(&dvs, 1, 0, parser_gas->arch, cur_line); + bc = yasm_bc_create_data(&dvs, 1, 0, p_object->arch, cur_line); yasm_bc_set_multiple(bc, e); return bc; @@ -628,8 +624,7 @@ parse_line(yasm_parser_gas *parser_gas) get_next_token(); /* DIR_IDENT */ if (!parse_dirstrvals(parser_gas, &vps)) return NULL; - yasm_objfmt_directive(parser_gas->objfmt, "ident", &vps, NULL, - cur_line); + yasm_objfmt_directive(p_object, "ident", &vps, NULL, cur_line); yasm_vps_delete(&vps); return NULL; case DIR_FILE: @@ -667,8 +662,7 @@ parse_line(yasm_parser_gas *parser_gas) vp = yasm_vp_create(filename, NULL); yasm_vps_append(&vps, vp); - yasm_dbgfmt_directive(parser_gas->dbgfmt, "file", - parser_gas->cur_section, &vps, cur_line); + yasm_dbgfmt_directive(p_object, "file", &vps, cur_line); yasm_vps_delete(&vps); return NULL; @@ -691,8 +685,7 @@ parse_line(yasm_parser_gas *parser_gas) yasm_vps_append(&vps, vp); get_next_token(); /* STRING */ - yasm_dbgfmt_directive(parser_gas->dbgfmt, "file", - parser_gas->cur_section, &vps, cur_line); + yasm_dbgfmt_directive(p_object, "file", &vps, cur_line); yasm_vps_delete(&vps); return NULL; @@ -725,8 +718,7 @@ parse_line(yasm_parser_gas *parser_gas) yasm_vps_append(&vps, vp); get_next_token(); /* INTNUM */ - yasm_dbgfmt_directive(parser_gas->dbgfmt, "loc", - parser_gas->cur_section, &vps, cur_line); + yasm_dbgfmt_directive(p_object, "loc", &vps, cur_line); yasm_vps_delete(&vps); return NULL; @@ -760,8 +752,7 @@ parse_line(yasm_parser_gas *parser_gas) yasm_vps_append(&vps, vp); get_next_token(); /* ID */ - yasm_objfmt_directive(parser_gas->objfmt, "type", &vps, NULL, - cur_line); + yasm_objfmt_directive(p_object, "type", &vps, NULL, cur_line); yasm_vps_delete(&vps); return NULL; @@ -791,8 +782,7 @@ parse_line(yasm_parser_gas *parser_gas) vp = yasm_vp_create(NULL, e); yasm_vps_append(&vps, vp); - yasm_objfmt_directive(parser_gas->objfmt, "size", &vps, NULL, - cur_line); + yasm_objfmt_directive(p_object, "size", &vps, NULL, cur_line); yasm_vps_delete(&vps); return NULL; @@ -818,7 +808,7 @@ parse_instr(yasm_parser_gas *parser_gas) get_next_token(); if (is_eol()) { /* no operands */ - return yasm_bc_create_insn(parser_gas->arch, insn.arch_data, + return yasm_bc_create_insn(p_object->arch, insn.arch_data, 0, NULL, cur_line); } @@ -843,7 +833,7 @@ parse_instr(yasm_parser_gas *parser_gas) } get_next_token(); } - return yasm_bc_create_insn(parser_gas->arch, insn.arch_data, + return yasm_bc_create_insn(p_object->arch, insn.arch_data, num_operands, &operands, cur_line); } case PREFIX: @@ -852,7 +842,7 @@ parse_instr(yasm_parser_gas *parser_gas) get_next_token(); /* PREFIX */ bc = parse_instr(parser_gas); if (!bc) - bc = yasm_bc_create_empty_insn(parser_gas->arch, cur_line); + bc = yasm_bc_create_empty_insn(p_object->arch, cur_line); yasm_bc_insn_add_prefix(bc, prefix.arch_data); return bc; } @@ -862,7 +852,7 @@ parse_instr(yasm_parser_gas *parser_gas) get_next_token(); /* SEGREG */ bc = parse_instr(parser_gas); if (!bc) - bc = yasm_bc_create_empty_insn(parser_gas->arch, cur_line); + bc = yasm_bc_create_empty_insn(p_object->arch, cur_line); yasm_bc_insn_add_seg_prefix(bc, segreg); } default: @@ -1084,7 +1074,7 @@ done: if (!e1) return NULL; - ea = yasm_arch_ea_create(parser_gas->arch, e1); + ea = yasm_arch_ea_create(p_object->arch, e1); if (strong) yasm_ea_set_strong(ea, 1); return ea; @@ -1135,7 +1125,7 @@ parse_operand(yasm_parser_gas *parser_gas) return NULL; } get_next_token(); /* ')' */ - reg = yasm_arch_reggroup_get_reg(parser_gas->arch, reg, regindex); + reg = yasm_arch_reggroup_get_reg(p_object->arch, reg, regindex); if (reg == 0) { yasm_error_set(YASM_ERROR_SYNTAX, N_("bad register index `%u'"), regindex); @@ -1414,8 +1404,8 @@ gas_get_section(yasm_parser_gas *parser_gas, char *name, } } - new_section = yasm_objfmt_section_switch(parser_gas->objfmt, &vps, - objext_valparams, cur_line); + new_section = yasm_objfmt_section_switch(p_object, &vps, objext_valparams, + cur_line); yasm_vps_delete(&vps); return new_section; @@ -1432,7 +1422,7 @@ gas_switch_section(yasm_parser_gas *parser_gas, char *name, new_section = gas_get_section(parser_gas, yasm__xstrdup(name), flags, type, objext_valparams, builtin); if (new_section) { - parser_gas->cur_section = new_section; + cursect = new_section; parser_gas->prev_bc = yasm_section_bcs_last(new_section); } else yasm_error_set(YASM_ERROR_GENERAL, N_("invalid section name `%s'"), @@ -1471,7 +1461,7 @@ gas_parser_align(yasm_parser_gas *parser_gas, yasm_section *sect, return yasm_bc_create_align(boundval, fillval, maxskipval, yasm_section_is_code(sect) ? - yasm_arch_get_fill(parser_gas->arch) : NULL, + yasm_arch_get_fill(p_object->arch) : NULL, cur_line); } @@ -1506,13 +1496,13 @@ gas_parser_dir_fill(yasm_parser_gas *parser_gas, /*@only@*/ yasm_expr *repeat, yasm_dvs_initialize(&dvs); yasm_dvs_append(&dvs, yasm_dv_create_expr(value)); - bc = yasm_bc_create_data(&dvs, ssize, 0, parser_gas->arch, cur_line); + bc = yasm_bc_create_data(&dvs, ssize, 0, p_object->arch, cur_line); yasm_bc_set_multiple(bc, repeat); return bc; } - +#if 0 static void gas_parser_directive(yasm_parser_gas *parser_gas, const char *name, yasm_valparamhead *valparams, @@ -1521,10 +1511,10 @@ gas_parser_directive(yasm_parser_gas *parser_gas, const char *name, unsigned long line = cur_line; /* Handle (mostly) output-format independent directives here */ - if (!yasm_arch_parse_directive(parser_gas->arch, name, valparams, + if (!yasm_arch_parse_directive(p_object->arch, name, valparams, objext_valparams, parser_gas->object, line)) { ; - } else if (yasm_objfmt_directive(parser_gas->objfmt, name, valparams, + } else if (yasm_objfmt_directive(p_object, name, valparams, objext_valparams, line)) { yasm_error_set(YASM_ERROR_GENERAL, N_("unrecognized directive [%s]"), name); @@ -1534,3 +1524,4 @@ gas_parser_directive(yasm_parser_gas *parser_gas, const char *name, if (objext_valparams) yasm_vps_delete(objext_valparams); } +#endif diff --git a/modules/parsers/gas/gas-parser.c b/modules/parsers/gas/gas-parser.c index bbc5c586..2b79db82 100644 --- a/modules/parsers/gas/gas-parser.c +++ b/modules/parsers/gas/gas-parser.c @@ -37,16 +37,14 @@ static void -gas_parser_do_parse(yasm_object *object, yasm_preproc *pp, yasm_arch *a, - yasm_objfmt *of, yasm_dbgfmt *df, FILE *f, - const char *in_filename, int save_input, - yasm_section *def_sect, yasm_errwarns *errwarns) +gas_parser_do_parse(yasm_object *object, yasm_preproc *pp, FILE *f, + int save_input, yasm_linemap *linemap, + yasm_errwarns *errwarns) { yasm_parser_gas parser_gas; parser_gas.object = object; - parser_gas.linemap = yasm_object_get_linemap(parser_gas.object); - parser_gas.symtab = yasm_object_get_symtab(parser_gas.object); + parser_gas.linemap = linemap; parser_gas.in = f; @@ -58,13 +56,9 @@ gas_parser_do_parse(yasm_object *object, yasm_preproc *pp, yasm_arch *a, parser_gas.dir_line = 0; parser_gas.preproc = pp; - parser_gas.arch = a; - parser_gas.objfmt = of; - parser_gas.dbgfmt = df; parser_gas.errwarns = errwarns; - parser_gas.cur_section = def_sect; - parser_gas.prev_bc = yasm_section_bcs_first(def_sect); + parser_gas.prev_bc = yasm_section_bcs_first(object->cur_section); parser_gas.save_input = save_input; parser_gas.save_last = 0; diff --git a/modules/parsers/gas/gas-parser.h b/modules/parsers/gas/gas-parser.h index 80a92cd3..71b293f2 100644 --- a/modules/parsers/gas/gas-parser.h +++ b/modules/parsers/gas/gas-parser.h @@ -115,7 +115,6 @@ typedef struct yasm_parser_gas { int debug; /*@only@*/ yasm_object *object; - /*@dependent@*/ yasm_section *cur_section; /* last "base" label for local (.) labels */ /*@null@*/ char *locallabel_base; @@ -127,13 +126,9 @@ typedef struct yasm_parser_gas { unsigned long dir_line; /*@dependent@*/ yasm_preproc *preproc; - /*@dependent@*/ yasm_arch *arch; - /*@dependent@*/ yasm_objfmt *objfmt; - /*@dependent@*/ yasm_dbgfmt *dbgfmt; /*@dependent@*/ yasm_errwarns *errwarns; /*@dependent@*/ yasm_linemap *linemap; - /*@dependent@*/ yasm_symtab *symtab; /*@null@*/ yasm_bytecode *prev_bc; yasm_bytecode *temp_bc; @@ -163,7 +158,9 @@ typedef struct yasm_parser_gas { } yasm_parser_gas; /* shorter access names to commonly used parser_gas fields */ -#define p_symtab (parser_gas->symtab) +#define p_object (parser_gas->object) +#define p_symtab (parser_gas->object->symtab) +#define cursect (parser_gas->object->cur_section) #define curtok (parser_gas->token) #define curval (parser_gas->tokval) diff --git a/modules/parsers/gas/gas-token.re b/modules/parsers/gas/gas-token.re index eca535bd..b1742bd5 100644 --- a/modules/parsers/gas/gas-token.re +++ b/modules/parsers/gas/gas-token.re @@ -126,13 +126,13 @@ rept_input(yasm_parser_gas *parser_gas, /*@out@*/ YYCTYPE *buf, return (max_size-numleft); } - +#if 0 static size_t fill_input(void *d, unsigned char *buf, size_t max) { return yasm_preproc_input((yasm_preproc *)d, (char *)buf, max); } - +#endif static YYCTYPE * fill(yasm_parser_gas *parser_gas, YYCTYPE *cursor) { @@ -406,7 +406,7 @@ scan: parser_gas->state = INSTDIR; RETURN(DIR_DATA); } '.word' { - lvalp->int_info = yasm_arch_wordsize(parser_gas->arch)/8; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)/8; parser_gas->state = INSTDIR; RETURN(DIR_DATA); } '.quad' { @@ -487,15 +487,15 @@ scan: '.zero' { parser_gas->state = INSTDIR; RETURN(DIR_ZERO); } /* other directives */ '.code16' { - yasm_arch_set_var(parser_gas->arch, "mode_bits", 16); + yasm_arch_set_var(p_object->arch, "mode_bits", 16); goto scan; } '.code32' { - yasm_arch_set_var(parser_gas->arch, "mode_bits", 32); + yasm_arch_set_var(p_object->arch, "mode_bits", 32); goto scan; } '.code64' { - yasm_arch_set_var(parser_gas->arch, "mode_bits", 64); + yasm_arch_set_var(p_object->arch, "mode_bits", 64); goto scan; } '.equ' { parser_gas->state = INSTDIR; RETURN(DIR_EQU); } @@ -518,7 +518,7 @@ scan: savech = s->tok[TOKLEN]; s->tok[TOKLEN] = '\0'; switch (yasm_arch_parse_check_regtmod - (parser_gas->arch, lvalp->arch_data, TOK+1, TOKLEN-1)) { + (p_object->arch, lvalp->arch_data, TOK+1, TOKLEN-1)) { case YASM_ARCH_REG: s->tok[TOKLEN] = savech; RETURN(REG); @@ -562,7 +562,7 @@ scan: savech = s->tok[TOKLEN]; s->tok[TOKLEN] = '\0'; switch (yasm_arch_parse_check_insnprefix - (parser_gas->arch, lvalp->arch_data, TOK, TOKLEN)) { + (p_object->arch, lvalp->arch_data, TOK, TOKLEN)) { case YASM_ARCH_INSN: s->tok[TOKLEN] = savech; parser_gas->state = INSTDIR; diff --git a/modules/parsers/nasm/nasm-parse.c b/modules/parsers/nasm/nasm-parse.c index c2687e91..7d4d7d35 100644 --- a/modules/parsers/nasm/nasm-parse.c +++ b/modules/parsers/nasm/nasm-parse.c @@ -199,7 +199,7 @@ nasm_parser_parse(yasm_parser_nasm *parser_nasm) yasm_errwarn_propagate(parser_nasm->errwarns, cur_line); - temp_bc = yasm_section_bcs_append(parser_nasm->cur_section, bc); + temp_bc = yasm_section_bcs_append(cursect, bc); if (temp_bc) parser_nasm->prev_bc = temp_bc; if (parser_nasm->save_input) @@ -506,7 +506,7 @@ dv_done: if (is_eol()) /* allow trailing , on list */ break; } - return yasm_bc_create_data(&dvs, size, 0, parser_nasm->arch, + return yasm_bc_create_data(&dvs, size, 0, p_object->arch, cur_line); } case RESERVE_SPACE: @@ -583,8 +583,8 @@ parse_instr(yasm_parser_nasm *parser_nasm) get_next_token(); if (is_eol()) { /* no operands */ - return yasm_bc_create_insn(parser_nasm->arch, insn.arch_data, - 0, NULL, cur_line); + return yasm_bc_create_insn(p_object->arch, insn.arch_data, 0, + NULL, cur_line); } /* parse operands */ @@ -608,7 +608,7 @@ parse_instr(yasm_parser_nasm *parser_nasm) } get_next_token(); } - return yasm_bc_create_insn(parser_nasm->arch, insn.arch_data, + return yasm_bc_create_insn(p_object->arch, insn.arch_data, num_operands, &operands, cur_line); } case PREFIX: { @@ -677,7 +677,7 @@ parse_operand(yasm_parser_nasm *parser_nasm) if (!op) return NULL; if (op->type == YASM_INSN__OPERAND_REG && - yasm_arch_get_reg_size(parser_nasm->arch, op->data.reg) != size) + yasm_arch_get_reg_size(p_object->arch, op->data.reg) != size) yasm_error_set(YASM_ERROR_TYPE, N_("cannot override register size")); else { @@ -761,7 +761,7 @@ parse_memaddr(yasm_parser_nasm *parser_nasm) yasm_expr *e = parse_expr(parser_nasm, NORM_EXPR); if (!e) return NULL; - return yasm_arch_ea_create(parser_nasm->arch, e); + return yasm_arch_ea_create(p_object->arch, e); } } } @@ -957,8 +957,7 @@ parse_expr6(yasm_parser_nasm *parser_nasm, expr_type type) case ID: e = p_expr_new_ident(yasm_expr_sym( yasm_symtab_define_label(p_symtab, ID_val, - yasm_section_bcs_first(parser_nasm->cur_section), 0, - cur_line))); + yasm_section_bcs_first(cursect), 0, cur_line))); yasm_xfree(ID_val); break; default: @@ -1032,7 +1031,7 @@ parse_expr6(yasm_parser_nasm *parser_nasm, expr_type type) case START_SECTION_ID: /* "$$" references the start of the current section */ sym = yasm_symtab_define_label(p_symtab, "$$", - yasm_section_bcs_first(parser_nasm->cur_section), 0, cur_line); + yasm_section_bcs_first(cursect), 0, cur_line); e = p_expr_new_ident(yasm_expr_sym(sym)); break; default: @@ -1079,8 +1078,7 @@ dir_extern(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams) { yasm_valparam *vp = yasm_vps_first(valparams); - yasm_objfmt_extern_declare(parser_nasm->objfmt, vp->val, objext_valparams, - cur_line); + yasm_objfmt_extern_declare(p_object, vp->val, objext_valparams, cur_line); } static void @@ -1088,8 +1086,7 @@ dir_global(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams) { yasm_valparam *vp = yasm_vps_first(valparams); - yasm_objfmt_global_declare(parser_nasm->objfmt, vp->val, objext_valparams, - cur_line); + yasm_objfmt_global_declare(p_object, vp->val, objext_valparams, cur_line); } static void @@ -1106,12 +1103,12 @@ dir_common(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, return; } if (vp2->val) { - yasm_objfmt_common_declare(parser_nasm->objfmt, vp->val, + yasm_objfmt_common_declare(p_object, vp->val, p_expr_new_ident(yasm_expr_sym( yasm_symtab_use(p_symtab, vp2->val, line))), objext_valparams, line); } else if (vp2->param) { - yasm_objfmt_common_declare(parser_nasm->objfmt, vp->val, vp2->param, + yasm_objfmt_common_declare(p_object, vp->val, vp2->param, objext_valparams, line); vp2->param = NULL; } @@ -1121,12 +1118,11 @@ static void dir_section(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams) { - yasm_valparam *vp = yasm_vps_first(valparams); yasm_section *new_section = - yasm_objfmt_section_switch(parser_nasm->objfmt, valparams, - objext_valparams, cur_line); + yasm_objfmt_section_switch(p_object, valparams, objext_valparams, + cur_line); if (new_section) { - parser_nasm->cur_section = new_section; + cursect = new_section; parser_nasm->prev_bc = yasm_section_bcs_last(new_section); } else yasm_error_set(YASM_ERROR_SYNTAX, N_("invalid argument to [%s]"), @@ -1141,16 +1137,16 @@ dir_absolute(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, unsigned long line = cur_line; /* it can be just an ID or a complete expression, so handle both. */ if (vp->val) - parser_nasm->cur_section = - yasm_object_create_absolute(parser_nasm->object, + cursect = + yasm_object_create_absolute(p_object, p_expr_new_ident(yasm_expr_sym( yasm_symtab_use(p_symtab, vp->val, line))), line); else if (vp->param) { - parser_nasm->cur_section = - yasm_object_create_absolute(parser_nasm->object, vp->param, line); + cursect = + yasm_object_create_absolute(p_object, vp->param, line); vp->param = NULL; } - parser_nasm->prev_bc = yasm_section_bcs_last(parser_nasm->cur_section); + parser_nasm->prev_bc = yasm_section_bcs_last(cursect); } static void @@ -1181,9 +1177,8 @@ dir_align(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, /* Alignments must be a power of two. */ if (is_exp2(boundint)) { - if (boundint > yasm_section_get_align(parser_nasm->cur_section)) - yasm_section_set_align(parser_nasm->cur_section, boundint, - cur_line); + if (boundint > yasm_section_get_align(cursect)) + yasm_section_set_align(cursect, boundint, cur_line); } } @@ -1191,10 +1186,10 @@ dir_align(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, * use arch (nop) fill. */ parser_nasm->prev_bc = - yasm_section_bcs_append(parser_nasm->cur_section, + yasm_section_bcs_append(cursect, yasm_bc_create_align(boundval, NULL, NULL, - /*yasm_section_is_code(parser_nasm->cur_section) ?*/ - yasm_arch_get_fill(parser_nasm->arch)/* : NULL*/, + /*yasm_section_is_code(cursect) ?*/ + yasm_arch_get_fill(p_object->arch)/* : NULL*/, cur_line)); } @@ -1205,7 +1200,7 @@ dir_cpu(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, yasm_valparam *vp; yasm_vps_foreach(vp, valparams) { if (vp->val) - yasm_arch_parse_cpu(parser_nasm->arch, vp->val, strlen(vp->val)); + yasm_arch_parse_cpu(p_object->arch, vp->val, strlen(vp->val)); else if (vp->param) { const yasm_intnum *intcpu; intcpu = yasm_expr_get_intnum(&vp->param, 0); @@ -1215,7 +1210,7 @@ dir_cpu(yasm_parser_nasm *parser_nasm, yasm_valparamhead *valparams, else { char strcpu[16]; sprintf(strcpu, "%lu", yasm_intnum_get_uint(intcpu)); - yasm_arch_parse_cpu(parser_nasm->arch, strcpu, strlen(strcpu)); + yasm_arch_parse_cpu(p_object->arch, strcpu, strlen(strcpu)); } } } @@ -1267,14 +1262,12 @@ nasm_parser_directive(yasm_parser_nasm *parser_nasm, const char *name, if (i != NELEMS(dirs)) { ; - } else if (!yasm_arch_parse_directive(parser_nasm->arch, name, valparams, - objext_valparams, parser_nasm->object, line)) { + } else if (!yasm_arch_parse_directive(p_object->arch, name, valparams, + objext_valparams, p_object, line)) { ; - } else if (!yasm_dbgfmt_directive(parser_nasm->dbgfmt, name, - parser_nasm->cur_section, valparams, - line)) { + } else if (!yasm_dbgfmt_directive(p_object, name, valparams, line)) { ; - } else if (yasm_objfmt_directive(parser_nasm->objfmt, name, valparams, + } else if (yasm_objfmt_directive(p_object, name, valparams, objext_valparams, line)) { yasm_error_set(YASM_ERROR_SYNTAX, N_("unrecognized directive [%s]"), name); diff --git a/modules/parsers/nasm/nasm-parser.c b/modules/parsers/nasm/nasm-parser.c index a5173bd5..9599e4a4 100644 --- a/modules/parsers/nasm/nasm-parser.c +++ b/modules/parsers/nasm/nasm-parser.c @@ -34,16 +34,14 @@ static void -nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp, yasm_arch *a, - yasm_objfmt *of, yasm_dbgfmt *df, FILE *f, - const char *in_filename, int save_input, - yasm_section *def_sect, yasm_errwarns *errwarns) +nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp, FILE *f, + int save_input, yasm_linemap *linemap, + yasm_errwarns *errwarns) { yasm_parser_nasm parser_nasm; parser_nasm.object = object; - parser_nasm.linemap = yasm_object_get_linemap(parser_nasm.object); - parser_nasm.symtab = yasm_object_get_symtab(parser_nasm.object); + parser_nasm.linemap = linemap; parser_nasm.in = f; @@ -51,13 +49,9 @@ nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp, yasm_arch *a, parser_nasm.locallabel_base_len = 0; parser_nasm.preproc = pp; - parser_nasm.arch = a; - parser_nasm.objfmt = of; - parser_nasm.dbgfmt = df; parser_nasm.errwarns = errwarns; - parser_nasm.cur_section = def_sect; - parser_nasm.prev_bc = yasm_section_bcs_first(def_sect); + parser_nasm.prev_bc = yasm_section_bcs_first(object->cur_section); parser_nasm.save_input = save_input; parser_nasm.save_last = 0; diff --git a/modules/parsers/nasm/nasm-parser.h b/modules/parsers/nasm/nasm-parser.h index 3eff7b9d..949b7c00 100644 --- a/modules/parsers/nasm/nasm-parser.h +++ b/modules/parsers/nasm/nasm-parser.h @@ -82,20 +82,15 @@ typedef struct yasm_parser_nasm { int debug; /*@only@*/ yasm_object *object; - /*@dependent@*/ yasm_section *cur_section; /* last "base" label for local (.) labels */ /*@null@*/ char *locallabel_base; size_t locallabel_base_len; /*@dependent@*/ yasm_preproc *preproc; - /*@dependent@*/ yasm_arch *arch; - /*@dependent@*/ yasm_objfmt *objfmt; - /*@dependent@*/ yasm_dbgfmt *dbgfmt; /*@dependent@*/ yasm_errwarns *errwarns; /*@dependent@*/ yasm_linemap *linemap; - /*@dependent@*/ yasm_symtab *symtab; /*@null@*/ yasm_bytecode *prev_bc; @@ -125,7 +120,9 @@ typedef struct yasm_parser_nasm { } yasm_parser_nasm; /* shorter access names to commonly used parser_nasm fields */ -#define p_symtab (parser_nasm->symtab) +#define p_object (parser_nasm->object) +#define p_symtab (parser_nasm->object->symtab) +#define cursect (parser_nasm->object->cur_section) #define curtok (parser_nasm->token) #define curval (parser_nasm->tokval) diff --git a/modules/parsers/nasm/nasm-token.re b/modules/parsers/nasm/nasm-token.re index e75e3d31..b72883d9 100644 --- a/modules/parsers/nasm/nasm-token.re +++ b/modules/parsers/nasm/nasm-token.re @@ -227,71 +227,71 @@ scan: /* size specifiers */ 'byte' { lvalp->int_info = 8; RETURN(SIZE_OVERRIDE); } 'hword' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)/2; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2; RETURN(SIZE_OVERRIDE); } 'word' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch); + lvalp->int_info = yasm_arch_wordsize(p_object->arch); RETURN(SIZE_OVERRIDE); } 'dword' | 'long' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*2; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2; RETURN(SIZE_OVERRIDE); } 'qword' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*4; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4; RETURN(SIZE_OVERRIDE); } 'tword' { lvalp->int_info = 80; RETURN(SIZE_OVERRIDE); } 'dqword' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*8; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; RETURN(SIZE_OVERRIDE); } /* pseudo-instructions */ 'db' { lvalp->int_info = 8; RETURN(DECLARE_DATA); } 'dhw' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)/2; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2; RETURN(DECLARE_DATA); } 'dw' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch); + lvalp->int_info = yasm_arch_wordsize(p_object->arch); RETURN(DECLARE_DATA); } 'dd' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*2; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2; RETURN(DECLARE_DATA); } 'dq' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*4; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4; RETURN(DECLARE_DATA); } 'dt' { lvalp->int_info = 80; RETURN(DECLARE_DATA); } 'ddq' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*8; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; RETURN(DECLARE_DATA); } 'resb' { lvalp->int_info = 8; RETURN(RESERVE_SPACE); } 'reshw' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)/2; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2; RETURN(RESERVE_SPACE); } 'resw' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch); + lvalp->int_info = yasm_arch_wordsize(p_object->arch); RETURN(RESERVE_SPACE); } 'resd' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*2; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2; RETURN(RESERVE_SPACE); } 'resq' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*4; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4; RETURN(RESERVE_SPACE); } 'rest' { lvalp->int_info = 80; RETURN(RESERVE_SPACE); } 'resdq' { - lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*8; + lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; RETURN(RESERVE_SPACE); } @@ -352,7 +352,7 @@ scan: s->tok[TOKLEN] = '\0'; if (parser_nasm->state != INSTRUCTION) switch (yasm_arch_parse_check_insnprefix - (parser_nasm->arch, lvalp->arch_data, TOK, TOKLEN)) { + (p_object->arch, lvalp->arch_data, TOK, TOKLEN)) { case YASM_ARCH_INSN: parser_nasm->state = INSTRUCTION; s->tok[TOKLEN] = savech; @@ -364,7 +364,7 @@ scan: break; } switch (yasm_arch_parse_check_regtmod - (parser_nasm->arch, lvalp->arch_data, TOK, TOKLEN)) { + (p_object->arch, lvalp->arch_data, TOK, TOKLEN)) { case YASM_ARCH_REG: s->tok[TOKLEN] = savech; RETURN(REG); @@ -616,7 +616,7 @@ directive2: savech = s->tok[TOKLEN]; s->tok[TOKLEN] = '\0'; switch (yasm_arch_parse_check_regtmod - (parser_nasm->arch, lvalp->arch_data, TOK, TOKLEN)) { + (p_object->arch, lvalp->arch_data, TOK, TOKLEN)) { case YASM_ARCH_REG: s->tok[TOKLEN] = savech; RETURN(REG);