ELFIO icon indicating copy to clipboard operation
ELFIO copied to clipboard

load and validate file, no issues, save same unmodified one leads to issues

Open arne123 opened this issue 1 year ago • 5 comments

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");

demo.tar.gz

any Idea about that?

arne123 avatar Aug 25 '23 12:08 arne123

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

serge1 avatar Aug 28 '23 16:08 serge1

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

arne123 avatar Aug 28 '23 22:08 arne123

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.

serge1 avatar Aug 29 '23 17:08 serge1

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."

arne123 avatar Aug 29 '23 21:08 arne123

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

arne123 avatar Aug 30 '23 14:08 arne123

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.

serge1 avatar Mar 03 '24 15:03 serge1