mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
When CONFIG_TRIM_UNUSED_KSYMS is enabled, Kbuild recursively traverses the directory tree to determine which EXPORT_SYMBOL to trim. If an EXPORT_SYMBOL turns out to be unused by anyone, Kbuild begins the second traverse, where some source files are recompiled with their EXPORT_SYMBOL() tuned into a no-op. Linus stated negative opinions about this slowness in commits: -5cf0fd591f
("Kbuild: disable TRIM_UNUSED_KSYMS option") -a555bdd0c5
("Kbuild: enable TRIM_UNUSED_KSYMS again, with some guarding") We can do this better now. The final data structures of EXPORT_SYMBOL are generated by the modpost stage, so modpost can selectively emit KSYMTAB entries that are really used by modules. Commitf73edc8951
("kbuild: unify two modpost invocations") is another ground-work to do this in a one-pass algorithm. With the list of modules, modpost sets sym->used if it is used by a module. modpost emits KSYMTAB only for symbols with sym->used==true. BTW, Nicolas explained why the trimming was implemented with recursion: https://lore.kernel.org/all/2o2rpn97-79nq-p7s2-nq5-8p83391473r@syhkavp.arg/ Actually, we never achieved that level of optimization where the chain reaction of trimming comes into play because: - CONFIG_LTO_CLANG cannot remove any unused symbols - CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled only for vmlinux, but not modules If deeper trimming is required, we need to revisit this, but I guess that is unlikely to happen. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
92 lines
2.4 KiB
C
92 lines
2.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
#ifndef _LINUX_EXPORT_H
|
|
#define _LINUX_EXPORT_H
|
|
|
|
#include <linux/compiler.h>
|
|
#include <linux/linkage.h>
|
|
#include <linux/stringify.h>
|
|
|
|
/*
|
|
* 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.
|
|
*
|
|
* Try not to add #includes here. It slows compilation and makes kernel
|
|
* hackers place grumpy comments in header files.
|
|
*/
|
|
|
|
/*
|
|
* This comment block is used by fixdep. Please do not remove.
|
|
*
|
|
* When CONFIG_MODVERSIONS is changed from n to y, all source files having
|
|
* EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
|
|
* side effect of the *.o build rule.
|
|
*/
|
|
|
|
#ifndef __ASSEMBLY__
|
|
#ifdef MODULE
|
|
extern struct module __this_module;
|
|
#define THIS_MODULE (&__this_module)
|
|
#else
|
|
#define THIS_MODULE ((struct module *)0)
|
|
#endif
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#ifdef CONFIG_64BIT
|
|
#define __EXPORT_SYMBOL_REF(sym) \
|
|
.balign 8 ASM_NL \
|
|
.quad sym
|
|
#else
|
|
#define __EXPORT_SYMBOL_REF(sym) \
|
|
.balign 4 ASM_NL \
|
|
.long sym
|
|
#endif
|
|
|
|
#define ___EXPORT_SYMBOL(sym, license, ns) \
|
|
.section ".export_symbol","a" ASM_NL \
|
|
__export_symbol_##sym: ASM_NL \
|
|
.asciz license ASM_NL \
|
|
.asciz ns ASM_NL \
|
|
__EXPORT_SYMBOL_REF(sym) ASM_NL \
|
|
.previous
|
|
|
|
#if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
|
|
|
|
/*
|
|
* Allow symbol exports to be disabled completely so that C code may
|
|
* be reused in other execution contexts such as the UEFI stub or the
|
|
* decompressor.
|
|
*/
|
|
#define __EXPORT_SYMBOL(sym, sec, ns)
|
|
|
|
#elif defined(__GENKSYMS__)
|
|
|
|
#define __EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
|
|
|
|
#elif defined(__ASSEMBLY__)
|
|
|
|
#define __EXPORT_SYMBOL(sym, license, ns) \
|
|
___EXPORT_SYMBOL(sym, license, ns)
|
|
|
|
#else
|
|
|
|
#define __EXPORT_SYMBOL(sym, license, ns) \
|
|
extern typeof(sym) sym; \
|
|
__ADDRESSABLE(sym) \
|
|
asm(__stringify(___EXPORT_SYMBOL(sym, license, ns)))
|
|
|
|
#endif /* CONFIG_MODULES */
|
|
|
|
#ifdef DEFAULT_SYMBOL_NAMESPACE
|
|
#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, __stringify(DEFAULT_SYMBOL_NAMESPACE))
|
|
#else
|
|
#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
|
|
#endif
|
|
|
|
#define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
|
|
#define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "GPL")
|
|
#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", __stringify(ns))
|
|
#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "GPL", __stringify(ns))
|
|
|
|
#endif /* _LINUX_EXPORT_H */
|