18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci#ifndef __ASM_GENERIC_EXPORT_H
38c2ecf20Sopenharmony_ci#define __ASM_GENERIC_EXPORT_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#ifndef KSYM_FUNC
68c2ecf20Sopenharmony_ci#define KSYM_FUNC(x) x
78c2ecf20Sopenharmony_ci#endif
88c2ecf20Sopenharmony_ci#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
98c2ecf20Sopenharmony_ci#define KSYM_ALIGN 4
108c2ecf20Sopenharmony_ci#elif defined(CONFIG_64BIT)
118c2ecf20Sopenharmony_ci#define KSYM_ALIGN 8
128c2ecf20Sopenharmony_ci#else
138c2ecf20Sopenharmony_ci#define KSYM_ALIGN 4
148c2ecf20Sopenharmony_ci#endif
158c2ecf20Sopenharmony_ci#ifndef KCRC_ALIGN
168c2ecf20Sopenharmony_ci#define KCRC_ALIGN 4
178c2ecf20Sopenharmony_ci#endif
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci.macro __put, val, name
208c2ecf20Sopenharmony_ci#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
218c2ecf20Sopenharmony_ci	.long	\val - ., \name - ., 0
228c2ecf20Sopenharmony_ci#elif defined(CONFIG_64BIT)
238c2ecf20Sopenharmony_ci	.quad	\val, \name, 0
248c2ecf20Sopenharmony_ci#else
258c2ecf20Sopenharmony_ci	.long	\val, \name, 0
268c2ecf20Sopenharmony_ci#endif
278c2ecf20Sopenharmony_ci.endm
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/*
308c2ecf20Sopenharmony_ci * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
318c2ecf20Sopenharmony_ci * section flag requires it. Use '%progbits' instead of '@progbits' since the
328c2ecf20Sopenharmony_ci * former apparently works on all arches according to the binutils source.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci.macro ___EXPORT_SYMBOL name,val,sec
368c2ecf20Sopenharmony_ci#ifdef CONFIG_MODULES
378c2ecf20Sopenharmony_ci	.section ___ksymtab\sec+\name,"a"
388c2ecf20Sopenharmony_ci	.balign KSYM_ALIGN
398c2ecf20Sopenharmony_ci__ksymtab_\name:
408c2ecf20Sopenharmony_ci	__put \val, __kstrtab_\name
418c2ecf20Sopenharmony_ci	.previous
428c2ecf20Sopenharmony_ci	.section __ksymtab_strings,"aMS",%progbits,1
438c2ecf20Sopenharmony_ci__kstrtab_\name:
448c2ecf20Sopenharmony_ci	.asciz "\name"
458c2ecf20Sopenharmony_ci	.previous
468c2ecf20Sopenharmony_ci#ifdef CONFIG_MODVERSIONS
478c2ecf20Sopenharmony_ci	.section ___kcrctab\sec+\name,"a"
488c2ecf20Sopenharmony_ci	.balign KCRC_ALIGN
498c2ecf20Sopenharmony_ci#if defined(CONFIG_MODULE_REL_CRCS)
508c2ecf20Sopenharmony_ci	.long __crc_\name - .
518c2ecf20Sopenharmony_ci#else
528c2ecf20Sopenharmony_ci	.long __crc_\name
538c2ecf20Sopenharmony_ci#endif
548c2ecf20Sopenharmony_ci	.weak __crc_\name
558c2ecf20Sopenharmony_ci	.previous
568c2ecf20Sopenharmony_ci#endif
578c2ecf20Sopenharmony_ci#endif
588c2ecf20Sopenharmony_ci.endm
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#if defined(CONFIG_TRIM_UNUSED_KSYMS)
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#include <linux/kconfig.h>
638c2ecf20Sopenharmony_ci#include <generated/autoksyms.h>
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci.macro __ksym_marker sym
668c2ecf20Sopenharmony_ci	.section ".discard.ksym","a"
678c2ecf20Sopenharmony_ci__ksym_marker_\sym:
688c2ecf20Sopenharmony_ci	 .previous
698c2ecf20Sopenharmony_ci.endm
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define __EXPORT_SYMBOL(sym, val, sec)				\
728c2ecf20Sopenharmony_ci	__ksym_marker sym;					\
738c2ecf20Sopenharmony_ci	__cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
748c2ecf20Sopenharmony_ci#define __cond_export_sym(sym, val, sec, conf)			\
758c2ecf20Sopenharmony_ci	___cond_export_sym(sym, val, sec, conf)
768c2ecf20Sopenharmony_ci#define ___cond_export_sym(sym, val, sec, enabled)		\
778c2ecf20Sopenharmony_ci	__cond_export_sym_##enabled(sym, val, sec)
788c2ecf20Sopenharmony_ci#define __cond_export_sym_1(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
798c2ecf20Sopenharmony_ci#define __cond_export_sym_0(sym, val, sec) /* nothing */
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#else
828c2ecf20Sopenharmony_ci#define __EXPORT_SYMBOL(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
838c2ecf20Sopenharmony_ci#endif
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#define EXPORT_SYMBOL(name)					\
868c2ecf20Sopenharmony_ci	__EXPORT_SYMBOL(name, KSYM_FUNC(name),)
878c2ecf20Sopenharmony_ci#define EXPORT_SYMBOL_GPL(name) 				\
888c2ecf20Sopenharmony_ci	__EXPORT_SYMBOL(name, KSYM_FUNC(name), _gpl)
898c2ecf20Sopenharmony_ci#define EXPORT_DATA_SYMBOL(name)				\
908c2ecf20Sopenharmony_ci	__EXPORT_SYMBOL(name, name,)
918c2ecf20Sopenharmony_ci#define EXPORT_DATA_SYMBOL_GPL(name)				\
928c2ecf20Sopenharmony_ci	__EXPORT_SYMBOL(name, name,_gpl)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#endif
95