From: Andrew Haley <aph@redhat.com>
To: me@felipebalbi.com
Cc: gcc-help@gcc.gnu.org
Subject: Re: Figurig out start and end of sections
Date: Wed, 14 Apr 2010 08:49:00 -0000 [thread overview]
Message-ID: <4BC58172.8030808@redhat.com> (raw)
In-Reply-To: <20100414050602.GA4050@gandalf>
On 04/14/2010 06:08 AM, Felipe Balbi wrote:
> Hi Andrew,
>
> for some reason I didn't receive your reply.
>
>> On 04/13/2010 06:40 PM, Felipe Balbi wrote:
>>> is there any way to figure out where a section starts and ends ?
>>>
>>> I added a specific section to my program using
>>> __attribute__((section "<section name>")) and now I want to figure out
>>> where that section starts so I can iterate over it and call the
>>> function
>>> pointers I'm adding to it.
>>
>> Terminate the list with a null pointer; AFAIK that's what everyone else
>> does. To get the start address, you just need to define a global
>> variable
>> in that section. Of course this means you have to link everything in
>> the
>> correct order.
>
> I think you're talking about something like:
>
> void (*func_ptr)(void)[] __attribute__((section ".my_section")) = {
> func1,
> func2,
> func3,
> NULL,
> };
No.
void (*func_ptr)(void) __attribute__((section ".my_section") = foo;
void (*func_ptr)(void) __attribute__((section ".my_section") = bar;
etc, etc. I'm assuming the entries are in different files.
And in the last file,
void *poo __attribute__((section ".my_section") = NULL;
> is that right ? (the code above isn't really correct).
>
> I don't really have an array. I'm trying to mimic what the kernel does
> with the modules, but then again, the kernel declares the constants for
> the start and end of initcalls in constants within the ld script.
>
> So what I have right now is:
>
> main.c:
>
> [..]
>
> int __attribute__((section(".init"))) register_struct(struct my_struct *ptr)
> {
> [..]
> }
>
> [..]
>
> static int call_initcalls(void)
> {
> initcall_t *fn;
>
> for (fn = __start_initcall; fn; fn++)
> fn();
I don't understand this. How can you increment a function pointer?
>
> return 0;
> }
>
> then on another source code, I define an initcall_t.
>
> initcall.c:
>
> [..]
>
> static int __attribute__((section(".init"))) init(void)
> {
> return register_struct(ptr);
> }
>
> static initcall_t initcall_t_init __attribute__((section(".my.init")))
> __attribute__((__used__)) = init;
>
> then several little "plugins" would define that and all those pointers
> are going to the right section. Now how to fetch them and call them ??
> currently I'm getting segfault. :-p
>
next prev parent reply other threads:[~2010-04-14 8:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-13 17:40 Figuring " Felipe Balbi
2010-04-13 17:44 ` Andrew Haley
2010-04-14 5:08 ` Figurig " Felipe Balbi
2010-04-14 8:49 ` Andrew Haley [this message]
2010-04-14 0:24 ` Figuring " Ian Lance Taylor
2010-04-14 8:49 ` Andrew Haley
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=4BC58172.8030808@redhat.com \
--to=aph@redhat.com \
--cc=gcc-help@gcc.gnu.org \
--cc=me@felipebalbi.com \
/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).