]> git.ipfire.org Git - people/ms/linux.git/commitdiff
tracing: Fix ftrace_event_call alignment for use with gcc 4.5
authorJeff Mahoney <jeffm@suse.com>
Wed, 24 Feb 2010 18:59:23 +0000 (13:59 -0500)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 15 Mar 2010 16:06:17 +0000 (09:06 -0700)
commit 86c38a31aa7f2dd6e74a262710bf8ebf7455acc5 upstream.

GCC 4.5 introduces behavior that forces the alignment of structures to
 use the largest possible value. The default value is 32 bytes, so if
 some structures are defined with a 4-byte alignment and others aren't
 declared with an alignment constraint at all - it will align at 32-bytes.

 For things like the ftrace events, this results in a non-standard array.
 When initializing the ftrace subsystem, we traverse the _ftrace_events
 section and call the initialization callback for each event. When the
 structures are misaligned, we could be treating another part of the
 structure (or the zeroed out space between them) as a function pointer.

 This patch forces the alignment for all the ftrace_event_call structures
 to 4 bytes.

 Without this patch, the kernel fails to boot very early when built with
 gcc 4.5.

 It's trivial to check the alignment of the members of the array, so it
 might be worthwhile to add something to the build system to do that
 automatically. Unfortunately, that only covers this case. I've asked one
 of the gcc developers about adding a warning when this condition is seen.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
LKML-Reference: <4B85770B.6010901@suse.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/linux/syscalls.h
include/trace/ftrace.h
kernel/trace/trace.h

index 207466a49f3d59b9d0927670c379d8be091a4d37..254077057cb801ba4f025832d764b9d80198486a 100644 (file)
@@ -132,7 +132,8 @@ struct perf_event_attr;
 
 #define SYSCALL_TRACE_ENTER_EVENT(sname)                               \
        static const struct syscall_metadata __syscall_meta_##sname;    \
-       static struct ftrace_event_call event_enter_##sname;            \
+       static struct ftrace_event_call                                 \
+       __attribute__((__aligned__(4))) event_enter_##sname;            \
        static struct trace_event enter_syscall_print_##sname = {       \
                .trace                  = print_syscall_enter,          \
        };                                                              \
@@ -154,7 +155,8 @@ struct perf_event_attr;
 
 #define SYSCALL_TRACE_EXIT_EVENT(sname)                                        \
        static const struct syscall_metadata __syscall_meta_##sname;    \
-       static struct ftrace_event_call event_exit_##sname;             \
+       static struct ftrace_event_call                                 \
+       __attribute__((__aligned__(4))) event_exit_##sname;             \
        static struct trace_event exit_syscall_print_##sname = {        \
                .trace                  = print_syscall_exit,           \
        };                                                              \
index c6fe03e902ca2c4502c984b79645d1d3648f2640..1ca49902094c86015e5db33b235c4643836c0d74 100644 (file)
@@ -65,7 +65,8 @@
        };
 #undef DEFINE_EVENT
 #define DEFINE_EVENT(template, name, proto, args)      \
-       static struct ftrace_event_call event_##name
+       static struct ftrace_event_call                 \
+       __attribute__((__aligned__(4))) event_##name
 
 #undef DEFINE_EVENT_PRINT
 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
index 4df6a77eb1966bd4ea12779121f12e96ddf1d3f6..a1edaa8518ee7915c611428ae69003821bdc42ff 100644 (file)
@@ -791,7 +791,8 @@ extern const char *__stop___trace_bprintk_fmt[];
 
 #undef FTRACE_ENTRY
 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print)            \
-       extern struct ftrace_event_call event_##call;
+       extern struct ftrace_event_call                                 \
+       __attribute__((__aligned__(4))) event_##call;
 #undef FTRACE_ENTRY_DUP
 #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print)                \
        FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))