[PATCH] kernel: Shrink embedded kernel, remove WARN strings when!CONFIG_PRINTK
From: Joe Perches
Date: Tue May 22 2012 - 21:34:45 EST
WARN strings are currently always saved in text.
When printk is not enabled, this wastes space.
Don't call or compile slowpath_warn_<foo> when !CONFIG_PRINTK.
This makes an embedded image without printk support ~1% smaller.
x86-32 allnoconfig/embedded:
$ size vmlinux.new vmlinux.old
text data bss dec hex filename
1180807 182720 1269372 2632899 282cc3 vmlinux.new
1198760 182720 1267948 2649428 286d54 vmlinux.old
Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
---
include/asm-generic/bug.h | 18 +++++++++++++++++-
kernel/panic.c | 3 +++
2 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 2520a6e..a16101a 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -59,7 +59,8 @@ struct bug_entry {
* appear at runtime. Use the versions with printk format strings
* to provide better diagnostics.
*/
-#ifndef __WARN_TAINT
+#if !defined(__WARN_TAINT)
+
#ifndef __ASSEMBLY__
extern __printf(3, 4)
void warn_slowpath_fmt(const char *file, const int line,
@@ -70,15 +71,30 @@ void warn_slowpath_fmt_taint(const char *file, const int line, unsigned taint,
extern void warn_slowpath_null(const char *file, const int line);
#define WANT_WARN_ON_SLOWPATH
#endif
+
+#ifdef CONFIG_PRINTK
#define __WARN() warn_slowpath_null(__FILE__, __LINE__)
#define __WARN_printf(arg...) warn_slowpath_fmt(__FILE__, __LINE__, arg)
#define __WARN_printf_taint(taint, arg...) \
warn_slowpath_fmt_taint(__FILE__, __LINE__, taint, arg)
#else
+#define __WARN() do {} while (0)
+#define __WARN_printf(fmt, ...) \
+do { \
+ if (0) \
+ printk(fmt, ##__VA_ARGS__); \
+} while (0)
+#define __WARN_printf_taint(taint, fmt, ...) \
+ __WARN_printf(fmt, ##__VA_ARGS__)
+#endif
+
+#else
+
#define __WARN() __WARN_TAINT(TAINT_WARN)
#define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
#define __WARN_printf_taint(taint, arg...) \
do { printk(arg); __WARN_TAINT(taint); } while (0)
+
#endif
#ifndef WARN_ON
diff --git a/kernel/panic.c b/kernel/panic.c
index 8ed89a1..bc57785 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -396,6 +396,7 @@ struct slowpath_args {
va_list args;
};
+#ifdef CONFIG_PRINTK
static void warn_slowpath_common(const char *file, int line, void *caller,
unsigned taint, struct slowpath_args *args)
{
@@ -449,6 +450,8 @@ void warn_slowpath_null(const char *file, int line)
EXPORT_SYMBOL(warn_slowpath_null);
#endif
+#endif
+
#ifdef CONFIG_CC_STACKPROTECTOR
/*
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/