Commit 24c58229 authored by Stephan Herhut's avatar Stephan Herhut
Browse files

the module system now keeps track of certain commandline

arguments that are used to build libraries. In case an
incompatible set of flags was used, the module system
will refuse to compile the source and give an error 
message. As this change made a new module format neccessary,
everyone will have to recompile his stdlib once more.
parent 2c8125bc
......@@ -14,6 +14,15 @@
* global_t is generated from globals.mac and in globals.c where the
* initialization code again is generated from globals.mac.
*
* We define a macro GLOBALS_MODFLAGS here that evaluates to an integer
* describing the state of some flags in the globals structure. It should
* contain all those flags that might lead to incompatible code generation
* when toggled. Make sure that each incompatible configuration leads to a
* distinct value.
*
* To be able to give some account on the used settings, we define
* GLOBALS_MODFLAGS_TEXT( flags) that evaluates to a string depending
* on the settings used.
*/
#ifndef _SAC_GLOBALS_H_
......@@ -22,6 +31,9 @@
#include "types.h"
#include <stdio.h>
#define GLOBALS_MODFLAGS (global.optimize.dophm)
#define GLOBALS_MODFLAGS_TEXT(n) ((n == 1) ? "PHM enabled" : "PHM disabled")
extern FILE *yyin;
extern global_t global;
......
......@@ -33,16 +33,17 @@ typedef sttable_t *(*symtabfun_p) ();
typedef stringset_t *(*deptabfun_p) ();
typedef const char *(*astversionfun_p) ();
typedef int (*serversionfun_p) ();
typedef int (*flagfun_p) ();
typedef void (*nsmapfun_p) ();
static bool
hasSameASTVersion (module_t *module)
static void
checkHasSameASTVersion (module_t *module)
{
astversionfun_p astverfun;
serversionfun_p serverfun;
char *name;
DBUG_ENTER ("hasSameASTVersion");
DBUG_ENTER ("checkHasSameASTVersion");
name = ILIBmalloc (sizeof (char) * (strlen (module->name) + 14));
sprintf (name, "__%s_ASTVERSION", module->name);
......@@ -55,6 +56,13 @@ hasSameASTVersion (module_t *module)
module->name);
}
if (!ILIBstringCompare (astverfun (), build_ast)) {
CTIabort ("The module '%s' uses an incompatible syntax tree layout. "
"Please update the module and compiler to the most "
"recent version.",
module->name);
}
sprintf (name, "__%s_SERIALIZER", module->name);
serverfun = (serversionfun_p)LIBMgetLibraryFunction (name, module->lib);
......@@ -67,8 +75,44 @@ hasSameASTVersion (module_t *module)
name = ILIBfree (name);
DBUG_RETURN ((serverfun () == SAC_SERIALIZE_VERSION)
&& ILIBstringCompare (astverfun (), build_ast));
if (!(serverfun () == SAC_SERIALIZE_VERSION)) {
CTIabort ("The module '%s' uses an incompatible serialisation algorithm. "
"Please update the module and compiler to the most "
"recent version.",
module->name);
}
DBUG_VOID_RETURN;
}
static void
checkWasBuildUsingSameFlags (module_t *module)
{
flagfun_p flagfun;
char *name;
DBUG_ENTER ("wasBuildUsingSameFlags");
name = ILIBmalloc (sizeof (char) * (strlen (module->name) + 13));
sprintf (name, "__%s_USEDFLAGS", module->name);
flagfun = (flagfun_p)LIBMgetLibraryFunction (name, module->lib);
if (flagfun == NULL) {
CTIabort ("The module '%s' is either corrupted or uses an outdated "
"file format.",
module->name);
}
if (!(flagfun () == GLOBALS_MODFLAGS)) {
CTIabort ("The module '%s' was built using incompatible compiler "
"settings. The settings were [%s]. Please recompile the "
"module using the current settings or switch the "
"settings used when compiling the module.",
module->name, GLOBALS_MODFLAGS_TEXT (flagfun ()));
}
DBUG_VOID_RETURN;
}
static void
......@@ -151,11 +195,8 @@ AddModuleToPool (const char *name)
LIBMgetError ());
}
if (!hasSameASTVersion (result)) {
CTIabort ("Module `%s' [%s] was compiled using an incompatible version of "
"sac2c.",
name, result->sofile);
}
checkHasSameASTVersion (result);
checkWasBuildUsingSameFlags (result);
addNamespaceMappings (result);
......
......@@ -145,6 +145,11 @@ GenerateSerFileVersionInfo (node *module, FILE *file)
" return( %d); \n}\n\n",
NSgetName (MODULE_NAMESPACE (module)), SAC_SERIALIZE_VERSION);
fprintf (file,
"int __%s_USEDFLAGS() {\n"
" return( %d); \n}\n\n",
NSgetName (MODULE_NAMESPACE (module)), GLOBALS_MODFLAGS);
DBUG_VOID_RETURN;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment