| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* |
| 3 | * Please do not include this explicitly. |
| 4 | * This is used by C files generated by modpost. |
| 5 | */ |
| 6 | |
| 7 | #ifndef __LINUX_EXPORT_INTERNAL_H__ |
| 8 | #define __LINUX_EXPORT_INTERNAL_H__ |
| 9 | |
| 10 | #include <linux/compiler.h> |
| 11 | #include <linux/types.h> |
| 12 | |
| 13 | #if defined(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS) |
| 14 | /* |
| 15 | * relative reference: this reduces the size by half on 64-bit architectures, |
| 16 | * and eliminates the need for absolute relocations that require runtime |
| 17 | * processing on relocatable kernels. |
| 18 | */ |
| 19 | #define __KSYM_ALIGN ".balign 4" |
| 20 | #define __KSYM_REF(sym) ".long " #sym "- ." |
| 21 | #elif defined(CONFIG_64BIT) |
| 22 | #define __KSYM_ALIGN ".balign 8" |
| 23 | #define __KSYM_REF(sym) ".quad " #sym |
| 24 | #else |
| 25 | #define __KSYM_ALIGN ".balign 4" |
| 26 | #define __KSYM_REF(sym) ".long " #sym |
| 27 | #endif |
| 28 | |
| 29 | /* |
| 30 | * For every exported symbol, do the following: |
| 31 | * |
| 32 | * - Put the name of the symbol and namespace (empty string "" for none) in |
| 33 | * __ksymtab_strings. |
| 34 | * - Place a struct kernel_symbol entry in the __ksymtab section. |
| 35 | * |
| 36 | * Note on .section use: we specify progbits since usage of the "M" (SHF_MERGE) |
| 37 | * section flag requires it. Use '%progbits' instead of '@progbits' since the |
| 38 | * former apparently works on all arches according to the binutils source. |
| 39 | */ |
| 40 | #define __KSYMTAB(name, sym, sec, ns) \ |
| 41 | asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1" "\n" \ |
| 42 | "__kstrtab_" #name ":" "\n" \ |
| 43 | " .asciz \"" #name "\"" "\n" \ |
| 44 | "__kstrtabns_" #name ":" "\n" \ |
| 45 | " .asciz \"" ns "\"" "\n" \ |
| 46 | " .previous" "\n" \ |
| 47 | " .section \"___ksymtab" sec "+" #name "\", \"a\"" "\n" \ |
| 48 | __KSYM_ALIGN "\n" \ |
| 49 | "__ksymtab_" #name ":" "\n" \ |
| 50 | __KSYM_REF(sym) "\n" \ |
| 51 | __KSYM_REF(__kstrtab_ ##name) "\n" \ |
| 52 | __KSYM_REF(__kstrtabns_ ##name) "\n" \ |
| 53 | " .previous" "\n" \ |
| 54 | ) |
| 55 | |
| 56 | #if defined(CONFIG_PARISC) && defined(CONFIG_64BIT) |
| 57 | #define KSYM_FUNC(name) P%name |
| 58 | #else |
| 59 | #define KSYM_FUNC(name) name |
| 60 | #endif |
| 61 | |
| 62 | #define KSYMTAB_FUNC(name, sec, ns) __KSYMTAB(name, KSYM_FUNC(name), sec, ns) |
| 63 | #define KSYMTAB_DATA(name, sec, ns) __KSYMTAB(name, name, sec, ns) |
| 64 | |
| 65 | #define SYMBOL_CRC(sym, crc, sec) \ |
| 66 | asm(".section \"___kcrctab" sec "+" #sym "\",\"a\"" "\n" \ |
| 67 | ".balign 4" "\n" \ |
| 68 | "__crc_" #sym ":" "\n" \ |
| 69 | ".long " #crc "\n" \ |
| 70 | ".previous" "\n") |
| 71 | |
| 72 | #endif /* __LINUX_EXPORT_INTERNAL_H__ */ |