]> granicus.if.org Git - yasm/commitdiff
Add versioning to all loadable module interfaces. The version is checked by
authorPeter Johnson <peter@tortall.net>
Wed, 30 Jul 2003 04:36:29 +0000 (04:36 -0000)
committerPeter Johnson <peter@tortall.net>
Wed, 30 Jul 2003 04:36:29 +0000 (04:36 -0000)
module users to ensure the module interface they're using matches the
interface the module was compiled with.  The #define YASM_module_VERSION
should be incremented on every functional change to the module interface.

svn path=/trunk/yasm/; revision=1021

18 files changed:
frontends/yasm/yasm.c
libyasm/arch.h
libyasm/dbgfmt.h
libyasm/objfmt.h
libyasm/optimizer.h
libyasm/parser.h
libyasm/preproc.h
modules/arch/lc3b/lc3barch.c
modules/arch/x86/x86arch.c
modules/dbgfmts/null/null-dbgfmt.c
modules/objfmts/bin/bin-objfmt.c
modules/objfmts/coff/coff-objfmt.c
modules/objfmts/dbg/dbg-objfmt.c
modules/objfmts/elf/elf-objfmt.c
modules/optimizers/basic/basic-optimizer.c
modules/parsers/nasm/nasm-parser.c
modules/preprocs/nasm/nasm-preproc.c
modules/preprocs/raw/raw-preproc.c

index 3846260564e52f4b88e7fd355f94bb7a874ed262..0d6a2cc18cff26fcc0de4c780482bd567cd599f2 100644 (file)
@@ -50,6 +50,18 @@ extern const lt_dlsymlist lt_preloaded_symbols[];
 /* Preprocess-only buffer size */
 #define PREPROC_BUF_SIZE    16384
 
+/* Check the module version */
+#define check_module_version(d, TYPE, desc)    \
+do { \
+    if (d && d->version != YASM_##TYPE##_VERSION) { \
+       print_error( \
+           _("%s: module version mismatch: %s `%s' (need %d, module %d)"), \
+           _("FATAL"), _(desc), d->keyword, YASM_##TYPE##_VERSION, \
+           d->version); \
+       exit(EXIT_FAILURE); \
+    } \
+} while (0)
+
 /*@null@*/ /*@only@*/ static char *obj_filename = NULL, *in_filename = NULL;
 /*@null@*/ /*@only@*/ static char *machine_name = NULL;
 static int special_options = 0;
@@ -315,6 +327,7 @@ main(int argc, char *argv[])
            cleanup(NULL);
            return EXIT_FAILURE;
        }
+       check_module_version(cur_preproc, PREPROC, "preproc");
 
        apply_preproc_saved_options();
 
@@ -352,6 +365,7 @@ main(int argc, char *argv[])
            return EXIT_FAILURE;
        }
     }
+    check_module_version(cur_arch, ARCH, "arch");
 
     /* Set up architecture using the selected (or default) machine */
     if (!machine_name)
@@ -383,6 +397,7 @@ main(int argc, char *argv[])
                    _("optimizer"));
        return EXIT_FAILURE;
     }
+    check_module_version(cur_optimizer, OPTIMIZER, "optimizer");
 
     yasm_arch_common_initialize(cur_arch);
     yasm_expr_initialize(cur_arch);
@@ -397,6 +412,7 @@ main(int argc, char *argv[])
                    _("object format"));
        return EXIT_FAILURE;
     }
+    check_module_version(cur_objfmt, OBJFMT, "objfmt");
 
     /* If not already specified, default to null as the debug format. */
     if (!cur_dbgfmt)
@@ -426,6 +442,7 @@ main(int argc, char *argv[])
                    _("debug format"));
        return EXIT_FAILURE;
     }
+    check_module_version(cur_dbgfmt, DBGFMT, "dbgfmt");
 
     /* determine the object filename if not specified */
     if (!obj_filename) {
@@ -463,6 +480,7 @@ main(int argc, char *argv[])
            return EXIT_FAILURE;
        }
     }
+    check_module_version(cur_parser, PARSER, "parser");
 
     /* If not already specified, default to the parser's default preproc. */
     if (!cur_preproc)
@@ -493,6 +511,7 @@ main(int argc, char *argv[])
        cleanup(NULL);
        return EXIT_FAILURE;
     }
+    check_module_version(cur_preproc, PREPROC, "preproc");
 
     apply_preproc_saved_options();
 
index 8cd10066912254d9228a4fd05f421415ae622e08..c374e2d075d4b03d87ad929a6c50bc778fd2e920 100644 (file)
@@ -84,6 +84,17 @@ typedef struct yasm_arch_machine {
     const char *keyword;
 } yasm_arch_machine;
 
+/** Version number of #yasm_arch interface.  Any functional change to the
+ * #yasm_arch interface should simultaneously increment this number.  This
+ * version should be checked by #yasm_arch loaders to verify that the
+ * expected version (the version defined by its libyasm header files) matches
+ * the loaded module version (the version defined by the module's libyasm
+ * header files).  Doing this will ensure that the module version's function
+ * definitions match the module loader's function definitions.  The version
+ * number must never be decreased.
+ */
+#define YASM_ARCH_VERSION      0
+
 /** YASM architecture interface.
  * \note All "data" in parser-related functions (parse_*) needs to start the
  *      parse initialized to 0 to make it okay for a parser-related function
@@ -91,6 +102,12 @@ typedef struct yasm_arch_machine {
  *      on the same piece of data.
  */
 struct yasm_arch {
+    /** Version (see #YASM_ARCH_VERSION).  Should always be set to
+     * #YASM_ARCH_VERSION by the module source and checked against
+     * #YASM_ARCH_VERSION by the module loader.
+     */
+    unsigned int version;
+
     /** One-line description of the architecture. */
     const char *name;
 
index 97616690378b71a15665cdcefafb86e2c1768964..57ce67a1d574dafe661cf8c526d436c57866cd80 100644 (file)
 #ifndef YASM_DBGFMT_H
 #define YASM_DBGFMT_H
 
+/** Version number of #yasm_dbgfmt interface.  Any functional change to the
+ * #yasm_dbgfmt interface should simultaneously increment this number.  This
+ * version should be checked by #yasm_dbgfmt loaders to verify that the
+ * expected version (the version defined by its libyasm header files) matches
+ * the loaded module version (the version defined by the module's libyasm
+ * header files).  Doing this will ensure that the module version's function
+ * definitions match the module loader's function definitions.  The version
+ * number must never be decreased.
+ */
+#define YASM_DBGFMT_VERSION    0
+
 /** YASM debug format interface. */
 struct yasm_dbgfmt {
+    /** Version (see #YASM_DBGFMT_VERSION).  Should always be set to
+     * #YASM_DBGFMT_VERSION by the module source and checked against
+     * #YASM_DBGFMT_VERSION by the module loader.
+     */
+    unsigned int version;
+
     /** One-line description of the debug format. */
     const char *name;
 
index f1d81b073a450518f8e124877f2b2d97b2e04b3b..bc0d7b29e2ac96ed6693005487a95f29e8de1ccf 100644 (file)
 #ifndef YASM_OBJFMT_H
 #define YASM_OBJFMT_H
 
+/** Version number of #yasm_objfmt interface.  Any functional change to the
+ * #yasm_objfmt interface should simultaneously increment this number.  This
+ * version should be checked by #yasm_objfmt loaders to verify that the
+ * expected version (the version defined by its libyasm header files) matches
+ * the loaded module version (the version defined by the module's libyasm
+ * header files).  Doing this will ensure that the module version's function
+ * definitions match the module loader's function definitions.  The version
+ * number must never be decreased.
+ */
+#define YASM_OBJFMT_VERSION    0
+
 /** YASM object format interface. */
 struct yasm_objfmt {
+    /** Version (see #YASM_OBJFMT_VERSION).  Should always be set to
+     * #YASM_OBJFMT_VERSION by the module source and checked against
+     * #YASM_OBJFMT_VERSION by the module loader.
+     */
+    unsigned int version;
+
     /** One-line description of the object format. */
     const char *name;
 
index a0cfb448dbd3b613aa141ace2a9a2b268b9e2e58..ba6a3bfbe65f6161d82a4f7143cb9de453bd0a4f 100644 (file)
 #ifndef YASM_OPTIMIZER_H
 #define YASM_OPTIMIZER_H
 
+/** Version number of #yasm_optimizer interface.  Any functional change to the
+ * #yasm_optimizer interface should simultaneously increment this number.  This
+ * version should be checked by #yasm_optimizer loaders to verify that the
+ * expected version (the version defined by its libyasm header files) matches
+ * the loaded module version (the version defined by the module's libyasm
+ * header files).  Doing this will ensure that the module version's function
+ * definitions match the module loader's function definitions.  The version
+ * number must never be decreased.
+ */
+#define YASM_OPTIMIZER_VERSION 0
+
 /* Interface to the optimizer module(s) */
 struct yasm_optimizer {
+    /** Version (see #YASM_OPTIMIZER_VERSION).  Should always be set to
+     * #YASM_OPTIMIZER_VERSION by the module source and checked against
+     * #YASM_OPTIMIZER_VERSION by the module loader.
+     */
+    unsigned int version;
+
     /* one-line description of the optimizer */
     const char *name;
 
index 04400ab32dbc30e631b583b8e45cc656f924b66e..7afd5b3c0ccc182f34e15eaeadbeacbb71965ac4 100644 (file)
@@ -1,4 +1,4 @@
-/* $IdPath: yasm/libyasm/parser.h,v 1.21 2003/03/13 06:54:19 peter Exp $
+/* $IdPath$
  * Parser module interface header file
  *
  *  Copyright (C) 2001  Peter Johnson
 #ifndef YASM_PARSER_H
 #define YASM_PARSER_H
 
+/** Version number of #yasm_parser interface.  Any functional change to the
+ * #yasm_parser interface should simultaneously increment this number.  This
+ * version should be checked by #yasm_parser loaders to verify that the
+ * expected version (the version defined by its libyasm header files) matches
+ * the loaded module version (the version defined by the module's libyasm
+ * header files).  Doing this will ensure that the module version's function
+ * definitions match the module loader's function definitions.  The version
+ * number must never be decreased.
+ */
+#define YASM_PARSER_VERSION    0
+
 /* Interface to the parser module(s) -- the "front end" of the assembler */
 struct yasm_parser {
+    /** Version (see #YASM_PARSER_VERSION).  Should always be set to
+     * #YASM_PARSER_VERSION by the module source and checked against
+     * #YASM_PARSER_VERSION by the module loader.
+     */
+    unsigned int version;
+
     /* one-line description of the parser */
     const char *name;
 
index 8226f9aa2063444b128bf6973f353ab2e30f8b1e..7082b6fff2cb1a1af7f37e5eb501158f966e2ce4 100644 (file)
 #ifndef YASM_PREPROC_H
 #define YASM_PREPROC_H
 
+/** Version number of #yasm_preproc interface.  Any functional change to the
+ * #yasm_preproc interface should simultaneously increment this number.  This
+ * version should be checked by #yasm_preproc loaders to verify that the
+ * expected version (the version defined by its libyasm header files) matches
+ * the loaded module version (the version defined by the module's libyasm
+ * header files).  Doing this will ensure that the module version's function
+ * definitions match the module loader's function definitions.  The version
+ * number must never be decreased.
+ */
+#define YASM_PREPROC_VERSION   0
+
 /* Interface to the preprocesor module(s) */
 struct yasm_preproc {
+    /** Version (see #YASM_PREPROC_VERSION).  Should always be set to
+     * #YASM_PREPROC_VERSION by the module source and checked against
+     * #YASM_PREPROC_VERSION by the module loader.
+     */
+    unsigned int version;
+
     /* one-line description of the preprocessor */
     const char *name;
 
index 84ce45ba3763f98b593ade4e440e6666fcdef776..f7485bde5f5dc0979f7ce2885e86125dd2706a32 100644 (file)
@@ -93,6 +93,7 @@ static yasm_arch_machine lc3b_machines[] = {
 
 /* Define arch structure -- see arch.h for details */
 yasm_arch yasm_lc3b_LTX_arch = {
+    YASM_ARCH_VERSION,
     "LC-3b",
     "lc3b",
     lc3b_initialize,
index 467995f90e34187e696ed48292a59c28402f828f..568dd980bc2cc5097b276977a676015482d84318 100644 (file)
@@ -217,6 +217,7 @@ static yasm_arch_machine x86_machines[] = {
 
 /* Define arch structure -- see arch.h for details */
 yasm_arch yasm_x86_LTX_arch = {
+    YASM_ARCH_VERSION,
     "x86 (IA-32 and derivatives), AMD64",
     "x86",
     x86_initialize,
index 9c0d9d6f5a34d111b23f03451f0d28f919ec0c7f..7bc698dedc3d7c33643128fe82256fc2246f13cf 100644 (file)
@@ -25,7 +25,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <util.h>
-/*@unused@*/ RCSID("$IdPath: yasm/modules/dbgfmts/null/null-dbgfmt.c,v 1.8 2003/03/26 05:07:56 peter Exp $");
+/*@unused@*/ RCSID("$IdPath$");
 
 #define YASM_LIB_INTERNAL
 #include <libyasm.h>
@@ -33,6 +33,7 @@
 
 /* Define dbgfmt structure -- see dbgfmt.h for details */
 yasm_dbgfmt yasm_null_LTX_dbgfmt = {
+    YASM_DBGFMT_VERSION,
     "No debugging info",
     "null",
     NULL,   /*null_dbgfmt_initialize*/
index 8f743a857b31044ce9c17a7549e3c0847c850887..2026a18833bebbc021cb52642c0223630cd953f4 100644 (file)
@@ -486,6 +486,7 @@ static const char *bin_objfmt_dbgfmt_keywords[] = {
 
 /* Define objfmt structure -- see objfmt.h for details */
 yasm_objfmt yasm_bin_LTX_objfmt = {
+    YASM_OBJFMT_VERSION,
     "Flat format binary",
     "bin",
     NULL,
index 6b84b14039f3176fc1f9cbdf0168c4a184ff4565..05d35884fd58f3e25a39ba111af38e48a0c6dac3 100644 (file)
@@ -1137,6 +1137,7 @@ static const char *coff_objfmt_dbgfmt_keywords[] = {
 
 /* Define objfmt structure -- see objfmt.h for details */
 yasm_objfmt yasm_coff_LTX_objfmt = {
+    YASM_OBJFMT_VERSION,
     "COFF (DJGPP)",
     "coff",
     "o",
@@ -1162,6 +1163,7 @@ yasm_objfmt yasm_coff_LTX_objfmt = {
 
 /* Define objfmt structure -- see objfmt.h for details */
 yasm_objfmt yasm_win32_LTX_objfmt = {
+    YASM_OBJFMT_VERSION,
     "Win32",
     "win32",
     "obj",
index b02da4b1c184f76f486bd247fadcdfee4f16be56..0b3efff974f185e394785ae3efc86ce655f2b859 100644 (file)
@@ -230,6 +230,7 @@ static const char *dbg_objfmt_dbgfmt_keywords[] = {
 
 /* Define objfmt structure -- see objfmt.h for details */
 yasm_objfmt yasm_dbg_LTX_objfmt = {
+    YASM_OBJFMT_VERSION,
     "Trace of all info passed to object format module",
     "dbg",
     "dbg",
index 2ba9473e6c8572b91b1b359617ef03119112220c..45beb26b99bb1abf3b2cee2c3a7fda6d3048f4c2 100644 (file)
@@ -724,6 +724,7 @@ static const char *elf_objfmt_dbgfmt_keywords[] = {
 
 /* Define objfmt structure -- see objfmt.h for details */
 yasm_objfmt yasm_elf_LTX_objfmt = {
+    YASM_OBJFMT_VERSION,
     "ELF",
     "elf",
     "o",
index f680485a4c843adbd461cfc113c395e4e80f9026..3887a4a6fb17535d01a4be121869ba1a02543f16 100644 (file)
@@ -238,6 +238,7 @@ basic_optimize(yasm_sectionhead *sections)
 
 /* Define optimizer structure -- see optimizer.h for details */
 yasm_optimizer yasm_basic_LTX_optimizer = {
+    YASM_OPTIMIZER_VERSION,
     "Only the most basic optimizations",
     "basic",
     basic_optimize
index 8343750e0d653f0fe28f94c0e859a5cc06b10236..7a50c553bef96c868c80ce3d16ab1edba4682546 100644 (file)
@@ -25,7 +25,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <util.h>
-/*@unused@*/ RCSID("$IdPath: yasm/modules/parsers/nasm/nasm-parser.c,v 1.34 2003/05/04 22:15:09 peter Exp $");
+/*@unused@*/ RCSID("$IdPath$");
 
 #define YASM_LIB_INTERNAL
 #include <libyasm.h>
@@ -89,6 +89,7 @@ static const char *nasm_parser_preproc_keywords[] = {
 
 /* Define parser structure -- see parser.h for details */
 yasm_parser yasm_nasm_LTX_parser = {
+    YASM_PARSER_VERSION,
     "NASM-compatible parser",
     "nasm",
     nasm_parser_preproc_keywords,
index 2ad8e50d3593222514a34678dfbaf081f0a0825a..f43609222450eb1a6f24bca00c12599b8521c15f 100644 (file)
@@ -25,7 +25,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <util.h>
-/*@unused@*/ RCSID("$IdPath: yasm/modules/preprocs/nasm/nasm-preproc.c,v 1.8 2003/04/01 04:06:47 mu Exp $");
+/*@unused@*/ RCSID("$IdPath$");
 
 #define YASM_LIB_INTERNAL
 #include <libyasm.h>
@@ -195,6 +195,7 @@ nasm_preproc_add_include_file (const char *filename)
 
 /* Define preproc structure -- see preproc.h for details */
 yasm_preproc yasm_nasm_LTX_preproc = {
+    YASM_PREPROC_VERSION,
     "Real NASM Preprocessor",
     "nasm",
     nasm_preproc_initialize,
index 4319e7fc44bbf8836109e53a5e8384dd6b80976d..2d837202c34c1a50037909ac266ca2d689bbd595 100644 (file)
@@ -25,7 +25,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <util.h>
-/*@unused@*/ RCSID("$IdPath: yasm/modules/preprocs/raw/raw-preproc.c,v 1.23 2003/04/01 04:06:47 mu Exp $");
+/*@unused@*/ RCSID("$IdPath$");
 
 #define YASM_LIB_INTERNAL
 #include <libyasm.h>
@@ -74,6 +74,7 @@ raw_preproc_input(char *buf, size_t max_size)
 
 /* Define preproc structure -- see preproc.h for details */
 yasm_preproc yasm_raw_LTX_preproc = {
+    YASM_PREPROC_VERSION,
     "Disable preprocessing",
     "raw",
     raw_preproc_initialize,