xref: /openbmc/linux/include/asm-generic/export.h (revision 8651ec01daedad26290f76beeb4736f9d2da4b87)
122823ab4SAl Viro #ifndef __ASM_GENERIC_EXPORT_H
222823ab4SAl Viro #define __ASM_GENERIC_EXPORT_H
322823ab4SAl Viro 
422823ab4SAl Viro #ifndef KSYM_FUNC
522823ab4SAl Viro #define KSYM_FUNC(x) x
622823ab4SAl Viro #endif
7ed13fc33SMatthias Maennich #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
822823ab4SAl Viro #define KSYM_ALIGN 4
9ed13fc33SMatthias Maennich #elif defined(CONFIG_64BIT)
10ed13fc33SMatthias Maennich #define KSYM_ALIGN 8
11ed13fc33SMatthias Maennich #else
12ed13fc33SMatthias Maennich #define KSYM_ALIGN 4
1371810db2SArd Biesheuvel #endif
1422823ab4SAl Viro #ifndef KCRC_ALIGN
1522823ab4SAl Viro #define KCRC_ALIGN 4
1622823ab4SAl Viro #endif
1722823ab4SAl Viro 
187290d580SArd Biesheuvel .macro __put, val, name
197290d580SArd Biesheuvel #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
20*8651ec01SMatthias Maennich 	.long	\val - ., \name - ., 0 - .
217290d580SArd Biesheuvel #elif defined(CONFIG_64BIT)
22*8651ec01SMatthias Maennich 	.quad	\val, \name, 0
237290d580SArd Biesheuvel #else
24*8651ec01SMatthias Maennich 	.long	\val, \name, 0
257290d580SArd Biesheuvel #endif
267290d580SArd Biesheuvel .endm
277290d580SArd Biesheuvel 
2822823ab4SAl Viro /*
2922823ab4SAl Viro  * note on .section use: @progbits vs %progbits nastiness doesn't matter,
3022823ab4SAl Viro  * since we immediately emit into those sections anyway.
3122823ab4SAl Viro  */
3222823ab4SAl Viro .macro ___EXPORT_SYMBOL name,val,sec
3322823ab4SAl Viro #ifdef CONFIG_MODULES
3494e58e0aSMasahiro Yamada 	.globl __ksymtab_\name
3522823ab4SAl Viro 	.section ___ksymtab\sec+\name,"a"
3622823ab4SAl Viro 	.balign KSYM_ALIGN
3794e58e0aSMasahiro Yamada __ksymtab_\name:
3894e58e0aSMasahiro Yamada 	__put \val, __kstrtab_\name
3922823ab4SAl Viro 	.previous
4022823ab4SAl Viro 	.section __ksymtab_strings,"a"
4194e58e0aSMasahiro Yamada __kstrtab_\name:
4222823ab4SAl Viro 	.asciz "\name"
4322823ab4SAl Viro 	.previous
4422823ab4SAl Viro #ifdef CONFIG_MODVERSIONS
4522823ab4SAl Viro 	.section ___kcrctab\sec+\name,"a"
4622823ab4SAl Viro 	.balign KCRC_ALIGN
4794e58e0aSMasahiro Yamada __kcrctab_\name:
4871810db2SArd Biesheuvel #if defined(CONFIG_MODULE_REL_CRCS)
4994e58e0aSMasahiro Yamada 	.long __crc_\name - .
5071810db2SArd Biesheuvel #else
5194e58e0aSMasahiro Yamada 	.long __crc_\name
5271810db2SArd Biesheuvel #endif
5394e58e0aSMasahiro Yamada 	.weak __crc_\name
5422823ab4SAl Viro 	.previous
5522823ab4SAl Viro #endif
5622823ab4SAl Viro #endif
5722823ab4SAl Viro .endm
5822823ab4SAl Viro #undef __put
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