Skip to content

Commit f501693

Browse files
author
Paul Gortmaker
committed
module.h: split out the EXPORT_SYMBOL into export.h
A lot of files pull in module.h when all they are really looking for is the basic EXPORT_SYMBOL functionality. The recent data from Ingo[1] shows that this is one of several instances that has a significant impact on compile times, and it should be targeted for factoring out (as done here). Note that several commonly used header files in include/* directly include <linux/module.h> themselves (some 34 of them!) The most commonly used ones of these will have to be made independent of module.h before the full benefit of this change can be realized. We also transition THIS_MODULE from module.h to export.h, since there are lots of files with subsystem structs that in turn will have a struct module *owner and only be doing: .owner = THIS_MODULE; and absolutely nothing else modular. So, we also want to have the THIS_MODULE definition present in the lightweight header. [1] https://lkml.org/lkml/2011/5/23/76 Signed-off-by: Paul Gortmaker <[email protected]>
1 parent 839d881 commit f501693

File tree

2 files changed

+90
-67
lines changed

2 files changed

+90
-67
lines changed

include/linux/export.h

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#ifndef _LINUX_EXPORT_H
2+
#define _LINUX_EXPORT_H
3+
/*
4+
* Export symbols from the kernel to modules. Forked from module.h
5+
* to reduce the amount of pointless cruft we feed to gcc when only
6+
* exporting a simple symbol or two.
7+
*
8+
* If you feel the need to add #include <linux/foo.h> to this file
9+
* then you are doing something wrong and should go away silently.
10+
*/
11+
12+
/* Some toolchains use a `_' prefix for all user symbols. */
13+
#ifdef CONFIG_SYMBOL_PREFIX
14+
#define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
15+
#else
16+
#define MODULE_SYMBOL_PREFIX ""
17+
#endif
18+
19+
struct kernel_symbol
20+
{
21+
unsigned long value;
22+
const char *name;
23+
};
24+
25+
#ifdef MODULE
26+
extern struct module __this_module;
27+
#define THIS_MODULE (&__this_module)
28+
#else
29+
#define THIS_MODULE ((struct module *)0)
30+
#endif
31+
32+
#ifdef CONFIG_MODULES
33+
34+
#ifndef __GENKSYMS__
35+
#ifdef CONFIG_MODVERSIONS
36+
/* Mark the CRC weak since genksyms apparently decides not to
37+
* generate a checksums for some symbols */
38+
#define __CRC_SYMBOL(sym, sec) \
39+
extern void *__crc_##sym __attribute__((weak)); \
40+
static const unsigned long __kcrctab_##sym \
41+
__used \
42+
__attribute__((section("___kcrctab" sec "+" #sym), unused)) \
43+
= (unsigned long) &__crc_##sym;
44+
#else
45+
#define __CRC_SYMBOL(sym, sec)
46+
#endif
47+
48+
/* For every exported symbol, place a struct in the __ksymtab section */
49+
#define __EXPORT_SYMBOL(sym, sec) \
50+
extern typeof(sym) sym; \
51+
__CRC_SYMBOL(sym, sec) \
52+
static const char __kstrtab_##sym[] \
53+
__attribute__((section("__ksymtab_strings"), aligned(1))) \
54+
= MODULE_SYMBOL_PREFIX #sym; \
55+
static const struct kernel_symbol __ksymtab_##sym \
56+
__used \
57+
__attribute__((section("___ksymtab" sec "+" #sym), unused)) \
58+
= { (unsigned long)&sym, __kstrtab_##sym }
59+
60+
#define EXPORT_SYMBOL(sym) \
61+
__EXPORT_SYMBOL(sym, "")
62+
63+
#define EXPORT_SYMBOL_GPL(sym) \
64+
__EXPORT_SYMBOL(sym, "_gpl")
65+
66+
#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
67+
__EXPORT_SYMBOL(sym, "_gpl_future")
68+
69+
#ifdef CONFIG_UNUSED_SYMBOLS
70+
#define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
71+
#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
72+
#else
73+
#define EXPORT_UNUSED_SYMBOL(sym)
74+
#define EXPORT_UNUSED_SYMBOL_GPL(sym)
75+
#endif
76+
77+
#endif /* __GENKSYMS__ */
78+
79+
#else /* !CONFIG_MODULES... */
80+
81+
#define EXPORT_SYMBOL(sym)
82+
#define EXPORT_SYMBOL_GPL(sym)
83+
#define EXPORT_SYMBOL_GPL_FUTURE(sym)
84+
#define EXPORT_UNUSED_SYMBOL(sym)
85+
#define EXPORT_UNUSED_SYMBOL_GPL(sym)
86+
87+
#endif /* CONFIG_MODULES */
88+
89+
#endif /* _LINUX_EXPORT_H */

include/linux/module.h

+1-67
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/kobject.h>
1717
#include <linux/moduleparam.h>
1818
#include <linux/tracepoint.h>
19+
#include <linux/export.h>
1920

2021
#include <linux/percpu.h>
2122
#include <asm/module.h>
@@ -25,21 +26,8 @@
2526
/* Not Yet Implemented */
2627
#define MODULE_SUPPORTED_DEVICE(name)
2728

28-
/* Some toolchains use a `_' prefix for all user symbols. */
29-
#ifdef CONFIG_SYMBOL_PREFIX
30-
#define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
31-
#else
32-
#define MODULE_SYMBOL_PREFIX ""
33-
#endif
34-
3529
#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
3630

37-
struct kernel_symbol
38-
{
39-
unsigned long value;
40-
const char *name;
41-
};
42-
4331
struct modversion_info
4432
{
4533
unsigned long crc;
@@ -98,11 +86,8 @@ void trim_init_extable(struct module *m);
9886
extern const struct gtype##_id __mod_##gtype##_table \
9987
__attribute__ ((unused, alias(__stringify(name))))
10088

101-
extern struct module __this_module;
102-
#define THIS_MODULE (&__this_module)
10389
#else /* !MODULE */
10490
#define MODULE_GENERIC_TABLE(gtype,name)
105-
#define THIS_MODULE ((struct module *)0)
10691
#endif
10792

10893
/* Generic info of form tag = "info" */
@@ -218,52 +203,6 @@ struct module_use {
218203
struct module *source, *target;
219204
};
220205

221-
#ifndef __GENKSYMS__
222-
#ifdef CONFIG_MODVERSIONS
223-
/* Mark the CRC weak since genksyms apparently decides not to
224-
* generate a checksums for some symbols */
225-
#define __CRC_SYMBOL(sym, sec) \
226-
extern void *__crc_##sym __attribute__((weak)); \
227-
static const unsigned long __kcrctab_##sym \
228-
__used \
229-
__attribute__((section("___kcrctab" sec "+" #sym), unused)) \
230-
= (unsigned long) &__crc_##sym;
231-
#else
232-
#define __CRC_SYMBOL(sym, sec)
233-
#endif
234-
235-
/* For every exported symbol, place a struct in the __ksymtab section */
236-
#define __EXPORT_SYMBOL(sym, sec) \
237-
extern typeof(sym) sym; \
238-
__CRC_SYMBOL(sym, sec) \
239-
static const char __kstrtab_##sym[] \
240-
__attribute__((section("__ksymtab_strings"), aligned(1))) \
241-
= MODULE_SYMBOL_PREFIX #sym; \
242-
static const struct kernel_symbol __ksymtab_##sym \
243-
__used \
244-
__attribute__((section("___ksymtab" sec "+" #sym), unused)) \
245-
= { (unsigned long)&sym, __kstrtab_##sym }
246-
247-
#define EXPORT_SYMBOL(sym) \
248-
__EXPORT_SYMBOL(sym, "")
249-
250-
#define EXPORT_SYMBOL_GPL(sym) \
251-
__EXPORT_SYMBOL(sym, "_gpl")
252-
253-
#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
254-
__EXPORT_SYMBOL(sym, "_gpl_future")
255-
256-
257-
#ifdef CONFIG_UNUSED_SYMBOLS
258-
#define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
259-
#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
260-
#else
261-
#define EXPORT_UNUSED_SYMBOL(sym)
262-
#define EXPORT_UNUSED_SYMBOL_GPL(sym)
263-
#endif
264-
265-
#endif
266-
267206
enum module_state
268207
{
269208
MODULE_STATE_LIVE,
@@ -581,11 +520,6 @@ int unregister_module_notifier(struct notifier_block * nb);
581520
extern void print_modules(void);
582521

583522
#else /* !CONFIG_MODULES... */
584-
#define EXPORT_SYMBOL(sym)
585-
#define EXPORT_SYMBOL_GPL(sym)
586-
#define EXPORT_SYMBOL_GPL_FUTURE(sym)
587-
#define EXPORT_UNUSED_SYMBOL(sym)
588-
#define EXPORT_UNUSED_SYMBOL_GPL(sym)
589523

590524
/* Given an address, look for it in the exception tables. */
591525
static inline const struct exception_table_entry *

0 commit comments

Comments
 (0)