I am looking for a nice way of enumerating all ELF sections and their addresses of the current binary and all shared objects the current process might have loaded.
I know about the existance of dl_iterate_phdr() which gives me an easy to use list of ELF segments, but I am looking for ELF sections, so it's not the right call for me.
I don't care about portability, as long as it works on Linux with ELF I am happy!
Any hint appreciated!
I assume you're trying to programmatically access this information from a C/C++ program. I suspect you should be able to do what you want with the GNU Binary File Descriptor library (BFD), which is used to implement the GNU linker, objdump, etc. (it also has a Wikipedia article). See in particular section 2.6 of the manual, which is all about sections. BFD creates a linked list of "struct bfd_section", accessed through the "sections" member of struct bfd. I think you should be able to open the current binary by using bfd_fopen on argv[0]. BFD ships with binutils.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With