Skip to contentSkip to conversation

List of all-zero .data variables in linux-2.4.3 available

DISCUSSION Adam J. Richter 5 participants 5 messages Apr 12, 2001

lore
Share & tools
lore
#0 lore raw

For anyone who is interested, I have produced a list of all
of the .data variables that contain all zeroes and could be moved to .bss within the kernel and all of the modules (all of the modules that we build at Yggdrasil for x86, which is almost all). These are global or static variables that have been declared

	int foo = 0;

instead of

	int foo;	/* = 0 */

	The result is that the .o files are bigger than they have

to be. The kernel memory image is not bigger, and gzip shrinks the runs of zeroes down to almost nothing, so it does not have a huge effect on bootable disks. Still, it would be nice to save the disk space of the approximately 75 kilobytes of zeroes and perhaps squeeze in another sector or two when building boot floppies.

I have also included a copy of the program that I wrote to
find these all-zero .data variables.

The program and the output are FTPable from
ftp://ftp.yggdrasil.com/private/adam/linux/zerovars/. Files with no all-zero .data variables are not included in the listing. If you maintain any code in the kernel, you might want to look at the output to see how your code stacks up.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
[email protected]     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America

fax +1 408 261-6631 "Free Software For The Rest Of Us."

#1 lore raw

Shouldn't a compiler be able to deal with this instead? (Just a thought.)
/Johan

----- Original Message -----
From: Adam J. Richter <[email protected]>
To: <[email protected]>
Sent: Thursday, April 12, 2001 2:36 PM
Subject: List of all-zero .data variables in linux-2.4.3 available

Quoted 22 lines

For anyone who is interested, I have produced a list of all of the .data variables that contain all zeroes and could be moved to .bss within the kernel and all of the modules (all of the modules that we build at Yggdrasil for x86, which is almost all). These are global or static variables that have been declared

int foo = 0;

instead of

int foo; /* = 0 */

The result is that the .o files are bigger than they have
to be. The kernel memory image is not bigger, and gzip shrinks the runs of zeroes down to almost nothing, so it does not have a huge effect on bootable disks. Still, it would be nice to save the disk space of the approximately 75 kilobytes of zeroes and perhaps squeeze in another sector or two when building boot floppies.

I have also included a copy of the program that I wrote to find these all-zero .data variables.

Quoted 7 lines

The program and the output are FTPable from ftp://ftp.yggdrasil.com/private/adam/linux/zerovars/. Files with no all-zero .data variables are not included in the listing. If you maintain any code in the kernel, you might want to look at the output to see how your code stacks up.

Adam J. Richter __ ______________ 4880 Stevens Creek Blvd, Suite

104

Quoted 1 line

[email protected] \ / San Jose, California

95129-1034

Quoted 8 lines

+1 408 261-6630 | g g d r a s i l United States of America
fax +1 408 261-6631 "Free Software For The Rest Of Us."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw
Quoted 3 lines · On Thu, 12 Apr 2001 [email protected] wrote:

Shouldn't a compiler be able to deal with this instead? (Just a thought.)
/Johan

The compiler does deal with it. That's why you have a choice when you write code.

The defacto standard has been that initialized data, regardless of whether it's initialized with zero, goes into the ".data" area (segment). Non initialized data, that gets zeroed at run-time goes into the ".bss" area.

If you declare a file-scope variable as:

	int foo;

it goes into '.bss'.

If you declare it as:

	int foo = 0;

it goes into '.data'.

Data that is in '.data' occupies space in the executable image. With the kernel, it makes the kernel larger than necessary.

Data that is in '.bss' is just a single long int in the file header. It tells the loader how much space to allocate and zero. There is quite an obvious advantage to using '.bss' when possible, rather than '.data'.

At one time, data that was declared as:

	int foo;

may, or may not, have been initialized to zero. This was "implementation defined". Therefore we were taught to always initialize these variables.

The C98 standard now requires that such variables be initialized to zero so you don't need to do this anymore. This allows such variables to be put into space that is allocated at run-time, making executable files shorter.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of course you get it all back when you reboot..."; Actual explanation obtained from the Micro$oft help desk.

#4 lore raw
In reply to Adam J. Richter
Quoted 5 lines · Adam J. Richter

For anyone who is interested, I have produced a list of all
of the .data variables that contain all zeroes and could be moved to .bss within the kernel and all of the modules (all of the modules that we build at Yggdrasil for x86, which is almost all). These are global or static variables that have been declared

Thanks, but Andrey Panin did you one better -- he produced a patch which fixes up a good number of these. You should follow lkml more closely :)

Signature · 3 lines
Jeff Garzik       | Sam: "Mind if I drive?"
Building 1024     | Max: "Not if you don't mind me clawing at the dash
MandrakeSoft      |       and shrieking like a cheerleader."