Question on MODULE_VERSION macro
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
In message <[email protected]> you write:
Quoted 2 lines
Rusty,
Christoph mentioned that aMODULE_VERSIONmacro may be pending.
Hey, thanks Christoph for the reminder. I stopped when we were frozen.
This still seems to apply. Do people think this is huge overkill, or a work of obvious beauty and genius?
Doesn't put things in sysfs, but Greg was working on that for module parameters... Greg?
Cheers,
Rusty.
Name: Add a MODULE_VERSION macro
Author: Rusty Russell
Status: Tested on 2.6.0-test5
D: At the kernel summit, various people asked for a MODULE_VERSION
D: macro to store module strings (for later access through sysfs).
D: A simple md4 is needed to identify changes in modules which,
D: inevitably, do not update the version. It skips whitespace and
D: comments, and includes #includes which are in the same dir. D:
D: The module versions should be set according to this definition,
D: based on the RPM one, or CVS Revision tags. Violators will be shot. D:
D: [<epoch>`:']<version>[`-'<extraversion>] D: <epoch>: A (small) unsigned integer which allows you to start versions D: anew. If not mentioned, it's zero. eg. "2:1.0" is after D: "1:2.0". D: <version>: The <version> may contain only alphanumerics. D: <extraversion>: Like <version>, but inserted for local D: customizations, eg "rh3" or "rusty1".
D:
D: Comparison of two versions (assuming same epoch):
D:
D: Split each into all-digit and all-alphabetical parts. Compare each
D: one one at a time: digit parts numerically, alphabetical in ASCII
D: order. So 0.10 comes after 0.9.
include/linux/module.h +18 -0
@@ -123,6 +123,24 @@ extern const struct gtype##_id __mod_##g#define MODULE_DEVICE_TABLE (type,name) \ MODULE_GENERIC_TABLE(type##_device,name) +/* Version of form [<epoch>:]<version>[-<extra-version>]. +Or for CVS/RCS ID version, everything but the number is stripped. +<epoch>: A (small) unsigned integer which allows you to start versions +anew. If not mentioned, it's zero. eg. "2:1.0" is after +"1:2.0". +<version>: The <version> may contain only alphanumerics and the +character `.'. Ordered by numeric sort for numeric parts, +ascii sort for ascii parts (as per RPM or DEB algorithm). +<extraversion>: Like <version>, but inserted for local +customizations, eg "rh3" or "rusty1". + +Using this automatically adds a checksum of the .c files and the +local headers to the end. Use MODULE_VERSION("") if you want just +this. Macro includes room for this. +*/ +#define MODULE_VERSION (_version) \ + MODULE_INFO(version, _version "\0xxxxxxxxxxxxxxxxxxxxxxxx") +/* Given an address, look for it in the exception tables */ const struct exception_table_entry *search_exception_tables (unsigned long add);
scripts/Makefile +1 -1
@@ -12,7 +12,7 @@ host-progs := fixdep split-include conma mk_elfconfig pnmtologo bin2c always := $(host-progs) empty.o -modpost-objs := modpost.o file2alias.o +modpost-objs := modpost.o file2alias.o sumversion.o subdir-$(CONFIG_MODVERSIONS) += genksyms
scripts/Makefile.build +2 -4
@@ -64,8 +64,6 @@ endif # We keep a list of all modules in $(MODVERDIR) -touch-module = @echo $(@:.o=.ko) > $(MODVERDIR)/$(@F:.o=.mod) - __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ $(if $(KBUILD_MODULES),$(obj-m)) \ $(subdir-ym) $(always)
@@ -178,7 +176,7 @@ endef $(single-used-m): %.o: %.c FORCE $(call if_changed_rule,cc_o_c) - $(touch-module) + @{ echo $(@:.o=.ko); echo $<; } > $(MODVERDIR)/$(@F:.o=.mod) quiet_cmd_cc_lst_c = MKLST $@ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
@@ -273,7 +271,7 @@ $(multi-used-y) : %.o: $(multi-objs-y) F $(multi-used-m) : %.o: $(multi-objs-m) FORCE $(call if_changed,link_multi-m) - $(touch-module) + @{ echo $(@:.o=.ko); echo $(link_multi_deps:.o=.c); } > $(MODVERDIR)/$(@F:.o=.mod) targets += $(multi-used-y) $(multi-used-m)
scripts/Makefile.modpost +2 -1
@@ -10,10 +10,11 @@ include scripts/Makefile.lib # -__modules := $(shell cat /dev/null $(wildcard $(MODVERDIR)/*.mod)) +__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: $(__modules) ) $(warning *** Uh-oh, you have stale module entries. You messed with SUBDIRS,) $(warning do not complain if something goes wrong.) endif
scripts/modpost.c +31 -18
102 lines not on this page · raw message
scripts/modpost.h +10 -0
@@ -80,9 +80,19 @@ struct elf_info {Elf_Sym *symtab_start;Elf_Sym *symtab_stop;const char *strtab; +char *modinfo; +unsigned int modinfo_len; };void handle_moddevtable (struct module *mod,struct elf_info *info,Elf_Sym *sym,const char *symname);void add_moddevtable (struct buffer *buf,struct module *mod); + +void maybe_frob_version (const char *modfilename, +void *modinfo, +unsigned long modinfo_len, +unsigned long modinfo_offset); + +void *grab_file (const char *filename,unsigned long *size); +void release_file (void *file,unsigned long size);
scripts/sumversion.c +540 -0
540 lines not on this page · raw message
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Quoted 9 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 2 lines
Rusty,
Christoph mentioned that aMODULE_VERSIONmacro may be pending.Hey, thanks Christoph for the reminder. I stopped when we were frozen.
This still seems to apply. Do people think this is huge overkill, or a work of obvious beauty and genius?
Looks sane. I'm guessing that modinfo can show this?
Quoted 2 lines
Doesn't put things in sysfs, but Greg was working on that for module parameters... Greg?
Oh yeah, I'll dig out that patch later this week. An older version has been sitting in my bk tree forever, need to update it with the last changes you sent me.
thanks,
greg k-h
In message <[email protected]> you write:
Quoted 5 lines · Rusty Russell
Quoted 4 lines
In message <[email protected]> you write:
Quoted 2 lines
Rusty,
Christoph mentioned that aMODULE_VERSIONmacro may be pending.
Quoted 7 lines
Quoted 5 lines
Hey, thanks Christoph for the reminder. I stopped when we were frozen.
This still seems to apply. Do people think this is huge overkill, or a work of obvious beauty and genius?
Looks sane. I'm guessing that modinfo can show this?
Yes. Looks like so:
arch/i386/kernel/apm.c renamed from arch/i386/kernel/apm.c.~1~ +1 -0
@@ -2081,3 +2081,4 @@MODULE_PARM_DESC (smp,"Set this to enable APM use on an SMP platform. Use with caution on older systems" );MODULE_ALIAS_MISCDEV (APM_MINOR_DEV ); +MODULE_VERSION ("1.16ac-rustytest" );
$ modinfo arch/i386/kernel/apm.ko author: Stephen Rothwell description: Advanced Power Management license: GPL .... version: 1.16ac-rustytest B13E9451C4CA3B89577DEFF vermagic: 2.6.1-bk5 SMP PENTIUMII gcc-3.2 depends:
Thanks,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Any update on the MODULE_VERSION macro getting into mainline?
-Brian
Quoted 42 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 7 lines · Rusty Russell
Quoted 6 lines
In message <[email protected]> you write:
Quoted 2 lines
Rusty,
Christoph mentioned that aMODULE_VERSIONmacro may be pending.Quoted 7 lines
Quoted 5 lines
Hey, thanks Christoph for the reminder. I stopped when we were frozen.
This still seems to apply. Do people think this is huge overkill, or a work of obvious beauty and genius?
Looks sane. I'm guessing that modinfo can show this?
Yes. Looks like so:
arch/i386/kernel/apm.c renamed from arch/i386/kernel/apm.c.~1~ +1
-0@@ -2081,3 +2081,4 @@MODULE_PARM_DESC (smp,"Set this to enable APM use on an SMP platform. Use with caution on older systems" );MODULE_ALIAS_MISCDEV (APM_MINOR_DEV ); +MODULE_VERSION ("1.16ac-rustytest" );$ modinfo arch/i386/kernel/apm.ko author: Stephen Rothwell description: Advanced Power Management license: GPL .... version: 1.16ac-rustytest B13E9451C4CA3B89577DEFF vermagic: 2.6.1-bk5 SMP PENTIUMII gcc-3.2 depends:Thanks,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
In message <[email protected]> you write:
Quoted 1 line
Any update on the
MODULE_VERSIONmacro getting into mainline?
Sam need to ack the build system changes.
Sam?
The way it works is that the .mod file contains the name of the module (as before), but succeeding lines are the constituent parts (assumed to be .c files, which usually works: if they use MODULE_VERSION in a file for which this isn't true we'll get a warning).
As we postprocess modules, we look in the .modinfo section for a "version=", which is placed by the MODULE_VERSION() macro. This will be of form "version=<macroarg>" "\0" [24 chars] "\0". The 24 chars are replaced by the md4 sum of the .c files and any files they #include using '#include "file"' which are found in the current directory. Whitespace is collapsed outside strings, and comments are ignored for purposes of the sum.
The result is a .modinfo entry such as
version=1.16ac-rustytest B13E9451C4CA3B89577DEFF
Cheers!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: Add a MODULE_VERSION macro
Author: Rusty Russell
Status: Tested on 2.6.0-test5
D: At the kernel summit, various people asked for a MODULE_VERSION
D: macro to store module strings (for later access through sysfs).
D: A simple md4 is needed to identify changes in modules which,
D: inevitably, do not update the version. It skips whitespace and
D: comments, and includes #includes which are in the same dir. D:
D: The module versions should be set according to this definition,
D: based on the RPM one, or CVS Revision tags. Violators will be shot. D:
D: [<epoch>`:']<version>[`-'<extraversion>] D: <epoch>: A (small) unsigned integer which allows you to start versions D: anew. If not mentioned, it's zero. eg. "2:1.0" is after D: "1:2.0". D: <version>: The <version> may contain only alphanumerics. D: <extraversion>: Like <version>, but inserted for local D: customizations, eg "rh3" or "rusty1".
D:
D: Comparison of two versions (assuming same epoch):
D:
D: Split each into all-digit and all-alphabetical parts. Compare each
D: one one at a time: digit parts numerically, alphabetical in ASCII
D: order. So 0.10 comes after 0.9.
include/linux/module.h +18 -0
@@ -123,6 +123,24 @@ extern const struct gtype##_id __mod_##g#define MODULE_DEVICE_TABLE (type,name) \ MODULE_GENERIC_TABLE(type##_device,name) +/* Version of form [<epoch>:]<version>[-<extra-version>]. +Or for CVS/RCS ID version, everything but the number is stripped. +<epoch>: A (small) unsigned integer which allows you to start versions +anew. If not mentioned, it's zero. eg. "2:1.0" is after +"1:2.0". +<version>: The <version> may contain only alphanumerics and the +character `.'. Ordered by numeric sort for numeric parts, +ascii sort for ascii parts (as per RPM or DEB algorithm). +<extraversion>: Like <version>, but inserted for local +customizations, eg "rh3" or "rusty1". + +Using this automatically adds a checksum of the .c files and the +local headers to the end. Use MODULE_VERSION("") if you want just +this. Macro includes room for this. +*/ +#define MODULE_VERSION (_version) \ + MODULE_INFO(version, _version "\0xxxxxxxxxxxxxxxxxxxxxxxx") +/* Given an address, look for it in the exception tables */ const struct exception_table_entry *search_exception_tables (unsigned long add);
scripts/Makefile +1 -1
@@ -12,7 +12,7 @@ host-progs := fixdep split-include conma mk_elfconfig pnmtologo bin2c always := $(host-progs) empty.o -modpost-objs := modpost.o file2alias.o +modpost-objs := modpost.o file2alias.o sumversion.o subdir-$(CONFIG_MODVERSIONS) += genksyms
scripts/Makefile.build +2 -4
@@ -64,8 +64,6 @@ endif # We keep a list of all modules in $(MODVERDIR) -touch-module = @echo $(@:.o=.ko) > $(MODVERDIR)/$(@F:.o=.mod) - __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ $(if $(KBUILD_MODULES),$(obj-m)) \ $(subdir-ym) $(always)
@@ -178,7 +176,7 @@ endef $(single-used-m): %.o: %.c FORCE $(call if_changed_rule,cc_o_c) - $(touch-module) + @{ echo $(@:.o=.ko); echo $<; } > $(MODVERDIR)/$(@F:.o=.mod) quiet_cmd_cc_lst_c = MKLST $@ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
@@ -273,7 +271,7 @@ $(multi-used-y) : %.o: $(multi-objs-y) F $(multi-used-m) : %.o: $(multi-objs-m) FORCE $(call if_changed,link_multi-m) - $(touch-module) + @{ echo $(@:.o=.ko); echo $(link_multi_deps:.o=.c); } > $(MODVERDIR)/$(@F:.o=.mod) targets += $(multi-used-y) $(multi-used-m)
scripts/Makefile.modpost +2 -1
@@ -10,10 +10,11 @@ include scripts/Makefile.lib # -__modules := $(shell cat /dev/null $(wildcard $(MODVERDIR)/*.mod)) +__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: $(__modules) ) $(warning *** Uh-oh, you have stale module entries. You messed with SUBDIRS,) $(warning do not complain if something goes wrong.) endif
scripts/modpost.c +31 -18
102 lines not on this page · raw message
scripts/modpost.h +10 -0
@@ -80,9 +80,19 @@ struct elf_info {Elf_Sym *symtab_start;Elf_Sym *symtab_stop;const char *strtab; +char *modinfo; +unsigned int modinfo_len; };void handle_moddevtable (struct module *mod,struct elf_info *info,Elf_Sym *sym,const char *symname);void add_moddevtable (struct buffer *buf,struct module *mod); + +void maybe_frob_version (const char *modfilename, +void *modinfo, +unsigned long modinfo_len, +unsigned long modinfo_offset); + +void *grab_file (const char *filename,unsigned long *size); +void release_file (void *file,unsigned long size);
scripts/sumversion.c +540 -0
540 lines not on this page · raw message
Quoted 3 lines
Quoted 1 line
Any update on the
MODULE_VERSIONmacro getting into mainline?Sam need to ack the build system changes.
I have taken a look at it now.
As you mention yourself this assume all input files for a module is .c files. Which is almost always the case.
But I do not like the fact that we warn in cases where .s files is actually used.
Current implementation will also fail when using O= syntax.
The more correct approach is to list the .o files in the
.mod file. Then in sumversion find the corresponding .file.o.cmd, and parse up the name of the corresponding source file (listed as the first filename in the deps_ assignment, and pass this filename to grab_file.
Example .file.o.cmd file:
sam@mars:~/bk/v2.6> head -10 ~/b/drivers/scsi/aic7xxx/.aic7xxx_osm.o.cmdcmd_drivers/scsi/aic7xxx/aic7xxx_osm.o := gcc -Wp,-MD,drivers/scsi/aic7xxx/.aic7xxx_osm.o.d -nostdinc -iwithprefix include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/sam/bk/v2.6/include -I/home/sam/bk/v2.6/drivers/scsi/aic7xxx -Idrivers/scsi/aic7xxx -D__KERNEL__ -I/home/sam/bk/v2.6/include -Iinclude -I/home/sam/bk/v2.6/include2 -Iinclude2 -I/home/sam/bk/v2.6/include -Wall -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -pipe -mpreferred-stack-boundary=2 -march=i686 -I/home/sam/bk/v2.6/include/asm-i386/mach-default -Iinclude/asm-i386/mach-default -O2 -fomit-frame-pointer -I/home/sam/bk/v2.6/drivers/scsi -Idrivers/scsi -DMODULE -DKBUILD_BASENAME=aic7xxx_osm -DKBUILD_MODNAME=aic7xxx -c -o drivers/scsi/aic7xxx/aic7xxx_osm.o /home/sam/bk/v2.6/drivers/scsi/aic7xxx/aic7xxx_osm.c
deps_drivers/scsi/aic7xxx/aic7xxx_osm.o := \
/home/sam/bk/v2.6/drivers/scsi/aic7xxx/aic7xxx_osm.c \
$(wildcard include/config/aic7xxx/reset/delay/ms.h) \
$(wildcard include/config/aic7xxx/proc/stats.h) \Here the source file is listed with absolute path.
It must be as simple as searching through the file for a line starting with deps_, and then read the following line.
The .mod file will specify the path to the .file.o.cmd file, since this is an output file, there is no need to use $(srctree).
I hope I made the approach clear enough?
Sam
In message <[email protected]> you write:
Quoted 4 lines
The more correct approach is to list the .o files in the
.mod file. Then in sumversion find the corresponding .file.o.cmd, and parse up the name of the corresponding source file (listed as the first filename in thedeps_assignment, and pass this filename tograb_file.
OK, I've implemented that. It doesn't complain about non-C files, although the parsing might be sub-optimal.
See get_source_name() for new code. I also put the explicit depend on elfconfig.h in the Makefile.
Thanks!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: Add a MODULE_VERSION macro
Author: Rusty Russell
Status: Tested on 2.6.3-bk3
At the kernel summit, various people asked for a MODULE_VERSION macro to store module strings (for later access through sysfs). A simple md4 is needed to identify changes in modules which, inevitably, do not update the version. It skips whitespace and comments, and includes #includes which are in the same dir.
The module versions should be set according to this definition, based on the RPM one, or CVS Revision tags. Violators will be shot.
[<epoch>:']<version>[-'<extraversion>]
<epoch>: A (small) unsigned integer which allows you to start versions
anew. If not mentioned, it's zero. eg. "2:1.0" is after
"1:2.0".
<version>: The <version> may contain only alphanumerics. <extraversion>: Like <version>, but inserted for local
customizations, eg "rh3" or "rusty1".
Comparison of two versions (assuming same epoch):
Split each into all-digit and all-alphabetical parts. Compare each one one at a time: digit parts numerically, alphabetical in ASCII order. So 0.10 comes after 0.9.
include/linux/module.h +18 -0
@@ -127,6 +127,24 @@ extern const struct gtype##_id __mod_##g#define MODULE_DEVICE_TABLE (type,name) \ MODULE_GENERIC_TABLE(type##_device,name) +/* Version of form [<epoch>:]<version>[-<extra-version>]. +Or for CVS/RCS ID version, everything but the number is stripped. +<epoch>: A (small) unsigned integer which allows you to start versions +anew. If not mentioned, it's zero. eg. "2:1.0" is after +"1:2.0". +<version>: The <version> may contain only alphanumerics and the +character `.'. Ordered by numeric sort for numeric parts, +ascii sort for ascii parts (as per RPM or DEB algorithm). +<extraversion>: Like <version>, but inserted for local +customizations, eg "rh3" or "rusty1". + +Using this automatically adds a checksum of the .c files and the +local headers to the end. Use MODULE_VERSION("") if you want just +this. Macro includes room for this. +*/ +#define MODULE_VERSION (_version) \ + MODULE_INFO(version, _version "\0xxxxxxxxxxxxxxxxxxxxxxxx") +/* Given an address, look for it in the exception tables */ const struct exception_table_entry *search_exception_tables (unsigned long add);
scripts/Makefile +2 -2
@@ -12,7 +12,7 @@ host-progs := fixdep split-include conma mk_elfconfig pnmtologo bin2c always := $(host-progs) empty.o -modpost-objs := modpost.o file2alias.o +modpost-objs := modpost.o file2alias.o sumversion.o subdir-$(CONFIG_MODVERSIONS) += genksyms
@@ -24,7 +24,7 @@ $(addprefix $(obj)/,$(filter-out fixdep, # dependencies on generated files need to be listed explicitly -$(obj)/modpost.o $(obj)/file2alias.o: $(obj)/elfconfig.h +$(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h quiet_cmd_elfconfig = MKELF $@ cmd_elfconfig = $(obj)/mk_elfconfig $(ARCH) < $< > $@
scripts/Makefile.build +2 -4
@@ -64,8 +64,6 @@ endif # We keep a list of all modules in $(MODVERDIR) -touch-module = @echo $(@:.o=.ko) > $(MODVERDIR)/$(@F:.o=.mod) - __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ $(if $(KBUILD_MODULES),$(obj-m)) \ $(subdir-ym) $(always)
@@ -178,7 +176,7 @@ endef $(single-used-m): %.o: %.c FORCE $(call if_changed_rule,cc_o_c) - $(touch-module) + @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod) quiet_cmd_cc_lst_c = MKLST $@ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
@@ -273,7 +271,7 @@ $(multi-used-y) : %.o: $(multi-objs-y) F $(multi-used-m) : %.o: $(multi-objs-m) FORCE $(call if_changed,link_multi-m) - $(touch-module) + @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod) targets += $(multi-used-y) $(multi-used-m)
scripts/Makefile.modpost +2 -1
@@ -10,10 +10,11 @@ include scripts/Makefile.lib # -__modules := $(shell cat /dev/null $(wildcard $(MODVERDIR)/*.mod)) +__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: $(__modules) ) $(warning *** Uh-oh, you have stale module entries. You messed with SUBDIRS,) $(warning do not complain if something goes wrong.) endif
scripts/modpost.c +31 -18
102 lines not on this page · raw message
scripts/modpost.h +10 -0
@@ -80,9 +80,19 @@ struct elf_info {Elf_Sym *symtab_start;Elf_Sym *symtab_stop;const char *strtab; +char *modinfo; +unsigned int modinfo_len; };void handle_moddevtable (struct module *mod,struct elf_info *info,Elf_Sym *sym,const char *symname);void add_moddevtable (struct buffer *buf,struct module *mod); + +void maybe_frob_version (const char *modfilename, +void *modinfo, +unsigned long modinfo_len, +unsigned long modinfo_offset); + +void *grab_file (const char *filename,unsigned long *size); +void release_file (void *file,unsigned long size);
scripts/sumversion.c +599 -0
599 lines not on this page · raw message
Quoted 11 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 4 lines
The more correct approach is to list the .o files in the
.mod file. Then in sumversion find the corresponding .file.o.cmd, and parse up the name of the corresponding source file (listed as the first filename in thedeps_assignment, and pass this filename tograb_file.OK, I've implemented that. It doesn't complain about non-C files, although the parsing might be sub-optimal.
See
get_source_name()for new code. I also put the explicit depend onelfconfig.hin theMakefile.
Took a second look at it.
The reason why you parse the sourcefile, is to locate files included from the local directory.
But this information is already available in the .module.o.cmd file, so no reason to parse that information up from the .c file - and eventually having troubles with .s files.
You can get rid of parse_cpp_line(), include_file(), and some of the helpers when implementing this algorithm. So all in all a good simplification.
Note also that in the original implementation you have missed release_file() in a few places. But when you implement the above you will hit them.
Sam
In message <[email protected]> you write:
Quoted 7 lines
But this information is already available in the .module.o.cmd file, so no reason to parse that information up from the .c file - and eventually having troubles with .s files.
You can get rid of
parse_cpp_line(),include_file(), and some of the helpers when implementing this algorithm. So all in all a good simplification.
Yep, fixed this, and fixed the broken modules_install for Andrew. This one actually boot tested.
Quoted 3 lines
Note also that in the original implementation you have missed
release_file()in a few places. But when you implement the above you will hit them.
Fixed them too.
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: Add a MODULE_VERSION macro
Author: Rusty Russell
Status: Tested on 2.6.3-bk4
At the kernel summit, various people asked for a MODULE_VERSION macro to store module strings (for later access through sysfs). A simple md4 is needed to identify changes in modules which, inevitably, do not update the version. It skips whitespace and comments, and includes #includes which are in the same dir.
The module versions should be set according to this definition, based on the RPM one, or CVS Revision tags. Violators will be shot.
[<epoch>:']<version>[-'<extraversion>]
<epoch>: A (small) unsigned integer which allows you to start versions
anew. If not mentioned, it's zero. eg. "2:1.0" is after
"1:2.0".
<version>: The <version> may contain only alphanumerics. <extraversion>: Like <version>, but inserted for local
customizations, eg "rh3" or "rusty1".
Comparison of two versions (assuming same epoch):
Split each into all-digit and all-alphabetical parts. Compare each one one at a time: digit parts numerically, alphabetical in ASCII order. So 0.10 comes after 0.9.
include/linux/module.h +18 -0
@@ -127,6 +127,24 @@ extern const struct gtype##_id __mod_##g#define MODULE_DEVICE_TABLE (type,name) \ MODULE_GENERIC_TABLE(type##_device,name) +/* Version of form [<epoch>:]<version>[-<extra-version>]. +Or for CVS/RCS ID version, everything but the number is stripped. +<epoch>: A (small) unsigned integer which allows you to start versions +anew. If not mentioned, it's zero. eg. "2:1.0" is after +"1:2.0". +<version>: The <version> may contain only alphanumerics and the +character `.'. Ordered by numeric sort for numeric parts, +ascii sort for ascii parts (as per RPM or DEB algorithm). +<extraversion>: Like <version>, but inserted for local +customizations, eg "rh3" or "rusty1". + +Using this automatically adds a checksum of the .c files and the +local headers to the end. Use MODULE_VERSION("") if you want just +this. Macro includes room for this. +*/ +#define MODULE_VERSION (_version) \ + MODULE_INFO(version, _version "\0xxxxxxxxxxxxxxxxxxxxxxxx") +/* Given an address, look for it in the exception tables */ const struct exception_table_entry *search_exception_tables (unsigned long add);
scripts/Makefile +2 -2
@@ -12,7 +12,7 @@ host-progs := fixdep split-include conma mk_elfconfig pnmtologo bin2c always := $(host-progs) empty.o -modpost-objs := modpost.o file2alias.o +modpost-objs := modpost.o file2alias.o sumversion.o subdir-$(CONFIG_MODVERSIONS) += genksyms
@@ -24,7 +24,7 @@ $(addprefix $(obj)/,$(filter-out fixdep, # dependencies on generated files need to be listed explicitly -$(obj)/modpost.o $(obj)/file2alias.o: $(obj)/elfconfig.h +$(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h quiet_cmd_elfconfig = MKELF $@ cmd_elfconfig = $(obj)/mk_elfconfig $(ARCH) < $< > $@
scripts/Makefile.build +2 -4
@@ -64,8 +64,6 @@ endif # We keep a list of all modules in $(MODVERDIR) -touch-module = @echo $(@:.o=.ko) > $(MODVERDIR)/$(@F:.o=.mod) - __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ $(if $(KBUILD_MODULES),$(obj-m)) \ $(subdir-ym) $(always)
@@ -178,7 +176,7 @@ endef $(single-used-m): %.o: %.c FORCE $(call if_changed_rule,cc_o_c) - $(touch-module) + @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod) quiet_cmd_cc_lst_c = MKLST $@ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
@@ -273,7 +271,7 @@ $(multi-used-y) : %.o: $(multi-objs-y) F $(multi-used-m) : %.o: $(multi-objs-m) FORCE $(call if_changed,link_multi-m) - $(touch-module) + @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod) targets += $(multi-used-y) $(multi-used-m)
scripts/Makefile.modinst +1 -1
@@ -9,7 +9,7 @@ include scripts/Makefile.lib # -__modules := $(shell cat /dev/null $(wildcard $(MODVERDIR)/*.mod)) +__modules := $(shell head -q -n1 /dev/null $(wildcard $(MODVERDIR)/*.mod)) modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o))) ifneq ($(filter-out $(modules),$(__modules)),)
scripts/Makefile.modpost +2 -1
@@ -10,10 +10,11 @@ include scripts/Makefile.lib # -__modules := $(shell cat /dev/null $(wildcard $(MODVERDIR)/*.mod)) +__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: $(__modules) ) $(warning *** Uh-oh, you have stale module entries. You messed with SUBDIRS,) $(warning do not complain if something goes wrong.) endif
scripts/modpost.c +31 -18
102 lines not on this page · raw message
scripts/modpost.h +10 -0
@@ -80,9 +80,19 @@ struct elf_info {Elf_Sym *symtab_start;Elf_Sym *symtab_stop;const char *strtab; +char *modinfo; +unsigned int modinfo_len; };void handle_moddevtable (struct module *mod,struct elf_info *info,Elf_Sym *sym,const char *symname);void add_moddevtable (struct buffer *buf,struct module *mod); + +void maybe_frob_version (const char *modfilename, +void *modinfo, +unsigned long modinfo_len, +unsigned long modinfo_offset); + +void *grab_file (const char *filename,unsigned long *size); +void release_file (void *file,unsigned long size);
scripts/sumversion.c +550 -0
550 lines not on this page · raw message
Hi Rusty.
I have not yet fully understood why you want to parse every source file. I can see in the implemntation that you only calculate the sum of code-lines, and not comments.
But why do we want to add this complexity - compared to just calculating the sum of the whole file?
If the calculated sum is being presented as based on the source code I assume people can understand that the sum does not match even after updating a comment.
The current implementation fails to locate include files in the local directory when compiled using "make O=...".
This is due to the fact that some files are present in the _deps file with full path, others with relative path.
Example:
/home/sam/bk/v2.6/drivers/scsi/aic7xxx/aiclib.h \
/home/sam/bk/v2.6/drivers/scsi/aic7xxx/aic7xxx.h \
$(wildcard include/config/used.h) \ drivers/scsi/aic7xxx/aic7xxx_reg.h \
/home/sam/bk/v2.6/drivers/scsi/aic7xxx/aic7xxx_inline.h \
I took a quick look and cannot explain why gcc spits out include files with different paths.
My next question. Since we only parse a subset of the headers, is it really needed to parse any of them?
My thinking is that we should either:
a) parse all header files (except those marked with $(wildcard))
b) parse no header files.
See also a few specific comments below.
Sam
scripts/sumversion.c line 331
Quoted 10 lines
scripts/sumversion.c +10
-0+/* We have dir/file.o. Open dir/.file.o.cmd, look for deps_ line to +* figure out source file. */ +static int parse_source_files (const char *objfile,struct md4_ctx *md) +{ +char *cmd, *file, *p, *end; +const char *base; +unsigned long flen; +int dirlen, ret =0 ; + + cmd =malloc (strlen (objfile) +sizeof ("..cmd" ));
You miss a "+ 1" to count for trailing '\0'.
Quoted 47 lines
scripts/sumversion.c +47
-0+ + base =strrchr (objfile,'/' ); +if (base) { + base++; + dirlen = base - objfile; +sprintf (cmd,"%.*s.%s.cmd" , dirlen, objfile, base); + }else { + dirlen =0 ; +sprintf (cmd,".%s.cmd" , objfile); + } + + file =grab_file (cmd, &flen); +if (!file) { +fprintf (stderr,"Warning: could not find %s for %s\n" , + cmd, objfile); + goto out; + } + +/* There will be a line like so: +deps_drivers/net/dummy.o := \ +drivers/net/dummy.c \ +$(wildcard include/config/net/fastroute.h) \ +include/linux/config.h \ +$(wildcard include/config/h.h) \ +include/linux/module.h \ + +Sum all files in the same dir or subdirs. +*/ +/* Strictly illegal: file is not nul terminated. */ + p =strstr (file,"\ndeps_" ); +if (!p) { +fprintf (stderr,"Warning: could not find deps_ line in %s\n" , + cmd); + goto out_file; + } + p =strstr (p,":=" ); +if (!p) { +fprintf (stderr,"Warning: could not find := line in %s\n" , + cmd); + goto out_file; + } + p +=strlen (":=" ); + p +=strspn (p," \\\n" ); + + end =strstr (p,"\n\n" ); +if (!end) { + fprintf(stderr, "Warning: could not find end line in %s\n",
scripts/sumversion.c line 388
Quoted 10 lines
scripts/sumversion.c +10
-0+ cmd); + goto out_file; + } + +while (p < end) { +unsigned int len; + + len =strcspn (p," \\\n" ); +if (memcmp (objfile, p, dirlen) ==0 ) { +char source[len +1 ];
gcc extension, you do not want to use malloc here?
scripts/sumversion.c line 392
Quoted 4 lines
scripts/sumversion.c +4
-0+ +memcpy (source, p, len); + source[len] ='\0' ; +printf ("parsing %s\n" , source);
Debug printf - to be deleted.
Quoted 19 lines
scripts/sumversion.c +19
-0+if (!parse_file (source, md)) { +fprintf (stderr, +"Warning: could not open %s: %s\n" , + source,strerror (errno)); + goto out_file; + } + } + p += len; + p +=strspn (p," \\\n" ); + } + +/* Everyone parsed OK */ + ret =1 ; +out_file: +release_file (file, flen); +out: +free (cmd); +return ret; +}
In message <[email protected]> you write:
Quoted 10 lines
Hi Rusty.
I have not yet fully understood why you want to parse every source file. I can see in the implemntation that you only calculate the sum of code-lines, and not comments.
But why do we want to add this complexity - compared to just calculating the sum of the whole file?
If the calculated sum is being presented as based on the source code I assume people can understand that the sum does not match even after updating a comment.
The strongest example is that Andrew Morton always "fixes" whitespace as patches go through his tree. It's about 50 lines of code, and it's not slow (but has definite room for optimization).
Quoted 2 lines
The current implementation fails to locate include files in the local directory when compiled using "make O=...".
There's no documentation I could find for "O=", BTW. I'm not even sure what it does...
Quoted 2 lines
This is due to the fact that some files are present in the
_depsfile with full path, others with relative path.
Right. 8(
Quoted 5 lines
My next question. Since we only parse a subset of the headers, is it really needed to parse any of them?
My thinking is that we should either:
a) parse all header files (except those marked with $(wildcard))
b) parse no header files.
I was thinking of the driver author. Driver consists of three .c files, and a local .h file. They want to catch anyone touching any of these files. But they don't want the sum to change just because someone adds a new inline function to linux/kernel.h.
If it's impractical, we can just skip all the headers. But it would be a real loss.
Quoted 3 lines
scripts/sumversion.c line 331
Quoted 1 line
scripts/sumversion.c +1
-0+ cmd =malloc (strlen (objfile) +sizeof ("..cmd" ));You miss a "+ 1" to count for trailing '\0'.
Um, sizeof() vs strlen().
Quoted 4 lines
scripts/sumversion.c line 388
Quoted 3 lines
scripts/sumversion.c +3
-0+ len =strcspn (p," \\\n" ); +if (memcmp (objfile, p, dirlen) ==0 ) { +char source[len +1 ];gcc extension, you do not want to use malloc here?
Yeah, I love GCC. It's also in ISO C, BTW.
Quoted 2 lines
scripts/sumversion.c line 392
Quoted 1 line
scripts/sumversion.c +1
-0+printf ("parsing %s\n" , source);Debug printf - to be deleted.
Ack.
Thanks!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Quoted 5 lines · Rusty Russell
Quoted 2 lines
The current implementation fails to locate include files in the local directory when compiled using "make O=...".
There's no documentation I could find for "O=", BTW. I'm not even sure what it does...
Check README in the kernel src.
Specify the output directory, allowing you to compile from RO media, or just to have several kernel configs based on same src tree.
Sam
Looks like the MODULE_VERSION macro is now in the tree. Greg, any status on the sysfs patch you mention below?
thanks,
Brian
Quoted 29 lines · Greg KH
Quoted 10 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 2 lines
Rusty,
Christoph mentioned that aMODULE_VERSIONmacro may be pending.Hey, thanks Christoph for the reminder. I stopped when we were frozen.
This still seems to apply. Do people think this is huge overkill, or a work of obvious beauty and genius?
Looks sane. I'm guessing that modinfo can show this?
Quoted 2 lines
Doesn't put things in sysfs, but Greg was working on that for module parameters... Greg?
Oh yeah, I'll dig out that patch later this week. An older version has been sitting in my bk tree forever, need to update it with the last changes you sent me.
thanks,
greg k-h
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Quoted 2 lines · Brian King
Looks like the
MODULE_VERSIONmacro is now in the tree. Greg, any status on the sysfs patch you mention below?
Already posted to lkml a week or so ago, and Rusty responded back with a different patch. I'll get to his response hopefully by the end of the week...
thanks,
greg k-h