This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Do weak variables waste mem?


On Tue, Feb 24, 2015 at 01:01:15PM +0000, Thomas Schmid wrote:
> For me it looks like a waste of mem. Why is there space left on the end of section .bss?

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.

> <inc.h:>
> 
> int var1 __attribute__((__weak__));
> int var2 __attribute__((__weak__));
> 
> <s1.c>
> #include "inc.h"
> 
> <s2.c>
> #include "inc.h"

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]