From 1aa6c0d1cbfcd0608a029a805952a2ecae0794da Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 11 Apr 2004 22:58:26 -0700 Subject: [PATCH] Fix scripts/kernel-doc to handle __attribute__ From: Tom Rini The following patch is needed so that kernel-doc can handle functions which have __attribute__'s on them (such as __attribute__ ((weak))). --- scripts/kernel-doc | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 3c02ef90abc8..945a28bdedbd 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -1376,6 +1376,7 @@ sub dump_function($$) { $prototype =~ s/^inline +//; $prototype =~ s/^__inline__ +//; $prototype =~ s/^#define +//; #ak added + $prototype =~ s/__attribute__ \(\([a-z,]*\)\)//; # Yes, this truly is vile. We are looking for: # 1. Return type (may be nothing if we're looking at a macro) -- cgit v1.2.3 From 3bca5aa3e53f330d9f239503639b24308418bb2e Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 11 Apr 2004 23:00:24 -0700 Subject: [PATCH] ver_linux fix From: Rusty Russell From: Adrian Bunk Some versions of ps print non-version lines when ps --version is invoked. grep them out. --- scripts/ver_linux | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/ver_linux b/scripts/ver_linux index bec902b2f7c0..47f14cbac39e 100755 --- a/scripts/ver_linux +++ b/scripts/ver_linux @@ -68,7 +68,8 @@ ldd -v > /dev/null 2>&1 && ldd -v || ldd --version |head -n 1 | awk \ ls -l /usr/lib/lib{g,stdc}++.so 2>/dev/null | awk -F. \ '{print "Linux C++ Library " $4"."$5"."$6}' -ps --version 2>&1 | awk 'NR==1{print "Procps ", $NF}' +ps --version 2>&1 | grep version | awk \ +'NR==1{print "Procps ", $NF}' ifconfig --version 2>&1 | grep tools | awk \ 'NR==1{print "Net-tools ", $NF}' -- cgit v1.2.3 From f17ea0566ba38378df8e10a5f1f67cf1f6cc2c66 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 11 Apr 2004 23:02:14 -0700 Subject: [PATCH] Fix genksyms parsing From: Rusty Russell From: Andreas Schwab I'm getting a warning when building for ia64 with MODVERSIONS enabled. This is a bug in genksyms, it can't cope with some arguments of __typeof__. The following patch will fix that. Actually the argument of __typeof__ is an abstract declarator, but the genksyms parser has no production for that; decl_specifier_seq also matches some invalid constructs, but I don't think this is a problem in practice, since the compiler will reject them. --- scripts/genksyms/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 386189f4d108..099043713db4 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -197,7 +197,7 @@ storage_class_specifier: type_specifier: simple_type_specifier | cvar_qualifier - | TYPEOF_KEYW '(' type_specifier ')' + | TYPEOF_KEYW '(' decl_specifier_seq ')' /* References to s/u/e's defined elsewhere. Rearrange things so that it is easier to expand the definition fully later. */ -- cgit v1.2.3 From 7ee168c0b7a988210cc8024d105dfd1cb3e956e6 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 11 Apr 2004 23:05:02 -0700 Subject: [PATCH] Move __this_module to modpost From: Brian Gerst Move the __this_module structure to the modpost code where it really belongs. --- include/linux/module.h | 16 +--------------- scripts/Makefile.modpost | 2 ++ scripts/modpost.c | 12 ++++++++++++ 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'scripts') diff --git a/include/linux/module.h b/include/linux/module.h index 4c9b53d5d51c..0a86652fb1cb 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -70,6 +70,7 @@ static const char __module_cat(name,__LINE__)[] \ extern const struct gtype##_id __mod_##gtype##_table \ __attribute__ ((unused, alias(__stringify(name)))) +extern struct module __this_module; #define THIS_MODULE (&__this_module) #else /* !MODULE */ @@ -481,21 +482,6 @@ static inline int unregister_module_notifier(struct notifier_block * nb) #endif /* CONFIG_MODULES */ -#ifdef MODULE -extern struct module __this_module; -#ifdef KBUILD_MODNAME -/* We make the linker do some of the work. */ -struct module __this_module -__attribute__((section(".gnu.linkonce.this_module"))) = { - .name = __stringify(KBUILD_MODNAME), - .init = init_module, -#ifdef CONFIG_MODULE_UNLOAD - .exit = cleanup_module, -#endif -}; -#endif /* KBUILD_MODNAME */ -#endif /* MODULE */ - #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index cd716ece8976..d349dda5edf7 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -35,6 +35,8 @@ targets += $(modules) # Compile version info for unresolved symbols +modname = $(*F) + quiet_cmd_cc_o_c = CC $@ cmd_cc_o_c = $(CC) $(c_flags) $(CFLAGS_MODULE) \ -c -o $@ $< diff --git a/scripts/modpost.c b/scripts/modpost.c index a0976fcb9982..69168e18d5bf 100644 --- a/scripts/modpost.c +++ b/scripts/modpost.c @@ -343,6 +343,9 @@ handle_modversions(struct module *mod, struct elf_info *info, /* ignore global offset table */ if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0) break; + /* ignore __this_module, it will be resolved shortly */ + if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0) + break; #ifdef STT_REGISTER if (info->hdr->e_machine == EM_SPARC || info->hdr->e_machine == EM_SPARCV9) { @@ -468,6 +471,15 @@ add_header(struct buffer *b) buf_printf(b, "#include \n"); buf_printf(b, "\n"); buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); + buf_printf(b, "\n"); + buf_printf(b, "struct module __this_module\n"); + buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n"); + buf_printf(b, " .name = __stringify(KBUILD_MODNAME),\n"); + buf_printf(b, " .init = init_module,\n"); + buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"); + buf_printf(b, " .exit = cleanup_module,\n"); + buf_printf(b, "#endif\n"); + buf_printf(b, "};\n"); } /* Record CRCs for unresolved symbols */ -- cgit v1.2.3 From 7fdaa12102db8aa6bf3ecfcd11bd8b655585a87e Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 11 Apr 2004 23:05:15 -0700 Subject: [PATCH] fix modversions now __this_module is created only in .ko From: Rusty Russell Brian Gerst's patch which moved __this_module out from module.h into the module post-processing had a side effect. genksyms didn't see the undefined symbols for modules without a module_init (or module_exit), and hence didn't generate a version for them, causing the kernel to be tainted. The simple solution is to always include the versions for these functions. Also includes two cleanups: 1) alloc_symbol is easier to use if it populates ->next for us. 2) add_exported_symbol should set owner to module, not head of module list (we don't use this field in entries in that list, fortunately). --- scripts/modpost.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'scripts') diff --git a/scripts/modpost.c b/scripts/modpost.c index 69168e18d5bf..889d5d08a289 100644 --- a/scripts/modpost.c +++ b/scripts/modpost.c @@ -113,12 +113,13 @@ static inline unsigned int tdb_hash(const char *name) * the list of unresolved symbols per module */ struct symbol * -alloc_symbol(const char *name) +alloc_symbol(const char *name, struct symbol *next) { struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); memset(s, 0, sizeof(*s)); strcpy(s->name, name); + s->next = next; return s; } @@ -128,17 +129,15 @@ void new_symbol(const char *name, struct module *module, unsigned int *crc) { unsigned int hash; - struct symbol *new = alloc_symbol(name); + struct symbol *new; + hash = tdb_hash(name) % SYMBOL_HASH_SIZE; + new = symbolhash[hash] = alloc_symbol(name, symbolhash[hash]); new->module = module; if (crc) { new->crc = *crc; new->crc_valid = 1; } - - hash = tdb_hash(name) % SYMBOL_HASH_SIZE; - new->next = symbolhash[hash]; - symbolhash[hash] = new; } struct symbol * @@ -165,7 +164,7 @@ add_exported_symbol(const char *name, struct module *module, unsigned int *crc) struct symbol *s = find_symbol(name); if (!s) { - new_symbol(name, modules, crc); + new_symbol(name, module, crc); return; } if (crc) { @@ -319,7 +318,6 @@ void handle_modversions(struct module *mod, struct elf_info *info, Elf_Sym *sym, const char *symname) { - struct symbol *s; unsigned int crc; switch (sym->st_shndx) { @@ -356,13 +354,10 @@ handle_modversions(struct module *mod, struct elf_info *info, #endif if (memcmp(symname, MODULE_SYMBOL_PREFIX, - strlen(MODULE_SYMBOL_PREFIX)) == 0) { - s = alloc_symbol(symname + - strlen(MODULE_SYMBOL_PREFIX)); - /* add to list */ - s->next = mod->unres; - mod->unres = s; - } + strlen(MODULE_SYMBOL_PREFIX)) == 0) + mod->unres = alloc_symbol(symname + + strlen(MODULE_SYMBOL_PREFIX), + mod->unres); break; default: /* All exported symbols */ @@ -393,7 +388,6 @@ read_symbols(char *modname) const char *symname; struct module *mod; struct elf_info info = { }; - struct symbol *s; Elf_Sym *sym; /* When there's no vmlinux, don't print warnings about @@ -419,10 +413,12 @@ read_symbols(char *modname) * the automatic versioning doesn't pick it up, but it's really * important anyhow */ if (modversions) { - s = alloc_symbol("struct_module"); - /* add to list */ - s->next = mod->unres; - mod->unres = s; + mod->unres = alloc_symbol("struct_module", mod->unres); + + /* Always version init_module and cleanup_module, in + * case module doesn't have its own. */ + mod->unres = alloc_symbol("init_module", mod->unres); + mod->unres = alloc_symbol("cleanup_module", mod->unres); } } -- cgit v1.2.3 From ffe52a4ad78700325df3ca8c4d44ba04a1149545 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 11 Apr 2004 23:07:40 -0700 Subject: [PATCH] kill spurious MAKDEV scripts From: Christoph Hellwig Kill magic ide/sound makedev scripts in scripts/. The userland MAKEDEV is the proper place and already has support for them. --- Documentation/ide.txt | 6 +- Documentation/sound/alsa/ALSA-Configuration.txt | 3 +- scripts/MAKEDEV.ide | 49 -------- scripts/MAKEDEV.snd | 161 ------------------------ 4 files changed, 3 insertions(+), 216 deletions(-) delete mode 100755 scripts/MAKEDEV.ide delete mode 100755 scripts/MAKEDEV.snd (limited to 'scripts') diff --git a/Documentation/ide.txt b/Documentation/ide.txt index 6ed7eb16335e..07811d2df557 100644 --- a/Documentation/ide.txt +++ b/Documentation/ide.txt @@ -65,9 +65,7 @@ sixth.. ide5, usually PCI, probed To access devices on interfaces > ide0, device entries please make sure that device files for them are present in /dev. If not, please create such -entries, by simply running the included shell script: - - /usr/src/linux/scripts/MAKEDEV.ide +entries, by using /dev/MAKEDEV. This driver automatically probes for most IDE interfaces (including all PCI ones), for the drives/geometries attached to those interfaces, and for the IRQ @@ -344,7 +342,7 @@ The character device interface consists of the following devices: nht1 major 37, minor 129 second IDE tape, no rewind on close. ... -Run linux/scripts/MAKEDEV.ide to create the above entries. +Run /dev/MAKEDEV to create the above entries. The general magnetic tape commands compatible interface, as defined by include/linux/mtio.h, is accessible through the character device. diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt index 0badcacd9dc0..addec50998e6 100644 --- a/Documentation/sound/alsa/ALSA-Configuration.txt +++ b/Documentation/sound/alsa/ALSA-Configuration.txt @@ -30,8 +30,7 @@ isapnptools. Creating ALSA devices ===================== -Use the MAKEDEV.snd script located in the directory named scripts -in the linux kernel tree. +Use the /dev/MAKEDEV script to create the nessecary device nodes. Module parameters diff --git a/scripts/MAKEDEV.ide b/scripts/MAKEDEV.ide deleted file mode 100755 index feecb99bb865..000000000000 --- a/scripts/MAKEDEV.ide +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# -# This script creates the proper /dev/ entries for IDE devices -# on the primary, secondary, tertiary, and quaternary interfaces. -# See ../Documentation/ide.txt for more information. -# -makedev () { - rm -f /dev/$1 - echo mknod /dev/$1 $2 $3 $4 - mknod /dev/$1 $2 $3 $4 - chown root:disk /dev/$1 - chmod 660 /dev/$1 -} - -makedevs () { - rm -f /dev/$1* - makedev $1 b $2 $3 - for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 - do - makedev $1$part b $2 `expr $3 + $part` - done -} - -makedevs hda 3 0 -makedevs hdb 3 64 -makedevs hdc 22 0 -makedevs hdd 22 64 -makedevs hde 33 0 -makedevs hdf 33 64 -makedevs hdg 34 0 -makedevs hdh 34 64 -makedevs hdi 56 0 -makedevs hdj 56 64 -makedevs hdk 57 0 -makedevs hdl 57 64 -makedevs hdm 88 0 -makedevs hdn 88 64 -makedevs hdo 89 0 -makedevs hdp 89 64 -makedevs hdq 90 0 -makedevs hdr 90 64 -makedevs hds 91 0 -makedevs hdt 91 64 - -for tape in 0 1 2 3 4 5 6 7 -do - makedev ht$tape c 37 $tape - makedev nht$tape c 37 `expr $tape + 128` -done diff --git a/scripts/MAKEDEV.snd b/scripts/MAKEDEV.snd deleted file mode 100755 index 586973289206..000000000000 --- a/scripts/MAKEDEV.snd +++ /dev/null @@ -1,161 +0,0 @@ -#!/bin/bash -# -# This script creates the proper /dev/ entries for ALSA devices. -# See ../Documentation/sound/alsa/ALSA-Configuration.txt for more -# information. - -MAJOR=116 -OSSMAJOR=14 -MAX_CARDS=4 -PERM=666 -OWNER=root.root - -if [ "`grep -w -E "^audio" /etc/group`x" != x ]; then - PERM=660 - OWNER=root.audio -fi - -function create_odevice () { - rm -f $1 - echo -n "Creating $1..." - mknod -m $PERM $1 c $OSSMAJOR $2 - chown $OWNER $1 - echo " done" -} - -function create_odevices () { - tmp=0 - tmp1=0 - rm -f $1 $1? - echo -n "Creating $1?..." - while [ $tmp1 -lt $MAX_CARDS ]; do - minor=$[ $2 + $tmp ] - mknod -m $PERM $1$tmp1 c $OSSMAJOR $minor - chown $OWNER $1$tmp1 - tmp=$[ $tmp + 16 ] - tmp1=$[ $tmp1 + 1 ] - done - echo " done" -} - -function create_device1 () { - rm -f $1 - minor=$2 - echo -n "Creating $1..." - mknod -m $PERM $1 c $MAJOR $minor - chown $OWNER $1 - echo " done" -} - -function create_devices () { - tmp=0 - rm -f $1 $1? - echo -n "Creating $1?..." - while [ $tmp -lt $MAX_CARDS ]; do - minor=$[ $tmp * 32 ] - minor=$[ $2 + $minor ] - mknod -m $PERM "${1}C${tmp}" c $MAJOR $minor - chown $OWNER "${1}C${tmp}" - tmp=$[ $tmp + 1 ] - done - echo " done" -} - -function create_devices2 () { - tmp=0 - rm -f $1 $1? - echo -n "Creating $1??..." - while [ $tmp -lt $MAX_CARDS ]; do - tmp1=0 - while [ $tmp1 -lt $3 ]; do - minor=$[ $tmp * 32 ] - minor=$[ $2 + $minor + $tmp1 ] - mknod -m $PERM "${1}C${tmp}D${tmp1}" c $MAJOR $minor - chown $OWNER "${1}C${tmp}D${tmp1}" - tmp1=$[ $tmp1 + 1 ] - done - tmp=$[ $tmp + 1 ] - done - echo " done" -} - -function create_devices3 () { - tmp=0 - rm -f $1 $1? - echo -n "Creating $1??$4..." - while [ $tmp -lt $MAX_CARDS ]; do - tmp1=0 - while [ $tmp1 -lt $3 ]; do - minor=$[ $tmp * 32 ] - minor=$[ $2 + $minor + $tmp1 ] - mknod -m $PERM "${1}C${tmp}D${tmp1}${4}" c $MAJOR $minor - chown $OWNER "${1}C${tmp}D${tmp1}${4}" - tmp1=$[ $tmp1 + 1 ] - done - tmp=$[ $tmp + 1 ] - done - echo " done" -} - -if test "$1" = "-?" || test "$1" = "-h" || test "$1" = "--help"; then - echo "Usage: snddevices [max]" - exit -fi - -if test "$1" = "max"; then - DSP_MINOR=19 -fi - -# OSS (Lite) compatible devices... - -if test $OSSMAJOR -eq 14; then - create_odevices /dev/mixer 0 - create_odevice /dev/sequencer 1 - create_odevices /dev/midi 2 - create_odevices /dev/dsp 3 - create_odevices /dev/audio 4 - create_odevice /dev/sndstat 6 - create_odevice /dev/music 8 - create_odevices /dev/dmmidi 9 - create_odevices /dev/dmfm 10 - create_odevices /dev/amixer 11 # alternate mixer - create_odevices /dev/adsp 12 # alternate dsp - create_odevices /dev/amidi 13 # alternate midi - create_odevices /dev/admmidi 14 # alternate direct midi - # create symlinks - ln -svf /dev/mixer0 /dev/mixer - ln -svf /dev/midi0 /dev/midi - ln -svf /dev/dsp0 /dev/dsp - ln -svf /dev/audio0 /dev/audio - ln -svf /dev/music /dev/sequencer2 - ln -svf /dev/adsp0 /dev/adsp - ln -svf /dev/amidi0 /dev/amidi -fi - -# Remove old devices - -mv -f /dev/sndstat /dev/1sndstat -rm -f /dev/snd* -mv -f /dev/1sndstat /dev/sndstat -if [ -d /dev/snd ]; then - rm -f /dev/snd/* - rmdir /dev/snd -fi - -# Create new ones - -mkdir -p /dev/snd -create_devices /dev/snd/control 0 -create_device1 /dev/snd/seq 1 -create_device1 /dev/snd/timer 33 -create_devices2 /dev/snd/hw 4 4 -create_devices2 /dev/snd/midi 8 8 -create_devices3 /dev/snd/pcm 16 8 p -create_devices3 /dev/snd/pcm 24 8 c - -# Loader devices - -echo "ALSA loader devices" -rm -f /dev/aload* -create_devices /dev/aload 0 -create_device1 /dev/aloadSEQ 1 -- cgit v1.2.3 From 6ab26f0a7443f4d4e2b13c31717088ad410cb64b Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Mon, 12 Apr 2004 01:03:15 -0700 Subject: [PATCH] Fix More Problems Introduced By Module Structure Added in modpost.c From: Rusty Russell Sam Ravnborg found these. 1) have_vmlinux is a global, and should not be reset every time. 2) We pretend every module needs cleanup_module so it gets versioned, but that isn't defined for CONFIG_MODULE_UNLOAD=n. 3) The visible effect of this is that modpost will start complaning about undefined symbols - previously this happened only when the module was isntalled. --- scripts/modpost.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/modpost.c b/scripts/modpost.c index 889d5d08a289..99433732e912 100644 --- a/scripts/modpost.c +++ b/scripts/modpost.c @@ -390,14 +390,20 @@ read_symbols(char *modname) struct elf_info info = { }; Elf_Sym *sym; - /* When there's no vmlinux, don't print warnings about - * unresolved symbols (since there'll be too many ;) */ - have_vmlinux = is_vmlinux(modname); - parse_elf(&info, modname); mod = new_module(modname); + /* When there's no vmlinux, don't print warnings about + * unresolved symbols (since there'll be too many ;) */ + if (is_vmlinux(modname)) { + unsigned int fake_crc = 0; + have_vmlinux = 1; + /* May not have this if !CONFIG_MODULE_UNLOAD: fake it. + If it appears, we'll get the real CRC. */ + add_exported_symbol("cleanup_module", mod, &fake_crc); + } + for (sym = info.symtab_start; sym < info.symtab_stop; sym++) { symname = info.strtab + sym->st_name; -- cgit v1.2.3 From 07e5823127155b3a29003aca926f87c9843f6810 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Mon, 12 Apr 2004 01:05:40 -0700 Subject: [PATCH] kbuild: external module support From: Sam Ravnborg Based on initial patch from Andreas Gruenbacher there is now better support for building external modules with kbuild. The preferred syntax is now: make -C $KERNELSRC M=$PWD but the old syntax: make -C $KERNELSRC SUBDIRS=$PWD modules will remain supported. The major differences compared to before are that: 1) No attempt is made to neither check nor update any files in $KERNELSRC 2) Module versions are now supported During stage 2 of kernel compilation where the modules are built, a new file Module.symvers is created. This file contains the version for all symbols exported by the kernel and any module compiled within the kernel tree. When the external module is build the Module.symvers file is being read and symbol versions are used from that file. The purpose of avoiding any updates in the kernel src is that usually in a distribution the kernel src will be read-only, and there is no need to try to update it. And when building an external module the focus is on the module, not the kernel. I expect the distributions will start using something like this: kernel src - with no generated files. Not even .config: /usr/src/linux- Output from build: /lib/modules/linux-/build where build is a real directory with relevant output files and the appropriate .config. I have some Documentation in the pipe-line, but wants to see how this approach is received before completing it. This patch is made on top of the previously posted patch to divide make clean in three steps. And you may need to edit the following line in the patch to make it apply: %docs: scripts_basic FORCE to %docs: scripts FORCE --- Makefile | 279 ++++++++++++++++++++++++++++++----------------- scripts/Makefile.modpost | 12 +- scripts/modpost.c | 114 ++++++++++++++++++- scripts/modpost.h | 1 + 4 files changed, 290 insertions(+), 116 deletions(-) (limited to 'scripts') diff --git a/Makefile b/Makefile index b2b15283fa5e..6139d83a3e32 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,19 @@ ifndef KBUILD_CHECKSRC KBUILD_CHECKSRC = 0 endif +# Use make M=dir to specify direcotry of external module to build +# Old syntax make ... SUBDIRS=$PWD is still supported +# Setting the environment variable KBUILD_EXTMOD take precedence +ifdef SUBDIRS + KBUILD_EXTMOD ?= $(SUBDIRS) +endif +ifdef M + ifeq ("$(origin M)", "command line") + KBUILD_EXTMOD := $(M) + endif +endif + + # kbuild supports saving output files in a separate directory. # To locate output files in a separate directory two syntax'es are supported. # In both cases the working directory must be the root of the kernel src. @@ -81,9 +94,9 @@ ifdef O endif # That's our default target when none is given on the command line -.PHONY: all -all: - +.PHONY: _all +_all: + ifneq ($(KBUILD_OUTPUT),) # Invoke a second make in the output directory, passing relevant variables # check that the output directory actually exists @@ -94,10 +107,11 @@ $(if $(wildcard $(KBUILD_OUTPUT)),, \ .PHONY: $(MAKECMDGOALS) -$(filter-out all,$(MAKECMDGOALS)) all: +$(filter-out _all,$(MAKECMDGOALS)) _all: $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \ - KBUILD_SRC=$(CURDIR) KBUILD_VERBOSE=$(KBUILD_VERBOSE) \ - KBUILD_CHECK=$(KBUILD_CHECK) -f $(CURDIR)/Makefile $@ + KBUILD_SRC=$(CURDIR) KBUILD_VERBOSE=$(KBUILD_VERBOSE) \ + KBUILD_CHECK=$(KBUILD_CHECK) KBUILD_EXTMOD=$(KBUILD_EXTMOD) \ + -f $(CURDIR)/Makefile $@ # Leave processing to above invocation of make skip-makefile := 1 @@ -107,6 +121,15 @@ endif # ifeq ($(KBUILD_SRC),) # We process the rest of the Makefile if this is the final invocation of make ifeq ($(skip-makefile),) +# If building an external module we do not care about the all: rule +# but instead _all depend on modules +.PHONY: all +ifeq ($(KBUILD_EXTMOD),) +_all: all +else +_all: modules +endif + # Make sure we're not wasting cpu-cycles doing locale handling, yet do make # sure error messages appear in the user-desired language ifdef LC_ALL @@ -194,7 +217,7 @@ endif # in addition to whatever we do anyway. # Just "make" or "make all" shall build modules as well -ifneq ($(filter all modules,$(MAKECMDGOALS)),) +ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) KBUILD_MODULES := 1 endif @@ -203,7 +226,7 @@ ifeq ($(MAKECMDGOALS),) endif export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE -export KBUILD_CHECKSRC KBUILD_SRC +export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD # Beautify output # --------------------------------------------------------------------------- @@ -299,7 +322,10 @@ export CPPFLAGS NOSTDINC_FLAGS OBJCOPYFLAGS LDFLAGS export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE -export MODVERDIR := .tmp_versions +# When compiling out-of-tree modules, put MODVERDIR in the module +# tree rather than in the kernel tree. The kernel tree might +# even be read-only. +export MODVERDIR := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/).tmp_versions # The temporary file to save gcc -MD generated dependencies must not # contain a comma @@ -340,11 +366,13 @@ ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) endif endif -ifneq ($(filter config %config,$(MAKECMDGOALS)),) - config-targets := 1 - ifneq ($(filter-out config %config,$(MAKECMDGOALS)),) - mixed-targets := 1 - endif +ifeq ($(KBUILD_EXTMOD),) + ifneq ($(filter config %config,$(MAKECMDGOALS)),) + config-targets := 1 + ifneq ($(filter-out config %config,$(MAKECMDGOALS)),) + mixed-targets := 1 + endif + endif endif ifeq ($(mixed-targets),1) @@ -371,6 +399,7 @@ else # Build targets only - this includes vmlinux, arch specific targets, clean # targets and others. In general all targets except *config targets. +ifeq ($(KBUILD_EXTMOD),) # Additional helpers built in scripts/ # Carefully list dependencies so we do not try to build scripts twice # in parrallel @@ -393,7 +422,7 @@ drivers-y := drivers/ sound/ net-y := net/ libs-y := lib/ core-y := usr/ -SUBDIRS := +endif # KBUILD_EXTMOD ifeq ($(dot-config),1) # In this section, we need .config @@ -420,33 +449,6 @@ endif include $(srctree)/arch/$(ARCH)/Makefile -# Let architecture Makefiles change CPPFLAGS if needed -CFLAGS := $(CPPFLAGS) $(CFLAGS) -AFLAGS := $(CPPFLAGS) $(AFLAGS) - -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ - -SUBDIRS += $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ - $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ - $(net-y) $(net-m) $(libs-y) $(libs-m))) - -ALL_SUBDIRS := $(sort $(SUBDIRS) $(patsubst %/,%,$(filter %/, \ - $(init-n) $(init-) \ - $(core-n) $(core-) $(drivers-n) $(drivers-) \ - $(net-n) $(net-) $(libs-n) $(libs-)))) - -init-y := $(patsubst %/, %/built-in.o, $(init-y)) -core-y := $(patsubst %/, %/built-in.o, $(core-y)) -drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y)) -net-y := $(patsubst %/, %/built-in.o, $(net-y)) -libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) -libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y)) -libs-y := $(libs-y1) $(libs-y2) - -# Here goes the main Makefile -# --------------------------------------------------------------------------- - - ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE CFLAGS += -Os else @@ -480,6 +482,27 @@ CFLAGS += $(call check_gcc,-Wdeclaration-after-statement,) MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) export MODLIB + +ifeq ($(KBUILD_EXTMOD),) +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ + +vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ + $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ + $(net-y) $(net-m) $(libs-y) $(libs-m))) + +vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \ + $(init-n) $(init-) \ + $(core-n) $(core-) $(drivers-n) $(drivers-) \ + $(net-n) $(net-) $(libs-n) $(libs-)))) + +init-y := $(patsubst %/, %/built-in.o, $(init-y)) +core-y := $(patsubst %/, %/built-in.o, $(core-y)) +drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y)) +net-y := $(patsubst %/, %/built-in.o, $(net-y)) +libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) +libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y)) +libs-y := $(libs-y1) $(libs-y2) + # Build vmlinux # --------------------------------------------------------------------------- @@ -568,12 +591,12 @@ vmlinux: $(vmlinux-objs) $(kallsyms.o) arch/$(ARCH)/kernel/vmlinux.lds.s FORCE # The actual objects are generated when descending, # make sure no implicit rule kicks in -$(sort $(vmlinux-objs)) arch/$(ARCH)/kernel/vmlinux.lds.s: $(SUBDIRS) ; +$(sort $(vmlinux-objs)) arch/$(ARCH)/kernel/vmlinux.lds.s: $(vmlinux-dirs) ; -# Handle descending into subdirectories listed in $(SUBDIRS) +# Handle descending into subdirectories listed in $(vmlinux-dirs) -.PHONY: $(SUBDIRS) -$(SUBDIRS): prepare-all scripts +.PHONY: $(vmlinux-dirs) +$(vmlinux-dirs): prepare-all scripts $(Q)$(MAKE) $(build)=$@ # Things we need to do before we recursively start building the kernel @@ -601,14 +624,7 @@ ifneq ($(KBUILD_SRC),) endif prepare0: prepare1 include/linux/version.h include/asm include/config/MARKER -ifdef KBUILD_MODULES -ifeq ($(origin SUBDIRS),file) $(Q)rm -rf $(MODVERDIR) -else - @echo '*** Warning: Overriding SUBDIRS on the command line can cause' - @echo '*** inconsistencies' -endif -endif $(if $(CONFIG_MODULES),$(Q)mkdir -p $(MODVERDIR)) # All the preparing.. @@ -693,7 +709,7 @@ all: modules # Build modules .PHONY: modules -modules: $(SUBDIRS) $(if $(KBUILD_BUILTIN),vmlinux) +modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) @echo ' Building modules, stage 2.'; $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost @@ -786,14 +802,13 @@ CLEAN_FILES += vmlinux System.map kernel.spec \ MRPROPER_DIRS += include/config include2 MRPROPER_FILES += .config .config.old include/asm .version \ include/linux/autoconf.h include/linux/version.h \ - include/linux/modversions.h \ - tags TAGS cscope* + Module.symvers tags TAGS cscope* # clean - Delete most, but leave enough to build external modules # clean: rm-dirs := $(CLEAN_DIRS) clean: rm-files := $(CLEAN_FILES) -clean-dirs := $(addprefix _clean_,$(ALL_SUBDIRS)) +clean-dirs := $(addprefix _clean_,$(vmlinux-alldirs)) .PHONY: $(clean-dirs) clean archclean $(clean-dirs): @@ -833,52 +848,6 @@ distclean: mrproper -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \ -type f -print | xargs rm -f -# Generate tags for editors -# --------------------------------------------------------------------------- - -define all-sources - ( find . $(RCS_FIND_IGNORE) \ - \( -name include -o -name arch \) -prune -o \ - -name '*.[chS]' -print; \ - find arch/$(ARCH) $(RCS_FIND_IGNORE) \ - -name '*.[chS]' -print; \ - find include $(RCS_FIND_IGNORE) \ - \( -name config -o -name 'asm-*' \) -prune \ - -o -name '*.[chS]' -print; \ - find include/asm-$(ARCH) $(RCS_FIND_IGNORE) \ - -name '*.[chS]' -print; \ - find include/asm-generic $(RCS_FIND_IGNORE) \ - -name '*.[chS]' -print ) -endef - -quiet_cmd_cscope-file = FILELST cscope.files - cmd_cscope-file = $(all-sources) > cscope.files - -quiet_cmd_cscope = MAKE cscope.out - cmd_cscope = cscope -k -b -q - -cscope: FORCE - $(call cmd,cscope-file) - $(call cmd,cscope) - -quiet_cmd_TAGS = MAKE $@ -cmd_TAGS = $(all-sources) | etags - - -# Exuberant ctags works better with -I - -quiet_cmd_tags = MAKE $@ -define cmd_tags - rm -f $@; \ - CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \ - $(all-sources) | xargs ctags $$CTAGSF -a -endef - -TAGS: FORCE - $(call cmd,TAGS) - -tags: FORCE - $(call cmd,tags) - # RPM target # --------------------------------------------------------------------------- @@ -961,6 +930,110 @@ help: %docs: scripts_basic FORCE $(Q)$(MAKE) $(build)=Documentation/DocBook $@ +else # KBUILD_EXTMOD + +### +# External module support. +# When building external modules the kernel used as basis is considered +# read-only, and no consistency checks are made and the make +# system is not used on the basis kernel. If updates are required +# in the basis kernel ordinary make commands (without M=...) must +# be used. +# +# The following are the only valid targets when building external +# modules. +# make M=dir clean Delete all automatically generated files +# make M=dir modules Make all modules in specified dir +# make M=dir Same as 'make M=dir modules' +# make M=dir modules_install +# Install the modules build in the module directory +# Assumes install directory is already created + +# We are always building modules +KBUILD_MODULES := 1 + +.PHONY: $(KBUILD_EXTMOD) +$(KBUILD_EXTMOD): FORCE + $(Q)$(MAKE) $(build)=$@ + +.PHONY: modules +modules: $(KBUILD_EXTMOD) + @echo ' Building modules, stage 2.'; + $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost + +.PHONY: modules_install +modules_install: + $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst + +clean-dirs := _clean_$(KBUILD_EXTMOD) + +.PHONY: $(clean-dirs) clean +$(clean-dirs): + $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) + +clean: $(clean-dirs) + @find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \ + \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ + -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \ + -type f -print | xargs rm -f + +help: + @echo ' Building external modules.' + @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target' + @echo '' + @echo ' modules - default target, build the module(s)' + @echo ' modules_install - install the module' + @echo ' clean - remove generated files in module directory only' + @echo '' +endif # KBUILD_EXTMOD + +# Generate tags for editors +# --------------------------------------------------------------------------- + +define all-sources + ( find . $(RCS_FIND_IGNORE) \ + \( -name include -o -name arch \) -prune -o \ + -name '*.[chS]' -print; \ + find arch/$(ARCH) $(RCS_FIND_IGNORE) \ + -name '*.[chS]' -print; \ + find include $(RCS_FIND_IGNORE) \ + \( -name config -o -name 'asm-*' \) -prune \ + -o -name '*.[chS]' -print; \ + find include/asm-$(ARCH) $(RCS_FIND_IGNORE) \ + -name '*.[chS]' -print; \ + find include/asm-generic $(RCS_FIND_IGNORE) \ + -name '*.[chS]' -print ) +endef + +quiet_cmd_cscope-file = FILELST cscope.files + cmd_cscope-file = $(all-sources) > cscope.files + +quiet_cmd_cscope = MAKE cscope.out + cmd_cscope = cscope -k -b -q + +cscope: FORCE + $(call cmd,cscope-file) + $(call cmd,cscope) + +quiet_cmd_TAGS = MAKE $@ +cmd_TAGS = $(all-sources) | etags - + +# Exuberant ctags works better with -I + +quiet_cmd_tags = MAKE $@ +define cmd_tags + rm -f $@; \ + CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \ + $(all-sources) | xargs ctags $$CTAGSF -a +endef + +TAGS: FORCE + $(call cmd,TAGS) + +tags: FORCE + $(call cmd,tags) + + # Scripts to check various things for consistency # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index d349dda5edf7..777b1a111ab5 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -13,12 +13,6 @@ include scripts/Makefile.lib __modules := $(shell head -q -n1 /dev/null $(wildcard $(MODVERDIR)/*.mod)) modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o))) -ifneq ($(filter-out $(modules),$(__modules)),) - $(warning Trouble: $(filter-out $(modules),$(__modules))) - $(warning *** Uh-oh, you have stale module entries. You messed with SUBDIRS,) - $(warning do not complain if something goes wrong.) -endif - __modversions: $(modules) @: @@ -55,9 +49,11 @@ $(modules:.ko=.mod.c): __modpost ; # Extract all checksums for all exported symbols quiet_cmd_modpost = MODPOST - cmd_modpost = scripts/modpost $(filter-out FORCE,$^) + cmd_modpost = scripts/modpost \ + $(if $(filter vmlinux,$^),-o,-i) $(objtree)/Module.symvers \ + $(filter-out FORCE,$^) -__modpost: $(wildcard vmlinux) $(modules:.ko=.o) FORCE +__modpost: $(if $(KBUILD_EXTMOD),,$(wildcard vmlinux)) $(modules:.ko=.o) FORCE $(call if_changed,modpost) targets += __modpost diff --git a/scripts/modpost.c b/scripts/modpost.c index 99433732e912..523e302cf89e 100644 --- a/scripts/modpost.c +++ b/scripts/modpost.c @@ -16,7 +16,7 @@ /* Are we using CONFIG_MODVERSIONS? */ int modversions = 0; -/* Do we have vmlinux? */ +/* Warn about undefined symbols? (do so if we have vmlinux) */ int have_vmlinux = 0; void @@ -58,6 +58,17 @@ void *do_nofail(void *ptr, const char *file, int line, const char *expr) static struct module *modules; +struct module * +find_module(char *modname) +{ + struct module *mod; + + for (mod = modules; mod; mod = mod->next) + if (strcmp(mod->name, modname) == 0) + break; + return mod; +} + struct module * new_module(char *modname) { @@ -181,7 +192,7 @@ grab_file(const char *filename, unsigned long *size) int fd; fd = open(filename, O_RDONLY); - if (fstat(fd, &st) != 0) + if (fd < 0 || fstat(fd, &st) != 0) return NULL; *size = st.st_size; @@ -402,6 +413,8 @@ read_symbols(char *modname) /* May not have this if !CONFIG_MODULE_UNLOAD: fake it. If it appears, we'll get the real CRC. */ add_exported_symbol("cleanup_module", mod, &fake_crc); + add_exported_symbol("struct_module", mod, &fake_crc); + mod->skip = 1; } for (sym = info.symtab_start; sym < info.symtab_stop; sym++) { @@ -604,19 +617,106 @@ write_if_changed(struct buffer *b, const char *fname) fclose(file); } +void +read_dump(const char *fname) +{ + unsigned long size, pos = 0; + void *file = grab_file(fname, &size); + char *line; + + if (!file) { + perror(fname); + abort(); + } + + while ((line = get_next_line(&pos, file, size))) { + char *symname, *modname, *d; + unsigned int crc; + struct module *mod; + + if (!(symname = strchr(line, '\t'))) + goto fail; + *symname++ = '\0'; + if (!(modname = strchr(symname, '\t'))) + goto fail; + *modname++ = '\0'; + if (strchr(modname, '\t')) + goto fail; + crc = strtoul(line, &d, 16); + if (*symname == '\0' || *modname == '\0' || *d != '\0') + goto fail; + + if (!(mod = find_module(modname))) { + if (is_vmlinux(modname)) { + modversions = 1; + have_vmlinux = 1; + } + mod = new_module(NOFAIL(strdup(modname))); + mod->skip = 1; + } + add_exported_symbol(symname, mod, &crc); + } + return; +fail: + fatal("parse error in symbol dump file\n"); +} + +void +write_dump(const char *fname) +{ + struct buffer buf = { }; + struct symbol *symbol; + int n; + + for (n = 0; n < SYMBOL_HASH_SIZE ; n++) { + symbol = symbolhash[n]; + while (symbol) { + symbol = symbol->next; + } + } + + for (n = 0; n < SYMBOL_HASH_SIZE ; n++) { + symbol = symbolhash[n]; + while (symbol) { + buf_printf(&buf, "0x%08x\t%s\t%s\n", symbol->crc, + symbol->name, symbol->module->name); + symbol = symbol->next; + } + } + write_if_changed(&buf, fname); +} + int main(int argc, char **argv) { struct module *mod; struct buffer buf = { }; char fname[SZ]; + char *dump_read = NULL, *dump_write = NULL; + int opt; - for (; argv[1]; argv++) { - read_symbols(argv[1]); + while ((opt = getopt(argc, argv, "i:o:")) != -1) { + switch(opt) { + case 'i': + dump_read = optarg; + break; + case 'o': + dump_write = optarg; + break; + default: + exit(1); + } + } + + if (dump_read) + read_dump(dump_read); + + while (optind < argc) { + read_symbols(argv[optind++]); } for (mod = modules; mod; mod = mod->next) { - if (is_vmlinux(mod->name)) + if (mod->skip) continue; buf.pos = 0; @@ -629,6 +729,10 @@ main(int argc, char **argv) sprintf(fname, "%s.mod.c", mod->name); write_if_changed(&buf, fname); } + + if (dump_write) + write_dump(dump_write); + return 0; } diff --git a/scripts/modpost.h b/scripts/modpost.h index 0b18b4192a63..ddb013d9fd98 100644 --- a/scripts/modpost.h +++ b/scripts/modpost.h @@ -73,6 +73,7 @@ struct module { const char *name; struct symbol *unres; int seen; + int skip; struct buffer dev_table_buf; }; -- cgit v1.2.3