patch 2.1.19 to detect invalid EXPORT_SYMBOL

Keith Owens (kaos@ocs.com.au)
Thu, 02 Jan 1997 22:29:01 +1100


2.1.19 silently fails to EXPORT_SYMBOL if autoconf.h is not included
before module.h, normally by including config.h. The fix of changing
module.h to unconditionally include config.h affects modules that do
not really need this inclusion because they do not export symbols. The
problem really only affects those sources that use EXPORT_SYMBOL *and*
have incorrect includes.

Detecting the problem in mkdep is a bit messy. mkdep would have to
remember the order of config.h and module.h, it would also have to
recognise the EXPORT_SYMBOL macros. Adding new macros means changing
mkdep. Not really worth slowing down the dependency process.

This patch will only affect the offending sources, they will fail to
compile. The error message that appears is not perfect but it will do
the job. If the includes are in the wrong order you get messages like

source:line: parse error before `config_must_be_included_before_module'
source:line: warning: data definition has no type or storage class

for each EXPORT_SYMBOL and similar macros.

diff -ur linux-2.1.19/include/linux/module.h linux/include/linux/module.h
--- linux-2.1.19/include/linux/module.h Wed Jan 1 19:33:01 1997
+++ linux/include/linux/module.h Thu Jan 2 22:04:33 1997
@@ -183,6 +183,12 @@

/* We want the EXPORT_SYMBOL tag left intact for recognition. */

+#elif !defined(AUTOCONF_INCLUDED)
+
+#define EXPORT_SYMBOL(var) error config_must_be_included_before_module
+#define EXPORT_SYMBOL_NOVERS(var) error config_must_be_included_before_module
+#define EXPORT_NO_SYMBOLS error config_must_be_included_before_module
+
#elif !defined(CONFIG_MODULES)

#define EXPORT_SYMBOL(var)
diff -ur linux-2.1.19/scripts/Configure linux/scripts/Configure
--- linux-2.1.19/scripts/Configure Fri May 31 20:46:27 1996
+++ linux/scripts/Configure Thu Jan 2 20:14:34 1997
@@ -422,6 +422,7 @@
echo "/*" > $CONFIG_H
echo " * Automatically generated C config: don't edit" >> $CONFIG_H
echo " */" >> $CONFIG_H
+echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H

DEFAULT=""
if [ "$1" = "-d" ] ; then
diff -ur linux-2.1.19/scripts/Menuconfig linux/scripts/Menuconfig
--- linux-2.1.19/scripts/Menuconfig Wed Oct 30 02:38:07 1996
+++ linux/scripts/Menuconfig Thu Jan 2 20:16:38 1997
@@ -1020,6 +1020,7 @@
echo "/*" >$CONFIG_H
echo " * Automatically generated by make menuconfig: don't edit" >>$CONFIG_H
echo " */" >>$CONFIG_H
+ echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H

MAKE=: #To prevent sound Makefile from running.

diff -ur linux-2.1.19/scripts/tkgen.c linux/scripts/tkgen.c
--- linux-2.1.19/scripts/tkgen.c Thu Jun 6 20:30:41 1996
+++ linux/scripts/tkgen.c Thu Jan 2 20:16:25 1997
@@ -978,6 +978,7 @@
printf("\tputs $autocfg \"/*\"\n");
printf("\tputs $autocfg \" * Automatically generated C config: don't edit\"\n");
printf("\tputs $autocfg \" */\"\n");
+ printf("\tputs $autocfg \"#define AUTOCONF_INCLUDED\"\n");
for(cfg = scfg; cfg != NULL; cfg = cfg->next)
{
switch (cfg->tok)