Skip to contentSkip to conversation

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

DISCUSSION Adam J. Richter 3 participants 3 messages Apr 12, 2001 – Apr 16, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines
Quoted 1 line

= Adam Richter

= Ulrich Drepper

Quoted 3 lines
Quoted 1 line

Shouldn't a compiler be able to deal with this instead?

Yes.

No. gcc must not do this. There are situations where you must place a zero-initialized variable in .data. It is a programmer problem.

I am aware of a couple of cases where code relied on static
variables being allocated contiguously, but, in both cases, those variables were either all zeros or all non-zeros, so my proposed change would not break such code. Also, variables being allocated contiguously is not an assumption supported by any standard that I am aware of, and the very rare cases where code relies on this should instead use an array (they've been of the same type in the examples that I have come across). At the very least, it seems to me that this should be a compiler optimization flag, preferably defaulted to "on".

If you have some other scenario in mind, I'd appreciate an
example or a clear reference to some explanation, and I think others on linux-kernel would probably appreciate that too. It is a topic that comes up repeatedly on linux-kernel.

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
Quoted 4 lines · Adam J. Richter

I am aware of a couple of cases where code relied on static
variables being allocated contiguously, but, in both cases, those variables were either all zeros or all non-zeros, so my proposed change would not break such code.

Continuous placement is not the only property defined by initialization. There are many more. You cannot change this since it will quite a few programs and libraries and subtle and hard to impossible to identify ways. Simply educate programmers to not initialize.

Signature · 3 lines
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------
#2 lore raw
In reply to Adam J. Richter

Hi!

Quoted 10 lines
Quoted 4 lines

I am aware of a couple of cases where code relied on static
variables being allocated contiguously, but, in both cases, those variables were either all zeros or all non-zeros, so my proposed change would not break such code.

Continuous placement is not the only property defined by initialization. There are many more. You cannot change this since it will quite a few programs and libraries and subtle and hard to impossible to identify ways. Simply educate programmers to not initialize.

Unless ansiC specifies such behaviour, such code is buggy. And buggy code should be fixed, not be used as argument against optimalization. [Of course, you can turn off that optimalization for buggy code, if code is too ugly to fix.]

Signature · 2 lines
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt,
details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.