blob: 07a36a874dcafa1ebeda1ae2ec548738ab275917 [file] [log] [blame]
Masahiro Yamadabf49d9d2019-10-18 13:50:53 +09001/* SPDX-License-Identifier: GPL-2.0-only */
Al Viro22823ab2016-01-11 10:54:54 -05002#ifndef __ASM_GENERIC_EXPORT_H
3#define __ASM_GENERIC_EXPORT_H
4
5#ifndef KSYM_FUNC
6#define KSYM_FUNC(x) x
7#endif
Matthias Maenniched13fc32019-09-06 11:32:26 +01008#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
Al Viro22823ab2016-01-11 10:54:54 -05009#define KSYM_ALIGN 4
Matthias Maenniched13fc32019-09-06 11:32:26 +010010#elif defined(CONFIG_64BIT)
11#define KSYM_ALIGN 8
12#else
13#define KSYM_ALIGN 4
Ard Biesheuvel71810db2017-02-03 09:54:06 +000014#endif
Al Viro22823ab2016-01-11 10:54:54 -050015#ifndef KCRC_ALIGN
16#define KCRC_ALIGN 4
17#endif
Al Viro22823ab2016-01-11 10:54:54 -050018
Ard Biesheuvel7290d582018-08-21 21:56:09 -070019.macro __put, val, name
20#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
Will Deacon069e1c02019-09-11 13:26:46 +010021 .long \val - ., \name - ., 0
Ard Biesheuvel7290d582018-08-21 21:56:09 -070022#elif defined(CONFIG_64BIT)
Matthias Maennich8651ec02019-09-06 11:32:27 +010023 .quad \val, \name, 0
Ard Biesheuvel7290d582018-08-21 21:56:09 -070024#else
Matthias Maennich8651ec02019-09-06 11:32:27 +010025 .long \val, \name, 0
Ard Biesheuvel7290d582018-08-21 21:56:09 -070026#endif
27.endm
28
Al Viro22823ab2016-01-11 10:54:54 -050029/*
Jessica Yuce2b6172019-11-12 12:35:59 +010030 * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
31 * section flag requires it. Use '%progbits' instead of '@progbits' since the
32 * former apparently works on all arches according to the binutils source.
Al Viro22823ab2016-01-11 10:54:54 -050033 */
Jessica Yuce2b6172019-11-12 12:35:59 +010034
Al Viro22823ab2016-01-11 10:54:54 -050035.macro ___EXPORT_SYMBOL name,val,sec
Quentin Perretae242862021-02-03 14:19:30 +000036#if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS)
Al Viro22823ab2016-01-11 10:54:54 -050037 .section ___ksymtab\sec+\name,"a"
38 .balign KSYM_ALIGN
Masahiro Yamada94e58e02018-05-09 16:23:49 +090039__ksymtab_\name:
40 __put \val, __kstrtab_\name
Al Viro22823ab2016-01-11 10:54:54 -050041 .previous
Jessica Yuce2b6172019-11-12 12:35:59 +010042 .section __ksymtab_strings,"aMS",%progbits,1
Masahiro Yamada94e58e02018-05-09 16:23:49 +090043__kstrtab_\name:
Al Viro22823ab2016-01-11 10:54:54 -050044 .asciz "\name"
Al Viro22823ab2016-01-11 10:54:54 -050045 .previous
46#ifdef CONFIG_MODVERSIONS
47 .section ___kcrctab\sec+\name,"a"
48 .balign KCRC_ALIGN
Ard Biesheuvel71810db2017-02-03 09:54:06 +000049#if defined(CONFIG_MODULE_REL_CRCS)
Masahiro Yamada94e58e02018-05-09 16:23:49 +090050 .long __crc_\name - .
Ard Biesheuvel71810db2017-02-03 09:54:06 +000051#else
Masahiro Yamada94e58e02018-05-09 16:23:49 +090052 .long __crc_\name
Ard Biesheuvel71810db2017-02-03 09:54:06 +000053#endif
Masahiro Yamada94e58e02018-05-09 16:23:49 +090054 .weak __crc_\name
Al Viro22823ab2016-01-11 10:54:54 -050055 .previous
56#endif
57#endif
58.endm
Al Viro22823ab2016-01-11 10:54:54 -050059
Masahiro Yamadabbda5ec2018-11-30 10:05:26 +090060#if defined(CONFIG_TRIM_UNUSED_KSYMS)
Al Viro22823ab2016-01-11 10:54:54 -050061
62#include <linux/kconfig.h>
63#include <generated/autoksyms.h>
64
Masahiro Yamadabbda5ec2018-11-30 10:05:26 +090065.macro __ksym_marker sym
66 .section ".discard.ksym","a"
67__ksym_marker_\sym:
68 .previous
69.endm
70
Al Viro22823ab2016-01-11 10:54:54 -050071#define __EXPORT_SYMBOL(sym, val, sec) \
Masahiro Yamadabbda5ec2018-11-30 10:05:26 +090072 __ksym_marker sym; \
Masahiro Yamadac0a0aba2016-10-27 17:46:38 -070073 __cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
Al Viro22823ab2016-01-11 10:54:54 -050074#define __cond_export_sym(sym, val, sec, conf) \
75 ___cond_export_sym(sym, val, sec, conf)
76#define ___cond_export_sym(sym, val, sec, enabled) \
77 __cond_export_sym_##enabled(sym, val, sec)
78#define __cond_export_sym_1(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
79#define __cond_export_sym_0(sym, val, sec) /* nothing */
80
81#else
82#define __EXPORT_SYMBOL(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
83#endif
84
85#define EXPORT_SYMBOL(name) \
Masahiro Yamada94e58e02018-05-09 16:23:49 +090086 __EXPORT_SYMBOL(name, KSYM_FUNC(name),)
Al Viro22823ab2016-01-11 10:54:54 -050087#define EXPORT_SYMBOL_GPL(name) \
Masahiro Yamada94e58e02018-05-09 16:23:49 +090088 __EXPORT_SYMBOL(name, KSYM_FUNC(name), _gpl)
Al Viro22823ab2016-01-11 10:54:54 -050089#define EXPORT_DATA_SYMBOL(name) \
Masahiro Yamada94e58e02018-05-09 16:23:49 +090090 __EXPORT_SYMBOL(name, name,)
Al Viro22823ab2016-01-11 10:54:54 -050091#define EXPORT_DATA_SYMBOL_GPL(name) \
Masahiro Yamada94e58e02018-05-09 16:23:49 +090092 __EXPORT_SYMBOL(name, name,_gpl)
Al Viro22823ab2016-01-11 10:54:54 -050093
94#endif