This sounds like a very bad idea, but if you have legal use, I just parse /proc/self/maps and open the link files. There is no reason to believe that the section headers are even mapped to memory; in all likelihood, they are located immediately after .data on the disk, and thus will be overwritten with zeros for .bss when the shared object is mapped to memory.
Once you open the files, you can use libbfd , but I would just use elf.h directly. Itβs easy to keep track of the Ehdr table in the Shdr table.
source share