public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kwanghoon Choi <khchoi@ruby.kaist.ac.kr>
To: gcc-help@gcc.gnu.org
Cc: Kwanghoon Choi <khchoi@ruby.kaist.ac.kr>
Subject: Help?
Date: Tue, 02 Jan 2001 18:27:00 -0000	[thread overview]
Message-ID: <Pine.SOL.4.05.10101031040190.23560-100000@ruby.kaist.ac.kr> (raw)

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 )



             reply	other threads:[~2001-01-02 18:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-02 18:27 Kwanghoon Choi [this message]
2001-01-02 19:37 ` Help? Alexandre Oliva
  -- strict thread matches above, loose matches on Subject: below --
2018-06-01 15:58 Help!! Tomas Ukkonen
2006-12-26 13:38 help!! manish manish
2006-12-27 17:01 ` help!! Ian Lance Taylor
2006-01-28  5:42 Help? Garvin Pang
2006-01-28  7:41 ` Help? Brian Dessent
2005-06-02 15:54 help_ imacat
2003-07-12 10:05 help? Shen Hui
2003-03-03 17:37 help!!! Jim Frost
2003-03-07  5:46 ` help!!! LLeweLLyn Reese
     [not found] <20021204042724.64819.qmail@web15002.mail.bjs.yahoo.com>
2002-12-04  0:16 ` help! Ben Elliston
2002-11-19 10:16 help!!! mingo lu
     [not found] <20020617195757.13842.qmail@uwdvg001.cms.usa.net>
2002-06-17 13:05 ` help!! Phil Edwards
2002-04-04 23:41 Help! 朱 少波
2000-05-15  9:15 HELP!!! Michael Michael
2000-05-16 23:27 ` HELP!!! Martin v. Loewis
2000-03-08 14:14 HELP !!! Fabrício Souza
2000-03-09 17:00 ` Alexandre Oliva
2000-04-01  0:00   ` Alexandre Oliva
2000-04-01  0:00 ` Fabrício Souza
2000-02-24  0:56 Help! 陳鵬升
2000-04-01  0:00 ` Help! 陳鵬升

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.SOL.4.05.10101031040190.23560-100000@ruby.kaist.ac.kr \
    --to=khchoi@ruby.kaist.ac.kr \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).