[Bug] Preserve all eight bits of ELF32 relocation types

Open Beginner friendly
#10 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp

Research direction

The ELF32 relocation decoding is in src/loader/elf/elf.cpp around lines 257-263, where the type is masked with 0xf instead of 0xff. Start there and check the ELF32 and ELF64 branches side by side, including how REL and RELA tables are handled. Done means an ELF32 fixture with a type above 15 (such as R_386_IRELATIVE, 42) and one below 16 both decode correctly, while symbol-index decoding stays the same.

Written by the indexing model from the issue text.

Description

bug good first issue

Summary

ELF32 relocation types are truncated to four bits, so valid relocation types greater than 15 are reported incorrectly even though the project advertises ELF32 relocation parsing.

Evidence

In src/loader/elf/elf.cpp:257-263, the ELF32 path decodes the relocation info as:

relocation.type = relocation.info & 0xfU;
relocation.symbol_index = relocation.info >> 8;

The ELF32 r_info layout reserves the low 8 bits for the relocation type; only the symbol index starts at bit 8.

I assembled a valid 32-bit object containing an R_386_IRELATIVE relocation. readelf shows raw Info 0000022a and the symbolic type R_386_IRELATIVE, while Caraxes reports:

.rel.data offset=0x0 type=10 symbol=2 (target)

The low byte is 0x2a (42), but the four-bit mask reduces it to 0xa (10).

Impact

Consumers of the loader receive incorrect relocation metadata for common ELF32 relocation types. This can break import/PLT recovery and any architecture-specific logic that dispatches on the relocation type.

Expected behavior

ELF32 relocation decoding should preserve all eight type bits and return the correct numeric type. ELF64 behavior should remain based on its 32-bit type field.

Acceptance criteria

  • The R_386_IRELATIVE reproducer reports type 42.
  • Add an ELF32 regression fixture covering a type above 15 and a type below 16.
  • Verify symbol-index decoding remains unchanged.
  • Keep the result consistent for both REL and RELA relocation tables.
Dominant language
C++
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TiElixir/caraxes

All issues in TiElixir/caraxes

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.