serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library
http://serge1.github.io/ELFIO
MIT License
720 stars 155 forks source link

Read only required section information in the elfio class 'load' function #80

Closed oss-explorer closed 1 year ago

oss-explorer commented 2 years ago

Can only the required sections of the executable be read into the memory instead of reading the complete binary/all the sections and segments of the binary in the 'class elfio' load() function? With the complete executable being read into the memory, there is a peak in memory usage when binary sizes are in GB. Can you please consider this enhancement?

serge1 commented 2 years ago

Thank you for your suggestion. The current design of the library based on the fact that lifetime of the file stream cannot be garanteed after elfio::load() function finishes. I'll see whether a lazy section/segment data loading is possible as far as user garantees proper lifetime of the stream.

Meiri28 commented 2 years ago

beside the peak in the memory, there is another reason to take this approach. some of linux distribution have live memory dump file in /proc/kcore, in this elf file you can't always read from all of his segments(some of them are not readable although the file is with read permissions). this scenario lead to error in the stream and later to mistakes in the data elfio parse from this file.

serge1 commented 2 years ago

Hi @Meiri28, it is interesting aspect. How do you urge the library to treat /proc/kcore being an ELF file?

Meiri28 commented 2 years ago

This file is in elf formate. It's looks like a core dump but his size is enormous and as I said not all the data is readable. You can read more about kcore file in here.

serge1 commented 1 year ago

The commit 9827eac9 implementing 'lazy' load for segments and sections should finalize the initial request. Please reopen the issue if it does not work for you