LINKER/LOADER DOUBT

P

Pradeep

Hi all,

I m basically trying to understand the linking/loading process, please
bear with me as i have specified my question in an unclear fashion.

Any document that u think can clarify my doubts will also do, just
specify the link of the doc.

After reading some documents online, i have perceived that the some
information about symbol resolution is built into the executable.
(WHAT EXACTLY IS THIS INFORMATION & HOW IT IS USED DURING THE COMPILE
TIME & RUN TIME?, IF POSSIBLE EXPLAIN WITH SOME EXAMPLE). This
requires giving the soname during the compile time(BUT WHT IS THE
MAJOR NUMBER AND RELEASE VERSION INFO IN THE REAL NAME, WHAT IS ITS
SIGNIFICANCE AND HOW IS IT USED). But during loading the loader call
the runtime linker that actually does the relocation of symbols in the
executables, and once relocated the address is fixed ( FIXED IN
CONTEXT OF THE PROCESS?, HOW DOES THIS HAPPENS ?). The global data
of a shared object is static by default, and it gets copied to the
executable process image, and each process is having a private copy of
it.


That means
/* Library code */
foo.c

int fooVar;

int fooFun(){
return ++fooVar;
}

/* executable code */
x.c
main(int argc, char **argv){
for (i != argc)
fooFun();
}

multiple instances of x.c will have private values of fooVar in their
process image, if i invoke them with multiple cmd line params just to
check.

x.c 1 will have 2
x.c 1 2 3 4 5 6 will have 7 ...

IF THIS IS THE CASE, THEN WHERE DOES fooVar IS STORED IN CALLING EXE.
SO ITS THREAD SAFE.



int fooFun(){
static int fooVar;
return ++fooVar;
}
This will have inconsistent behaviour coz its only one instance is
there in dll, SO WHERE IS THIS HAPPENING AND WHERE IS IT STORED, IS IT
AVAILABLE AS A SYMBOL IN THE SHARED LIBRARY. CAN SOMEONE EXPLAIN ME
THE BEHAVIOUR IN CONTEXT OF ONE PROCESS RUNNING MULTIPLE THREADS AND
MULTIPLE INSTANCE OF THE SAME PROCESS.


but all automatic variables are allocated on to the stack of the
executable stack.

int fooFun(){
int fooVar = 0;
return ++fooVar;
}

will always return 1 and fooVar will be alocated onto the stack of
calling process. IS IT SO?

And for all allocation done and released in a function call from
Shared library will use the calling process Heap.
 
J

Jens.Toerring

Pradeep said:
I m basically trying to understand the linking/loading process, please
bear with me as i have specified my question in an unclear fashion.

And then you are unfortunately wrong here. Linking, loading and
processes are things that are outside the realm of C. Typically,
they are rather system specific (but more or less independent of
the language the progam was written in), so your best bet is to
ask in a group that deals with the details of the system you are
using.
Regards, Jens
 
S

senapathy

And then you are unfortunately wrong here. Linking, loading and
processes are things that are outside the realm of C. Typically,
they are rather system specific (but more or less independent of
the language the progam was written in), so your best bet is to
ask in a group that deals with the details of the system you are
using.
Regards, Jens

Pls. refer the book
"embedded systems programming in c & c++"
it has a seperate topic about the "linkers, locaters, loaders"

senapathy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top