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

Mach-O AArch64 relocation addend improvements #581

Merged
merged 3 commits into from
Oct 24, 2023

Conversation

philipc
Copy link
Contributor

@philipc philipc commented Oct 10, 2023

macho: fix PC relative relocation offset for AArch64

For PC relative relocations on some architectures, the implicit addend does not include the offset required due to the PC being different from the place of the relocation.

Previously we always used an offset of 4, since this is commonly required by x86-64. However, this is not correct for AArch64 or for some x8-64 relocations, and probably not correct for other architectures either. For example, the ARM offset may vary depending on the instruction used.

For now, disable this handling for all non x86 targets. This fixes AArch64. Support for other architectures is left as a TODO.

write/macho: fix ARM64_RELOC_ADDEND handling

  • fix SectionHeader::nreloc to include additional ARM64_RELOC_ADDEND relocations
  • switch order of ARM64_RELOC_ADDEND and its paired relocation
  • emit ARM64_RELOC_ADDEND for more relocation types

Closes #580

read/macho: handle ARM64_RELOC_ADDEND

Closes #466

cc @nathanwhit If you're still working in this area, can you review and ensure that your changes from #465 still work? I'll look into adding some tests for this too.

For PC relative relocations on some architectures, the implicit addend
does not include the offset required due to the PC being different from
the place of the relocation.

Previously we always used an offset of 4, since this is commonly required
by x86-64. However, this is not correct for AArch64 or for some x8-64
relocations, and probably not correct for other architectures either.
For example, the ARM offset may vary depending on the instruction used.

For now, disable this handling for all non x86 targets. This fixes AArch64.
Support for other architectures is left as a TODO.
- fix SectionHeader::nreloc to include additional ARM64_RELOC_ADDEND relocations
- switch order of ARM64_RELOC_ADDEND and its paired relocation
- emit ARM64_RELOC_ADDEND for more relocation types
@philipc philipc merged commit a829634 into gimli-rs:master Oct 24, 2023
12 checks passed
@philipc philipc deleted the issue-580 branch October 24, 2023 04:36
mcbegamerxx954 pushed a commit to mcbegamerxx954/object that referenced this pull request Jun 15, 2024
Mach-O AArch64 relocation addend improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant