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