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
Post a Comment