Re: [Announce] Linux-tiny project revival

From: Dick Streefland
Date: Fri Sep 28 2007 - 10:36:21 EST

Rob Landley <rob@xxxxxxxxxxx> wrote:
| The "change every printk in the kernel" suggestion came from me trying to
| figure out how to get the printk() calls below a certain log level to
| optimize out and not take up space in the binary.
| The above doesn't address the original cause of the thread, as far as I can
| tell.

It does, provided you change the macro definition to:

#define _printk(level, str, ...) \
do { \
if (sizeof(level) == 1) /* continued printk */\
actual_printk(str, __VA_ARGS__); \
else if ((level[1] - '0') < CONFIG_PRINTK_DOICARE) \
actual_printk(level str, __VA_ARGS__); \
} while(0);
#define printk(level_str, ...) _printk(level_str, __VA_ARGS__)

Gcc will do constant folding on the string subscripts, and remove the
code and the string constants for calls above the desired level.

This is basically the same as I proposed in my earlier message [*],
but with the disadvantage that you need to modify all printk() calls
without an explicit level and add the ugly comma to the KERN_* macros.
Just compile the code in my message with -O and -S and you will see
that the KERN_NOTICE call and the corresponding string literal are
optimized away.


Dick Streefland //// Altium BV
dick.streefland@xxxxxxxxx (@ @)

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at