Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the LoongArch support code and some more #483

Merged
merged 9 commits into from
Sep 6, 2023

Conversation

xen0n
Copy link
Contributor

@xen0n xen0n commented Aug 2, 2023

There were #458 and #470, but unfortunately both were partly incorrect. I've fixed them and added some more support for LoongArch relocations while at it.

@sevaa
Copy link
Contributor

sevaa commented Aug 13, 2023

We don't have any LoongArch binaries to autotest against, do we?

@xen0n
Copy link
Contributor Author

xen0n commented Aug 14, 2023

I tried to add some tests but IIRC the readelf test failed because the prebuilt binary is too old to recognize some of the new LoongArch relocs (or the architecture itself), and at that time I don't have enough time to look into this. I may be able to follow up a few days later though.

@eliben
Copy link
Owner

eliben commented Aug 16, 2023

It may be time to bump the pre-built readelf to recognize LoongArch; otherwise I feel like we're stretching it without real files to test against.

@sevaa
Copy link
Contributor

sevaa commented Aug 16, 2023

The latest readelf will break a whole bunch of autotests, at least on the DWARF side. There is a reason we carry around our own. That said, that bullet needs to be eventually bitten.

@sevaa
Copy link
Contributor

sevaa commented Aug 20, 2023

@xen0n: Try grabbing an updated copy of readelf from the master branch, see if makes a difference.

@xen0n
Copy link
Contributor Author

xen0n commented Aug 23, 2023

I'm rebasing this PR, hoping to post an updated revision this week.

@eliben
Copy link
Owner

eliben commented Sep 1, 2023

@xen0n if you want this PR to make it into the next release of pyelftools, please address the comments soon

@xen0n
Copy link
Contributor Author

xen0n commented Sep 1, 2023

@xen0n if you want this PR to make it into the next release of pyelftools, please address the comments soon

Thanks for the reminder; I'll try to do this tonight.

@xen0n
Copy link
Contributor Author

xen0n commented Sep 4, 2023

Update: I'm blocked by the readelf DWARF test cases, still working my way through missing generic codepaths that get exercised by the LoongArch test binary I just made. everything should be okay now!

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 (eliben#458)")
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
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 (eliben#470)")
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
Fixes: 2059475 ("Add support for LoongArch (eliben#470)")
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
@sevaa
Copy link
Contributor

sevaa commented Sep 4, 2023

The basic ELF/LoongArch binary is a part of the autotest, the relocations is the only architecture specific part that needed any nontrivial treatment and that's done. Friendly register names on RISC platforms, as we've concluded, are nowhere on GNU binutils' radar and therefore shouldn't be on pyelftools', either. :) :(

I think this is good to go. 謝謝

@@ -322,6 +331,12 @@ def _reloc_calc_sym_plus_addend(value, sym_value, offset, addend=0):
def _reloc_calc_sym_plus_addend_pcrel(value, sym_value, offset, addend=0):
return sym_value + addend - offset

def _reloc_calc_value_plus_sym_addend(value, sym_value, offset, addend=0):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you rebase this PR, one of the recent commits made _reloc_calc_sym_plus_value do the same thing -- can that be used instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

@@ -95,6 +96,11 @@ def _get_cu_base(cu):
else:
raise ValueError("Can't find the base IP (low_pc) for a CU")

_CONTROL_CHAR_RE = re.compile(r'[\x01-\x1f]')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining what this is for

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an explanation for it (meant for use in _format_symbol_name).

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
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>
…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>
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
@eliben eliben merged commit 20cc45c into eliben:master Sep 6, 2023
3 checks passed
@xen0n xen0n deleted the fix-loong-support branch September 6, 2023 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants