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: Mon, 2 Mar 2015 13:54:47 +0000 (UTC)
- Subject: Re: Do weak variables waste mem?
- Authentication-results: sourceware.org; auth=none
- References: <20150225233141 dot GF16384 at bubble dot grove dot modra dot org>
- Reply-to: Thomas Schmid <scth2000 at yahoo dot de>
Alan Modra schrieb am 26.02.2015 0:31:
>If you are able to modify the generator then a number of options are
>1) Emit code that does
> #ifdef MAIN_PROGRAIN
> variable definition
> variable declaration (with extern)
> then define MAIN_PROGRAM in just one source file that includes your
>2) Use linkonce or comdat group sections for the variables.
>You might also like to investigate whether --gc-sections works for
>you. Not all targets support this linker option.. If your target
>doesn't then you could consider adding support to the linker.
Thank you for your help - for a moment, I thought, "linkonce" will do the job, but unfortunately it doesn't.
This mechanism isn't very clever, it takes the section of the first .o file und discards all other sections, regardless of their content, in my case this will often lead to execution errors because of missing variables at load time.
I didn't find out, if "comdat" is similar or a bit more clever and if it is possible to use this feature for weak variables. Is there any documentation?
--gc-sections with -fdata-sections sounds also interesting, but in my first simple tests, I couldn't manage to leave any content in .text und .bss. It seems that the linker thinks, that the variables are never used.