[PATCH 3/3] ARM: zImage: fix issues with missing GOT entries for some global variables

Russell King - ARM Linux linux at arm.linux.org.uk
Wed Apr 27 04:58:53 EDT 2011


On Wed, Apr 20, 2011 at 08:47:17AM -0400, Nicolas Pitre wrote:
> Uninitialized variables are allocated to the .bss section, regardless if 
> they're static or not.  The static keyword only affects the global 
> visibility of the variable,

Wrong.

int foo(void)
{
	static int bar = 1;
	return bar++;
}

With static allowed to have its normal meaning, this function will return
1 on the first call, 2 on the second, etc.  With static defined away, it
will always return 1.  That's a behavioural change.

Moreover, if we have:

int foo(void)
{
	static int table[] = { ... };
}

then with static defined away, this turns into a runtime memcpy from
read-only data to read-write data each time the function is called.

Defining away static causes this kind of undesirable (and often hidden)
effect - and in these cases it most certainly is not just about variable
visibility.



More information about the linux-arm-kernel mailing list