Unix Programming - executable segments -data,text.stack

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > December 2004 > executable segments -data,text.stack





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author executable segments -data,text.stack
sachin_mzn@yahoo.com

2004-12-27, 7:47 am

Hi,

I am little confused about the different segments in an executable.

I know that there are primarily 3 segment, text, data and stack.

I know all local varibales goes into stack.

But I am confused that what goes into text and data segment.

Many say machine instruction goes into text. Can some one clarify me
what is it?

do global functions go into text segment? If it is true then what about
local variables declared in global function, will they go into text ot
stack segment?

Regards,
Sachin

Arto Viitanen

2004-12-27, 7:47 am

>>>>> "sachin" == sachin mzn <sachin_mzn@yahoo.com> writes:

sachin> Hi, I am little confused about the different segments in an
sachin> executable.

sachin> I know that there are primarily 3 segment, text, data and stack.

sachin> I know all local varibales goes into stack.

sachin> But I am confused that what goes into text and data segment.

sachin> Many say machine instruction goes into text. Can some one clarify me
sachin> what is it?

sachin> do global functions go into text segment? If it is true then what
sachin> about local variables declared in global function, will they go into
sachin> text ot stack segment?

sachin> Regards, Sachin

Modern von Neumann computers use memory for both running program and data it
uses. Virtual memory is a way to make a) use more programs than fit together
on to the computer's memory and b) use programs that use more memory than
what computer's memory is. There are two main ways to implement virtual
memory: segmented memory and paged memory. In segmented memory, program is
divided to different segments, that can be load to memory when needed. In
paged memory, the memory is divided to small portions called page, that can
be loaded one at the time (and in different parts of the memory). Actually,
modern Unix systems use paged segmented memory.

Program file is an image of the program to be run on the memory. It is
divided to different segments. Text segment contains the program code to be
run. If program uses dynamic libraries, when the program is loaded to be run,
libraries it refers are also loaded. The data program will be using is
divided into two segments: data and stack. Data contains global variables
(and their default variables), constants etc. Also dynamically allocated
memory (links etc.) is on the data segment. Stack is a segment that is
actually only in running program (that is on program file there is no stack)
and it will contain local variables that are not allocated to registers,
function parameters that are not allocated to registers etc.

Reason for three segments is, that first in the memory space is text, since
it size is known. Then there is data, which is growing upwards. Stack is on
the other size of the memory space (2^word size) and it is growing downwards.

Normally text segment is marked readonly, since there is no need to change
running program. Because of this, text segment might be shared between
several instances of the running program (they are called processes).

--
Arto V. Viitanen av@cs.uta.fi
University of Tampere, Department of Computer Sciences
Tampere, Finland http://www.cs.uta.fi/~av/
sachin_mzn@yahoo.com

2004-12-29, 2:48 am

Thanks Arto,

But I want to know where actually a global function definition placed
in
a process segment. Is it placed into a text segment?

Arto Viitanen

2004-12-29, 7:55 am

>>>>> "sachin" == sachin mzn <sachin_mzn@yahoo.com> writes:

sachin> Thanks Arto, But I want to know where actually a global function
sachin> definition placed in a process segment. Is it placed into a text
sachin> segment?

Yes.

--
Arto V. Viitanen av@cs.uta.fi
University of Tampere, Department of Computer Sciences
Tampere, Finland http://www.cs.uta.fi/~av/
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com