This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Help?
- To: gcc-help at gcc dot gnu dot org
- Subject: Help?
- From: Kwanghoon Choi <khchoi at ruby dot kaist dot ac dot kr>
- Date: Wed, 3 Jan 2001 11:24:46 +0900 (KST)
- cc: Kwanghoon Choi <khchoi at ruby dot kaist dot ac dot kr>
Hello all,
I would like to know the precise sequence of loading and execution of
a given executable. In my specific flatform (the ARM machine, uclinux kernel,
gcc, and glibc), I am using binary executables in a flat form, not like ELF.
The below simple program gets crashed whenever I compile the program with
-lpthread even if the program does not use the thread library. If I omit
the option -lpthread, it works well!
main()
{
int childpid;
if( (childpid = vfork()) == -1 ) {
/* can't vfork */
}
else if(childpid == 0) {
/* child process */
}
else {
/* parent process */
}
}
I know it is foolish to give the option -lpthread in my simple program,
but it is just a test to resolve my questions to be explained.
In order to examine why, I instrumented some printf-like functions into
uclinux kernel sources and glibc sources.
By instrumenting pthread library functions in glibc, I found that
pthread_initialize() gets called before the main() function.
The reason seems to be that the function is declared as this:
static void pthread_initialize(void) __attribute__((constructor));
My execution sequence is like this as far as I know by instrumenting
printf-like functions.
KERNEL : ...
search_binary_handler() // load an executable in a flat form
do_load_flat_binary() // $UCLINUX/fs/binfmt_flat.c
...
wake_up() // the process for the executable
// gets control
???
USER : ???
__libc_start_main // $GLIBC/sysdeps/generic/libc-start.c
// glibc's entry ?
???
pthread_initialize() // $GLIBC/linuxpthread/pthread.c
// pthread initialization
...
main() // user's program
First, I don't know who really calls __libc_start_main() functions. Notice
that it receives several arguments, mostly function pointers.
int __libc_start_main (int (*main) (int, char **, char **), int argc,
char **argv, void (*init) (void), void (*fini) (void),
void (*rtld_fini) (void), void *stack_end)
{
...
}
Second, though I know pthread_initialize() is (indirectly) called in the
__libc_start_main(), I don't know where exectly. The reason is that
pthread_initialize() seems to be called via some function pointer, e.g. init().
Third, I don't know how GCC compiles the functions declared with
__attribute__((constructor)). I would like to know the compilation
strategy specifically in the flat-formed executable.
Although I will check this mailing list reguraly, it would be happy
to forward your reply to khchoi@pllab.kaist.ac.kr.
Thank you for reading my long mail.
Kwanghoon
p.s. I looked around the site of GCC online documentation
(http://www.gnu.org/software/gcc/onlinedocs/)
but it contains some broken links, e.g. for GCC manual
(http://gcc.gnu.org/onlinedocs/gcc_toc.html)