ELFIO
ELFIO copied to clipboard
load and validate file, no issues, save same unmodified one leads to issues
I just discovered an issue where saving an unmodified file leads to an issue. Validate does not report anything, but saving fails here:
https://github.com/serge1/ELFIO/blob/main/elfio/elfio.hpp#L869
if ( req_offset < cur_offset ) {
// something has gone awfully wrong, abort!
// section_align would turn out negative, seeking backwards and overwriting previous data
all I am doing is
reader.load("demo.elf");
std::cout << reader.validate();
reader.save("new_file.elf");
any Idea about that?
Hi,
Thank you for providing an example file. It is interesting and I am wondering what is confusing the library. In general case, the scenario of loading and saving may not always work. Please see the thread #74 and the last statement in https://github.com/serge1/ELFIO/wiki/How-to-modify-section-data.
Best regards
Thanks for the hints. In order to prevent any remapping of the file I want just to change the content of an existing section, not changing its size. Anyhow, I was expecting that the validation applies same checks as saving, but seems not.
Edit:
I just got aware that the target architecture of the attached elf is kind of special.
The Section Addresses are pointing to 16Bit wide elements, the size of section is counted in bytes.
Means that section address + section size is != next section address
, instead it is
section address << 1 + section size = next section address << 1
Definitely, the library does not support such configuration. I am not aware of a generic way to support it. So, you may tweak the sources and update the calculations. Alternatively, in condition that it is a commonly used architecture, you may send me a link to a description of its ABI.
Found this: https://www.ti.com/lit/pdf/sprac71
"However, for the C28x ELF format, fields that represent target addresses are native (word-oriented), but fields that represent target sizes are expressed in bytes."
Just as reference, I build a test case using libelf:
- loading elf file
- search and modify a specific section
- save elf file
This is working, so libelf does not get confused by this architecture
The issue is opened for a long time. I am not familiar with the features of this specialized architecture and without external help or explanation will not be able to support it. So, I am closing the issue. Please reopen if new information is available or external help is found.