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.
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.