kbuild support for %.symtypes files
RFC PATCH 1/1 kbuild support for %.symtypes files
Hello,
here is a patch that adds a new -T option to genksyms for generating dumps of the type definition that makes up the symbol version hashes. This allows to trace modversion changes back to what caused them. The dump format is the name of the type defined, followed by its definition (which is almost C):
s#list_head struct list_head { s#list_head * next , * prev ; }
The s#, u#, e#, and t# prefixes stand for struct, union, enum, and typedef. The exported symbols do not define types, and thus do not have an x# prefix:
nfs4_acl_get_whotype int nfs4_acl_get_whotype ( char * , t#u32 )
The symbol type defintion of a single file can be generated with:
make fs/jbd/journal.symtypes
If KBUILD_SYMTYPES is defined, all the *.symtypes of all object files that export symbols are generated.
The single *.symtypes files can be combined into a single file after a kernel build with a script like the following:
for f in $(find -name '*.symtypes' | sort); do
f=${f#./}
echo "/* ${f%.symtypes}.o */"
cat $f
echo
done \
| sed -e '\:UNKNOWN:d' \
-e 's:[,;] }:}:g' \
-e 's:\([[({]\) :\1:g' \
-e 's: \([])},;]\):\1:g' \
-e 's: $::' \
$f \
| awk '
/^.#/ { if (defined[$1] == $0) {
print $1
next
}
defined[$1] = $0
}
{ print }'
When the kernel ABI changes, diffing individual *.symtype files, or the combined files, against each other will show which symbol changes caused the ABI changes. This can save a tremendous amount of time.
I've been discussing this patch with Jon, and I think the patch makes more sense upstream than in a vendor kernel only. Comments?
Thanks,
Andreas
Dump the types that make up modversions
scripts/Makefile.build +11 -1
@@ -140,6 +140,15 @@ cmd_cc_i_c = $(CPP) $(c_flags) - %.i: %.c FORCE $(call if_changed_dep,cc_i_c) +quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ +cmd_cc_symtypes_c = \ + $(CPP) -D__GENKSYMS__ $(c_flags) $< \ + | $(GENKSYMS) -T $@ >/dev/null; \ + test -s $@ || rm -f $@ + +%.symtypes : %.c FORCE + $(call if_changed_dep,cc_symtypes_c) + # C (.c) files # The C file is compiled and updated dependency information is generated. # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
@@ -166,7 +175,8 @@ cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D cmd_modversions = \ if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ $(CPP) -D__GENKSYMS__ $(c_flags) $< \ - | $(GENKSYMS) -a $(ARCH) \ + | $(GENKSYMS) $(if $(KBUILD_SYMTYPES), \ + -T $(@D)/$(@F:.o=.symtypes)) -a $(ARCH) \ > $(@D)/.tmp_$(@F:.o=.ver); \ \ $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
scripts/genksyms/genksyms.c +51 -26
164 lines not on this page · raw message
scripts/genksyms/genksyms.h +1 -0
@@ -41,6 +41,7 @@ struct symbol {enum symbol_type type;struct string_list *defn;struct symbol *expansion_trail; +struct symbol *visited;int is_extern; };
Makefile +4 -1
@@ -961,7 +961,8 @@ clean: archclean $(clean-dirs) $(call cmd,rmfiles) @find . $(RCS_FIND_IGNORE) \ \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ - -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \ + -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ + -o -name '*.symtypes' \) \ -type f -print | xargs rm -f # mrproper - Delete all generated files, including .config
@@ -1303,6 +1304,8 @@ endif $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.o: %.S prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) +%.symtypes: %.c prepare scripts FORCE + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) # Modules / %/: prepare scripts FORCE
Quoted 8 lines · Andreas Gruenbacher
Hello,
here is a patch that adds a new -T option to genksyms for generating dumps of the type definition that makes up the symbol version hashes. This allows to trace modversion changes back to what caused them. The dump format is the name of the type defined, followed by its definition (which is almost C):
s#list_head struct
list_head{ s#list_head * next , * prev ; }
Reading something just a little more complex than the above was very difficult. So I went on and updated your patch to spit out something almost 'C' alike with proper indention and a few newlines too.
The list_head struct looks like this now:
struct#list_head struct list_head {
struct# list_head * next , * prev;
};The real win is for structs with 20+ members, they are now divided up in several lines.
See attached patch.
Changes:
o print_node properly idents symbols (added putident)
o close file before exit
o ident cmd_cc_symtypes_c in Makefile.build
Patch is not yet committed, awaiting feedback from you first.
Sam
Makefile +4 -1
@@ -948,7 +948,8 @@ clean: archclean $(clean-dirs) $(call cmd,rmfiles) @find . $(RCS_FIND_IGNORE) \ \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ - -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \ + -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ + -o -name '*.symtypes' \) \ -type f -print | xargs rm -f # mrproper - Delete all generated files, including .config
@@ -1290,6 +1291,8 @@ endif $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.o: %.S prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) +%.symtypes: %.c prepare scripts FORCE + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) # Modules / %/: prepare scripts FORCE
scripts/Makefile.build +11 -1
@@ -140,6 +140,15 @@ cmd_cc_i_c = $(CPP) $(c_flags) - %.i: %.c FORCE $(call if_changed_dep,cc_i_c) +quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ + cmd_cc_symtypes_c = \ + $(CPP) -D__GENKSYMS__ $(c_flags) $< \ + | $(GENKSYMS) -T $@ >/dev/null; \ + test -s $@ || rm -f $@ + +%.symtypes: %.c FORCE + $(call if_changed_dep,cc_symtypes_c) + # C (.c) files # The C file is compiled and updated dependency information is generated. # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
@@ -166,7 +175,8 @@ cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D cmd_modversions = \ if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ $(CPP) -D__GENKSYMS__ $(c_flags) $< \ - | $(GENKSYMS) -a $(ARCH) \ + | $(GENKSYMS) $(if $(KBUILD_SYMTYPES), \ + -T $(@D)/$(@F:.o=.symtypes)) -a $(ARCH) \ > $(@D)/.tmp_$(@F:.o=.ver); \ \ $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
scripts/genksyms/genksyms.c +95 -29
221 lines not on this page · raw message
scripts/genksyms/genksyms.h +1 -0
@@ -41,6 +41,7 @@ struct symbol {enum symbol_type type;struct string_list *defn;struct symbol *expansion_trail; +struct symbol *visited;int is_extern; };
Quoted 15 lines · Sam Ravnborg
Quoted 9 lines · Andreas Gruenbacher
Hello,
here is a patch that adds a new -T option to genksyms for generating dumps of the type definition that makes up the symbol version hashes. This allows to trace modversion changes back to what caused them. The dump format is the name of the type defined, followed by its definition (which is almost C):
s#list_head struct
list_head{ s#list_head * next , * prev ; }Reading something just a little more complex than the above was very difficult. So I went on and updated your patch to spit out something almost 'C' alike with proper indention and a few newlines too.
Quoted 8 lines
The
list_headstruct looks like this now:struct#list_head struct list_head { struct# list_head * next , * prev; };The real win is for structs with 20+ members, they are now divided up in several lines.
Please let's not beautify the output: this would make diffing and grepping harder. It's easy to pipe the simple, line oriented format through a formatting filter if necessary.
The output could be made more readable by converting the "x#" prefix to C keywords (struct, union, etc.). I didn't do this because that would introduce parse problems, and constructing dependency graphs from the dump files would become tricky.
Andreas
Signature · 2 lines
Andreas Gruenbacher <[email protected]> Novell / SUSE Labs
Quoted 6 lines · Andreas Gruenbacher
Hello,
here is a patch that adds a new -T option to genksyms for generating dumps of the type definition that makes up the symbol version hashes. This allows to trace modversion changes back to what caused them. The dump format is the name of the type defined, followed by its definition (which is almost C):
Applid as is. But please take a closer look at the output format. Making it human readable somewho is desireable - even it the parsing needs a bit more effort then.
Sam