Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

CONFIG_SYMBOL_PREFIX: cleanup.

We have CONFIG_SYMBOL_PREFIX, which three archs define to the string
"_". But Al Viro broke this in "consolidate cond_syscall and
SYSCALL_ALIAS declarations" (in linux-next), and he's not the first to
do so.

Using CONFIG_SYMBOL_PREFIX is awkward, since we usually just want to
prefix it so something. So various places define helpers which are
defined to nothing if CONFIG_SYMBOL_PREFIX isn't set:

1) include/asm-generic/unistd.h defines __SYMBOL_PREFIX.
2) include/asm-generic/vmlinux.lds.h defines VMLINUX_SYMBOL(sym)
3) include/linux/export.h defines MODULE_SYMBOL_PREFIX.
4) include/linux/kernel.h defines SYMBOL_PREFIX (which differs from #7)
5) kernel/modsign_certificate.S defines ASM_SYMBOL(sym)
6) scripts/modpost.c defines MODULE_SYMBOL_PREFIX
7) scripts/Makefile.lib defines SYMBOL_PREFIX on the commandline if
CONFIG_SYMBOL_PREFIX is set, so that we have a non-string version
for pasting.

(arch/h8300/include/asm/linkage.h defines SYMBOL_NAME(), too).

Let's solve this properly:
1) No more generic prefix, just CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX.
2) Make linux/export.h usable from asm.
3) Define VMLINUX_SYMBOL() and VMLINUX_SYMBOL_STR().
4) Make everyone use them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Tested-by: James Hogan <james.hogan@imgtec.com> (metag)

+57 -88
+1 -1
Makefile
··· 1398 1398 # Run depmod only if we have System.map and depmod is executable 1399 1399 quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) 1400 1400 cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ 1401 - $(KERNELRELEASE) "$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX))" 1401 + $(KERNELRELEASE) "$(patsubst y,_,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX))" 1402 1402 1403 1403 # Create temporary dir for module support files 1404 1404 # clean it up only when building all modules
+6
arch/Kconfig
··· 384 384 Modules only use ELF REL relocations. Modules with ELF RELA 385 385 relocations will give an error. 386 386 387 + config HAVE_UNDERSCORE_SYMBOL_PREFIX 388 + bool 389 + help 390 + Some architectures generate an _ in front of C symbols; things like 391 + module loading and assembly files need to know about this. 392 + 387 393 # 388 394 # ABI hall of shame 389 395 #
+1 -4
arch/blackfin/Kconfig
··· 1 - config SYMBOL_PREFIX 2 - string 3 - default "_" 4 - 5 1 config MMU 6 2 def_bool n 7 3 ··· 29 33 select ARCH_HAVE_CUSTOM_GPIO_H 30 34 select ARCH_WANT_OPTIONAL_GPIOLIB 31 35 select HAVE_UID16 36 + select HAVE_UNDERSCORE_SYMBOL_PREFIX 32 37 select VIRT_TO_BUS 33 38 select ARCH_WANT_IPC_PARSE_VERSION 34 39 select HAVE_GENERIC_HARDIRQS
+1 -4
arch/h8300/Kconfig
··· 12 12 select MODULES_USE_ELF_RELA 13 13 select OLD_SIGSUSPEND3 14 14 select OLD_SIGACTION 15 - 16 - config SYMBOL_PREFIX 17 - string 18 - default "_" 15 + select HAVE_UNDERSCORE_SYMBOL_PREFIX 19 16 20 17 config MMU 21 18 bool
+1 -4
arch/metag/Kconfig
··· 1 - config SYMBOL_PREFIX 2 - string 3 - default "_" 4 - 5 1 config METAG 6 2 def_bool y 7 3 select EMBEDDED ··· 23 27 select HAVE_MOD_ARCH_SPECIFIC 24 28 select HAVE_PERF_EVENTS 25 29 select HAVE_SYSCALL_TRACEPOINTS 30 + select HAVE_UNDERSCORE_SYMBOL_PREFIX 26 31 select IRQ_DOMAIN 27 32 select MODULES_USE_ELF_RELA 28 33 select OF
+5 -3
drivers/mtd/chips/gen_probe.c
··· 204 204 struct cfi_private *cfi = map->fldrv_priv; 205 205 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID; 206 206 #ifdef CONFIG_MODULES 207 - char probename[16+sizeof(MODULE_SYMBOL_PREFIX)]; 207 + char probename[sizeof(VMLINUX_SYMBOL_STR(cfi_cmdset_%4.4X))]; 208 208 cfi_cmdset_fn_t *probe_function; 209 209 210 - sprintf(probename, MODULE_SYMBOL_PREFIX "cfi_cmdset_%4.4X", type); 210 + sprintf(probename, VMLINUX_SYMBOL_STR(cfi_cmdset_%4.4X), type); 211 211 212 212 probe_function = __symbol_get(probename); 213 213 if (!probe_function) { 214 - request_module(probename + sizeof(MODULE_SYMBOL_PREFIX) - 1); 214 + char modname[sizeof("cfi_cmdset_%4.4X")]; 215 + sprintf(modname, "cfi_cmdset_%4.4X", type); 216 + request_module(modname); 215 217 probe_function = __symbol_get(probename); 216 218 } 217 219
+4 -8
include/asm-generic/unistd.h
··· 1 1 #include <uapi/asm-generic/unistd.h> 2 + #include <linux/export.h> 2 3 3 4 /* 4 5 * These are required system calls, we should ··· 18 17 * but it doesn't work on all toolchains, so we just do it by hand 19 18 */ 20 19 #ifndef cond_syscall 21 - #ifdef CONFIG_SYMBOL_PREFIX 22 - #define __SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX 23 - #else 24 - #define __SYMBOL_PREFIX 25 - #endif 26 - #define cond_syscall(x) asm(".weak\t" __SYMBOL_PREFIX #x "\n\t" \ 27 - ".set\t" __SYMBOL_PREFIX #x "," \ 28 - __SYMBOL_PREFIX "sys_ni_syscall") 20 + #define cond_syscall(x) asm(".weak\t" VMLINUX_SYMBOL_STR(x) "\n\t" \ 21 + ".set\t" VMLINUX_SYMBOL_STR(x) "," \ 22 + VMLINUX_SYMBOL_STR(sys_ni_syscall)) 29 23 #endif
+1 -7
include/asm-generic/vmlinux.lds.h
··· 52 52 #define LOAD_OFFSET 0 53 53 #endif 54 54 55 - #ifndef SYMBOL_PREFIX 56 - #define VMLINUX_SYMBOL(sym) sym 57 - #else 58 - #define PASTE2(x,y) x##y 59 - #define PASTE(x,y) PASTE2(x,y) 60 - #define VMLINUX_SYMBOL(sym) PASTE(SYMBOL_PREFIX, sym) 61 - #endif 55 + #include <linux/export.h> 62 56 63 57 /* Align . to a 8 byte boundary equals to maximum function alignment. */ 64 58 #define ALIGN_FUNCTION() . = ALIGN(8)
+14 -6
include/linux/export.h
··· 5 5 * to reduce the amount of pointless cruft we feed to gcc when only 6 6 * exporting a simple symbol or two. 7 7 * 8 - * If you feel the need to add #include <linux/foo.h> to this file 9 - * then you are doing something wrong and should go away silently. 8 + * Try not to add #includes here. It slows compilation and makes kernel 9 + * hackers place grumpy comments in header files. 10 10 */ 11 11 12 12 /* Some toolchains use a `_' prefix for all user symbols. */ 13 - #ifdef CONFIG_SYMBOL_PREFIX 14 - #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX 13 + #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX 14 + #define __VMLINUX_SYMBOL(x) _##x 15 + #define __VMLINUX_SYMBOL_STR(x) "_" #x 15 16 #else 16 - #define MODULE_SYMBOL_PREFIX "" 17 + #define __VMLINUX_SYMBOL(x) x 18 + #define __VMLINUX_SYMBOL_STR(x) #x 17 19 #endif 18 20 21 + /* Indirect, so macros are expanded before pasting. */ 22 + #define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x) 23 + #define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x) 24 + 25 + #ifndef __ASSEMBLY__ 19 26 struct kernel_symbol 20 27 { 21 28 unsigned long value; ··· 58 51 __CRC_SYMBOL(sym, sec) \ 59 52 static const char __kstrtab_##sym[] \ 60 53 __attribute__((section("__ksymtab_strings"), aligned(1))) \ 61 - = MODULE_SYMBOL_PREFIX #sym; \ 54 + = VMLINUX_SYMBOL_STR(sym); \ 62 55 static const struct kernel_symbol __ksymtab_##sym \ 63 56 __used \ 64 57 __attribute__((section("___ksymtab" sec "+" #sym), unused)) \ ··· 92 85 #define EXPORT_UNUSED_SYMBOL_GPL(sym) 93 86 94 87 #endif /* CONFIG_MODULES */ 88 + #endif /* !__ASSEMBLY__ */ 95 89 96 90 #endif /* _LINUX_EXPORT_H */
-7
include/linux/kernel.h
··· 723 723 /* Trap pasters of __FUNCTION__ at compile-time */ 724 724 #define __FUNCTION__ (__func__) 725 725 726 - /* This helps us to avoid #ifdef CONFIG_SYMBOL_PREFIX */ 727 - #ifdef CONFIG_SYMBOL_PREFIX 728 - #define SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX 729 - #else 730 - #define SYMBOL_PREFIX "" 731 - #endif 732 - 733 726 /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ 734 727 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 735 728 # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
+2 -2
include/linux/module.h
··· 190 190 /* Get/put a kernel symbol (calls must be symmetric) */ 191 191 void *__symbol_get(const char *symbol); 192 192 void *__symbol_get_gpl(const char *symbol); 193 - #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) 193 + #define symbol_get(x) ((typeof(&x))(__symbol_get(VMLINUX_SYMBOL_STR(x)))) 194 194 195 195 /* modules using other modules: kdb wants to see this. */ 196 196 struct module_use { ··· 453 453 #ifdef CONFIG_MODULE_UNLOAD 454 454 unsigned long module_refcount(struct module *mod); 455 455 void __symbol_put(const char *symbol); 456 - #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) 456 + #define symbol_put(x) __symbol_put(VMLINUX_SYMBOL_STR(x)) 457 457 void symbol_put_addr(void *addr); 458 458 459 459 /* Sometimes we know we already have a refcount, and it's easier not
+3 -10
kernel/modsign_certificate.S
··· 1 - /* SYMBOL_PREFIX defined on commandline from CONFIG_SYMBOL_PREFIX */ 2 - #ifndef SYMBOL_PREFIX 3 - #define ASM_SYMBOL(sym) sym 4 - #else 5 - #define PASTE2(x,y) x##y 6 - #define PASTE(x,y) PASTE2(x,y) 7 - #define ASM_SYMBOL(sym) PASTE(SYMBOL_PREFIX, sym) 8 - #endif 1 + #include <linux/export.h> 9 2 10 3 #define GLOBAL(name) \ 11 - .globl ASM_SYMBOL(name); \ 12 - ASM_SYMBOL(name): 4 + .globl VMLINUX_SYMBOL(name); \ 5 + VMLINUX_SYMBOL(name): 13 6 14 7 .section ".init.data","aw" 15 8
+1 -1
kernel/module.c
··· 1209 1209 1210 1210 /* Since this should be found in kernel (which can't be removed), 1211 1211 * no locking is necessary. */ 1212 - if (!find_symbol(MODULE_SYMBOL_PREFIX "module_layout", NULL, 1212 + if (!find_symbol(VMLINUX_SYMBOL_STR(module_layout), NULL, 1213 1213 &crc, true, false)) 1214 1214 BUG(); 1215 1215 return check_version(sechdrs, versindex, "module_layout", mod, crc,
-7
scripts/Makefile.lib
··· 119 119 $(CFLAGS_GCOV)) 120 120 endif 121 121 122 - ifdef CONFIG_SYMBOL_PREFIX 123 - _sym_flags = -DSYMBOL_PREFIX=$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX)) 124 - _cpp_flags += $(_sym_flags) 125 - _a_flags += $(_sym_flags) 126 - endif 127 - 128 - 129 122 # If building the kernel in a separate objtree expand all occurrences 130 123 # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). 131 124
+15 -21
scripts/mod/modpost.c
··· 18 18 #include "modpost.h" 19 19 #include "../../include/generated/autoconf.h" 20 20 #include "../../include/linux/license.h" 21 - 22 - /* Some toolchains use a `_' prefix for all user symbols. */ 23 - #ifdef CONFIG_SYMBOL_PREFIX 24 - #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX 25 - #else 26 - #define MODULE_SYMBOL_PREFIX "" 27 - #endif 28 - 21 + #include "../../include/linux/export.h" 29 22 30 23 /* Are we using CONFIG_MODVERSIONS? */ 31 24 int modversions = 0; ··· 555 562 static int ignore_undef_symbol(struct elf_info *info, const char *symname) 556 563 { 557 564 /* ignore __this_module, it will be resolved shortly */ 558 - if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0) 565 + if (strcmp(symname, VMLINUX_SYMBOL_STR(__this_module)) == 0) 559 566 return 1; 560 567 /* ignore global offset table */ 561 568 if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0) ··· 576 583 return 0; 577 584 } 578 585 579 - #define CRC_PFX MODULE_SYMBOL_PREFIX "__crc_" 580 - #define KSYMTAB_PFX MODULE_SYMBOL_PREFIX "__ksymtab_" 586 + #define CRC_PFX VMLINUX_SYMBOL_STR(__crc_) 587 + #define KSYMTAB_PFX VMLINUX_SYMBOL_STR(__ksymtab_) 581 588 582 589 static void handle_modversions(struct module *mod, struct elf_info *info, 583 590 Elf_Sym *sym, const char *symname) ··· 630 637 } 631 638 #endif 632 639 633 - if (memcmp(symname, MODULE_SYMBOL_PREFIX, 634 - strlen(MODULE_SYMBOL_PREFIX)) == 0) { 635 - mod->unres = 636 - alloc_symbol(symname + 637 - strlen(MODULE_SYMBOL_PREFIX), 638 - ELF_ST_BIND(sym->st_info) == STB_WEAK, 639 - mod->unres); 640 - } 640 + #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX 641 + if (symname[0] != '_') 642 + break; 643 + else 644 + symname++; 645 + #endif 646 + mod->unres = alloc_symbol(symname, 647 + ELF_ST_BIND(sym->st_info) == STB_WEAK, 648 + mod->unres); 641 649 break; 642 650 default: 643 651 /* All exported symbols */ ··· 646 652 sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, 647 653 export); 648 654 } 649 - if (strcmp(symname, MODULE_SYMBOL_PREFIX "init_module") == 0) 655 + if (strcmp(symname, VMLINUX_SYMBOL_STR(init_module)) == 0) 650 656 mod->has_init = 1; 651 - if (strcmp(symname, MODULE_SYMBOL_PREFIX "cleanup_module") == 0) 657 + if (strcmp(symname, VMLINUX_SYMBOL_STR(cleanup_module)) == 0) 652 658 mod->has_cleanup = 1; 653 659 break; 654 660 }