2011-05-24 01:11:39 +07:00
|
|
|
#ifndef _LINUX_EXPORT_H
|
|
|
|
#define _LINUX_EXPORT_H
|
kbuild: allow archs to select link dead code/data elimination
Introduce LD_DEAD_CODE_DATA_ELIMINATION option for architectures to
select to build with -ffunction-sections, -fdata-sections, and link
with --gc-sections. It requires some work (documented) to ensure all
unreferenced entrypoints are live, and requires toolchain and build
verification, so it is made a per-arch option for now.
On a random powerpc64le build, this yelds a significant size saving,
it boots and runs fine, but there is a lot I haven't tested as yet, so
these savings may be reduced if there are bugs in the link.
text data bss dec filename
11169741 1180744 1923176 14273661 vmlinux
10445269 1004127 1919707 13369103 vmlinux.dce
~700K text, ~170K data, 6% removed from kernel image size.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
2016-08-24 19:29:20 +07:00
|
|
|
|
2011-05-24 01:11:39 +07:00
|
|
|
/*
|
|
|
|
* Export symbols from the kernel to modules. Forked from module.h
|
|
|
|
* to reduce the amount of pointless cruft we feed to gcc when only
|
|
|
|
* exporting a simple symbol or two.
|
|
|
|
*
|
2013-03-15 11:34:17 +07:00
|
|
|
* Try not to add #includes here. It slows compilation and makes kernel
|
|
|
|
* hackers place grumpy comments in header files.
|
2011-05-24 01:11:39 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Some toolchains use a `_' prefix for all user symbols. */
|
2013-03-15 11:34:17 +07:00
|
|
|
#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
|
|
|
|
#define __VMLINUX_SYMBOL(x) _##x
|
|
|
|
#define __VMLINUX_SYMBOL_STR(x) "_" #x
|
2011-05-24 01:11:39 +07:00
|
|
|
#else
|
2013-03-15 11:34:17 +07:00
|
|
|
#define __VMLINUX_SYMBOL(x) x
|
|
|
|
#define __VMLINUX_SYMBOL_STR(x) #x
|
2011-05-24 01:11:39 +07:00
|
|
|
#endif
|
|
|
|
|
2013-03-15 11:34:17 +07:00
|
|
|
/* Indirect, so macros are expanded before pasting. */
|
|
|
|
#define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x)
|
|
|
|
#define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x)
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
2011-05-24 01:11:39 +07:00
|
|
|
struct kernel_symbol
|
|
|
|
{
|
|
|
|
unsigned long value;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef MODULE
|
|
|
|
extern struct module __this_module;
|
|
|
|
#define THIS_MODULE (&__this_module)
|
|
|
|
#else
|
|
|
|
#define THIS_MODULE ((struct module *)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_MODULES
|
|
|
|
|
2016-01-22 13:32:26 +07:00
|
|
|
#if defined(__KERNEL__) && !defined(__GENKSYMS__)
|
2011-05-24 01:11:39 +07:00
|
|
|
#ifdef CONFIG_MODVERSIONS
|
|
|
|
/* Mark the CRC weak since genksyms apparently decides not to
|
|
|
|
* generate a checksums for some symbols */
|
kbuild: allow archs to select link dead code/data elimination
Introduce LD_DEAD_CODE_DATA_ELIMINATION option for architectures to
select to build with -ffunction-sections, -fdata-sections, and link
with --gc-sections. It requires some work (documented) to ensure all
unreferenced entrypoints are live, and requires toolchain and build
verification, so it is made a per-arch option for now.
On a random powerpc64le build, this yelds a significant size saving,
it boots and runs fine, but there is a lot I haven't tested as yet, so
these savings may be reduced if there are bugs in the link.
text data bss dec filename
11169741 1180744 1923176 14273661 vmlinux
10445269 1004127 1919707 13369103 vmlinux.dce
~700K text, ~170K data, 6% removed from kernel image size.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
2016-08-24 19:29:20 +07:00
|
|
|
#define __CRC_SYMBOL(sym, sec) \
|
|
|
|
extern __visible void *__crc_##sym __attribute__((weak)); \
|
|
|
|
static const unsigned long __kcrctab_##sym \
|
|
|
|
__used \
|
|
|
|
__attribute__((section("___kcrctab" sec "+" #sym), used)) \
|
2011-05-24 01:11:39 +07:00
|
|
|
= (unsigned long) &__crc_##sym;
|
|
|
|
#else
|
|
|
|
#define __CRC_SYMBOL(sym, sec)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* For every exported symbol, place a struct in the __ksymtab section */
|
kbuild: allow archs to select link dead code/data elimination
Introduce LD_DEAD_CODE_DATA_ELIMINATION option for architectures to
select to build with -ffunction-sections, -fdata-sections, and link
with --gc-sections. It requires some work (documented) to ensure all
unreferenced entrypoints are live, and requires toolchain and build
verification, so it is made a per-arch option for now.
On a random powerpc64le build, this yelds a significant size saving,
it boots and runs fine, but there is a lot I haven't tested as yet, so
these savings may be reduced if there are bugs in the link.
text data bss dec filename
11169741 1180744 1923176 14273661 vmlinux
10445269 1004127 1919707 13369103 vmlinux.dce
~700K text, ~170K data, 6% removed from kernel image size.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
2016-08-24 19:29:20 +07:00
|
|
|
#define ___EXPORT_SYMBOL(sym, sec) \
|
|
|
|
extern typeof(sym) sym; \
|
|
|
|
__CRC_SYMBOL(sym, sec) \
|
|
|
|
static const char __kstrtab_##sym[] \
|
|
|
|
__attribute__((section("__ksymtab_strings"), aligned(1))) \
|
|
|
|
= VMLINUX_SYMBOL_STR(sym); \
|
|
|
|
static const struct kernel_symbol __ksymtab_##sym \
|
|
|
|
__used \
|
|
|
|
__attribute__((section("___ksymtab" sec "+" #sym), used)) \
|
2011-05-24 01:11:39 +07:00
|
|
|
= { (unsigned long)&sym, __kstrtab_##sym }
|
|
|
|
|
kbuild: add fine grained build dependencies for exported symbols
Like with kconfig options, we now have the ability to compile in and
out individual EXPORT_SYMBOL() declarations based on the content of
include/generated/autoksyms.h. However we don't want the entire
world to be rebuilt whenever that file is touched.
Let's apply the same build dependency trick used for CONFIG_* symbols
where the time stamp of empty files whose paths matching those symbols
is used to trigger fine grained rebuilds. In our case the key is the
symbol name passed to EXPORT_SYMBOL().
However, unlike config options, we cannot just use fixdep to parse
the source code for EXPORT_SYMBOL(ksym) because several variants exist
and parsing them all in a separate tool, and keeping it in synch, is
not trivially maintainable. Furthermore, there are variants such as
EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
that are instanciated via a macro for which we can't easily determine
the actual exported symbol name(s) short of actually running the
preprocessor on them.
Storing the symbol name string in a special ELF section doesn't work
for targets that output assembly or preprocessed source.
So the best way is really to leverage the preprocessor by having it
output actual symbol names anchored by a special sequence that can be
easily filtered out. Then the list of symbols is simply fed to fixdep
to be merged with the other dependencies.
That implies the preprocessor is executed twice for each source file.
A previous attempt relied on a warning pragma for each EXPORT_SYMBOL()
instance that was filtered apart from stderr by the build system with
a sed script during the actual compilation pass. Unfortunately the
preprocessor/compiler diagnostic output isn't stable between versions
and this solution, although more efficient, was deemed too fragile.
Because of the lowercasing performed by fixdep, there might be name
collisions triggering spurious rebuilds for similar symbols. But this
shouldn't be a big issue in practice. (This is the case for CONFIG_*
symbols and I didn't want to be different here, whatever the original
reason for doing so.)
To avoid needless build overhead, the exported symbol name gathering is
performed only when CONFIG_TRIM_UNUSED_KSYMS is selected.
Signed-off-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-23 01:41:57 +07:00
|
|
|
#if defined(__KSYM_DEPS__)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For fine grained build dependencies, we want to tell the build system
|
|
|
|
* about each possible exported symbol even if they're not actually exported.
|
|
|
|
* We use a string pattern that is unlikely to be valid code that the build
|
|
|
|
* system filters out from the preprocessor output (see ksym_dep_filter
|
|
|
|
* in scripts/Kbuild.include).
|
|
|
|
*/
|
|
|
|
#define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym ===
|
|
|
|
|
|
|
|
#elif defined(CONFIG_TRIM_UNUSED_KSYMS)
|
2016-01-22 13:32:26 +07:00
|
|
|
|
|
|
|
#include <generated/autoksyms.h>
|
|
|
|
|
|
|
|
#define __EXPORT_SYMBOL(sym, sec) \
|
2016-06-14 12:58:55 +07:00
|
|
|
__cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
|
2016-01-22 13:32:26 +07:00
|
|
|
#define __cond_export_sym(sym, sec, conf) \
|
|
|
|
___cond_export_sym(sym, sec, conf)
|
|
|
|
#define ___cond_export_sym(sym, sec, enabled) \
|
|
|
|
__cond_export_sym_##enabled(sym, sec)
|
|
|
|
#define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
|
|
|
|
#define __cond_export_sym_0(sym, sec) /* nothing */
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define __EXPORT_SYMBOL ___EXPORT_SYMBOL
|
|
|
|
#endif
|
|
|
|
|
2011-05-24 01:11:39 +07:00
|
|
|
#define EXPORT_SYMBOL(sym) \
|
|
|
|
__EXPORT_SYMBOL(sym, "")
|
|
|
|
|
|
|
|
#define EXPORT_SYMBOL_GPL(sym) \
|
|
|
|
__EXPORT_SYMBOL(sym, "_gpl")
|
|
|
|
|
|
|
|
#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
|
|
|
|
__EXPORT_SYMBOL(sym, "_gpl_future")
|
|
|
|
|
|
|
|
#ifdef CONFIG_UNUSED_SYMBOLS
|
|
|
|
#define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
|
|
|
|
#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
|
|
|
|
#else
|
|
|
|
#define EXPORT_UNUSED_SYMBOL(sym)
|
|
|
|
#define EXPORT_UNUSED_SYMBOL_GPL(sym)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __GENKSYMS__ */
|
|
|
|
|
|
|
|
#else /* !CONFIG_MODULES... */
|
|
|
|
|
|
|
|
#define EXPORT_SYMBOL(sym)
|
|
|
|
#define EXPORT_SYMBOL_GPL(sym)
|
|
|
|
#define EXPORT_SYMBOL_GPL_FUTURE(sym)
|
|
|
|
#define EXPORT_UNUSED_SYMBOL(sym)
|
|
|
|
#define EXPORT_UNUSED_SYMBOL_GPL(sym)
|
|
|
|
|
|
|
|
#endif /* CONFIG_MODULES */
|
2013-03-15 11:34:17 +07:00
|
|
|
#endif /* !__ASSEMBLY__ */
|
2011-05-24 01:11:39 +07:00
|
|
|
|
|
|
|
#endif /* _LINUX_EXPORT_H */
|