Re: [patch 03/26] Dynamic kernel command-line - arm

From: Russell King
Date: Mon Jan 22 2007 - 17:27:58 EST


On Mon, Jan 22, 2007 at 11:14:00PM +0100, Bernhard Walle wrote:
> * Russell King <rmk+lkml@xxxxxxxxxxxxxxxx> [2007-01-18 16:23]:
> > On Thu, Jan 18, 2007 at 04:31:51PM +0100, Tomas Carnecky wrote:
> > > Russell King wrote:
> > > > On Thu, Jan 18, 2007 at 01:58:52PM +0100, Bernhard Walle wrote:
> > > >> -static char command_line[COMMAND_LINE_SIZE];
> > > >> +static char __initdata command_line[COMMAND_LINE_SIZE];
> > > >
> > > > Uninitialised data is placed in the BSS. Adding __initdata to BSS
> > > > data causes grief.
> > > >
> > >
> > > Static variables are implicitly initialized to zero. Does that also
> > > count as initialization?
> >
> > No. As I say, they're placed in the BSS. The BSS is zeroed as part of
> > the C runtime initialisation.
> >
> > If you want to place a variable in a specific section, it must be
> > explicitly initialised. Eg,
> >
> > static char __initdata command_line[COMMAND_LINE_SIZE] = "";
>
> Why? It must be initialised if you rely on a initialised value in the
> code.

That comment most certainly is 100% incorrect. The following:

static char foo[16];

has a well defined value when you read from it before writing to it.
If you think otherwise, suggest you read any specification of the C
language.

> But I don't think that this in in case here. Can you tell me the
> code where you read from command_line before writing to it?

That wasn't my point.

Anyway, here's what the GCC manual has to say about use of
__attribute__((section)) on variables:

`section ("SECTION-NAME")'
Use the `section' attribute with an _initialized_ definition of a
_global_ variable, as shown in the example. GCC issues a warning
and otherwise ignores the `section' attribute in uninitialized
variable declarations.

You may only use the `section' attribute with a fully initialized
global definition because of the way linkers work. The linker
requires each object be defined once, with the exception that
uninitialized variables tentatively go in the `common' (or `bss')
section and can be multiply "defined". You can force a variable
to be initialized with the `-fno-common' flag or the `nocommon'
attribute.

which reflects precisely what I've been saying concerning the addition
of __initdata.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of:
-
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/