Support ARM ELF THM_PC22 / THM_JUMP24 relocs #4503
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This revision adds proper support for the following ARM ELF relocations:
RZ_ARM_THM_PC22
RZ_ARM_THM_JUMP24
These require a rather special encoding as some bits of the relative offset are encoded in a non-common fashion.
Your checklist for this pull request
Detailed description
As of now, rizin implements a rather rudimentary handling of ARM ELF Relocation: it just overwrites the the patch address with the value calculated for the symbol. While this works in some cases, there are others that do not, most notably
ARM_THM_PC22
andARM_THM_JUMP24
that use a quite different encoding.With this change, the relocations are correctly handled and lead to properly encoded values. Note that this change doesn't handle possible overflows for which some thunk would need to be inserted.
The implementation was heavily inspired by lld's implementation, although the special cases (e.g. BL/BLX patching, missing J1J2 support) are not considered in this change.
I did not extend the documentation as it is not that detailed / does not even exist here.
Test plan
To test the change, it would be sufficient to check that after relocation, the
bl
instruction to the proper target exists and is not replaced by some unrelated instruction.Example:
Previously:
With this change:
I added a test for a binary that contains THM_PC22.
Closing issues