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

Reverse the order of emitting relocations on MachO #702

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

bjorn3
Copy link
Contributor

@bjorn3 bjorn3 commented Jun 27, 2024

This prevents a crash of Apple's new linker.

This prevents a crash of Apple's new linker.
@philipc
Copy link
Contributor

philipc commented Jun 28, 2024

This probably should be treated as a breaking change. What do you think about trying to avoid that by detecting if it needs to be reversed? Too magical?

                let need_reverse = |relocs: &[Relocation]| {
                    let Some(first) = relocs.first() else { return false; };
                    let Some(last) = relocs.last() else { return false; };
                    first.offset < last.offset
                }; 
                if need_reverse(&section.relocations) {
                    for reloc in section.relocations.iter().rev() {
                        write_reloc(reloc)?;
                    }
                } else {
                    for reloc in &section.relocations {
                        write_reloc(reloc)?;
                    }
                }

Also, out of interest, I checked that just swapping the ARM64_RELOC_GOT_LOAD_PAGE21/ ARM64_RELOC_GOT_LOAD_PAGEOFF12 pairs is enough for the cg_clif tests to pass. I think it is safer to reverse everything though.

@bjorn3
Copy link
Contributor Author

bjorn3 commented Jun 28, 2024

Too magical?

Maybe? I applied your suggestion anyway.

Copy link
Contributor

@philipc philipc left a comment

Choose a reason for hiding this comment

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

Thanks!

@philipc philipc merged commit 2a297a5 into gimli-rs:master Jun 28, 2024
10 checks passed
@bjorn3 bjorn3 deleted the fix_macho_reloc_order branch June 28, 2024 10:45
@bjorn3
Copy link
Contributor Author

bjorn3 commented Jun 28, 2024

Would it be possible to get a patch release for this? That would allow me to fix cg_clif on arm64 macOS quicker as I wouldn't need to get a Cranelift PR for bumping the object version merged and wait a couple of weeks for the next Cranelift release.

@philipc
Copy link
Contributor

philipc commented Jun 28, 2024

Yes, I'll do a release tomorrow.

@philipc
Copy link
Contributor

philipc commented Jun 29, 2024

Released 0.36.1

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.

2 participants