This is the mail archive of the
mailing list for the binutils project.
Re: Do weak variables waste mem?
- From: Thomas Schmid <scth2000 at yahoo dot de>
- To: Alan Modra <amodra at gmail dot com>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Wed, 25 Feb 2015 14:22:43 +0000 (UTC)
- Subject: Re: Do weak variables waste mem?
- Authentication-results: sourceware.org; auth=none
- References: <20150224223312 dot GC16384 at bubble dot grove dot modra dot org>
- Reply-to: Thomas Schmid <scth2000 at yahoo dot de>
Alan Modra schrieb am 24.02.2015 23:33:
> You have defined two copies of the variables. Without the
> __attribute__((__weak__)) you also have two definitions of each
> variable, but some compilers (including gcc) treat them specially - as
> common variables. You should instead declare the variables as extern
> in the header, and define them in one of the source files.
When you say "two copies of the variables", you mean that each object uses its own variable?
When i look at the symbol table, only one variable is used.
I agree that defining the variables explicitly is the better solution, but this declarations are generated and not easy to change.
In reality these variables are also declared with __attribute__((__section__())) to put these special variables together. They are finally put back to .bss via linkerscript.