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?



Alan Modra schrieb am 26.02.2015 0:31:
>If you are able to modify the generator then a number of options are
>available.
>1) Emit code that does
>    #ifdef MAIN_PROGRAIN
>      variable definition
>    #else
>      variable declaration (with extern)
>    #endif
>   then define MAIN_PROGRAM in just one source file that includes your
>   headers.
>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.


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