Replies: 2 comments
-
Needed to add some checks, so can align section to segments now:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear all,
I am checking if elfio is a good replacement for libelf which I used to use to post-process elf files for some micro-controller development. Mainly I use it for some crc calculation, so I need to rebuild a memory dump like it would be on the device, calculate a crc and write the result to some specific section.
But while working fine, libelf is somehow difficult to integrate (using windows, cmake etc)
The other option is to use binutils libbfd(could use mingw libs here), but I really like the low dependency approach of elfio, which in addition would give me the chance learn some c++ again
In order to rebuild the memory structure, I need to know the lma (load memory address) of sections, which is, at least according to my understanding, just possible if using the program/segment headers where I can find a mapping of VIRTUAL to PHYSCAL
So, my first question is, does elfio offer a method to obtain the lma of a section?
Or what would be the correct way to calculate the LMA? For me so far lma = seg_paddr + sec_offs - seg_offs; (see code below) gave corrects results.
2nd question:
In order to get the physical address of a section, I need to find out which section belongs to which segment.
There is no mapping table etc, its is done by iteration and some address + offset magic.
In the past I played around and found a method which worked for the elf files I had a that time, but now having a different compiler this method is failing, because the section sizes are overlapping.
Anyway, readelf does this correct, but is kind of complex:
Here at binutils
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=binutils/readelf.c;hb=HEAD#l6711
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=include/elf/internal.h;hb=HEAD#l317
or here at elfutils
https://sourceware.org/git/?p=elfutils.git;a=blob;f=src/readelf.c;hb=HEAD#l1503
can I achieve similar functionality using elfio?
Beta Was this translation helpful? Give feedback.
All reactions