xref: /openbmc/linux/include/asm-generic/export.h (revision bf49d9dd6fef688733e2ddbd55f7bcb57df194e4)
1*bf49d9ddSMasahiro Yamada /* SPDX-License-Identifier: GPL-2.0-only */
222823ab4SAl Viro #ifndef __ASM_GENERIC_EXPORT_H
322823ab4SAl Viro #define __ASM_GENERIC_EXPORT_H
422823ab4SAl Viro 
522823ab4SAl Viro #ifndef KSYM_FUNC
622823ab4SAl Viro #define KSYM_FUNC(x) x
722823ab4SAl Viro #endif
8ed13fc33SMatthias Maennich #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
922823ab4SAl Viro #define KSYM_ALIGN 4
10ed13fc33SMatthias Maennich #elif defined(CONFIG_64BIT)
11ed13fc33SMatthias Maennich #define KSYM_ALIGN 8
12ed13fc33SMatthias Maennich #else
13ed13fc33SMatthias Maennich #define KSYM_ALIGN 4
1471810db2SArd Biesheuvel #endif
1522823ab4SAl Viro #ifndef KCRC_ALIGN
1622823ab4SAl Viro #define KCRC_ALIGN 4
1722823ab4SAl Viro #endif
1822823ab4SAl Viro 
197290d580SArd Biesheuvel .macro __put, val, name
207290d580SArd Biesheuvel #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
21069e1c07SWill Deacon 	.long	\val - ., \name - ., 0
227290d580SArd Biesheuvel #elif defined(CONFIG_64BIT)
238651ec01SMatthias Maennich 	.quad	\val, \name, 0
247290d580SArd Biesheuvel #else
258651ec01SMatthias Maennich 	.long	\val, \name, 0
267290d580SArd Biesheuvel #endif
277290d580SArd Biesheuvel .endm
287290d580SArd Biesheuvel 
2922823ab4SAl Viro /*
3022823ab4SAl Viro  * note on .section use: @progbits vs %progbits nastiness doesn't matter,
3122823ab4SAl Viro  * since we immediately emit into those sections anyway.
3222823ab4SAl Viro  */
3322823ab4SAl Viro .macro ___EXPORT_SYMBOL name,val,sec
3422823ab4SAl Viro #ifdef CONFIG_MODULES
3594e58e0aSMasahiro Yamada 	.globl __ksymtab_\name
3622823ab4SAl Viro 	.section ___ksymtab\sec+\name,"a"
3722823ab4SAl Viro 	.balign KSYM_ALIGN
3894e58e0aSMasahiro Yamada __ksymtab_\name:
3994e58e0aSMasahiro Yamada 	__put \val, __kstrtab_\name
4022823ab4SAl Viro 	.previous
4122823ab4SAl Viro 	.section __ksymtab_strings,"a"
4294e58e0aSMasahiro Yamada __kstrtab_\name:
4322823ab4SAl Viro 	.asciz "\name"
4422823ab4SAl Viro 	.previous
4522823ab4SAl Viro #ifdef CONFIG_MODVERSIONS
4622823ab4SAl Viro 	.section ___kcrctab\sec+\name,"a"
4722823ab4SAl Viro 	.balign KCRC_ALIGN
4894e58e0aSMasahiro Yamada __kcrctab_\name:
4971810db2SArd Biesheuvel #if defined(CONFIG_MODULE_REL_CRCS)
5094e58e0aSMasahiro Yamada 	.long __crc_\name - .
5171810db2SArd Biesheuvel #else
5294e58e0aSMasahiro Yamada 	.long __crc_\name
5371810db2SArd Biesheuvel #endif
5494e58e0aSMasahiro Yamada 	.weak __crc_\name
5522823ab4SAl Viro 	.previous
5622823ab4SAl Viro #endif
5722823ab4SAl Viro #endif
5822823ab4SAl Viro .endm
5922823ab4SAl Viro 
60bbda5ec6SMasahiro Yamada #if defined(CONFIG_TRIM_UNUSED_KSYMS)
6122823ab4SAl Viro 
6222823ab4SAl Viro #include <linux/kconfig.h>
6322823ab4SAl Viro #include <generated/autoksyms.h>
6422823ab4SAl Viro 
65bbda5ec6SMasahiro Yamada .macro __ksym_marker sym
66bbda5ec6SMasahiro Yamada 	.section ".discard.ksym","a"
67bbda5ec6SMasahiro Yamada __ksym_marker_\sym:
68bbda5ec6SMasahiro Yamada 	 .previous
69bbda5ec6SMasahiro Yamada .endm
70bbda5ec6SMasahiro Yamada 
7122823ab4SAl Viro #define __EXPORT_SYMBOL(sym, val, sec)				\
72bbda5ec6SMasahiro Yamada 	__ksym_marker sym;					\
73c0a0aba8SMasahiro Yamada 	__cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
7422823ab4SAl Viro #define __cond_export_sym(sym, val, sec, conf)			\
7522823ab4SAl Viro 	___cond_export_sym(sym, val, sec, conf)
7622823ab4SAl Viro #define ___cond_export_sym(sym, val, sec, enabled)		\
7722823ab4SAl Viro 	__cond_export_sym_##enabled(sym, val, sec)
7822823ab4SAl Viro #define __cond_export_sym_1(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
7922823ab4SAl Viro #define __cond_export_sym_0(sym, val, sec) /* nothing */
8022823ab4SAl Viro 
8122823ab4SAl Viro #else
8222823ab4SAl Viro #define __EXPORT_SYMBOL(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
8322823ab4SAl Viro #endif
8422823ab4SAl Viro 
8522823ab4SAl Viro #define EXPORT_SYMBOL(name)					\
8694e58e0aSMasahiro Yamada 	__EXPORT_SYMBOL(name, KSYM_FUNC(name),)
8722823ab4SAl Viro #define EXPORT_SYMBOL_GPL(name) 				\
8894e58e0aSMasahiro Yamada 	__EXPORT_SYMBOL(name, KSYM_FUNC(name), _gpl)
8922823ab4SAl Viro #define EXPORT_DATA_SYMBOL(name)				\
9094e58e0aSMasahiro Yamada 	__EXPORT_SYMBOL(name, name,)
9122823ab4SAl Viro #define EXPORT_DATA_SYMBOL_GPL(name)				\
9294e58e0aSMasahiro Yamada 	__EXPORT_SYMBOL(name, name,_gpl)
9322823ab4SAl Viro 
9422823ab4SAl Viro #endif
95