Skip to content

Commit 22823ab

Browse files
author
Al Viro
committed
EXPORT_SYMBOL() for asm
Add asm-usable variants of EXPORT_SYMBOL/EXPORT_SYMBOL_GPL. This commit just adds the default implementation; most of the architectures can simply add export.h to asm/Kbuild and start using <asm/export.h> from assembler. The rest needs to have their <asm/export.h> define everal macros and then explicitly include <asm-generic/export.h> One area where the things might diverge from default is the alignment; normally it's 8 bytes on 64bit targets and 4 on 32bit ones, both for unsigned long and for struct kernel_symbol. Unfortunately, amd64 and m68k are unusual - m68k aligns to 2 bytes (for both) and amd64 aligns struct kernel_symbol to 16 bytes. For those we'll need asm/export.h to override the constants used by generic version - KSYM_ALIGN and KCRC_ALIGN for kernel_symbol and unsigned long resp. And no, __alignof__ would not do the trick - on amd64 __alignof__ of struct kernel_symbol is 8, not 16. More serious source of unpleasantness is treatment of function descriptors on architectures that have those. Things like ppc64, parisc, ia64, etc. need more than the address of the first insn to call an arbitrary function. As the result, their representation of pointers to functions is not the typical "address of the entry point" - it's an address of a small static structure containing all the required information (including the entry point, of course). Sadly, the asm-side conventions differ in what the function name refers to - entry point or the function descriptor. On ppc64 we do the latter; bar: .quad foo is what void (*bar)(void) = foo; turns into and the rare places where we need to explicitly work with the label of entry point are dealt with as DOTSYM(foo). For our purposes it's ideal - generic macros are usable. However, parisc would have foo and P%foo used for label of entry point and address of the function descriptor and bar: .long P%foo woudl be used instead. ia64 goes similar to parisc in that respect, except that there it's @Fptr(foo) rather than P%foo. Such architectures need to define KSYM_FUNC that would turn a function name into whatever is needed to refer to function descriptor. What's more, on such architectures we need to know whether we are exporting a function or an object - in assembler we have to tell that explicitly, to decide whether we want EXPORT_SYMBOL(foo) produce e.g. __ksymtab_foo: .quad foo or __ksymtab_foo: .quad @Fptr(foo) For that reason we introduce EXPORT_DATA_SYMBOL{,_GPL}(), to be used for exports of data objects. On normal architectures it's the same thing as EXPORT_SYMBOL{,_GPL}(), but on parisc-like ones they differ and the right one needs to be used. Most of the exports are functions, so we keep EXPORT_SYMBOL for those... Signed-off-by: Al Viro <[email protected]>
1 parent 7f2084f commit 22823ab

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

include/asm-generic/export.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#ifndef __ASM_GENERIC_EXPORT_H
2+
#define __ASM_GENERIC_EXPORT_H
3+
4+
#ifndef KSYM_FUNC
5+
#define KSYM_FUNC(x) x
6+
#endif
7+
#ifdef CONFIG_64BIT
8+
#define __put .quad
9+
#ifndef KSYM_ALIGN
10+
#define KSYM_ALIGN 8
11+
#endif
12+
#ifndef KCRC_ALIGN
13+
#define KCRC_ALIGN 8
14+
#endif
15+
#else
16+
#define __put .long
17+
#ifndef KSYM_ALIGN
18+
#define KSYM_ALIGN 4
19+
#endif
20+
#ifndef KCRC_ALIGN
21+
#define KCRC_ALIGN 4
22+
#endif
23+
#endif
24+
25+
#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
26+
#define KSYM(name) _##name
27+
#else
28+
#define KSYM(name) name
29+
#endif
30+
31+
/*
32+
* note on .section use: @progbits vs %progbits nastiness doesn't matter,
33+
* since we immediately emit into those sections anyway.
34+
*/
35+
.macro ___EXPORT_SYMBOL name,val,sec
36+
#ifdef CONFIG_MODULES
37+
.globl KSYM(__ksymtab_\name)
38+
.section ___ksymtab\sec+\name,"a"
39+
.balign KSYM_ALIGN
40+
KSYM(__ksymtab_\name):
41+
__put \val, KSYM(__kstrtab_\name)
42+
.previous
43+
.section __ksymtab_strings,"a"
44+
KSYM(__kstrtab_\name):
45+
#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
46+
.asciz "_\name"
47+
#else
48+
.asciz "\name"
49+
#endif
50+
.previous
51+
#ifdef CONFIG_MODVERSIONS
52+
.section ___kcrctab\sec+\name,"a"
53+
.balign KCRC_ALIGN
54+
KSYM(__kcrctab_\name):
55+
__put KSYM(__crc_\name)
56+
.weak KSYM(__crc_\name)
57+
.previous
58+
#endif
59+
#endif
60+
.endm
61+
#undef __put
62+
63+
#if defined(__KSYM_DEPS__)
64+
65+
#define __EXPORT_SYMBOL(sym, val, sec) === __KSYM_##sym ===
66+
67+
#elif defined(CONFIG_TRIM_UNUSED_KSYMS)
68+
69+
#include <linux/kconfig.h>
70+
#include <generated/autoksyms.h>
71+
72+
#define __EXPORT_SYMBOL(sym, val, sec) \
73+
__cond_export_sym(sym, val, sec, config_enabled(__KSYM_##sym))
74+
#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) \
86+
__EXPORT_SYMBOL(name, KSYM_FUNC(KSYM(name)),)
87+
#define EXPORT_SYMBOL_GPL(name) \
88+
__EXPORT_SYMBOL(name, KSYM_FUNC(KSYM(name)), _gpl)
89+
#define EXPORT_DATA_SYMBOL(name) \
90+
__EXPORT_SYMBOL(name, KSYM(name),)
91+
#define EXPORT_DATA_SYMBOL_GPL(name) \
92+
__EXPORT_SYMBOL(name, KSYM(name),_gpl)
93+
94+
#endif

0 commit comments

Comments
 (0)