A question about a MACRO,EXPORT_SYMBOL

cheng long kevinclcn@gmail.com
Sun Apr 23 02:48:00 GMT 2006


Hi, ALL!

In Linux 2.6.11, there is a EXPORT_SYMBOL in <linux/module.h>.

192 #define __EXPORT_SYMBOL(sym, sec) \
193 __CRC_SYMBOL(sym, sec) \
194 static const char __kstrtab_##sym[] \
195 __attribute__((section("__ksymtab_strings"))) \
196 = MODULE_SYMBOL_PREFIX #sym; \
197 static const struct kernel_symbol __ksymtab_##sym \
198 __attribute_used__ \
199 __attribute__((section("__ksymtab" sec), unused)) \
200 = { (unsigned long)&sym, __kstrtab_##sym }

202 #define EXPORT_SYMBOL(sym) \
203 __EXPORT_SYMBOL(sym, "")

29 #ifndef MODULE_SYMBOL_PREFIX
30 #define MODULE_SYMBOL_PREFIX ""
31 #endif

I've simplified as follows.

1 #define EXPORT_SYMBOL(sym) \
2 static const char __kstrtabe_##sym[]=#sym; \
3 static const struct kernel_symbol_ksymtab_##sym \
4 = { (unsigned long)&sym, __kstrtab_##sym }

My questions are:
1.   What's the "#" mean in line 2?
2.   If the sym is a function, which is a address, the MACRO can't work.
      For example,
         int func(){ return 1 }
         EXPORT_SYMBOL(func);
3    How does it known the sym is not a "static" function, or, if sym is a
      static function, what happend?



Thank you very much!

Regards
Cheng



More information about the Gcc-help mailing list