diff --git a/build_tools/make_buildopts_h b/build_tools/make_buildopts_h
index 0be011744c358aa7eefb3270ec6d0f4d27006a12..fc7fdd2c9da7fbebf89a1969098996dafcec8b7e 100755
--- a/build_tools/make_buildopts_h
+++ b/build_tools/make_buildopts_h
@@ -19,4 +19,7 @@ done
 if ${GREP} AST_DEVMODE makeopts | ${GREP} -q yes
 then
 	echo "#define AST_DEVMODE 1"
+	TMP="${TMP} AST_DEVMODE"
 fi
+BUILDSUM=`echo ${TMP} | md5sum`
+echo "#define AST_BUILDOPT_SUM {0x${BUILDSUM:0:8}, 0x${BUILDSUM:8:8}, 0x${BUILDSUM:16:8}, 0x${BUILDSUM:24:8}}"
diff --git a/include/asterisk/module.h b/include/asterisk/module.h
index 4c6cc507b2ea4444dd7ee5bc5b69e97fce8e6ce7..119ae88f06471152a109591f92e930108564e2e2 100644
--- a/include/asterisk/module.h
+++ b/include/asterisk/module.h
@@ -216,6 +216,7 @@ struct ast_module_info {
 
 	const char *key;
 	unsigned int flags;
+	unsigned int buildopt_sum[4];		/* The value of AST_BUILDOPT_SUM when this module was compiled */
 };
 
 void ast_module_register(const struct ast_module_info *);
@@ -242,7 +243,8 @@ void ast_module_unref(struct ast_module *);
 		AST_MODULE,				\
 		desc,					\
 		keystr,					\
-		flags_to_set				\
+		flags_to_set,				\
+		AST_BUILDOPT_SUM,			\
 	};						\
 	static void  __attribute__ ((constructor)) __reg_module(void) \
 	{ \
@@ -343,6 +345,7 @@ static void __restore_globals(void)
 		.flags = flags_to_set,				\
 		.description = desc,				\
 		.key = keystr,					\
+		.buildopt_sum = AST_BUILDOPT_SUM,		\
 		fields						\
 	};							\
 	static void  __attribute__ ((constructor)) __reg_module(void) \
diff --git a/main/loader.c b/main/loader.c
index e51505ea073766663627aa442c6938e56ccf095a..b51888dbea4193850090ceb74ecb68a95156c293 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -76,6 +76,8 @@ static unsigned char expected_key[] =
 { 0x87, 0x76, 0x79, 0x35, 0x23, 0xea, 0x3a, 0xd3,
   0x25, 0x2a, 0xbb, 0x35, 0x87, 0xe4, 0x22, 0x24 };
 
+static unsigned int buildopt_sum[4] = AST_BUILDOPT_SUM;
+
 static unsigned int embedding = 1; /* we always start out by registering embedded modules,
 				      since they are here before we dlopen() any
 				   */
@@ -603,6 +605,8 @@ int ast_module_reload(const char *name)
 
 static unsigned int inspect_module(const struct ast_module *mod)
 {
+	unsigned int buildopt_empty[4] = { 0, };
+
 	if (!mod->info->description) {
 		ast_log(LOG_WARNING, "Module '%s' does not provide a description.\n", mod->resource);
 		return 1;
@@ -618,6 +622,13 @@ static unsigned int inspect_module(const struct ast_module *mod)
 		return 1;
 	}
 
+	if (memcmp(buildopt_empty, mod->info->buildopt_sum, sizeof(buildopt_empty)) &&
+	    memcmp(buildopt_sum, mod->info->buildopt_sum, sizeof(buildopt_sum))) {
+		ast_log(LOG_WARNING, "Module '%s' was not compiled with the same compile-time options as this version of Asterisk.\n", mod->resource);
+		ast_log(LOG_WARNING, "Module '%s' will not be initialized as it may cause instability.\n", mod->resource);
+		return 1;
+	}
+
 	return 0;
 }