Stream: git-wasmtime

Topic: wasmtime / issue #2907 Cranelift: absolute relocation in ...


view this post on Zulip Wasmtime GitHub notifications bot (May 15 2021 at 04:59):

syrusakbary opened issue #2907:

Cranelift emits AbsoluteRelocation Reloc::Abs8 when is_pic setting is enabled in architecture aarch64

Steps to Reproduce

(module
  ;; Recursive factorial
  (func (export "fac-rec") (param i64) (result i64)
    (if (result i64) (i64.eq (local.get 0) (i64.const 0))
      (then (i64.const 1))
      (else
        (i64.mul (local.get 0) (call 0 (i64.sub (local.get 0) (i64.const 1))))
      )
    )
  )
)
$ wasmtime wasm2obj fac.wat fac.o

Code emitted fac.o has absolute relocations.

Expected Results

Is expected for Cranelift to emit a relative relocation for aarch64 when is_pic is enabled.

Actual Results

Code emitted with an absolute relocation.

Versions and Environment

Cranelift version: cranelift-codegen = "0.73.0"
Operating system: Any
Architecture: Aarch64

Extra info

Here's where the wrong code is emitted:
https://github.com/bytecodealliance/wasmtime/blob/207da989acf5c6d828dd5d1704c05c0d01b1dead/cranelift/codegen/src/isa/aarch64/inst/emit.rs#L2440-L2462

In the new x86 backend however, the is_pic case is properly handled:

https://github.com/bytecodealliance/wasmtime/blob/e676589b0c6e8228c421e18249d4635eb6c4bbe4/cranelift/codegen/src/isa/x64/inst/emit.rs#L2350-L2387

view this post on Zulip Wasmtime GitHub notifications bot (May 15 2021 at 04:59):

syrusakbary labeled issue #2907:

Cranelift emits AbsoluteRelocation Reloc::Abs8 when is_pic setting is enabled in architecture aarch64

Steps to Reproduce

(module
  ;; Recursive factorial
  (func (export "fac-rec") (param i64) (result i64)
    (if (result i64) (i64.eq (local.get 0) (i64.const 0))
      (then (i64.const 1))
      (else
        (i64.mul (local.get 0) (call 0 (i64.sub (local.get 0) (i64.const 1))))
      )
    )
  )
)
$ wasmtime wasm2obj fac.wat fac.o

Code emitted fac.o has absolute relocations.

Expected Results

Is expected for Cranelift to emit a relative relocation for aarch64 when is_pic is enabled.

Actual Results

Code emitted with an absolute relocation.

Versions and Environment

Cranelift version: cranelift-codegen = "0.73.0"
Operating system: Any
Architecture: Aarch64

Extra info

Here's where the wrong code is emitted:
https://github.com/bytecodealliance/wasmtime/blob/207da989acf5c6d828dd5d1704c05c0d01b1dead/cranelift/codegen/src/isa/aarch64/inst/emit.rs#L2440-L2462

In the new x86 backend however, the is_pic case is properly handled:

https://github.com/bytecodealliance/wasmtime/blob/e676589b0c6e8228c421e18249d4635eb6c4bbe4/cranelift/codegen/src/isa/x64/inst/emit.rs#L2350-L2387

view this post on Zulip Wasmtime GitHub notifications bot (May 15 2021 at 04:59):

syrusakbary labeled issue #2907:

Cranelift emits AbsoluteRelocation Reloc::Abs8 when is_pic setting is enabled in architecture aarch64

Steps to Reproduce

(module
  ;; Recursive factorial
  (func (export "fac-rec") (param i64) (result i64)
    (if (result i64) (i64.eq (local.get 0) (i64.const 0))
      (then (i64.const 1))
      (else
        (i64.mul (local.get 0) (call 0 (i64.sub (local.get 0) (i64.const 1))))
      )
    )
  )
)
$ wasmtime wasm2obj fac.wat fac.o

Code emitted fac.o has absolute relocations.

Expected Results

Is expected for Cranelift to emit a relative relocation for aarch64 when is_pic is enabled.

Actual Results

Code emitted with an absolute relocation.

Versions and Environment

Cranelift version: cranelift-codegen = "0.73.0"
Operating system: Any
Architecture: Aarch64

Extra info

Here's where the wrong code is emitted:
https://github.com/bytecodealliance/wasmtime/blob/207da989acf5c6d828dd5d1704c05c0d01b1dead/cranelift/codegen/src/isa/aarch64/inst/emit.rs#L2440-L2462

In the new x86 backend however, the is_pic case is properly handled:

https://github.com/bytecodealliance/wasmtime/blob/e676589b0c6e8228c421e18249d4635eb6c4bbe4/cranelift/codegen/src/isa/x64/inst/emit.rs#L2350-L2387

view this post on Zulip Wasmtime GitHub notifications bot (May 15 2021 at 05:36):

cfallin commented on issue #2907:

Thanks for the report @syrusakbary !

Indeed this is a missing feature in the current aarch64 backend; it hasn't been needed yet but it should certainly be implemented at some point. In the short term it could make sense to assert not-PIC, so at least the failure is correct; but I'd be happy to review a PR, if you would like to take a crack at this. (Otherwise I don't know if anyone currently has the bandwidth to do this offhand, to assign this issue, though @bnjbvr please correct me if you have any plans for PIC as part of the M1 focus!)


Last updated: Oct 23 2024 at 20:03 UTC