gcov kernel support
Subsystems (8)
PATCH 2/4 seq_file: add function to write binary data
In reply to Peter OberparleiterFrom: Peter Oberparleiter <[email protected]>
seq_write() can be used to construct seq_files containing arbitrary data. Required by the gcov-profiling interface to synthesize binary profiling data files.
---
fs/seq_file.c | 20 ++++++++++++++++++++ include/linux/seq_file.h | 1 + 2 files changed, 21 insertions(+)
fs/seq_file.c +20 -0
@@ -640,6 +640,26 @@ int seq_puts(struct seq_file *m, const c }EXPORT_SYMBOL (seq_puts); +/** +* seq_write - write arbitrary data to buffer +* @seq: seq_file identifying the buffer to which data should be written +* @data: data address +* @len: number of bytes +* +* Return 0 on success, non-zero otherwise. +*/ +int seq_write (struct seq_file *seq,const void *data,size_t len) +{ +if (seq->count + len < seq->size) { +memcpy (seq->buf + seq->count, data, len); + seq->count += len; +return 0 ; + } + seq->count = seq->size; +return -1 ; +} +EXPORT_SYMBOL (seq_write); +struct list_head *seq_list_start (struct list_head *head,loff_t pos) {struct list_head *lh;
include/linux/seq_file.h +1 -0
@@ -43,6 +43,7 @@ int seq_release(struct inode *, struct fint seq_escape (struct seq_file *,const char *,const char *);int seq_putc (struct seq_file *m,char c);int seq_puts (struct seq_file *m,const char *s); +int seq_write (struct seq_file *seq,const void *data,size_t len);int seq_printf (struct seq_file *,const char *, ...) __attribute__ ((format (printf,2 ,3 )));
PATCH 4/4 gcov: enable GCOV_PROFILE_ALL for x86_64
In reply to Peter OberparleiterFrom: Peter Oberparleiter <[email protected]>
Enable gcov profiling of the entire kernel on x86_64. Required changes include disabling profiling for:
* arch/kernel/acpi/realmode and arch/kernel/boot/compressed:
not linked to main kernel
* arch/vdso, arch/kernel/vsyscall_64 and arch/kernel/hpet:
profiling causes segfaults during boot (incompatible context)
--- arch/x86/boot/Makefile | 1 + arch/x86/boot/compressed/Makefile | 1 + arch/x86/kernel/Makefile | 2 ++ arch/x86/kernel/acpi/realmode/Makefile | 1 + arch/x86/vdso/Makefile | 1 + kernel/gcov/Kconfig | 2 +- 6 files changed, 7 insertions(+), 1 deletion(-)
kernel/gcov/Kconfig +1 -1
@@ -34,7 +34,7 @@ config GCOV_KERNEL config GCOV_PROFILE_ALL bool "Profile entire Kernel" depends on GCOV_KERNEL - depends on S390 || X86_32 + depends on S390 || X86 default n ---help--- This options activates profiling for the entire kernel.
arch/x86/kernel/acpi/realmode/Makefile +1 -0
@@ -42,6 +42,7 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os $(call cc-option, -mpreferred-stack-boundary=2) KBUILD_CFLAGS += $(call cc-option, -m32) KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ +GCOV_PROFILE := n WAKEUP_OBJS = $(addprefix $(obj)/,$(wakeup-y))
arch/x86/boot/Makefile +1 -0
@@ -69,6 +69,7 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os $(call cc-option, -mpreferred-stack-boundary=2) KBUILD_CFLAGS += $(call cc-option, -m32) KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ +GCOV_PROFILE := n $(obj)/bzImage: asflags-y := $(SVGA_MODE)
arch/x86/boot/compressed/Makefile +1 -0
@@ -15,6 +15,7 @@ KBUILD_CFLAGS += $(call cc-option,-ffree KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ +GCOV_PROFILE := n LDFLAGS := -m elf_$(UTS_MACHINE) LDFLAGS_vmlinux := -T
arch/x86/vdso/Makefile +1 -0
@@ -123,6 +123,7 @@ quiet_cmd_vdso = VDSO $@ -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) VDSO_LDFLAGS = -fPIC -shared $(call ld-option, -Wl$(comma)--hash-style=sysv) +GCOV_PROFILE := n # # Install the unstripped copy of vdso*.so listed in $(vdso-install-y).
arch/x86/kernel/Makefile +2 -0
@@ -24,6 +24,8 @@ CFLAGS_vsyscall_64.o := $(PROFILING) -g0 CFLAGS_hpet.o := $(nostackp) CFLAGS_tsc.o := $(nostackp) CFLAGS_paravirt.o := $(nostackp) +GCOV_PROFILE_vsyscall_64.o := n +GCOV_PROFILE_hpet.o := n obj-y := process_$(BITS).o signal.o entry_$(BITS).o obj-y += traps.o irq.o irq_$(BITS).o dumpstack_$(BITS).o
PATCH 3/4 gcov: add gcov profiling infrastructure
In reply to Peter OberparleiterFrom: Peter Oberparleiter <[email protected]>
Enable the use of GCC's coverage testing tool gcov [1] with the Linux kernel. gcov may be useful for:
* debugging (has this code been reached at all?)
* test improvement (how do I change my test to cover these lines?)
* minimizing kernel configurations (do I need this option if the associated code is never run?)
The profiling patch incorporates the following changes:
* change kbuild to include profiling flags
* provide functions needed by profiling code
* present profiling data as files in debugfs
Note that on some architectures, enabling gcc's profiling option "-fprofile-arcs" for the entire kernel may trigger compile/link/ run-time problems, some of which are caused by toolchain bugs and others which require adjustment of architecture code.
For this reason profiling the entire kernel is initially restricted to those architectures for which it is known to work without changes. This restriction can be lifted once an architecture has been tested and found compatible with gcc's profiling. Profiling of single files or directories is still available on all platforms (see config help text).
[1] http://gcc.gnu.org/onlinedocs/gcc/Gcov.html
---
Documentation/gcov.txt | 246 +++++++++++++ Documentation/kernel-parameters.txt | 7 Makefile | 11 arch/Kconfig | 2 include/linux/compiler-gcc3.h | 6 kernel/Makefile | 1 kernel/gcov/Kconfig | 48 ++ kernel/gcov/Makefile | 3 kernel/gcov/base.c | 155 ++++++++ kernel/gcov/fs.c | 674 ++++++++++++++++++++++++++++++++++++ kernel/gcov/gcc_3_4.c | 445 +++++++++++++++++++++++ kernel/gcov/gcov.h | 128 ++++++ scripts/Makefile.lib | 11 13 files changed, 1732 insertions(+), 5 deletions(-)
Documentation/gcov.txt new file +246 -0
@@ -0,0 +1,246 @@ +Using gcov with the Linux kernel +================================ + +1. Introduction +2. Preparation +3. Customization +4. Files +5. Modules +6. Separated build and test machines +7. Troubleshooting +Appendix A: sample script: gather_on_build.sh +Appendix B: sample script: gather_on_test.sh + + +1. Introduction +=============== + +gcov profiling kernel support enables the use of GCC's coverage testing +tool gcov [1] with the Linux kernel. Coverage data of a running kernel +is exported in gcov-compatible format via the "gcov" debugfs directory. +To get coverage data for a specific file, change to the kernel build +directory and use gcov with the -o option as follows (requires root): + +# cd /tmp/linux-out +# gcov -o /sys/kernel/debug/gcov/tmp/linux-out/kernel spinlock.c + +This will create source code files annotated with execution counts +in the current directory. In addition, graphical gcov front-ends such +as lcov [2] can be used to automate the process of collecting data +for the entire kernel and provide coverage overviews in HTML format. + +Possible uses: + +* debugging (has this line been reached at all?) +* test improvement (how do I change my test to cover these lines?) +* minimizing kernel configurations (do I need this option if the + associated code is never run?) + +-- + +[1] http://gcc.gnu.org/onlinedocs/gcc/Gcov.html +[2] http://ltp.sourceforge.net/coverage/lcov.php + + +2. Preparation +============== + +Configure the kernel with: + + CONFIG_DEBUGFS=y + CONFIG_GCOV_KERNEL=y + +and to get coverage data for the entire kernel: + + CONFIG_GCOV_PROFILE_ALL=y + +Note that kernels compiled with profiling flags will be significantly +larger and run slower. Also CONFIG_GCOV_PROFILE_ALL may not be supported +on all architectures. + +Profiling data will only become accessible once debugfs has been +mounted: + + mount -t debugfs none /sys/kernel/debug + + +3. Customization +================ + +To enable profiling for specific files or directories, add a line +similar to the following to the respective kernel Makefile: + + For a single file (e.g. main.o): + GCOV_PROFILE_main.o := y + + For all files in one directory: + GCOV_PROFILE := y + +To exclude files from being profiled even when CONFIG_GCOV_PROFILE_ALL +is specified, use: + + GCOV_PROFILE_main.o := n + and: + GCOV_PROFILE := n + +Only files which are linked to the main kernel image or are compiled as +kernel modules are supported by this mechanism. + + +4. Files +======== + +The gcov kernel support creates the following files in debugfs: + + /sys/kernel/debug/gcov + Parent directory for all gcov-related files. + + /sys/kernel/debug/gcov/reset + Global reset file: resets all coverage data to zero when + written to. + + /sys/kernel/debug/gcov/path/to/compile/dir/file.gcda + The actual gcov data file as understood by the gcov + tool. Resets file coverage data to zero when written to. + + /sys/kernel/debug/gcov/path/to/compile/dir/file.gcno + Symbolic link to a static data file required by the gcov + tool. This file is generated by gcc when compiling with + option -ftest-coverage. + + +5. Modules +========== + +Kernel modules may contain cleanup code which is only run during +module unload time. The gcov mechanism provides a means to collect +coverage data for such code by keeping a copy of the data associated +with the unloaded module. This data remains available through debugfs. +Once the module is loaded again, the associated coverage counters are +initialized with the data from its previous instantiation. + +This behavior can be deactivated by specifying the gcov_persist kernel +parameter: + + gcov_persist=0 + +At run-time, a user can also choose to discard data for an unloaded +module by writing to its data file or the global reset file. + + +6. Separated build and test machines +==================================== + +The gcov kernel profiling infrastructure is designed to work out-of-the +box for setups where kernels are built and run on the same machine. In +cases where the kernel runs on a separate machine, special preparations +must be made, depending on where the gcov tool is used: + +a) gcov is run on the TEST machine + +The gcov tool version on the test machine must be compatible with the +gcc version used for kernel build. Also the following files need to be +copied from build to test machine: + +from the source tree: + - all C source files + headers + +from the build tree: + - all C source files + headers + - all .gcda and .gcno files + - all links to directories + +It is important to note that these files need to be placed into the +exact same file system location on the test machine as on the build +machine. If any of the path components is symbolic link, the actual +directory needs to be used instead (due to make's CURDIR handling). + +b) gcov is run on the BUILD machine + +The following files need to be copied after each test case from test +to build machine: + +from the gcov directory in sysfs: + - all .gcda files + - all links to .gcno files + +These files can be copied to any location on the build machine. gcov +must then be called with the -o option pointing to that directory. + +Example directory setup on the build machine: + + /tmp/linux: kernel source tree + /tmp/out: kernel build directory as specified by make O= + /tmp/coverage: location of the files copied from the test machine + + [user@build] cd /tmp/out + [user@build] gcov -o /tmp/coverage/tmp/out/init main.c + + +7. Troubleshooting +================== + +Problem: Compilation aborts during linker step. +Cause: Profiling flags are specified for source files which are not + linked to the main kernel or which are linked by a custom + linker procedure. +Solution: Exclude affected source files from profiling by specifying + GCOV_PROFILE := n or GCOV_PROFILE_basename.o := n in the + corresponding Makefile. + + +Appendix A: gather_on_build.sh +============================== + +Sample script to gather coverage meta files on the build machine +(see 6a): + +#!/bin/bash + +KSRC=$1 +KOBJ=$2 +DEST=$3 + +if [ -z "$KSRC" ] || [ -z "$KOBJ" ] || [ -z "$DEST" ]; then + echo "Usage: $0 <ksrc directory> <kobj directory> <output.tar.gz>" >&2 + exit 1 +fi + +KSRC=$(cd $KSRC; printf "all:\n\t@echo \${CURDIR}\n" | make -f -) +KOBJ=$(cd $KOBJ; printf "all:\n\t@echo \${CURDIR}\n" | make -f -) + +find $KSRC $KOBJ \( -name '*.gcno' -o -name '*.[ch]' -o -type l \) -a \ + -perm /u+r,g+r | tar cfz $DEST -P -T - + +if [ $? -eq 0 ] ; then + echo "$DEST successfully created, copy to test system and unpack with:" + echo " tar xfz $DEST -P" +else + echo "Could not create file $DEST" +fi + + +Appendix B: gather_on_test.sh +============================= + +Sample script to gather coverage data files on the test machine +(see 6b): + +#!/bin/bash + +DEST=$1 +GCDA=/sys/kernel/debug/gcov + +if [ -z "$DEST" ] ; then + echo "Usage: $0 <output.tar.gz>" >&2 + exit 1 +fi + +find $GCDA -name '*.gcno' -o -name '*.gcda' | tar cfz $DEST -T - + +if [ $? -eq 0 ] ; then + echo "$DEST successfully created, copy to build system and unpack with:" + echo " tar xfz $DEST" +else + echo "Could not create file $DEST" +fi
Documentation/kernel-parameters.txt +7 -0
@@ -42,6 +42,7 @@ parameter is applicable: EFI EFI Partitioning (GPT) is enabled EIDE EIDE/ATAPI support is enabled. FB The frame buffer device is enabled. + GCOV GCOV profiling is enabled. HW Appropriate hardware is enabled. IA-64 IA-64 architecture is enabled. IMA Integrity measurement architecture is enabled.
@@ -765,6 +766,12 @@ and is between 256 and 4096 characters. Format: off | on default: on + gcov_persist= [GCOV] When non-zero (default), profiling data for + kernel modules is saved and remains accessible via + debugfs, even when the module is unloaded/reloaded. + When zero, profiling data is discarded and associated + debugfs files are removed at module unload time. + gdth= [HW,SCSI] See header of drivers/scsi/gdth.c.
Makefile +6 -5
@@ -338,6 +338,7 @@ AFLAGS_MODULE = $(MODFLAGS) LDFLAGS_MODULE = CFLAGS_KERNEL = AFLAGS_KERNEL = +CFLAGS_GCOV = -fprofile-arcs -ftest-coverage # Use LINUXINCLUDE when you must reference the include/ directory.
@@ -364,7 +365,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP M export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS -export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE +export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE # When compiling out-of-tree modules, put MODVERDIR in the module
@@ -1224,8 +1225,8 @@ clean: archclean $(clean-dirs) \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '*.symtypes' -o -name 'modules.order' \ - -o -name 'Module.markers' -o -name '.tmp_*.o.*' \) \ - -type f -print | xargs rm -f + -o -name 'Module.markers' -o -name '.tmp_*.o.*' \ + -o -name '*.gcno' \) -type f -print | xargs rm -f # mrproper - Delete all generated files, including .config #
@@ -1427,8 +1428,8 @@ clean: $(clean-dirs) $(call cmd,rmfiles) @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 + -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ + -o -name '*.gcno' \) -type f -print | xargs rm -f help: @echo ' Building external modules.'
arch/Kconfig +2 -0
@@ -112,3 +112,5 @@ config HAVE_DMA_API_DEBUG config HAVE_DEFAULT_NO_SPIN_MUTEXES bool + +source "kernel/gcov/Kconfig"
kernel/Makefile +1 -0
@@ -70,6 +70,7 @@ obj-$(CONFIG_STOP_MACHINE) += stop_machi obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o obj-$(CONFIG_AUDIT) += audit.o auditfilter.o obj-$(CONFIG_AUDITSYSCALL) += auditsc.o +obj-$(CONFIG_GCOV_KERNEL) += gcov/ obj-$(CONFIG_AUDIT_TREE) += audit_tree.o obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_KGDB) += kgdb.o
kernel/gcov/Kconfig new file +48 -0
48 lines not on this page · raw message
kernel/gcov/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +EXTRA_CFLAGS := -DSRCTREE='"$(srctree)"' -DOBJTREE='"$(objtree)"' + +obj-$(CONFIG_GCOV_KERNEL) := base.o fs.o gcc_3_4.o
kernel/gcov/base.c new file +155 -0
155 lines not on this page · raw message
kernel/gcov/fs.c new file +674 -0
674 lines not on this page · raw message
kernel/gcov/gcc_3_4.c new file +445 -0
445 lines not on this page · raw message
kernel/gcov/gcov.h new file +128 -0
128 lines not on this page · raw message
scripts/Makefile.lib +11 -0
@@ -116,6 +116,17 @@ _a_flags = $(KBUILD_CPPFLAGS) $(KB $(asflags-y) $(AFLAGS_$(basetarget).o) _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) +# +# Enable gcov profiling flags for a file, directory or for all files depending +# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL +# (in this order) +# +ifeq ($(CONFIG_GCOV_KERNEL),y) +_c_flags += $(if $(patsubst n%,, \ + $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ + $(CFLAGS_GCOV)) +endif + # If building the kernel in a separate objtree expand all occurrences # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
include/linux/compiler-gcc3.h +6 -0
@@ -16,6 +16,12 @@#define __must_check __attribute__((warn_unused_result))#endif +#ifdef CONFIG_GCOV_KERNEL +# if __GNUC_MINOR__ <4 +# error "GCOV profiling support for gcc versions below 3.4 not included" +# endif /* __GNUC_MINOR__ */ +#endif /* CONFIG_GCOV_KERNEL */ +/* * A trick to suppress uninitialized variable warning without generating any * code
PATCH 1/4 kernel: constructor support
In reply to Peter OberparleiterFrom: Peter Oberparleiter <[email protected]>
Call constructors (gcc-generated initcall-like functions) during kernel start and module load. Constructors are e.g. used for gcov data initialization.
Disable constructor support for usermode Linux to prevent conflicts with host glibc.
--- include/asm-generic/vmlinux.lds.h | 11 ++++++++++- include/linux/init.h | 2 ++ include/linux/module.h | 6 ++++++ init/Kconfig | 5 +++++ init/main.c | 13 +++++++++++++ kernel/module.c | 16 ++++++++++++++++ 6 files changed, 52 insertions(+), 1 deletion(-)
include/asm-generic/vmlinux.lds.h +10 -1
@@ -332,6 +332,14 @@/* Section used for early init (in .S files) */ #define HEAD_TEXT *(HEAD_TEXT_SECTION) +#ifdef CONFIG_CONSTRUCTORS +#define KERNEL_CTORS () VMLINUX_SYMBOL(__ctors_start) = .; \ + *(.ctors) \ + VMLINUX_SYMBOL(__ctors_end) = .; +#else +#define KERNEL_CTORS () +#endif +/* init and exit section handling */ #define INIT_DATA \ *(.init.data) \
@@ -340,7 +348,8 @@ CPU_DISCARD(init.data) \ CPU_DISCARD(init.rodata) \ MEM_DISCARD(init.data) \ - MEM_DISCARD(init.rodata) + MEM_DISCARD(init.rodata) \ + KERNEL_CTORS()#define INIT_TEXT \ *(.init.text) \
include/linux/init.h +2 -0
@@ -136,6 +136,8 @@ typedef void (*exitcall_t)(void);extern initcall_t __con_initcall_start[], __con_initcall_end[];extern initcall_t __security_initcall_start[], __security_initcall_end[]; +typedef void (*ctor_fn_t )(void ); +/* Defined in init/main.c */ extern int do_one_initcall (initcall_t fn);extern char __initdata boot_command_line[];
include/linux/module.h +6 -0
@@ -354,6 +354,12 @@ struct modulelocal_t ref;#endif #endif + +#ifdef CONFIG_CONSTRUCTORS +/* Constructor functions. */ +ctor_fn_t *ctors; +unsigned int num_ctors; +#endif };#ifndef MODULE_ARCH_INIT #define MODULE_ARCH_INIT {}
init/main.c +13 -0
@@ -700,6 +700,18 @@ asmlinkage void __init start_kernel(voidrest_init (); } +/* Call all constructor functions linked into the kernel. */ +static void __init do_ctors (void ) +{ +#ifdef CONFIG_CONSTRUCTORS +extern ctor_fn_t __ctors_start[], __ctors_end[]; +ctor_fn_t *call; + +for (call = __ctors_start; call < __ctors_end; call++) + (*call)(); +#endif +} +int initcall_debug;core_param (initcall_debug, initcall_debug, bool,0644 );
@@ -780,6 +792,7 @@ static void __init do_basic_setup(void)usermodehelper_init ();driver_init ();init_irq_proc (); +do_ctors ();do_initcalls (); }
kernel/module.c +16 -0
@@ -2172,6 +2172,10 @@ static noinline struct module *load_modusizeof (*mod->tracepoints), &mod->num_tracepoints);#endif +#ifdef CONFIG_CONSTRUCTORS + mod->ctors =section_objs (hdr, sechdrs, secstrings,".ctors" , +sizeof (*mod->ctors), &mod->num_ctors); +#endif #ifdef CONFIG_MODVERSIONS if ((mod->num_syms && !mod->crcs)
@@ -2328,6 +2332,17 @@ static noinline struct module *load_modu goto free_hdr; } +/* Call module constructors. */ +static void do_mod_ctors (struct module *mod) +{ +#ifdef CONFIG_CONSTRUCTORS +unsigned long i; + +for (i =0 ; i < mod->num_ctors; i++) + mod->ctors[i](); +#endif +} +/* This is where the real work happens */ SYSCALL_DEFINE3(init_module, void __user *, umod, unsigned long, len, const char __user *, uargs)
@@ -2356,6 +2371,7 @@ SYSCALL_DEFINE3(init_module, void __userblocking_notifier_call_chain (&module_notify_list,MODULE_STATE_COMING , mod); +do_mod_ctors (mod);/* Start the module */ if (mod->init !=NULL ) ret =do_one_initcall (mod->init);
init/Kconfig +5 -0
@@ -16,6 +16,11 @@ config DEFCONFIG_LIST default "$ARCH_DEFCONFIG" default "arch/$ARCH/defconfig" +config CONSTRUCTORS + bool + depends on !UML + default y + menu "General setup" config EXPERIMENTAL
cover gcov kernel support
This patchset implements support for performing kernel code coverage measurements based on gcc's gcov mechanism. It can be used to improve kernel code quality by identifying code parts which are not exercised during test cases. Patch base is 2.6.30-rc4.
Changes since last version:
* moved compiler version assertion to include/linux/compiler-gcc3.h
* moved all module-specific code under CONFIG_MODULES
* added symbolic names for gcda file record numbers
* split seq_write_gcov_int() into two functions
* coding style changes:
* fixed multi-line comments
* added braces for multi-line blocks
* improved rc and error label usage
* made local variable initialization consistent
* added initialization indentation
* improved readability by using local variables
Patch overview:
[PATCH 1/4] kernel: constructor support
[PATCH 2/4] seq_file: add function to write binary data [PATCH 3/4] gcov: add gcov profiling infrastructure [PATCH 4/4] gcov: enable GCOV_PROFILE_ALL for x86_64
For more information see Documentation/gcov.txt and the previous post:
http://marc.info/?l=linux-kernel&m=123565658224661
Re: [PATCH 1/4] kernel: constructor support
In reply to Peter OberparleiterQuoted 6 lines · Peter Oberparleiter
From: Peter Oberparleiter <[email protected]>
Call constructors (gcc-generated initcall-like functions) during kernel start and module load. Constructors are e.g. used for gcov data initialization.
Quoted 7 lines
Disable constructor support for usermode Linux to prevent conflicts with host glibc.
Signed-off-by Peter Oberparleiter <[email protected]>Acked-by Rusty Russell <[email protected]>Cc Sam Ravnborg <[email protected]>Cc Jeff Dike <[email protected]>
For UML, Acked-by: WANG Cong <[email protected]>
A small detail below.
Quoted 73 lines
---
include/asm-generic/vmlinux.lds.h | 11 ++++++++++- include/linux/init.h | 2 ++ include/linux/module.h | 6 ++++++ init/Kconfig | 5 +++++ init/main.c | 13 +++++++++++++ kernel/module.c | 16 ++++++++++++++++ 6 files changed, 52 insertions(+), 1 deletion(-)Index:
linux-2.6.30-rc4/include/asm-generic/vmlinux.lds.h
===================================================================include/asm-generic/vmlinux.lds.h +10
-1@@ -332,6 +332,14 @@/* Section used for early init (in .S files) */ #define HEAD_TEXT *(HEAD_TEXT_SECTION) +#ifdef CONFIG_CONSTRUCTORS +#define KERNEL_CTORS () VMLINUX_SYMBOL(__ctors_start) = .; \ + *(.ctors) \ + VMLINUX_SYMBOL(__ctors_end) = .; +#else +#define KERNEL_CTORS () +#endif +/* init and exit section handling */ #define INIT_DATA \ *(.init.data) \@@ -340,7 +348,8 @@ CPU_DISCARD(init.data) \ CPU_DISCARD(init.rodata) \ MEM_DISCARD(init.data) \ - MEM_DISCARD(init.rodata) + MEM_DISCARD(init.rodata) \ + KERNEL_CTORS()#define INIT_TEXT \ *(.init.text) \Index:
linux-2.6.30-rc4/include/linux/init.h
===================================================================include/linux/init.h +2
-0@@ -136,6 +136,8 @@ typedef void (*exitcall_t)(void);extern initcall_t __con_initcall_start[], __con_initcall_end[];extern initcall_t __security_initcall_start[], __security_initcall_end[]; +typedef void (*ctor_fn_t )(void ); +/* Defined in init/main.c */ extern int do_one_initcall (initcall_t fn);extern char __initdata boot_command_line[];Index:
linux-2.6.30-rc4/include/linux/module.h
===================================================================include/linux/module.h +6
-0@@ -354,6 +354,12 @@ struct modulelocal_t ref;#endif #endif + +#ifdef CONFIG_CONSTRUCTORS +/* Constructor functions. */ +ctor_fn_t *ctors; +unsigned int num_ctors; +#endif };#ifndef MODULE_ARCH_INIT #define MODULE_ARCH_INIT {}Index:
linux-2.6.30-rc4/init/main.c
===================================================================
init/main.c asmlinkage void __init start_kernel(void · line 707
Quoted 8 lines
init/main.c +5
-0@@ -700,6 +700,18 @@ asmlinkage void __init start_kernel(voidrest_init (); } +/* Call all constructor functions linked into the kernel. */ +static void __init do_ctors (void ) +{ +#ifdef CONFIG_CONSTRUCTORS +extern ctor_fn_t __ctors_start[], __ctors_end[];
I would like these to be globally decleared, since they are.
Signature · 1 line
Live like a child, think like the god.
Re: [PATCH 1/4] kernel: constructor support
Quoted 10 lines · Américo Wang
Quoted 9 lines · Peter Oberparleiter
From: Peter Oberparleiter <[email protected]>
Index:linux-2.6.30-rc4/init/main.c
===================================================================init/main.c +0
-0@@ -700,6 +700,18 @@ asmlinkage void __init start_kernel(voidrest_init (); }
Quoted 8 lines
init/main.c asmlinkage void __init start_kernel(void · line 707
Quoted 5 lines
init/main.c +5
-0+/* Call all constructor functions linked into the kernel. */ +static void __init do_ctors (void ) +{ +#ifdef CONFIG_CONSTRUCTORS +extern ctor_fn_t __ctors_start[], __ctors_end[];I would like these to be globally decleared, since they are.
Ok, I will move the __ctors_* declarations to include/linux/ínit.h
Thanks.
Re: [PATCH 1/4] kernel: constructor support
Quoted 20 lines · Peter Oberparleiter
Quoted 10 lines · Américo Wang
Quoted 9 lines · Peter Oberparleiter
From: Peter Oberparleiter <[email protected]>
Index:linux-2.6.30-rc4/init/main.c
===================================================================init/main.c +0
-0@@ -700,6 +700,18 @@ asmlinkage void __init start_kernel(voidrest_init (); }Quoted 8 lines
init/main.c asmlinkage void __init start_kernel(void · line 707
Quoted 5 lines
init/main.c +5
-0+/* Call all constructor functions linked into the kernel. */ +static void __init do_ctors (void ) +{ +#ifdef CONFIG_CONSTRUCTORS +extern ctor_fn_t __ctors_start[], __ctors_end[];I would like these to be globally decleared, since they are.
Quoted 1 line
Ok, I will move the __ctors_* declarations to include/linux/ínit.h
include/asm-generic/sections.h please.
And please add a comment too.
That the other entries in the same file lacks a comment is not the example to follow.
Sam
Re: [PATCH 1/4] kernel: constructor support
Quoted 19 lines · Sam Ravnborg
Quoted 18 lines · Peter Oberparleiter
Quoted 17 lines · Américo Wang
Quoted 6 lines · Peter Oberparleiter
From: Peter Oberparleiter <[email protected]>
Index:linux-2.6.30-rc4/init/main.c
===================================================================init/main.c asmlinkage void __init start_kernel(void · line 707
Quoted 8 lines
init/main.c +5
-0@@ -700,6 +700,18 @@ asmlinkage void __init start_kernel(voidrest_init (); } +/* Call all constructor functions linked into the kernel. */ +static void __init do_ctors (void ) +{ +#ifdef CONFIG_CONSTRUCTORS +extern ctor_fn_t __ctors_start[], __ctors_end[];I would like these to be globally decleared, since they are.
Quoted 4 lines
Quoted 1 line
Ok, I will move the __ctors_* declarations to include/linux/ínit.h
include/asm-generic/sections.hplease.
And please add a comment too.
Ok. I'm also assuming that the preferred type declaration for section boundaries defined in sections.h would be char[] so I'm changing that as well.
Updated patch set to follow. Thanks.