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

Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux

Pull mudule updates from Rusty Russell:
"We get rid of the general module prefix confusion with a binary config
option, fix a remove/insert race which Never Happens, and (my
favorite) handle the case when we have too many modules for a single
commandline. Seriously, the kernel is full, please go away!"

* tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux:
modpost: fix unwanted VMLINUX_SYMBOL_STR expansion
X.509: Support parse long form of length octets in Authority Key Identifier
module: don't unlink the module until we've removed all exposure.
kernel: kallsyms: memory override issue, need check destination buffer length
MODSIGN: do not send garbage to stderr when enabling modules signature
modpost: handle huge numbers of modules.
modpost: add -T option to read module names from file/stdin.
modpost: minor cleanup.
genksyms: pass symbol-prefix instead of arch
module: fix symbol versioning with symbol prefixes
CONFIG_SYMBOL_PREFIX: cleanup.

+202 -140
+1 -1
Makefile
··· 1399 1399 # Run depmod only if we have System.map and depmod is executable 1400 1400 quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) 1401 1401 cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ 1402 - $(KERNELRELEASE) "$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX))" 1402 + $(KERNELRELEASE) "$(patsubst y,_,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX))" 1403 1403 1404 1404 # Create temporary dir for module support files 1405 1405 # clean it up only when building all modules
+6
arch/Kconfig
··· 381 381 Modules only use ELF REL relocations. Modules with ELF RELA 382 382 relocations will give an error. 383 383 384 + config HAVE_UNDERSCORE_SYMBOL_PREFIX 385 + bool 386 + help 387 + Some architectures generate an _ in front of C symbols; things like 388 + module loading and assembly files need to know about this. 389 + 384 390 # 385 391 # ABI hall of shame 386 392 #
+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 ··· 24 28 select HAVE_OPROFILE 25 29 select HAVE_PERF_EVENTS 26 30 select HAVE_SYSCALL_TRACEPOINTS 31 + select HAVE_UNDERSCORE_SYMBOL_PREFIX 27 32 select IRQ_DOMAIN 28 33 select MODULES_USE_ELF_RELA 29 34 select OF
+48 -9
crypto/asymmetric_keys/x509_cert_parser.c
··· 373 373 return 0; 374 374 } 375 375 376 + /* The keyIdentifier in AuthorityKeyIdentifier SEQUENCE is tag(CONT,PRIM,0) */ 377 + #define SEQ_TAG_KEYID (ASN1_CONT << 6) 378 + 376 379 /* 377 380 * Process certificate extensions that are used to qualify the certificate. 378 381 */ ··· 410 407 } 411 408 412 409 if (ctx->last_oid == OID_authorityKeyIdentifier) { 410 + size_t key_len; 411 + 413 412 /* Get hold of the CA key fingerprint */ 414 413 if (vlen < 5) 415 414 return -EBADMSG; 416 - if (v[0] != (ASN1_SEQ | (ASN1_CONS << 5)) || 417 - v[1] != vlen - 2 || 418 - v[2] != (ASN1_CONT << 6) || 419 - v[3] != vlen - 4) 420 - return -EBADMSG; 421 - v += 4; 422 - vlen -= 4; 423 415 424 - f = kmalloc(vlen * 2 + 1, GFP_KERNEL); 416 + /* Authority Key Identifier must be a Constructed SEQUENCE */ 417 + if (v[0] != (ASN1_SEQ | (ASN1_CONS << 5))) 418 + return -EBADMSG; 419 + 420 + /* Authority Key Identifier is not indefinite length */ 421 + if (unlikely(vlen == ASN1_INDEFINITE_LENGTH)) 422 + return -EBADMSG; 423 + 424 + if (vlen < ASN1_INDEFINITE_LENGTH) { 425 + /* Short Form length */ 426 + if (v[1] != vlen - 2 || 427 + v[2] != SEQ_TAG_KEYID || 428 + v[3] > vlen - 4) 429 + return -EBADMSG; 430 + 431 + key_len = v[3]; 432 + v += 4; 433 + } else { 434 + /* Long Form length */ 435 + size_t seq_len = 0; 436 + size_t sub = v[1] - ASN1_INDEFINITE_LENGTH; 437 + 438 + if (sub > 2) 439 + return -EBADMSG; 440 + 441 + /* calculate the length from subsequent octets */ 442 + v += 2; 443 + for (i = 0; i < sub; i++) { 444 + seq_len <<= 8; 445 + seq_len |= v[i]; 446 + } 447 + 448 + if (seq_len != vlen - 2 - sub || 449 + v[sub] != SEQ_TAG_KEYID || 450 + v[sub + 1] > vlen - 4 - sub) 451 + return -EBADMSG; 452 + 453 + key_len = v[sub + 1]; 454 + v += (sub + 2); 455 + } 456 + 457 + f = kmalloc(key_len * 2 + 1, GFP_KERNEL); 425 458 if (!f) 426 459 return -ENOMEM; 427 - for (i = 0; i < vlen; i++) 460 + for (i = 0; i < key_len; i++) 428 461 sprintf(f + i * 2, "%02x", v[i]); 429 462 pr_debug("authority %s\n", f); 430 463 ctx->cert->authority = f;
+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
+1
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
+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
··· 786 786 /* Trap pasters of __FUNCTION__ at compile-time */ 787 787 #define __FUNCTION__ (__func__) 788 788 789 - /* This helps us to avoid #ifdef CONFIG_SYMBOL_PREFIX */ 790 - #ifdef CONFIG_SYMBOL_PREFIX 791 - #define SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX 792 - #else 793 - #define SYMBOL_PREFIX "" 794 - #endif 795 - 796 789 /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ 797 790 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 798 791 # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
+9 -11
include/linux/linkage.h
··· 3 3 4 4 #include <linux/compiler.h> 5 5 #include <linux/stringify.h> 6 + #include <linux/export.h> 6 7 #include <asm/linkage.h> 7 8 8 9 #ifdef __cplusplus ··· 16 15 #define asmlinkage CPP_ASMLINKAGE 17 16 #endif 18 17 19 - #ifdef CONFIG_SYMBOL_PREFIX 20 - #define __SYMBOL_NAME(x) CONFIG_SYMBOL_PREFIX __stringify(x) 21 - #else 22 - #define __SYMBOL_NAME(x) __stringify(x) 23 - #endif 24 - 25 18 #ifndef cond_syscall 26 - #define cond_syscall(x) asm(".weak\t" __SYMBOL_NAME(x) \ 27 - "\n\t.set\t" __SYMBOL_NAME(x) "," __SYMBOL_NAME(sys_ni_syscall)); 19 + #define cond_syscall(x) asm( \ 20 + ".weak " VMLINUX_SYMBOL_STR(x) "\n\t" \ 21 + ".set " VMLINUX_SYMBOL_STR(x) "," \ 22 + VMLINUX_SYMBOL_STR(sys_ni_syscall)) 28 23 #endif 29 24 30 25 #ifndef SYSCALL_ALIAS 31 - #define SYSCALL_ALIAS(alias, name) \ 32 - asm ("\t.globl " __SYMBOL_NAME(alias) \ 33 - "\n\t.set\t" __SYMBOL_NAME(alias) "," __SYMBOL_NAME(name)) 26 + #define SYSCALL_ALIAS(alias, name) asm( \ 27 + ".globl " VMLINUX_SYMBOL_STR(alias) "\n\t" \ 28 + ".set " VMLINUX_SYMBOL_STR(alias) "," \ 29 + VMLINUX_SYMBOL_STR(name)) 34 30 #endif 35 31 36 32 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
+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
+1 -1
kernel/Makefile
··· 176 176 openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ 177 177 -batch -x509 -config x509.genkey \ 178 178 -outform DER -out signing_key.x509 \ 179 - -keyout signing_key.priv 179 + -keyout signing_key.priv 2>&1 180 180 @echo "###" 181 181 @echo "### Key pair generated." 182 182 @echo "###"
+18 -8
kernel/kallsyms.c
··· 84 84 85 85 /* 86 86 * Expand a compressed symbol data into the resulting uncompressed string, 87 + * if uncompressed string is too long (>= maxlen), it will be truncated, 87 88 * given the offset to where the symbol is in the compressed stream. 88 89 */ 89 - static unsigned int kallsyms_expand_symbol(unsigned int off, char *result) 90 + static unsigned int kallsyms_expand_symbol(unsigned int off, 91 + char *result, size_t maxlen) 90 92 { 91 93 int len, skipped_first = 0; 92 94 const u8 *tptr, *data; ··· 115 113 116 114 while (*tptr) { 117 115 if (skipped_first) { 116 + if (maxlen <= 1) 117 + goto tail; 118 118 *result = *tptr; 119 119 result++; 120 + maxlen--; 120 121 } else 121 122 skipped_first = 1; 122 123 tptr++; 123 124 } 124 125 } 125 126 126 - *result = '\0'; 127 + tail: 128 + if (maxlen) 129 + *result = '\0'; 127 130 128 131 /* Return to offset to the next symbol. */ 129 132 return off; ··· 183 176 unsigned int off; 184 177 185 178 for (i = 0, off = 0; i < kallsyms_num_syms; i++) { 186 - off = kallsyms_expand_symbol(off, namebuf); 179 + off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); 187 180 188 181 if (strcmp(namebuf, name) == 0) 189 182 return kallsyms_addresses[i]; ··· 202 195 int ret; 203 196 204 197 for (i = 0, off = 0; i < kallsyms_num_syms; i++) { 205 - off = kallsyms_expand_symbol(off, namebuf); 198 + off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); 206 199 ret = fn(data, namebuf, NULL, kallsyms_addresses[i]); 207 200 if (ret != 0) 208 201 return ret; ··· 301 294 302 295 pos = get_symbol_pos(addr, symbolsize, offset); 303 296 /* Grab name */ 304 - kallsyms_expand_symbol(get_symbol_offset(pos), namebuf); 297 + kallsyms_expand_symbol(get_symbol_offset(pos), 298 + namebuf, KSYM_NAME_LEN); 305 299 if (modname) 306 300 *modname = NULL; 307 301 return namebuf; ··· 323 315 324 316 pos = get_symbol_pos(addr, NULL, NULL); 325 317 /* Grab name */ 326 - kallsyms_expand_symbol(get_symbol_offset(pos), symname); 318 + kallsyms_expand_symbol(get_symbol_offset(pos), 319 + symname, KSYM_NAME_LEN); 327 320 return 0; 328 321 } 329 322 /* See if it's in a module. */ ··· 342 333 343 334 pos = get_symbol_pos(addr, size, offset); 344 335 /* Grab name */ 345 - kallsyms_expand_symbol(get_symbol_offset(pos), name); 336 + kallsyms_expand_symbol(get_symbol_offset(pos), 337 + name, KSYM_NAME_LEN); 346 338 modname[0] = '\0'; 347 339 return 0; 348 340 } ··· 473 463 474 464 iter->type = kallsyms_get_symbol_type(off); 475 465 476 - off = kallsyms_expand_symbol(off, iter->name); 466 + off = kallsyms_expand_symbol(off, iter->name, ARRAY_SIZE(iter->name)); 477 467 478 468 return off - iter->nameoff; 479 469 }
+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
+12 -6
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 - return check_version(sechdrs, versindex, "module_layout", mod, crc, 1215 + return check_version(sechdrs, versindex, 1216 + VMLINUX_SYMBOL_STR(module_layout), mod, crc, 1216 1217 NULL); 1217 1218 } 1218 1219 ··· 1862 1861 { 1863 1862 trace_module_free(mod); 1864 1863 1865 - /* Delete from various lists */ 1866 - mutex_lock(&module_mutex); 1867 - stop_machine(__unlink_module, mod, NULL); 1868 - mutex_unlock(&module_mutex); 1869 1864 mod_sysfs_teardown(mod); 1865 + 1866 + /* We leave it in list to prevent duplicate loads, but make sure 1867 + * that noone uses it while it's being deconstructed. */ 1868 + mod->state = MODULE_STATE_UNFORMED; 1870 1869 1871 1870 /* Remove dynamic debug info */ 1872 1871 ddebug_remove_module(mod->name); ··· 1879 1878 1880 1879 /* Free any allocated parameters. */ 1881 1880 destroy_params(mod->kp, mod->num_kp); 1881 + 1882 + /* Now we can delete it from the lists */ 1883 + mutex_lock(&module_mutex); 1884 + stop_machine(__unlink_module, mod, NULL); 1885 + mutex_unlock(&module_mutex); 1882 1886 1883 1887 /* This may be NULL, but that's OK */ 1884 1888 unset_module_init_ro_nx(mod);
+2 -1
scripts/Makefile.build
··· 211 211 212 212 cmd_gensymtypes = \ 213 213 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ 214 - $(GENKSYMS) $(if $(1), -T $(2)) -a $(ARCH) \ 214 + $(GENKSYMS) $(if $(1), -T $(2)) \ 215 + $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \ 215 216 $(if $(KBUILD_PRESERVE),-p) \ 216 217 -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null)) 217 218
-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
+5 -3
scripts/Makefile.modpost
··· 60 60 modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers 61 61 62 62 # Step 1), find all modules listed in $(MODVERDIR)/ 63 - __modules := $(sort $(shell grep -h '\.ko$$' /dev/null $(wildcard $(MODVERDIR)/*.mod))) 63 + MODLISTCMD := find $(MODVERDIR) -name '*.mod' | xargs -r grep -h '\.ko$$' | sort -u 64 + __modules := $(shell $(MODLISTCMD)) 64 65 modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o))) 65 66 66 67 # Stop after building .o files if NOFINAL is set. Makes compile tests quicker ··· 79 78 $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ 80 79 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) 81 80 81 + # We can go over command line length here, so be careful. 82 82 quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules 83 - cmd_modpost = $(modpost) -s 83 + cmd_modpost = $(MODLISTCMD) | sed 's/\.ko$$/.o/' | $(modpost) -s -T - 84 84 85 85 PHONY += __modpost 86 86 __modpost: $(modules:.ko=.o) FORCE 87 - $(call cmd,modpost) $(wildcard vmlinux) $(filter-out FORCE,$^) 87 + $(call cmd,modpost) $(wildcard vmlinux) 88 88 89 89 quiet_cmd_kernel-mod = MODPOST $@ 90 90 cmd_kernel-mod = $(modpost) $@
+7 -11
scripts/genksyms/genksyms.c
··· 45 45 46 46 static int flag_debug, flag_dump_defs, flag_reference, flag_dump_types, 47 47 flag_preserve, flag_warnings; 48 - static const char *arch = ""; 49 48 static const char *mod_prefix = ""; 50 49 51 50 static int errors; ··· 730 731 { 731 732 fputs("Usage:\n" "genksyms [-adDTwqhV] > /path/to/.tmp_obj.ver\n" "\n" 732 733 #ifdef __GNU_LIBRARY__ 733 - " -a, --arch Select architecture\n" 734 + " -s, --symbol-prefix Select symbol prefix\n" 734 735 " -d, --debug Increment the debug level (repeatable)\n" 735 736 " -D, --dump Dump expanded symbol defs (for debugging only)\n" 736 737 " -r, --reference file Read reference symbols from a file\n" ··· 741 742 " -h, --help Print this message\n" 742 743 " -V, --version Print the release version\n" 743 744 #else /* __GNU_LIBRARY__ */ 744 - " -a Select architecture\n" 745 + " -s Select symbol prefix\n" 745 746 " -d Increment the debug level (repeatable)\n" 746 747 " -D Dump expanded symbol defs (for debugging only)\n" 747 748 " -r file Read reference symbols from a file\n" ··· 762 763 763 764 #ifdef __GNU_LIBRARY__ 764 765 struct option long_opts[] = { 765 - {"arch", 1, 0, 'a'}, 766 + {"symbol-prefix", 1, 0, 's'}, 766 767 {"debug", 0, 0, 'd'}, 767 768 {"warnings", 0, 0, 'w'}, 768 769 {"quiet", 0, 0, 'q'}, ··· 775 776 {0, 0, 0, 0} 776 777 }; 777 778 778 - while ((o = getopt_long(argc, argv, "a:dwqVDr:T:ph", 779 + while ((o = getopt_long(argc, argv, "s:dwqVDr:T:ph", 779 780 &long_opts[0], NULL)) != EOF) 780 781 #else /* __GNU_LIBRARY__ */ 781 - while ((o = getopt(argc, argv, "a:dwqVDr:T:ph")) != EOF) 782 + while ((o = getopt(argc, argv, "s:dwqVDr:T:ph")) != EOF) 782 783 #endif /* __GNU_LIBRARY__ */ 783 784 switch (o) { 784 - case 'a': 785 - arch = optarg; 785 + case 's': 786 + mod_prefix = optarg; 786 787 break; 787 788 case 'd': 788 789 flag_debug++; ··· 825 826 genksyms_usage(); 826 827 return 1; 827 828 } 828 - if ((strcmp(arch, "h8300") == 0) || (strcmp(arch, "blackfin") == 0) || 829 - (strcmp(arch, "metag") == 0)) 830 - mod_prefix = "_"; 831 829 { 832 830 extern int yydebug; 833 831 extern int yy_flex_debug;
+62 -32
scripts/mod/modpost.c
··· 15 15 #include <stdio.h> 16 16 #include <ctype.h> 17 17 #include <string.h> 18 + #include <limits.h> 19 + #include <stdbool.h> 18 20 #include "modpost.h" 19 21 #include "../../include/generated/autoconf.h" 20 22 #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 - 23 + #include "../../include/linux/export.h" 29 24 30 25 /* Are we using CONFIG_MODVERSIONS? */ 31 26 int modversions = 0; ··· 80 85 va_end(arglist); 81 86 } 82 87 88 + static inline bool strends(const char *str, const char *postfix) 89 + { 90 + if (strlen(str) < strlen(postfix)) 91 + return false; 92 + 93 + return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; 94 + } 95 + 83 96 static int is_vmlinux(const char *modname) 84 97 { 85 98 const char *myname; ··· 123 120 return mod; 124 121 } 125 122 126 - static struct module *new_module(char *modname) 123 + static struct module *new_module(const char *modname) 127 124 { 128 125 struct module *mod; 129 - char *p, *s; 126 + char *p; 130 127 131 128 mod = NOFAIL(malloc(sizeof(*mod))); 132 129 memset(mod, 0, sizeof(*mod)); 133 130 p = NOFAIL(strdup(modname)); 134 131 135 132 /* strip trailing .o */ 136 - s = strrchr(p, '.'); 137 - if (s != NULL) 138 - if (strcmp(s, ".o") == 0) { 139 - *s = '\0'; 140 - mod->is_dot_o = 1; 141 - } 133 + if (strends(p, ".o")) { 134 + p[strlen(p) - 2] = '\0'; 135 + mod->is_dot_o = 1; 136 + } 142 137 143 138 /* add to list */ 144 139 mod->name = p; ··· 563 562 static int ignore_undef_symbol(struct elf_info *info, const char *symname) 564 563 { 565 564 /* ignore __this_module, it will be resolved shortly */ 566 - if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0) 565 + if (strcmp(symname, VMLINUX_SYMBOL_STR(__this_module)) == 0) 567 566 return 1; 568 567 /* ignore global offset table */ 569 568 if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0) ··· 584 583 return 0; 585 584 } 586 585 587 - #define CRC_PFX MODULE_SYMBOL_PREFIX "__crc_" 588 - #define KSYMTAB_PFX MODULE_SYMBOL_PREFIX "__ksymtab_" 586 + #define CRC_PFX VMLINUX_SYMBOL_STR(__crc_) 587 + #define KSYMTAB_PFX VMLINUX_SYMBOL_STR(__ksymtab_) 589 588 590 589 static void handle_modversions(struct module *mod, struct elf_info *info, 591 590 Elf_Sym *sym, const char *symname) ··· 638 637 } 639 638 #endif 640 639 641 - if (memcmp(symname, MODULE_SYMBOL_PREFIX, 642 - strlen(MODULE_SYMBOL_PREFIX)) == 0) { 643 - mod->unres = 644 - alloc_symbol(symname + 645 - strlen(MODULE_SYMBOL_PREFIX), 646 - ELF_ST_BIND(sym->st_info) == STB_WEAK, 647 - mod->unres); 648 - } 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); 649 649 break; 650 650 default: 651 651 /* All exported symbols */ ··· 654 652 sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, 655 653 export); 656 654 } 657 - if (strcmp(symname, MODULE_SYMBOL_PREFIX "init_module") == 0) 655 + if (strcmp(symname, VMLINUX_SYMBOL_STR(init_module)) == 0) 658 656 mod->has_init = 1; 659 - if (strcmp(symname, MODULE_SYMBOL_PREFIX "cleanup_module") == 0) 657 + if (strcmp(symname, VMLINUX_SYMBOL_STR(cleanup_module)) == 0) 660 658 mod->has_cleanup = 1; 661 659 break; 662 660 } ··· 1764 1762 mod->unres = alloc_symbol("module_layout", 0, mod->unres); 1765 1763 } 1766 1764 1765 + static void read_symbols_from_files(const char *filename) 1766 + { 1767 + FILE *in = stdin; 1768 + char fname[PATH_MAX]; 1769 + 1770 + if (strcmp(filename, "-") != 0) { 1771 + in = fopen(filename, "r"); 1772 + if (!in) 1773 + fatal("Can't open filenames file %s: %m", filename); 1774 + } 1775 + 1776 + while (fgets(fname, PATH_MAX, in) != NULL) { 1777 + if (strends(fname, "\n")) 1778 + fname[strlen(fname)-1] = '\0'; 1779 + read_symbols(fname); 1780 + } 1781 + 1782 + if (in != stdin) 1783 + fclose(in); 1784 + } 1785 + 1767 1786 #define SZ 500 1768 1787 1769 1788 /* We first write the generated file into memory using the ··· 1957 1934 s->name, mod->name); 1958 1935 continue; 1959 1936 } 1960 - buf_printf(b, "\t{ %#8x, \"%s\" },\n", s->crc, s->name); 1937 + buf_printf(b, "\t{ %#8x, __VMLINUX_SYMBOL_STR(%s) },\n", 1938 + s->crc, s->name); 1961 1939 } 1962 1940 1963 1941 buf_printf(b, "};\n"); ··· 2146 2122 struct module *mod; 2147 2123 struct buffer buf = { }; 2148 2124 char *kernel_read = NULL, *module_read = NULL; 2149 - char *dump_write = NULL; 2125 + char *dump_write = NULL, *files_source = NULL; 2150 2126 int opt; 2151 2127 int err; 2152 2128 struct ext_sym_list *extsym_iter; 2153 2129 struct ext_sym_list *extsym_start = NULL; 2154 2130 2155 - while ((opt = getopt(argc, argv, "i:I:e:msSo:awM:K:")) != -1) { 2131 + while ((opt = getopt(argc, argv, "i:I:e:msST:o:awM:K:")) != -1) { 2156 2132 switch (opt) { 2157 2133 case 'i': 2158 2134 kernel_read = optarg; ··· 2184 2160 case 'S': 2185 2161 sec_mismatch_verbose = 0; 2186 2162 break; 2163 + case 'T': 2164 + files_source = optarg; 2165 + break; 2187 2166 case 'w': 2188 2167 warn_unresolved = 1; 2189 2168 break; ··· 2208 2181 2209 2182 while (optind < argc) 2210 2183 read_symbols(argv[optind++]); 2184 + 2185 + if (files_source) 2186 + read_symbols_from_files(files_source); 2211 2187 2212 2188 for (mod = modules; mod; mod = mod->next) { 2213 2189 if (mod->skip)