Skip to content

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

Open

Description

@teymour-aldridge

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.life-white.uk-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.

Activity

  1. added
    bugIncorrect behavior in the current implementation that needs fixing
    craneliftIssues related to the Cranelift code generator
    on Jul 30, 2022
  2. cfallin commented on Aug 1, 2022

    @cfallin
    Member

    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.

  3. teymour-aldridge commented on Aug 2, 2022

    @teymour-aldridge
    ContributorAuthor

    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 :)

  4. changed the title [-]Cranelift: error "unimplemented relocation addend Relocation" on M1 Mac only[/-] [+]Cranelift: error "unimplemented relocation addend Relocation" on MacOS on aarch64[/+] on Aug 5, 2022
  5. afonso360 commented on Oct 11, 2022

    @afonso360
    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.

  6. afonso360 commented on Jan 8, 2023

    @afonso360
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixingcraneliftIssues related to the Cranelift code generator

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions