Reg initializing data in segments other than .data

Prasad Venkata Boddupalli bprasad@CS.Arizona.EDU
Tue Jan 31 22:44:00 GMT 2006


I earlier asked as how to have variables assigned to a segment different 
from .data initialized while loading. Since I have my own loader, my 
question was whether the linker, depending upon the attributes of a 
section, writes those initial values into the executable.

Thanks to Mr.Lu and Mr.Nick for their detailed answers. However Mr.Lu 
wrote that it might need changes to linker while Mr.Nick in the following 
fragment hinted that linker already does that.

On Mon, 9 Jan 2006, Nick Clifton wrote:

> The linker script syntax does not (currently) allow you to specify segments or 
> their attributes explicitly.  Instead the linker attempts to create the 
> minimum number of segments necessary in order to group the sections from the 
> input files in the way that the linker script dictates.  (The linker sometimes 
> fails at this task.  See the section describing the "not enough room for 
> program headers" error message in the linker documentation).
>
> So, really, all you want is to make sure that the shared data is not put into 
> the segment that is going to be assigned to ordinary data and that the shared 
> data segment created by the linker has the correct attributes.  Getting the 
> correct attributes should be easy.  The linker calculates the attributes of 
> the segments it creates based on the attributes of the input sections assigned 
> to those segments.  So provided that the symbols in your .shared_section 
> sections have the STT_OBJECT attribute (or at least do not have the STT_COMMON 
> attribute) then the linker should end up assigning them to a segment with the 
> SHF_ALLOC attribute, which will ensure that they are initialised at run-time.

However, when I load the file image of a segment, whose attributes are 
indeed 'ALLOC' and derived from a section one of whose attributes is
'not' STT_COMMON, the values are zero and not the same as initialized 
values. Which suggests that linker might not have written the correct 
values into the corresponding segment portion of the executable. Am I 
probably right on that conclusion ?

However, the file size of the segment equals memory size which probably
hints that the values are copied into the executable. But, why could they 
be zero ?

thanks to this informative list,
Prasad.



More information about the Binutils mailing list