]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/export.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[mirror_ubuntu-jammy-kernel.git] / include / linux / export.h
CommitLineData
bf49d9dd 1/* SPDX-License-Identifier: GPL-2.0-only */
f5016932
PG
2#ifndef _LINUX_EXPORT_H
3#define _LINUX_EXPORT_H
b67067f1 4
f5016932
PG
5/*
6 * Export symbols from the kernel to modules. Forked from module.h
7 * to reduce the amount of pointless cruft we feed to gcc when only
8 * exporting a simple symbol or two.
9 *
b92021b0
RR
10 * Try not to add #includes here. It slows compilation and makes kernel
11 * hackers place grumpy comments in header files.
f5016932
PG
12 */
13
b92021b0 14#ifndef __ASSEMBLY__
f5016932
PG
15#ifdef MODULE
16extern struct module __this_module;
17#define THIS_MODULE (&__this_module)
18#else
19#define THIS_MODULE ((struct module *)0)
20#endif
21
f5016932
PG
22#ifdef CONFIG_MODVERSIONS
23/* Mark the CRC weak since genksyms apparently decides not to
24 * generate a checksums for some symbols */
71810db2
AB
25#if defined(CONFIG_MODULE_REL_CRCS)
26#define __CRC_SYMBOL(sym, sec) \
27 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
94e58e0a
MY
28 " .weak __crc_" #sym " \n" \
29 " .long __crc_" #sym " - . \n" \
8651ec01 30 " .previous \n")
f5016932 31#else
71810db2
AB
32#define __CRC_SYMBOL(sym, sec) \
33 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
94e58e0a
MY
34 " .weak __crc_" #sym " \n" \
35 " .long __crc_" #sym " \n" \
8651ec01 36 " .previous \n")
71810db2
AB
37#endif
38#else
f5016932
PG
39#define __CRC_SYMBOL(sym, sec)
40#endif
41
7290d580
AB
42#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
43#include <linux/compiler.h>
44/*
45 * Emit the ksymtab entry as a pair of relative references: this reduces
46 * the size by half on 64-bit architectures, and eliminates the need for
47 * absolute relocations that require runtime processing on relocatable
48 * kernels.
49 */
c3a6cf19 50#define __KSYMTAB_ENTRY(sym, sec) \
8651ec01
MM
51 __ADDRESSABLE(sym) \
52 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
53 " .balign 4 \n" \
69923208 54 "__ksymtab_" #sym ": \n" \
8651ec01
MM
55 " .long " #sym "- . \n" \
56 " .long __kstrtab_" #sym "- . \n" \
fa6643cd 57 " .long __kstrtabns_" #sym "- . \n" \
8651ec01
MM
58 " .previous \n")
59
7290d580
AB
60struct kernel_symbol {
61 int value_offset;
62 int name_offset;
8651ec01 63 int namespace_offset;
7290d580
AB
64};
65#else
66#define __KSYMTAB_ENTRY(sym, sec) \
67 static const struct kernel_symbol __ksymtab_##sym \
68 __attribute__((section("___ksymtab" sec "+" #sym), used)) \
ed13fc33 69 __aligned(sizeof(void *)) \
c3a6cf19 70 = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
7290d580
AB
71
72struct kernel_symbol {
73 unsigned long value;
74 const char *name;
8651ec01 75 const char *namespace;
7290d580
AB
76};
77#endif
78
69a94abb
MY
79#ifdef __GENKSYMS__
80
c3a6cf19 81#define ___EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
69a94abb
MY
82
83#else
84
c3a6cf19
MY
85/* For every exported symbol, place a struct in the __ksymtab section */
86#define ___EXPORT_SYMBOL(sym, sec, ns) \
b67067f1 87 extern typeof(sym) sym; \
8651ec01 88 __CRC_SYMBOL(sym, sec); \
b67067f1 89 static const char __kstrtab_##sym[] \
7290d580 90 __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
c3a6cf19 91 = #sym; \
fa6643cd 92 static const char __kstrtabns_##sym[] \
8651ec01 93 __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
c3a6cf19 94 = ns; \
7290d580 95 __KSYMTAB_ENTRY(sym, sec)
f5016932 96
69a94abb
MY
97#endif
98
99#if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
f922c4ab
AB
100
101/*
102 * Allow symbol exports to be disabled completely so that C code may
103 * be reused in other execution contexts such as the UEFI stub or the
104 * decompressor.
105 */
c3a6cf19 106#define __EXPORT_SYMBOL(sym, sec, ns)
f922c4ab 107
bbda5ec6
MY
108#elif defined(CONFIG_TRIM_UNUSED_KSYMS)
109
110#include <generated/autoksyms.h>
c1a95fda
NP
111
112/*
113 * For fine grained build dependencies, we want to tell the build system
114 * about each possible exported symbol even if they're not actually exported.
bbda5ec6
MY
115 * We use a symbol pattern __ksym_marker_<symbol> that the build system filters
116 * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are
117 * discarded in the final link stage.
c1a95fda 118 */
bbda5ec6
MY
119#define __ksym_marker(sym) \
120 static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
f2355416 121
c3a6cf19 122#define __EXPORT_SYMBOL(sym, sec, ns) \
8651ec01 123 __ksym_marker(sym); \
c3a6cf19
MY
124 __cond_export_sym(sym, sec, ns, __is_defined(__KSYM_##sym))
125#define __cond_export_sym(sym, sec, ns, conf) \
126 ___cond_export_sym(sym, sec, ns, conf)
127#define ___cond_export_sym(sym, sec, ns, enabled) \
128 __cond_export_sym_##enabled(sym, sec, ns)
129#define __cond_export_sym_1(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
130#define __cond_export_sym_0(sym, sec, ns) /* nothing */
8651ec01 131
f2355416 132#else
f2355416 133
c3a6cf19 134#define __EXPORT_SYMBOL(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
f5016932 135
69a94abb 136#endif /* CONFIG_MODULES */
f5016932 137
8e2adc6a 138#ifdef DEFAULT_SYMBOL_NAMESPACE
c3a6cf19
MY
139#include <linux/stringify.h>
140#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, __stringify(DEFAULT_SYMBOL_NAMESPACE))
141#else
142#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
8e2adc6a
MM
143#endif
144
c3a6cf19
MY
145#define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
146#define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "_gpl")
147#define EXPORT_SYMBOL_GPL_FUTURE(sym) _EXPORT_SYMBOL(sym, "_gpl_future")
148#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", #ns)
149#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", #ns)
f5016932
PG
150
151#ifdef CONFIG_UNUSED_SYMBOLS
c3a6cf19
MY
152#define EXPORT_UNUSED_SYMBOL(sym) _EXPORT_SYMBOL(sym, "_unused")
153#define EXPORT_UNUSED_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "_unused_gpl")
f5016932
PG
154#else
155#define EXPORT_UNUSED_SYMBOL(sym)
156#define EXPORT_UNUSED_SYMBOL_GPL(sym)
157#endif
158
b92021b0 159#endif /* !__ASSEMBLY__ */
f5016932
PG
160
161#endif /* _LINUX_EXPORT_H */