pyelftools icon indicating copy to clipboard operation
pyelftools copied to clipboard

ELF file for ARM is not properly supported.

Open scudette opened this issue 10 years ago • 3 comments

I have a dwarf file produced from ARM (android) and readelf.py fails:

$ readelf.py --debug-dump=info module_dwarf.ko
ELF error: Unsupported relocation type: 2

The reason for that is because there are no relocation recipes for ARM in elftools/elf/relocation.py only ones exist for MIPS and X64 and X86.

The complete list is here: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf table 4-8.

As a quick hack we can lie and say that this is a MIPS file and this works ok (at least on this file) but it would be good to have proper support.

class ELFFile(elffile.ELFFile):
    def get_machine_arch(self):
        result = super(ELFFile, self).get_machine_arch()
        if result == "ARM":
            result = "MIPS"

        return result

elffile.ELFFile = ELFFile

scudette avatar Sep 23 '15 15:09 scudette

There's definitely some support for ARM there - we have arm files for the readelf comparison tests; but maybe this particular functionality is not supported (applying relocations in dwarf). Patches welcome! [I'm unlikely to find time to implement this functionality any time soon]

eliben avatar Sep 23 '15 15:09 eliben

I added support for R_ARM_ABS32 relocation. How can I add test cases to compare output with readelf?

frederiksdun avatar Oct 24 '16 09:10 frederiksdun

@frederiksdun it's best to add a new file to test/testfiles_for_readelf-- have it the simplest possible file. Then tests/run_readelf_tests.py will run the tests on it

eliben avatar Oct 24 '16 12:10 eliben