public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: dboml <dboml@free.fr>
To: gcc-help@gcc.gnu.org
Subject: How use linux_kernel init_calls system in a modular application?
Date: Thu, 22 Sep 2011 19:19:00 -0000	[thread overview]
Message-ID: <4E7B8A22.8020509@free.fr> (raw)

Hello,
I develop a modular application like this:
main.c
main.h
modul1/module1.c
modul1/module1.h
modul2/module2.c
modul2/module2.h
modul3/module3.c
modul3/module3.h

so in main.c, i need to include all modules header like this:

#ifdef USE_MODULE_1
     #include modul1/module1.H
#endif
#ifdef USE_MODULE_2
     #include modul2/module2.H
#endif
#ifdef USE_MODULE_3
     #include modul3/module3.H
#endif

int main () {
     #ifdef USE_MODULE_1
         module1_init();
     #endif
     #ifdef USE_MODULE_2
         module2_init();
     #endif
     #ifdef USE_MODULE_3
         module3_init();
     #endif
}

So, i decide to use the system in linux KERNEL initCalls.
It is based on linker sections where are stor init modules functions.
in main.h:
typedef int (*initcall_t)(void);
#define MODULE_INIT(fn) static initcall_t __initcall_##fn __used 
__attribute__((__section__(".initcall.init"))) = fn;

in modul1/module1.c :
MODULE_INIT(module1_init)

And then, use it in main.c
main(){
for (fn = __initcall_start; fn < __initcall_end; fn++)
         do_one_initcall(*fn);
}

My question is: how configure the linker for my linux app?
For the moment i "don't use" any special linker script.
Can't find a good tutorial....

Thanks for any help.

David.

                 reply	other threads:[~2011-09-22 19:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4E7B8A22.8020509@free.fr \
    --to=dboml@free.fr \
    --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).