xref: /openbmc/linux/include/asm-generic/export.h (revision 7b453719)
1bf49d9ddSMasahiro Yamada /* SPDX-License-Identifier: GPL-2.0-only */
222823ab4SAl Viro #ifndef __ASM_GENERIC_EXPORT_H
322823ab4SAl Viro #define __ASM_GENERIC_EXPORT_H
422823ab4SAl Viro 
5*7b453719SMasahiro Yamada /*
6*7b453719SMasahiro Yamada  * This comment block is used by fixdep. Please do not remove.
7*7b453719SMasahiro Yamada  *
8*7b453719SMasahiro Yamada  * When CONFIG_MODVERSIONS is changed from n to y, all source files having
9*7b453719SMasahiro Yamada  * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
10*7b453719SMasahiro Yamada  * side effect of the *.o build rule.
11*7b453719SMasahiro Yamada  */
12*7b453719SMasahiro Yamada 
1322823ab4SAl Viro #ifndef KSYM_FUNC
1422823ab4SAl Viro #define KSYM_FUNC(x) x
1522823ab4SAl Viro #endif
16ed13fc33SMatthias Maennich #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
1722823ab4SAl Viro #define KSYM_ALIGN 4
18ed13fc33SMatthias Maennich #elif defined(CONFIG_64BIT)
19ed13fc33SMatthias Maennich #define KSYM_ALIGN 8
20ed13fc33SMatthias Maennich #else
21ed13fc33SMatthias Maennich #define KSYM_ALIGN 4
2271810db2SArd Biesheuvel #endif
2322823ab4SAl Viro 
247290d580SArd Biesheuvel .macro __put, val, name
257290d580SArd Biesheuvel #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
26069e1c07SWill Deacon 	.long	\val - ., \name - ., 0
277290d580SArd Biesheuvel #elif defined(CONFIG_64BIT)
288651ec01SMatthias Maennich 	.quad	\val, \name, 0
297290d580SArd Biesheuvel #else
308651ec01SMatthias Maennich 	.long	\val, \name, 0
317290d580SArd Biesheuvel #endif
327290d580SArd Biesheuvel .endm
337290d580SArd Biesheuvel 
3422823ab4SAl Viro /*
35ce2b617cSJessica Yu  * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
36ce2b617cSJessica Yu  * section flag requires it. Use '%progbits' instead of '@progbits' since the
37ce2b617cSJessica Yu  * former apparently works on all arches according to the binutils source.
3822823ab4SAl Viro  */
39ce2b617cSJessica Yu 
4022823ab4SAl Viro .macro ___EXPORT_SYMBOL name,val,sec
4154effa65SQuentin Perret #if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS)
4222823ab4SAl Viro 	.section ___ksymtab\sec+\name,"a"
4322823ab4SAl Viro 	.balign KSYM_ALIGN
4494e58e0aSMasahiro Yamada __ksymtab_\name:
4594e58e0aSMasahiro Yamada 	__put \val, __kstrtab_\name
4622823ab4SAl Viro 	.previous
47ce2b617cSJessica Yu 	.section __ksymtab_strings,"aMS",%progbits,1
4894e58e0aSMasahiro Yamada __kstrtab_\name:
4922823ab4SAl Viro 	.asciz "\name"
5022823ab4SAl Viro 	.previous
5122823ab4SAl Viro #endif
5222823ab4SAl Viro .endm
5322823ab4SAl Viro 
54bbda5ec6SMasahiro Yamada #if defined(CONFIG_TRIM_UNUSED_KSYMS)
5522823ab4SAl Viro 
5622823ab4SAl Viro #include <linux/kconfig.h>
5722823ab4SAl Viro #include <generated/autoksyms.h>
5822823ab4SAl Viro 
59bbda5ec6SMasahiro Yamada .macro __ksym_marker sym
60bbda5ec6SMasahiro Yamada 	.section ".discard.ksym","a"
61bbda5ec6SMasahiro Yamada __ksym_marker_\sym:
62bbda5ec6SMasahiro Yamada 	 .previous
63bbda5ec6SMasahiro Yamada .endm
64bbda5ec6SMasahiro Yamada 
6522823ab4SAl Viro #define __EXPORT_SYMBOL(sym, val, sec)				\
66bbda5ec6SMasahiro Yamada 	__ksym_marker sym;					\
67c0a0aba8SMasahiro Yamada 	__cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
6822823ab4SAl Viro #define __cond_export_sym(sym, val, sec, conf)			\
6922823ab4SAl Viro 	___cond_export_sym(sym, val, sec, conf)
7022823ab4SAl Viro #define ___cond_export_sym(sym, val, sec, enabled)		\
7122823ab4SAl Viro 	__cond_export_sym_##enabled(sym, val, sec)
7222823ab4SAl Viro #define __cond_export_sym_1(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
7322823ab4SAl Viro #define __cond_export_sym_0(sym, val, sec) /* nothing */
7422823ab4SAl Viro 
7522823ab4SAl Viro #else
7622823ab4SAl Viro #define __EXPORT_SYMBOL(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
7722823ab4SAl Viro #endif
7822823ab4SAl Viro 
7922823ab4SAl Viro #define EXPORT_SYMBOL(name)					\
8094e58e0aSMasahiro Yamada 	__EXPORT_SYMBOL(name, KSYM_FUNC(name),)
8122823ab4SAl Viro #define EXPORT_SYMBOL_GPL(name) 				\
8294e58e0aSMasahiro Yamada 	__EXPORT_SYMBOL(name, KSYM_FUNC(name), _gpl)
8322823ab4SAl Viro #define EXPORT_DATA_SYMBOL(name)				\
8494e58e0aSMasahiro Yamada 	__EXPORT_SYMBOL(name, name,)
8522823ab4SAl Viro #define EXPORT_DATA_SYMBOL_GPL(name)				\
8694e58e0aSMasahiro Yamada 	__EXPORT_SYMBOL(name, name,_gpl)
8722823ab4SAl Viro 
8822823ab4SAl Viro #endif
89