This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Do weak variables waste mem?
- From: Alan Modra <amodra at gmail dot com>
- To: Thomas Schmid <scth2000 at yahoo dot de>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Wed, 25 Feb 2015 09:03:12 +1030
- Subject: Re: Do weak variables waste mem?
- Authentication-results: sourceware.org; auth=none
- References: <1018022324 dot 6397754 dot 1424782875554 dot JavaMail dot yahoo at mail dot yahoo dot com>
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