Closed nmeum closed 1 year ago
BTW: If you strip the binary (thereby getting rid of section 6 about which melf complains) then the error message changes to:
section SHN_EXT 3 (empty @4096) and section table (3964 ... 4243) intersect (src/Data/Internal/Elf.hs:277)
Section 3 starts at 0x1000 and ends at 0x1000 + 0x1f44 = 0x2f44 in the ELF file. Section 6 starts at 0xf44 and ends at 0xf44 + 0x370 = 0x12B4. Obviously they intersect so I don't see any bug in melf here.
melf has to build the tree of the sections/segments so it is more demanding on the structure of ELF file. Some gcc/binutils versions have bugs that result in generating ELF files where sections or segments or tables intersect. You can find another example of such incorrect binary in melf/testdata/arm_64_lsb/chmod.bad. That file was created by some old version of gcc/binutils and that bug was fixed in the later versions of gcc/binutils.
In this case section 3 is ".bss". It should not (and does not) have any data in ELF file. But sections table says it has size 0x1f44 which is wrong. You may want to report the bug to RISC-V binutils maintainers.
Consider the following ELF binary: https://user.informatik.uni-bremen.de/~tempel/tmp/test-binary.elf
This binary is parsed fine by the elf package:
melf, however, does not seem to like this binary:
Other tools such as
readelf(1)
et cetera also do not complain about this binary:So I guess this is a bug in melf?