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

Cranelift: error "unimplemented relocation addend Relocation" on MacOS on aarch64 #4564

Open
teymour-aldridge opened this issue Jul 30, 2022 · 4 comments
Labels
bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator

Comments

@teymour-aldridge
Copy link
Contributor

teymour-aldridge commented Jul 30, 2022

Thanks for filing an issue! Please fill out the TODOs below.

.clif Test Case

function u0:0() -> i64 apple_aarch64 {
    sig0 = (i64) -> i64 apple_aarch64
    sig1 = (i64) -> i64 apple_aarch64
    fn0 = u0:1 sig0
    fn1 = u0:2 sig1

block0:
    v0 = iconst.i64 13
    v1 = call fn1(v0)
    v2 = call fn0(v1)
    v3 = iconst.i64 0
    return v3
}

function u0:1(i64) -> i64 apple_aarch64 {
    sig0 = (i64) -> i64 apple_aarch64
    sig1 = (i64) -> i64 apple_aarch64
    fn0 = colocated u0:2 sig0
    fn1 = colocated u0:2 sig1

block0(v0: i64):
    v1 = iconst.i64 0
    v2 = icmp eq v0, v1
    brz v2, block2
    jump block1

block1:
    v3 = iconst.i64 0
    return v3

block2:
    v4 = iconst.i64 1
    v5 = icmp.i64 eq v0, v4
    brz v5, block4
    jump block3

block3:
    v6 = iconst.i64 1
    return v6

block4:
    v7 = iconst.i64 1
    v8 = isub.i64 v0, v7
    v9 = call fn0(v8)
    v10 = iconst.i64 2
    v11 = isub.i64 v0, v10
    v12 = call fn1(v11)
    v13 = iadd v9, v12
    return v13
}

Steps to Reproduce

  1. Run on an Apple M1 chip

Expected Results

  • The program should compile

Actual Results

The program paniced:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unimplemented relocation addend Relocation { offset: 104, size: 26, kind: Relative, encoding: AArch64Call, symbol: SymbolId(3), addend: -4 }")', <some path>/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-object-0.86.1/src/backend.rs:500:22

Versions and Environment

Cranelift version or commit: 0.86.1

Operating system: MacOS

Architecture: M1

Extra Info

This works for me on aarch64-unknown-gnu (see https://cirrus-ci.com/task/6079482023903232 - it runs a lot of additional things, but near the bottom of the "test" task it compiles the Fibonacci function fine), but not aarch64-apple-darwin. It also works on x86_64-apple-darwin.

@teymour-aldridge teymour-aldridge added bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator labels Jul 30, 2022
@cfallin
Copy link
Member

cfallin commented Aug 1, 2022

Thanks for the report. Did this CLIF come from Wasmtime or some other frontend? (I ask because we try to support Wasmtime's use of Cranelift on aarch64-apple-darwin but the use of Cranelift with other frontends is much less well-tested. That doesn't mean we don't want to support it, I'm just trying to judge the severity.) It sounds like we need to implement another relocation case here. If you're willing to dig into it further, I'd be happy to review a PR.

@teymour-aldridge
Copy link
Contributor Author

Did this CLIF come from Wasmtime or some other frontend?

It came from a different frontend (a small compiler I'm writing). The problem seems to be withcranelift-object, because I can run the same program without error by using cranelift-jit (which I have adopted as a stopgap solution).

If you're willing to dig into it further, I'd be happy to review a PR.

I'd be happy to, but I'm not sure what a relocation is :)

@teymour-aldridge teymour-aldridge changed the title Cranelift: error "unimplemented relocation addend Relocation" on M1 Mac only Cranelift: error "unimplemented relocation addend Relocation" on MacOS on aarch64 Aug 5, 2022
@afonso360
Copy link
Contributor

I think this might already be fixed upstream in gimli-rs/object#465, so it might be a case of just updating the object crate whenever they do their next release.

@afonso360
Copy link
Contributor

👋 Hey,

Would you be able to test this code using PR #5434? It includes the updated version of object, and I suspect it might fix your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

No branches or pull requests

3 participants