How do you get the start and end addresses of a custom ELF section in C (gcc)? -


i've seen usage of of gcc __section__ attribute (especially in linux kernel) collect data (usually function pointers) custom elf sections. how "stuff" gets put in custom sections retrieved , used?

as long section name results in valid c variable name, gcc (ld, rather) generates 2 magic variables: __start_section , __stop_section. can used retrieve start , end addresses of section, so:

/**  * assuming you've tagged stuff earlier with:  * __attribute((__section__("my_custom_section")))  */  struct thing *iter = &__start_my_custom_section;  ( ; iter < &__stop_my_custom_section; ++iter) {     /* *iter */ } 

i couldn’t find formal documentation feature, few obscure mailing list references. if know docs are, drop comment!

if you're using own linker script (as linux kernel does) you'll have add magic variables (see vmlinux.lds.[sh] , this answer).

see here example of using custom elf sections.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -