cdrom: track if a cdrom_device_info was opened for data
[linux-2.6-block.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
d143b9db
GKH
5#include <linux/stringify.h>
6
f5016932
PG
7/*
8 * Export symbols from the kernel to modules. Forked from module.h
9 * to reduce the amount of pointless cruft we feed to gcc when only
10 * exporting a simple symbol or two.
11 *
b92021b0
RR
12 * Try not to add #includes here. It slows compilation and makes kernel
13 * hackers place grumpy comments in header files.
f5016932
PG
14 */
15
7b453719
MY
16/*
17 * This comment block is used by fixdep. Please do not remove.
18 *
19 * When CONFIG_MODVERSIONS is changed from n to y, all source files having
20 * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
21 * side effect of the *.o build rule.
22 */
23
b92021b0 24#ifndef __ASSEMBLY__
f5016932
PG
25#ifdef MODULE
26extern struct module __this_module;
27#define THIS_MODULE (&__this_module)
28#else
29#define THIS_MODULE ((struct module *)0)
30#endif
31
7290d580
AB
32#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
33#include <linux/compiler.h>
34/*
35 * Emit the ksymtab entry as a pair of relative references: this reduces
36 * the size by half on 64-bit architectures, and eliminates the need for
37 * absolute relocations that require runtime processing on relocatable
38 * kernels.
39 */
c3a6cf19 40#define __KSYMTAB_ENTRY(sym, sec) \
8651ec01
MM
41 __ADDRESSABLE(sym) \
42 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
43 " .balign 4 \n" \
69923208 44 "__ksymtab_" #sym ": \n" \
8651ec01
MM
45 " .long " #sym "- . \n" \
46 " .long __kstrtab_" #sym "- . \n" \
fa6643cd 47 " .long __kstrtabns_" #sym "- . \n" \
8651ec01
MM
48 " .previous \n")
49
7290d580
AB
50struct kernel_symbol {
51 int value_offset;
52 int name_offset;
8651ec01 53 int namespace_offset;
7290d580
AB
54};
55#else
56#define __KSYMTAB_ENTRY(sym, sec) \
57 static const struct kernel_symbol __ksymtab_##sym \
58 __attribute__((section("___ksymtab" sec "+" #sym), used)) \
ed13fc33 59 __aligned(sizeof(void *)) \
c3a6cf19 60 = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
7290d580
AB
61
62struct kernel_symbol {
63 unsigned long value;
64 const char *name;
8651ec01 65 const char *namespace;
7290d580
AB
66};
67#endif
68
69a94abb
MY
69#ifdef __GENKSYMS__
70
c3a6cf19 71#define ___EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
69a94abb
MY
72
73#else
74
ce2b617c
JY
75/*
76 * For every exported symbol, do the following:
77 *
ce2b617c
JY
78 * - Put the name of the symbol and namespace (empty string "" for none) in
79 * __ksymtab_strings.
80 * - Place a struct kernel_symbol entry in the __ksymtab section.
81 *
82 * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
83 * section flag requires it. Use '%progbits' instead of '@progbits' since the
84 * former apparently works on all arches according to the binutils source.
85 */
86#define ___EXPORT_SYMBOL(sym, sec, ns) \
87 extern typeof(sym) sym; \
88 extern const char __kstrtab_##sym[]; \
89 extern const char __kstrtabns_##sym[]; \
ce2b617c
JY
90 asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1 \n" \
91 "__kstrtab_" #sym ": \n" \
92 " .asciz \"" #sym "\" \n" \
93 "__kstrtabns_" #sym ": \n" \
94 " .asciz \"" ns "\" \n" \
95 " .previous \n"); \
7290d580 96 __KSYMTAB_ENTRY(sym, sec)
f5016932 97
69a94abb
MY
98#endif
99
100#if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
f922c4ab
AB
101
102/*
103 * Allow symbol exports to be disabled completely so that C code may
104 * be reused in other execution contexts such as the UEFI stub or the
105 * decompressor.
106 */
c3a6cf19 107#define __EXPORT_SYMBOL(sym, sec, ns)
f922c4ab 108
bbda5ec6
MY
109#elif defined(CONFIG_TRIM_UNUSED_KSYMS)
110
111#include <generated/autoksyms.h>
c1a95fda
NP
112
113/*
114 * For fine grained build dependencies, we want to tell the build system
115 * about each possible exported symbol even if they're not actually exported.
bbda5ec6
MY
116 * We use a symbol pattern __ksym_marker_<symbol> that the build system filters
117 * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are
118 * discarded in the final link stage.
c1a95fda 119 */
bbda5ec6 120#define __ksym_marker(sym) \
33def849 121 static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
f2355416 122
c3a6cf19 123#define __EXPORT_SYMBOL(sym, sec, ns) \
8651ec01 124 __ksym_marker(sym); \
c3a6cf19
MY
125 __cond_export_sym(sym, sec, ns, __is_defined(__KSYM_##sym))
126#define __cond_export_sym(sym, sec, ns, conf) \
127 ___cond_export_sym(sym, sec, ns, conf)
128#define ___cond_export_sym(sym, sec, ns, enabled) \
129 __cond_export_sym_##enabled(sym, sec, ns)
130#define __cond_export_sym_1(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
e1327a12
QP
131
132#ifdef __GENKSYMS__
133#define __cond_export_sym_0(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
134#else
c3a6cf19 135#define __cond_export_sym_0(sym, sec, ns) /* nothing */
e1327a12 136#endif
8651ec01 137
f2355416 138#else
f2355416 139
c3a6cf19 140#define __EXPORT_SYMBOL(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
f5016932 141
69a94abb 142#endif /* CONFIG_MODULES */
f5016932 143
8e2adc6a 144#ifdef DEFAULT_SYMBOL_NAMESPACE
c3a6cf19
MY
145#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, __stringify(DEFAULT_SYMBOL_NAMESPACE))
146#else
147#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
8e2adc6a
MM
148#endif
149
c3a6cf19
MY
150#define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
151#define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "_gpl")
d143b9db
GKH
152#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", __stringify(ns))
153#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", __stringify(ns))
f5016932 154
b92021b0 155#endif /* !__ASSEMBLY__ */
f5016932
PG
156
157#endif /* _LINUX_EXPORT_H */