Skip to content

Added support for symbol relocation for RISC-V architecture #613

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

adjordjevic-TT
Copy link

Added support for symbol relocation for RISC-V architecture.

Added ENUM_RELOC_TYPE_RISCV to enums.py

Added _RELOCATION_RECIPES_RISCV, two more relocation functions (_reloc_calc_value_plus_sym_6 and _reloc_calc_value_minus_sym_addend_6) and case when e-machine is RISC-V to relocation.py.

@adjordjevic-TT adjordjevic-TT marked this pull request as draft April 2, 2025 08:40
@adjordjevic-TT adjordjevic-TT reopened this Apr 2, 2025
@adjordjevic-TT adjordjevic-TT marked this pull request as ready for review April 2, 2025 08:41
@adjordjevic-TT
Copy link
Author

@eliben Can you take a look at this?

@eliben
Copy link
Owner

eliben commented May 5, 2025

@sevaa any concerns?

@sevaa
Copy link
Contributor

sevaa commented May 5, 2025

Looks in line with how relocation is handled for other architectures. Is there any way to test this?

@adjordjevic-TT
Copy link
Author

adjordjevic-TT commented May 5, 2025

Would it be enough to just provide arbitrary elf that uses RISCV relocations and just to add it to testfiles or those elfs have some specific content? @sevaa

@sevaa
Copy link
Contributor

sevaa commented May 5, 2025

An erroneously written piece of relocation logic most likely will not crash; it will produce wrong bits in the loaded section. How does one test that?

@adjordjevic-TT
Copy link
Author

Ideally, we can create elf that uses RISCV relocations with some functions/variables and if we are able to find those symbols relocations are working properly, but I don't think it is practical to test every sing one relocation type. Everything that is implemented is taken from here: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#reloc-table

@sevaa
Copy link
Contributor

sevaa commented May 5, 2025

If @eliben says it's OK not to test this exhaustively, I will be OK with that :)

@eliben
Copy link
Owner

eliben commented May 5, 2025

@adjordjevic-TT can you say what you're using these RISC-V relocations for? (in other words, why this PR?)

@sevaa several of the readelf comparison tests rely on correct implementation of relocations. Wouldn't a file compiled for RISC-V with relocations inside therefore exercise this logic?

@adjordjevic-TT
Copy link
Author

We are using it for finding variable's address or value and for implementing backtracing (callstack) for kernels that are running on our hardware that is based on RISCV arch.

@eliben
Copy link
Owner

eliben commented May 5, 2025

@adjordjevic-TT could you add a simple unit test? Look at the other unit tests in the test/ directory for inspiration (the file itself can be placed in testfiles_for_unittests, and please add a .c file alongside it with build instructions to reproduce the binary)

@sevaa
Copy link
Contributor

sevaa commented May 5, 2025

The only sections that are parsed, dumped, and compared by the readelf test are the DWARF ones and notes; in executable/SO binaries, relocations against those are rare (none in the corpus, last time I checked). Were we to dump and compare the disassembly, though, or the initialized global data section, that would be the test.

@eliben
Copy link
Owner

eliben commented May 5, 2025

The only sections that are parsed, dumped, and compared by the readelf test are the DWARF ones and notes; in executable/SO binaries, relocations against those are rare (none in the corpus, last time I checked). Were we to dump and compare the disassembly, though, or the initialized global data section, that would be the test.

Let's continue this discussion in #601

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants