[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
trying to understand the -init/-fini options
From: |
Shankar Kalpathi Easwaran |
Subject: |
trying to understand the -init/-fini options |
Date: |
Tue, 27 Aug 2013 20:19:27 -0700 (PDT) |
I am trying to understand the effect of the -init/-fini command line options.
I was thinking that these options create an .init section/.fini section and
call the functions specified in the command line when the binary is
initialized / atexit time.
Below is an example that I am working with :-
1.c
----
int fn() {
printf("Hello world\n");
return 0;
}
int main() { return 0; }
$gcc --version
gcc (Ubuntu 4.8.1-2ubuntu1~10.04.1) 4.8.1
Case (1)
------------
$gcc 1.c -Wl,-init,fn -o out
$./out ==> Expect to print "Hello World"
(Nothing is printed)
Case (2)
-----------
$cat 1.c
int fn() {
return 0;
}
int main() { return 0; }
$gcc -c 1.c
$ld 1.o -init fn -fini fn -o out
$readelf -S -W out | grep -E 'init|fini'
(Nothing is printed)
I expected to see the linker to create init/fini sections.
Case (3)
-----------
$cat 1.c
int fn() {
return 0;
}
$gcc -c 1.c && ar cr lib1.a 1.o
$ld -init fn lib1.a -o out -t
(Nothing is printed)
Expected 1.o to be pulled in from the archive and the linker to create
init/fini sections.
Case (4)
-----------
What is the difference between .init section and .init_array section ?
When does the linker try to create either of them ?
Similiar is the question of the difference between the .fini section and the
.fini_array section ?
Case (5)
-------------
Is there a difference when a shared object is created for the above cases as
I see the linker is setting DT_INIT/DT_FINI to point to the functions that I
specify for -init/-fini respectively.
Thanks
Shankar Easwaran
--
View this message in context:
http://old.nabble.com/trying-to-understand-the--init--fini-options-tp35883069p35883069.html
Sent from the Gnu - Binutils - Bugs mailing list archive at Nabble.com.
- trying to understand the -init/-fini options,
Shankar Kalpathi Easwaran <=