kernel: Shrink embedded kernel, remove WARN strings when !CONFIG_PRINTK
PATCH 1/1 kernel: Shrink embedded kernel, remove WARN strings when !CONFIG_PRINTK
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 <[email protected]>
--- include/asm-generic/bug.h | 18 +++++++++++++++++- kernel/panic.c | 3 +++ 2 files changed, 20 insertions(+), 1 deletions(-)
include/asm-generic/bug.h +17 -1
@@ -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
kernel/panic.c +3 -0
@@ -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 /*