Subject: Re: kernel compilation using gcc 3.2.2 - supposed to work?
To: Jason Thorpe <thorpej@wasabisystems.com>
From: theo borm <theo4490@borm.org>
List: tech-kern
Date: 04/23/2003 00:27:05
Jason Thorpe wrote:

> This, however, is not. A zero-length format string is a perfectly 
> legitimate argument, and note that it has special significance with 
> log() and addlog().

That the others were "unwanted features" had occurred to me already. 
About the log() I was not sure;
I also think that a zero length format specifier should be legal.

Grepping all kernel sources I could only find one single instance where 
this function was used with
a zero length argument (which is of course not an exhaustive search, but 
it gives a good indication
of the importance of a certain feature)

So I took a look at the log() and kprintf() function (which it calls) 
itself, and though I could see
that the zero length format specifier is correctly handled by the:
if (*fmt == 0)
goto done;

I failed to see the significance of the only remaining bit of payload:
if ((oflags == TOBUFONLY) && (vp != NULL))
*(char **)vp = sbuf;
especially since the kprintf function is called from log() with both vp 
and sbuf set to NULL.

So I assumed that the only purpose of the log() with zero-length format 
specifier was to log the
level without any further details, and more-or-less the same effect can 
be obtained by using
a single space instead of an empty string (satisfying gcc)
I have not looked into the matter very thoroughly; I did see some 
occurrences of addlog()
with what appeared to be a zero length format specifier, but have not 
figured out why these
work while log() doesn't.

Patching gcc to handle the situation is of course the right route to 
follow, I was simply looking
for a quick patch to satisfy my curiosity.

Still I think it's amazing that the kernel code survives essentially 
intact in (what I consider) a
major compiler migration, and that fact stands as a tribute to it's 
architects, and as a tribute to
the designers of gcc.

cheers,
Theo.



>
> The change for GCC 3.3 was to add a switch that disables warnings for 
> zero-length format strings.
>
> GCC 3.3 also has changes to not warn about NULL format arguments to 
> NetBSD's userlevel err(3), warn(3), etc. library functions (NULL is a 
> legitimate format argument for those functions, yet when non-NULL is 
> passed, we want normal printf format checking).
>
> -- Jason R. Thorpe <thorpej@wasabisystems.com>
>