Messages in this thread |  | | From | Keith Owens <> | Subject | Re: 2.1.22 unneeded global symbols | Date | Tue, 28 Jan 1997 23:06:17 +1100 |
| |
On Mon, 27 Jan 1997 21:33:48 +0000 (GMT), alan@lxorguk.ukuu.org.uk (Alan Cox) wrote: >> \begin{C-Legalese} >> If you pass the address of object to another compilation unit >> (i.e. source file), this object does not need to be extern; it >> can be static or allocated (but NOT automatic). >> \end{C-legalese} > >Ah but the following isnt going to work > >foo.c > >static void flobble(int x) >{ > printf("Kersplat\n"); >} > >bar.c > >extern void flobble(int); > >int main() >{ > register_kersplat_handler(flobble); >}
Nobody has suggested making *every* symbol static, only those symbols which are currently external and are not referenced by name from other sources. The above example is a valid case where flobble has to be non-static and does not apply to the real problem.
What Thomas Koenig and I have been complaining about is the ~2,000 external symbols that are not declared as static but neither are they referenced by name from other sources. The fact that they may be passed by address to other routines is irrelevant, their name scope is local no matter what their use scope.
My approach is simple - if there are no external references *by name* to a non-automatic symbol then that symbol should be static. Restricts usage checking to the local source, makes it easier to track down the real usage of the symbol and lets gcc find unused non-automatic symbols.
As an example, see drivers/scsi/53c7,8xx.c. gcc flags one of the procedures as unused, it can only do that because the procedure is correctly defined as static. Comment out that procedure and another couple of procedures become unused because they are static and their only reference is from the first unused proc. Result - the removal of code that is never used and a smaller driver.
We cannot do this with many sources because their procs and global variables are not defined as static. However *if* they are never referenced by name from other sources, why are they not defined as static?
My current report is ftp://ftp.ocs.com.au/pub/extra_externals-2.1.23.gz
|  |