Fix the LoongArch support code and some more (#483)
authorWÁNG Xuěruì <1175567+xen0n@users.noreply.github.com>
Wed, 6 Sep 2023 12:38:41 +0000 (20:38 +0800)
committerGitHub <noreply@github.com>
Wed, 6 Sep 2023 12:38:41 +0000 (05:38 -0700)
commit20cc45cea34190b607f9f05f2154978247793166
treea0f7cf9e7bcf94d163655c2f460fceeebd7b1fab
parentc9e558f76bbe9418f56b79779852e1ab77b6f8fa
Fix the LoongArch support code and some more (#483)

* Fix LoongArch support in dwarfdump.py

The e_machine constant is EM_LOONGARCH, and the emulation name is just
elf{32,64}-loongarch without the endian prefix.

Fixes: 6c36d79 ("add support for loongarch64 to dwarfdump (#458)")
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
* Fix the EF_LOONGARCH_* symbol names

The current code gets the logic right, but not the symbol names. Fix
them for consistency with the canonical definition that's binutils.

Fixes: 2059475 ("Add support for LoongArch (#470)")
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
* Fix a missing description string in elffile.py for LoongArch

Fixes: 2059475 ("Add support for LoongArch (#470)")
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
* Provide EF_LARCH_* name aliases for the EF_LOONGARCH_* constants

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
* Add definitions for LoongArch relocations

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
* Add support for basic 32- and 64-bit LoongArch relocations

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
* scripts/readelf.py: Properly format control chars in symbol names

This is necessary to match readelf behavior on fake symbol names, that
usually look like "L0^A" when rendered (being "L0\x01" in reality).

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
* scripts/readelf.py: Fix register display order in _dump_debug_frames_interp

According to binutils sources (function frame_display_row in
binutils/dwarf.c), the apparent ordering of the ra register after other
registers is merely a side effect of most architectures allocating a
larger DWARF register number for their respective ra registers. This has
no effect on all readelf test cases, but is necessary for a future
LoongArch test binary to pass comparisons.

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
* Add test program and artifact covering basic LoongArch relocations

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
---------

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
elftools/elf/constants.py
elftools/elf/descriptions.py
elftools/elf/elffile.py
elftools/elf/enums.py
elftools/elf/relocation.py
scripts/dwarfdump.py
scripts/readelf.py
test/testfiles_for_readelf/loongarch-relocs.c [new file with mode: 0644]
test/testfiles_for_readelf/loongarch64-relocs.o.elf [new file with mode: 0644]